open-mmlab/mmdetection · critical · RuntimeError

Please run "pip install openmim" and run "mim install mmpret

Error message

Please run "pip install openmim" and run "mim install mmpretrain" to install mmpretrain first.

What it means

BaseReID subclasses mmpretrain's ImageClassifier, which is only available if mmpretrain is installed. __init__ raises RuntimeError at construction time when the mmpretrain import failed (mmpretrain is None), telling you to install it via mim.

Source

Thrown at mmdet/models/reid/base_reid.py:23

try:
    import mmpretrain
    from mmpretrain.models.classifiers import ImageClassifier
except ImportError:
    mmpretrain = None
    ImageClassifier = object

from mmdet.registry import MODELS
from mmdet.structures import ReIDDataSample


@MODELS.register_module()
class BaseReID(ImageClassifier):
    """Base model for re-identification."""

    def __init__(self, *args, **kwargs):
        if mmpretrain is None:
            raise RuntimeError('Please run "pip install openmim" and '
                               'run "mim install mmpretrain" to '
                               'install mmpretrain first.')
        super().__init__(*args, **kwargs)

    def forward(self,
                inputs: torch.Tensor,
                data_samples: Optional[List[ReIDDataSample]] = None,
                mode: str = 'tensor'):
        """The unified entry for a forward process in both training and test.

        The method should accept three modes: "tensor", "predict" and "loss":

        - "tensor": Forward the whole network and return tensor or tuple of
          tensor without any post-processing, same as a common nn.Module.
        - "predict": Forward and return the predictions, which are fully
          processed to a list of :obj:`ReIDDataSample`.
        - "loss": Forward and return a dict of losses according to the given
          inputs and data samples.

View on GitHub (pinned to cfd5d3a985)

Solutions

  1. pip install openmim && mim install mmpretrain
  2. If mim install fails, install a compatible pinned version: pip install mmpretrain>=1.0.0 matching your mmdet version
  3. Verify with python -c "import mmpretrain" that the import succeeds (a failing import also triggers this error)

Example fix

# before
mmdet installed only -> building reid model raises
# after
pip install -U openmim
mim install mmpretrain
Defensive patterns

Strategy: validation

Validate before calling

try:
    import mmpretrain  # noqa
    ok = True
except Exception:
    ok = False
assert ok, 'install mmpretrain before building ReID models'

Prevention

When it happens

Trigger: Building any ReID model (BaseReID and subclasses like GFocalReID, LinearReIDHead-based classifiers) without mmpretrain installed; e.g. training QDTrack/DeepSORT reid configs in a bare mmdet environment.

Common situations: Fresh mmdetection install without the optional mmpretrain dependency; version mismatch where mmpretrain import raises inside mmdet's try/except, silently becoming None.

Related errors


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