How to get the same size output of conv_transpose2d

First I have a feature map, then I used nn.Conv2d(in_channel, out_channel, 3, stride=2, padding=1, bias=True) to generate a intermediary feature map. Next, fed it to nn.ConvTranspose2d(conv_channels, conv_channels, 3, stride=2, padding=1, output_padding=1) and get the final output.
My question is how to control the parameters padding and output_padding in order to get the same size final output with the initial feature map. When I used padding=1 and output_padding=1, It only worked as the initial feature map had even number size. While I used feature map with odd number size, It’s wrong.
Could anyone help me please?

This convolution arithmetic doc gives you some general information about convolutions as well as transposed convolutions and also about the relationship of their parameters, which might be useful for your use case.
Depending on your input shape, you might need to change more parameters than the padding, such as the kernel size.