pytorch / pytorch/vision

Input checks for interpolation parameter

Open
#7,192 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
17.9k
Forks
7.3k
Avg merge
1d 15h
Merged PRs (30d)
13

Description

After #7176, we no longer warn and coerce integer inputs for interpolation into our enum. This means, passing an int will just fail down the line:

import torch
from torchvision import transforms

transform = transforms.Resize(size=(32, 64), interpolation=0)

transform(torch.rand(3, 256, 128))
Traceback (most recent call last):
  File "/home/philip/git/pytorch/vision/main.py", line 6, in <module>
    transform(torch.rand(3, 256, 128))
  File "/home/philip/.conda/envs/pytorch-vision-dev/lib/python3.8/site-packages/torch/nn/modules/module.py", line 1488, in _call_impl
    return forward_call(*args, **kwargs)
  File "/home/philip/git/pytorch/vision/torchvision/transforms/transforms.py", line 336, in forward
    return F.resize(img, self.size, self.interpolation, self.max_size, self.antialias)
  File "/home/philip/git/pytorch/vision/torchvision/transforms/functional.py", line 430, in resize
    raise TypeError("Argument interpolation should be a InterpolationMode")
TypeError: Argument interpolation should be a InterpolationMode

(Note that it is failing in the functional rather in the transforms part)

However, the above is only true for transforms v1. We don't have any such checks for transforms v2:

import torch
from torchvision.prototype import transforms

transform = transforms.Resize(size=(32, 64), interpolation=0)

transform(torch.rand(3, 256, 128))
Traceback (most recent call last):
  File "/home/philip/git/pytorch/vision/main.py", line 6, in <module>
    transform(torch.rand(3, 256, 128))
  File "/home/philip/.conda/envs/pytorch-vision-dev/lib/python3.8/site-packages/torch/nn/modules/module.py", line 1488, in _call_impl
    return forward_call(*args, **kwargs)
  File "/home/philip/git/pytorch/vision/torchvision/prototype/transforms/_transform.py", line 40, in forward
    flat_outputs = [
  File "/home/philip/git/pytorch/vision/torchvision/prototype/transforms/_transform.py", line 41, in <listcomp>
    self._transform(inpt, params) if check_type(inpt, self._transformed_types) else inpt for inpt in flat_inputs
  File "/home/philip/git/pytorch/vision/torchvision/prototype/transforms/_geometry.py", line 69, in _transform
    return F.resize(
  File "/home/philip/git/pytorch/vision/torchvision/prototype/transforms/functional/_geometry.py", line 243, in resize
    return resize_image_tensor(inpt, size, interpolation=interpolation, max_size=max_size, antialias=antialias)
  File "/home/philip/git/pytorch/vision/torchvision/prototype/transforms/functional/_geometry.py", line 170, in resize_image_tensor
    mode=interpolation.value,
AttributeError: 'int' object has no attribute 'value'

We won't get silent bugs here, but it is still worth it to have an expressive error message. Especially since int was allowed before.

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 with torchvision/transforms/functional.py and the prototype transform paths shown in the trace, especially _geometry.py and _geometry functions handling Resize interpolation. Compare how v1 and v2 validate the interpolation argument, then make invalid integer input produce an expressive error in both paths and verify the affected Resize behavior with the existing transform tests.

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
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.