Skip to content
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 ConvTranspose2d #7

Open
ssdutHB opened this issue Feb 1, 2018 · 4 comments
Open

Add ConvTranspose2d #7

ssdutHB opened this issue Feb 1, 2018 · 4 comments

Comments

@ssdutHB
Copy link

ssdutHB commented Feb 1, 2018

Could you please add nn.ConvTranspose2d into the transformation? Because the ConvTranspose2d operation is now very common in neural networks.

@longcw
Copy link
Owner

longcw commented Feb 2, 2018

I think it's feasible and easy to convert torch.nn.ConvTransposed2d to Deconvolution since I already did that for UpsamplingBilinear2d. But I don't have enough time to implement it now.
You can follow here to implement it. You need to

  1. convert the layer parameters of ConvTransposed2d to that of Deconvolution in caffe,
  2. and check if weight and bias of ConvTransposed2d are saved properly for caffe: https://github.com/longcw/pytorch2caffe/blob/master/pytorch2caffe.py#L101

@ssdutHB
Copy link
Author

ssdutHB commented Feb 2, 2018

Hi, longcw. Thanks for your quick reply. Yesterday, I transferred "conv_transpose2d" from pytorch to caffe as what you said above. But I found that there is a parameter "output_padding" in "conv_transpose2d". That optional parameter will add specific padding to the result of deconvolution, so that the user can get a specific output shape. But the Decovolution layer in caffe has no such parameter. So it's a problem now for me.
Consider, if we want to convert a deconv layer from pytorch, which is "nn.ConvTranspose2d(128,128,kernel_size =3,stride=2,padding =1,output_padding = 1)",
How can we write a caffe layer?

The code above can convert a tensor with shape(batch,channel,width,height) to shape(batch,channel,widthx2,heightx2).

if we write a caffe layer with above parameter
layer {
name: "ConvNdBackward73"
type: "Deconvolution"
bottom: "AddBackward72"
top: "ConvNdBackward73"
convolution_param {
num_output: 128
pad: 1
kernel_size: 3
stride: 2
bias_term: false
}
}

we get (batch,channel,width,height) to (batch,channel,widthx2-1.heightx2-1)

In conclusion, I think the deconv operation in pytorch can't be perfectly converted to caffe. Am I right?

@longcw
Copy link
Owner

longcw commented Feb 2, 2018

So the only difference is the output_padding. If the output_padding is not zero then we will need an extra "padding layer" (?) in caffe. BTW, welcome to send pull requests for your improvement.

@OPPOA113
Copy link

@longcw @ssdutHB
so finally, if "conv_transpose2d" can be transferred to "Deconvolution"? and how? thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants