Caffe之mnist数据集初体验

本文介绍如何使用Caffe框架搭建LeNet网络并应用于MNIST数据集进行训练与测试。从环境配置、数据集下载及转换,到模型结构定义与训练测试过程,详尽地展示了整个流程。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

参考官网: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网络给跑起来了,但我们怎么去用这个训练过的模型呢?

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值