【T-Tensorflow框架学习】Tensorflow Mnist数据集简介

版权声明:转载请声名出处,谢谢 https://blog.csdn.net/u010591976/article/details/82177566

Tensorflow Mnist数据集简介:

'''
Creat by HuangDandan
[email protected]
2018-08-26
'''
#Tensorflow Mnist数据集简介
import numpy as np
import tensorflow as tf
import matplotlib.pyplot as plt
#从tensorfolw.examples.tutorials.mnist数据集中导入数据
from tensorflow.examples.tutorials.mnist import input_data

print("packs loaded")
print("Download and Extract MNIst dataset")
#运行时会自动下载下载数据集合到主文件夹下的data文件夹
mnist = input_data.read_data_sets('data/',one_hot=True)

print
#打印数据的类型
print("type of 'mnist' is %s"%(type(mnist)))
#打印训练集和测试集数据的个数
print("number of train data is %d"%(mnist.train.num_examples))
print("number of test data is %d"%(mnist.test.num_examples))

#MNIST数据集的数据可视化
print("MNIST database")
trainimg = mnist.train.images
trainlabel = mnist.train.labels
testimg = mnist.test.images
testlabel = mnist.test.labels
print
print("type of 'trainimg' is %s" %(type(trainimg)))
print("type of 'trainlabel' is %s" %(type(trainlabel)))
print("type of 'testing'is %s" %(type(testimg)))
print("type of 'testlabel'is %s" %(type(testlabel)))

#返回(图片个数,像素点个数)
print("shape of 'trainimg' is %s" %(trainimg.shape,))
print("shape of 'trainlabel' is %s" %(trainlabel.shape,))
print("shape of 'testing'is %s" %(testimg.shape,))
print("shape of 'testlabel' is %s" %(testlabel.shape,))

#training data可视化
print("training data")
nsample = 5
randidx = np.random.randint(trainimg.shape[0],size = nsample)

for i in randidx:
    curr_img = np.reshape(trainimg[i,:],(28,28))
    curr_label = np.argmax(trainlabel[i,:]) #label
    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()

#Batch Learning 调用mnist.train.next_batch(batch_size)
#通过nest_batch拿到x和y
print("Batch Learning")
batch_size = 100
batch_xs, batch_ys = mnist.train.next_batch(batch_size)
print("type of 'batch_xs' is %s"%(type(batch_xs)))
print("type of 'batch_xs' 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,))

输出:

packs loaded
Download and Extract MNIst dataset
WARNING:tensorflow:From D:/PycharmProjects/验证码识别小项目.py:173: read_data_sets (from tensorflow.contrib.learn.python.learn.datasets.mnist) is deprecated and will be removed in a future version.
Instructions for updating:
Please use alternatives such as official/mnist/dataset.py from tensorflow/models.
Extracting data/train-images-idx3-ubyte.gz
WARNING:tensorflow:From F:\Anaconda\lib\site-packages\tensorflow\contrib\learn\python\learn\datasets\mnist.py:260: maybe_download (from tensorflow.contrib.learn.python.learn.datasets.base) is deprecated and will be removed in a future version.
Instructions for updating:
Please write your own downloading logic.
WARNING:tensorflow:From F:\Anaconda\lib\site-packages\tensorflow\contrib\learn\python\learn\datasets\mnist.py:262: extract_images (from tensorflow.contrib.learn.python.learn.datasets.mnist) is deprecated and will be removed in a future version.
Instructions for updating:
Please use tf.data to implement this functionality.
Extracting data/train-labels-idx1-ubyte.gz
WARNING:tensorflow:From F:\Anaconda\lib\site-packages\tensorflow\contrib\learn\python\learn\datasets\mnist.py:267: extract_labels (from tensorflow.contrib.learn.python.learn.datasets.mnist) is deprecated and will be removed in a future version.
Instructions for updating:
Please use tf.data to implement this functionality.
WARNING:tensorflow:From F:\Anaconda\lib\site-packages\tensorflow\contrib\learn\python\learn\datasets\mnist.py:110: dense_to_one_hot (from tensorflow.contrib.learn.python.learn.datasets.mnist) is deprecated and will be removed in a future version.
Instructions for updating:
Please use tf.one_hot on tensors.
Extracting data/t10k-images-idx3-ubyte.gz
Extracting data/t10k-labels-idx1-ubyte.gz
WARNING:tensorflow:From F:\Anaconda\lib\site-packages\tensorflow\contrib\learn\python\learn\datasets\mnist.py:290: DataSet.__init__ (from tensorflow.contrib.learn.python.learn.datasets.mnist) is deprecated and will be removed in a future version.
Instructions for updating:
Please use alternatives such as official/mnist/dataset.py from tensorflow/models.
type of 'mnist' is <class 'tensorflow.contrib.learn.python.learn.datasets.base.Datasets'>
number of train data is 55000
number of test data is 10000
MNIST database
type of 'trainimg' is <class 'numpy.ndarray'>
type of 'trainlabel' is <class 'numpy.ndarray'>
type of 'testing'is <class 'numpy.ndarray'>
type of 'testlabel'is <class 'numpy.ndarray'>
shape of 'trainimg' is (55000, 784)
shape of 'trainlabel' is (55000, 10)
shape of 'testing'is (10000, 784)
shape of 'testlabel' is (10000, 10)
training data
45460th Training Datalabel is5
F:\Anaconda\lib\site-packages\matplotlib\figure.py:2267: UserWarning: This figure includes Axes that are not compatible with tight_layout, so results might be incorrect.
  warnings.warn("This figure includes Axes that are not compatible "
12171th Training Datalabel is1
47707th Training Datalabel is7
8450th Training Datalabel is0
27075th Training Datalabel is2
Batch Learning
type of 'batch_xs' is <class 'numpy.ndarray'>
type of 'batch_xs' is <class 'numpy.ndarray'>
shape of 'batch_xs' is (100, 784)
shape of 'batch_ys' is (100, 10)

猜你喜欢

转载自blog.csdn.net/u010591976/article/details/82177566
今日推荐