open-mmlab/mmdetection · error · ValueError

only {num_videos} videos loaded,but {self.world_size} gpus w

Error message

only {num_videos} videos loaded,but {self.world_size} gpus were given.

What it means

In test mode, mmdet's video track img sampler must place all images of one video on the same GPU, so it needs at least as many videos as distributed ranks. With fewer videos than world_size, some rank would receive an empty chunk and the run aborts with this ValueError.

Source

Thrown at mmdet/datasets/samplers/track_img_sampler.py:95

            'exist in test mode'
            video_indices = self.dataset.repeat_indices
            for index in video_indices:
                self.indices.extend([(index, frame_ind) for frame_ind in range(
                    ori_dataset.get_len_per_video(index))])
        else:
            assert isinstance(
                self.dataset, BaseVideoDataset
            ), 'TrackImgSampler is only supported in BaseVideoDataset or '
            'dataset wrapper: ClassBalancedDataset and ConcatDataset, but '
            f'got {type(self.dataset)} '
            self.test_mode = self.dataset.test_mode
            num_videos = len(self.dataset)

            if self.test_mode:
                # in test mode, the images belong to the same video must be put
                # on the same device.
                if num_videos < self.world_size:
                    raise ValueError(f'only {num_videos} videos loaded,'
                                     f'but {self.world_size} gpus were given.')
                chunks = np.array_split(
                    list(range(num_videos)), self.world_size)
                for videos_inds in chunks:
                    indices_chunk = []
                    for video_ind in videos_inds:
                        indices_chunk.extend([
                            (video_ind, frame_ind) for frame_ind in range(
                                self.dataset.get_len_per_video(video_ind))
                        ])
                    self.indices.append(indices_chunk)
            else:
                for video_ind in range(num_videos):
                    self.indices.extend([
                        (video_ind, frame_ind) for frame_ind in range(
                            self.dataset.get_len_per_video(video_ind))
                    ])

View on GitHub (pinned to cfd5d3a985)

Solutions

  1. Reduce the number of GPUs/processes to be <= number of test videos (often 1 for small sets)
  2. Add more videos to the dataset split if you truly need multi-GPU eval
  3. Ensure you are not accidentally in test_mode with a distributed launcher for single-video inference; use non-distributed single-process eval instead

Example fix

# before
torchrun --nproc_per_node=8 tools/test.py config.py ckpt.pth  # dataset has 2 videos
# after
torchrun --nproc_per_node=2 tools/test.py config.py ckpt.pth  # or 1 process
Defensive patterns

Strategy: validation

Validate before calling

num_videos = len(track_dataset)
world_size = int(os.environ.get('WORLD_SIZE', 1))
assert num_videos >= world_size, f'{num_videos} videos < {world_size} GPUs; reduce nproc_per_node'

Prevention

When it happens

Trigger: Distributed testing (torchrun/mmlauncher with N processes) of a tracking dataset (e.g. MOT17 via VideoSampler) that contains fewer videos than N — e.g. 2 test videos launched on 8 GPUs.

Common situations: Running multi-GPU eval on a small validation subset, a custom tracking dataset with 1-2 videos, or single-video demo scripts accidentally launched with distributed settings; world_size derived from env without matching dataset size.

Related errors


AI-assisted analysis of open-mmlab/mmdetection@cfd5d3a985 (2026-08-27). Data as JSON: /api/errors/5171594c02e37ebf. Report an issue: GitHub.