Solution 23
Resize_ function in Pytorch distorts the image
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