pytorch / pytorch/vision

`to_pil_image` rounds down

Open Beginner friendly
#8,141 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

The current code is: pic = pic.mul(255).byte().

If the input is, say, 0.9999, this will be rounded down to 254 instead of 255.

>>> torch.as_tensor([0.9999]).mul(255).byte().item()
254

I would suggest that the code be: pic = pic.mul(255).round().byte():

>>> torch.as_tensor([0.9999]).mul(255).round().byte().item()
255
Versions

N/A

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 to_pil_image entry point and reproduce the reported conversion with the provided PyTorch example. Inspect the existing tests around this conversion, then verify that an input of 0.9999 produces 255 rather than 254 and that existing behavior remains covered.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.