0

I am getting error this error while running my pytorch model /usr/local/lib/python3.7/dist-packages/ipykernel_launcher.py:47: UserWarning: Using a target size (torch.Size([1, 55, 46, 46])) that is different to the input size (torch.Size([1, 55, 47, 47])). This will likely lead to incorrect results due to broadcasting. Please ensure they have the same size. . My input size is (1,55,46,46) but i dont know why i am getting [1, 55, 47, 47] and unable to change it to (1,55,46,46)?

class AutoEncoder(nn.Module):
  def __init__(self):
    super(AutoEncoder, self).__init__()
    self.encoder = nn.Sequential(
            nn.Conv2d(55, 16, 3, stride=1, padding=1),  # b, 16, 10, 10
            nn.ReLU(True),
            nn.MaxPool2d(2, stride=1),  # b, 16, 5, 5
            nn.Conv2d(16, 8, 3, stride=1, padding=1),  # b, 8, 3, 3
            nn.ReLU(True),
            nn.MaxPool2d(2, stride=1)  # b, 8, 2, 2
        )
    self.decoder = nn.Sequential(
            nn.ConvTranspose2d(8, 16, 3, stride=1),  # b, 16, 5, 5
            nn.ReLU(True),
            nn.ConvTranspose2d(16, 8, 5, stride=1, padding=1),  # b, 8, 15, 15
            nn.ReLU(True),
            nn.ConvTranspose2d(8, 55, 2, stride=1, padding=1),  # b, 1, 28, 28
            nn.Tanh()
        )
  def forward(self, x):
    x = self.encoder(x)
    print(x.shape)
    x = self.decoder(x)
    print(x.shape)
    return x
  • Your padding is incompatible with kernel size and stride. – Shai Mar 04 '22 at 06:38
  • @RabeeQasem `(1,55,46,46)` this is the shape –  Mar 04 '22 at 07:57
  • I used a random tensor like `x=torch.rand(1,55,46,46)` and i send it to the `forward` function and i didn't received any warning or errors the code works fine :/ – noob Mar 04 '22 at 07:58
  • if you like the output to be (1,55,46,46) you need to change the final layer in the `decode` function to this `nn.ConvTranspose2d(8, 55, 1, stride=1, padding=1), ` i hope this is you what you need – noob Mar 04 '22 at 08:02
  • @RabeeQasem Yes its working but i am expecting the same shape from the decoder. So when i actually run it i am receiving this shape `(torch.Size([1, 55, 47, 47]))`. with your `nn.ConvTranspose2d(8, 55, 1, stride=1, padding=1)` modification i am receiving `torch.Size([1, 55, 19, 19])` shape. But i am expecting this shape `(1,55,46,46)` from the decoder output –  Mar 04 '22 at 08:09

0 Answers0