F::interpolate get wrong result using libtorch 1.71

while using libtorch 1.71 to resize feature, I found that F::interpolate would get the wrong result which is different with pytorch 1.71.

Here is my libtorch code.

cv::Mat image = cv::imread("/home/lll/Pictures/test.jpg");

torch::Tensor image_tensor = torch::from_blob(image.data, {image.rows, image.cols, 3}, torch::kByte);

image_tensor = image_tensor.permute({2, 0, 1}).toType(torch::kFloat).div_(255);
image_tensor = image_tensor.unsqueeze(0);
image_tensor = image_tensor.to(torch::kCUDA);

namespace F = torch::nn::functional;
image_tensor = F::interpolate(
                .size(std::vector<int64_t>({256, 256}))
image_tensor = image_tensor.mul(0.5).add(0.5).mul(255);
image_tensor = image_tensor.squeeze(0).permute({1, 2, 0}).toType(torch::kByte).to(torch::kCPU);

cv::Mat test_mat(256, 256, CV_8UC3);
std::memcpy((void *) test_mat.data, image_tensor.data_ptr(), sizeof(torch::kU8) * image_tensor.numel());
cv::imshow("test", test_mat);

Here is my pytorch code.

_transforms = transforms.Compose([
transforms.Normalize((0.5, 0.5, 0.5), (128 / 255., 128 / 255., 128 / 255.))])
image = cv2.imread("/home/lll/Pictures/test.jpg")

image = torch.from_numpy(image)
image = image.permute(2, 0, 1)
image = image.unsqueeze(0)
image = image.float()

image = _transforms(image)

image = F.interpolate(image, size=(256, 256), mode='bilinear', align_corners=True)
image = image.squeeze(0).permute(1, 2, 0)

image = image * 0.5 + 0.5
image = image.byte()
cv2.imshow("test", image.numpy())

I using opencv to visualize the result.
This is the original image
and this is the worng result.It seems to split the channels and merge them into a single image
This is the correct result witch I want

Strangely enough, when I use Libtorch 1.4.0 with the same code,I could get the right results.
If you could help me I will appreciate it.

Based on the output it looks like the permutation failed in the libtorch example, but it looks correct to me (at least you are permuting it to channels-first, interpolate, and back to channels-last).

Thank you for your reply,
according to your hints I check the size of image before interpolate is (1,3,W,H), and the output feature size is (1,3,512,512), it looks the same on the pytorch side.
Also, when I use torch.jit.trace and save to conver pytoch model to libtorch model which has F.interpolate in the model, the wrong result comes up again,I couldn’t solve it at all, because all model layers are compressed into a single file.

I suspect if there’s some problem with the interpolate function but I am not able to find the problem in the source code.
When I went back to 1.4.0, all the errors were gone and everything was back to normal using the same code.

Sloved! ref thanks ngimel and ptrblck.