SSD网络模型prototxt修改

本章节所有的代码样例都不能直接复制到网络模型中使用,需要用户根据使用的网络模型,自行调整相应参数,比如bottom、top中的参数要和具体网络模型中的bottom、top一一对应,并且bottom和top对应的参数顺序不能更改。

对于SSD网络,参考扩展算子列表在原始prototxt文件的最后增加后处理算子层SSDDetectionOutput。

参见caffe.proto文件(该文件路径为${INSTALL_DIR}/include/proto),先在LayerParameter message中添加自定义层参数的声明(如下自定义层在caffe.proto中已经声明,用户无需再次添加):

message LayerParameter {
...
  optional SSDDetectionOutputParameter ssddetectionoutput_param = 232;
...
}

参见caffe.proto文件,此算子的Type及属性定义如下:

message SSDDetectionOutputParameter {
    optional int32 num_classes= 1 [default = 2];
    optional bool share_location = 2 [default = true];
    optional int32 background_label_id = 3 [default = 0];
    optional float iou_threshold = 4 [default = 0.45];
    optional int32 top_k = 5 [default = 400];
    optional float eta = 6 [default = 1.0];
    optional bool variance_encoded_in_target = 7 [default = false];
    optional int32 code_type = 8 [default = 2];
    optional int32 keep_top_k = 9 [default = 200];
    optional float confidence_threshold = 10 [default = 0.01];
}

参见支持Caffe算子清单,SSDDetectionOutput算子有3个输入,2个输出,基于上述原则,构造的代码样例如下:

layer {
  name: "detection_out"
  type: "SSDDetectionOutput"
  bottom: "bbox_delta"
  bottom: "score"
  bottom: "anchors"
  top: "out_boxnum"
  top: "y"
  ssddetectionoutput_param {
    num_classes: 2
    share_location: true
    background_label_id: 0
    iou_threshold: 0.45
    top_k: 400
    eta: 1.0
    variance_encoded_in_target: false
    code_type: 2
    keep_top_k: 200
    confidence_threshold: 0.01
  }
}

参数解释请参见支持Caffe算子清单