← Back to list

Solution 23

Resize_ function in Pytorch distorts the image

Talha Hanif Butt · 2026-02-22 14:06 · 0 claps · 0.3 min read
#resize-images #pytorch #pil #transformation #distortion
Open on Medium ↗
Wiki topics: ML · Machine Learning

Solution 23

Resize_ function in Pytorch distorts the image

I recently used resize_ function in pytorch but realized that it distorts the image. The solution to it is as follows:

import torchvision.transforms as T
transform = T.ToPILImage()
img = transform(img)
img = img.resize((48, 48), Image.BICUBIC)
transform = T.ToTensor()
img = transform(img)

Basically, instead of applying resize operation directly on the tensor, convert it into PIL image, resize it and then again convert it into a tensor, this way the image doesn’t get distorted.


메타데이터
post_id
3fcbcdc5d023
slug
solution-23-3fcbcdc5d023
url
https://medium.com/@thanifbutt/solution-23-3fcbcdc5d023
canonical_url
https://medium.com/@thanifbutt/solution-23-3fcbcdc5d023
author_url
https://medium.com/@thanifbutt
status
ok
fetched_at
2026-06-26 03:39:16