@ptrblck - I also observe that when the stride is > 1 (say 2) the transpose Conv can’t reconstruct the original image size. But if I use unit stride then transpose Conv reconstructs the exact image size. See below:
Code snippet for perfect reconstruction:
In [1]: import torch
In [2]: D=torch.randn(1,1,28,28)
In [3]: import torch.nn as nn
In [4]: s,k,p=1,5,0
In [5]: conv1 = nn.Conv2d(1,1,kernel_size=k,stride=s,padding=p)
In [6]: deconv1 = nn.ConvTranspose2d(1,1,kernel_size=k,stride=s,padding=p)
In [7]: D1=conv1(D)
In [8]: D1_t = deconv1(D1)
In [10]: D1_t.shape
Out[10]: torch.Size([1, 1, 28, 28])==> size of the reconstructed image
Code snippet when reconstruction is not perfect when I use stride=2.
In [11]: s,k,p=2,5,0
In [12]: conv1 = nn.Conv2d(1,1,kernel_size=k,stride=s,padding=p)
In [13]: deconv1 = nn.ConvTranspose2d(1,1,kernel_size=k,stride=s,padding=p)
In [14]: D1 = conv1(D)
In [15]: D1_t = deconv1(D1)
In [16]: D.shape
Out[16]: torch.Size([1, 1, 28, 28])
In [17]: D1_t.shape
Out[17]: torch.Size([1, 1, 27, 27]) ==> size of the reconstructed image