open-mmlab / mmtracking

OpenMMLab Video Perception Toolbox. It supports Video Object Detection (VID), Multiple Object Tracking (MOT), Single Object Tracking (SOT), Video Instance Segmentation (VIS) with a unified framework.
https://mmtracking.readthedocs.io/en/latest/
Apache License 2.0
3.56k stars 598 forks source link

Getting dictionary key error when iterating through custom CocoVideoDataset dataloader #789

Open ekim322 opened 1 year ago

ekim322 commented 1 year ago

I am trying to train a SOT model (Siamese RPN) on a custom dataset.

My code runs into an error when it starts iterating through the train dataset in mmcv/runner/epoch_based_runner.py -> class EpochBasedRunner -> train()

class EpochBasedRunner(BaseRunner):
    ....
    ....
    def train(self, data_loader, **kwargs):
        self.model.train()
        self.mode = 'train'
        self.data_loader = data_loader
        self._max_iters = self._max_epochs * len(self.data_loader)
        self.call_hook('before_train_epoch')
        time.sleep(2)  # Prevent possible deadlock during epoch transition
        for i, data_batch in enumerate(self.data_loader):          <-- error occurs in this line
            self.data_batch = data_batch

The iterator (enumerate(self.data_loader)) calls mmtrack/datasets/pipelines/processing.py -> class PairSampling -> call()

  def __call__(self, pair_video_infos):
      """
      Args:
          pair_video_infos (list[dict]): contains two video infos. Each video
              info contains the keys: ['bboxes','bboxes_isvalid','filename',
              'frame_ids','video_id','visible'].
      Returns:
          List[dict]: contains the information of sampled data.
      """
      video_info, video_info_another = pair_video_infos
      if len(video_info['frame_ids']) > 1 and len(          <-- error occurs in this line 
              video_info_another['frame_ids']) > 1:
          template_frame_ind = np.random.choice(len(video_info['frame_ids']))

and I get an error saying

  File "/home/ekim/anaconda3/envs/open-mmlab/lib/python3.7/site-packages/mmdet/datasets/custom.py", line 220, in __getitem__
    data = self.prepare_train_img(idx)
  File "/home/ekim/mmtracking/mmtrack/datasets/coco_video_dataset.py", line 282, in prepare_train_img
    return self.prepare_data(idx)
  File "/home/ekim/mmtracking/mmtrack/datasets/coco_video_dataset.py", line 270, in prepare_data
    return self.pipeline(results)
  File "/home/ekim/anaconda3/envs/open-mmlab/lib/python3.7/site-packages/mmdet/datasets/pipelines/compose.py", line 41, in __call__
    data = t(data)
  File "/home/ekim/mmtracking/mmtrack/datasets/pipelines/processing.py", line 344, in __call__
    if len(video_info['frame_ids']) > 1 and len(
KeyError: 'frame_ids'

Both the video_info and video_info_another dictionaries do not have the key 'frame_ids'. The only keys they have are ['img_info', 'ann_info', 'img_prefix', 'seg_prefix', 'proposal_file', 'bbox_fields', 'mask_fields', 'seg_fields', 'is_video_data'].

I am following the custom dataset instruction from the documentation and I've checked the sample config, but I don't see anywhere with 'frame_ids'.

Am I supposed to be adding frame_ids somewhere in the configuration? I see 'frame_id' in the annotations.json file for the images but I don't see where 'frame_ids' are added

dyhBUPT commented 1 year ago

Hi, have you ever changed the cfg file?

If you can train Siamese RPN on public datasets, but meet errors on your custom dataset with the same cfg file, it seems caused by your wrong dataset/gt format. Please make sure that your custom dataset aligns with one public dataset.

Best wishes.