class_docstr: CondInst box head used in https://arxiv.org/abs/1904.02689.
  
  Note that CondInst Bbox Head is a extension of FCOS head.
  Two differences are described as follows:
  
  1. CondInst box head predicts a set of params for each instance.
  2. CondInst box head return the pos_gt_inds and pos_inds.
  
  Args:
      num_params (int): Number of params for instance segmentation.
class_docstr_tok: ["CondInst","box","head","used","in","https",":","\/\/arxiv.org\/abs\/1904.02689",".","Note","that","CondInst","Bbox","Head","is","a","extension","of","FCOS","head",".","Two","differences","are","described","as","follows",":","1",".","CondInst","box","head","predicts","a","set","of","params","for","each","instance",".","2",".","CondInst","box","head","return","the","pos_gt_inds","and","pos_inds",".","Args",":","num_params","(","int",")",":","Number","of","params","for","instance","segmentation","."]
docstr: Calculate the loss based on the features extracted by the detection
  head.
  
  Args:
      cls_scores (list[Tensor]): Box scores for each scale level,
          each is a 4D-tensor, the channel number is
          num_points * num_classes.
      bbox_preds (list[Tensor]): Box energies / deltas for each scale
          level, each is a 4D-tensor, the channel number is
          num_points * 4.
      centernesses (list[Tensor]): centerness for each scale level, each
          is a 4D-tensor, the channel number is num_points * 1.
      param_preds (List[Tensor]): param_pred for each scale level, each
          is a 4D-tensor, the channel number is num_params.
      batch_gt_instances (list[:obj:`InstanceData`]): Batch of
          gt_instance.  It usually includes ``bboxes`` and ``labels``
          attributes.
      batch_img_metas (list[dict]): Meta information of each image, e.g.,
          image size, scaling factor, etc.
      batch_gt_instances_ignore (list[:obj:`InstanceData`], Optional):
          Batch of gt_instances_ignore. It includes ``bboxes`` attribute
          data that is ignored during training and testing.
          Defaults to None.
  
  Returns:
      dict[str, Tensor]: A dictionary of loss components.
docstr_tok: ["Calculate","the","loss","based","on","the","features","extracted","by","the","detection","head",".","Args",":","cls_scores","(","list","[","Tensor","]",")",":","Box","scores","for","each","scale","level",",","each","is","a","4D-tensor",",","the","channel","number","is","num_points","*","num_classes",".","bbox_preds","(","list","[","Tensor","]",")",":","Box","energies","\/","deltas","for","each","scale","level",",","each","is","a","4D-tensor",",","the","channel","number","is","num_points","*","4.","centernesses","(","list","[","Tensor","]",")",":","centerness","for","each","scale","level",",","each","is","a","4D-tensor",",","the","channel","number","is","num_points","*","1.","param_preds","(","List","[","Tensor","]",")",":","param_pred","for","each","scale","level",",","each","is","a","4D-tensor",",","the","channel","number","is","num_params",".","batch_gt_instances","(","list","[",":","obj",":","`","InstanceData","`","]",")",":","Batch","of","gt_instance",".","It","usually","includes","``","bboxes","``","and","``","labels","``","attributes",".","batch_img_metas","(","list","[","dict","]",")",":","Meta","information","of","each","image",",","e.g.",",","image","size",",","scaling","factor",",","etc",".","batch_gt_instances_ignore","(","list","[",":","obj",":","`","InstanceData","`","]",",","Optional",")",":","Batch","of","gt_instances_ignore",".","It","includes","``","bboxes","``","attribute","data","that","is","ignored","during","training","and","testing",".","Defaults","to","None",".","Returns",":","dict","[","str",",","Tensor","]",":","A","dictionary","of","loss","components","."]
code: def loss_by_feat(
      self,
      cls_scores: List[Tensor],
      bbox_preds: List[Tensor],
      centernesses: List[Tensor],
      param_preds: List[Tensor],
      batch_gt_instances: InstanceList,
      batch_img_metas: List[dict],
      batch_gt_instances_ignore: OptInstanceList = None,
  ) -> Dict[str, Tensor]:
      """Calculate the loss based on the features extracted by the detection
      head.
  
      Args:
          cls_scores (list[Tensor]): Box scores for each scale level,
              each is a 4D-tensor, the channel number is
              num_points * num_classes.
          bbox_preds (list[Tensor]): Box energies / deltas for each scale
              level, each is a 4D-tensor, the channel number is
              num_points * 4.
          centernesses (list[Tensor]): centerness for each scale level, each
              is a 4D-tensor, the channel number is num_points * 1.
          param_preds (List[Tensor]): param_pred for each scale level, each
              is a 4D-tensor, the channel number is num_params.
          batch_gt_instances (list[:obj:`InstanceData`]): Batch of
              gt_instance.  It usually includes ``bboxes`` and ``labels``
              attributes.
          batch_img_metas (list[dict]): Meta information of each image, e.g.,
              image size, scaling factor, etc.
          batch_gt_instances_ignore (list[:obj:`InstanceData`], Optional):
              Batch of gt_instances_ignore. It includes ``bboxes`` attribute
              data that is ignored during training and testing.
              Defaults to None.
  
      Returns:
          dict[str, Tensor]: A dictionary of loss components.
      """
      assert len(cls_scores) == len(bbox_preds) == len(centernesses)
      featmap_sizes = [featmap.size()[-2:] for featmap in cls_scores]
      # Need stride for rel coord compute
      all_level_points_strides = self.prior_generator.grid_priors(
          featmap_sizes,
          dtype=bbox_preds[0].dtype,
          device=bbox_preds[0].device,
          with_stride=True,
      )
      all_level_points = [i[:, :2] for i in all_level_points_strides]
      all_level_strides = [i[:, 2] for i in all_level_points_strides]
      (
          labels,
          bbox_targets,
          pos_inds_list,
          pos_gt_inds_list,
      ) = self.get_targets(all_level_points, batch_gt_instances)
  
      num_imgs = cls_scores[0].size(0)
      # flatten cls_scores, bbox_preds and centerness
      flatten_cls_scores = [
          cls_score.permute(0, 2, 3, 1).reshape(
              -1, self.cls_out_channels
          )
          for cls_score in cls_scores
      ]
      flatten_bbox_preds = [
          bbox_pred.permute(0, 2, 3, 1).reshape(-1, 4)
          for bbox_pred in bbox_preds
      ]
      flatten_centerness = [
          centerness.permute(0, 2, 3, 1).reshape(-1)
          for centerness in centernesses
      ]
      flatten_cls_scores = torch.cat(flatten_cls_scores)
      flatten_bbox_preds = torch.cat(flatten_bbox_preds)
      flatten_centerness = torch.cat(flatten_centerness)
      flatten_labels = torch.cat(labels)
      flatten_bbox_targets = torch.cat(bbox_targets)
      # repeat points to align with bbox_preds
      flatten_points = torch.cat(
          [points.repeat(num_imgs, 1) for points in all_level_points]
      )
  
      # FG cat_id: [0, num_classes -1], BG cat_id: num_classes
      bg_class_ind = self.num_classes
      pos_inds = (
          ((flatten_labels >= 0) & (flatten_labels < bg_class_ind))
          .nonzero()
          .reshape(-1)
      )
      num_pos = torch.tensor(
          len(pos_inds), dtype=torch.float, device=bbox_preds[0].device
      )
      num_pos = max(reduce_mean(num_pos), 1.0)
      loss_cls = self.loss_cls(
          flatten_cls_scores, flatten_labels, avg_factor=num_pos
      )
  
      pos_bbox_preds = flatten_bbox_preds[pos_inds]
      pos_centerness = flatten_centerness[pos_inds]
      pos_bbox_targets = flatten_bbox_targets[pos_inds]
      pos_centerness_targets = self.centerness_target(pos_bbox_targets)
      # centerness weighted iou loss
      centerness_denorm = max(
          reduce_mean(pos_centerness_targets.sum().detach()), 1e-6
      )
  
      if len(pos_inds) > 0:
          pos_points = flatten_points[pos_inds]
          pos_decoded_bbox_preds = self.bbox_coder.decode(
              pos_points, pos_bbox_preds
          )
          pos_decoded_target_preds = self.bbox_coder.decode(
              pos_points, pos_bbox_targets
          )
          loss_bbox = self.loss_bbox(
              pos_decoded_bbox_preds,
              pos_decoded_target_preds,
              weight=pos_centerness_targets,
              avg_factor=centerness_denorm,
          )
          loss_centerness = self.loss_centerness(
              pos_centerness, pos_centerness_targets, avg_factor=num_pos
          )
      else:
          loss_bbox = pos_bbox_preds.sum()
          loss_centerness = pos_centerness.sum()
  
      self._raw_positive_infos.update(cls_scores=cls_scores)
      self._raw_positive_infos.update(centernesses=centernesses)
      self._raw_positive_infos.update(param_preds=param_preds)
      self._raw_positive_infos.update(all_level_points=all_level_points)
      self._raw_positive_infos.update(
          all_level_strides=all_level_strides
      )
      self._raw_positive_infos.update(pos_gt_inds_list=pos_gt_inds_list)
      self._raw_positive_infos.update(pos_inds_list=pos_inds_list)
  
      return dict(
          loss_cls=loss_cls,
          loss_bbox=loss_bbox,
          loss_centerness=loss_centerness,
      )
  
imports: import copy
  from typing import Dict, List, Optional, Tuple
  import torch
  import torch.nn
  import torch.nn.functional
  from mmcv.cnn import ConvModule, Scale
  from mmengine.config import ConfigDict
  from mmengine.model import BaseModule, kaiming_init
  from mmengine.structures import InstanceData
  from torch import Tensor
  from mmdet.registry import MODELS
  from mmdet.structures.bbox import cat_boxes
  from mmdet.utils import ConfigType, InstanceList, MultiConfig, OptConfigType, OptInstanceList, reduce_mean
  from ..task_modules.prior_generators import MlvlPointGenerator
  from ..utils import aligned_bilinear, filter_scores_and_topk, multi_apply, relative_coordinate_maps, select_single_mlvl
  from ..utils.misc import empty_instances
  from .base_mask_head import BaseMaskHead
  from .fcos_head import FCOSHead
label_desc: Use image node_id 4 for calling the CondInstBboxHead obj's underlying member method code with example usage: obj.loss_by_feat(cls_scores, bbox_preds, centernesses, param_preds, batch_gt_instances, batch_img_metas, batch_gt_instances_ignore) and returns: dict