open-mmlab/mmdetection · error · RuntimeError

motmetrics is not installed, please install it by: pip insta

Error message

motmetrics is not installed, please install it by: pip install seaborn

What it means

random_color raises RuntimeError when seaborn is missing because it picks colors from sns.color_palette(). Note the message text is misleading — it says to install 'motmetrics' but the actual missing package is seaborn.

Source

Thrown at mmdet/visualization/local_visualizer.py:512

        # It is convenient for users to obtain the drawn image.
        # For example, the user wants to obtain the drawn image and
        # save it as a video during video inference.
        self.set_image(drawn_img)

        if show:
            self.show(drawn_img, win_name=name, wait_time=wait_time)

        if out_file is not None:
            mmcv.imwrite(drawn_img[..., ::-1], out_file)
        else:
            self.add_image(name, drawn_img, step)


def random_color(seed):
    """Random a color according to the input seed."""
    if sns is None:
        raise RuntimeError('motmetrics is not installed,\
                 please install it by: pip install seaborn')
    np.random.seed(seed)
    colors = sns.color_palette()
    color = colors[np.random.choice(range(len(colors)))]
    color = tuple([int(255 * c) for c in color])
    return color


@VISUALIZERS.register_module()
class TrackLocalVisualizer(Visualizer):
    """Tracking Local Visualizer for the MOT, VIS tasks.

    Args:
        name (str): Name of the instance. Defaults to 'visualizer'.
        image (np.ndarray, optional): the origin image to draw. The format
            should be RGB. Defaults to None.
        vis_backends (list, optional): Visual backend config list.
            Defaults to None.

View on GitHub (pinned to cfd5d3a985)

Solutions

  1. pip install seaborn (the message's 'pip install seaborn' is correct only at the end; motmetrics is not what's missing)
  2. If you can't install, avoid per-id colored drawing (drop the ids argument or set show=False)

Example fix

// before
visualizer.draw_datasample(img, datasample)  # RuntimeError: motmetrics is not installed
// after
# pip install seaborn
visualizer.draw_datasample(img, datasample)
Defensive patterns

Strategy: validation

Validate before calling

from mmdet.utils import matplotlib_utils  # noqa
import importlib.util
HAS_SNS = importlib.util.find_spec('seaborn') is not None
if not HAS_SNS:
    print('colored per-id drawing unavailable; install seaborn')

Try / catch

try:
    visualizer.draw_datasample(img, data_sample)
except RuntimeError as e:
    if 'seaborn' in str(e):
        pass  # degrade to no visualization

Prevention

When it happens

Trigger: Calling DetLocalVisualizer drawing paths (e.g. _draw_instances with ids, MOT/VID tracking visualization) that call random_color when sns is None.

Common situations: Visualizing tracking results with the local visualizer without installing seaborn; developers get confused because the message names the wrong package (a known copy-paste bug, motmetrics is unrelated).

Related errors


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