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
🌐
Reddit
reddit.com › r/pytorch › resize 3d tensor
r/pytorch on Reddit: Resize 3d tensor
July 22, 2023 -

I want to resize my [512,512,96] tensor to [64,64,64]. Torchvision.transoforms.Resize only works with the last two dimensions

image = T.Resize(64)(image) turns torch.Size([512, 512, 96]) to torch.Size([512, 341, 64]) ???(no idea where the 341)

image = T.Resize((64,64))(image) turns torch.Size([512, 512, 96]) to torch.Size([512, 64, 64]) .

image = T.Resize((64,64,64))(image) throws this error

If size is a sequence, it should have 1 or 2 values

Any ideas, besides iterating over all the images in a for loop and concatenating them

Getting Better at Tensor Dimensions with PyTorch Mar 23, 2024
r/deeplearning
2y ago
Getting Better at Dimensions with PyTorch Mar 23, 2024
r/pytorch
2y ago
[P] PyTorch Tutorial Updated (14 examples + TensorBoard) May 28, 2017
r/MachineLearning
9y ago
A torchvision transforms visualizer Apr 8, 2021
r/computervision
5y ago
More results from reddit.com
Discussions

Pytorch resize 3d numpy array
Dear all, I have 3d image and I would like to write a dataloader with a rescale trasformation . What is the best way to do the rescaling? I have [240,240,180] I would like to trasform [128,128,128]. Any suggestion on function for dataloader. Thanks so much class Resize(object): def __init__(self, ... More on discuss.pytorch.org
🌐 discuss.pytorch.org
7
1
February 19, 2020
python - Resize PyTorch Tensor - Stack Overflow
If not the case, the in-place resize_ ... = t.data.resize_(1,2,3). ... Find the answer to your question by asking. Ask question ... See similar questions with these tags. ... New site design and philosophy for Stack Overflow: Starting February 24, 2026... ... 2 PyTorch: The number of sizes provided (0) must be greater or equal to the number of dimensions in the tensor ... More on stackoverflow.com
🌐 stackoverflow.com
Resizing the ground truth of 3D CT scan
How can I resize a 3D image tensor of size 143 x 512 x 512 to 143 x 256 x 256? More on discuss.pytorch.org
🌐 discuss.pytorch.org
7
0
April 5, 2021
Reshape 3D Pytorch Tensor
Hi, So I have a Pytorch Tensor of size [4055, 4, 80]. Now I would like to get a resultant Pytorch tensor of size [4055, (4*80)] or [4055, 320]. How can I do that? More on discuss.pytorch.org
🌐 discuss.pytorch.org
1
0
April 26, 2022
🌐
GeeksforGeeks
geeksforgeeks.org › how-to-resize-a-tensor-in-pytorch
How to resize a tensor in PyTorch? - GeeksforGeeks
March 23, 2022 - # import torch library import torch # define a tensor tens = torch.Tensor([10, 20, 30, 40, 50]) # display tensor and it's size print("\n Original Tensor: ", tens) # Squeeze the tensor in dimension 1 tens_1 = torch.unsqueeze(tens, dim=1) print("\n After resize tensor to 5x1: \n", tens_1) ... In this article, we will discuss how to Slice a 3D Tensor in Pytorch.
🌐
PyTorch Forums
discuss.pytorch.org › vision
Pytorch resize 3d numpy array - vision - PyTorch Forums
February 19, 2020 - Dear all, I have 3d image and I would like to write a dataloader with a rescale trasformation . What is the best way to do the rescaling? I have [240,240,180] I would like to trasform [128,128,128]. Any suggestion on function for dataloader. Thanks so much class Resize(object): def __init__(self, output_size): assert isinstance(output_size, (int, tuple)) self.output_size = output_size def __call__(self, sample): image, label = sample["data"], sample["l...
🌐
TutorialsPoint
tutorialspoint.com › how-to-resize-a-tensor-in-pytorch
How to resize a tensor in PyTorch?
November 6, 2021 - To resize a PyTorch tensor, we use the .view() method.
🌐
PyTorch Forums
discuss.pytorch.org › t › reshape-3d-pytorch-tensor › 150074
Reshape 3D Pytorch Tensor - PyTorch Forums
April 26, 2022 - Hi, So I have a Pytorch Tensor of size [4055, 4, 80]. Now I would like to get a resultant Pytorch tensor of size [4055, (4*80)] or [4055, 320]. How can I do that?
Find elsewhere
🌐
Tutorial Reference
tutorialreference.com › python › examples › faq › python-pytorch-how-to-resize-a-tensor
Python PyTorch: How to Resize a Tensor in PyTorch | Tutorial Reference
Avoid resize_() unless you have a specific low-level need - it can create tensors with uninitialized garbage data. Use -1 in any dimension to let PyTorch calculate the size automatically.
🌐
DEV Community
dev.to › hyperkai › resize-in-pytorch-47j7
Resize in PyTorch - DEV Community
May 16, 2025 - A tensor must be 3D or more D. Don't use img=. v2 is recommended to use according to V1 or V2? Which one should I use?. from torchvision.datasets import OxfordIIITPet from torchvision.transforms.v2 import Resize from torchvision.transforms.functional import InterpolationMode r = Resize(size=100) r = Resize(size=100, interpolation=InterpolationMode.BILINEAR, max_size=None, antialias=True) r # Resize(size=[100], interpolation=InterpolationMode.BILINEAR, # antialias=True) r.size # [100] r.interpolation # <InterpolationMode.BILINEAR: 'bilinear'> print(r.max_size) # None r.antialias # True origin_data = OxfordIIITPet( root="data", transform=None ) s1000_data = OxfordIIITPet( # `s` is size.
🌐
GeeksforGeeks
geeksforgeeks.org › reshaping-a-tensor-in-pytorch
Reshaping a Tensor in Pytorch - GeeksforGeeks
September 1, 2021 - Method 1: Using view() method We can resize the tensors in PyTorch by using the view() m ... A Pytorch Tensor is basically the same as a NumPy array. This means it does not know anything about deep learning or computational graphs or gradients ...
🌐
Python Guides
pythonguides.com › pytorch-resize-images
How To Resize Images In PyTorch - Python Guides
June 19, 2025 - This method is extremely powerful when working with batches of images already loaded as tensors. It’s the approach I typically use in production systems. ... The quality of resized images can vary significantly based on the interpolation method. PyTorch offers several options:
🌐
Medium
medium.com › @amit25173 › expert-guide-to-resizing-pytorch-tensors-b88d3f34a76b
Expert Guide to Resizing PyTorch Tensors | by Amit Yadav | Medium
February 9, 2025 - A tensor is “contiguous” if these data points are stored sequentially, which makes resizing more efficient. If it’s non-contiguous, reshaping can be trickier and slower because PyTorch needs to create a new memory layout, especially with operations like view() that rely on continuity.
🌐
PyTorch
docs.pytorch.org › vision › main › generated › torchvision.transforms.functional.resize.html
resize — Torchvision main documentation
Resize the input image to the given size. If the image is torch Tensor, it is expected to have […, H, W] shape, where …
🌐
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 ...
🌐
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 ...