I suggest you use the OpenCV library. Regardless of whether you use your MNIST or PIL data when it loads, they are all just NumPy arrays. If you want the MNIST datasets to fit your trained model, here's how I did it:
1.Use cv2.imread to download all the images you want them to act as training datasets.
2.Use cv2.cvtColor to convert all images to grayscale images and resize them to 28x28.
3. Place each pixel in all data sets at 255.
4. As usual, exercise!
I did not try to make this my own format, but theoretically this is the same.
source
share