#Mnist数据集 属性已经写好 可以直接调用
import numpy as np
import tensorflow as tf
import matplotlib.pyplot as plt
from tensorflow.examples.tutorials.mnist import input_data
print("大家吃鸡")
print("下载呢")
mnist = input_data.read_data_sets('data/',one_hot=True)
print
print("类型 %s" % (type(mnist)))
print("训练数据 %d" % (mnist.train.num_examples))
print("测试数据 %d" % (mnist.test.num_examples))
#mnist数据的规格
#图片的大小为28*28*1
trainimg = mnist.train.images
trainlabel = mnist.train.labels
testimg = mnist.test.images
testlabel = mnist.test.labels
print
print("数据类型 %s" % (type(trainimg)))
print("标签类型 %s" % (type(trainlabel)))
print("训练集的shape %s" % (trainimg.shape,))
print("训练集的标签的shape %s" % (trainlabel.shape,))
print("测试集的shape %s" % (testimg.shape,))
print("测试集的标签的shape %s" % (testlabel.shape,))
#实际操作
nsample = 5
randidx = np.random.randint(trainimg.shape[0],size = nsample)
for i in randidx:
curr_img = np.reshape(trainimg[i, :],(28,28)) #28 读取数据 28的矩阵
curr_label = np.argmax(trainlabel[i, :]) #标签 转换
plt.matshow(curr_img,cmap = plt.get_cmap('gray')) #显示该矩阵
print("" + str(i) + "th训练数据 "
+ "标签为: " + str(curr_label))
plt.show()
#batch数据 自动去batch数据
print("Batch learning")
batch_size = 100
batch_xs,batch_ys = mnist.train.next_batch(batch_size)
print("batch数据 %s" % (type(batch_xs)))
print("batch标签 %s" % (type(batch_ys)))
print("batch数据的shape %s " % (batch_xs.shape,))
print("batch标签的shape %s " % (batch_ys.shape,))