`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.
>>> torch.as_tensor([0.9999]).mul(255).byte().item()
254I would suggest that the code be: pic = pic.mul(255).round().byte():
>>> torch.as_tensor([0.9999]).mul(255).round().byte().item()
255Versions
N/A
Source: pytorch/vision