欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

tensorflow實(shí)現(xiàn)加載mnist數(shù)據(jù)集

 更新時(shí)間:2018年09月08日 10:16:08   作者:Missayaa  
這篇文章主要為大家詳細(xì)介紹了tensorflow實(shí)現(xiàn)加載mnist數(shù)據(jù)集,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

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

下面還有四張其他的類(lèi)似圖片

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論