def forward(self, input: torch.Tensor, target: torch.Tensor):
    '\n        Args:\n            input: (B, #anchors, #classes) float tensor.\n                Predicted logits for each class\n            target: (B, #anchors, #classes) float tensor.\n                One-hot encoded classification targets\n            weights: (B, #anchors) float tensor.\n                Anchor-wise weights.\n\n        Returns:\n            weighted_loss: (B, #anchors, #classes) float tensor after weighting.\n        '
    num_pos = torch.sum(target)
    pred_sigmoid = torch.sigmoid(input)
    alpha_weight = ((target * self.alpha) + ((1 - target) * (1 - self.alpha)))
    pt = ((target * (1.0 - pred_sigmoid)) + ((1.0 - target) * pred_sigmoid))
    focal_weight = (alpha_weight * torch.pow(pt, self.gamma))
    bce_loss = self.sigmoid_cross_entropy_with_logits(input, target)
    loss = (focal_weight * bce_loss)
    loss = (loss.sum() / num_pos)
    return loss
Args:
    input: (B, #anchors, #classes) float tensor.
        Predicted logits for each class
    target: (B, #anchors, #classes) float tensor.
        One-hot encoded classification targets
    weights: (B, #anchors) float tensor.
        Anchor-wise weights.

Returns:
    weighted_loss: (B, #anchors, #classes) float tensor after weighting.
def forward(self, input: torch.Tensor, target: torch.Tensor):
    '\n        Args:\n            input: (B, #anchors, #classes) float tensor.\n                Predicted logits for each class\n            target: (B, #anchors, #classes) float tensor.\n                One-hot encoded classification targets\n            weights: (B, #anchors) float tensor.\n                Anchor-wise weights.\n\n        Returns:\n            weighted_loss: (B, #anchors, #classes) float tensor after weighting.\n        '
    num_pos = torch.sum(target)
    pred_sigmoid = torch.sigmoid(input)
    alpha_weight = ((target * self.alpha) + ((1 - target) * (1 - self.alpha)))
    pt = ((target * (1.0 - pred_sigmoid)) + ((1.0 - target) * pred_sigmoid))
    focal_weight = (alpha_weight * torch.pow(pt, self.gamma))
    bce_loss = self.sigmoid_cross_entropy_with_logits(input, target)
    loss = (focal_weight * bce_loss)
    loss = (loss.sum() / num_pos)
    return loss