def forward(self, prediction_tensor, target_tensor):
    alpha = self.alpha
    gamma = self.gamma
    'Compute focal loss for predictions.\n            Multi-labels Focal loss formula:\n                FL = -alpha * (z-p)^gamma * log(p) -(1-alpha) * p^gamma * log(1-p)\n                     ,which alpha = 0.25, gamma = 2, p = sigmoid(x), z = target_tensor.\n        Args:\n         prediction_tensor: A float tensor of shape [batch_size, num_anchors,\n            num_classes] representing the predicted logits for each class\n         target_tensor: A float tensor of shape [batch_size, num_anchors,\n            num_classes] representing one-hot encoded classification targets\n         weights: A float tensor of shape [batch_size, num_anchors]\n         alpha: A scalar tensor for focal loss alpha hyper-parameter\n         gamma: A scalar tensor for focal loss gamma hyper-parameter\n        Returns:\n            loss: A (scalar) tensor representing the value of the loss function\n        '
    sigmoid_p = torch.sigmoid(prediction_tensor)
    zeros = torch.zeros_like(sigmoid_p, dtype=sigmoid_p.dtype)
    pos_p_sub = torch.where((target_tensor > zeros), (target_tensor - sigmoid_p), zeros)
    neg_p_sub = torch.where((target_tensor > zeros), zeros, sigmoid_p)
    per_entry_cross_ent = ((((- alpha) * (pos_p_sub ** gamma)) * torch.log(clip_by_tensor(sigmoid_p, 1e-08, 1.0))) - (((1 - alpha) * (neg_p_sub ** gamma)) * torch.log(clip_by_tensor((1.0 - sigmoid_p), 1e-08, 1.0))))
    return per_entry_cross_ent.mean()
def forward(self, prediction_tensor, target_tensor):
    alpha = self.alpha
    gamma = self.gamma
    'Compute focal loss for predictions.\n            Multi-labels Focal loss formula:\n                FL = -alpha * (z-p)^gamma * log(p) -(1-alpha) * p^gamma * log(1-p)\n                     ,which alpha = 0.25, gamma = 2, p = sigmoid(x), z = target_tensor.\n        Args:\n         prediction_tensor: A float tensor of shape [batch_size, num_anchors,\n            num_classes] representing the predicted logits for each class\n         target_tensor: A float tensor of shape [batch_size, num_anchors,\n            num_classes] representing one-hot encoded classification targets\n         weights: A float tensor of shape [batch_size, num_anchors]\n         alpha: A scalar tensor for focal loss alpha hyper-parameter\n         gamma: A scalar tensor for focal loss gamma hyper-parameter\n        Returns:\n            loss: A (scalar) tensor representing the value of the loss function\n        '
    sigmoid_p = torch.sigmoid(prediction_tensor)
    zeros = torch.zeros_like(sigmoid_p, dtype=sigmoid_p.dtype)
    pos_p_sub = torch.where((target_tensor > zeros), (target_tensor - sigmoid_p), zeros)
    neg_p_sub = torch.where((target_tensor > zeros), zeros, sigmoid_p)
    per_entry_cross_ent = ((((- alpha) * (pos_p_sub ** gamma)) * torch.log(clip_by_tensor(sigmoid_p, 1e-08, 1.0))) - (((1 - alpha) * (neg_p_sub ** gamma)) * torch.log(clip_by_tensor((1.0 - sigmoid_p), 1e-08, 1.0))))
    return per_entry_cross_ent.mean()