首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

TensorFlow 手写数字识别与一步一步实现卷积神经网络

手写数字识别

接下来将会以 MNIST 数据集为例,使用卷积层和池化层,实现一个卷积神经网络来进行手写数字识别,并输出卷积和池化效果。

数据准备

MNIST 数据集下载

MNIST 数据集可以从 THE MNIST DATABASE of handwritten digits 的网站直接下载。

网址:http://yann.lecun.com/exdb/mnist/

train-images-idx3-ubyte.gz: 训练集图片

train-labels-idx1-ubyte.gz: 训练集列标

t10k-images-idx3-ubyte.gz: 测试集图片

t10k-labels-idx1-ubyte.gz: 测试集列标

TensorFlow 有加载 MNIST 数据库相关的模块,可以在程序运行时直接加载。

代码如下:

代码的输出依次是:

1.单个手写数字图片的维度:

(784,)

2.转化为二维矩阵之后的打印结果:

(28, 28)

3.使用 matplotlib 输出为图片

模型实现

TensorFlow conv2d 函数介绍:

参数 x:

4 维张量,每一个维度分别是 batch,in_height,in_height,in_channels。

[batch, in_height, in_width, in_channels]

灰度图像只有 2 维来表示每一个像素的值,彩色图像每一个像素点有 3 通道的 RGB 值,所以一个彩色图片转化成张量后是 3 维的,分别是长度,宽度,颜色通道数。又因为每一次训练都是训练都是输入很多张图片,所以,多个 3 维张量组合在一起变成了 4 维张量。

参数 w:

过滤器,因为是二维卷积,所以它的维度是:

[filter_height, filter_width, in_channels, out_channels]

与参数 x 对应,前 3 个参数分别是对应 x 的 filter_height, filter_width, in_channels,最后一个参数是过滤器的输出通道数量。

参数 strides:

1 维长度为 4 的张量,对应参数 x 的 4 个维度上的步长。

参数 padding:

边缘填充方式,主要是 “SAME”, “VALID”,一般使用 “SAME”。

卷积层简单封装

TensorFlow max_pool 函数介绍:

参数 x:

和 conv2d 的参数 x 相同,是一个 4 维张量,每一个维度分别代表 batch,in_height,in_height,in_channels。

参数 ksize:

池化核的大小,是一个 1 维长度为 4 的张量,对应参数 x 的 4 个维度上的池化大小。

参数 strides:

1 维长度为 4 的张量,对应参数 x 的 4 个维度上的步长。

参数 padding:

边缘填充方式,主要是 “SAME”, “VALID”,一般使用 “SAME”。

接下来将会使用 TensorFlow 实现以下结构的卷积神经网络:

池化层简单封装

超参数定义:卷积神经网络函数

卷积神经网络定义:

效果评估

训练过程输出

模型优化

经典卷积神经网络

图像分类实战项目

The CIFAR-10 dataset

https://www.cs.toronto.edu/~kriz/cifar.html

目标检测实战项目

Tensorflow Object Detection API

https://github.com/tensorflow/models/tree/master/research/object_detection

主要参考对象:

1.TensorFlow 官方介绍

Image Recognition

https://tensorflow.google.cn/tutorials/image_recognition

https://www.tensorflow.org/tutorials/deep_cnn

2.最经典论文

ImageNet Classification with Deep Convolutional Neural Networks

http://papers.nips.cc/paper/4824-imagenet-classification-with-deep-convolutional-neural-networks

3.最经典课程

Convolutional Neural Networks

http://cs231n.github.io/convolutional-networks/

Deep learning

http://neuralnetworksanddeeplearning.com/chap6.html

3.Wikipedia

Convolutional neural network

https://en.wikipedia.org/wiki/Convolutional_neural_network

4.Good tutorial

Comparison of Normal Neural network

https://leonardoaraujosantos.gitbooks.io/artificial-inteligence/content/convolutional_neural_networks.html

Convolutional Neural Networks (LeNet)

http://deeplearning.net/tutorial/lenet.html#sparse-connectivity

Convolutional neural networks from scratch

http://gluon.mxnet.io/chapter04_convolutional-neural-networks/cnn-scratch.html

卷积神经网络

http://prors.readthedocs.io/zh_CN/latest/2ndPart/Chapter8.SceneClassification/ConvNet.html

ImageNet Classification with Deep Convolutional

Neural Networks

https://papers.nips.cc/paper/4824-imagenet-classification-with-deep-convolutional-neural-networks.pdf

  • 发表于:
  • 原文链接http://kuaibao.qq.com/s/20180330G1YO1K00?refer=cp_1026
  • 腾讯「腾讯云开发者社区」是腾讯内容开放平台帐号(企鹅号)传播渠道之一,根据《腾讯内容开放平台服务协议》转载发布内容。
  • 如有侵权,请联系 cloudcommunity@tencent.com 删除。

扫码

添加站长 进交流群

领取专属 10元无门槛券

私享最新 技术干货

扫码加入开发者社群
领券