Errors related to torch.nn.Upsample

Hi, I have an image with size of 3 * 500 * 500 (channel *width *height). I want to use torch.nn.Upsample to resize this image into the one with size of 3 * 256 * 256. but when I use the folowing code:
upsample = torch.nn.Upsample(256)
image = upsample(image)
it returned an image with size of 3 * 500 * 256
can anybody tell me how to fix this problem?

Your input is most likely missing the batch dimension so that [3, 500, 500] would be treated as a temporal signal with [batch_size=3, channels=500, seq_len=500]. unsqueeze the batch dimension and it should work:

image = torch.randn(3, 500, 500)
upsample = torch.nn.Upsample(256)
image = upsample(image)
print(image.shape)
# > torch.Size([3, 500, 256])

image = torch.randn(1, 3, 500, 500)
upsample = torch.nn.Upsample(256)
image = upsample(image)
print(image.shape)
# > torch.Size([1, 3, 256, 256])