pytorch / pytorch/vision

Rotation sampling grid is undesireably low-res

Open Beginner friendly
#9,029 4 comments 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

🐛 Describe the bug

https://github.com/pytorch/vision/blob/f799a5348d990de02f9189d9496f369bacfe5cf3/torchvision/transforms/_functional_tensor.py#L594

This function that creates the resampling grid will use the default tensor dtype. If this is bfloat16/float16 and the image is sufficiently large (over 250x250 px), this results in significant quantizing that seems undesirable. The output will look extremely subsampled from the original. This would not occur if the dtype was higher precision.

My suggestion would be to update these linspace to either be dtype=theta.dtype or explicitly dtype=torch.float32 to prevent this from happening.

Versions

Current

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 in torchvision/transforms/_functional_tensor.py around line 594, where the resampling grid is created with linspace. Reproduce the rotation behavior using bfloat16 or float16 on an image larger than 250x250 pixels, then verify the grid avoids the reported quantization and the output is no longer visibly subsampled.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
computer-vision
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Active
Clarity
Clearly specified
Newbie friendliness
78/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.