mnist手写数字识别为学习tensorflow等深度学习框架的入门经典数据集,tensorflow有直接加载mnist数据库相关的模块, 其地位类似于使用R语言作数据挖掘中的iris数据集。网络上关于使用mnist数据集实现各类深度学习算法的代码非常多,但是对于初学者而言,依着葫芦画瓢虽然将网上down的代码跑通了,但是对于其中每个步骤或是数据集可能一脸懵逼,下面对该数据集做简要的初步探索。



1. MNIST数据集下载
下载地址:http://yann.lecun.com/exdb/mnist/
下载数据为4个,分别为:
train-images-idx3-ubyte.gz: 训练集图片
train-labels-idx1-ubyte.gz: 训练集列标
t10k-images-idx3-ubyte.gz: 测试集图片
t10k-labels-idx1-ubyte.gz: 测试集列标



下载后放入文件夹./MNIST_data中.使用tensorflow加载该数据集

> from tensorflow.examples.tutorials.mnist import input_data
> mnist = input_data.read_data_sets("./MNIST_data", one_hot=False)

mnist手写数字识别数据初探


2. 查看训练集和测试集数量

> mnist.train.num_example

> mnist.test.num_examples

mnist手写数字识别数据初探


# 获取训练集第一个图片的矩阵数据
> first_data=mnist.train.images[0]
> first_data

# 图片的维度
> print(first_data.shape)
# 将一维向量转换成 28*28 的矩阵
> image_matrix=first_data.reshape((28,28))
# 输出矩阵的维度
> print(image_matrix.shape)

mnist手写数字识别数据初探


3. 可视化数据集

> import matplotlib.pyplot as pyplot
> pyplot.imshow(image_matrix)
> pyplot.show()

mnist手写数字识别数据初探






相关文章: