tensorflow實現(xiàn)加載mnist數(shù)據(jù)集
更新時間:2018年09月08日 10:16:08 作者:Missayaa
這篇文章主要為大家詳細介紹了tensorflow實現(xiàn)加載mnist數(shù)據(jù)集,具有一定的參考價值,感興趣的小伙伴們可以參考一下
mnist作為最基礎(chǔ)的圖片數(shù)據(jù)集,在以后的cnn,rnn任務(wù)中都會用到
import numpy as np import tensorflow as tf import matplotlib.pyplot as plt from tensorflow.examples.tutorials.mnist import input_data #數(shù)據(jù)集存放地址,采用0-1編碼 mnist = input_data.read_data_sets('F:/mnist/data/',one_hot = True) print(mnist.train.num_examples) print(mnist.test.num_examples) trainimg = mnist.train.images trainlabel = mnist.train.labels testimg = mnist.test.images testlabel = mnist.test.labels #打印相關(guān)信息 print(type(trainimg)) print(trainimg.shape,) print(trainlabel.shape,) print(testimg.shape,) print(testlabel.shape,) nsample = 5 randidx = np.random.randint(trainimg.shape[0],size = nsample) #輸出幾張數(shù)字的圖 for i in randidx: curr_img = np.reshape(trainimg[i,:],(28,28)) curr_label = np.argmax(trainlabel[i,:]) plt.matshow(curr_img,cmap=plt.get_cmap('gray')) plt.title(""+str(i)+"th Training Data"+"label is"+str(curr_label)) print(""+str(i)+"th Training Data"+"label is"+str(curr_label)) plt.show()
程序運行結(jié)果如下:
Extracting F:/mnist/data/train-images-idx3-ubyte.gz Extracting F:/mnist/data/train-labels-idx1-ubyte.gz Extracting F:/mnist/data/t10k-images-idx3-ubyte.gz Extracting F:/mnist/data/t10k-labels-idx1-ubyte.gz 55000 10000 <class 'numpy.ndarray'> (55000, 784) (55000, 10) (10000, 784) (10000, 10) 52636th
輸出的圖片如下:
Training Datalabel is9
下面還有四張其他的類似圖片
以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
Python神經(jīng)網(wǎng)絡(luò)TensorFlow基于CNN卷積識別手寫數(shù)字
這篇文章主要介紹了Python神經(jīng)網(wǎng)絡(luò)TensorFlow基于CNN卷積識別手寫數(shù)字的實現(xiàn)示例解析,有需要的朋友可以借鑒參考下,希望能夠有所幫助2021-10-10pycharm日志總是彈出“無法運行Git,未安裝Git”的問題
這篇文章主要介紹了pycharm日志總是彈出“無法運行Git,未安裝Git”的問題,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2023-06-06python 簡單照相機調(diào)用系統(tǒng)攝像頭實現(xiàn)方法 pygame
今天小編就為大家分享一篇python 簡單照相機調(diào)用系統(tǒng)攝像頭實現(xiàn)方法 pygame,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2018-08-08詳解Python的collections模塊中的deque雙端隊列結(jié)構(gòu)
deque結(jié)構(gòu)可以看作是內(nèi)置的list結(jié)構(gòu)的加強版,且比隊列提供了更強大的方法,下面就通過幾個小例子來詳解Python的collections模塊中的deque雙端隊列結(jié)構(gòu):2016-07-07