【问题标题】:How to use the Spatial Pyramid Layer in caffe in proto files?如何在 proto 文件中使用 caffe 中的空间金字塔层?
【发布时间】:2017-12-19 11:57:29
【问题描述】:

您好,我想知道如何在 proto 文件中使用 SPP Layer。 也许有人可以向我解释如何阅读 caffe 文档,因为有时我很难直接理解它。

我的尝试是基于这个protofile,但我认为它与当前版本不同?


我这样定义层:

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
  }
}

当我尝试开始学习时,我收到以下错误消息:

[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:

完整的 proto 文件(具有批量标准化和 SPP 的 Lenet):

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"
}

【问题讨论】:

  • 我将 protobuf-net 更改为 protobuf,因为我很确定它与 protobuf-net 无关;老实说,我怀疑它与 protobuf 有关,但我不太确定
  • @MarcGravell 好的,谢谢

标签: neural-network protocol-buffers caffe


【解决方案1】:

好的,我找到了。


定义 SPP 层的正确方法如下:

layer {
  name: "spatial_pyramid_pooling"
  type: "SPP"
  bottom: "conv2"
  top: "pool2"
  spp_param {
    pyramid_height: 2
  }
} 

请注意,我之前写的是 layers 而不是 layer。 此外,您可以在spp_param{} 中指定该层的参数。 正式版的 caffe 没有 bins 作为选项,而是金字塔高度。所以我第一次尝试的版本是不正确的。


给我自己和任何刚接触 caffe 并且对文档的风格有点困惑的人的一些注释。

文档:

  • 图层类型:SPP

...

message SPPParameter {
  enum PoolMethod {
    MAX = 0;
    AVE = 1;
    STOCHASTIC = 2;
  }
  optional uint32 pyramid_height = 1;
  optional PoolMethod pool = 2 [default = MAX]; // The pooling method
  enum Engine {
    DEFAULT = 0;
    CAFFE = 1;
    CUDNN = 2;
  }
  optional Engine engine = 6 [default = DEFAULT];
}

注意事项:

  • 层类型定义了在 proto 文件中声明层类型的关键字(如果你知道的话,这是合乎逻辑的)

  • 此定义中的Enumsparameter 的可能值。

  • 不能在与类型或名称相同的级别上定义参数。相反,您必须将其包装在 layerspecifc 参数关键字 (spp_param) 中。 这个关键字是这样构建的 <layertype>_param{} 小写字母。

【讨论】:

  • 如果图层类型包含多个单词,例如 InnerProduct,则在相应参数中的两个单词之间会出现下划线,例如 inner_product_param
猜你喜欢
  • 1970-01-01
  • 2017-04-03
  • 1970-01-01
  • 1970-01-01
  • 2016-08-25
  • 2023-04-09
  • 2011-02-11
  • 1970-01-01
  • 2018-12-30
相关资源
最近更新 更多