'why does pytorch's utils.save_image() change the color of my image
I am saving two images with pytorch's utils.save_image() function here. one is the real image and the other, the perturbed image (just a patch). However, the latter image lost its real appearance when saved with save_image().
# save source image
utils.save_image(data.data, "./%s/%d_%d_org.png" % ("log", batch_idx, labels),
normalize=True)
# save adv image
utils.save_image(noised_data.data, "./%s/%d_%d_adv.png" % ("log", batch_idx, target_class), normalize=True)
Solution 1:[1]
So, I managed to solve this by adding make_grid() to the save method and clipping the image to [0,1] without normalizing.
utils.save_image(utils.make_grid(torch.clip(noised_data.data, 0, 1)), "./%s/%d_%d_adv.png" % ("log", batch_idx, target_class))
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |


