Neural network 如何在原始文件中使用caffe中的空间金字塔层?
嗨,我想知道如何在proto文件中使用。 也许有人能给我解释一下如何阅读caffe文档,因为有时我很难直接理解 我的尝试基于此,但我认为它与当前版本不同Neural network 如何在原始文件中使用caffe中的空间金字塔层?,neural-network,protocol-buffers,caffe,Neural Network,Protocol Buffers,Caffe,嗨,我想知道如何在proto文件中使用。 也许有人能给我解释一下如何阅读caffe文档,因为有时我很难直接理解 我的尝试基于此,但我认为它与当前版本不同 我这样定义层: layers { name: "spatial_pyramid_pooling" type: "SPP" bottom: "conv2" top: "spatial_pyramid_pooling" spatial_pyramid_pooling_param { pool: MAX spat
我这样定义层:
layers {
name: "spatial_pyramid_pooling"
type: "SPP"
bottom: "conv2"
top: "spatial_pyramid_pooling"
spatial_pyramid_pooling_param {
pool: MAX
spatial_bin: 1
spatial_bin: 2
spatial_bin: 3
spatial_bin: 6
scale: 1
}
}
layer {
name: "spatial_pyramid_pooling"
type: "SPP"
bottom: "conv2"
top: "pool2"
spp_param {
pyramid_height: 2
}
}
当我尝试开始学习时,会收到以下错误消息:
[libprotobuf ERROR google/protobuf/text_format.cc:287] Error parsing text-format caffe.NetParameter: 137:9: Expected integer or identifier, got: "SPP"
F0714 13:25:38.782958 2061316096 upgrade_proto.cpp:88] Check failed: ReadProtoFromTextFile(param_file, param) Failed to parse NetParameter file:
name: "TessDigitMean"
layer {
name: "input"
type: "Data"
top: "data"
top: "label"
include {
phase: TRAIN
}
transform_param {
scale: 0.00390625
}
data_param {
source: "/Users/rvaldez/Documents/Datasets/Digits/SeperatedProviderV3_1020_batchnormalizedV2AndSPP/1/caffe/train_lmdb"
batch_size: 64
backend: LMDB
}
}
layer {
name: "input"
type: "Data"
top: "data"
top: "label"
include {
phase: TEST
}
transform_param {
scale: 0.00390625
}
data_param {
source: "/Users/rvaldez/Documents/Datasets/Digits/SeperatedProviderV3_1020_batchnormalizedV2AndSPP/1/caffe/test_lmdb"
batch_size: 10
backend: LMDB
}
}
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: "bn1"
type: "BatchNorm"
bottom: "pool1"
top: "bn1"
batch_norm_param {
use_global_stats: false
}
param {
lr_mult: 0
}
param {
lr_mult: 0
}
param {
lr_mult: 0
}
include {
phase: TRAIN
}
}
layer {
name: "bn1"
type: "BatchNorm"
bottom: "pool1"
top: "bn1"
batch_norm_param {
use_global_stats: true
}
param {
lr_mult: 0
}
param {
lr_mult: 0
}
param {
lr_mult: 0
}
include {
phase: TEST
}
}
layer {
name: "conv2"
type: "Convolution"
bottom: "bn1"
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"
}
}
}
layers {
name: "spatial_pyramid_pooling"
type: "SPP"
bottom: "conv2"
top: "spatial_pyramid_pooling"
spatial_pyramid_pooling_param {
pool: MAX
spatial_bin: 1
spatial_bin: 2
spatial_bin: 3
spatial_bin: 6
scale: 1
}
}
layer {
name: "bn2"
type: "BatchNorm"
bottom: "spatial_pyramid_pooling"
top: "bn2"
batch_norm_param {
use_global_stats: false
}
param {
lr_mult: 0
}
param {
lr_mult: 0
}
param {
lr_mult: 0
}
include {
phase: TRAIN
}
}
layer {
name: "bn2"
type: "BatchNorm"
bottom: "pool2"
top: "bn2"
batch_norm_param {
use_global_stats: true
}
param {
lr_mult: 0
}
param {
lr_mult: 0
}
param {
lr_mult: 0
}
include {
phase: TEST
}
}
layer {
name: "ip1"
type: "InnerProduct"
bottom: "bn2"
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"
}
}
}
layer {
name: "accuracy"
type: "Accuracy"
bottom: "ip2"
bottom: "label"
top: "accuracy"
include {
phase: TEST
}
}
layer {
name: "loss"
type: "SoftmaxWithLoss"
bottom: "ip2"
bottom: "label"
top: "loss"
}
完整的原始文件(带有批量标准化和SPP的Lenet):
[libprotobuf ERROR google/protobuf/text_format.cc:287] Error parsing text-format caffe.NetParameter: 137:9: Expected integer or identifier, got: "SPP"
F0714 13:25:38.782958 2061316096 upgrade_proto.cpp:88] Check failed: ReadProtoFromTextFile(param_file, param) Failed to parse NetParameter file:
name: "TessDigitMean"
layer {
name: "input"
type: "Data"
top: "data"
top: "label"
include {
phase: TRAIN
}
transform_param {
scale: 0.00390625
}
data_param {
source: "/Users/rvaldez/Documents/Datasets/Digits/SeperatedProviderV3_1020_batchnormalizedV2AndSPP/1/caffe/train_lmdb"
batch_size: 64
backend: LMDB
}
}
layer {
name: "input"
type: "Data"
top: "data"
top: "label"
include {
phase: TEST
}
transform_param {
scale: 0.00390625
}
data_param {
source: "/Users/rvaldez/Documents/Datasets/Digits/SeperatedProviderV3_1020_batchnormalizedV2AndSPP/1/caffe/test_lmdb"
batch_size: 10
backend: LMDB
}
}
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: "bn1"
type: "BatchNorm"
bottom: "pool1"
top: "bn1"
batch_norm_param {
use_global_stats: false
}
param {
lr_mult: 0
}
param {
lr_mult: 0
}
param {
lr_mult: 0
}
include {
phase: TRAIN
}
}
layer {
name: "bn1"
type: "BatchNorm"
bottom: "pool1"
top: "bn1"
batch_norm_param {
use_global_stats: true
}
param {
lr_mult: 0
}
param {
lr_mult: 0
}
param {
lr_mult: 0
}
include {
phase: TEST
}
}
layer {
name: "conv2"
type: "Convolution"
bottom: "bn1"
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"
}
}
}
layers {
name: "spatial_pyramid_pooling"
type: "SPP"
bottom: "conv2"
top: "spatial_pyramid_pooling"
spatial_pyramid_pooling_param {
pool: MAX
spatial_bin: 1
spatial_bin: 2
spatial_bin: 3
spatial_bin: 6
scale: 1
}
}
layer {
name: "bn2"
type: "BatchNorm"
bottom: "spatial_pyramid_pooling"
top: "bn2"
batch_norm_param {
use_global_stats: false
}
param {
lr_mult: 0
}
param {
lr_mult: 0
}
param {
lr_mult: 0
}
include {
phase: TRAIN
}
}
layer {
name: "bn2"
type: "BatchNorm"
bottom: "pool2"
top: "bn2"
batch_norm_param {
use_global_stats: true
}
param {
lr_mult: 0
}
param {
lr_mult: 0
}
param {
lr_mult: 0
}
include {
phase: TEST
}
}
layer {
name: "ip1"
type: "InnerProduct"
bottom: "bn2"
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"
}
}
}
layer {
name: "accuracy"
type: "Accuracy"
bottom: "ip2"
bottom: "label"
top: "accuracy"
include {
phase: TEST
}
}
layer {
name: "loss"
type: "SoftmaxWithLoss"
bottom: "ip2"
bottom: "label"
top: "loss"
}
好的,我找到了
定义SPP层的正确方法如下:
layers {
name: "spatial_pyramid_pooling"
type: "SPP"
bottom: "conv2"
top: "spatial_pyramid_pooling"
spatial_pyramid_pooling_param {
pool: MAX
spatial_bin: 1
spatial_bin: 2
spatial_bin: 3
spatial_bin: 6
scale: 1
}
}
layer {
name: "spatial_pyramid_pooling"
type: "SPP"
bottom: "conv2"
top: "pool2"
spp_param {
pyramid_height: 2
}
}
请注意,我以前编写的是层
,而不是层
。
此外,您可以在spp_param{}
中为该层指定参数。
caffe的官方版本没有垃圾箱作为选项,而是金字塔高度。所以我第一次尝试所基于的版本是不正确的
给我自己和任何一个刚接触caffe的人一些笔记,这些人对文档的风格有点困惑 文档:
layers {
name: "spatial_pyramid_pooling"
type: "SPP"
bottom: "conv2"
top: "spatial_pyramid_pooling"
spatial_pyramid_pooling_param {
pool: MAX
spatial_bin: 1
spatial_bin: 2
spatial_bin: 3
spatial_bin: 6
scale: 1
}
}
layer {
name: "spatial_pyramid_pooling"
type: "SPP"
bottom: "conv2"
top: "pool2"
spp_param {
pyramid_height: 2
}
}
- 图层类型:SPP
layers {
name: "spatial_pyramid_pooling"
type: "SPP"
bottom: "conv2"
top: "spatial_pyramid_pooling"
spatial_pyramid_pooling_param {
pool: MAX
spatial_bin: 1
spatial_bin: 2
spatial_bin: 3
spatial_bin: 6
scale: 1
}
}
layer {
name: "spatial_pyramid_pooling"
type: "SPP"
bottom: "conv2"
top: "pool2"
spp_param {
pyramid_height: 2
}
}
- Layer type定义了在proto文件中声明层类型的关键字(如果您知道的话,这是一种逻辑)
- 此定义中的枚举是参数的可能值
- 参数不能与类型或名称在同一级别上定义。相反,您必须将其包装在layerspecifc参数关键字(
)中。 此关键字的构建类似于此spp_param
,以小写字母表示\u param{}