Could you try to use img = img.permute(1, 2, 0) instead of the view call?
img = img.permute(1, 2, 0)
view