-
Notifications
You must be signed in to change notification settings - Fork 967
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support of depth-wise convolution #1098
Conversation
@soumith If it is useful, I will continue on writing the test part for TDD. Thank you! |
@Atcold Thanks for the advice. Will work on it. |
are you planning to work on a CUDA implementation for this? If not, consider putting this in https://github.com/clementfarabet/lua---nnx which we reserve for experimental modules |
@soumith Yes. Actually I have written a CUDA implemention fot this (still under testng for its speed). See https://github.com/stooloveu/cunn |
@stooloveu, let me know when your code passes the test I gave you, so that I can give it a final look. OK? |
@Atcold Like I said in the email, the dimensions are correct. I also modified the test script by adding weight and bias to test the result, it is also identical (with the output of your test code). |
@stooloveu, sweet! Could you please profile your code vs. mine? |
@stooloveu This PR is starting to look quite good. All that remains is some unit tests and documentation. @Atcold What do you mean your code? Do you already have a version of this? |
@nicholas-leonard @Atcold Thank you! The codes for both nn and cunn are done. I was working on exams last week and I will put some work on the test and documentation this weekend. And I think what he meant by his code was that he wrote some test code to compare those results for preliminary small-size tests. |
@nicholas-leonard, Torch "can" already perform depth-wise convolutions. It is simply non efficient. Hence, I delegated @stooloveu to take care of the optimised version, for both CPU and GPU, which has to produce the same numerical results of the non efficient version but quickly. |
@nicholas-leonard @soumith This functional part (depth wise convolution) for 'nn' package is ready to merge: It has passed the test written by @Atcold (see above). The test code and profiling information can be found at: https://github.com/stooloveu/SpatialDepthWiseConvolution_profiling The documentation has been added into I will also submit a pull request for the GPU version under 'torch/cunn'. Please let me know if there's any problem. Many thanks! EDIT:
|
Yeah, it looks fine to me (yup, tests are needed). |
Added @Atcold 's unit test, rebased to one commit (that was hell), merged in 5f1f7a2. Thanks @stooloveu @Atcold |
@Atcold @nicholas-leonard @stooloveu why is bias a 2D Tensor with shape cc @soumith |
looks like a bug to me. the bias code is wrong. bias has to be 1d and nOutputPlane |
you have one single bias value for each output channel. so bias tensor will just be 1d of size nOutputPlane |
I think as the output image size will be a 3D tensor (nOutputPlane * nInputPlane) x oheight x owidth, the bias should be a 1D tensor with the size of (nOutputPlane * nInputPlane). |
And also Chainer's implementation for reference: |
i think there's a terminology fix here. nOutputPlane = nInputPlane * channel_multiplier. |
bias will be 1d of size nOutputPlane. trevor, when channel_multiplier = 1, it's groups=nInputPlane. the fix we need to do is make bias be 1d |
Yeah, that's a good point. I used nOutputPlane to be consistent with normal conv. Maybe I should address the terminology better. Thanks! |
I think we should benchmark these functions against what we currently have in pytorch, because it only performs a for loop over the number of channels. One alternative implementation is to follow something similar to caffe, which have dedicated kernels for each operation, so should be faster? |
I added support for 'SpatialDepthWiseConvolution', which is similar to TensorFlow's 'depthwise_conv2d'. I think it might be useful for some users.
Do not merge 'README.md' and 'install.sh', I edited for my own convenience. However, description for this module can be found in 'README.md'. If it is useful, the description can be added to the docs file later.