Expressions as input to the arguements of torch.nn.ConvTranspose2d

Suppose I want the output of a deconvolution layer to be exactly twice in size(read scale) of its input the parameters stride, padding, etc depends upon the input size.

So, is there a way to pass in expressions rather than constant values for the arguements?

Any help would be much appreciated.

Any other way that the output can be made twice the input?

ConvTranspose has an ouput_size parameter.

An example from the docs:

upsample = nn.ConvTranspose2d(16, 16, 3, stride=2, padding=1)
h = downsample(input)
torch.Size([1, 16, 6, 6])

>>> output = upsample(h, output_size=input.size())
torch.Size([1, 16, 12, 12])

So, in your case, output_size = input.size() * 2

1 Like

Thanks a lot!!
I am being a bit naive. Can you point me to the link in the doc where it says so?

** And does nn.Conv2d also take in ouput_size as parameter? I find no mention of that in docs.


I took this example from here:, at the end of the section.

For nn.Conv2d, I think no. You could calculate the appropriate padding depending on input size and kernel_size though.
For example, here is how it is done in the case of convTranspose:

1 Like

Thanks a ton!!!

Great community.