Mnist数据集简介
生活随笔
收集整理的這篇文章主要介紹了
Mnist数据集简介
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
1,基本概念
MNIST是一個非常有名的手寫體數字識別數據集,在很多資料中,這個數據集都會被用作深度學習的入門樣例。而TensorFlow的封裝讓使用MNIST數據集變得更加方便。MNIST數據集是NIST數據集的一個子集,MNIST 數據集可在 http://yann.lecun.com/exdb/mnist/ 獲取, 它包含了四個部分:
(1)Training set images: train-images-idx3-ubyte.gz (9.9 MB, 解壓后 47 MB, 包含 60,000 個樣本)
(2)Training set labels: train-labels-idx1-ubyte.gz (29 KB, 解壓后 60 KB, 包含 60,000 個標簽)
(3)Test set images: t10k-images-idx3-ubyte.gz (1.6 MB, 解壓后 7.8 MB, 包含 10,000 個樣本)
(4)Test set labels: t10k-labels-idx1-ubyte.gz (5KB, 解壓后 10 KB, 包含 10,000 個標簽)
2,代碼解讀
import tensorflow as tf
import numpy as np
import matplotlib.pyplot as plt
from tensorflow.examples.tutorials.mnist import input_data#下載mnist數據集并查看大小
mnist = input_data.read_data_sets('data',one_hot = True)
print("type of mnist is %s" %(type(mnist)))
print("number of trian data is %d" %(mnist.train.num_examples))#訓練集樣本個數
print("number of test data is %d" %(mnist.test.num_examples))#測試集樣本個數#mnist數據集具體信息(樣本,標簽)
trainimg = mnist.train.images
trainlabel = mnist.train.labels
testimg = mnist.test.images
testlabel = mnist.test.labelsprint("type of trainimg is %s" %(type(trainimg))) #訓練集樣本的類型
print("type of trainlabel is %s" %(type(trainlabel)))#訓練標簽的類型
print("type of testimg is %s" %(type(testimg)))
print("type of testlabel is %s" %(type(testlabel)))print("shape of trainimg is %s" %(trainimg.shape,))#訓練樣本的個數,單個樣本像素點的個數(28*28)
print("shape of trainlabel is %s" %(trainlabel.shape,))#訓練標簽的個數,單個樣本可能類別的個數(10)
print("shape of testimg is %s" %(testimg.shape,))
print("shape of testlabel is %s" %(testlabel.shape,))
運行結果:
#展示訓練集樣本的實例
nsample=3
randidx = np.random.randint(trainimg.shape[0],size=nsample)for i in randidx:cur_img = np.reshape(trainimg[i,:],(28,28))cur_label = np.argmax(trainlabel[i,:])plt.matshow(cur_img,cmap = plt.get_cmap('gray'))plt.title(""+str(i)+"th Training Data"+"Label is"+str(cur_label))plt.show()
運行結果:
#Batch Learning
batch_size = 128 #batch大小
batch_xs, batch_ys = mnist.train.next_batch(batch_size) #訓練集batch中樣本的個數(batch_xs),相應標簽的個數(batch_ys)print("type of batch_xs is %s" %(type(batch_xs)))
print("type of batch_ys is %s" %(type(batch_ys)))print("shape of batch_xs is %s" %(batch_xs.shape,))
print("shape of batch_ys is %s" %(batch_ys.shape,))
運行結果:
總結
以上是生活随笔為你收集整理的Mnist数据集简介的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 秋雨萧瑟下一句是什么啊?
- 下一篇: 神经网络:代码实现