class_docstr: The roi track head.
  
  This module is used in multi-object tracking methods, such as MaskTrack
  R-CNN.
  
  Args:
      roi_extractor (dict): Configuration of roi extractor. Defaults to None.
      embed_head (dict): Configuration of embed head. Defaults to None.
      train_cfg (dict): Configuration when training. Defaults to None.
      test_cfg (dict): Configuration when testing. Defaults to None.
      init_cfg (dict): Configuration of initialization. Defaults to None.
class_docstr_tok: ["The","roi","track","head",".","This","module","is","used","in","multi-object","tracking","methods",",","such","as","MaskTrack","R-CNN",".","Args",":","roi_extractor","(","dict",")",":","Configuration","of","roi","extractor",".","Defaults","to","None",".","embed_head","(","dict",")",":","Configuration","of","embed","head",".","Defaults","to","None",".","train_cfg","(","dict",")",":","Configuration","when","training",".","Defaults","to","None",".","test_cfg","(","dict",")",":","Configuration","when","testing",".","Defaults","to","None",".","init_cfg","(","dict",")",":","Configuration","of","initialization",".","Defaults","to","None","."]
docstr: Calculate losses from a batch of inputs and data samples.
  
  Args:
      key_feats (list[Tensor]): list of multi-level image features.
      ref_feats (list[Tensor]): list of multi-level ref_img features.
      rpn_results_list (list[:obj:`InstanceData`]): List of region
          proposals.
      data_samples (list[:obj:`TrackDataSample`]): The batch
          data samples. It usually includes information such
          as `gt_instance`.
  
  Returns:
      dict: A dictionary of loss components.
docstr_tok: ["Calculate","losses","from","a","batch","of","inputs","and","data","samples",".","Args",":","key_feats","(","list","[","Tensor","]",")",":","list","of","multi-level","image","features",".","ref_feats","(","list","[","Tensor","]",")",":","list","of","multi-level","ref_img","features",".","rpn_results_list","(","list","[",":","obj",":","`","InstanceData","`","]",")",":","List","of","region","proposals",".","data_samples","(","list","[",":","obj",":","`","TrackDataSample","`","]",")",":","The","batch","data","samples",".","It","usually","includes","information","such","as","`","gt_instance","`",".","Returns",":","dict",":","A","dictionary","of","loss","components","."]
code: def loss(
      self,
      key_feats: List[Tensor],
      ref_feats: List[Tensor],
      rpn_results_list: InstanceList,
      data_samples: TrackSampleList,
      **kwargs,
  ) -> dict:
      """Calculate losses from a batch of inputs and data samples.
  
      Args:
          key_feats (list[Tensor]): list of multi-level image features.
          ref_feats (list[Tensor]): list of multi-level ref_img features.
          rpn_results_list (list[:obj:`InstanceData`]): List of region
              proposals.
          data_samples (list[:obj:`TrackDataSample`]): The batch
              data samples. It usually includes information such
              as `gt_instance`.
  
      Returns:
          dict: A dictionary of loss components.
      """
      assert self.with_track
      batch_gt_instances = []
      ref_batch_gt_instances = []
      batch_gt_instances_ignore = []
      gt_instance_ids = []
      ref_gt_instance_ids = []
      for track_data_sample in data_samples:
          key_data_sample = track_data_sample.get_key_frames()[0]
          ref_data_sample = track_data_sample.get_ref_frames()[0]
          batch_gt_instances.append(key_data_sample.gt_instances)
          ref_batch_gt_instances.append(ref_data_sample.gt_instances)
          if "ignored_instances" in key_data_sample:
              batch_gt_instances_ignore.append(
                  key_data_sample.ignored_instances
              )
          else:
              batch_gt_instances_ignore.append(None)
  
          gt_instance_ids.append(
              key_data_sample.gt_instances.instances_ids
          )
          ref_gt_instance_ids.append(
              ref_data_sample.gt_instances.instances_ids
          )
  
      losses = dict()
      num_imgs = len(data_samples)
      if batch_gt_instances_ignore is None:
          batch_gt_instances_ignore = [None] * num_imgs
      sampling_results = []
      for i in range(num_imgs):
          rpn_results = rpn_results_list[i]
  
          assign_result = self.bbox_assigner.assign(
              rpn_results,
              batch_gt_instances[i],
              batch_gt_instances_ignore[i],
          )
          sampling_result = self.bbox_sampler.sample(
              assign_result,
              rpn_results,
              batch_gt_instances[i],
              feats=[lvl_feat[i][None] for lvl_feat in key_feats],
          )
          sampling_results.append(sampling_result)
  
      bboxes = [res.bboxes for res in sampling_results]
      bbox_feats, num_bbox_per_img = self.extract_roi_feats(
          key_feats, bboxes
      )
  
      # batch_size is 1
      ref_gt_bboxes = [
          ref_batch_gt_instance.bboxes
          for ref_batch_gt_instance in ref_batch_gt_instances
      ]
      ref_bbox_feats, num_bbox_per_ref_img = self.extract_roi_feats(
          ref_feats, ref_gt_bboxes
      )
  
      loss_track = self.embed_head.loss(
          bbox_feats,
          ref_bbox_feats,
          num_bbox_per_img,
          num_bbox_per_ref_img,
          sampling_results,
          gt_instance_ids,
          ref_gt_instance_ids,
      )
      losses.update(loss_track)
  
      return losses
  
file_path: mmdetection/mmdet/models/tracking_heads/roi_track_head.py
imports: from abc import ABCMeta
  from typing import List, Optional, Tuple
  from mmengine.model import BaseModule
  from torch import Tensor
  from mmdet.registry import MODELS, TASK_UTILS
  from mmdet.structures import TrackSampleList
  from mmdet.structures.bbox import bbox2roi
  from mmdet.utils import InstanceList
label_desc: Use image node_id 6 for calling the RoITrackHead obj's underlying member method code with example usage: obj.loss(key_feats, ref_feats, rpn_results_list, data_samples) and returns: losses