MMSegmentation
raw JSON → 1.2.2 verified Fri May 01 auth: no python
MMSegmentation is an open-source semantic segmentation toolbox based on PyTorch, part of the OpenMMLab project. It provides a unified framework for training, testing, and deploying segmentation models, supporting a wide range of architectures (e.g., DeepLabV3+, PSPNet, U-Net) and datasets. Current version is 1.2.2 (Dec 2023), with a major v1.0.0 release marking a structural overhaul from v0.x. Release cadence is irregular, with minor patches every few months.
pip install mmsegmentation==1.2.2 Common errors
error ModuleNotFoundError: No module named 'mmcv' ↓
cause MMSegmentation requires mmcv (OpenMMLab Computer Vision) as a dependency. It is not installed automatically with pip install mmsegmentation.
fix
Install a compatible version: pip install mmcv>=2.0.0,<2.2.0
error AttributeError: module 'mmseg' has no attribute 'init_model' ↓
cause Incorrect import path; init_model is in mmseg.apis, not mmseg directly.
fix
Use: from mmseg.apis import init_model
error FileNotFoundError: config file not found ↓
cause MMSegmentation expects config files in a specific format and path. Using a relative path without proper resolution causes failure.
fix
Use mmengine's Config API: from mmengine.config import Config; cfg = Config.fromfile('path/to/config.py')
Warnings
breaking MMSegmentation v1.0.0 is a major rewrite from v0.x. Configs, APIs, and model definitions are not backward-compatible. Do not mix mmseg v1.x with mmcv<2.0.0. ↓
fix Migrate configs to the new format using mmseg's migration tools or rewrite for v1.x. Use mmcv>=2.0.0.
gotcha The 'inference_model' and 'init_model' functions are imported from 'mmseg.apis', not 'mmseg.models' or 'mmseg.core'. Common mistake leads to ImportError. ↓
fix Use 'from mmseg.apis import init_model, inference_model'.
deprecated The 'mmseg.core' module is deprecated in v1.x. Functions like 'inference' and 'segmentation' were moved to mmseg.apis. ↓
fix Update imports to use mmseg.apis instead of mmseg.core.
gotcha When using custom datasets, the class palette must be defined correctly in the config. Missing or misordered palette can cause silent mislabeling. ↓
fix Always define 'palette' in the dataset config and ensure it matches the order of classes in 'classes'.
Imports
- MMSegInferencer
from mmseg.apis import MMSegInferencer - init_model wrong
from mmseg.models import init_modelcorrectfrom mmseg.apis import init_model - inference_model wrong
from mmseg.core import inferencecorrectfrom mmseg.apis import inference_model
Quickstart
from mmseg.apis import MMSegInferencer
import os
# Initialize the inferencer with a pretrained model
inferencer = MMSegInferencer(
model='deeplabv3plus_r18-d8_4xb2-80k_cityscapes-512x1024',
device='cuda' if os.environ.get('CUDA_VISIBLE_DEVICES') else 'cpu'
)
# Run inference on an image
result = inferencer('demo/demo.png')
print(result['predictions'].shape)