mnist数据集

#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,))

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值