mnist

mnist是什么?

它是在机器学习和计算机视觉领域相当于hello world的一个最基础的数据集,内容是手写的数字(从0到9)。我们想通过这个数据集来让计算机进行图像识别和手写识别。

from matplotlib import pyplot as plt
from PIL import Image

%matplotlib inline

下载和读取数据集

import numpy as np
import tensorflow as tf
from tensorflow.examples.tutorials.mnist import input_data

mnist = input_data.read_data_sets("MNIST_data/", one_hot=True)

mnist里有已经划分好的训练集,测试集和验证集。

validation set用于调超参。超参确定后,用test set来测试模型的表现。如果提前用了test set,可能会导致过拟合。

print(mnist.train.images.shape)
print(mnist.train.labels.shape)

(55000, 784)
(55000, 10)

print(mnist.test.images.shape)
print(mnist.test.labels.shape)

(10000, 784)
(10000, 10)

print(mnist.validation.images.shape)
print(mnist.validation.labels.shape)

(5000, 784)
(5000, 10)

784表示每一张图有28x28=784个特征(像素点)。

10表示标签是one hot encoding的形式,也就是说每一张图都有可能是0,1,2,3,4,5,6,7,8,9这十个数字当中的一个,所以就设定十个位置,如果这个数字是9,9这个位置上就标成1,其他9个位置均标成0。

在这里插入图片描述

任选一张图片:

mnist.train.images[5]
mnist.train.images[5].shape

(784,)

这个784x1的向量,是一个28x28的矩阵经过一维化(flatten)得到的。一张28x28像素的图片原本是28x28的矩阵。

在这里插入图片描述

以下是逆操作:

a = np.reshape(mnist.train.images[5]
  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值