class_docstr: The roi embed head.
  
  This module is used in multi-object tracking methods, such as MaskTrack
  R-CNN.
  
  Args:
      num_convs (int): The number of convoluational layers to embed roi
          features. Defaults to 0.
      num_fcs (int): The number of fully connection layers to embed roi
          features. Defaults to 0.
      roi_feat_size (int|tuple(int)): The spatial size of roi features.
          Defaults to 7.
      in_channels (int): The input channel of roi features. Defaults to 256.
      conv_out_channels (int): The output channel of roi features after
          forwarding convoluational layers. Defaults to 256.
      with_avg_pool (bool): Whether use average pooling before passing roi
          features into fully connection layers. Defaults to False.
      fc_out_channels (int): The output channel of roi features after
          forwarding fully connection layers. Defaults to 1024.
      conv_cfg (dict): Config dict for convolution layer. Defaults to None,
          which means using conv2d.
      norm_cfg (dict): Config dict for normalization layer. Defaults to None.
      loss_match (dict): The loss function. Defaults to
          dict(type='CrossEntropyLoss', use_sigmoid=False, loss_weight=1.0)
      init_cfg (dict): Configuration of initialization. Defaults to None.
class_docstr_tok: ["The","roi","embed","head",".","This","module","is","used","in","multi-object","tracking","methods",",","such","as","MaskTrack","R-CNN",".","Args",":","num_convs","(","int",")",":","The","number","of","convoluational","layers","to","embed","roi","features",".","Defaults","to","0.","num_fcs","(","int",")",":","The","number","of","fully","connection","layers","to","embed","roi","features",".","Defaults","to","0.","roi_feat_size","(","int|tuple","(","int",")",")",":","The","spatial","size","of","roi","features",".","Defaults","to","7.","in_channels","(","int",")",":","The","input","channel","of","roi","features",".","Defaults","to","256.","conv_out_channels","(","int",")",":","The","output","channel","of","roi","features","after","forwarding","convoluational","layers",".","Defaults","to","256.","with_avg_pool","(","bool",")",":","Whether","use","average","pooling","before","passing","roi","features","into","fully","connection","layers",".","Defaults","to","False",".","fc_out_channels","(","int",")",":","The","output","channel","of","roi","features","after","forwarding","fully","connection","layers",".","Defaults","to","1024.","conv_cfg","(","dict",")",":","Config","dict","for","convolution","layer",".","Defaults","to","None",",","which","means","using","conv2d",".","norm_cfg","(","dict",")",":","Config","dict","for","normalization","layer",".","Defaults","to","None",".","loss_match","(","dict",")",":","The","loss","function",".","Defaults","to","dict","(","type='CrossEntropyLoss","'",",","use_sigmoid=False",",","loss_weight=1.0",")","init_cfg","(","dict",")",":","Configuration","of","initialization",".","Defaults","to","None","."]
docstr: Calculate the ground truth for all samples in a batch according to
  the sampling_results.
  
  Args:
      sampling_results (List[obj:SamplingResult]): Assign results of
          all images in a batch after sampling.
      gt_instance_ids (list[Tensor]): The instance ids of gt_bboxes of
          all images in a batch, each tensor has shape (num_gt, ).
      ref_gt_instance_ids (list[Tensor]): The instance ids of gt_bboxes
          of all reference images in a batch, each tensor has shape
          (num_gt, ).
  
  Returns:
      Tuple[list[Tensor]]: Ground truth for proposals in a batch.
      Containing the following list of Tensors:
  
          - track_id_targets (list[Tensor]): The instance ids of
            Gt_labels for all proposals in a batch, each tensor in list
            has shape (num_proposals,).
          - track_id_weights (list[Tensor]): Labels_weights for
            all proposals in a batch, each tensor in list has
            shape (num_proposals,).
docstr_tok: ["Calculate","the","ground","truth","for","all","samples","in","a","batch","according","to","the","sampling_results",".","Args",":","sampling_results","(","List","[","obj",":","SamplingResult","]",")",":","Assign","results","of","all","images","in","a","batch","after","sampling",".","gt_instance_ids","(","list","[","Tensor","]",")",":","The","instance","ids","of","gt_bboxes","of","all","images","in","a","batch",",","each","tensor","has","shape","(","num_gt",",",")",".","ref_gt_instance_ids","(","list","[","Tensor","]",")",":","The","instance","ids","of","gt_bboxes","of","all","reference","images","in","a","batch",",","each","tensor","has","shape","(","num_gt",",",")",".","Returns",":","Tuple","[","list","[","Tensor","]","]",":","Ground","truth","for","proposals","in","a","batch",".","Containing","the","following","list","of","Tensors",":","-","track_id_targets","(","list","[","Tensor","]",")",":","The","instance","ids","of","Gt_labels","for","all","proposals","in","a","batch",",","each","tensor","in","list","has","shape","(","num_proposals",",",")",".","-","track_id_weights","(","list","[","Tensor","]",")",":","Labels_weights","for","all","proposals","in","a","batch",",","each","tensor","in","list","has","shape","(","num_proposals",",",")","."]
code: def get_targets(
      self,
      sampling_results: List[SamplingResult],
      gt_instance_ids: List[Tensor],
      ref_gt_instance_ids: List[Tensor],
  ) -> Tuple[List, List]:
      """Calculate the ground truth for all samples in a batch according to
      the sampling_results.
  
      Args:
          sampling_results (List[obj:SamplingResult]): Assign results of
              all images in a batch after sampling.
          gt_instance_ids (list[Tensor]): The instance ids of gt_bboxes of
              all images in a batch, each tensor has shape (num_gt, ).
          ref_gt_instance_ids (list[Tensor]): The instance ids of gt_bboxes
              of all reference images in a batch, each tensor has shape
              (num_gt, ).
  
      Returns:
          Tuple[list[Tensor]]: Ground truth for proposals in a batch.
          Containing the following list of Tensors:
  
              - track_id_targets (list[Tensor]): The instance ids of
                Gt_labels for all proposals in a batch, each tensor in list
                has shape (num_proposals,).
              - track_id_weights (list[Tensor]): Labels_weights for
                all proposals in a batch, each tensor in list has
                shape (num_proposals,).
      """
      track_id_targets = []
      track_id_weights = []
  
      for res, gt_instance_id, ref_gt_instance_id in zip(
          sampling_results, gt_instance_ids, ref_gt_instance_ids
      ):
          pos_instance_ids = gt_instance_id[res.pos_assigned_gt_inds]
          pos_match_id = gt_instance_id.new_zeros(len(pos_instance_ids))
          for i, id in enumerate(pos_instance_ids):
              if id in ref_gt_instance_id:
                  pos_match_id[i] = (
                      ref_gt_instance_id.tolist().index(id) + 1
                  )
  
          track_id_target = gt_instance_id.new_zeros(
              len(res.bboxes), dtype=torch.int64
          )
          track_id_target[: len(res.pos_bboxes)] = pos_match_id
          track_id_weight = res.bboxes.new_zeros(len(res.bboxes))
          track_id_weight[: len(res.pos_bboxes)] = 1.0
  
          track_id_targets.append(track_id_target)
          track_id_weights.append(track_id_weight)
  
      return track_id_targets, track_id_weights
  
imports: from collections import defaultdict
  from typing import List, Optional, Tuple
  import torch
  import torch.nn
  from mmcv.cnn import ConvModule
  from mmengine.model import BaseModule
  from torch import Tensor
  from torch.nn.modules.utils import _pair
  from mmdet.models.losses import accuracy
  from mmdet.models.task_modules import SamplingResult
  from mmdet.models.task_modules.tracking import embed_similarity
  from mmdet.registry import MODELS
label_desc: Use image node_id 6 for calling the RoIEmbedHead obj's underlying member method code with example usage: obj.get_targets(sampling_results, gt_instance_ids, ref_gt_instance_ids) and returns: track_id_targets,  track_id_weights