TensorFlow提供了一個庫,可以直接用來自動下載與安裝MNIST,
MNIST里包含3個資料集:第一個是訓練資料集(mnist.train.images),另外兩個分別是測驗資料集(mnist.test.images)和驗證資料集(mnist.validation),
代碼中的one_hot=True,表示將樣本標簽轉化為one_hot編碼,
剛開始的列印資訊是解壓資料集的意思,如果是第一次運行,還會顯示下載資料的相關訊息,
接著列印出來的是訓練集的圖片資訊,是一個55000行、784列的矩陣,即,訓練集里有55000張圖片,
1 from tensorflow.examples.tutorials.mnist import input_data2 mnist = input_data.read_data_sets("MNIST_data/",one_hot=True)3 print ('輸入資料:',mnist.train.images)4 print ('輸入列印shape:',mnist.train.images.shape)5 import pylab6 im = mnist.train.images[1]7 im = im.reshape(-1,28)8 pylab.imshow(im)9 pylab.show()
代碼的輸出結果如圖:

轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/71978.html
標籤:其他
上一篇:Python
