Training LeNet on MNIST with Caffe
2017-08-21 11:07
351 查看
前面的话:这是参照http://caffe.berkeleyvision.org/gathered/examples/mnist.html 的一个简单caffe实例。
最后炼出的丹(模型的参数)就存在
一、准备数据
cd $CAFFE_ROOT # 获取数据 ./data/mnist/get_mnist.sh # 转格式 ./examples/mnist/create_mnist.sh
二、定义LeNet网络结构
在lenet_train_test.prototxt中
# 网络的名字 name: "LeNet" # 数据层 训练时使用 layer { name: "mnist" type: "Data" top: "data" top: "label" include { phase: TRAIN } transform_param { scale: 0.00390625 } data_param { source: "examples/mnist/mnist_train_lmdb" batch_size: 64 backend: LMDB } } # 数据层 测试时使用 layer { name: "mnist" type: "Data" top: "data" top: "label" include { phase: TEST } transform_param { scale: 0.00390625 } data_param { source: "examples/mnist/mnist_test_lmdb" batch_size: 100 backend: LMDB } } # 卷积层1 layer { name: "conv1" type: "Convolution" bottom: "data" top: "conv1" # weight和bias的学习速率 param { lr_mult: 1 } param { lr_mult: 2 } convolution_param { num_output: 20 kernel_size: 5 stride: 1 weight_filler { type: "xavier" } bias_filler { type: "constant" } } } # 池化层1 layer { name: "pool1" type: "Pooling" bottom: "conv1" top: "pool1" pooling_param { pool: MAX kernel_size: 2 stride: 2 } } # 卷积层2 layer { name: "conv2" type: "Convolution" bottom: "pool1" top: "conv2" param { lr_mult: 1 } param { lr_mult: 2 } convolution_param { num_output: 50 kernel_size: 5 stride: 1 weight_filler { type: "xavier" } bias_filler { type: "constant" } } } # 池化层2 layer { name: "pool2" type: "Pooling" bottom: "conv2" top: "pool2" pooling_param { pool: MAX kernel_size: 2 stride: 2 } } # 全连接层1 layer { name: "ip1" type: "InnerProduct" bottom: "pool2" top: "ip1" param { lr_mult: 1 } param { lr_mult: 2 } inner_product_param { num_output: 500 weight_filler { type: "xavier" } bias_filler { type: "constant" } } } # ReLU层1 layer { name: "relu1" type: "ReLU" bottom: "ip1" top: "ip1" } # 全连接层2 layer { name: "ip2" type: "InnerProduct" bottom: "ip1" top: "ip2" param { lr_mult: 1 } param { lr_mult: 2 } inner_product_param { 4000 num_output: 10 weight_filler { type: "xavier" } bias_filler { type: "constant" } } } # 准确率层 测试时使用 layer { name: "accuracy" type: "Accuracy" bottom: "ip2" bottom: "label" top: "accuracy" include { phase: TEST } } # loss层 layer { name: "loss" type: "SoftmaxWithLoss" bottom: "ip2" bottom: "label" top: "loss" }
三、定义Solver结构
在lenet_solver.prototxt中
# The train/test net protocol buffer definition net: "examples/mnist/lenet_train_test.prototxt" # test_iter specifies how many forward passes the test should carry out. # In the case of MNIST, we have test batch size 100 and 100 test iterations, # covering the full 10,000 testing images. test_iter: 100 # Carry out testing every 500 training iterations. test_interval: 500 # The base learning rate, momentum and the weight decay of the network. base_lr: 0.01 momentum: 0.9 weight_decay: 0.0005 # The learning rate policy lr_policy: "inv" gamma: 0.0001 power: 0.75 # Display every 100 iterations display: 100 # The maximum number of iterations max_iter: 10000 # snapshot intermediate results snapshot: 5000 snapshot_prefix: "examples/mnist/lenet" # solver mode: CPU or GPU solver_mode: GPU
四、训练和测试模型
cd $CAFFE_ROOT ./examples/mnist/train_lenet.sh
最后炼出的丹(模型的参数)就存在
lenet_iter_10000中
相关文章推荐
- Training LeNet on MNIST with Caffe
- 测试Caffe,Training LeNet on MNIST with Caffe
- Training LeNet on MNIST with Caffe|保存log绘制accuracy loss曲线
- caffe 练习1:training LeNet on MNIST with Caffe/ 用LeNet识别手写字符集 Mnist------by 香蕉麦乐迪
- caffe学习笔记:1、Training LeNet on MNIST with Caffe
- caffe 练习1:training LeNet on MNIST with Caffe/ 用LeNet识别手写字符集 Mnist------by 香蕉麦乐迪
- Caffe学习笔记《Training LeNet on MNIST with Caffe》
- Training LeNet on MNIST with Caffe
- 【Caffe 测试】Training LeNet on MNIST with Caffe
- Training MNIST LeNet on MNIST with Caffe
- caffe中MNIST数据集训练与测试LeNet
- Ubuntu 14.04 64位机上用Caffe+MNIST训练Lenet网络操作步骤
- 【caffe学习笔记之6】caffe-matlab/python训练LeNet模型并应用于mnist数据集(1)
- 利用caffe在mnist上训练LeNet
- 解析./build/tools/caffe train --solver=examples/mnist/lenet_solver.prototxt
- 【转载】Training a deep autoencoder or a classifier on MNIST digits
- 深入理解Caffe MNIST DEMO中的LeNet网络模型
- Vehicle Logo Recognition System Based on Convolutional Neural Networks With a Pretraining Strategy
- caffe中mnist中 lenet_train_test.prototxt和lenet.prototxt(deploy文件)区别
- Caffe 实践 在数据集MNIST上使用LeNet