{"action":"created","issue":{"url":"https://api.github.com/repos/BVLC/caffe/issues/1615","labels_url":"https://api.github.com/repos/BVLC/caffe/issues/1615/labels{/name}","comments_url":"https://api.github.com/repos/BVLC/caffe/issues/1615/comments","events_url":"https://api.github.com/repos/BVLC/caffe/issues/1615/events","html_url":"https://github.com/BVLC/caffe/pull/1615","id":52624701,"number":1615,"title":"Refactor convolution layer and add deconvolution layer","user":{"login":"longjon","id":940817,"avatar_url":"https://avatars.githubusercontent.com/u/940817?v=3","gravatar_id":"","url":"https://api.github.com/users/longjon","html_url":"https://github.com/longjon","followers_url":"https://api.github.com/users/longjon/followers","following_url":"https://api.github.com/users/longjon/following{/other_user}","gists_url":"https://api.github.com/users/longjon/gists{/gist_id}","starred_url":"https://api.github.com/users/longjon/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/longjon/subscriptions","organizations_url":"https://api.github.com/users/longjon/orgs","repos_url":"https://api.github.com/users/longjon/repos","events_url":"https://api.github.com/users/longjon/events{/privacy}","received_events_url":"https://api.github.com/users/longjon/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/BVLC/caffe/labels/focus","name":"focus","color":"006b75"},{"url":"https://api.github.com/repos/BVLC/caffe/labels/ready%20for%20review","name":"ready for review","color":"bfe5bf"}],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":8,"created_at":"2014-12-22T06:54:57Z","updated_at":"2015-06-17T09:31:25Z","closed_at":"2015-02-01T07:53:58Z","pull_request":{"url":"https://api.github.com/repos/BVLC/caffe/pulls/1615","html_url":"https://github.com/BVLC/caffe/pull/1615","diff_url":"https://github.com/BVLC/caffe/pull/1615.diff","patch_url":"https://github.com/BVLC/caffe/pull/1615.patch"},"body":"This PR adds a `DeconvolutionLayer` that flips the forward and backward passes of `ConvolutionLayer`. (The resulting operation is still convolution, but the sense of all the parameters is reversed, so that, in particular, strided deconvolution results in upsampling whereas strided convolution results in downsampling.)\r\n\r\nRather than duplicate all the `ConvolutionLayer` code, common sections are factored out into a parent class, `BaseConvolutionLayer`. The tricky GEMM parameters and the column buffer are hidden from the forward and backward implementations, which I hope you agree are much more readable.\r\n\r\nPositives\r\n* Readable implementations of convolution and deconvolution.\r\n* Deconvolution supports all functions of convolution, including padding (note that padding is removed from the output rather than added to the input!), groups, rectangular kernels, biases.\r\n* Whereas `ConvolutionLayer` needs to do an `im2col` and a `col2im` in the backward pass, both operations in `DeconvolutionLayer`'s backward pass require `im2col`, so a special flag is added to avoid doing this twice.\r\n\r\nReservations\r\n* The diff is pretty heavy; it was not straightforward to make the changes in a gradual way, so the history is constructed post-hoc. However, the code should be pretty understandable to the few of you intimately familiar with `ConvolutionLayer`. Also note that the diff size is really half what it appears to be, because of the point below.\r\n* Almost all the code is duplicated via s/cpu/gpu/. This PR is not the place to address this, but I hope we can get (some part of?) #610 merged soon, because this is getting silly.\r\n* Is \"deconvolution\" really the right name? This layer does not have to be used in the context of undoing a convolution (although it could be). It seems likely that this name will stick one way or another.\r\n\r\nDesign choices\r\n* The original idea was to add convolution helper functions under `util/`. However, these end up requiring a large number of arguments (each needs most of the convolution parameters). So, one could wrap all the common arguments in a `struct`, like cuDNN... but then that `struct` may as well be the layer class itself, so we have the current design.\r\n* Rather than use a special flag to skip the extra `im2col` in deconv backward, we could leave the column buffer out of the wrapper functions. However, this leads to more duplicated code, and cuts down significantly on readability.\r\n* The forward helper and weight diff helper are both `im2col`s followed by gemms, so in theory we could unify them. However, then we need additional arguments and logic to figure out when to transpose the column buffer. I think this could still be done, but it's a bit of a wash.\r\n\r\nForthcoming\r\n* Doc comments for `DeconvolutionLayer`.\r\n* Tests specific to `DeconvolutionLayer`. Note that most of the functionality is exercised by the `ConvolutionLayer` tests. I've only briefly checked the forward/backward passes for upsampling/downsampling, so there could be a bug or two left.\r\n* cuDNN deconvolution should be straightforward to implement as well, since cuDNN already provides the same kind of abstraction as this refactoring. However, I won't be able to do that right away; PRs are welcome!"},"comment":{"url":"https://api.github.com/repos/BVLC/caffe/issues/comments/112735621","html_url":"https://github.com/BVLC/caffe/pull/1615#issuecomment-112735621","issue_url":"https://api.github.com/repos/BVLC/caffe/issues/1615","id":112735621,"user":{"login":"yyyek","id":9815267,"avatar_url":"https://avatars.githubusercontent.com/u/9815267?v=3","gravatar_id":"","url":"https://api.github.com/users/yyyek","html_url":"https://github.com/yyyek","followers_url":"https://api.github.com/users/yyyek/followers","following_url":"https://api.github.com/users/yyyek/following{/other_user}","gists_url":"https://api.github.com/users/yyyek/gists{/gist_id}","starred_url":"https://api.github.com/users/yyyek/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/yyyek/subscriptions","organizations_url":"https://api.github.com/users/yyyek/orgs","repos_url":"https://api.github.com/users/yyyek/repos","events_url":"https://api.github.com/users/yyyek/events{/privacy}","received_events_url":"https://api.github.com/users/yyyek/received_events","type":"User","site_admin":false},"created_at":"2015-06-17T09:31:25Z","updated_at":"2015-06-17T09:31:25Z","body":"Is there any tutorial for this layer? I don't know how to use it"}}