-
Notifications
You must be signed in to change notification settings - Fork 7.2k
Fix bug of changing input tensor in utils.save_image #1244
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
The original code will change the image tensor passed in by multiplying it by 255. The PR fixes that.
related to #1206 |
torchvision/utils.py
Outdated
**kwargs: Other arguments are documented in ``make_grid``. | ||
""" | ||
from PIL import Image | ||
tensor = tensor.clone() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of cloning the tensor, I agree with @fmassa that replacing the in-place operations is the better choice here, since it is unclear why they are used in the first place.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see, let me change the PR
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
Codecov Report
@@ Coverage Diff @@
## master #1244 +/- ##
==========================================
- Coverage 65.64% 65.09% -0.55%
==========================================
Files 74 74
Lines 5784 5785 +1
Branches 884 884
==========================================
- Hits 3797 3766 -31
- Misses 1723 1741 +18
- Partials 264 278 +14
Continue to review full report at Codecov.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
The original code of torchvision.utils.save_image will change the image tensor passed in by multiplying it by 255. The PR fixes that.
Sample code to reproduce the bug:
import torch
from torchvision.utils import save_image
img = torch.ones((5, 3, 64, 64))
save_image(img[0], 'dummy.jpg')
print(torch.max(img))