title: How to save grayscale image in Pytorch?
body: <p>I want to save grayscale image in Pytorch, each image has four gray values, <code>0</code>, <code>60</code>, <code>120</code> and <code>180</code>. I try the following way to save images, but the saved image is not I expected.</p>
  
  <pre><code>for i, (inputs) in enumerate(test_generator):
      pred = modelPl(inputs.float()).detach()
      fig,ax = plt.subplots(1,1,figsize = (5,5))
      ax.imshow(pred[0,:,:], cmap = "gray")
      print(pred.shape)
      torchvision.utils.save_image(pred, saveTestPath + 'img_{0}.png'.format(i)) 
  </code></pre>
  
  <p><code>Output:</code>
  <code>torch.Size([400, 400])</code></p>
  
  <p><code>Expected image:</code></p>
  
  <p><a href="https://i.stack.imgur.com/mkmuS.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/mkmuS.png" alt="enter image description here"></a>   </p>
  
  <p>However, the saved picture is not correct as follows:</p>
  
  <p><a href="https://i.stack.imgur.com/29kc4.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/29kc4.png" alt="enter image description here"></a></p>