"Focal Loss for Dense Object Detection" by Tsung-Yi Lin et al. introduces the Focal Loss function as an improvement over the standard Cross-Entropy (CE) loss for the specific problem of dense object detection. The Focal Loss is designed to address the issue of class imbalance by down-weighting the contribution of easy examples so that the loss focuses more on hard, misclassified examples.
The standard Binary Cross-Entropy (BCE) loss and the CE loss used in the Focal Loss paper are conceptually similar but have different formulations due to the problem they are addressing.
In a standard BCE loss for a binary classification problem, the loss is formulated as follows:
BCE(p_t) = - y log(p) - (1 - y) log(1 - p),
where:
y is the ground truth label (0 or 1),
p is the predicted probability of the positive class,
p_t is the transformed probability, and it's equal to p if y=1, or 1-p if y=0.
The CE loss from the Focal Loss paper for binary classification, denoted as equation (1), can be written as:
CE(p_t) = - log(p_t),
where p_t is the same transformed probability as in BCE and takes into account whether y is 0 or 1.
The Focal Loss itself, described in equations (2) and (3) of the paper, modifies this CE loss to create a new loss function:
FL(p_t) = - α_t (1 - p_t) ^ γ log(p_t),
where:
α_t is a balancing factor that can differ depending on the ground truth class,
(1 - p_t) ^ γ is a modulating factor with the tunable focusing parameter γ that reduces the loss contribution from easy examples and increases the relative loss for hard, misclassified examples.
The BCE loss inherently has terms for both the positive class and the negative class. In contrast, the CE loss from the Focal Loss paper, by using p_t, simplifies the expression, because it only has to deal with the negative log-likelihood of the transformed prediction p_t. It does not explicitly separate the two cases for y=0 and y=1. The Focal Loss extends this CE loss by adding the modulating factor (1 - p_t) ^ γ and the optional weighting factor α_t.
One key difference between BCE and CE in the context of object detection tasks is that the latter (including as modified by Focal Loss) must often be adapted to work with multiple classes and not just binary outcomes. The Focal Loss paper generalizes this approach to multi-class scenarios by using a one-vs-all approach, where the Focal Loss is applied independently to each class.