callcut.training.FocalLossπ
- class callcut.training.FocalLoss(alpha=0.25, gamma=2.0)[source]π
Focal loss for handling class imbalance.
Down-weights easy examples to focus training on hard negatives. Particularly useful when positive (call) frames are rare.
The focal loss is defined as:
\[\begin{split}FL(p_t) = -\\alpha_t (1 - p_t)^\\gamma \\log(p_t)\end{split}\]where \(p_t\) is the modelβs estimated probability for the correct class.
- Parameters:
Attributes
Methods
forward(logits, targets)Compute focal loss.
Examples
>>> loss_fn = FocalLoss(alpha=0.75, gamma=2.0) >>> loss = loss_fn(logits, targets)