Install & Compatibility
Where this runs
tested against v2.2.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
py 3.10
✕ dependency_conflict
2/4 runs
py 3.11
✕ dependency_conflict
2/4 runs
py 3.12
✕ dependency_conflict
✕ dependency_conflict
py 3.13
✕ dependency_conflict
✕ dependency_conflict
py 3.9
✕ dependency_conflict
2/4 runs
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
Config
✓ from mmcv import Config
While mmengine.Config is also commonly used in MMEngine-based projects, mmcv.Config remains for general configuration parsing.
Runner
✓ from mmengine.runner import Runner
✗ from mmcv.runner import Runner
As of v2.0.0, training-related modules like Runner, Hook, and Parallel moved from MMCV to MMEngine.
build_from_cfg
✓ from mmcv.registry import build_from_cfg
✗ from mmcv.cnn import build_from_cfg
The import path for build_from_cfg changed in v2.x to mmcv.registry.
Compose
✓ from mmcv.transforms import Compose
✗ from mmcv.datasets.pipelines import Compose
Data augmentation and transformation pipelines moved to mmcv.transforms in v2.x.
This quickstart demonstrates loading a configuration using `mmcv.Config` and applying basic image transformations with `mmcv.transforms.Compose` and `Resize`/`RandomFlip`. It showcases the core utilities of MMCV for managing configurations and data pipelines, essential for computer vision tasks.
from mmcv import Config
from mmcv.transforms import Compose, Resize, RandomFlip
import numpy as np
# 1. Load a config (can be a dummy dict or a path to a .py config file)
cfg_dict = dict(
model=dict(
type='ResNet',
depth=50,
num_classes=1000
),
data=dict(
train_pipeline=[
dict(type='Resize', scale=(224, 224)),
dict(type='RandomFlip', prob=0.5)
]
)
)
cfg = Config(cfg_dict)
print(f"Loaded config model type: {cfg.model.type}")
# 2. Use data transforms
pipeline = Compose([
Resize(scale=(256, 256)),
RandomFlip(prob=0.5)
])
# Dummy image data
dummy_img = np.random.rand(512, 512, 3).astype(np.uint8)
data_sample = dict(img=dummy_img, img_shape=dummy_img.shape[:2], ori_shape=dummy_img.shape[:2])
transformed_data = pipeline(data_sample)
print(f"Original image shape: {data_sample['img'].shape}")
print(f"Transformed image shape: {transformed_data['img'].shape}")
Debug
Known issues
breakingMMCV v2.0.0 introduced significant breaking changes by moving training-related modules (like `Runner`, `Hook`, `Optimizer`) to a new library, `MMEngine`. Direct imports from `mmcv.runner` or similar paths will fail.fixUpdate imports to use `mmengine` for these modules (e.g., `from mmengine.runner import Runner`). Ensure `mmengine` is installed alongside `mmcv`.
affects: >=2.0.0
gotchaInstalling `mmcv-full` (the version with CUDA/hardware extensions) via `pip install mmcv-full` can be problematic and may result in a CPU-only build or version mismatches. The `mim` tool is highly recommended for managing `mmcv-full` installations.fixFirst, install `openmim` (`pip install -U openmim`), then use `mim install mmcv-full`. Refer to the official installation guide for specific PyTorch and CUDA version compatibility.
affects: All versions with CUDA extensions
gotchaMMCV-full has strict compatibility requirements with PyTorch and CUDA versions. Mismatched versions can lead to runtime errors (e.g., CUDA kernel errors) or unexpected behavior.fixAlways check the official MMCV installation guide for the exact PyTorch and CUDA versions supported by your chosen `mmcv-full` version. Use `mim install mmcv-full` to leverage OpenMMLab's pre-built packages which handle compatibility.
affects: All versions requiring CUDA/hardware extensions
breakingThe paths for data transformation pipelines and utilities (e.g., `Compose`) changed in v2.x. Old imports like `from mmcv.datasets.pipelines import Compose` are no longer correct.fixUpdate import paths to `from mmcv.transforms import Compose` and similarly for other transformation components.
affects: >=2.0.0
Upgrade
Version history
2.2.0latest on PyPI · released Apr 24, 2024
Audit
Dependencies
torchrequiredCore deep learning framework dependency for models and operations.
mmenginerequiredSince v2.0.0, core training components like Runner, Hook, and optimizers are provided by MMEngine.