open-mmlab/mmdetection · error · NotImplementedError

Please train `detector` and `reid` models firstly, then

Error message

Please train `detector` and `reid` models firstly, then                 inference with SORT/DeepSORT.

What it means

SORT/DeepSORT are inference-only wrappers around separately trained detector and ReID models, so BaseSort.loss raises NotImplementedError to signal that end-to-end training is not supported. You must supply pretrained weights via init_cfg for both detector and reid.

Source

Thrown at mmdet/models/mot/deep_sort.py:51

                 data_preprocessor: OptConfigType = None,
                 init_cfg: OptConfigType = None):
        super().__init__(data_preprocessor, init_cfg)

        if detector is not None:
            self.detector = MODELS.build(detector)

        if reid is not None:
            self.reid = MODELS.build(reid)

        if tracker is not None:
            self.tracker = MODELS.build(tracker)

        self.preprocess_cfg = data_preprocessor

    def loss(self, inputs: Tensor, data_samples: TrackSampleList,
             **kwargs) -> dict:
        """Calculate losses from a batch of inputs and data samples."""
        raise NotImplementedError(
            'Please train `detector` and `reid` models firstly, then \
                inference with SORT/DeepSORT.')

    def predict(self,
                inputs: Tensor,
                data_samples: TrackSampleList,
                rescale: bool = True,
                **kwargs) -> TrackSampleList:
        """Predict results from a video and data samples with post- processing.

        Args:
            inputs (Tensor): of shape (N, T, C, H, W) encoding
                input images. The N denotes batch size.
                The T denotes the number of key frames
                and reference frames.
            data_samples (list[:obj:`TrackDataSample`]): The batch
                data samples. It usually includes information such
                as `gt_instance`.

View on GitHub (pinned to cfd5d3a985)

Solutions

  1. Train the detector (e.g. Faster R-CNN) and ReID model separately first
  2. Point init_cfg.checkpoint of detector and reid to the trained weights and use tools/test.py for tracking inference

Example fix

# before
python tools/train.py configs/sort/sort_deepsort_faster-rcnn_r50_fpn_8xb2-4e_mot17halftrain.py
# after
python tools/test.py configs/sort/sort_deepsort_faster-rcnn_r50_fpn_8xb2-4e_mot17halftrain.py \
  --checkpoint detector_and_reid.pth
Defensive patterns

Strategy: validation

Validate before calling

assert model.cfg.model.type not in ('SORT','DeepSORT') or not training, 'SORT/DeepSORT are inference-only'

Prevention

When it happens

Trigger: Running tools/train.py with a sort_deepsort config, or calling model(imgs, data_samples, mode='loss') on SORT/DeepSORT.

Common situations: Users try to fine-tune a SORT/DeepSORT config from scratch instead of loading a trained detector + ReID checkpoint.

Related errors


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