{"record":{"id":"506f03f9c562469c","repo":"open-mmlab/mmdetection","slug":"please-train-detector-and-reid-models-firstly","errorCode":null,"errorMessage":"Please train `detector` and `reid` models firstly, then                 inference with SORT/DeepSORT.","messagePattern":"Please train `detector` and `reid` models firstly, then                 inference with SORT/DeepSORT\\.","errorType":"exception","errorClass":"NotImplementedError","httpStatus":null,"severity":"error","filePath":"mmdet/models/mot/deep_sort.py","lineNumber":51,"sourceCode":"                 data_preprocessor: OptConfigType = None,\n                 init_cfg: OptConfigType = None):\n        super().__init__(data_preprocessor, init_cfg)\n\n        if detector is not None:\n            self.detector = MODELS.build(detector)\n\n        if reid is not None:\n            self.reid = MODELS.build(reid)\n\n        if tracker is not None:\n            self.tracker = MODELS.build(tracker)\n\n        self.preprocess_cfg = data_preprocessor\n\n    def loss(self, inputs: Tensor, data_samples: TrackSampleList,\n             **kwargs) -> dict:\n        \"\"\"Calculate losses from a batch of inputs and data samples.\"\"\"\n        raise NotImplementedError(\n            'Please train `detector` and `reid` models firstly, then \\\n                inference with SORT/DeepSORT.')\n\n    def predict(self,\n                inputs: Tensor,\n                data_samples: TrackSampleList,\n                rescale: bool = True,\n                **kwargs) -> TrackSampleList:\n        \"\"\"Predict results from a video and data samples with post- processing.\n\n        Args:\n            inputs (Tensor): of shape (N, T, C, H, W) encoding\n                input images. The N denotes batch size.\n                The T denotes the number of key frames\n                and reference frames.\n            data_samples (list[:obj:`TrackDataSample`]): The batch\n                data samples. It usually includes information such\n                as `gt_instance`.","sourceCodeStart":33,"sourceCodeEnd":69,"githubUrl":"https://github.com/open-mmlab/mmdetection/blob/cfd5d3a985b0249de009b67d04f37263e11cdf3d/mmdet/models/mot/deep_sort.py#L33-L69","documentation":"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.","triggerScenarios":"Running tools/train.py with a sort_deepsort config, or calling model(imgs, data_samples, mode='loss') on SORT/DeepSORT.","commonSituations":"Users try to fine-tune a SORT/DeepSORT config from scratch instead of loading a trained detector + ReID checkpoint.","solutions":["Train the detector (e.g. Faster R-CNN) and ReID model separately first","Point init_cfg.checkpoint of detector and reid to the trained weights and use tools/test.py for tracking inference"],"exampleFix":"# before\npython tools/train.py configs/sort/sort_deepsort_faster-rcnn_r50_fpn_8xb2-4e_mot17halftrain.py\n# after\npython tools/test.py configs/sort/sort_deepsort_faster-rcnn_r50_fpn_8xb2-4e_mot17halftrain.py \\\n  --checkpoint detector_and_reid.pth","handlingStrategy":"validation","validationCode":"assert model.cfg.model.type not in ('SORT','DeepSORT') or not training, 'SORT/DeepSORT are inference-only'","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Check init_cfg.checkpoint is set for both detector and reid before running SORT/DeepSORT","Use tools/test.py, never tools/train.py, with SORT/DeepSORT configs"],"tags":["mmdetection","tracking","sort","deepsort"],"backgroundTag":"inference-only-model","analyzedSha":"cfd5d3a985b0249de009b67d04f37263e11cdf3d","analyzedAt":"2026-08-27T20:54:20.183Z","schemaVersion":2},"datasetVersion":"2026-08-28T00:17:15.603Z"}