torchvision.ops.focal_loss — Torchvision main documentation
pytorch.org › torchvision › opsReturns: Loss tensor with the reduction option applied. """ if not torch. jit. is_scripting and not torch. jit. is_tracing (): _log_api_usage_once (sigmoid_focal_loss) p = torch. sigmoid (inputs) ce_loss = F. binary_cross_entropy_with_logits (inputs, targets, reduction = "none") p_t = p * targets + (1-p) * (1-targets) loss = ce_loss * ((1-p_t) ** gamma) if alpha >= 0: alpha_t = alpha * targets + (1-alpha) * (1-targets) loss = alpha_t * loss if reduction == "mean": loss = loss. mean elif ...