class_docstr: Dynamic Instance Interactive Head for `Sparse R-CNN: End-to-End Object
  Detection with Learnable Proposals <https://arxiv.org/abs/2011.12450>`_
  
  Args:
      num_classes (int): Number of class in dataset.
          Defaults to 80.
      num_ffn_fcs (int): The number of fully-connected
          layers in FFNs. Defaults to 2.
      num_heads (int): The hidden dimension of FFNs.
          Defaults to 8.
      num_cls_fcs (int): The number of fully-connected
          layers in classification subnet. Defaults to 1.
      num_reg_fcs (int): The number of fully-connected
          layers in regression subnet. Defaults to 3.
      feedforward_channels (int): The hidden dimension
          of FFNs. Defaults to 2048
      in_channels (int): Hidden_channels of MultiheadAttention.
          Defaults to 256.
      dropout (float): Probability of drop the channel.
          Defaults to 0.0
      ffn_act_cfg (:obj:`ConfigDict` or dict): The activation config
          for FFNs.
      dynamic_conv_cfg (:obj:`ConfigDict` or dict): The convolution
          config for DynamicConv.
      loss_iou (:obj:`ConfigDict` or dict): The config for iou or
          giou loss.
      init_cfg (:obj:`ConfigDict` or dict or list[:obj:`ConfigDict` or \
          dict]): 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).
      """
      pos_inds_list = [res.pos_inds for res in sampling_results]
      neg_inds_list = [res.neg_inds for res in sampling_results]
      pos_priors_list = [res.pos_priors for res in sampling_results]
      neg_priors_list = [res.neg_priors for res in sampling_results]
      pos_gt_bboxes_list = [
          res.pos_gt_bboxes for res in sampling_results
      ]
      pos_gt_labels_list = [
          res.pos_gt_labels for res in sampling_results
      ]
      labels, label_weights, bbox_targets, bbox_weights = multi_apply(
          self._get_targets_single,
          pos_inds_list,
          neg_inds_list,
          pos_priors_list,
          neg_priors_list,
          pos_gt_bboxes_list,
          pos_gt_labels_list,
          cfg=rcnn_train_cfg,
      )
      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
  import torch
  import torch.nn
  from mmcv.cnn import build_activation_layer, build_norm_layer
  from mmcv.cnn.bricks.transformer import FFN, MultiheadAttention
  from mmengine.config import ConfigDict
  from mmengine.model import bias_init_with_prob
  from torch import Tensor
  from mmdet.models.losses import accuracy
  from mmdet.models.task_modules import SamplingResult
  from mmdet.models.utils import multi_apply
  from mmdet.registry import MODELS
  from mmdet.utils import ConfigType, OptConfigType, reduce_mean
  from .bbox_head import BBoxHead
label_desc: Use image node_id 6 for calling the DIIHead 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