MMCV: OpenMMLab Computer Vision Foundation

2.2.0 · active · verified Thu Apr 16

MMCV (OpenMMLab Computer Vision Foundation) is a foundational library for computer vision research and development, providing a comprehensive set of building blocks including rich data augmentation and transformation operations, various deep learning utilities, and support for hardware-specific optimizations. It is a core component of the OpenMMLab ecosystem. The current version is 2.2.0, with frequent releases to add features, bug fixes, and support for new PyTorch versions and hardware platforms.

Common errors

Warnings

Install

Imports

Quickstart

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}")

view raw JSON →