MMEngine
MMEngine is the foundational training engine for OpenMMLab projects, providing a comprehensive and flexible framework for deep learning training, evaluation, and deployment. It offers utilities for configuration management, logging, hooks, runners, and visualization. The current stable version is 0.10.7, with frequent patch and minor releases and active development towards 0.11.0.
Warnings
- breaking Major API refactor for OpenMMLab V1.0 projects. If migrating from older OpenMMLab frameworks (e.g., using `mmcv.runner`), significant code changes are required as MMEngine unifies the core engine components.
- gotcha MMEngine's Config system uses Python files (`.py`) for configurations, allowing for complex logic and inheritance. This differs from older YAML/JSON configurations. Misunderstanding the inheritance mechanism or how `register_module` works can lead to errors.
- gotcha Many advanced features, optimizers, and visualization backends (e.g., MLflow, TensorBoard, specific deepspeed optimizers) are optional dependencies. Attempting to use them without prior installation will result in `ImportError`.
- gotcha Starting from v0.11.0, MMEngine will default to using `opencv-python-headless` for image processing. If your workflow relies on `opencv-python` with GUI functionalities, ensure it's explicitly installed and managed.
- gotcha Versions prior to v0.11.0rc0 may encounter bugs related to config parsing when running on Python 3.12.
Install
-
pip install mmengine
Imports
- Config
from mmengine.config import Config
- Runner
from mmengine.runner import Runner
- LoggerHook
from mmengine.hooks import LoggerHook
- Visualizer
from mmengine.visualization import Visualizer
- DATASETS
from mmengine.registry import DATASETS
Quickstart
from mmengine.config import Config
# Define configuration using a dictionary
cfg_dict = dict(
model=dict(type='MyCustomModel', num_classes=10, init_cfg=None),
dataloader=dict(batch_size=32, num_workers=4),
optimizer=dict(type='Adam', lr=0.001)
)
# Create a Config object
cfg = Config(cfg_dict)
# Access configuration parameters
print(f"Model type: {cfg.model.type}")
print(f"Optimizer learning rate: {cfg.optimizer.lr}")
# You can also load from a file:
# cfg = Config.fromfile('path/to/your_config.py')