Why do I get washedout images when displaying make_grid output?

Shisho_Sama: <p>Hello everyone.<br>
Today I faced something strange. When using <code>torchvision.utils.make_grid()</code>, I noticed when ever I display the resulting image in matplotib, the image is washedout! but when I save it using save_img , it turns out just fine.<br>
This is how it looks when I display the output of <code>make_grid()</code> in matplotlib :<br>
<div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/2X/2/245a531f9b0d6817cb3344db996c69b1f4c21ee9.png" data-download-href="https://discuss.pytorch.org/uploads/default/245a531f9b0d6817cb3344db996c69b1f4c21ee9" title="make_grid_img1"><img src="https://discuss.pytorch.org/uploads/default/optimized/2X/2/245a531f9b0d6817cb3344db996c69b1f4c21ee9_2_690x293.png" alt="make_grid_img1" data-base62-sha1="5bAHWiLCkQ9gANFnG8JLA8qiZqp" width="690" height="293" srcset="https://discuss.pytorch.org/uploads/default/optimized/2X/2/245a531f9b0d6817cb3344db996c69b1f4c21ee9_2_690x293.png, https://discuss.pytorch.org/uploads/default/optimized/2X/2/245a531f9b0d6817cb3344db996c69b1f4c21ee9_2_1035x439.png 1.5x, https://discuss.pytorch.org/uploads/default/optimized/2X/2/245a531f9b0d6817cb3344db996c69b1f4c21ee9_2_1380x586.png 2x" data-dominant-color="808080"><div class="meta"><svg class="fa d-icon d-icon-far-image svg-icon" aria-hidden="true"><use href="#far-image"></use></svg><span class="filename">make_grid_img1</span><span class="informations">2111×899 109 KB</span><svg class="fa d-icon d-icon-discourse-expand svg-icon" aria-hidden="true"><use href="#discourse-expand"></use></svg></div></a></div><br>
and this is how it got saved to the disk :<br>
<img src="https://discuss.pytorch.org/uploads/default/original/2X/6/6429ce5dd2306ef576254d2d4cf38209ef91f83a.jpeg" alt="imgs_0" data-base62-sha1="ei5jBDjJND2VKadoL6T3C6mOfJ8" width="292" height="122"><br>
and this is the snippet I wrote :</p>
<pre><code class="lang-auto">from` torchvision.utils` import save_image, make_grid

fig = plt.figure(figsize=(28, 28))
for i in range(5):
  grid_imgs = make_grid(torch.from_numpy(img_pairs[i]),
                        nrow=5,
                        normalize=True)
  save_image(grid_imgs,f'results/imgs_{i}.jpg')
  ax = fig.add_subplot(5, 1, i+1, xticks=[], yticks=[])
  ax.imshow(grid_imgs.numpy().transpose(1,2,0),cmap='Greys_r')
</code></pre>
<p>normalizing and not doesnt affect anything.<br>
What am I missing here ?<br>
Your kind help is greatly appreciated</p>

urw7rs: <p>I think removing ax = … and using plt.imshow(…) instead of ax.imshow(…) could work.</p>

Shisho_Sama: <p>Thanks thats not the case, since I have several images to display I needed as many axes so I need to use that.</p>
<p>Thanks to dear God, I found the cause!<br>
This was caused by <strong>save_image()</strong> method! I moved the <code>save_image()</code> after showing the image and all was fine!<br>
This seems like a bug to me. this should not happen at all! <a class="mention" href="/u/smth">@smth</a></p>

ptrblck: <p>Thanks for raising this bug!<br>
I’ve created an issue <a href="https://github.com/pytorch/vision/issues/1337" rel="nofollow noopener">here</a> to track and fix it.</p>

ptrblck: <p>Fixed <a href="https://github.com/pytorch/vision/pull/1244" rel="nofollow noopener">here</a>. Should be available in the nightly builds.</p>