TensorFlow學習筆記之四(MNIST數字識別)

關於MNIST數據集

  • 有6萬張28*28像素點的0~9手寫數字圖片和標籤,用於測試。
  • 有1萬張28*28像素點的0~9手寫數字圖片和標籤,用於測試。

每張圖片有784個像素點(28*28=784)組成一個長度爲784的一維數組,用做個輸入特徵
[000010011010...011010]7281 \begin{gathered} \begin{bmatrix} 0 & 0 & 0 &0 & 1 & 0 &0 & 1 & 1 &0 & 1 & 0 &...&0 & 1 & 1 &0 & 1 & 0 \end{bmatrix} \end{gathered}_{728*1}
圖片的標籤以一維數組形式給出,每個元素表示對應分類出現的概率。比如下面的標籤表示數字4
[0000100000] \begin{gathered} \begin{bmatrix} 0 & 0 & 0 &0 & 1 & 0 &0 & 0 & 0 & 0 \end{bmatrix} \end{gathered}

#手寫識別字mnist
import input_data

# 使用官方提供的input_data模塊的read_data_sets自動加載數據集,"Mnist_data/"是數據集存放的路徑,當前目錄的Mnist_data目錄下面。並以獨熱碼的方式存取。
# read_data_sets會自動檢查本地是否有數據集,如果沒有,會自動下載train,
mnist = input_data.read_data_sets("Mnist_data/",one_hot = True)


print("訓練集大小爲: ", mnist.train.num_examples)

print("驗證集大小爲:", mnist.validation.num_examples)

print("測試樣本大小爲:", mnist.test.num_examples)

print("訓練集中指定的圖片類型爲:", mnist.train.images[0].shape)

print("訓練集中指定的標籤類型爲:", mnist.train.labels[0].shape)

print("查看訓練集中指定的標籤:")
print(mnist.train.labels[0], '\n')

print("查看訓練集中指定的圖片:")
print(mnist.train.images[0])

在這裏插入圖片描述

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章