Pytorch - Functional Interpolate mixing channels

Hello everyone,

I have the following issue regarding the use of functional interpolate in pytorch(my version is 1.7.1, running on Windows):

I want to downsample an image, on a scale factor of 2.
The tensor of the original has the shape: [1 x 3 x 128 x 256]

The result of the interpolate is the following:

The tensor of the downsampled image has expected shape: [1 x 3 x 64 x 128]
But the result seems all “mixed” up. It seems as its trying to draw each of the channels individually in the image.

The code that does this is as it follows(even changing the align_corners parameters isnt doing much):

    def scaling_pyramid(self, img, num_scales):
        scaled_imgs = []
        s = img.size()
        h = s[2]
        w = s[3]
        for i in range(num_scales):
            ratio = 2 ** (i + 1)
            nh = h // ratio
            nw = w // ratio
            print(img[0, :, :, :])
            scaled_imgs.append(torch.nn.functional.interpolate(img, size=[nh, nw], mode="bilinear", align_corners=False))
            print(scaled_imgs[i][0, :, :, :])
            current_tensor = scaled_imgs[i][0, :, :, :]
            show_scaling_image = current_tensor.resize_(current_tensor.shape[1], current_tensor.shape[2], current_tensor.shape[0]).cpu().numpy()
        return scaled_imgs

Any hints / help will be greatly appreaciated!

Since im new, i cannot post 2 pieces of media on the post…

So, in this reply, I attach the original image.


I assume that the resize_ operation fails in:


and creates an interleaved tensor.
Print the shape of current_tensor before applying this operation and make sure that you permute the dimensions properly before resizing the tensor.