class_docstr: Bbox head used in CrowdDet.
  
  .. code-block:: none
  
                                    /-> cls convs_1 -> cls fcs_1 -> cls_1
                                 |--
                                 |  \-> reg convs_1 -> reg fcs_1 -> reg_1
                                 |
                                 |  /-> cls convs_2 -> cls fcs_2 -> cls_2
      shared convs -> shared fcs |--
                                 |  \-> reg convs_2 -> reg fcs_2 -> reg_2
                                 |
                                 |                     ...
                                 |
                                 |  /-> cls convs_k -> cls fcs_k -> cls_k
                                 |--
                                    \-> reg convs_k -> reg fcs_k -> reg_k
  
  
  Args:
      num_instance (int): The number of branches after shared fcs.
          Defaults to 2.
      with_refine (bool): Whether to use refine module. Defaults to False.
      num_shared_convs (int): The number of shared convs. Defaults to 0.
      num_shared_fcs (int): The number of shared fcs. Defaults to 2.
      num_cls_convs (int): The number of cls convs. Defaults to 0.
      num_cls_fcs (int): The number of cls fcs. Defaults to 0.
      num_reg_convs (int): The number of reg convs. Defaults to 0.
      num_reg_fcs (int): The number of reg fcs. Defaults to 0.
      conv_out_channels (int): The number of conv out channels.
          Defaults to 256.
      fc_out_channels (int): The number of fc out channels. Defaults to 1024.
      init_cfg (dict or list[dict], optional): Initialization config dict.
          Defaults to None.
docstr: Calculate the ground truth for all samples in a batch according to
  the sampling_results.
  
  Almost the same as the implementation in bbox_head, we passed
  additional parameters pos_inds_list and neg_inds_list to
  `_get_targets_single` function.
  
  Args:
      sampling_results (List[obj:SamplingResult]): Assign results of
          all images in a batch after sampling.
      rcnn_train_cfg (obj:ConfigDict): `train_cfg` of RCNN.
      concat (bool): Whether to concatenate the results of all
          the images in a single batch.
  
  Returns:
      Tuple[Tensor]: Ground truth for proposals in a single image.
      Containing the following list of Tensors:
  
      - labels (list[Tensor],Tensor): Gt_labels for all proposals in a
        batch, each tensor in list has shape (num_proposals,) when
        `concat=False`, otherwise just a single tensor has shape
        (num_all_proposals,).
      - label_weights (list[Tensor]): Labels_weights for
        all proposals in a batch, each tensor in list has shape
        (num_proposals,) when `concat=False`, otherwise just a single
        tensor has shape (num_all_proposals,).
      - bbox_targets (list[Tensor],Tensor): Regression target for all
        proposals in a batch, each tensor in list has shape
        (num_proposals, 4) when `concat=False`, otherwise just a single
        tensor has shape (num_all_proposals, 4), the last dimension 4
        represents [tl_x, tl_y, br_x, br_y].
      - bbox_weights (list[tensor],Tensor): Regression weights for
        all proposals in a batch, each tensor in list has shape
        (num_proposals, 4) when `concat=False`, otherwise just a
        single tensor has shape (num_all_proposals, 4).
docstr_tok: ["Calculate","the","ground","truth","for","all","samples","in","a","batch","according","to","the","sampling_results",".","Almost","the","same","as","the","implementation","in","bbox_head",",","we","passed","additional","parameters","pos_inds_list","and","neg_inds_list","to","`","_get_targets_single","`","function",".","Args",":","sampling_results","(","List","[","obj",":","SamplingResult","]",")",":","Assign","results","of","all","images","in","a","batch","after","sampling",".","rcnn_train_cfg","(","obj",":","ConfigDict",")",":","`","train_cfg","`","of","RCNN",".","concat","(","bool",")",":","Whether","to","concatenate","the","results","of","all","the","images","in","a","single","batch",".","Returns",":","Tuple","[","Tensor","]",":","Ground","truth","for","proposals","in","a","single","image",".","Containing","the","following","list","of","Tensors",":","-","labels","(","list","[","Tensor","]",",","Tensor",")",":","Gt_labels","for","all","proposals","in","a","batch",",","each","tensor","in","list","has","shape","(","num_proposals",",",")","when","`","concat=False","`",",","otherwise","just","a","single","tensor","has","shape","(","num_all_proposals",",",")",".","-","label_weights","(","list","[","Tensor","]",")",":","Labels_weights","for","all","proposals","in","a","batch",",","each","tensor","in","list","has","shape","(","num_proposals",",",")","when","`","concat=False","`",",","otherwise","just","a","single","tensor","has","shape","(","num_all_proposals",",",")",".","-","bbox_targets","(","list","[","Tensor","]",",","Tensor",")",":","Regression","target","for","all","proposals","in","a","batch",",","each","tensor","in","list","has","shape","(","num_proposals",",","4",")","when","`","concat=False","`",",","otherwise","just","a","single","tensor","has","shape","(","num_all_proposals",",","4",")",",","the","last","dimension","4","represents","[","tl_x",",","tl_y",",","br_x",",","br_y","]",".","-","bbox_weights","(","list","[","tensor","]",",","Tensor",")",":","Regression","weights","for","all","proposals","in","a","batch",",","each","tensor","in","list","has","shape","(","num_proposals",",","4",")","when","`","concat=False","`",",","otherwise","just","a","single","tensor","has","shape","(","num_all_proposals",",","4",")","."]
code: def get_targets(
      self,
      sampling_results: List[SamplingResult],
      rcnn_train_cfg: ConfigDict,
      concat: bool = True,
  ) -> tuple:
      """Calculate the ground truth for all samples in a batch according to
      the sampling_results.
  
      Almost the same as the implementation in bbox_head, we passed
      additional parameters pos_inds_list and neg_inds_list to
      `_get_targets_single` function.
  
      Args:
          sampling_results (List[obj:SamplingResult]): Assign results of
              all images in a batch after sampling.
          rcnn_train_cfg (obj:ConfigDict): `train_cfg` of RCNN.
          concat (bool): Whether to concatenate the results of all
              the images in a single batch.
  
      Returns:
          Tuple[Tensor]: Ground truth for proposals in a single image.
          Containing the following list of Tensors:
  
          - labels (list[Tensor],Tensor): Gt_labels for all proposals in a
            batch, each tensor in list has shape (num_proposals,) when
            `concat=False`, otherwise just a single tensor has shape
            (num_all_proposals,).
          - label_weights (list[Tensor]): Labels_weights for
            all proposals in a batch, each tensor in list has shape
            (num_proposals,) when `concat=False`, otherwise just a single
            tensor has shape (num_all_proposals,).
          - bbox_targets (list[Tensor],Tensor): Regression target for all
            proposals in a batch, each tensor in list has shape
            (num_proposals, 4) when `concat=False`, otherwise just a single
            tensor has shape (num_all_proposals, 4), the last dimension 4
            represents [tl_x, tl_y, br_x, br_y].
          - bbox_weights (list[tensor],Tensor): Regression weights for
            all proposals in a batch, each tensor in list has shape
            (num_proposals, 4) when `concat=False`, otherwise just a
            single tensor has shape (num_all_proposals, 4).
      """
      labels = []
      bbox_targets = []
      bbox_weights = []
      label_weights = []
      for i in range(len(sampling_results)):
          sample_bboxes = torch.cat(
              [
                  sampling_results[i].pos_gt_bboxes,
                  sampling_results[i].neg_gt_bboxes,
              ]
          )
          sample_priors = sampling_results[i].priors
          sample_priors = sample_priors.repeat(
              1, self.num_instance
          ).reshape(-1, 4)
          sample_bboxes = sample_bboxes.reshape(-1, 4)
  
          if not self.reg_decoded_bbox:
              _bbox_targets = self.bbox_coder.encode(
                  sample_priors, sample_bboxes
              )
          else:
              _bbox_targets = sample_priors
          _bbox_targets = _bbox_targets.reshape(
              -1, self.num_instance * 4
          )
          _bbox_weights = torch.ones(_bbox_targets.shape)
          _labels = torch.cat(
              [
                  sampling_results[i].pos_gt_labels,
                  sampling_results[i].neg_gt_labels,
              ]
          )
          _labels_weights = torch.ones(_labels.shape)
  
          bbox_targets.append(_bbox_targets)
          bbox_weights.append(_bbox_weights)
          labels.append(_labels)
          label_weights.append(_labels_weights)
  
      if concat:
          labels = torch.cat(labels, 0)
          label_weights = torch.cat(label_weights, 0)
          bbox_targets = torch.cat(bbox_targets, 0)
          bbox_weights = torch.cat(bbox_weights, 0)
      return labels, label_weights, bbox_targets, bbox_weights
  
imports: from typing import List, Optional, Tuple, Union
  import numpy
  import torch
  import torch.nn.functional
  from mmcv.cnn import ConvModule
  from mmengine.config import ConfigDict
  from mmengine.structures import InstanceData
  from torch import Tensor, nn
  from mmdet.models.roi_heads.bbox_heads.bbox_head import BBoxHead
  from mmdet.models.task_modules.samplers import SamplingResult
  from mmdet.models.utils import empty_instances
  from mmdet.registry import MODELS
  from mmdet.structures.bbox import bbox_overlaps
label_desc: Use image node_id 4 for calling the MultiInstanceBBoxHead obj's underlying member method code with example usage: obj.get_targets(sampling_results, rcnn_train_cfg, concat) and returns: labels,  label_weights,  bbox_targets,  bbox_weights