I’m running into an issue when exporting a model from pytorch (version 1.0.0) to onnx, and then importing into tensorrt (version 5.0.3 in jetpack 4.1.1).

In pytorch/onnx, the convtranspose2d layer (with parameters: kernel size = 3, stride = 2, padding = 1, output padding = 1, dilation = 1; input tensor dimension 1 x 256 x 16 x 32) produces output tensors with dimension 1 x 256 x 32 x 64 (the desired size).

When imported into tensorrt, the layer produces output tensors with dimension 1 x 256 x 31 x 63.

Looking at pytorch’s documentation (https://pytorch.org/docs/stable/nn.html#torch.nn.ConvTranspose2d), the given formula for output dimension (eg, for height) is: (H_in - 1)*stride - 2*padding + kernel_size + output_padding. plugging in our parameters gives 32.

Looking at tensorrt’s documentation on the deconvolution layer (https://docs.nvidia.com/deeplearning/sdk/pdf/TensorRT-Developer-Guide.pdf - section A.1.5), the given formula for output dimension is: (H_in -1)*stride + t - 2*padding, where t = kernel_size + dilation*(kernel_size-1). there are a few confusing bits here:

- plugging in our parameters doesn’t actually give 31, but 33. does the padding in this formula sum both the input padding and output_padding?
- this differs from the pytorch formula only in the last bit: pytorch adds output_padding, and tensorrt adds dilation*(kernel_size-1) instead

Any thoughts on how we can get these two APIs to output the same dimensions here, and why the tensorrt dimension is not as expected?

Thanks for taking a look.