#8141·vision

`to_pil_image` rounds down

Author: rb-synthCreated Dec 4, 2023Updated Sep 5, 2026

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.

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

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

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

Versions

N/A