{"action":"created","comment":{"url":"https://api.github.com/repos/Kaixhin/nninit/pulls/comments/109319040","pull_request_review_id":30413228,"id":109319040,"diff_hunk":"@@ -270,4 +270,95 @@ nninit.sparse = function(module, tensor, sparsity)\n   return module\n end\n \n+--[[\n+--  Aghajanyan, A. (2017)\n+--  Convolution Aware Initialization\n+--  arXiv preprint arXiv:1702.06295\n+--]]\n+nninit.convaware = function(module, tensor, options)\n+  -- The author of the paper provided a reference implementation for Keras: https://github.com/farizrahman4u/keras-contrib/pull/60\n+\n+  local sizes = tensor:size()\n+  if #sizes ~= 4 then\n+    error(\"nninit.convaware only supports 2d convolutions, feel free to issue a pull request to extend this implementation\")\n+  end\n+\n+  -- Make sure that the signal library is available, which provides the Fourier transform\n+  local requireSignal = function()\n+    require('signal')\n+  end\n+  if pcall(requireSignal) == false then\n+    error(\"nninit.convaware requires the signal library, please make sure to install it: https://github.com/soumith/torch-signal\")\n+  end\n+\n+  -- Store the sizes of the convolution tensor to make the implementation easier to read\n+  local filterCount = sizes[1]\n+  local filterStacks = sizes[2]\n+  local filterRows = sizes[3]\n+  local filterCols = sizes[4]\n+\n+  -- Due to the irfft2 interface of the signal library, we currently have to restrict the filter size\n+  if filterRows ~= filterCols then\n+    error(\"nninit.convaware requires the filters to have the same number of rows and columns, feel free to issue a pull request to extend this implementation\")\n+  end\n+\n+  -- Calculate \"fanIn\" and \"fanOut\" for 2d convolution tensors based on module conventions\n+  local fanIn = filterStacks * filterRows * filterCols\n+  local fanOut = filterCount * filterRows * filterCols\n+\n+  -- Setup options where \"std\" specifies the noise to break symmetry in the inverse Fourier transform\n+  options = options or {}\n+  std = options.std or 0.05\n+\n+  -- Specify the variables for the frequency domain tensor\n+  local fourierTensor = require('signal').rfft2(torch.zeros(filterRows, filterCols))\n+  local fourierRows = fourierTensor:size(1)\n+  local fourierCols = fourierTensor:size(2)\n+  local fourierSize = fourierRows * fourierCols\n+\n+  -- Specify the variables for the orthogonal tensor buffer\n+  local orthogonalIndex = fourierSize\n+  local orthogonalTensor = nil\n+\n+  -- For each filter, create a suitable basis tensor and perform an inverse Fourier transform to obtain the filter coefficients\n+  for filterIndex = 1, filterCount do\n+    basisTensor = torch.zeros(filterStacks, fourierSize)\n+\n+    -- Create a suitable basis tensor using the orthogonal tensor buffer, making sure to refill the buffer should it be empty\n+    for basisIndex = 1, filterStacks do\n+      if orthogonalIndex == fourierSize then\n+        local randomTensor = torch.zeros(fourierSize, fourierSize):normal(0.0, 1.0)\n+        local symmetricTensor = randomTensor + randomTensor:t() - torch.diag(randomTensor:diag())\n+\n+        orthogonalIndex = 0\n+        orthogonalTensor, _, _ = torch.svd(symmetricTensor)\n+      end\n+\n+      -- Copy a column from the orthogonal tensor buffer into the basis tensor\n+      orthogonalIndex = orthogonalIndex + 1\n+      basisTensor[{ { basisIndex }, {} }] = orthogonalTensor[{ {}, { orthogonalIndex } }]\n+    end\n+\n+    basisTensor = basisTensor:view(filterStacks, fourierRows, fourierCols)\n+\n+    -- Perform the inverse Fourier transform from the basis tensor to obtain the filter coefficients, making sure to break the symmetry\n+    for basisIndex = 1, filterStacks do\n+      fourierTensor[{ {}, {}, { 1 } }] = basisTensor[{ { basisIndex }, {} }]\n+      fourierTensor[{ {}, {}, { 2 } }]:zero()\n+\n+      -- Unlike the Numpy implementation, the inverse Fourier transform in the signal library does sadly only support a single size argument\n+      tensor[{ { filterIndex }, { basisIndex }, {}, {} }] = require('signal').irfft2(fourierTensor, filterRows) + torch.zeros(filterRows, filterCols):normal(0.0, std)\n+    end\n+\n+    -- Clear the orthogonal tensor buffer, we do not want to reuse it for the next filter\n+    orthogonalIndex = fourierSize\n+    orthogonalTensor = nil","path":"nninit.lua","position":86,"original_position":86,"commit_id":"03ca3a4a7cff3ccf6a72c8e2da9e0c347cdcc41f","original_commit_id":"03ca3a4a7cff3ccf6a72c8e2da9e0c347cdcc41f","user":{"login":"sniklaus","id":1238034,"avatar_url":"https://avatars3.githubusercontent.com/u/1238034?v=3","gravatar_id":"","url":"https://api.github.com/users/sniklaus","html_url":"https://github.com/sniklaus","followers_url":"https://api.github.com/users/sniklaus/followers","following_url":"https://api.github.com/users/sniklaus/following{/other_user}","gists_url":"https://api.github.com/users/sniklaus/gists{/gist_id}","starred_url":"https://api.github.com/users/sniklaus/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sniklaus/subscriptions","organizations_url":"https://api.github.com/users/sniklaus/orgs","repos_url":"https://api.github.com/users/sniklaus/repos","events_url":"https://api.github.com/users/sniklaus/events{/privacy}","received_events_url":"https://api.github.com/users/sniklaus/received_events","type":"User","site_admin":false},"body":"I am not entirely sure, but this is how Armen's reference implementation operates as well.","created_at":"2017-04-02T20:25:26Z","updated_at":"2017-04-02T20:25:26Z","html_url":"https://github.com/Kaixhin/nninit/pull/10#discussion_r109319040","pull_request_url":"https://api.github.com/repos/Kaixhin/nninit/pulls/10","_links":{"self":{"href":"https://api.github.com/repos/Kaixhin/nninit/pulls/comments/109319040"},"html":{"href":"https://github.com/Kaixhin/nninit/pull/10#discussion_r109319040"},"pull_request":{"href":"https://api.github.com/repos/Kaixhin/nninit/pulls/10"}}},"pull_request":{"url":"https://api.github.com/repos/Kaixhin/nninit/pulls/10","id":113801583,"html_url":"https://github.com/Kaixhin/nninit/pull/10","diff_url":"https://github.com/Kaixhin/nninit/pull/10.diff","patch_url":"https://github.com/Kaixhin/nninit/pull/10.patch","issue_url":"https://api.github.com/repos/Kaixhin/nninit/issues/10","number":10,"state":"open","locked":false,"title":"added Convolution Aware Initialization","user":{"login":"sniklaus","id":1238034,"avatar_url":"https://avatars3.githubusercontent.com/u/1238034?v=3","gravatar_id":"","url":"https://api.github.com/users/sniklaus","html_url":"https://github.com/sniklaus","followers_url":"https://api.github.com/users/sniklaus/followers","following_url":"https://api.github.com/users/sniklaus/following{/other_user}","gists_url":"https://api.github.com/users/sniklaus/gists{/gist_id}","starred_url":"https://api.github.com/users/sniklaus/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sniklaus/subscriptions","organizations_url":"https://api.github.com/users/sniklaus/orgs","repos_url":"https://api.github.com/users/sniklaus/repos","events_url":"https://api.github.com/users/sniklaus/events{/privacy}","received_events_url":"https://api.github.com/users/sniklaus/received_events","type":"User","site_admin":false},"body":"I got in touch with Armen Aghajanyan, who wrote the Convolution Aware Initialization paper, and asked him a few questions about his research. Knowing that I implemented his paper in Torch, while his reference implementation is done in Keras, he asked me to make mine available for others. I consider the nninit library to be the best place for doing so (thank you for all the good work!), which is why I issue this pull request. I a tried to match the coding style to the existing codebase, please let me know should you want me to do any changes.","created_at":"2017-04-02T01:39:05Z","updated_at":"2017-04-02T20:25:26Z","closed_at":null,"merged_at":null,"merge_commit_sha":"cac4aafcc39e81a49847b378235a56183f932ffc","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/Kaixhin/nninit/pulls/10/commits","review_comments_url":"https://api.github.com/repos/Kaixhin/nninit/pulls/10/comments","review_comment_url":"https://api.github.com/repos/Kaixhin/nninit/pulls/comments{/number}","comments_url":"https://api.github.com/repos/Kaixhin/nninit/issues/10/comments","statuses_url":"https://api.github.com/repos/Kaixhin/nninit/statuses/03ca3a4a7cff3ccf6a72c8e2da9e0c347cdcc41f","head":{"label":"sniklaus:patch-1","ref":"patch-1","sha":"03ca3a4a7cff3ccf6a72c8e2da9e0c347cdcc41f","user":{"login":"sniklaus","id":1238034,"avatar_url":"https://avatars3.githubusercontent.com/u/1238034?v=3","gravatar_id":"","url":"https://api.github.com/users/sniklaus","html_url":"https://github.com/sniklaus","followers_url":"https://api.github.com/users/sniklaus/followers","following_url":"https://api.github.com/users/sniklaus/following{/other_user}","gists_url":"https://api.github.com/users/sniklaus/gists{/gist_id}","starred_url":"https://api.github.com/users/sniklaus/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sniklaus/subscriptions","organizations_url":"https://api.github.com/users/sniklaus/orgs","repos_url":"https://api.github.com/users/sniklaus/repos","events_url":"https://api.github.com/users/sniklaus/events{/privacy}","received_events_url":"https://api.github.com/users/sniklaus/received_events","type":"User","site_admin":false},"repo":{"id":86953635,"name":"nninit","full_name":"sniklaus/nninit","owner":{"login":"sniklaus","id":1238034,"avatar_url":"https://avatars3.githubusercontent.com/u/1238034?v=3","gravatar_id":"","url":"https://api.github.com/users/sniklaus","html_url":"https://github.com/sniklaus","followers_url":"https://api.github.com/users/sniklaus/followers","following_url":"https://api.github.com/users/sniklaus/following{/other_user}","gists_url":"https://api.github.com/users/sniklaus/gists{/gist_id}","starred_url":"https://api.github.com/users/sniklaus/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sniklaus/subscriptions","organizations_url":"https://api.github.com/users/sniklaus/orgs","repos_url":"https://api.github.com/users/sniklaus/repos","events_url":"https://api.github.com/users/sniklaus/events{/privacy}","received_events_url":"https://api.github.com/users/sniklaus/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/sniklaus/nninit","description":"Weight initialisation schemes for Torch7 neural network modules","fork":true,"url":"https://api.github.com/repos/sniklaus/nninit","forks_url":"https://api.github.com/repos/sniklaus/nninit/forks","keys_url":"https://api.github.com/repos/sniklaus/nninit/keys{/key_id}","collaborators_url":"https://api.github.com/repos/sniklaus/nninit/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/sniklaus/nninit/teams","hooks_url":"https://api.github.com/repos/sniklaus/nninit/hooks","issue_events_url":"https://api.github.com/repos/sniklaus/nninit/issues/events{/number}","events_url":"https://api.github.com/repos/sniklaus/nninit/events","assignees_url":"https://api.github.com/repos/sniklaus/nninit/assignees{/user}","branches_url":"https://api.github.com/repos/sniklaus/nninit/branches{/branch}","tags_url":"https://api.github.com/repos/sniklaus/nninit/tags","blobs_url":"https://api.github.com/repos/sniklaus/nninit/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/sniklaus/nninit/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/sniklaus/nninit/git/refs{/sha}","trees_url":"https://api.github.com/repos/sniklaus/nninit/git/trees{/sha}","statuses_url":"https://api.github.com/repos/sniklaus/nninit/statuses/{sha}","languages_url":"https://api.github.com/repos/sniklaus/nninit/languages","stargazers_url":"https://api.github.com/repos/sniklaus/nninit/stargazers","contributors_url":"https://api.github.com/repos/sniklaus/nninit/contributors","subscribers_url":"https://api.github.com/repos/sniklaus/nninit/subscribers","subscription_url":"https://api.github.com/repos/sniklaus/nninit/subscription","commits_url":"https://api.github.com/repos/sniklaus/nninit/commits{/sha}","git_commits_url":"https://api.github.com/repos/sniklaus/nninit/git/commits{/sha}","comments_url":"https://api.github.com/repos/sniklaus/nninit/comments{/number}","issue_comment_url":"https://api.github.com/repos/sniklaus/nninit/issues/comments{/number}","contents_url":"https://api.github.com/repos/sniklaus/nninit/contents/{+path}","compare_url":"https://api.github.com/repos/sniklaus/nninit/compare/{base}...{head}","merges_url":"https://api.github.com/repos/sniklaus/nninit/merges","archive_url":"https://api.github.com/repos/sniklaus/nninit/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/sniklaus/nninit/downloads","issues_url":"https://api.github.com/repos/sniklaus/nninit/issues{/number}","pulls_url":"https://api.github.com/repos/sniklaus/nninit/pulls{/number}","milestones_url":"https://api.github.com/repos/sniklaus/nninit/milestones{/number}","notifications_url":"https://api.github.com/repos/sniklaus/nninit/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/sniklaus/nninit/labels{/name}","releases_url":"https://api.github.com/repos/sniklaus/nninit/releases{/id}","deployments_url":"https://api.github.com/repos/sniklaus/nninit/deployments","created_at":"2017-04-02T01:10:54Z","updated_at":"2017-04-02T01:10:56Z","pushed_at":"2017-04-02T01:34:37Z","git_url":"git://github.com/sniklaus/nninit.git","ssh_url":"git@github.com:sniklaus/nninit.git","clone_url":"https://github.com/sniklaus/nninit.git","svn_url":"https://github.com/sniklaus/nninit","homepage":"","size":41,"stargazers_count":0,"watchers_count":0,"language":"Lua","has_issues":false,"has_projects":true,"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":0,"default_branch":"master"}},"base":{"label":"Kaixhin:master","ref":"master","sha":"f57b811c0e310cd24f9bb34adb4476d0518455d2","user":{"login":"Kaixhin","id":991891,"avatar_url":"https://avatars0.githubusercontent.com/u/991891?v=3","gravatar_id":"","url":"https://api.github.com/users/Kaixhin","html_url":"https://github.com/Kaixhin","followers_url":"https://api.github.com/users/Kaixhin/followers","following_url":"https://api.github.com/users/Kaixhin/following{/other_user}","gists_url":"https://api.github.com/users/Kaixhin/gists{/gist_id}","starred_url":"https://api.github.com/users/Kaixhin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Kaixhin/subscriptions","organizations_url":"https://api.github.com/users/Kaixhin/orgs","repos_url":"https://api.github.com/users/Kaixhin/repos","events_url":"https://api.github.com/users/Kaixhin/events{/privacy}","received_events_url":"https://api.github.com/users/Kaixhin/received_events","type":"User","site_admin":false},"repo":{"id":46289423,"name":"nninit","full_name":"Kaixhin/nninit","owner":{"login":"Kaixhin","id":991891,"avatar_url":"https://avatars0.githubusercontent.com/u/991891?v=3","gravatar_id":"","url":"https://api.github.com/users/Kaixhin","html_url":"https://github.com/Kaixhin","followers_url":"https://api.github.com/users/Kaixhin/followers","following_url":"https://api.github.com/users/Kaixhin/following{/other_user}","gists_url":"https://api.github.com/users/Kaixhin/gists{/gist_id}","starred_url":"https://api.github.com/users/Kaixhin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Kaixhin/subscriptions","organizations_url":"https://api.github.com/users/Kaixhin/orgs","repos_url":"https://api.github.com/users/Kaixhin/repos","events_url":"https://api.github.com/users/Kaixhin/events{/privacy}","received_events_url":"https://api.github.com/users/Kaixhin/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/Kaixhin/nninit","description":"Weight initialisation schemes for Torch7 neural network modules","fork":false,"url":"https://api.github.com/repos/Kaixhin/nninit","forks_url":"https://api.github.com/repos/Kaixhin/nninit/forks","keys_url":"https://api.github.com/repos/Kaixhin/nninit/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Kaixhin/nninit/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Kaixhin/nninit/teams","hooks_url":"https://api.github.com/repos/Kaixhin/nninit/hooks","issue_events_url":"https://api.github.com/repos/Kaixhin/nninit/issues/events{/number}","events_url":"https://api.github.com/repos/Kaixhin/nninit/events","assignees_url":"https://api.github.com/repos/Kaixhin/nninit/assignees{/user}","branches_url":"https://api.github.com/repos/Kaixhin/nninit/branches{/branch}","tags_url":"https://api.github.com/repos/Kaixhin/nninit/tags","blobs_url":"https://api.github.com/repos/Kaixhin/nninit/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Kaixhin/nninit/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Kaixhin/nninit/git/refs{/sha}","trees_url":"https://api.github.com/repos/Kaixhin/nninit/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Kaixhin/nninit/statuses/{sha}","languages_url":"https://api.github.com/repos/Kaixhin/nninit/languages","stargazers_url":"https://api.github.com/repos/Kaixhin/nninit/stargazers","contributors_url":"https://api.github.com/repos/Kaixhin/nninit/contributors","subscribers_url":"https://api.github.com/repos/Kaixhin/nninit/subscribers","subscription_url":"https://api.github.com/repos/Kaixhin/nninit/subscription","commits_url":"https://api.github.com/repos/Kaixhin/nninit/commits{/sha}","git_commits_url":"https://api.github.com/repos/Kaixhin/nninit/git/commits{/sha}","comments_url":"https://api.github.com/repos/Kaixhin/nninit/comments{/number}","issue_comment_url":"https://api.github.com/repos/Kaixhin/nninit/issues/comments{/number}","contents_url":"https://api.github.com/repos/Kaixhin/nninit/contents/{+path}","compare_url":"https://api.github.com/repos/Kaixhin/nninit/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Kaixhin/nninit/merges","archive_url":"https://api.github.com/repos/Kaixhin/nninit/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Kaixhin/nninit/downloads","issues_url":"https://api.github.com/repos/Kaixhin/nninit/issues{/number}","pulls_url":"https://api.github.com/repos/Kaixhin/nninit/pulls{/number}","milestones_url":"https://api.github.com/repos/Kaixhin/nninit/milestones{/number}","notifications_url":"https://api.github.com/repos/Kaixhin/nninit/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Kaixhin/nninit/labels{/name}","releases_url":"https://api.github.com/repos/Kaixhin/nninit/releases{/id}","deployments_url":"https://api.github.com/repos/Kaixhin/nninit/deployments","created_at":"2015-11-16T17:06:36Z","updated_at":"2017-03-27T08:53:22Z","pushed_at":"2017-04-02T01:39:05Z","git_url":"git://github.com/Kaixhin/nninit.git","ssh_url":"git@github.com:Kaixhin/nninit.git","clone_url":"https://github.com/Kaixhin/nninit.git","svn_url":"https://github.com/Kaixhin/nninit","homepage":"","size":38,"stargazers_count":85,"watchers_count":85,"language":"Lua","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":10,"mirror_url":null,"open_issues_count":1,"forks":10,"open_issues":1,"watchers":85,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/Kaixhin/nninit/pulls/10"},"html":{"href":"https://github.com/Kaixhin/nninit/pull/10"},"issue":{"href":"https://api.github.com/repos/Kaixhin/nninit/issues/10"},"comments":{"href":"https://api.github.com/repos/Kaixhin/nninit/issues/10/comments"},"review_comments":{"href":"https://api.github.com/repos/Kaixhin/nninit/pulls/10/comments"},"review_comment":{"href":"https://api.github.com/repos/Kaixhin/nninit/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/Kaixhin/nninit/pulls/10/commits"},"statuses":{"href":"https://api.github.com/repos/Kaixhin/nninit/statuses/03ca3a4a7cff3ccf6a72c8e2da9e0c347cdcc41f"}}}}
{"actor":{"display_login":"sniklaus"}}