Skip to content

Commit 2f579d5

Browse files
ntomitasoumith
authored andcommitted
clipping values, and replacing transposes with permute
Without clipping, any values larger than 255 will be replaced with int(v mod 256) by byte(), which results in high freq noise in image.
1 parent 7a97528 commit 2f579d5

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

torchvision/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,6 @@ def save_image(tensor, filename, nrow=8, padding=2,
9090
tensor = tensor.cpu()
9191
grid = make_grid(tensor, nrow=nrow, padding=padding,
9292
normalize=normalize, range=range, scale_each=scale_each)
93-
ndarr = grid.mul(255).byte().transpose(0, 2).transpose(0, 1).numpy()
93+
ndarr = grid.mul(255).clip(0, 255).byte().permute(1, 2, 0).numpy()
9494
im = Image.fromarray(ndarr)
9595
im.save(filename)

0 commit comments

Comments
 (0)