MMEngine

MMEngine by OpenMMLab is a foundational library for training deep learning models based on PyTorch. MMEngine implements a next-generation training architecture for the OpenMMLab algorithm library, providing a unified execution foundation for over 30 algorithm libraries within OpenMMLab. Its core components include the training engine, evaluation engine, and module management.

Weights and Biases is directly integrated into MMEngine through a dedicated WandbVisBackend that can be used to

  • log training and evaluation metrics.
  • log and manage experiment configs.
  • log additional records such as graph, images, scalars, etc.

Get started

Install openmim and wandb.

pip install -q -U openmim wandb
!pip install -q -U openmim wandb

Next, install mmengine and mmcv using mim.

mim install -q mmengine mmcv
!mim install -q mmengine mmcv

Use the WandbVisBackend with MMEngine Runner

This section demonstrates a typical workflow using WandbVisBackend using mmengine.runner.Runner.

  1. Define a visualizer from a visualization config.

    from mmengine.visualization import Visualizer
    
    # define the visualization configs
    visualization_cfg = dict(
        name="wandb_visualizer",
        vis_backends=[
            dict(
                type='WandbVisBackend',
                init_kwargs=dict(project="mmengine"),
            )
        ],
        save_dir="runs/wandb"
    )
    
    # get the visualizer from the visualization configs
    visualizer = Visualizer.get_instance(**visualization_cfg)
    

  1. Initialize a runner with the visualizer, and call runner.train().

    from mmengine.runner import Runner
    
    # build the mmengine Runner which is a training helper for PyTorch
    runner = Runner(
        model,
        work_dir='runs/gan/',
        train_dataloader=train_dataloader,
        train_cfg=train_cfg,
        optim_wrapper=opt_wrapper_dict,
        visualizer=visualizer, # pass the visualizer
    )
    
    # start training
    runner.train()
    

Use the WandbVisBackend with OpenMMLab computer vision libraries

The WandbVisBackend can also be used easily to track experiments with OpenMMLab computer vision libraries such as MMDetection.

# inherit base configs from the default runtime configs
_base_ = ["../_base_/default_runtime.py"]

# Assign the `WandbVisBackend` config dictionary to the
# `vis_backends` of the `visualizer` from the base configs
_base_.visualizer.vis_backends = [
    dict(
        type='WandbVisBackend',
        init_kwargs={
            'project': 'mmdet',
            'entity': 'geekyrakshit'
        },
    ),
]

Last modified January 29, 2025: 8607c88