您的位置:首页 > Web前端

Caffe常用层参数介绍

2016-07-25 16:50 260 查看

DATA

crop:截取原图像中一个固定patch

layers {
name: "data"
type: DATA
top: "data"
top: "label"
data_param {
source: "../data/ImageNet/imagenet-train" #数据存放位置
batch_size: 128 #一次批处理的大小,视内存大小而定。四维数组N*C*H*W中的N
backend: LMDB #数据库类型,默认为leveldb
}
include: { phase: TRAIN } #如果加了这一行的话表示是在训练过程中使用该层,可将TRAIN替换为TEST
}


CONVOLUTION

layer {
name: "conv"
type: "Convolution"
bottom: "data"
top: "conv"
param {
lr_mult: 1 #权重的学习率 该层lr=lr_mult*base_lr
decay_mult: 1 #权重的衰减值
}
param {
lr_mult: 2 #偏置项的学习率
decay_mult: 0 #偏置项的衰减值
}
convolution_param {
num_output: 96 #该层输出的filter的个数。四维数组N*C*H*W中的W
kernel_size: 11 #卷积核大小11*11。可设定长kernel_h与宽kernel_w
stride: 4 #步长,也就是卷积核滑动的距离
weight_filler { #卷积核初始化方式
type: "gaussian" #高斯分布
std: 0.01 #标准差为0.01
}
bias_filler { #偏置项初始化方式
type: "constant" #连续分布
value: 0
}
}
}


这里说一下关于weight_filler和bias_filler的几种设定方式:

TYPEPARAMEXPLAIN
ConstantValue以常量初始化,初始化值为[Value]
Gaussianstd,mean以高斯分布方式初始化,均值为[mean],标准差为[std]
uniformmin,max均匀分布,[min,max]
xavierscale均匀分布,[-scale,scale],scale=sqrt(3/K*H*W)

RELU

layer {
name: "relu"
type: "ReLU"
bottom: "conv"
top: "conv"
}


Relu标准函数:f(x)=max(0,x)。

当未指定negative_slope值时,为标准Relu层;指定negative_slope值时,f(x)={x,negative_slope×x,x>0x≤0

LRN

layer {
name: "norm"
type: "LRN"
bottom: "conv"
top: "norm"
lrn_param {
local_size: 5#对于cross channel LRN,表示需要求和的channel的数量;对于within channel LRN,表示需要求和的空间区域的边长。默认为5
alpha: 0.0001 #LRN公式中的参数alpha
beta: 0.75 #LRN公式中的参数beta
}
}


POOLING

layer {
name: "pool"
type: "Pooling"
bottom: "norm1"
top: "pool1"
pooling_param {
pool: MAX #有三种池化方式:MAX,AVG,STOCHASTIC
kernel_size: 3 #卷积核大小;可设定长kernel_h与宽kernel_w
stride: 2 #步长
}
}


INNERPRODUCT

参数和卷积层几乎一样,仅贴出代码,不做过多解释

layer {
name: "fc7"
type: "InnerProduct"
bottom: "fc6"
top: "fc7"
param {
lr_mult: 1
decay_mult: 1
}
param {
lr_mult: 2
decay_mult: 0
}
inner_product_param {
num_output: 4096
weight_filler {
type: "gaussian"
std: 0.005
}
bias_filler {
type: "constant"
value: 0.1
}
}
}


ACCURACY

layer {
name: "accuracy"
type: "Accuracy"
bottom: "fc8"
bottom: "label"
top: "accuracy"
include {phase: TEST}
}


可添加

accuracy_param {
top_k: 5
}


默认为top_1,添加该项后,选择测试top_k准确率。

SOFTMAX_LOSS

layers {
name: "loss"
type: SOFTMAX_LOSS
bottom: "pool3"
bottom: "label"
top: "loss"
include: { phase: TRAIN }
}


注意,在计算softmax_loss前,将pool3层默认经过了一次softmax计算。

另外,以上所有层的name项都是自己随意定的,只要好辨认,不重复就可以。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: