Nono.MA

One-liner to download MNIST as images

MARCH 7, 2025

Here's a one-liner to download the MNIST dataset as PNG images, white over black.

python -c "from tensorflow.keras.datasets import mnist; import os, matplotlib.pyplot as plt; (x_train, y_train), _ = mnist.load_data(); os.makedirs('mnist_images', exist_ok=True); [plt.imsave(f'mnist_images/{i}_{y}.png', img, cmap='gray') for i, (img, y) in enumerate(zip(x_train, y_train))]"

Run this in the command-line interface with a Python environment with the tensorflow and matplotlib packages.

BlogMl