Resize is not consistent with the new torchvision `read_image`

tcapelle: <p>Hey,<br>
I am trying to move my code to the new torchvsion API that uses <code>read_image</code> to torchscript my preprocessing with the model.<br>
But…<br>
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:</p>
<pre><code class="lang-auto">        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])
        )
</code></pre>
<p>As you can see, it appears that the resizing on the torch tensor is coarser.<br>
<div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/3X/6/5/656fefc633272c04695dc9b8fa9bb29f92a406e5.png" data-download-href="https://discuss.pytorch.org/uploads/default/656fefc633272c04695dc9b8fa9bb29f92a406e5" title="image"><img src="https://discuss.pytorch.org/uploads/default/optimized/3X/6/5/656fefc633272c04695dc9b8fa9bb29f92a406e5_2_409x500.png" alt="image" data-base62-sha1="etm2X1ClKwvaGmGr9lgYYTq2Y9n" width="409" height="500" srcset="https://discuss.pytorch.org/uploads/default/optimized/3X/6/5/656fefc633272c04695dc9b8fa9bb29f92a406e5_2_409x500.png, https://discuss.pytorch.org/uploads/default/optimized/3X/6/5/656fefc633272c04695dc9b8fa9bb29f92a406e5_2_613x750.png 1.5x, https://discuss.pytorch.org/uploads/default/optimized/3X/6/5/656fefc633272c04695dc9b8fa9bb29f92a406e5_2_818x1000.png 2x" data-dominant-color="BEBCC0"><div class="meta"><svg class="fa d-icon d-icon-far-image svg-icon" aria-hidden="true"><use href="#far-image"></use></svg><span class="filename">image</span><span class="informations">1417×1731 191 KB</span><svg class="fa d-icon d-icon-discourse-expand svg-icon" aria-hidden="true"><use href="#discourse-expand"></use></svg></div></a></div><br>
So if my model was trained using the old API with PIL, it produces weird reults on this coarser images.<br>
This is very similar to opencv.imread no antialising method.<br>
PD: The cast methods are just to show the tensors, this comes from fastai. <img src="https://discuss.pytorch.org/images/emoji/apple/laughing.png?v=12" title=":laughing:" class="emoji" alt=":laughing:" loading="lazy" width="20" height="20"></p>

ptrblck: <p>Could you explicitly set the <code>interpolation</code> argument to a value and check the results again, please?<br>
Based on <a href="https://github.com/pytorch/vision/blob/2e8c124ff7266437efd37c7a23684f64fe6904cd/torchvision/transforms/functional_tensor.py#L482-L483">this line of code</a> 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.</p>
<p>In older versions I guess only the nearest neighbor interpolation might have been used for tensors.</p>

tcapelle: <p>Thanks <a class="mention" href="/u/ptrblck">@ptrblck</a> !<br>
But I have already tried, and the results are equivalent.<br>
I was hoping that bilinear was equivalent to PIL bilinear.<br>
I found this issue: <a href="https://github.com/pytorch/vision/issues/2950" class="inline-onebox" rel="noopener nofollow ugc">In transforms.Resize, tensor interpolate is not the same as PIL resize. · Issue #2950 · pytorch/vision · GitHub</a><br>
I am currently preparing a blog post about this <a href="https://tcapelle.github.io/capeblog/pytorch/fastai/2021/02/26/image_resizing.html" rel="noopener nofollow ugc">here</a></p>