The Image.fromarray operation fails, if you manipulate the underlying data in this line of code 11.
Example:
dataset = datasets.MNIST(
    root='PATH',
    transform=transforms.ToTensor(),
    download=True)

img = dataset.data[0]
img = Image.fromarray(img.numpy(), mode='L')
img.show() # works

img = dataset.data[0].float()
img = Image.fromarray(img.numpy(), mode='L')
img.show() # interleaved output