{"id":9122,"library":"mmcv","title":"MMCV: OpenMMLab Computer Vision Foundation","description":"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.","status":"active","version":"2.2.0","language":"en","source_language":"en","source_url":"https://github.com/open-mmlab/mmcv","tags":["computer-vision","deep-learning","pytorch","openmmlab","data-augmentation","utilities"],"install":[{"cmd":"pip install -U openmim\nmim install mmcv-full","lang":"bash","label":"Recommended (with CUDA/hardware extensions)"},{"cmd":"pip install mmcv","lang":"bash","label":"Basic version (without CUDA/hardware extensions)"}],"dependencies":[{"reason":"Core deep learning framework dependency for models and operations.","package":"torch","optional":false},{"reason":"Since v2.0.0, core training components like Runner, Hook, and optimizers are provided by MMEngine.","package":"mmengine","optional":false}],"imports":[{"note":"While mmengine.Config is also commonly used in MMEngine-based projects, mmcv.Config remains for general configuration parsing.","symbol":"Config","correct":"from mmcv import Config"},{"note":"As of v2.0.0, training-related modules like Runner, Hook, and Parallel moved from MMCV to MMEngine.","wrong":"from mmcv.runner import Runner","symbol":"Runner","correct":"from mmengine.runner import Runner"},{"note":"The import path for build_from_cfg changed in v2.x to mmcv.registry.","wrong":"from mmcv.cnn import build_from_cfg","symbol":"build_from_cfg","correct":"from mmcv.registry import build_from_cfg"},{"note":"Data augmentation and transformation pipelines moved to mmcv.transforms in v2.x.","wrong":"from mmcv.datasets.pipelines import Compose","symbol":"Compose","correct":"from mmcv.transforms import Compose"}],"quickstart":{"code":"from mmcv import Config\nfrom mmcv.transforms import Compose, Resize, RandomFlip\nimport numpy as np\n\n# 1. Load a config (can be a dummy dict or a path to a .py config file)\ncfg_dict = dict(\n    model=dict(\n        type='ResNet',\n        depth=50,\n        num_classes=1000\n    ),\n    data=dict(\n        train_pipeline=[\n            dict(type='Resize', scale=(224, 224)),\n            dict(type='RandomFlip', prob=0.5)\n        ]\n    )\n)\ncfg = Config(cfg_dict)\nprint(f\"Loaded config model type: {cfg.model.type}\")\n\n# 2. Use data transforms\npipeline = Compose([\n    Resize(scale=(256, 256)),\n    RandomFlip(prob=0.5)\n])\n\n# Dummy image data\ndummy_img = np.random.rand(512, 512, 3).astype(np.uint8)\ndata_sample = dict(img=dummy_img, img_shape=dummy_img.shape[:2], ori_shape=dummy_img.shape[:2])\n\ntransformed_data = pipeline(data_sample)\nprint(f\"Original image shape: {data_sample['img'].shape}\")\nprint(f\"Transformed image shape: {transformed_data['img'].shape}\")","lang":"python","description":"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."},"warnings":[{"fix":"Update imports to use `mmengine` for these modules (e.g., `from mmengine.runner import Runner`). Ensure `mmengine` is installed alongside `mmcv`.","message":"MMCV 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.","severity":"breaking","affected_versions":">=2.0.0"},{"fix":"First, 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.","message":"Installing `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.","severity":"gotcha","affected_versions":"All versions with CUDA extensions"},{"fix":"Always 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.","message":"MMCV-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.","severity":"gotcha","affected_versions":"All versions requiring CUDA/hardware extensions"},{"fix":"Update import paths to `from mmcv.transforms import Compose` and similarly for other transformation components.","message":"The 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.","severity":"breaking","affected_versions":">=2.0.0"}],"env_vars":null,"last_verified":"2026-04-16T00:00:00.000Z","next_check":"2026-07-15T00:00:00.000Z","problems":[{"fix":"Change the import statement to `from mmengine.runner import Runner`. Ensure `mmengine` is installed.","cause":"Attempting to import training-related modules (like Runner) from MMCV in versions >= 2.0.0, where they have been moved to the MMEngine library.","error":"ModuleNotFoundError: No module named 'mmcv.runner'"},{"fix":"Uninstall any existing `mmcv` and `mmcv-full`. Install `openmim` (`pip install -U openmim`) and then use `mim install mmcv-full` after carefully checking PyTorch and CUDA compatibility in the official documentation.","cause":"This typically means `mmcv-full` was installed incorrectly, or the installed `mmcv-full` version's CUDA extensions do not match your current PyTorch or NVIDIA driver/CUDA toolkit environment.","error":"RuntimeError: CUDA error: no kernel image is available for execution on the device"},{"fix":"Update the import statement to `from mmcv.registry import build_from_cfg`.","cause":"The utility function `build_from_cfg` was moved to a different module path in MMCV v2.x.","error":"ImportError: cannot import name 'build_from_cfg' from 'mmcv.cnn'"}]}