17 #include "sigmoid_focal_loss_op.h" 21 REGISTER_CPU_OPERATOR(SigmoidFocalLoss, SigmoidFocalLossOp<float, CPUContext>);
22 REGISTER_CPU_OPERATOR(
23 SigmoidFocalLossGradient,
24 SigmoidFocalLossGradientOp<float, CPUContext>);
26 OPERATOR_SCHEMA(SigmoidFocalLoss)
30 The binary form of Focal Loss designed for use in RetinaNet-like models. 31 The input is assumed to be unnormalized scores (sometimes called 'logits') 32 arranged in a 4D tensor with shape (N, C, H, W), where N is the number of 33 elements in the batch, H and W are the height and width, and C = num_anchors * 34 num_classes defines num_anchors 'groups' of logits, each of length 35 num_classes. For the binary form of Focal Loss, num_classes does not include 36 the background category. (So, for COCO, num_classes = 80, not 81.) 38 The binary form of focal loss is: 40 FL(p_t) = -alpha * (1 - p_t)**gamma * log(p_t), 42 where p = sigmoid(x), p_t = p or 1 - p depending on if the label is 1 or 0, 45 See: https://arxiv.org/abs/1708.02002 for details. 49 "(float) default 1.0; multiply the loss by this scale factor.")
52 "(float) default 0.25; Focal Loss's alpha hyper-parameter.")
55 "(float) default 1.0; Focal Loss's gamma hyper-parameter.")
58 "(int) default 80; number of classes (excluding background).")
62 "4D tensor of sigmoid inputs (called 'scores' or 'logits') with shape " 63 "(N, C, H, W), where C = num_anchors * num_classes.")
67 "4D tensor of labels with shape (N, num_anchors, H, W). Each entry is " 68 "a class label in [0, num_classes - 1] (inclusive). The label " 69 "identifies the one class that should have a sigmoid target of 1.")
73 "Scalar; the loss is normalized by 1 / max(1, normalizer)." 80 OPERATOR_SCHEMA(SigmoidFocalLossGradient)
86 "See SigmoidFocalLoss.")
90 "See SigmoidFocalLoss.")
94 "See SigmoidFocalLoss.")
98 "Gradient of forward output 0 (loss)")
102 "Gradient of forward input 0 (logits)");
105 using GradientMakerBase::GradientMakerBase;
107 vector<OperatorDef> GetGradientDefs()
override {
108 vector<string> blob_names{
109 {I(0), I(1), I(2), GO(0)},
113 "SigmoidFocalLossGradient",
"", blob_names, vector<string>{GI(0)});
A global dictionary that holds information about what Caffe2 modules have been loaded in the current ...
static vector< OperatorDef > SingleGradientDef(const Args &...args)
a helper function to allow one to create one single operator def, which is usually the case for many ...