{"record":{"id":"56876190f8a47c6c","repo":"open-mmlab/mmdetection","slug":"invalid-mode-mode-only-supports-loss-predict-568761","errorCode":null,"errorMessage":"Invalid mode \"{mode}\". Only supports loss, predict and tensor mode","messagePattern":"Invalid mode \"(.+?)\"\\. Only supports loss, predict and tensor mode","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"mmdet/models/mot/base.py","lineNumber":114,"sourceCode":"            data_samples (list[:obj:`TrackDataSample`], optional): The\n                annotation data of every samples. Defaults to None.\n            mode (str): Return what kind of value. Defaults to 'predict'.\n\n        Returns:\n            The return type depends on ``mode``.\n\n            - If ``mode=\"tensor\"``, return a tensor or a tuple of tensor.\n            - If ``mode=\"predict\"``, return a list of :obj:`TrackDataSample`.\n            - If ``mode=\"loss\"``, return a dict of tensor.\n        \"\"\"\n        if mode == 'loss':\n            return self.loss(inputs, data_samples, **kwargs)\n        elif mode == 'predict':\n            return self.predict(inputs, data_samples, **kwargs)\n        elif mode == 'tensor':\n            return self._forward(inputs, data_samples, **kwargs)\n        else:\n            raise RuntimeError(f'Invalid mode \"{mode}\". '\n                               'Only supports loss, predict and tensor mode')\n\n    @abstractmethod\n    def loss(self, inputs: Dict[str, Tensor], data_samples: TrackSampleList,\n             **kwargs) -> Union[dict, tuple]:\n        \"\"\"Calculate losses from a batch of inputs and data samples.\"\"\"\n        pass\n\n    @abstractmethod\n    def predict(self, inputs: Dict[str, Tensor], data_samples: TrackSampleList,\n                **kwargs) -> TrackSampleList:\n        \"\"\"Predict results from a batch of inputs and data samples with post-\n        processing.\"\"\"\n        pass\n\n    def _forward(self,\n                 inputs: Dict[str, Tensor],\n                 data_samples: OptTrackSampleList = None,","sourceCodeStart":96,"sourceCodeEnd":132,"githubUrl":"https://github.com/open-mmlab/mmdetection/blob/cfd5d3a985b0249de009b67d04f37263e11cdf3d/mmdet/models/mot/base.py#L96-L132","documentation":"Raised by BaseMot.forward when the `mode` argument is anything other than 'loss', 'predict', or 'tensor'. MOT base models dispatch forward to loss/predict/_forward based on this mode string, mirroring mmdet's BaseDetector convention.","triggerScenarios":"Calling mot_model(imgs, data_samples, mode='val') or mode='inference', mode='test', or forgetting mode entirely in a custom loop where inputs happen to be a string.","commonSituations":"Custom test/training scripts that assume an older mmdet API (mode='train') or that pass a train/eval flag instead of the supported mode strings.","solutions":["Use mode='loss' when training, mode='predict' for inference returning DetDataSample, mode='tensor' for raw tensor outputs","If migrating old code, replace mode='train' with mode='loss' and mode='test' with mode='predict'"],"exampleFix":"# before\nlosses = model(imgs, batch_data_samples, mode='train')\n# after\nlosses = model(imgs, batch_data_samples, mode='loss')","handlingStrategy":"validation","validationCode":"VALID = {'loss','predict','tensor'}\nassert mode in VALID, f'mode must be one of {VALID}, got {mode!r}'","typeGuard":"def is_valid_mode(m: str) -> bool: return m in {'loss','predict','tensor'}","tryCatchPattern":null,"preventionTips":["Centralize mode strings as constants in custom loops","Remember mmdet 3.x modes: loss/predict/tensor (not train/test)"],"tags":["mmdetection","mot","forward-mode"],"backgroundTag":"invalid-argument-value","analyzedSha":"cfd5d3a985b0249de009b67d04f37263e11cdf3d","analyzedAt":"2026-08-27T20:54:20.183Z","schemaVersion":2},"datasetVersion":"2026-08-28T00:17:15.603Z"}