博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Mnist数据集简介
阅读量:3948 次
发布时间:2019-05-24

本文共 2155 字,大约阅读时间需要 7 分钟。

1,基本概念

MNIST是一个非常有名的手写体数字识别数据集,在很多资料中,这个数据集都会被用作深度学习的入门样例。而TensorFlow的封装让使用MNIST数据集变得更加方便。MNIST数据集是NIST数据集的一个子集,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 tfimport numpy as npimport matplotlib.pyplot as pltfrom 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.imagestrainlabel = mnist.train.labelstestimg =  mnist.test.imagestestlabel =  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=3randidx = 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 Learningbatch_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,))

运行结果:

在这里插入图片描述

转载地址:http://bohwi.baihongyu.com/

你可能感兴趣的文章
Setting Up the Search Interface 设置搜索界面
查看>>
Storing and Searching for Data 数据存储和搜索
查看>>
Remaining Backward Compatible 保持向后兼容
查看>>
Remembering Your User 记住你的用户
查看>>
Authenticating to OAuth2 Services 验证OAuth2服务
查看>>
Creating a Custom Account Type 创建自定义帐户类型
查看>>
Sending Content to Other Apps 将内容发送到其他应用程序
查看>>
Receiving Content from Other Apps 接收来自其他应用程序的内容
查看>>
Adding an Easy Share Action 添加一个简单的共享行动
查看>>
Taking Photos Simply 简单地拍摄照片
查看>>
Recording Videos Simply 简单录制视频
查看>>
Controlling the Camera 控制相机
查看>>
Creating Multiple APKs for Different API Levels 创建多个不同的API级别的APK
查看>>
Creating Multiple APKs for Different Screen Sizes 创建多个APKs为不同的屏幕尺寸
查看>>
Creating Multiple APKs for Different GL Textures 创建多个APK给不同的GL结构
查看>>
Android Package and Manifest File
查看>>
Creating Multiple APKs with 2+ Dimensions 创建两种以上屏幕尺寸多apk支持
查看>>
Abstracting the New APIs 抽象出新的API
查看>>
Proxying to the New APIs 代理新的API
查看>>
Creating an Implementation with Older APIs 用较早版本的APIs实现抽象类
查看>>