tensorflow實(shí)現(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()
程序運(yùn)行結(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)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
python獲取全國最新省市區(qū)數(shù)據(jù)并存入表實(shí)例代碼
我們在開發(fā)中經(jīng)常會遇到獲取省市區(qū)等信息的時(shí)候,下面這篇這篇文章主要給大家介紹了關(guān)于python獲取全國最新省市區(qū)數(shù)據(jù)并存入表的相關(guān)資料,需要的朋友可以參考下2021-08-08
Python3+Appium實(shí)現(xiàn)多臺移動設(shè)備操作的方法
這篇文章主要介紹了Python3+Appium實(shí)現(xiàn)多臺移動設(shè)備操作的方法,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2019-07-07
Python監(jiān)控主機(jī)是否存活并以郵件報(bào)警
本文是利用python腳本寫的簡單測試主機(jī)是否存活,此腳本有個(gè)缺點(diǎn)不適用線上,由于網(wǎng)絡(luò)延遲、丟包現(xiàn)象會造成誤報(bào)郵件,感興趣的朋友一起看看Python監(jiān)控主機(jī)是否存活并以郵件報(bào)警吧2015-09-09
Python?nonlocal關(guān)鍵字?與?global?關(guān)鍵字解析
這篇文章主要介紹了Python?nonlocal關(guān)鍵字?與?global?關(guān)鍵字解析,nonlocal關(guān)鍵字用來在函數(shù)或其他作用域中使用外層變量,global關(guān)鍵字用來在函數(shù)或其他局部作用域中使用全局變量,更多香瓜內(nèi)容需要的小伙伴可以參考一下2022-03-03
python?tkinter實(shí)現(xiàn)學(xué)生信息管理系統(tǒng)
這篇文章主要為大家詳細(xì)介紹了python?tkinter實(shí)現(xiàn)學(xué)生信息管理系統(tǒng),文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2022-02-02
python計(jì)算書頁碼的統(tǒng)計(jì)數(shù)字問題實(shí)例
這篇文章主要介紹了python計(jì)算書頁碼的統(tǒng)計(jì)數(shù)字問題實(shí)例,對比2個(gè)實(shí)例講述了數(shù)字統(tǒng)計(jì)的技巧,非常實(shí)用,需要的朋友可以參考下2014-09-09

