GitHub PullRequestReviewCommentEvent at 2014-12-01 19:24:19
Repository: caffe
Actor: shelhamer
Payload: {"action":"created","comment":{"url":"https://api.github.com/repos/BVLC/caffe/pulls/comments/21112577","id":21112577,"diff_hunk":"@@ -0,0 +1,128 @@\n+#include <algorithm>\n+#include <vector>\n+\n+#include \"caffe/layer.hpp\"\n+#include \"caffe/util/math_functions.hpp\"\n+#include \"caffe/vision_layers.hpp\"\n+\n+namespace caffe {\n+\n+template <typename Dtype>\n+void FilterLayer<Dtype>::LayerSetUp(const vector<Blob<Dtype>*>& bottom,\n+      const vector<Blob<Dtype>*>& top) {\n+  CHECK_EQ(top.size(), bottom.size()-1) <<\n+      \"Top.size() should be equal to bottom.size() - 1\";\n+  const FilterParameter& filter_param = this->layer_param_.filter_param();\n+  first_reshape_ = true;\n+  need_back_prop_.clear();\n+  std::copy(filter_param.need_back_prop().begin(),\n+      filter_param.need_back_prop().end(),\n+      std::back_inserter(need_back_prop_));\n+  CHECK_NE(0, need_back_prop_.size()) <<\n+      \"need_back_prop param needs to be specified\";\n+  CHECK_EQ(top.size(), need_back_prop_.size()) <<\n+      \"need_back_prop.size() needs to be equal to top.size()\";\n+}\n+\n+template <typename Dtype>\n+void FilterLayer<Dtype>::Reshape(const vector<Blob<Dtype>*>& bottom,\n+      const vector<Blob<Dtype>*>& top) {\n+  // bottom[0] is the \"SELECTOR_blob\"\n+  // bottom[1+] are the blobs to filter\n+  CHECK_EQ(bottom[0]->channels(), 1) <<\n+        \"Selector blob (bottom[0]) must have channels == 1\";\n+  CHECK_EQ(bottom[0]->width(), 1) <<\n+        \"Selector blob (bottom[0]) must have width == 1\";\n+  CHECK_EQ(bottom[0]->height(), 1) <<\n+        \"Selector blob (bottom[0]) must have height == 1\";\n+  int num_items = bottom[0]->num();\n+  for (int i = 1; i < bottom.size(); i++) {\n+    CHECK_EQ(num_items, bottom[i]->num()) <<\n+        \"Each bottom should have the same dimension as bottom[0]\";\n+  }\n+\n+  const Dtype* bottom_data_SELECTOR = bottom[0]->cpu_data();\n+  indices_to_forward_.clear();\n+\n+  // look for non-zero elements in bottom[0]. Items of each bottom that\n+  // have the same index as the items in bottom[0] with value == non-zero\n+  // will be forwarded\n+  for (size_t item_id = 0; item_id < num_items; ++item_id) {\n+    // we don't need an offset because item size == 1\n+    const Dtype* tmp_data_SELECTOR = bottom_data_SELECTOR + item_id;\n+    if (*tmp_data_SELECTOR != 0) {\n+      indices_to_forward_.push_back(item_id);\n+    }\n+  }\n+\n+  // only filtered items will be forwarded\n+  int new_tops_num = indices_to_forward_.size();\n+  // init\n+  if (first_reshape_) {\n+    new_tops_num = bottom[1]->num();\n+    first_reshape_ = false;\n+  }\n+\n+  for (size_t t = 0; t < top.size(); t++) {\n+    top[t]->Reshape(new_tops_num,\n+        bottom[t+1]->channels(),\n+        bottom[t+1]->height(),\n+        bottom[t+1]->width());\n+  }\n+}\n+\n+template <typename Dtype>\n+void FilterLayer<Dtype>::Forward_cpu(const vector<Blob<Dtype>*>& bottom,\n+      const vector<Blob<Dtype>*>& top) {\n+  int new_tops_num = indices_to_forward_.size();\n+  // forward all filtered items for all bottoms but the Selector (bottom[0])\n+  for (size_t b = 1; b < bottom.size(); b++) {\n+    const Dtype* bottom_data = bottom[b]->cpu_data();\n+    Dtype* top_data = top[b-1]->mutable_cpu_data();\n+    size_t dim = bottom[b]->count()/bottom[b]->num();","path":"src/caffe/layers/filter_layer.cpp","position":null,"original_position":82,"commit_id":"78a376eea2599cc67595b1f27e949e4938b4b8c1","original_commit_id":"0340047956600f5b7551072469f648b559a0a05c","user":{"login":"shelhamer","id":311113,"avatar_url":"https://avatars.githubusercontent.com/u/311113?v=3","gravatar_id":"","url":"https://api.github.com/users/shelhamer","html_url":"https://github.com/shelhamer","followers_url":"https://api.github.com/users/shelhamer/followers","following_url":"https://api.github.com/users/shelhamer/following{/other_user}","gists_url":"https://api.github.com/users/shelhamer/gists{/gist_id}","starred_url":"https://api.github.com/users/shelhamer/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/shelhamer/subscriptions","organizations_url":"https://api.github.com/users/shelhamer/orgs","repos_url":"https://api.github.com/users/shelhamer/repos","events_url":"https://api.github.com/users/shelhamer/events{/privacy}","received_events_url":"https://api.github.com/users/shelhamer/received_events","type":"User","site_admin":false},"body":"The @jeffdonahue is our master of lint -- could you add a rule for the\r\nstyle @longjon cited?\r\nOn Mon, Dec 1, 2014 at 06:56 Manuele <notifications@github.com> wrote:\r\n\r\n> In src/caffe/layers/filter_layer.cpp:\r\n>\r\n> > +    top[t]->Reshape(new_tops_num,\r\n> > +        bottom[t+1]->channels(),\r\n> > +        bottom[t+1]->height(),\r\n> > +        bottom[t+1]->width());\r\n> > +  }\r\n> > +}\r\n> > +\r\n> > +template <typename Dtype>\r\n> > +void FilterLayer<Dtype>::Forward_cpu(const vector<Blob<Dtype>*>& bottom,\r\n> > +      const vector<Blob<Dtype>*>& top) {\r\n> > +  int new_tops_num = indices_to_forward_.size();\r\n> > +  // forward all filtered items for all bottoms but the Selector (bottom[0])\r\n> > +  for (size_t b = 1; b < bottom.size(); b++) {\r\n> > +    const Dtype* bottom_data = bottom[b]->cpu_data();\r\n> > +    Dtype* top_data = top[b-1]->mutable_cpu_data();\r\n> > +    size_t dim = bottom[b]->count()/bottom[b]->num();\r\n>\r\n> Ok, I'll try to find them out without lint ;)\r\n>\r\n> —\r\n> Reply to this email directly or view it on GitHub\r\n> <https://github.com/BVLC/caffe/pull/1482/files#r21084409>.\r\n>","created_at":"2014-12-01T19:24:19Z","updated_at":"2014-12-01T19:24:19Z","html_url":"https://github.com/BVLC/caffe/pull/1482#discussion_r21112577","pull_request_url":"https://api.github.com/repos/BVLC/caffe/pulls/1482","_links":{"self":{"href":"https://api.github.com/repos/BVLC/caffe/pulls/comments/21112577"},"html":{"href":"https://github.com/BVLC/caffe/pull/1482#discussion_r21112577"},"pull_request":{"href":"https://api.github.com/repos/BVLC/caffe/pulls/1482"}}},"pull_request":{"url":"https://api.github.com/repos/BVLC/caffe/pulls/1482","id":25105703,"html_url":"https://github.com/BVLC/caffe/pull/1482","diff_url":"https://github.com/BVLC/caffe/pull/1482.diff","patch_url":"https://github.com/BVLC/caffe/pull/1482.patch","issue_url":"https://api.github.com/repos/BVLC/caffe/issues/1482","number":1482,"state":"open","locked":false,"title":"Filter layer","user":{"login":"mtamburrano","id":1943264,"avatar_url":"https://avatars.githubusercontent.com/u/1943264?v=3","gravatar_id":"","url":"https://api.github.com/users/mtamburrano","html_url":"https://github.com/mtamburrano","followers_url":"https://api.github.com/users/mtamburrano/followers","following_url":"https://api.github.com/users/mtamburrano/following{/other_user}","gists_url":"https://api.github.com/users/mtamburrano/gists{/gist_id}","starred_url":"https://api.github.com/users/mtamburrano/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mtamburrano/subscriptions","organizations_url":"https://api.github.com/users/mtamburrano/orgs","repos_url":"https://api.github.com/users/mtamburrano/repos","events_url":"https://api.github.com/users/mtamburrano/events{/privacy}","received_events_url":"https://api.github.com/users/mtamburrano/received_events","type":"User","site_admin":false},"body":"Filter_layer developed as discussed in #1448, implemented following the suggestions by @sguada and @longjon (paragraph 2(i)).\r\n\r\nThis layer accepts 2+ bottom blobs, the first blob acts as a selector, so it should be a vector s={0,1,2, .. n} in [0,1], and the remaining blobs are blobs to be filtered. Each value of 1 in the selector vector means that the items at the corresponding indices int the bottom_blobs[1+] will be kept, on the contrary a values of 0 means the items with corresponding symbols will be filtered out.\r\nSo only non-filtered items will be forwarded and afterwards will receive backpropagation. \r\n\r\nAs param the filter_layer needs a *need_back_prop vector*. This is needed because some blob could contains labels, and therefore will not need backpropagation. The need_back_prop vector as the same size as the top vector, and accepts 1s and 0s depending on whether it should be backpropagated or not.\r\n\r\nThis PR needs #1483 and #1484","created_at":"2014-11-26T18:44:48Z","updated_at":"2014-12-01T19:24:19Z","closed_at":null,"merged_at":null,"merge_commit_sha":"880559e3226d2912b350c2d5a8e108dcbf6a1a40","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/BVLC/caffe/pulls/1482/commits","review_comments_url":"https://api.github.com/repos/BVLC/caffe/pulls/1482/comments","review_comment_url":"https://api.github.com/repos/BVLC/caffe/pulls/comments/{number}","comments_url":"https://api.github.com/repos/BVLC/caffe/issues/1482/comments","statuses_url":"https://api.github.com/repos/BVLC/caffe/statuses/78a376eea2599cc67595b1f27e949e4938b4b8c1","head":{"label":"mtamburrano:filter_layer","ref":"filter_layer","sha":"78a376eea2599cc67595b1f27e949e4938b4b8c1","user":{"login":"mtamburrano","id":1943264,"avatar_url":"https://avatars.githubusercontent.com/u/1943264?v=3","gravatar_id":"","url":"https://api.github.com/users/mtamburrano","html_url":"https://github.com/mtamburrano","followers_url":"https://api.github.com/users/mtamburrano/followers","following_url":"https://api.github.com/users/mtamburrano/following{/other_user}","gists_url":"https://api.github.com/users/mtamburrano/gists{/gist_id}","starred_url":"https://api.github.com/users/mtamburrano/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mtamburrano/subscriptions","organizations_url":"https://api.github.com/users/mtamburrano/orgs","repos_url":"https://api.github.com/users/mtamburrano/repos","events_url":"https://api.github.com/users/mtamburrano/events{/privacy}","received_events_url":"https://api.github.com/users/mtamburrano/received_events","type":"User","site_admin":false},"repo":{"id":26318920,"name":"caffe","full_name":"mtamburrano/caffe","owner":{"login":"mtamburrano","id":1943264,"avatar_url":"https://avatars.githubusercontent.com/u/1943264?v=3","gravatar_id":"","url":"https://api.github.com/users/mtamburrano","html_url":"https://github.com/mtamburrano","followers_url":"https://api.github.com/users/mtamburrano/followers","following_url":"https://api.github.com/users/mtamburrano/following{/other_user}","gists_url":"https://api.github.com/users/mtamburrano/gists{/gist_id}","starred_url":"https://api.github.com/users/mtamburrano/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mtamburrano/subscriptions","organizations_url":"https://api.github.com/users/mtamburrano/orgs","repos_url":"https://api.github.com/users/mtamburrano/repos","events_url":"https://api.github.com/users/mtamburrano/events{/privacy}","received_events_url":"https://api.github.com/users/mtamburrano/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/mtamburrano/caffe","description":"Caffe: a fast framework for deep learning. For the most recent version checkout the dev branch. For the latest stable release checkout the master branch.","fork":true,"url":"https://api.github.com/repos/mtamburrano/caffe","forks_url":"https://api.github.com/repos/mtamburrano/caffe/forks","keys_url":"https://api.github.com/repos/mtamburrano/caffe/keys{/key_id}","collaborators_url":"https://api.github.com/repos/mtamburrano/caffe/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/mtamburrano/caffe/teams","hooks_url":"https://api.github.com/repos/mtamburrano/caffe/hooks","issue_events_url":"https://api.github.com/repos/mtamburrano/caffe/issues/events{/number}","events_url":"https://api.github.com/repos/mtamburrano/caffe/events","assignees_url":"https://api.github.com/repos/mtamburrano/caffe/assignees{/user}","branches_url":"https://api.github.com/repos/mtamburrano/caffe/branches{/branch}","tags_url":"https://api.github.com/repos/mtamburrano/caffe/tags","blobs_url":"https://api.github.com/repos/mtamburrano/caffe/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/mtamburrano/caffe/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/mtamburrano/caffe/git/refs{/sha}","trees_url":"https://api.github.com/repos/mtamburrano/caffe/git/trees{/sha}","statuses_url":"https://api.github.com/repos/mtamburrano/caffe/statuses/{sha}","languages_url":"https://api.github.com/repos/mtamburrano/caffe/languages","stargazers_url":"https://api.github.com/repos/mtamburrano/caffe/stargazers","contributors_url":"https://api.github.com/repos/mtamburrano/caffe/contributors","subscribers_url":"https://api.github.com/repos/mtamburrano/caffe/subscribers","subscription_url":"https://api.github.com/repos/mtamburrano/caffe/subscription","commits_url":"https://api.github.com/repos/mtamburrano/caffe/commits{/sha}","git_commits_url":"https://api.github.com/repos/mtamburrano/caffe/git/commits{/sha}","comments_url":"https://api.github.com/repos/mtamburrano/caffe/comments{/number}","issue_comment_url":"https://api.github.com/repos/mtamburrano/caffe/issues/comments/{number}","contents_url":"https://api.github.com/repos/mtamburrano/caffe/contents/{+path}","compare_url":"https://api.github.com/repos/mtamburrano/caffe/compare/{base}...{head}","merges_url":"https://api.github.com/repos/mtamburrano/caffe/merges","archive_url":"https://api.github.com/repos/mtamburrano/caffe/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/mtamburrano/caffe/downloads","issues_url":"https://api.github.com/repos/mtamburrano/caffe/issues{/number}","pulls_url":"https://api.github.com/repos/mtamburrano/caffe/pulls{/number}","milestones_url":"https://api.github.com/repos/mtamburrano/caffe/milestones{/number}","notifications_url":"https://api.github.com/repos/mtamburrano/caffe/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/mtamburrano/caffe/labels{/name}","releases_url":"https://api.github.com/repos/mtamburrano/caffe/releases{/id}","created_at":"2014-11-07T12:30:42Z","updated_at":"2014-11-27T09:13:47Z","pushed_at":"2014-12-01T18:05:35Z","git_url":"git://github.com/mtamburrano/caffe.git","ssh_url":"git@github.com:mtamburrano/caffe.git","clone_url":"https://github.com/mtamburrano/caffe.git","svn_url":"https://github.com/mtamburrano/caffe","homepage":"http://caffe.berkeleyvision.org/","size":29967,"stargazers_count":1,"watchers_count":1,"language":null,"has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":1,"mirror_url":null,"open_issues_count":0,"forks":1,"open_issues":0,"watchers":1,"default_branch":"master"}},"base":{"label":"BVLC:dev","ref":"dev","sha":"a35929f28dd5c0acf6d9eddc579d4ed3c7f7dc7a","user":{"login":"BVLC","id":6182163,"avatar_url":"https://avatars.githubusercontent.com/u/6182163?v=3","gravatar_id":"","url":"https://api.github.com/users/BVLC","html_url":"https://github.com/BVLC","followers_url":"https://api.github.com/users/BVLC/followers","following_url":"https://api.github.com/users/BVLC/following{/other_user}","gists_url":"https://api.github.com/users/BVLC/gists{/gist_id}","starred_url":"https://api.github.com/users/BVLC/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/BVLC/subscriptions","organizations_url":"https://api.github.com/users/BVLC/orgs","repos_url":"https://api.github.com/users/BVLC/repos","events_url":"https://api.github.com/users/BVLC/events{/privacy}","received_events_url":"https://api.github.com/users/BVLC/received_events","type":"Organization","site_admin":false},"repo":{"id":12791642,"name":"caffe","full_name":"BVLC/caffe","owner":{"login":"BVLC","id":6182163,"avatar_url":"https://avatars.githubusercontent.com/u/6182163?v=3","gravatar_id":"","url":"https://api.github.com/users/BVLC","html_url":"https://github.com/BVLC","followers_url":"https://api.github.com/users/BVLC/followers","following_url":"https://api.github.com/users/BVLC/following{/other_user}","gists_url":"https://api.github.com/users/BVLC/gists{/gist_id}","starred_url":"https://api.github.com/users/BVLC/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/BVLC/subscriptions","organizations_url":"https://api.github.com/users/BVLC/orgs","repos_url":"https://api.github.com/users/BVLC/repos","events_url":"https://api.github.com/users/BVLC/events{/privacy}","received_events_url":"https://api.github.com/users/BVLC/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/BVLC/caffe","description":"Caffe: a fast framework for deep learning. For the most recent version checkout the dev branch. For the latest stable release checkout the master branch.","fork":false,"url":"https://api.github.com/repos/BVLC/caffe","forks_url":"https://api.github.com/repos/BVLC/caffe/forks","keys_url":"https://api.github.com/repos/BVLC/caffe/keys{/key_id}","collaborators_url":"https://api.github.com/repos/BVLC/caffe/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/BVLC/caffe/teams","hooks_url":"https://api.github.com/repos/BVLC/caffe/hooks","issue_events_url":"https://api.github.com/repos/BVLC/caffe/issues/events{/number}","events_url":"https://api.github.com/repos/BVLC/caffe/events","assignees_url":"https://api.github.com/repos/BVLC/caffe/assignees{/user}","branches_url":"https://api.github.com/repos/BVLC/caffe/branches{/branch}","tags_url":"https://api.github.com/repos/BVLC/caffe/tags","blobs_url":"https://api.github.com/repos/BVLC/caffe/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/BVLC/caffe/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/BVLC/caffe/git/refs{/sha}","trees_url":"https://api.github.com/repos/BVLC/caffe/git/trees{/sha}","statuses_url":"https://api.github.com/repos/BVLC/caffe/statuses/{sha}","languages_url":"https://api.github.com/repos/BVLC/caffe/languages","stargazers_url":"https://api.github.com/repos/BVLC/caffe/stargazers","contributors_url":"https://api.github.com/repos/BVLC/caffe/contributors","subscribers_url":"https://api.github.com/repos/BVLC/caffe/subscribers","subscription_url":"https://api.github.com/repos/BVLC/caffe/subscription","commits_url":"https://api.github.com/repos/BVLC/caffe/commits{/sha}","git_commits_url":"https://api.github.com/repos/BVLC/caffe/git/commits{/sha}","comments_url":"https://api.github.com/repos/BVLC/caffe/comments{/number}","issue_comment_url":"https://api.github.com/repos/BVLC/caffe/issues/comments/{number}","contents_url":"https://api.github.com/repos/BVLC/caffe/contents/{+path}","compare_url":"https://api.github.com/repos/BVLC/caffe/compare/{base}...{head}","merges_url":"https://api.github.com/repos/BVLC/caffe/merges","archive_url":"https://api.github.com/repos/BVLC/caffe/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/BVLC/caffe/downloads","issues_url":"https://api.github.com/repos/BVLC/caffe/issues{/number}","pulls_url":"https://api.github.com/repos/BVLC/caffe/pulls{/number}","milestones_url":"https://api.github.com/repos/BVLC/caffe/milestones{/number}","notifications_url":"https://api.github.com/repos/BVLC/caffe/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/BVLC/caffe/labels{/name}","releases_url":"https://api.github.com/repos/BVLC/caffe/releases{/id}","created_at":"2013-09-12T18:39:48Z","updated_at":"2014-12-01T17:51:53Z","pushed_at":"2014-11-27T16:13:46Z","git_url":"git://github.com/BVLC/caffe.git","ssh_url":"git@github.com:BVLC/caffe.git","clone_url":"https://github.com/BVLC/caffe.git","svn_url":"https://github.com/BVLC/caffe","homepage":"http://caffe.berkeleyvision.org/","size":57052,"stargazers_count":1634,"watchers_count":1634,"language":"C++","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":874,"mirror_url":null,"open_issues_count":225,"forks":874,"open_issues":225,"watchers":1634,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/BVLC/caffe/pulls/1482"},"html":{"href":"https://github.com/BVLC/caffe/pull/1482"},"issue":{"href":"https://api.github.com/repos/BVLC/caffe/issues/1482"},"comments":{"href":"https://api.github.com/repos/BVLC/caffe/issues/1482/comments"},"review_comments":{"href":"https://api.github.com/repos/BVLC/caffe/pulls/1482/comments"},"review_comment":{"href":"https://api.github.com/repos/BVLC/caffe/pulls/comments/{number}"},"commits":{"href":"https://api.github.com/repos/BVLC/caffe/pulls/1482/commits"},"statuses":{"href":"https://api.github.com/repos/BVLC/caffe/statuses/78a376eea2599cc67595b1f27e949e4938b4b8c1"}}}}