{"action":"created","comment":{"url":"https://api.github.com/repos/pfnet/chainercv/pulls/comments/118841937","pull_request_review_id":40672805,"id":118841937,"diff_hunk":"@@ -0,0 +1,84 @@\n+import chainer\n+from chainer import cuda\n+import chainer.functions as F\n+from chainer import reporter\n+\n+import numpy as np\n+\n+from chainercv.evaluations import eval_semantic_segmentation\n+\n+\n+class PixelwiseSoftmaxClassifier(chainer.Chain):\n+\n+    \"\"\"A pixel-wise classifier.\n+\n+    It computes the loss and accuracy based on a given input/label pair for\n+    semantic segmentation.\n+\n+    Args:\n+        predictor (~chainer.Link): Predictor network.\n+        ignore_label (int): A class id that is going to be ignored in\n+            evaluation. The default value is -1.\n+        class_weight (array): An array\n+            that contains constant weights that will be multiplied with the\n+            loss values along with the channel dimension. This will be\n+            used in :func:`chainer.functions.softmax_cross_entropy`.\n+        compute_accuracy (bool): If :obj:`True`, compute accuracy on the\n+            forward computation. The default value is :obj:`True`.\n+\n+    \"\"\"\n+\n+    def __init__(self, predictor, ignore_label=-1, class_weight=None,\n+                 compute_accuracy=True):\n+        super(PixelwiseSoftmaxClassifier, self).__init__(predictor=predictor)\n+        self.n_class = predictor.n_class\n+        self.ignore_label = ignore_label\n+        if class_weight is not None:\n+            self.class_weight = np.asarray(class_weight, dtype=np.float32)\n+        else:\n+            self.class_weight = class_weight\n+        self.compute_accuracy = compute_accuracy\n+\n+    def to_cpu(self):\n+        super(PixelwiseSoftmaxClassifier, self).to_cpu()\n+        if self.class_weight is not None:\n+            self.class_weight = cuda.to_cpu(self.class_weight)\n+\n+    def to_gpu(self, device=None):\n+        super(PixelwiseSoftmaxClassifier, self).to_gpu(device)\n+        if self.class_weight is not None:\n+            self.class_weight = cuda.to_gpu(self.class_weight, device)\n+\n+    def __call__(self, x, t):\n+        \"\"\"Computes the loss value for an input and label pair.\n+\n+        It also computes accuracy and stores it to the attribute.\n+\n+        Args:\n+            x (~chainer.Variable): A variable with a 4D image array.\n+            t (~chainer.Variable): A variable with the ground truth\n+                image-wise label.","path":"chainercv/links/model/pixelwise_softmax_classifier.py","position":60,"original_position":60,"commit_id":"a6495835dcbc5f0719ad74b406464aa6c12f87eb","original_commit_id":"a6495835dcbc5f0719ad74b406464aa6c12f87eb","user":{"login":"Hakuyume","id":3014172,"avatar_url":"https://avatars0.githubusercontent.com/u/3014172?v=3","gravatar_id":"","url":"https://api.github.com/users/Hakuyume","html_url":"https://github.com/Hakuyume","followers_url":"https://api.github.com/users/Hakuyume/followers","following_url":"https://api.github.com/users/Hakuyume/following{/other_user}","gists_url":"https://api.github.com/users/Hakuyume/gists{/gist_id}","starred_url":"https://api.github.com/users/Hakuyume/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Hakuyume/subscriptions","organizations_url":"https://api.github.com/users/Hakuyume/orgs","repos_url":"https://api.github.com/users/Hakuyume/repos","events_url":"https://api.github.com/users/Hakuyume/events{/privacy}","received_events_url":"https://api.github.com/users/Hakuyume/received_events","type":"User","site_admin":false},"body":"What does `a 4D image array` mean? `(B, C, H, W)`?","created_at":"2017-05-28T14:06:44Z","updated_at":"2017-05-28T14:14:40Z","html_url":"https://github.com/pfnet/chainercv/pull/161#discussion_r118841937","pull_request_url":"https://api.github.com/repos/pfnet/chainercv/pulls/161","_links":{"self":{"href":"https://api.github.com/repos/pfnet/chainercv/pulls/comments/118841937"},"html":{"href":"https://github.com/pfnet/chainercv/pull/161#discussion_r118841937"},"pull_request":{"href":"https://api.github.com/repos/pfnet/chainercv/pulls/161"}}},"pull_request":{"url":"https://api.github.com/repos/pfnet/chainercv/pulls/161","id":119904946,"html_url":"https://github.com/pfnet/chainercv/pull/161","diff_url":"https://github.com/pfnet/chainercv/pull/161.diff","patch_url":"https://github.com/pfnet/chainercv/pull/161.patch","issue_url":"https://api.github.com/repos/pfnet/chainercv/issues/161","number":161,"state":"open","locked":false,"title":"Add SegNetBasic model","user":{"login":"mitmul","id":666535,"avatar_url":"https://avatars3.githubusercontent.com/u/666535?v=3","gravatar_id":"","url":"https://api.github.com/users/mitmul","html_url":"https://github.com/mitmul","followers_url":"https://api.github.com/users/mitmul/followers","following_url":"https://api.github.com/users/mitmul/following{/other_user}","gists_url":"https://api.github.com/users/mitmul/gists{/gist_id}","starred_url":"https://api.github.com/users/mitmul/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mitmul/subscriptions","organizations_url":"https://api.github.com/users/mitmul/orgs","repos_url":"https://api.github.com/users/mitmul/repos","events_url":"https://api.github.com/users/mitmul/events{/privacy}","received_events_url":"https://api.github.com/users/mitmul/received_events","type":"User","site_admin":false},"body":"Merge after #132 \r\n\r\n- SegNetBasic model is from this Caffe impl.: https://github.com/alexgkendall/SegNet-Tutorial/blob/master/Models/segnet_basic_train.prototxt\r\n\r\n### Training\r\n\r\n```\r\ncd examples/segnet\r\nCHAINER_TYPE_CHECK=0 python -OO -W ignore train.py --gpu 0\r\n```\r\n`eval_semantic_segmentation` makes a lot of warnings, so I suppressed them by giving `-W ignore` option.\r\n\r\n### Memo\r\n\r\n- According to the original implementation, the authors seemed to perform LR flipping to the input images for data augmentation: https://github.com/alexgkendall/caffe-segnet/blob/segnet-cleaned/src/caffe/layers/dense_image_data_layer.cpp#L168-L175\r\n- Chainer's LRN layer is different from Caffe's one in terms of the meaning of \"alpha\" argment: https://github.com/alexgkendall/caffe-segnet/blob/segnet-cleaned/src/caffe/layers/lrn_layer.cpp#L121\r\n\r\n## Results\r\n\r\nThe evaluation result after 16000 iterations:\r\n```\r\n                    Sky : 0.8675\r\n               Building : 0.6487\r\n                   Pole : 0.1795\r\n           Road_marking : 0.8493\r\n                   Road : 0.6230\r\n               Pavement : 0.6051\r\n                   Tree : 0.1813\r\n             SignSymbol : 0.1901\r\n              Fence,Car : 0.5924\r\n             Pedestrian : 0.2402\r\n              Bicyclist : 0.2111\r\n==================================\r\n               mean IoU : 0.4716\r\n Class average accuracy : 0.6705\r\nGlobal average accuracy : 0.8266\r\n```\r\n\r\n```\r\nGlobal accuracy : 82.8%\r\nClass accuracy : 62.3%\r\nMean IoU : 46.3%\r\n```\r\n\r\nThe trained weights to replicate the same results as below is here: [model_iteration-16000](https://www.dropbox.com/s/exas66necaqbxyw/model_iteration-16000?dl=1)","created_at":"2017-05-10T14:59:48Z","updated_at":"2017-05-28T14:14:40Z","closed_at":null,"merged_at":null,"merge_commit_sha":"56b986c8353bd37948b70b721f133f5db1f9449f","assignee":{"login":"rezoo","id":212315,"avatar_url":"https://avatars3.githubusercontent.com/u/212315?v=3","gravatar_id":"","url":"https://api.github.com/users/rezoo","html_url":"https://github.com/rezoo","followers_url":"https://api.github.com/users/rezoo/followers","following_url":"https://api.github.com/users/rezoo/following{/other_user}","gists_url":"https://api.github.com/users/rezoo/gists{/gist_id}","starred_url":"https://api.github.com/users/rezoo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rezoo/subscriptions","organizations_url":"https://api.github.com/users/rezoo/orgs","repos_url":"https://api.github.com/users/rezoo/repos","events_url":"https://api.github.com/users/rezoo/events{/privacy}","received_events_url":"https://api.github.com/users/rezoo/received_events","type":"User","site_admin":false},"assignees":[{"login":"rezoo","id":212315,"avatar_url":"https://avatars3.githubusercontent.com/u/212315?v=3","gravatar_id":"","url":"https://api.github.com/users/rezoo","html_url":"https://github.com/rezoo","followers_url":"https://api.github.com/users/rezoo/followers","following_url":"https://api.github.com/users/rezoo/following{/other_user}","gists_url":"https://api.github.com/users/rezoo/gists{/gist_id}","starred_url":"https://api.github.com/users/rezoo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rezoo/subscriptions","organizations_url":"https://api.github.com/users/rezoo/orgs","repos_url":"https://api.github.com/users/rezoo/repos","events_url":"https://api.github.com/users/rezoo/events{/privacy}","received_events_url":"https://api.github.com/users/rezoo/received_events","type":"User","site_admin":false}],"requested_reviewers":[],"milestone":null,"commits_url":"https://api.github.com/repos/pfnet/chainercv/pulls/161/commits","review_comments_url":"https://api.github.com/repos/pfnet/chainercv/pulls/161/comments","review_comment_url":"https://api.github.com/repos/pfnet/chainercv/pulls/comments{/number}","comments_url":"https://api.github.com/repos/pfnet/chainercv/issues/161/comments","statuses_url":"https://api.github.com/repos/pfnet/chainercv/statuses/a6495835dcbc5f0719ad74b406464aa6c12f87eb","head":{"label":"pfnet:add-segnet-model","ref":"add-segnet-model","sha":"a6495835dcbc5f0719ad74b406464aa6c12f87eb","user":{"login":"pfnet","id":9739572,"avatar_url":"https://avatars1.githubusercontent.com/u/9739572?v=3","gravatar_id":"","url":"https://api.github.com/users/pfnet","html_url":"https://github.com/pfnet","followers_url":"https://api.github.com/users/pfnet/followers","following_url":"https://api.github.com/users/pfnet/following{/other_user}","gists_url":"https://api.github.com/users/pfnet/gists{/gist_id}","starred_url":"https://api.github.com/users/pfnet/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pfnet/subscriptions","organizations_url":"https://api.github.com/users/pfnet/orgs","repos_url":"https://api.github.com/users/pfnet/repos","events_url":"https://api.github.com/users/pfnet/events{/privacy}","received_events_url":"https://api.github.com/users/pfnet/received_events","type":"Organization","site_admin":false},"repo":{"id":81784084,"name":"chainercv","full_name":"pfnet/chainercv","owner":{"login":"pfnet","id":9739572,"avatar_url":"https://avatars1.githubusercontent.com/u/9739572?v=3","gravatar_id":"","url":"https://api.github.com/users/pfnet","html_url":"https://github.com/pfnet","followers_url":"https://api.github.com/users/pfnet/followers","following_url":"https://api.github.com/users/pfnet/following{/other_user}","gists_url":"https://api.github.com/users/pfnet/gists{/gist_id}","starred_url":"https://api.github.com/users/pfnet/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pfnet/subscriptions","organizations_url":"https://api.github.com/users/pfnet/orgs","repos_url":"https://api.github.com/users/pfnet/repos","events_url":"https://api.github.com/users/pfnet/events{/privacy}","received_events_url":"https://api.github.com/users/pfnet/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/pfnet/chainercv","description":"Set of tools for Computer Vision using Chainer","fork":false,"url":"https://api.github.com/repos/pfnet/chainercv","forks_url":"https://api.github.com/repos/pfnet/chainercv/forks","keys_url":"https://api.github.com/repos/pfnet/chainercv/keys{/key_id}","collaborators_url":"https://api.github.com/repos/pfnet/chainercv/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/pfnet/chainercv/teams","hooks_url":"https://api.github.com/repos/pfnet/chainercv/hooks","issue_events_url":"https://api.github.com/repos/pfnet/chainercv/issues/events{/number}","events_url":"https://api.github.com/repos/pfnet/chainercv/events","assignees_url":"https://api.github.com/repos/pfnet/chainercv/assignees{/user}","branches_url":"https://api.github.com/repos/pfnet/chainercv/branches{/branch}","tags_url":"https://api.github.com/repos/pfnet/chainercv/tags","blobs_url":"https://api.github.com/repos/pfnet/chainercv/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/pfnet/chainercv/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/pfnet/chainercv/git/refs{/sha}","trees_url":"https://api.github.com/repos/pfnet/chainercv/git/trees{/sha}","statuses_url":"https://api.github.com/repos/pfnet/chainercv/statuses/{sha}","languages_url":"https://api.github.com/repos/pfnet/chainercv/languages","stargazers_url":"https://api.github.com/repos/pfnet/chainercv/stargazers","contributors_url":"https://api.github.com/repos/pfnet/chainercv/contributors","subscribers_url":"https://api.github.com/repos/pfnet/chainercv/subscribers","subscription_url":"https://api.github.com/repos/pfnet/chainercv/subscription","commits_url":"https://api.github.com/repos/pfnet/chainercv/commits{/sha}","git_commits_url":"https://api.github.com/repos/pfnet/chainercv/git/commits{/sha}","comments_url":"https://api.github.com/repos/pfnet/chainercv/comments{/number}","issue_comment_url":"https://api.github.com/repos/pfnet/chainercv/issues/comments{/number}","contents_url":"https://api.github.com/repos/pfnet/chainercv/contents/{+path}","compare_url":"https://api.github.com/repos/pfnet/chainercv/compare/{base}...{head}","merges_url":"https://api.github.com/repos/pfnet/chainercv/merges","archive_url":"https://api.github.com/repos/pfnet/chainercv/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/pfnet/chainercv/downloads","issues_url":"https://api.github.com/repos/pfnet/chainercv/issues{/number}","pulls_url":"https://api.github.com/repos/pfnet/chainercv/pulls{/number}","milestones_url":"https://api.github.com/repos/pfnet/chainercv/milestones{/number}","notifications_url":"https://api.github.com/repos/pfnet/chainercv/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/pfnet/chainercv/labels{/name}","releases_url":"https://api.github.com/repos/pfnet/chainercv/releases{/id}","deployments_url":"https://api.github.com/repos/pfnet/chainercv/deployments","created_at":"2017-02-13T04:15:10Z","updated_at":"2017-05-18T05:43:51Z","pushed_at":"2017-05-28T13:53:55Z","git_url":"git://github.com/pfnet/chainercv.git","ssh_url":"git@github.com:pfnet/chainercv.git","clone_url":"https://github.com/pfnet/chainercv.git","svn_url":"https://github.com/pfnet/chainercv","homepage":"","size":1046,"stargazers_count":41,"watchers_count":41,"language":"Python","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":11,"mirror_url":null,"open_issues_count":22,"forks":11,"open_issues":22,"watchers":41,"default_branch":"master"}},"base":{"label":"pfnet:master","ref":"master","sha":"03b30ee0acaac0cb3584b5470959778b037f8f66","user":{"login":"pfnet","id":9739572,"avatar_url":"https://avatars1.githubusercontent.com/u/9739572?v=3","gravatar_id":"","url":"https://api.github.com/users/pfnet","html_url":"https://github.com/pfnet","followers_url":"https://api.github.com/users/pfnet/followers","following_url":"https://api.github.com/users/pfnet/following{/other_user}","gists_url":"https://api.github.com/users/pfnet/gists{/gist_id}","starred_url":"https://api.github.com/users/pfnet/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pfnet/subscriptions","organizations_url":"https://api.github.com/users/pfnet/orgs","repos_url":"https://api.github.com/users/pfnet/repos","events_url":"https://api.github.com/users/pfnet/events{/privacy}","received_events_url":"https://api.github.com/users/pfnet/received_events","type":"Organization","site_admin":false},"repo":{"id":81784084,"name":"chainercv","full_name":"pfnet/chainercv","owner":{"login":"pfnet","id":9739572,"avatar_url":"https://avatars1.githubusercontent.com/u/9739572?v=3","gravatar_id":"","url":"https://api.github.com/users/pfnet","html_url":"https://github.com/pfnet","followers_url":"https://api.github.com/users/pfnet/followers","following_url":"https://api.github.com/users/pfnet/following{/other_user}","gists_url":"https://api.github.com/users/pfnet/gists{/gist_id}","starred_url":"https://api.github.com/users/pfnet/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pfnet/subscriptions","organizations_url":"https://api.github.com/users/pfnet/orgs","repos_url":"https://api.github.com/users/pfnet/repos","events_url":"https://api.github.com/users/pfnet/events{/privacy}","received_events_url":"https://api.github.com/users/pfnet/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/pfnet/chainercv","description":"Set of tools for Computer Vision using Chainer","fork":false,"url":"https://api.github.com/repos/pfnet/chainercv","forks_url":"https://api.github.com/repos/pfnet/chainercv/forks","keys_url":"https://api.github.com/repos/pfnet/chainercv/keys{/key_id}","collaborators_url":"https://api.github.com/repos/pfnet/chainercv/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/pfnet/chainercv/teams","hooks_url":"https://api.github.com/repos/pfnet/chainercv/hooks","issue_events_url":"https://api.github.com/repos/pfnet/chainercv/issues/events{/number}","events_url":"https://api.github.com/repos/pfnet/chainercv/events","assignees_url":"https://api.github.com/repos/pfnet/chainercv/assignees{/user}","branches_url":"https://api.github.com/repos/pfnet/chainercv/branches{/branch}","tags_url":"https://api.github.com/repos/pfnet/chainercv/tags","blobs_url":"https://api.github.com/repos/pfnet/chainercv/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/pfnet/chainercv/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/pfnet/chainercv/git/refs{/sha}","trees_url":"https://api.github.com/repos/pfnet/chainercv/git/trees{/sha}","statuses_url":"https://api.github.com/repos/pfnet/chainercv/statuses/{sha}","languages_url":"https://api.github.com/repos/pfnet/chainercv/languages","stargazers_url":"https://api.github.com/repos/pfnet/chainercv/stargazers","contributors_url":"https://api.github.com/repos/pfnet/chainercv/contributors","subscribers_url":"https://api.github.com/repos/pfnet/chainercv/subscribers","subscription_url":"https://api.github.com/repos/pfnet/chainercv/subscription","commits_url":"https://api.github.com/repos/pfnet/chainercv/commits{/sha}","git_commits_url":"https://api.github.com/repos/pfnet/chainercv/git/commits{/sha}","comments_url":"https://api.github.com/repos/pfnet/chainercv/comments{/number}","issue_comment_url":"https://api.github.com/repos/pfnet/chainercv/issues/comments{/number}","contents_url":"https://api.github.com/repos/pfnet/chainercv/contents/{+path}","compare_url":"https://api.github.com/repos/pfnet/chainercv/compare/{base}...{head}","merges_url":"https://api.github.com/repos/pfnet/chainercv/merges","archive_url":"https://api.github.com/repos/pfnet/chainercv/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/pfnet/chainercv/downloads","issues_url":"https://api.github.com/repos/pfnet/chainercv/issues{/number}","pulls_url":"https://api.github.com/repos/pfnet/chainercv/pulls{/number}","milestones_url":"https://api.github.com/repos/pfnet/chainercv/milestones{/number}","notifications_url":"https://api.github.com/repos/pfnet/chainercv/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/pfnet/chainercv/labels{/name}","releases_url":"https://api.github.com/repos/pfnet/chainercv/releases{/id}","deployments_url":"https://api.github.com/repos/pfnet/chainercv/deployments","created_at":"2017-02-13T04:15:10Z","updated_at":"2017-05-18T05:43:51Z","pushed_at":"2017-05-28T13:53:55Z","git_url":"git://github.com/pfnet/chainercv.git","ssh_url":"git@github.com:pfnet/chainercv.git","clone_url":"https://github.com/pfnet/chainercv.git","svn_url":"https://github.com/pfnet/chainercv","homepage":"","size":1046,"stargazers_count":41,"watchers_count":41,"language":"Python","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":11,"mirror_url":null,"open_issues_count":22,"forks":11,"open_issues":22,"watchers":41,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/pfnet/chainercv/pulls/161"},"html":{"href":"https://github.com/pfnet/chainercv/pull/161"},"issue":{"href":"https://api.github.com/repos/pfnet/chainercv/issues/161"},"comments":{"href":"https://api.github.com/repos/pfnet/chainercv/issues/161/comments"},"review_comments":{"href":"https://api.github.com/repos/pfnet/chainercv/pulls/161/comments"},"review_comment":{"href":"https://api.github.com/repos/pfnet/chainercv/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/pfnet/chainercv/pulls/161/commits"},"statuses":{"href":"https://api.github.com/repos/pfnet/chainercv/statuses/a6495835dcbc5f0719ad74b406464aa6c12f87eb"}}}}
{"actor":{"display_login":"Hakuyume"}}