class_docstr: Tracker for MaskTrack R-CNN.
  
  Args:
      match_weights (dict[str : float]): The Weighting factor when computing
      the match score. It contains keys as follows:
  
          - det_score (float): The coefficient of `det_score` when computing
              match score.
          - iou (float): The coefficient of `ious` when computing match
              score.
          - det_label (float): The coefficient of `label_deltas` when
              computing match score.
class_docstr_tok: ["Tracker","for","MaskTrack","R-CNN",".","Args",":","match_weights","(","dict","[","str",":","float","]",")",":","The","Weighting","factor","when","computing","the","match","score",".","It","contains","keys","as","follows",":","-","det_score","(","float",")",":","The","coefficient","of","`","det_score","`","when","computing","match","score",".","-","iou","(","float",")",":","The","coefficient","of","`","ious","`","when","computing","match","score",".","-","det_label","(","float",")",":","The","coefficient","of","`","label_deltas","`","when","computing","match","score","."]
docstr: Tracking forward function.
  
  Args:
      model (nn.Module): VIS model.
      img (Tensor): of shape (T, C, H, W) encoding input image.
          Typically these should be mean centered and std scaled.
          The T denotes the number of key images and usually is 1 in
          MaskTrackRCNN method.
      feats (list[Tensor]): Multi level feature maps of `img`.
      data_sample (:obj:`TrackDataSample`): The data sample.
          It includes information such as `pred_det_instances`.
      rescale (bool, optional): If True, the bounding boxes should be
          rescaled to fit the original scale of the image. Defaults to
          True.
  
  Returns:
      :obj:`InstanceData`: Tracking results of the input images.
      Each InstanceData usually contains ``bboxes``, ``labels``,
      ``scores`` and ``instances_id``.
docstr_tok: ["Tracking","forward","function",".","Args",":","model","(","nn.Module",")",":","VIS","model",".","img","(","Tensor",")",":","of","shape","(","T",",","C",",","H",",","W",")","encoding","input","image",".","Typically","these","should","be","mean","centered","and","std","scaled",".","The","T","denotes","the","number","of","key","images","and","usually","is","1","in","MaskTrackRCNN","method",".","feats","(","list","[","Tensor","]",")",":","Multi","level","feature","maps","of","`","img","`",".","data_sample","(",":","obj",":","`","TrackDataSample","`",")",":","The","data","sample",".","It","includes","information","such","as","`","pred_det_instances","`",".","rescale","(","bool",",","optional",")",":","If","True",",","the","bounding","boxes","should","be","rescaled","to","fit","the","original","scale","of","the","image",".","Defaults","to","True",".","Returns",":",":","obj",":","`","InstanceData","`",":","Tracking","results","of","the","input","images",".","Each","InstanceData","usually","contains","``","bboxes","``",",","``","labels","``",",","``","scores","``","and","``","instances_id","``","."]
code: def track(
      self,
      model: torch.nn.Module,
      feats: List[torch.Tensor],
      data_sample: DetDataSample,
      rescale=True,
      **kwargs,
  ) -> InstanceData:
      """Tracking forward function.
  
      Args:
          model (nn.Module): VIS model.
          img (Tensor): of shape (T, C, H, W) encoding input image.
              Typically these should be mean centered and std scaled.
              The T denotes the number of key images and usually is 1 in
              MaskTrackRCNN method.
          feats (list[Tensor]): Multi level feature maps of `img`.
          data_sample (:obj:`TrackDataSample`): The data sample.
              It includes information such as `pred_det_instances`.
          rescale (bool, optional): If True, the bounding boxes should be
              rescaled to fit the original scale of the image. Defaults to
              True.
  
      Returns:
          :obj:`InstanceData`: Tracking results of the input images.
          Each InstanceData usually contains ``bboxes``, ``labels``,
          ``scores`` and ``instances_id``.
      """
      metainfo = data_sample.metainfo
      bboxes = data_sample.pred_instances.bboxes
      masks = data_sample.pred_instances.masks
      labels = data_sample.pred_instances.labels
      scores = data_sample.pred_instances.scores
  
      frame_id = metainfo.get("frame_id", -1)
      # create pred_track_instances
      pred_track_instances = InstanceData()
  
      if bboxes.shape[0] == 0:
          ids = torch.zeros_like(labels)
          pred_track_instances = data_sample.pred_instances.clone()
          pred_track_instances.instances_id = ids
          return pred_track_instances
  
      rescaled_bboxes = bboxes.clone()
      if rescale:
          scale_factor = rescaled_bboxes.new_tensor(
              metainfo["scale_factor"]
          ).repeat((1, 2))
          rescaled_bboxes = rescaled_bboxes * scale_factor
      roi_feats, _ = model.track_head.extract_roi_feats(
          feats, [rescaled_bboxes]
      )
  
      if self.empty:
          num_new_tracks = bboxes.size(0)
          ids = torch.arange(
              self.num_tracks,
              self.num_tracks + num_new_tracks,
              dtype=torch.long,
          )
          self.num_tracks += num_new_tracks
      else:
          prev_bboxes = self.get("bboxes")
          prev_labels = self.get("labels")
          prev_roi_feats = self.get("roi_feats")
  
          similarity_logits = model.track_head.predict(
              roi_feats, prev_roi_feats
          )
          match_scores = self.get_match_score(
              bboxes,
              labels,
              scores,
              prev_bboxes,
              prev_labels,
              similarity_logits,
          )
          ids, _ = self.assign_ids(match_scores)
  
      valid_inds = ids > -1
      ids = ids[valid_inds]
      bboxes = bboxes[valid_inds]
      labels = labels[valid_inds]
      scores = scores[valid_inds]
      masks = masks[valid_inds]
      roi_feats = roi_feats[valid_inds]
  
      self.update(
          ids=ids,
          bboxes=bboxes,
          labels=labels,
          scores=scores,
          masks=masks,
          roi_feats=roi_feats,
          frame_ids=frame_id,
      )
      # update pred_track_instances
      pred_track_instances.bboxes = bboxes
      pred_track_instances.masks = masks
      pred_track_instances.labels = labels
      pred_track_instances.scores = scores
      pred_track_instances.instances_id = ids
  
      return pred_track_instances
  
file_path: mmdetection/mmdet/models/trackers/masktrack_rcnn_tracker.py
imports: from typing import List
  import torch
  from mmengine.structures import InstanceData
  from torch import Tensor
  from mmdet.registry import MODELS
  from mmdet.structures import DetDataSample
  from mmdet.structures.bbox import bbox_overlaps
  from .base_tracker import BaseTracker
label_desc: Use image node_id 4 for calling the MaskTrackRCNNTracker obj's underlying member method code with example usage: obj.track(model, feats, data_sample, rescale) and returns: pred_track_instances, pred_track_instances