tensorflow實(shí)現(xiàn)加載mnist數(shù)據(jù)集
mnist作為最基礎(chǔ)的圖片數(shù)據(jù)集,在以后的cnn,rnn任務(wù)中都會(huì)用到
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

下面還有四張其他的類似圖片
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
Python神經(jīng)網(wǎng)絡(luò)TensorFlow基于CNN卷積識(shí)別手寫數(shù)字
這篇文章主要介紹了Python神經(jīng)網(wǎng)絡(luò)TensorFlow基于CNN卷積識(shí)別手寫數(shù)字的實(shí)現(xiàn)示例解析,有需要的朋友可以借鑒參考下,希望能夠有所幫助2021-10-10
pycharm日志總是彈出“無(wú)法運(yùn)行Git,未安裝Git”的問(wèn)題
這篇文章主要介紹了pycharm日志總是彈出“無(wú)法運(yùn)行Git,未安裝Git”的問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2023-06-06
Django數(shù)據(jù)庫(kù)操作的實(shí)例(增刪改查)
下面小編就為大家?guī)?lái)一篇Django數(shù)據(jù)庫(kù)操作的實(shí)例(增刪改查)。小編覺(jué)得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2017-09-09
Python裝飾器用法與知識(shí)點(diǎn)小結(jié)
這篇文章主要介紹了Python裝飾器用法與知識(shí)點(diǎn),總結(jié)分析了Python 裝飾器的基本概念、原理、用法與操作注意事項(xiàng),需要的朋友可以參考下2020-03-03
python 簡(jiǎn)單照相機(jī)調(diào)用系統(tǒng)攝像頭實(shí)現(xiàn)方法 pygame
今天小編就為大家分享一篇python 簡(jiǎn)單照相機(jī)調(diào)用系統(tǒng)攝像頭實(shí)現(xiàn)方法 pygame,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2018-08-08
Python網(wǎng)絡(luò)爬蟲(chóng)之爬取微博熱搜
這篇文章主要介紹了Python網(wǎng)絡(luò)爬蟲(chóng)之爬取微博熱搜的相關(guān)知識(shí),非常不錯(cuò),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2019-04-04
詳解Python的collections模塊中的deque雙端隊(duì)列結(jié)構(gòu)
deque結(jié)構(gòu)可以看作是內(nèi)置的list結(jié)構(gòu)的加強(qiáng)版,且比隊(duì)列提供了更強(qiáng)大的方法,下面就通過(guò)幾個(gè)小例子來(lái)詳解Python的collections模塊中的deque雙端隊(duì)列結(jié)構(gòu):2016-07-07

