mnist library
Published: 2019-04-28

mnist library is the most commonly used library, but there are several different versions.


If you use example that comes with keras, you will download it from this address.But for some reason, the download could not come down.'s blog also recorded that it could not be downloaded, using other methods.

path = get_file(path, origin='')
f = np.load(path)
x_train, y_train = f['x_train'], f['y_train']
x_test, y_test = f['x_test'], f['y_test']
return (x_train, y_train), (x_test, y_test)


train-images-idx3-ubyte.gz: training set images (9912422 bytes)train-labels-idx1-ubyte.gz: training set labels (28881 bytes)t10k-images-idx3-ubyte.gz:  test set images (1648877 bytes)t10k-labels-idx1-ubyte.gz:  test set labels (4542 bytes)

This is the authentic source, but it seems that everyone does not use this directly, but uses a format of 1 or 3. this article records how to use these libraries.


( mnist.pkl.gz )

This is read by:

import cPickle, gzip, numpy

# Load the dataset
f ='mnist.pkl.gz', 'rb')
train_set, valid_set, test_set = cPickle.load(f)


Go online search, and this compressed package.This direct opening is the picture, and the content and label of each picture can be clearly seen.