Are you using the torchvision.datasets.MNIST dataset or your “own” handwritten images?
In the former case you could stick to the MNIST example 34. In the latter case, you could load your images as grayscale images using Image.open(PATH).convert('L') and apply your transformations on this image directly.