大多數示例使用手寫數字的MNIST數據集[1]。該數據集包含60,000個用於訓練的示例和10,000個用於測試的示例。這些數字已經過尺寸標準化並位於圖像中心,圖像是固定大小(28x28像素),其值為0到1。為簡單起見,每個圖像都被平展並轉換為784(28 * 28)個特徵的一維numpy數組。
在我們的示例中,我們使用TensorFlow https://github.com/tensorflow/tensorflow/blob/r0.7/tensorflow/examples/tutorials/mnist/input_data.py腳本來加載該數據集。
它對於管理我們的數據非常有用,並且可以處理:
# 導入 MNIST
from tensorflow.examples.tutorials.mnist import input_data
mnist = input_data.read_data_sets("/tmp/data/", one_hot=True)
# 加載數據
X_train = mnist.train.images
Y_train = mnist.train.labels
X_test = mnist.test.images
Y_test = mnist.test.labels
# 獲取接下來的64個圖像數組和標籤
batch_X, batch_Y = mnist.train.next_batch(64)
[1]: http://yann.lecun.com/exdb/mnist/