3、Caffe mnist数据集初体验

参考官网:caffe|Lenet
和一个很早的博客:mnist
开始自己的caffe初体验

Training LeNet on MNIST with Caffe

首先,我们配置好了caffe的环境,下载依赖项并且编译通过,有gpu没有gpu均可。

Prepare Datasts 准备数据集

第一步是下载数据集,并做转换,官网里给出两个命令,直接输入即可。

cd $CAFFE_ROOT   、、这个就是cd到caffe文件夹里即可
./data/mnist/get_mnist.sh
./examples/mnist/create_mnist.sh

可以分别看一下两个脚本的作用,一个是下载解析,一个数据转换成lmdb格式。

LeNet:the MNST Classification Model 模型介绍

在运行程序之前,我们先解释将会发生什么。
LeNet网络结构在用于数字分类任务上是非常有名的,在这里我们的模型稍微有点不一样就是我们使用了Relu激活函数替代了之前的sigmoid函数。
LeNet网络结构设计用到的CNN卷积神经网络至今仍在广泛运用。一般来说,它包含两个个卷积层和跟随卷积层的池化层,两个和卷积层类似的全连接层。我们在prototxt里定义了这样的网络结构。
打开prototxt观察:
这里写图片描述

. We will use a batch size of 64, and scale the incoming pixels so that they are in the range [0,1). Why 0.00390625? It is 1 divided by 256. And finally, this layer produces two blobs, one is the data blob, and one is the label blob.

各层都会有自己的定义和参数,bottom和top,底层和上层分别是谁。
卷积层说了卷积的参数,kernel的大小,stride的大小,还包括了weight和bias的初始化
这里写图片描述

lr_mults are the learning rate adjustments for the layer’s learnable parameters. In this case, we will set the weight learning rate to be the same as the learning rate given by the solver during runtime, and the bias learning rate to be twice as large as that - this usually leads to better convergence rates.

对于激活层,另外还可以做一些本地操作来减少内存,简单的就是bottom和top blobs的名字都是相同的
这里写图片描述

Training and Testing the model 训练和测试模型
cd $CAFFE_ROOT
./examples/mnist/train_lenet.sh
cd $CAFFE_ROOT
./examples/mnist/test_lenet.sh

以上就基本上把lenet网络给跑起来了,但我们怎么去用这个训练过的模型呢?

猜你喜欢

转载自blog.csdn.net/legalhighhigh/article/details/81697734