ConvTranspose2d Output Size Calculator
For a PyTorch nn.ConvTranspose2d layer the output size is H_out = (H_in - 1) × stride[0] - 2 × padding[0] + dilation[0] × (kernel_size[0] - 1) + output_padding[0] + 1, and W_out follows the same formula with index [1]. This is the inverse of Conv2d, and it is the formula given in the official PyTorch documentation for torch.nn.ConvTranspose2d.
Calculate the output size of a PyTorch ConvTranspose2d (transposed convolution) layer. Enter input shape, kernel, stride, padding, and output_padding for exact results.
Built by Michael Lip
PyTorch ConvTranspose2d output size formula, from the official docs
The Shape section of the torch.nn.ConvTranspose2d documentation states the output size as:
H_out = (H_in - 1) × stride[0] - 2 × padding[0] + dilation[0] × (kernel_size[0] - 1) + output_padding[0] + 1
W_out = (W_in - 1) × stride[1] - 2 × padding[1] + dilation[1] × (kernel_size[1] - 1) + output_padding[1] + 1PyTorch documentation, torch.nn.ConvTranspose2d, Shape section. Verified 15 August 2026.
Worked example, 7×7 to 14×14
With nn.ConvTranspose2d(64, 32, kernel_size=3, stride=2, padding=1, output_padding=1) and an input of [1, 64, 7, 7]:
H_out = (7 - 1) × 2 - 2 × 1 + 1 × (3 - 1) + 1 + 1 = 12 - 2 + 2 + 1 + 1 = 14
The output tensor is [1, 32, 14, 14]. The 7×7 feature map doubles to 14×14.
Two parameter sets double the resolution exactly for any input size. kernel_size=4, stride=2, padding=1, output_padding=0 gives H_out = 2 × H_in, and kernel_size=3, stride=2, padding=1, output_padding=1 does the same. Both are standard in DCGAN generators and U-Net decoders. The docs require output_padding to be strictly smaller than either stride or dilation.
Frequently Asked Questions
What is the ConvTranspose2d output size formula?
The formula is: H_out = (H_in - 1) * stride - 2*padding + dilation*(kernel_size-1) + output_padding + 1. This is the inverse of Conv2d and is used in decoder networks and GANs to upsample feature maps.
What is output_padding in ConvTranspose2d?
output_padding adds extra pixels to one side of the output. It resolves the ambiguity where multiple input sizes can map to the same Conv2d output. It must be less than stride. Common value is 0 or 1.
When should I use ConvTranspose2d vs Upsample + Conv2d?
ConvTranspose2d can produce checkerboard artifacts. An alternative is nn.Upsample followed by nn.Conv2d, which often gives smoother results. However, ConvTranspose2d is more parameter-efficient and widely used in U-Net and GAN architectures.
Is this tool free?
Yes. All HeyTensor tools are free, run in your browser, and require no signup.
Does this work offline?
Once loaded, the tool runs entirely in your browser. No internet needed after the initial page load.
About This Tool
This tool is part of HeyTensor, a free suite of PyTorch and deep learning utilities. All calculations run entirely in your browser, no data is sent to any server. The source code is open on GitHub.
Contact
HeyTensor is built and maintained by Michael Lip. For questions or feedback, email [email protected].