class_docstr: Pack the inputs data for the multi object tracking and video instance
  segmentation. All the information of images are packed to ``inputs``. All
  the information except images are packed to ``data_samples``. In order to
  get the original annotaiton and meta info, we add `instances` key into meta
  keys.
  
  Args:
      meta_keys (Sequence[str]): Meta keys to be collected in
          ``data_sample.metainfo``. Defaults to None.
      default_meta_keys (tuple): Default meta keys. Defaults to ('img_id',
          'img_path', 'ori_shape', 'img_shape', 'scale_factor',
          'flip', 'flip_direction', 'frame_id', 'is_video_data',
          'video_id', 'video_length', 'instances').
docstr: Method to pack the input data.
  Args:
      results (dict): Result dict from the data pipeline.
  Returns:
      dict:
      - 'inputs' (dict[Tensor]): The forward data of models.
      - 'data_samples' (obj:`TrackDataSample`): The annotation info of
          the samples.
code: def transform(self, results: dict) -> dict:
      """Method to pack the input data.
      Args:
          results (dict): Result dict from the data pipeline.
      Returns:
          dict:
          - 'inputs' (dict[Tensor]): The forward data of models.
          - 'data_samples' (obj:`TrackDataSample`): The annotation info of
              the samples.
      """
      packed_results = dict()
      packed_results["inputs"] = dict()
  
      # 1. Pack images
      if "img" in results:
          imgs = results["img"]
          imgs = np.stack(imgs, axis=0)
          imgs = imgs.transpose(0, 3, 1, 2)
          packed_results["inputs"] = to_tensor(imgs)
  
      # 2. Pack InstanceData
      if "gt_ignore_flags" in results:
          gt_ignore_flags_list = results["gt_ignore_flags"]
          valid_idx_list, ignore_idx_list = [], []
          for gt_ignore_flags in gt_ignore_flags_list:
              valid_idx = np.where(gt_ignore_flags == 0)[0]
              ignore_idx = np.where(gt_ignore_flags == 1)[0]
              valid_idx_list.append(valid_idx)
              ignore_idx_list.append(ignore_idx)
  
      assert (
          "img_id" in results
      ), "'img_id' must contained in the results "
      "for counting the number of images"
  
      num_imgs = len(results["img_id"])
      instance_data_list = [InstanceData() for _ in range(num_imgs)]
      ignore_instance_data_list = [
          InstanceData() for _ in range(num_imgs)
      ]
  
      for key in self.mapping_table.keys():
          if key not in results:
              continue
          if key == "gt_masks":
              mapped_key = self.mapping_table[key]
              gt_masks_list = results[key]
              if "gt_ignore_flags" in results:
                  for i, gt_mask in enumerate(gt_masks_list):
                      valid_idx, ignore_idx = (
                          valid_idx_list[i],
                          ignore_idx_list[i],
                      )
                      instance_data_list[i][mapped_key] = gt_mask[
                          valid_idx
                      ]
                      ignore_instance_data_list[i][
                          mapped_key
                      ] = gt_mask[ignore_idx]
  
              else:
                  for i, gt_mask in enumerate(gt_masks_list):
                      instance_data_list[i][mapped_key] = gt_mask
  
          else:
              anns_list = results[key]
              if "gt_ignore_flags" in results:
                  for i, ann in enumerate(anns_list):
                      valid_idx, ignore_idx = (
                          valid_idx_list[i],
                          ignore_idx_list[i],
                      )
                      instance_data_list[i][
                          self.mapping_table[key]
                      ] = to_tensor(ann[valid_idx])
                      ignore_instance_data_list[i][
                          self.mapping_table[key]
                      ] = to_tensor(ann[ignore_idx])
              else:
                  for i, ann in enumerate(anns_list):
                      instance_data_list[i][
                          self.mapping_table[key]
                      ] = to_tensor(ann)
  
      det_data_samples_list = []
      for i in range(num_imgs):
          det_data_sample = DetDataSample()
          det_data_sample.gt_instances = instance_data_list[i]
          det_data_sample.ignored_instances = ignore_instance_data_list[
              i
          ]
          det_data_samples_list.append(det_data_sample)
  
      # 3. Pack metainfo
      for key in self.meta_keys:
          if key not in results:
              continue
          img_metas_list = results[key]
          for i, img_meta in enumerate(img_metas_list):
              det_data_samples_list[i].set_metainfo(
                  {f"{key}": img_meta}
              )
  
      track_data_sample = TrackDataSample()
      track_data_sample.video_data_samples = det_data_samples_list
      if "key_frame_flags" in results:
          key_frame_flags = np.asarray(results["key_frame_flags"])
          key_frames_inds = np.where(key_frame_flags)[0].tolist()
          ref_frames_inds = np.where(~key_frame_flags)[0].tolist()
          track_data_sample.set_metainfo(
              dict(key_frames_inds=key_frames_inds)
          )
          track_data_sample.set_metainfo(
              dict(ref_frames_inds=ref_frames_inds)
          )
  
      packed_results["data_samples"] = track_data_sample
      return packed_results
  
imports: from typing import Optional, Sequence
  import numpy
  from mmcv.transforms import to_tensor
  from mmcv.transforms.base import BaseTransform
  from mmengine.structures import InstanceData, PixelData
  from mmdet.registry import TRANSFORMS
  from mmdet.structures import DetDataSample, ReIDDataSample, TrackDataSample
  from mmdet.structures.bbox import BaseBoxes
label_desc: Use image node_id 2 for calling the PackTrackInputs obj's underlying member method code with example usage: obj.transform(results) and returns: packed_results