Skip to content
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

fix save_image when height or width == 1 #1059

Merged
merged 2 commits into from
Jun 26, 2019
Merged

Conversation

trougnouf
Copy link
Contributor

This fixes the save_image function when one of the dimensions is one.

Otherwise error is as follow:

Traceback (most recent call last):
  File "run_nn.py", line 250, in <module>
    torchvision.utils.save_image(batch_x.detach().unsqueeze(2).cpu(), "dbg/%s-x.png"%(dbgtitle))
  File "/home/trougnouf/.local/lib/python3.6/site-packages/torchvision/utils.py", line 103, in save_image
    ndarr = grid.mul_(255).add_(0.5).clamp_(0, 255).permute(1, 2, 0).to('cpu', torch.uint8).numpy()
RuntimeError: number of dims don't match in permute

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 for the PR and the fix!

Could you add a test for it in test_utils.py?

@trougnouf
Copy link
Contributor Author

Done, thank you!

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.

LGTM!

Just waiting for CI to finish and then this is good to merge!

@codecov-io
Copy link

codecov-io commented Jun 26, 2019

Codecov Report

Merging #1059 into master will increase coverage by 0.11%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1059      +/-   ##
==========================================
+ Coverage   63.83%   63.95%   +0.11%     
==========================================
  Files          66       66              
  Lines        5279     5279              
  Branches      793      793              
==========================================
+ Hits         3370     3376       +6     
+ Misses       1676     1672       -4     
+ Partials      233      231       -2
Impacted Files Coverage Δ
torchvision/utils.py 65.38% <100%> (+3.84%) ⬆️
torchvision/transforms/functional.py 71.97% <0%> (+1.17%) ⬆️

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 2b6da28...97b946a. Read the comment docs.

@fmassa fmassa merged commit 427633a into pytorch:master Jun 26, 2019
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.

3 participants