We need to transpose the images in my example, as the data stored in the SVHN dataset is already in the “right” format ([c, h, w]). Since we are using PIL to convert them to grayscale, we need to pass the array as [h, w, c].
It won’t be necessary in your example, because you are already loading your data as PIL.Images.
Could you comment the img = Image.fromarray line and try it again?