Focal loss addresses class imbalance by down-weighting easy examples and focusing on hard ones. It is particularly useful for object detection where background is dominant.
focal(pt,γ=2.0)=−(1−pt)γlog(pt)Where p_t is the model's probability of the ground truth class. When p_t is high (easy), the weight (1-p_t)^gamma is small. When p_t is low (hard), the weight is large.
Implement:
focal_loss(logits, labels, gamma=2.0)
Where logits are raw model outputs, labels are 0/1 class labels.
No results yet
Run your code to check it against the examples, or submit to run every test.