Resize is not consistent with the new torchvision `read_image`

Hey,
I am trying to move my code to the new torchvsion API that uses read_image to torchscript my preprocessing with the model.
But…
I found that the resize method on a PIL image is different that the resize method now on the tensor_image. Maybe I am missing something, what I am doing on the model now is:

        self.transforms = nn.Sequential(
            T.Resize([192, 256]), 
            T.ConvertImageDtype(torch.float),
            T.Normalize([0.485, 0.456, 0.406], [0.229, 0.224, 0.225])
        )

As you can see, it appears that the resizing on the torch tensor is coarser.


So if my model was trained using the old API with PIL, it produces weird reults on this coarser images.
This is very similar to opencv.imread no antialising method.
PD: The cast methods are just to show the tensors, this comes from fastai. :laughing:

Could you explicitly set the interpolation argument to a value and check the results again, please?
Based on this line of code it seems that different interpolation methods might have been introduces ~3 months ago for tensors, so you might want to update to the nightly release.

In older versions I guess only the nearest neighbor interpolation might have been used for tensors.

Thanks @ptrblck !
But I have already tried, and the results are equivalent.
I was hoping that bilinear was equivalent to PIL bilinear.
I found this issue: In transforms.Resize, tensor interpolate is not the same as PIL resize. · Issue #2950 · pytorch/vision · GitHub
I am currently preparing a blog post about this here

1 Like