# Instead of using 
# img = transforms.ToTensor()(img)

# Use this:
img = transforms.ToTensor()(np.array(img))

ToTensor() recevies PIL objects or numpy arrays. So explictly changes the pil array to numpy array is fine.
Ref:

  
      github.com/pytorch/vision
  
  
    
  
	  
  

  
    
      Float PILImage not converted as writeable 521
    

    
      
        opened 
        
          
        
        May 7, 2020
      
      


      
        
          
          lukasHoel
        
      
    
  



  🐛 Bug
When we have a float PIL-Image (e.g. mode='F'), e.g. for the purpose of applying transforms to it, and finally convert...