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 proposals in the single image
  according to the sampling results.
  
  Almost the same as the implementation in `bbox_head`,
  we add pos_inds and neg_inds to select positive and
  negative samples instead of selecting the first num_pos
  as positive samples.
  
  Args:
      pos_inds (Tensor): The length is equal to the
          positive sample numbers contain all index
          of the positive sample in the origin proposal set.
      neg_inds (Tensor): The length is equal to the
          negative sample numbers contain all index
          of the negative sample in the origin proposal set.
      pos_priors (Tensor): Contains all the positive boxes,
          has shape (num_pos, 4), the last dimension 4
          represents [tl_x, tl_y, br_x, br_y].
      neg_priors (Tensor): Contains all the negative boxes,
          has shape (num_neg, 4), the last dimension 4
          represents [tl_x, tl_y, br_x, br_y].
      pos_gt_bboxes (Tensor): Contains gt_boxes for
          all positive samples, has shape (num_pos, 4),
          the last dimension 4
          represents [tl_x, tl_y, br_x, br_y].
      pos_gt_labels (Tensor): Contains gt_labels for
          all positive samples, has shape (num_pos, ).
      cfg (obj:`ConfigDict`): `train_cfg` of R-CNN.
  
  Returns:
      Tuple[Tensor]: Ground truth for proposals in a single image.
      Containing the following Tensors:
  
      - labels(Tensor): Gt_labels for all proposals, has
        shape (num_proposals,).
      - label_weights(Tensor): Labels_weights for all proposals, has
        shape (num_proposals,).
      - bbox_targets(Tensor):Regression target for all proposals, has
        shape (num_proposals, 4), the last dimension 4
        represents [tl_x, tl_y, br_x, br_y].
      - bbox_weights(Tensor):Regression weights for all proposals,
        has shape (num_proposals, 4).
docstr_tok: ["Calculate","the","ground","truth","for","proposals","in","the","single","image","according","to","the","sampling","results",".","Almost","the","same","as","the","implementation","in","`","bbox_head","`",",","we","add","pos_inds","and","neg_inds","to","select","positive","and","negative","samples","instead","of","selecting","the","first","num_pos","as","positive","samples",".","Args",":","pos_inds","(","Tensor",")",":","The","length","is","equal","to","the","positive","sample","numbers","contain","all","index","of","the","positive","sample","in","the","origin","proposal","set",".","neg_inds","(","Tensor",")",":","The","length","is","equal","to","the","negative","sample","numbers","contain","all","index","of","the","negative","sample","in","the","origin","proposal","set",".","pos_priors","(","Tensor",")",":","Contains","all","the","positive","boxes",",","has","shape","(","num_pos",",","4",")",",","the","last","dimension","4","represents","[","tl_x",",","tl_y",",","br_x",",","br_y","]",".","neg_priors","(","Tensor",")",":","Contains","all","the","negative","boxes",",","has","shape","(","num_neg",",","4",")",",","the","last","dimension","4","represents","[","tl_x",",","tl_y",",","br_x",",","br_y","]",".","pos_gt_bboxes","(","Tensor",")",":","Contains","gt_boxes","for","all","positive","samples",",","has","shape","(","num_pos",",","4",")",",","the","last","dimension","4","represents","[","tl_x",",","tl_y",",","br_x",",","br_y","]",".","pos_gt_labels","(","Tensor",")",":","Contains","gt_labels","for","all","positive","samples",",","has","shape","(","num_pos",",",")",".","cfg","(","obj",":","`","ConfigDict","`",")",":","`","train_cfg","`","of","R-CNN",".","Returns",":","Tuple","[","Tensor","]",":","Ground","truth","for","proposals","in","a","single","image",".","Containing","the","following","Tensors",":","-","labels","(","Tensor",")",":","Gt_labels","for","all","proposals",",","has","shape","(","num_proposals",",",")",".","-","label_weights","(","Tensor",")",":","Labels_weights","for","all","proposals",",","has","shape","(","num_proposals",",",")",".","-","bbox_targets","(","Tensor",")",":","Regression","target","for","all","proposals",",","has","shape","(","num_proposals",",","4",")",",","the","last","dimension","4","represents","[","tl_x",",","tl_y",",","br_x",",","br_y","]",".","-","bbox_weights","(","Tensor",")",":","Regression","weights","for","all","proposals",",","has","shape","(","num_proposals",",","4",")","."]
code: def _get_targets_single(
      self,
      pos_inds: Tensor,
      neg_inds: Tensor,
      pos_priors: Tensor,
      neg_priors: Tensor,
      pos_gt_bboxes: Tensor,
      pos_gt_labels: Tensor,
      cfg: ConfigDict,
  ) -> tuple:
      """Calculate the ground truth for proposals in the single image
      according to the sampling results.
  
      Almost the same as the implementation in `bbox_head`,
      we add pos_inds and neg_inds to select positive and
      negative samples instead of selecting the first num_pos
      as positive samples.
  
      Args:
          pos_inds (Tensor): The length is equal to the
              positive sample numbers contain all index
              of the positive sample in the origin proposal set.
          neg_inds (Tensor): The length is equal to the
              negative sample numbers contain all index
              of the negative sample in the origin proposal set.
          pos_priors (Tensor): Contains all the positive boxes,
              has shape (num_pos, 4), the last dimension 4
              represents [tl_x, tl_y, br_x, br_y].
          neg_priors (Tensor): Contains all the negative boxes,
              has shape (num_neg, 4), the last dimension 4
              represents [tl_x, tl_y, br_x, br_y].
          pos_gt_bboxes (Tensor): Contains gt_boxes for
              all positive samples, has shape (num_pos, 4),
              the last dimension 4
              represents [tl_x, tl_y, br_x, br_y].
          pos_gt_labels (Tensor): Contains gt_labels for
              all positive samples, has shape (num_pos, ).
          cfg (obj:`ConfigDict`): `train_cfg` of R-CNN.
  
      Returns:
          Tuple[Tensor]: Ground truth for proposals in a single image.
          Containing the following Tensors:
  
          - labels(Tensor): Gt_labels for all proposals, has
            shape (num_proposals,).
          - label_weights(Tensor): Labels_weights for all proposals, has
            shape (num_proposals,).
          - bbox_targets(Tensor):Regression target for all proposals, has
            shape (num_proposals, 4), the last dimension 4
            represents [tl_x, tl_y, br_x, br_y].
          - bbox_weights(Tensor):Regression weights for all proposals,
            has shape (num_proposals, 4).
      """
      num_pos = pos_priors.size(0)
      num_neg = neg_priors.size(0)
      num_samples = num_pos + num_neg
  
      # original implementation uses new_zeros since BG are set to be 0
      # now use empty & fill because BG cat_id = num_classes,
      # FG cat_id = [0, num_classes-1]
      labels = pos_priors.new_full(
          (num_samples,), self.num_classes, dtype=torch.long
      )
      label_weights = pos_priors.new_zeros(num_samples)
      bbox_targets = pos_priors.new_zeros(num_samples, 4)
      bbox_weights = pos_priors.new_zeros(num_samples, 4)
      if num_pos > 0:
          labels[pos_inds] = pos_gt_labels
          pos_weight = 1.0 if cfg.pos_weight <= 0 else cfg.pos_weight
          label_weights[pos_inds] = pos_weight
          if not self.reg_decoded_bbox:
              pos_bbox_targets = self.bbox_coder.encode(
                  pos_priors, pos_gt_bboxes
              )
          else:
              pos_bbox_targets = pos_gt_bboxes
          bbox_targets[pos_inds, :] = pos_bbox_targets
          bbox_weights[pos_inds, :] = 1
      if num_neg > 0:
          label_weights[neg_inds] = 1.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 5 for calling the DIIHead obj's underlying member method code with example usage: obj._get_targets_single(pos_inds, neg_inds, pos_priors, neg_priors, pos_gt_bboxes, pos_gt_labels, cfg) and returns: labels,  label_weights,  bbox_targets,  bbox_weights