caffe新增層:Focal Loss的caffe實現
1,caffe.proto
原始檔在src/caffe/proto/目錄裡
從492行這些optional裡,作者添加了兩行:
optional ReLU6Parameter relu6_param = 208;
optional FocalLossParameter focal_loss_param = 147;
從895行這裡添加了一行:
optional bool half_pad = 19 [default = false];
從1425行這裡新增一行:
optional bool reduce_boxes = 14 [default = false];
從1505行添加了一段:
message ReLU6Parameter{
enum Engine {
DEFAULT = 0;
CAFEE = 1;
CUDNN = 2;
}
optional Engine engine = 2[default = DEFAULT];
}
從1641行新增一段:
message FocalLossParameter{
enum Engine{
DEFAULT = 0;
CAFFE = 1;
CUDNN = 2;
}
optional Engine engine = 1[default = DEFAULT];
//The axis along which to perform the softmax -- may be negative to index
//from the end(e.g., -1 for the last axis).
//Any other axes will be evaluated as independent softmaxes.
optional int32 axis = 2[default = 1];
optional float alpha = 3[default = 0.25];
optional float gamma = 4[default = 2.0];
}
2.在src/caffe/layers/下放入focal_loss_layer.cpp和focal_loss_layer.cu檔案
3.在include/caffe/layers/下放入focla_loss_layer.hpp和multibox_focal_loss_layer.hpp
4. 修改prototxt:只需要修改一下層名
layer {
name: "mbox_loss"
type: "MultiBoxFocalLoss" #change the type
bottom: "mbox_loc"
bottom: "mbox_conf"
bottom: "mbox_priorbox"
bottom: "label"
top: "mbox_loss"
include {
phase: TRAIN
}
propagate_down: true
propagate_down: true
propagate_down: false
propagate_down: false
loss_param {
normalization: VALID
}
focal_loss_param { #set the alpha and gamma, default is alpha=0.25, gamma=2.0
alpha: 0.25
gamma: 2.0
}
multibox_loss_param {
loc_loss_type: SMOOTH_L1
conf_loss_type: SOFTMAX
loc_weight: 1.0
num_classes: 2
share_location: true
match_type: PER_PREDICTION
overlap_threshold: 0.5
use_prior_for_matching: true
background_label_id: 0
use_difficult_gt: true
neg_pos_ratio: 3.0
neg_overlap: 0.5
code_type: CENTER_SIZE
ignore_cross_boundary_bbox: false
mining_type: NONE #do not use OHEM
}
}
重新編譯Caffe
---------------------
作者:BigCowPeking
來源:CSDN
原文:https://blog.csdn.net/wfei101/article/details/79477542
版權宣告:本文為博主原創文章,轉載請附上博文連結!