It seems like you are looking for interpolate (a function in nn.functional):

import torch.nn.functional as nnf

x = torch.rand(5, 1, 44, 44)
out = nnf.interpolate(x, size=(224, 224), mode='bicubic', align_corners=False)

If you really care about the accuracy of the interpolation, you should have a look at ResizeRight: a pytorch/numpy package that accurately deals with all sorts of "edge cases" when resizing images. This can have an effect when directly merging features of different scales: inaccurate interpolation may result in misalignments.

Answer from Shai on Stack Overflow
🌐
GitHub
github.com › pytorch › vision › issues › 2950
In transforms.Resize, tensor interpolate is not the same as PIL resize. · Issue #2950 · pytorch/vision
November 3, 2020 - Resize supports tensors by F.interpolate, but the behavior is not the same as Pillow resize. vision/torchvision/transforms/functional.py · Lines 309 to 312 in f95b053 ·
Author: pytorch
🌐
PyTorch Forums
discuss.pytorch.org › vision
How to do image resizing with bilinear interpolation using torch tensor on CUDA? - vision - PyTorch Forums
June 24, 2021 - Hi all, I was wondering whether has anyone done bilinear interpolation resizing with PyTorch Tensor under CUDA? I tried this using torch.nn.functional.F.interpolate(rgb_image,(size,size)) and it works to resize the RGB image tensor shape ...
🌐
PyTorch
docs.pytorch.org › vision › main › generated › torchvision.transforms.Resize.html
Resize — Torchvision main documentation
interpolation (InterpolationMode) – Desired interpolation enum defined by torchvision.transforms.InterpolationMode. Default is InterpolationMode.BILINEAR. If input is Tensor, only InterpolationMode.NEAREST, InterpolationMode.NEAREST_EXACT, InterpolationMode.BILINEAR and InterpolationMode.BICUBIC are supported. The corresponding Pillow integer constants, e.g. PIL.Image.BILINEAR are accepted as well. max_size (int, optional) – The maximum allowed for the longer edge of the resized image.
🌐
Readthedocs
torcheeg.readthedocs.io › en › v1.0.11 › _modules › torcheeg › transforms › torch › resize.html
torcheeg.transforms.torch.resize — torcheeg 1.0.11 documentation
''' return super().__call__(*args, eeg=eeg, baseline=baseline, **kwargs) def apply(self, eeg: torch.Tensor, **kwargs) -> torch.Tensor: assert eeg.dim() == 3, f'The Resize only allows to input a 3-d tensor, but the input has dimension {eeg.dim()}' eeg = eeg.unsqueeze(0) align_corners = False if self.interpolation in ["bilinear", "bicubic"] else None interpolated_x = interpolate(eeg, size=self.size, mode=self.interpolation, align_corners=align_corners) return interpolated_x.squeeze(0) @property def repr_body(self) -> Dict: return dict(super().repr_body, **{'size': self.size, 'interpolation': self.interpolation}) Access comprehensive developer documentation for PyTorch View Docs ·
🌐
PyTorch
docs.pytorch.org › vision › 0.16 › generated › torchvision.transforms.Resize.html
Resize — Torchvision 0.16 documentation
interpolation (InterpolationMode) – Desired interpolation enum defined by torchvision.transforms.InterpolationMode. Default is InterpolationMode.BILINEAR. If input is Tensor, only InterpolationMode.NEAREST, InterpolationMode.NEAREST_EXACT, InterpolationMode.BILINEAR and InterpolationMode.BICUBIC are supported. The corresponding Pillow integer constants, e.g. PIL.Image.BILINEAR are accepted as well. max_size (int, optional) – The maximum allowed for the longer edge of the resized image.
🌐
PyTorch
docs.pytorch.org › vision › 0.15 › generated › torchvision.transforms.functional.resize.html
resize — Torchvision 0.15 documentation
torchvision.transforms.functional.resize(img: Tensor, size: List[int], interpolation: InterpolationMode = InterpolationMode.BILINEAR, max_size: Optional[int] = None, antialias: Optional[Union[str, bool]] = 'warn') → Tensor[source]¶
🌐
PyTorch
docs.pytorch.org › vision › 0.12 › generated › torchvision.transforms.functional.resize.html
resize — Torchvision 0.12 documentation
torchvision.transforms.functional.resize(img: torch.Tensor, size: List[int], interpolation: torchvision.transforms.functional.InterpolationMode = <InterpolationMode.BILINEAR: 'bilinear'>, max_size: Optional[int] = None, antialias: Optional[bool] = None) → torch.Tensor[source]¶
🌐
Readthedocs
torcheeg.readthedocs.io › en › v1.0.10 › _modules › torcheeg › transforms › torch › resize.html
torcheeg.transforms.torch.resize — torcheeg 1.0.10 documentation
''' return super().__call__(*args, eeg=eeg, baseline=baseline, **kwargs) def apply(self, eeg: torch.Tensor, **kwargs) -> torch.Tensor: assert eeg.dim() == 3, f'The Resize only allows to input a 3-d tensor, but the input has dimension {eeg.dim()}' eeg = eeg.unsqueeze(0) align_corners = False if self.interpolation in ["bilinear", "bicubic"] else None interpolated_x = interpolate(eeg, size=self.size, mode=self.interpolation, align_corners=align_corners) return interpolated_x.squeeze(0) @property def repr_body(self) -> Dict: return dict(super().repr_body, **{'size': self.size, 'interpolation': self.interpolation}) Access comprehensive developer documentation for PyTorch View Docs ·
Find elsewhere
🌐
Mlverse
torchvision.mlverse.org › reference › transform_resize.html
Resize the input image to the given size — transform_resize • torchvision
If size is a sequence like c(h, w), output size will be matched to this. If size is an int, smaller edge of the image will be matched to this number. i.e, if height > width, then image will be rescaled to (size * height / width, size). ... (int, optional) Desired interpolation...
🌐
PyTorch
docs.pytorch.org › vision › 0.13 › generated › torchvision.transforms.functional.resize.html
resize — Torchvision 0.13 documentation
torchvision.transforms.functional.resize(img: torch.Tensor, size: List[int], interpolation: torchvision.transforms.functional.InterpolationMode = <InterpolationMode.BILINEAR: 'bilinear'>, max_size: Optional[int] = None, antialias: Optional[bool] = None) → torch.Tensor[source]¶
🌐
Python Guides
pythonguides.com › pytorch-resize-images
How To Resize Images In PyTorch - Python Guides
June 19, 2025 - When I need more control or want to resize batches of images directly as tensors, I use the functional API: import torch import torch.nn.functional as F from torchvision import transforms from PIL import Image # Step 1: Load an image using PIL img = Image.open(r'C:\Users\Public\grand_canyon.jpg') # Replace path as needed # Step 2: Convert image to tensor to_tensor = transforms.ToTensor() img_tensor = to_tensor(img) # Shape: [C, H, W] # Step 3: Add batch dimension for interpolate (needed shape: [N, C, H, W]) batched_tensor = img_tensor.unsqueeze(0) # Shape: [1, C, H, W] # Step 4: Resize the image tensor using bilinear interpolation resized_tensor = F.interpolate(batched_tensor, size=(224, 224), mode='bilinear', align_corners=False) print(f"Resized tensor shape: {resized_tensor.shape}")
🌐
Medium
medium.com › @amit25173 › expert-guide-to-resizing-pytorch-tensors-b88d3f34a76b
Expert Guide to Resizing PyTorch Tensors | by Amit Yadav | Medium
February 9, 2025 - When resizing images, especially for models like CNNs, interpolation techniques help preserve the integrity of the data. torch.nn.functional.interpolate offers methods such as nearest, bilinear, and bicubic interpolation, each suited to different ...
🌐
Chsasank
chsasank.com › vision › transforms.html
Transforms — Torchvision master documentation
class torchvision.transforms.RandomResizedCrop(size, interpolation=2)[source]¶ · Crop the given PIL Image to random size and aspect ratio. A crop of random size of (0.08 to 1.0) of the original size and a random aspect ratio of 3/4 to 4/3 of the original aspect ratio is made.
🌐
PyTorch Forums
discuss.pytorch.org › t › inplace-resizing-with-interpolation-options › 204132
Inplace resizing with interpolation options - PyTorch Forums
June 5, 2024 - Hi, I am working on a deployment server where I want to resize a bunch of images to a fixed size. The problem is that I don’t want to create a new tensor when doing interpolation/resizing since it requires a memory allocation and it will have to reassign the values to the ‘images’ tensor.
🌐
PyTorch
docs.pytorch.org › vision › 0.18 › generated › torchvision.transforms.Resize.html
Resize — Torchvision 0.18 documentation
interpolation (InterpolationMode) – Desired interpolation enum defined by torchvision.transforms.InterpolationMode. Default is InterpolationMode.BILINEAR. If input is Tensor, only InterpolationMode.NEAREST, InterpolationMode.NEAREST_EXACT, InterpolationMode.BILINEAR and InterpolationMode.BICUBIC are supported. The corresponding Pillow integer constants, e.g. PIL.Image.BILINEAR are accepted as well. max_size (int, optional) – The maximum allowed for the longer edge of the resized image.
🌐
PyTorch
docs.pytorch.org › vision › 0.22 › generated › torchvision.transforms.Resize.html
Resize — Torchvision 0.22 documentation
interpolation (InterpolationMode) – Desired interpolation enum defined by torchvision.transforms.InterpolationMode. Default is InterpolationMode.BILINEAR. If input is Tensor, only InterpolationMode.NEAREST, InterpolationMode.NEAREST_EXACT, InterpolationMode.BILINEAR and InterpolationMode.BICUBIC are supported. The corresponding Pillow integer constants, e.g. PIL.Image.BILINEAR are accepted as well. max_size (int, optional) – The maximum allowed for the longer edge of the resized image.
🌐
DEV Community
dev.to › hyperkai › resize-in-pytorch-47j7
Resize in PyTorch - DEV Community
May 16, 2025 - If it's True(Default) and interpolation is BILINEAR or BICUBIC, anti-aliasing is applied for both a PIL image and tensor.
🌐
PyTorch
docs.pytorch.org › vision › stable › generated › torchvision.transforms.Resize.html
Resize — Torchvision 0.27 documentation
interpolation (InterpolationMode) – Desired interpolation enum defined by torchvision.transforms.InterpolationMode. Default is InterpolationMode.BILINEAR. If input is Tensor, only InterpolationMode.NEAREST, InterpolationMode.NEAREST_EXACT, InterpolationMode.BILINEAR and InterpolationMode.BICUBIC are supported. The corresponding Pillow integer constants, e.g. PIL.Image.BILINEAR are accepted as well. max_size (int, optional) – The maximum allowed for the longer edge of the resized image.
🌐
PyTorch
docs.pytorch.org › vision › 0.17 › generated › torchvision.transforms.functional.resize.html
resize — Torchvision 0.17 documentation
torchvision.transforms.functional.resize(img: Tensor, size: List[int], interpolation: InterpolationMode = InterpolationMode.BILINEAR, max_size: Optional[int] = None, antialias: Optional[bool] = True) → Tensor[source]¶