class_docstr: Quasi-Dense Similarity Learning for Multiple Object Tracking.
  
  This multi object tracker is the implementation of `QDTrack
  <https://arxiv.org/abs/2006.06664>`_.
  
  Args:
      detector (dict): Configuration of detector. Defaults to None.
      track_head (dict): Configuration of track head. Defaults to None.
      tracker (dict): Configuration of tracker. Defaults to None.
      freeze_detector (bool): If True, freeze the detector weights.
          Defaults to False.
      data_preprocessor (dict or ConfigDict, optional): The pre-process
         config of :class:`TrackDataPreprocessor`.  it usually includes,
          ``pad_size_divisor``, ``pad_value``, ``mean`` and ``std``.
      init_cfg (dict or list[dict]): Configuration of initialization.
          Defaults to None.
class_docstr_tok: ["Quasi-Dense","Similarity","Learning","for","Multiple","Object","Tracking",".","This","multi","object","tracker","is","the","implementation","of","`","QDTrack","<","https",":","\/\/arxiv.org\/abs\/2006.06664",">","`","_",".","Args",":","detector","(","dict",")",":","Configuration","of","detector",".","Defaults","to","None",".","track_head","(","dict",")",":","Configuration","of","track","head",".","Defaults","to","None",".","tracker","(","dict",")",":","Configuration","of","tracker",".","Defaults","to","None",".","freeze_detector","(","bool",")",":","If","True",",","freeze","the","detector","weights",".","Defaults","to","False",".","data_preprocessor","(","dict","or","ConfigDict",",","optional",")",":","The","pre-process","config","of",":","class",":","`","TrackDataPreprocessor","`",".","it","usually","includes",",","``","pad_size_divisor","``",",","``","pad_value","``",",","``","mean","``","and","``","std","``",".","init_cfg","(","dict","or","list","[","dict","]",")",":","Configuration","of","initialization",".","Defaults","to","None","."]
docstr: Calculate losses from a batch of inputs and data samples.
  
  Args:
      inputs (Dict[str, Tensor]): of shape (N, T, C, H, W) encoding
          input images. Typically these should be mean centered and std
          scaled. The N denotes batch size. The T denotes the number of
          frames.
      data_samples (list[:obj:`TrackDataSample`]): The batch
          data samples. It usually includes information such
          as `video_data_samples`.
  
  Returns:
      dict: A dictionary of loss components.
docstr_tok: ["Calculate","losses","from","a","batch","of","inputs","and","data","samples",".","Args",":","inputs","(","Dict","[","str",",","Tensor","]",")",":","of","shape","(","N",",","T",",","C",",","H",",","W",")","encoding","input","images",".","Typically","these","should","be","mean","centered","and","std","scaled",".","The","N","denotes","batch","size",".","The","T","denotes","the","number","of","frames",".","data_samples","(","list","[",":","obj",":","`","TrackDataSample","`","]",")",":","The","batch","data","samples",".","It","usually","includes","information","such","as","`","video_data_samples","`",".","Returns",":","dict",":","A","dictionary","of","loss","components","."]
code: def loss(
      self, inputs: Tensor, data_samples: TrackSampleList, **kwargs
  ) -> Union[dict, tuple]:
      """Calculate losses from a batch of inputs and data samples.
  
      Args:
          inputs (Dict[str, Tensor]): of shape (N, T, C, H, W) encoding
              input images. Typically these should be mean centered and std
              scaled. The N denotes batch size. The T denotes the number of
              frames.
          data_samples (list[:obj:`TrackDataSample`]): The batch
              data samples. It usually includes information such
              as `video_data_samples`.
  
      Returns:
          dict: A dictionary of loss components.
      """
      # modify the inputs shape to fit mmdet
      assert (
          inputs.dim() == 5
      ), "The img must be 5D Tensor (N, T, C, H, W)."
      assert (
          inputs.size(1) == 2
      ), "QDTrack can only have 1 key frame and 1 reference frame."
  
      # split the data_samples into two aspects: key frames and reference
      # frames
      ref_data_samples, key_data_samples = [], []
      key_frame_inds, ref_frame_inds = [], []
      # set cat_id of gt_labels to 0 in RPN
      for track_data_sample in data_samples:
          key_frame_inds.append(track_data_sample.key_frames_inds[0])
          ref_frame_inds.append(track_data_sample.ref_frames_inds[0])
          key_data_sample = track_data_sample.get_key_frames()[0]
          key_data_sample.gt_instances.labels = torch.zeros_like(
              key_data_sample.gt_instances.labels
          )
          key_data_samples.append(key_data_sample)
          ref_data_sample = track_data_sample.get_ref_frames()[0]
          ref_data_samples.append(ref_data_sample)
  
      key_frame_inds = torch.tensor(key_frame_inds, dtype=torch.int64)
      ref_frame_inds = torch.tensor(ref_frame_inds, dtype=torch.int64)
      batch_inds = torch.arange(len(inputs))
      key_imgs = inputs[batch_inds, key_frame_inds].contiguous()
      ref_imgs = inputs[batch_inds, ref_frame_inds].contiguous()
  
      x = self.detector.extract_feat(key_imgs)
      ref_x = self.detector.extract_feat(ref_imgs)
  
      losses = dict()
      # RPN head forward and loss
      assert (
          self.detector.with_rpn
      ), "QDTrack only support detector with RPN."
  
      proposal_cfg = self.detector.train_cfg.get(
          "rpn_proposal", self.detector.test_cfg.rpn
      )
      (
          rpn_losses,
          rpn_results_list,
      ) = self.detector.rpn_head.loss_and_predict(
          x, key_data_samples, proposal_cfg=proposal_cfg, **kwargs
      )
      ref_rpn_results_list = self.detector.rpn_head.predict(
          ref_x, ref_data_samples, **kwargs
      )
  
      # avoid get same name with roi_head loss
      keys = rpn_losses.keys()
      for key in keys:
          if "loss" in key and "rpn" not in key:
              rpn_losses[f"rpn_{key}"] = rpn_losses.pop(key)
      losses.update(rpn_losses)
  
      # roi_head loss
      losses_detect = self.detector.roi_head.loss(
          x, rpn_results_list, key_data_samples, **kwargs
      )
      losses.update(losses_detect)
  
      # tracking head loss
      losses_track = self.track_head.loss(
          x,
          ref_x,
          rpn_results_list,
          ref_rpn_results_list,
          data_samples,
          **kwargs,
      )
      losses.update(losses_track)
  
      return losses
  
file_path: mmdetection/mmdet/models/mot/qdtrack.py
imports: from typing import Optional, Union
  import torch
  from torch import Tensor
  from mmdet.registry import MODELS
  from mmdet.structures import TrackSampleList
  from mmdet.utils import OptConfigType, OptMultiConfig
  from .base import BaseMOTModel
label_desc: Use image node_id 3 for calling the QDTrack obj's underlying member method code with example usage: obj.loss(inputs, data_samples) and returns: losses