MNIST數據集介紹

2019-10-11     人工智慧遇見磐創

大多數示例使用手寫數字的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腳本來加載該數據集。

它對於管理我們的數據非常有用,並且可以處理:

  • 加載數據集
  • 將整個數據集加載到numpy數組中
# 導入 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
  • next_batch函數,可以遍歷整個數據集並僅返回所需的數據集樣本部分(以節省內存並避免加載整個數據集)。
# 獲取接下來的64個圖像數組和標籤
batch_X, batch_Y = mnist.train.next_batch(64)

[1]: http://yann.lecun.com/exdb/mnist/

文章來源: https://twgreatdaily.com/zh-cn/a3HovG0BMH2_cNUgx14j.html