Skip to content

Commit e65925d

Browse files
ntomitasoumith
authored andcommitted
Apply clamping in save_image (#121)
* 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. * replaced clip with clamp
1 parent 1b9304c commit e65925d

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).clamp(0, 255).byte().permute(1, 2, 0).numpy()
9494
im = Image.fromarray(ndarr)
9595
im.save(filename)

0 commit comments

Comments
 (0)