Hello, since the circular padding is not support for nn.CONVTRANSPOSE2D
so far, I use F.pad
before the transpose convolutional layer to apply the padding operator. However, the output shape cannot be maintained as the input tensor, e.g., a tensor with shape (16,16)
will be (18,18)
after circular padding and cannot be shaped back to (16,16)
using nn.CONVTRANSPOSE2D
.
I searched some previous discussions and try to define output size by:
class MyConvTranspose2d(nn.Module):
def __init__(self, conv, output_size):
super(MyConvTranspose2d, self).__init__()
self.output_size = output_size
self.conv = conv
self.p2d = (1, 1, 1, 1)
def forward(self, x):
x = F.pad(x, p2d, 'circular')
x = self.conv(x, output_size=self.output_size)
return x
conv = nn.ConvTranspose2d(1, 1, (3,3),stride=1)
self_layer = MyConvTranspose2d(conv, output_size=(16, 16))
tensor_16 = torch.randn(1, 1, 16, 16).to(device, dtype=torch.float)
self_layer(tensor_16)
but it pop put a error message: ValueError: requested an output size of (16, 16), but valid sizes range from [20, 20] to [20, 20] (for an input of torch.Size([18, 18]))
. I wondering if there’s any suggestions on this problem. Thank you!