Skip to content

Conversation

buoyancy99
Copy link
Contributor

@buoyancy99 buoyancy99 commented Aug 16, 2019

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))

The original code will change the image tensor passed in by multiplying it by 255. The PR fixes that.
@pmeier
Copy link
Collaborator

pmeier commented Aug 16, 2019

related to #1206

**kwargs: Other arguments are documented in ``make_grid``.
"""
from PIL import Image
tensor = tensor.clone()
Copy link
Collaborator

@pmeier pmeier Aug 16, 2019

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.

Copy link
Contributor Author

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@buoyancy99 buoyancy99 changed the title Fix bug of changing input tensor in function Fix bug of changing input tensor in utils.save_image Aug 16, 2019
@codecov-io
Copy link

Codecov Report

Merging #1244 into master will decrease coverage by 0.54%.
The diff coverage is 100%.

Impacted file tree graph

@@            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
Impacted Files Coverage Δ
torchvision/utils.py 66.03% <100%> (+0.65%) ⬆️
torchvision/datasets/cifar.py 71.26% <0%> (-6.9%) ⬇️
torchvision/datasets/folder.py 79.48% <0%> (-2.57%) ⬇️
torchvision/transforms/transforms.py 79.17% <0%> (-2.36%) ⬇️
torchvision/transforms/functional.py 69.07% <0%> (-2.32%) ⬇️
torchvision/datasets/voc.py 20.87% <0%> (-2.2%) ⬇️
torchvision/datasets/lsun.py 20.83% <0%> (-2.09%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 19315e3...796304d. Read the comment docs.

Copy link
Member

@fmassa fmassa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants