class_docstr: YOLACT segmentation head used in https://arxiv.org/abs/1904.02689.
  
  Apply a semantic segmentation loss on feature space using layers that are
  only evaluated during training to increase performance with no speed
  penalty.
  
  Args:
      in_channels (int): Number of channels in the input feature map.
      num_classes (int): Number of categories excluding the background
          category.
      loss_segm (dict): Config of semantic segmentation loss.
docstr: Compute loss of the head.
  
  Args:
      segm_pred (list[Tensor]): Predicted semantic segmentation map
          with shape (N, num_classes, H, W).
      gt_masks (list[Tensor]): Ground truth masks for each image with
          the same shape of the input image.
      gt_labels (list[Tensor]): Class indices corresponding to each box.
  
  Returns:
      dict[str, Tensor]: A dictionary of loss components.
docstr_tok: ["Compute","loss","of","the","head",".","Args",":","segm_pred","(","list","[","Tensor","]",")",":","Predicted","semantic","segmentation","map","with","shape","(","N",",","num_classes",",","H",",","W",")",".","gt_masks","(","list","[","Tensor","]",")",":","Ground","truth","masks","for","each","image","with","the","same","shape","of","the","input","image",".","gt_labels","(","list","[","Tensor","]",")",":","Class","indices","corresponding","to","each","box",".","Returns",":","dict","[","str",",","Tensor","]",":","A","dictionary","of","loss","components","."]
code: def loss(self, segm_pred, gt_masks, gt_labels):
      """Compute loss of the head.
  
      Args:
          segm_pred (list[Tensor]): Predicted semantic segmentation map
              with shape (N, num_classes, H, W).
          gt_masks (list[Tensor]): Ground truth masks for each image with
              the same shape of the input image.
          gt_labels (list[Tensor]): Class indices corresponding to each box.
  
      Returns:
          dict[str, Tensor]: A dictionary of loss components.
      """
      loss_segm = []
      num_imgs, num_classes, mask_h, mask_w = segm_pred.size()
      for idx in range(num_imgs):
          cur_segm_pred = segm_pred[idx]
          cur_gt_masks = gt_masks[idx].float()
          cur_gt_labels = gt_labels[idx]
          segm_targets = self.get_targets(
              cur_segm_pred, cur_gt_masks, cur_gt_labels
          )
          if segm_targets is None:
              loss = self.loss_segm(
                  cur_segm_pred,
                  torch.zeros_like(cur_segm_pred),
                  torch.zeros_like(cur_segm_pred),
              )
          else:
              loss = self.loss_segm(
                  cur_segm_pred,
                  segm_targets,
                  avg_factor=num_imgs * mask_h * mask_w,
              )
          loss_segm.append(loss)
      return dict(loss_segm=loss_segm)
  
imports: import numpy
  import torch
  import torch.nn
  import torch.nn.functional
  from mmcv.cnn import ConvModule, xavier_init
  from mmcv.runner import force_fp32
  from mmdet.core import build_sampler, fast_nms, images_to_levels, multi_apply
  from ..builder import HEADS, build_loss
  from .anchor_head import AnchorHead
label_desc: Use image node_id 5 for calling the YOLACTSegmHead obj's underlying member method code with example usage: obj.loss(segm_pred, gt_masks, gt_labels) and returns: dict