Commit 93bceaf2 authored by buoyancy99's avatar buoyancy99 Committed by Francisco Massa
Browse files

Fix bug of changing input tensor in utils.save_image (#1244)

* Fix bug of changing input tensor in function

The original code will change the image tensor passed in by multiplying it by 255. The PR fixes that.

* fix inplace multiplication in save_image
parent 8878068e
......@@ -100,6 +100,6 @@ def save_image(tensor, filename, nrow=8, padding=2,
grid = make_grid(tensor, nrow=nrow, padding=padding, pad_value=pad_value,
normalize=normalize, range=range, scale_each=scale_each)
# Add 0.5 after unnormalizing to [0, 255] to round to nearest integer
ndarr = grid.mul_(255).add_(0.5).clamp_(0, 255).permute(1, 2, 0).to('cpu', torch.uint8).numpy()
ndarr = grid.mul(255).add_(0.5).clamp_(0, 255).permute(1, 2, 0).to('cpu', torch.uint8).numpy()
im = Image.fromarray(ndarr)
im.save(filename)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment