open-mmlab/mmdetection · error · RuntimeError
Invalid mode "{mode}". Only supports loss, predict and tenso
Error message
Invalid mode "{mode}". Only supports loss, predict and tensor mode What it means
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.
Source
Thrown at mmdet/models/mot/base.py:114
data_samples (list[:obj:`TrackDataSample`], optional): The
annotation data of every samples. Defaults to None.
mode (str): Return what kind of value. Defaults to 'predict'.
Returns:
The return type depends on ``mode``.
- If ``mode="tensor"``, return a tensor or a tuple of tensor.
- If ``mode="predict"``, return a list of :obj:`TrackDataSample`.
- If ``mode="loss"``, return a dict of tensor.
"""
if mode == 'loss':
return self.loss(inputs, data_samples, **kwargs)
elif mode == 'predict':
return self.predict(inputs, data_samples, **kwargs)
elif mode == 'tensor':
return self._forward(inputs, data_samples, **kwargs)
else:
raise RuntimeError(f'Invalid mode "{mode}". '
'Only supports loss, predict and tensor mode')
@abstractmethod
def loss(self, inputs: Dict[str, Tensor], data_samples: TrackSampleList,
**kwargs) -> Union[dict, tuple]:
"""Calculate losses from a batch of inputs and data samples."""
pass
@abstractmethod
def predict(self, inputs: Dict[str, Tensor], data_samples: TrackSampleList,
**kwargs) -> TrackSampleList:
"""Predict results from a batch of inputs and data samples with post-
processing."""
pass
def _forward(self,
inputs: Dict[str, Tensor],
data_samples: OptTrackSampleList = None,View on GitHub (pinned to cfd5d3a985)
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'
Example fix
# before losses = model(imgs, batch_data_samples, mode='train') # after losses = model(imgs, batch_data_samples, mode='loss')
Defensive patterns
Strategy: validation
Validate before calling
VALID = {'loss','predict','tensor'}
assert mode in VALID, f'mode must be one of {VALID}, got {mode!r}' Type guard
def is_valid_mode(m: str) -> bool: return m in {'loss','predict','tensor'} Prevention
- Centralize mode strings as constants in custom loops
- Remember mmdet 3.x modes: loss/predict/tensor (not train/test)
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.
Related errors
- trackeval is not installed,please install it by: pip install
- metric must be a list or a str.
- metric {metric} is not supported.
- module must be a str or a list.
- _forward function (namely 'tensor' mode) is not supported no
AI-assisted analysis of open-mmlab/mmdetection@cfd5d3a985 (2026-08-27).
Data as JSON: /api/errors/56876190f8a47c6c.
Report an issue: GitHub.