this code seems simpler
If you want to reverse the normalization, all you need to do is to use a new normalization, with slight modifications:
mean = torch.tensor([0.4915, 0.4823, 0.4468])
std = torch.tensor([0.2470, 0.2435, 0.2616])

normalize = transforms.Normalize(mean.tolist(), std.tolist()) 

unnormalize = transforms.Normalize((-mean / std).tolist(), (1.0 / std).tolist())
img_unn = unnormalize(img)

plt.imshow(img_unn.permute(1, 2, 0))
plt.show()


Anyway I hate the fact that we don’t have un-normalize (de-normalize), it would be quite helpful for regression neural networks too.

  

      github.com/pytorch/vision
  

  
    
  
	  
  

  
    
      [Feature Request] Un-Normalize Image Tensor 50
    

    
      
        opened 
        
          
        
        Jun 5, 2018
      
      

        
          closed 
        
          
        
        Jun 6, 2018
      
        

      
        
          
          varagrawal
        
      
    

    
    
  


  
    Basically the inverse of `transforms.Normalize` as this will allow us to visuali…ze tensors during training more easily.