ougni:

transform_mnist


I am not sure if your code is correct; but, a better alternative is to pass the invert function within the transform:
PIL.ImageOps. invert ( image )
Here is a link to PIL invert 24.