gistlib
To convert MNIST dataset images to actual pictures in python, follow the steps below:
main.pyimport numpy as np from PIL import Image 41 chars3 lines
import numpy as np from PIL import Image
train-images-idx3-ubyte.gz
main.pywith open("train-images-idx3-ubyte", "rb") as f: f.read(16) # skip the first 16 bytes data = np.fromfile(f, dtype=np.uint8).reshape(-1, 28, 28) 152 chars4 lines
with open("train-images-idx3-ubyte", "rb") as f: f.read(16) # skip the first 16 bytes data = np.fromfile(f, dtype=np.uint8).reshape(-1, 28, 28)
uint8
main.pyfor i in range(len(data)): image = Image.fromarray(data[i], mode='L') image.save(f'images/{i}.png') 108 chars4 lines
for i in range(len(data)): image = Image.fromarray(data[i], mode='L') image.save(f'images/{i}.png')
images
gistlibby LogSnag