Why does torch.nn.Upsample return a junk image?
When I execute the code segment below, nn.Upsample seems to be completely destroying my image. Am I applying it in the wrong way?
import torch
import imageio
import torch.nn as nn
from matplotlib import pyplot as plt

small = imageio.imread('small.png')                               # shape 200, 390, 4
small_reshaped = small.reshape(4, 200, 390)                       # shape 4, 200, 390
batch = torch.as_tensor(small_reshaped).unsqueeze(0)              # shape 1, 4, 200, 390
ups = nn.Upsample((500, 970))
upsampled_batch = ups(batch)                                      # shape 1, 4, 500, 970
upsampled_small = upsampled_batch[0].reshape(500, 970, 4)         # shape 500, 970, 4
plt.imshow(small)
plt.imshow(upsampled_small)
plt.show()

Before upsampling:

After upsampling:

Original image (small.png):


Resolved it. Reshaping destroys the image. I should have transposed instead.
See https://discuss.pytorch.org/t/for-beginners-do-not-use-view-or-reshape-to-swap-dimensions-of-tensors/75524 for more details.
A working solution:
...
small_reshaped = small.transpose(2, 0, 1)                          # shape 4, 200, 390
...
upsampled_small = upsampled_batch[0].transpose(0,1).transpose(1,2) # shape 500, 970, 4
...

