Custom image not being classified correctly (MNIST digit recognizer)

The model seems to work fine with all the images on the MNIST dataset, and with large accuracy as well. However, when I provide my own 28x28 images that are black and white, and I do invert them as well, they don’t seem to be classified as well with high accuracy.

I trained the set with the following transforms:

transforms.Compose([
  transforms.ToTensor(),
  transforms.Normalize(0.5, 0.5)
])

And here’s how I load my own images:

import numpy as np
import matplotlib.pyplot as plt

img = plt.imread("number.png")

def rgb2gray(rgb):
    return np.round(1 - np.mean(rgb, -1), decimals=1)

transform = transforms.Compose([
  transforms.ToTensor(),
  transforms.Normalize(0.5, 0.5)
])

img = rgb2gray(img)
img = transform(img)

You can view the code here: code.