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
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions test/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@ def test_save_image(self):
utils.save_image(t, f.name)
assert os.path.exists(f.name), 'The image is not present after save'

def test_save_image_single_pixel(self):
with tempfile.NamedTemporaryFile(suffix='.png') as f:
t = torch.rand(1, 3, 1, 1)
utils.save_image(t, f.name)
assert os.path.exists(f.name), 'The pixel image is not present after save'


if __name__ == '__main__':
unittest.main()
2 changes: 1 addition & 1 deletion torchvision/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def norm_range(t, range):
norm_range(tensor, range)

if tensor.size(0) == 1:
return tensor.squeeze()
return tensor.squeeze(0)

# make the mini-batch of images into a grid
nmaps = tensor.size(0)
Expand Down