{"action":"created","comment":{"url":"https://api.github.com/repos/pfnet/chainer/pulls/comments/58357945","id":58357945,"diff_hunk":"@@ -0,0 +1,335 @@\n+# Modified work:\n+# -----------------------------------------------------------------------------\n+# Copyright (c) 2015 Preferred Infrastructure, Inc.\n+# Copyright (c) 2015 Preferred Networks, Inc.\n+# -----------------------------------------------------------------------------\n+\n+# Original work of _roi_pooling_slice, forward_cpu and backward_cpu:\n+# -----------------------------------------------------------------------------\n+# Copyright 2014 Nervana Systems Inc.\n+# Licensed under the Apache License, Version 2.0 (the \"License\");\n+# you may not use this file except in compliance with the License.\n+# You may obtain a copy of the License at\n+#\n+#      http://www.apache.org/licenses/LICENSE-2.0\n+#\n+# Unless required by applicable law or agreed to in writing, software\n+# distributed under the License is distributed on an \"AS IS\" BASIS,\n+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n+# See the License for the specific language governing permissions and\n+# limitations under the License.\n+# -----------------------------------------------------------------------------\n+\n+# Original work of forward_gpu and backward_gpu:\n+# -----------------------------------------------------------------------------\n+# Fast R-CNN\n+# Copyright (c) 2015 Microsoft\n+# Licensed under The MIT License [see fast-rcnn/LICENSE for details]\n+# Written by Ross Girshick\n+# -----------------------------------------------------------------------------\n+\n+import numpy\n+import six\n+\n+from chainer import cuda\n+from chainer import function\n+from chainer.utils import type_check\n+\n+\n+def _roi_pooling_slice(size, stride, max_size, roi_offset):\n+    start = int(numpy.floor(size * stride))\n+    end = int(numpy.ceil((size + 1) * stride))\n+\n+    start = min(max(start + roi_offset, 0), max_size)\n+    end = min(max(end + roi_offset, 0), max_size)\n+\n+    return slice(start, end), end - start\n+\n+\n+class ROIPooling2D(function.Function):\n+\n+    \"\"\"RoI pooling over a set of 2d planes.\"\"\"\n+\n+    def __init__(self, outh, outw, spatial_scale):\n+        self.outh, self.outw = outh, outw\n+        self.spatial_scale = spatial_scale\n+\n+    def check_type_forward(self, in_types):\n+        type_check.expect(in_types.size() == 2)\n+\n+        x_type, roi_type = in_types\n+        type_check.expect(\n+            x_type.shape[0] == roi_type.shape[0],\n+            x_type.dtype == numpy.float32,\n+            x_type.ndim == 4,\n+            roi_type.dtype == numpy.float32,\n+            roi_type.ndim == 2,\n+            roi_type.shape[1] == 5,\n+        )\n+\n+    def forward_cpu(self, inputs):\n+        bottom_data, bottom_rois = inputs\n+        n_rois, channels, height, width = bottom_data.shape\n+        top_data = numpy.empty((n_rois, channels, self.outh, self.outw),\n+                               dtype=numpy.float32)\n+        self.argmax_data = numpy.empty_like(top_data).astype(numpy.int32)\n+\n+        for i_roi in six.moves.range(n_rois):\n+            idx, xmin, ymin, xmax, ymax = bottom_rois[i_roi]\n+            xmin = int(round(xmin * self.spatial_scale))\n+            xmax = int(round(xmax * self.spatial_scale))\n+            ymin = int(round(ymin * self.spatial_scale))\n+            ymax = int(round(ymax * self.spatial_scale))\n+            roi_width = max(xmax - xmin + 1, 1)\n+            roi_height = max(ymax - ymin + 1, 1)\n+            strideh = 1. * roi_height / self.outh\n+            stridew = 1. * roi_width / self.outw\n+\n+            for outh in six.moves.range(self.outh):\n+                sliceh, lenh = _roi_pooling_slice(\n+                    outh, strideh, height, ymin)\n+                if sliceh.stop <= sliceh.start:\n+                    continue\n+                for outw in six.moves.range(self.outw):\n+                    slicew, lenw = _roi_pooling_slice(\n+                        outw, stridew, width, xmin)\n+                    if slicew.stop <= slicew.start:","path":"chainer/functions/pooling/roi_pooling_2d.py","position":96,"original_position":96,"commit_id":"86aea41afb8c5b8cd32eaa5f69520b8fb6f1ed64","original_commit_id":"86aea41afb8c5b8cd32eaa5f69520b8fb6f1ed64","user":{"login":"unnonouno","id":740680,"avatar_url":"https://avatars.githubusercontent.com/u/740680?v=3","gravatar_id":"","url":"https://api.github.com/users/unnonouno","html_url":"https://github.com/unnonouno","followers_url":"https://api.github.com/users/unnonouno/followers","following_url":"https://api.github.com/users/unnonouno/following{/other_user}","gists_url":"https://api.github.com/users/unnonouno/gists{/gist_id}","starred_url":"https://api.github.com/users/unnonouno/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/unnonouno/subscriptions","organizations_url":"https://api.github.com/users/unnonouno/orgs","repos_url":"https://api.github.com/users/unnonouno/repos","events_url":"https://api.github.com/users/unnonouno/events{/privacy}","received_events_url":"https://api.github.com/users/unnonouno/received_events","type":"User","site_admin":false},"body":"Do you need to set `argmax_data` in this situation?","created_at":"2016-04-04T10:50:06Z","updated_at":"2016-04-04T10:50:06Z","html_url":"https://github.com/pfnet/chainer/pull/939#discussion_r58357945","pull_request_url":"https://api.github.com/repos/pfnet/chainer/pulls/939","_links":{"self":{"href":"https://api.github.com/repos/pfnet/chainer/pulls/comments/58357945"},"html":{"href":"https://github.com/pfnet/chainer/pull/939#discussion_r58357945"},"pull_request":{"href":"https://api.github.com/repos/pfnet/chainer/pulls/939"}}},"pull_request":{"url":"https://api.github.com/repos/pfnet/chainer/pulls/939","id":59039470,"html_url":"https://github.com/pfnet/chainer/pull/939","diff_url":"https://github.com/pfnet/chainer/pull/939.diff","patch_url":"https://github.com/pfnet/chainer/pull/939.patch","issue_url":"https://api.github.com/repos/pfnet/chainer/issues/939","number":939,"state":"open","locked":false,"title":"Add ROIPooling2D function","user":{"login":"wkentaro","id":4310419,"avatar_url":"https://avatars.githubusercontent.com/u/4310419?v=3","gravatar_id":"","url":"https://api.github.com/users/wkentaro","html_url":"https://github.com/wkentaro","followers_url":"https://api.github.com/users/wkentaro/followers","following_url":"https://api.github.com/users/wkentaro/following{/other_user}","gists_url":"https://api.github.com/users/wkentaro/gists{/gist_id}","starred_url":"https://api.github.com/users/wkentaro/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/wkentaro/subscriptions","organizations_url":"https://api.github.com/users/wkentaro/orgs","repos_url":"https://api.github.com/users/wkentaro/repos","events_url":"https://api.github.com/users/wkentaro/events{/privacy}","received_events_url":"https://api.github.com/users/wkentaro/received_events","type":"User","site_admin":false},"body":"- [x] CPU forward/backward\n- [x] GPU forward/backward\n- [x] Test for CPU/GPU","created_at":"2016-02-11T14:41:46Z","updated_at":"2016-04-04T10:50:06Z","closed_at":null,"merged_at":null,"merge_commit_sha":"f963c19eef4190072854f7a5ca0b6bc80c3b8077","assignee":{"login":"unnonouno","id":740680,"avatar_url":"https://avatars.githubusercontent.com/u/740680?v=3","gravatar_id":"","url":"https://api.github.com/users/unnonouno","html_url":"https://github.com/unnonouno","followers_url":"https://api.github.com/users/unnonouno/followers","following_url":"https://api.github.com/users/unnonouno/following{/other_user}","gists_url":"https://api.github.com/users/unnonouno/gists{/gist_id}","starred_url":"https://api.github.com/users/unnonouno/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/unnonouno/subscriptions","organizations_url":"https://api.github.com/users/unnonouno/orgs","repos_url":"https://api.github.com/users/unnonouno/repos","events_url":"https://api.github.com/users/unnonouno/events{/privacy}","received_events_url":"https://api.github.com/users/unnonouno/received_events","type":"User","site_admin":false},"milestone":null,"commits_url":"https://api.github.com/repos/pfnet/chainer/pulls/939/commits","review_comments_url":"https://api.github.com/repos/pfnet/chainer/pulls/939/comments","review_comment_url":"https://api.github.com/repos/pfnet/chainer/pulls/comments{/number}","comments_url":"https://api.github.com/repos/pfnet/chainer/issues/939/comments","statuses_url":"https://api.github.com/repos/pfnet/chainer/statuses/86aea41afb8c5b8cd32eaa5f69520b8fb6f1ed64","head":{"label":"wkentaro:roi-pooling-2d","ref":"roi-pooling-2d","sha":"86aea41afb8c5b8cd32eaa5f69520b8fb6f1ed64","user":{"login":"wkentaro","id":4310419,"avatar_url":"https://avatars.githubusercontent.com/u/4310419?v=3","gravatar_id":"","url":"https://api.github.com/users/wkentaro","html_url":"https://github.com/wkentaro","followers_url":"https://api.github.com/users/wkentaro/followers","following_url":"https://api.github.com/users/wkentaro/following{/other_user}","gists_url":"https://api.github.com/users/wkentaro/gists{/gist_id}","starred_url":"https://api.github.com/users/wkentaro/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/wkentaro/subscriptions","organizations_url":"https://api.github.com/users/wkentaro/orgs","repos_url":"https://api.github.com/users/wkentaro/repos","events_url":"https://api.github.com/users/wkentaro/events{/privacy}","received_events_url":"https://api.github.com/users/wkentaro/received_events","type":"User","site_admin":false},"repo":{"id":45491173,"name":"chainer","full_name":"wkentaro/chainer","owner":{"login":"wkentaro","id":4310419,"avatar_url":"https://avatars.githubusercontent.com/u/4310419?v=3","gravatar_id":"","url":"https://api.github.com/users/wkentaro","html_url":"https://github.com/wkentaro","followers_url":"https://api.github.com/users/wkentaro/followers","following_url":"https://api.github.com/users/wkentaro/following{/other_user}","gists_url":"https://api.github.com/users/wkentaro/gists{/gist_id}","starred_url":"https://api.github.com/users/wkentaro/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/wkentaro/subscriptions","organizations_url":"https://api.github.com/users/wkentaro/orgs","repos_url":"https://api.github.com/users/wkentaro/repos","events_url":"https://api.github.com/users/wkentaro/events{/privacy}","received_events_url":"https://api.github.com/users/wkentaro/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/wkentaro/chainer","description":"A flexible framework of neural networks for deep learning","fork":true,"url":"https://api.github.com/repos/wkentaro/chainer","forks_url":"https://api.github.com/repos/wkentaro/chainer/forks","keys_url":"https://api.github.com/repos/wkentaro/chainer/keys{/key_id}","collaborators_url":"https://api.github.com/repos/wkentaro/chainer/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/wkentaro/chainer/teams","hooks_url":"https://api.github.com/repos/wkentaro/chainer/hooks","issue_events_url":"https://api.github.com/repos/wkentaro/chainer/issues/events{/number}","events_url":"https://api.github.com/repos/wkentaro/chainer/events","assignees_url":"https://api.github.com/repos/wkentaro/chainer/assignees{/user}","branches_url":"https://api.github.com/repos/wkentaro/chainer/branches{/branch}","tags_url":"https://api.github.com/repos/wkentaro/chainer/tags","blobs_url":"https://api.github.com/repos/wkentaro/chainer/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/wkentaro/chainer/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/wkentaro/chainer/git/refs{/sha}","trees_url":"https://api.github.com/repos/wkentaro/chainer/git/trees{/sha}","statuses_url":"https://api.github.com/repos/wkentaro/chainer/statuses/{sha}","languages_url":"https://api.github.com/repos/wkentaro/chainer/languages","stargazers_url":"https://api.github.com/repos/wkentaro/chainer/stargazers","contributors_url":"https://api.github.com/repos/wkentaro/chainer/contributors","subscribers_url":"https://api.github.com/repos/wkentaro/chainer/subscribers","subscription_url":"https://api.github.com/repos/wkentaro/chainer/subscription","commits_url":"https://api.github.com/repos/wkentaro/chainer/commits{/sha}","git_commits_url":"https://api.github.com/repos/wkentaro/chainer/git/commits{/sha}","comments_url":"https://api.github.com/repos/wkentaro/chainer/comments{/number}","issue_comment_url":"https://api.github.com/repos/wkentaro/chainer/issues/comments{/number}","contents_url":"https://api.github.com/repos/wkentaro/chainer/contents/{+path}","compare_url":"https://api.github.com/repos/wkentaro/chainer/compare/{base}...{head}","merges_url":"https://api.github.com/repos/wkentaro/chainer/merges","archive_url":"https://api.github.com/repos/wkentaro/chainer/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/wkentaro/chainer/downloads","issues_url":"https://api.github.com/repos/wkentaro/chainer/issues{/number}","pulls_url":"https://api.github.com/repos/wkentaro/chainer/pulls{/number}","milestones_url":"https://api.github.com/repos/wkentaro/chainer/milestones{/number}","notifications_url":"https://api.github.com/repos/wkentaro/chainer/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/wkentaro/chainer/labels{/name}","releases_url":"https://api.github.com/repos/wkentaro/chainer/releases{/id}","deployments_url":"https://api.github.com/repos/wkentaro/chainer/deployments","created_at":"2015-11-03T19:43:33Z","updated_at":"2016-02-08T04:07:04Z","pushed_at":"2016-03-22T11:17:35Z","git_url":"git://github.com/wkentaro/chainer.git","ssh_url":"git@github.com:wkentaro/chainer.git","clone_url":"https://github.com/wkentaro/chainer.git","svn_url":"https://github.com/wkentaro/chainer","homepage":"http://chainer.org","size":5297,"stargazers_count":1,"watchers_count":1,"language":"Python","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":1,"default_branch":"master"}},"base":{"label":"pfnet:master","ref":"master","sha":"0d3dc6dfc48e5591aaeb599108daa77bcddbc9f4","user":{"login":"pfnet","id":9739572,"avatar_url":"https://avatars.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":36914478,"name":"chainer","full_name":"pfnet/chainer","owner":{"login":"pfnet","id":9739572,"avatar_url":"https://avatars.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/chainer","description":"A flexible framework of neural networks for deep learning","fork":false,"url":"https://api.github.com/repos/pfnet/chainer","forks_url":"https://api.github.com/repos/pfnet/chainer/forks","keys_url":"https://api.github.com/repos/pfnet/chainer/keys{/key_id}","collaborators_url":"https://api.github.com/repos/pfnet/chainer/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/pfnet/chainer/teams","hooks_url":"https://api.github.com/repos/pfnet/chainer/hooks","issue_events_url":"https://api.github.com/repos/pfnet/chainer/issues/events{/number}","events_url":"https://api.github.com/repos/pfnet/chainer/events","assignees_url":"https://api.github.com/repos/pfnet/chainer/assignees{/user}","branches_url":"https://api.github.com/repos/pfnet/chainer/branches{/branch}","tags_url":"https://api.github.com/repos/pfnet/chainer/tags","blobs_url":"https://api.github.com/repos/pfnet/chainer/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/pfnet/chainer/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/pfnet/chainer/git/refs{/sha}","trees_url":"https://api.github.com/repos/pfnet/chainer/git/trees{/sha}","statuses_url":"https://api.github.com/repos/pfnet/chainer/statuses/{sha}","languages_url":"https://api.github.com/repos/pfnet/chainer/languages","stargazers_url":"https://api.github.com/repos/pfnet/chainer/stargazers","contributors_url":"https://api.github.com/repos/pfnet/chainer/contributors","subscribers_url":"https://api.github.com/repos/pfnet/chainer/subscribers","subscription_url":"https://api.github.com/repos/pfnet/chainer/subscription","commits_url":"https://api.github.com/repos/pfnet/chainer/commits{/sha}","git_commits_url":"https://api.github.com/repos/pfnet/chainer/git/commits{/sha}","comments_url":"https://api.github.com/repos/pfnet/chainer/comments{/number}","issue_comment_url":"https://api.github.com/repos/pfnet/chainer/issues/comments{/number}","contents_url":"https://api.github.com/repos/pfnet/chainer/contents/{+path}","compare_url":"https://api.github.com/repos/pfnet/chainer/compare/{base}...{head}","merges_url":"https://api.github.com/repos/pfnet/chainer/merges","archive_url":"https://api.github.com/repos/pfnet/chainer/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/pfnet/chainer/downloads","issues_url":"https://api.github.com/repos/pfnet/chainer/issues{/number}","pulls_url":"https://api.github.com/repos/pfnet/chainer/pulls{/number}","milestones_url":"https://api.github.com/repos/pfnet/chainer/milestones{/number}","notifications_url":"https://api.github.com/repos/pfnet/chainer/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/pfnet/chainer/labels{/name}","releases_url":"https://api.github.com/repos/pfnet/chainer/releases{/id}","deployments_url":"https://api.github.com/repos/pfnet/chainer/deployments","created_at":"2015-06-05T05:50:37Z","updated_at":"2016-04-04T07:21:44Z","pushed_at":"2016-04-03T06:22:50Z","git_url":"git://github.com/pfnet/chainer.git","ssh_url":"git@github.com:pfnet/chainer.git","clone_url":"https://github.com/pfnet/chainer.git","svn_url":"https://github.com/pfnet/chainer","homepage":"http://chainer.org","size":16267,"stargazers_count":1275,"watchers_count":1275,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":255,"mirror_url":null,"open_issues_count":125,"forks":255,"open_issues":125,"watchers":1275,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/pfnet/chainer/pulls/939"},"html":{"href":"https://github.com/pfnet/chainer/pull/939"},"issue":{"href":"https://api.github.com/repos/pfnet/chainer/issues/939"},"comments":{"href":"https://api.github.com/repos/pfnet/chainer/issues/939/comments"},"review_comments":{"href":"https://api.github.com/repos/pfnet/chainer/pulls/939/comments"},"review_comment":{"href":"https://api.github.com/repos/pfnet/chainer/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/pfnet/chainer/pulls/939/commits"},"statuses":{"href":"https://api.github.com/repos/pfnet/chainer/statuses/86aea41afb8c5b8cd32eaa5f69520b8fb6f1ed64"}}}}