之前用deploy.prototxt 还原train_val.prototxt过程中,遇到了坑,所以打算总结一下

本人以熟悉的LeNet网络结构为例子

不同点主要在一前一后,相同点都在中间

train_val.prototxt 中的开头

看这个名字也知道,里面定义的是训练和验证时候的网络,所以在开始的时候要定义训练集和验证集的来源

name: "LeNet"
layer {
name: "mnist"
type: "Data"
top: "data"
top: "label"
include {
phase: TRAIN
}
transform_param {
scale: 0.00390625
}
data_param {
# 这里定义了之前将数据集转成lmdb数据格式的文件位置
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
}
}

  

deploy.prototxt 中的开头

看这个名字也知道,这个配置文件适用于部署,也就是用于实际场景时候的配置文件,所以开始的时候不必在定义数据集的来源,但是需要定义输入数据的大小格式。

name: "LeNet"
layer {
name: "data"
type: "Input"
top: "data"
# 输入数据的batch size, channel, width, height
input_param { shape: { dim: 64 dim: 1 dim: 28 dim: 28 } }
}

  

train_val.prototxt 中的结尾

如果是一般的卷积网络的话,最后面都是用一个全连接,将feature map 转成固定长度的向量,然后输出种类的个数。所以在最后的时候,需要说明输出种类的个数。

layer {
name: "ip2"
type: "InnerProduct"
bottom: "ip1"
top: "ip2"
param {
lr_mult: 1
}
param {
lr_mult: 2
}
inner_product_param {
# 在这里定义了输出种类的个数
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
}
}

  

最后还有一个不同就是,因为是训练模型,所以包括forward和backward,所以最后需要定义一个损失函数。这里用的是SoftmaxWithLoss,而在deploy.prototxt,因为只有forward,所以定义的是Softmax,也就是分类器。

layer {
name: "loss"
# 定义的是损失函数
type: "SoftmaxWithLoss"
bottom: "ip2"
bottom: "label"
top: "loss"
}

  

deploy.prototxt 中的最后

这里定义了Softmax分类器,输出最后各类的概率值。

layer {
name: "prob"
# 定义的是分类器
type: "Softmax"
bottom: "ip2"
top: "prob"
}

  

train_val.prototxt 和 deploy.prototxt中间部分

两个的中间部分都是一样的,定义了一些卷积、激活、池化、Dropout、LRN(local response normalization)、全连接等操作。

layer {
name: "conv1"
type: "Convolution"
bottom: "data"
top: "conv1"
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"
}
}
}
layer {
name: "pool1"
type: "Pooling"
bottom: "conv1"
top: "pool1"
pooling_param {
pool: MAX
kernel_size: 2
stride: 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"
}
}
}
layer {
name: "pool2"
type: "Pooling"
bottom: "conv2"
top: "pool2"
pooling_param {
pool: MAX
kernel_size: 2
stride: 2
}
}
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"
}
}
}
layer {
name: "relu1"
type: "ReLU"
bottom: "ip1"
top: "ip1"
}
layer {
name: "ip2"
type: "InnerProduct"
bottom: "ip1"
top: "ip2"
param {
lr_mult: 1
}
param {
lr_mult: 2
}
inner_product_param {
num_output: 10
weight_filler {
type: "xavier"
}
bias_filler {
type: "constant"
}
}
}

  

Caffe中deploy.prototxt 和 train_val.prototxt 区别的更多相关文章

  1. 浅谈caffe中train_val.prototxt和deploy.prototxt文件的区别

    本文以CaffeNet为例: 1. train_val.prototxt  首先,train_val.prototxt文件是网络配置文件.该文件是在训练的时候用的. 2.deploy.prototxt ...

  2. CAFFE中训练与使用阶段网络设计的不同

    神经网络中,我们通过最小化神经网络来训练网络,所以在训练时最后一层是损失函数层(LOSS), 在测试时我们通过准确率来评价该网络的优劣,因此最后一层是准确率层(ACCURACY). 但是当我们真正要使 ...

  3. 4.caffe:train_val.prototxt、 solver.prototxt 、 deploy.prototxt( 创建模型与编写配置文件)

    一,train_val.prototxt name: "CIFAR10_quick" layer { name: "cifar" type: "Dat ...

  4. Caffe学习系列(8):solver,train_val.prototxt,deploy.prototxt及其配置

    solver是caffe的核心. net: "examples/mnist/lenet_train_test.prototxt" test_iter: 100 test_inter ...

  5. train_val.prototxt文件和deploy.prototxt文件开头的区别

    1.开头不同 对train_val.prototxt文件来说,开头部分定义训练和测试的网络及参数 对deploy.prototxt文件来说,开头部分定义实际运用场景的配置文件,其参数不定义数据来源,仅 ...

  6. caffe中LetNet-5卷积神经网络模型文件lenet.prototxt理解

    caffe在 .\examples\mnist文件夹下有一个 lenet.prototxt文件,这个文件定义了一个广义的LetNet-5模型,对这个模型文件逐段分解一下. name: "Le ...

  7. Windows下使用python绘制caffe中.prototxt网络结构数据可视化

    准备工具: 1. 已编译好的pycaffe 2. Anaconda(python2.7) 3. graphviz 4. pydot  1. graphviz安装 graphviz是贝尔实验室开发的一个 ...

  8. caffe中train过程的train数据集、val数据集、test时候的test数据集区别

    val是validation的简称.training dataset 和 validation dataset都是在训练的时候起作用.而因为validation的数据集和training没有交集,所以 ...

  9. pycaffe︱caffe中fine-tuning模型三重天(函数详解、框架简述)

    本文主要参考caffe官方文档[<Fine-tuning a Pretrained Network for Style Recognition>](http://nbviewer.jupy ...

随机推荐

  1. Python json使用

    转自:https://www.cnblogs.com/wangyayun/p/6699184.html?utm_source=tuicool&utm_medium=referral 使用Pyt ...

  2. Java总结——常见Java集合实现细节(1)

    Java提高——常见Java集合实现细节(1) 2018年04月18日 15:07:35 阅读数:25 集合关系图 Set和Map set代表一种集合元素无序.集合元素不可重复的集合 map代表一种由 ...

  3. python3脚本获取本机公网ip

    python脚本获取本机公网ip   1.获取公网IP地址方式,访问:http://txt.go.sohu.com/ip/soip 2.代码实现 import requests import re r ...

  4. PAT 1066. Root of AVL Tree (25)

    An AVL tree is a self-balancing binary search tree. In an AVL tree, the heights of the two child sub ...

  5. 《编写可维护的javascript》读书笔记(上)

    最近在读<编写可维护的javascript>这本书,为了加深记忆,简单做个笔记,同时也让没有读过的同学有一个大概的了解. 一.编程风格 程序是写给人读的,所以一个团队的编程风格要保持一致. ...

  6. speech模块实现语音识别

    1.pip安装speech.pywin32 pip install speech pip install pywin32 2.例子 #!/usr/bin/python # coding:utf-8 f ...

  7. windows10 卸载 Docker 和 DockerNAT

    删除docker程序 记事本新建脚本文件 a.ps1,内容如下: $ErrorActionPreference = "SilentlyContinue" kill -force - ...

  8. [POJ1144]Network

    来源:Central Europe 1996 思路:Tarjan求割点. 一个点$x$为割点当且仅当: 1.$x$为根结点且有两棵不相交的子树. 2.$x$不为根结点且它的子树中没有可以返回到$x$的 ...

  9. BZOJ1170 : [Balkan2007]Cipher

    首先对于每个位置,求出它开始长度为y的横行的hash值,然后对于hash值再求一次竖列的hash值,排序后求出众数即可. 时间复杂度$O(n^2\log n)$. #include<cstdio ...

  10. Cannot create a new pixel buffer adaptor with an asset writer input that has already started writing'

    reason: '*** -[AVAssetWriterInputPixelBufferAdaptor initWithAssetWriterInput:sourcePixelBufferAttrib ...