open-mmlab/mmdetection · error · RuntimeError

sscikit-learn is not installed, please insta

Error message

sscikit-learn is not installed,                 please install it by: pip install scikit-learn

What it means

KalmanFilter for SORT/DeepSORT tracking needs scipy.linalg (cho_factor/cho_solve) for Mahalanobis gating. If scipy failed to import at module load, HAS_SCIPY is False and constructing the filter raises RuntimeError. The message text mentions scikit-learn but the actual missing package is scipy.

Source

Thrown at mmdet/models/task_modules/tracking/kalman_filter.py:45

            Filter, which adaptively modulates the noise scale according to
            the quality of detections. More details in
            https://arxiv.org/abs/2202.11983. Defaults to False.
    """
    chi2inv95 = {
        1: 3.8415,
        2: 5.9915,
        3: 7.8147,
        4: 9.4877,
        5: 11.070,
        6: 12.592,
        7: 14.067,
        8: 15.507,
        9: 16.919
    }

    def __init__(self, center_only: bool = False, use_nsa: bool = False):
        if not HAS_SCIPY:
            raise RuntimeError('sscikit-learn is not installed,\
                 please install it by: pip install scikit-learn')
        self.center_only = center_only
        if self.center_only:
            self.gating_threshold = self.chi2inv95[2]
        else:
            self.gating_threshold = self.chi2inv95[4]

        self.use_nsa = use_nsa
        ndim, dt = 4, 1.

        # Create Kalman filter model matrices.
        self._motion_mat = np.eye(2 * ndim, 2 * ndim)
        for i in range(ndim):
            self._motion_mat[i, ndim + i] = dt
        self._update_mat = np.eye(ndim, 2 * ndim)

        # Motion and observation uncertainty are chosen relative to the current
        # state estimate. These weights control the amount of uncertainty in

View on GitHub (pinned to cfd5d3a985)

Solutions

  1. pip install scipy (this is the actual missing dependency)
  2. If it still fails, also install lap and motmetrics which the trackers need next
  3. Ignore the misleading 'scikit-learn' wording; verify with python -c 'import scipy'

Example fix

# before: RuntimeError: sscikit-learn is not installed
# after
pip install scipy lap motmetrics
Defensive patterns

Strategy: validation

Validate before calling

import importlib.util
assert importlib.util.find_spec('scipy') is not None, 'pip install scipy'

Try / catch

try:
    kf = KalmanFilter()
except RuntimeError as e:
    raise SystemExit('Tracking motion module needs scipy (message mentions scikit-learn but install scipy)')

Prevention

When it happens

Trigger: Building any SORT/DeepSORT/ByteSORT tracker or motion=dict(type='KalmanFilter') in an environment where scipy is not installed.

Common situations: Minimal mmdetection install used for image detection, then a tracking config (sort_tracker, strongsort) is run; confusingly the error suggests installing scikit-learn, which does not fix it.

Related errors


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