Torchvision.transforms.functional.resize bilinear incorrect results

Hi there,

torchvision.transforms.functional.resize bilinear produces a result that does not match with the bilinear algorithm nor does it match with tf.image.resizeBilinear. I tried with multiple test cases, yet I always keep getting the wrong resize results. Perhaps there is something I’m missing? Thanks.

You might need to enable the antialias argument to reduce the error between torchvision and PIL:

x = torch.randint(0, 256, (3, 224, 224)).byte()

out = torchvision.transforms.functional.resize(
    x,
    size=(100, 100),
    interpolation=torchvision.transforms.functional.InterpolationMode.BILINEAR,
    antialias=True
)

img = torchvision.transforms.functional.to_pil_image(x)
ref = img.resize(size=(100, 100), resample=PIL.Image.Resampling.BILINEAR)
ref = torch.from_numpy(np.array(ref)).permute(2, 0, 1)

print((ref.float() - out.float()).abs().max())
# tensor(1.)