pytorch / pytorch/vision

transforms.functional.resize broken for (h,w) tensors

Open
#7,293 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

module: documentation module: transforms needs discussion
Dominant language
Python
Stars
17.9k
Forks
7.3k
Avg merge
1d 15h
Merged PRs (30d)
13

Description

🐛 Describe the bug

torchvision version: linux condaforge '0.13.1+cu113'

import torch
import torchvision

# Breaks
"""
ValueError: Input and output must have the same number of spatial dimensions, but got input with with spatial dimensions of [640] and output size of [960, 1280]. Please provide input tensor in (N, C, d1, d2, ...,dK) format and output size in (o1, o2, ...,oK) format.
"""
a = torch.zeros((480, 640))
a = torchvision.transforms.functional.resize(a, (2 * 480, 2 * 640))
print(a.shape)

# Works
b = torch.zeros((480, 640))
b = b.unsqueeze(0)
print(b.shape)
b = torchvision.transforms.functional.resize(b, (2 * 480, 2 * 640))
print(b.shape)
Versions
wget https://raw.githubusercontent.com/pytorch/pytorch/master/torch/utils/collect_env.py
# For security purposes, please check the contents of collect_env.py before running it.
python collect_env.py

cc @vfdev-5

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at the torchvision.transforms.functional.resize entry point and run the issue's two tensor examples to reproduce the differing behavior. Check the existing resize handling for a two-dimensional (h, w) tensor; done means the first example resizes successfully to the expected dimensions without requiring an added dimension.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
computer-vision
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.