code: def heatmap_focal_loss_with_pos_inds(
      pred: Tensor,
      targets: Tensor,
      pos_inds: Tensor,
      alpha: float = 2.0,
      beta: float = 4.0,
      gamma: float = 4.0,
      sigmoid_clamp: float = 1e-4,
      ignore_high_fp: float = -1.0,
      pos_weight: float = 1.0,
      neg_weight: float = 1.0,
      avg_factor: Optional[Union[int, float]] = None,
  ) -> Tensor:
      pred = torch.clamp(
          pred.sigmoid_(), min=sigmoid_clamp, max=1 - sigmoid_clamp
      )
  
      neg_weights = torch.pow(1 - targets, beta)
  
      pos_pred = pred[pos_inds]
      pos_loss = torch.log(pos_pred) * torch.pow(1 - pos_pred, gamma)
      neg_loss = (
          torch.log(1 - pred) * torch.pow(pred, gamma) * neg_weights
      )
      if ignore_high_fp > 0:
          not_high_fp = (pred < ignore_high_fp).float()
          neg_loss = not_high_fp * neg_loss
  
      pos_loss = -pos_loss.sum()
      neg_loss = -neg_loss.sum()
      if alpha >= 0:
          pos_loss = alpha * pos_loss
          neg_loss = (1 - alpha) * neg_loss
  
      pos_loss = pos_weight * pos_loss / avg_factor
      neg_loss = neg_weight * neg_loss / avg_factor
  
      return pos_loss, neg_loss
  
file_path: mmdetection/projects/Detic_new/detic/heatmap_focal_loss.py
imports: from typing import Optional, Union
  import torch
  import torch.nn
  from torch import Tensor
  from mmdet.registry import MODELS
label_desc: Use image node_id 1 for calling a global function with example usage: heatmap_focal_loss_with_pos_inds(pred, targets, pos_inds, alpha, beta, gamma, sigmoid_clamp, ignore_high_fp, pos_weight, neg_weight, avg_factor) and returns: pos_loss,  neg_loss