Skip to main content

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.

Getting startedโ€‹

First, you need to install openmim and wandb. You can then proceed to install mmengine and mmcv using openmim.

pip install -q -U openmim wandb
mim install -q mmengine mmcv

Using the WandbVisBackend with MMEngine Runnerโ€‹

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

First, you need to 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)
info

You pass a dictionary of arguments for W&B run initialization input parameters to init_kwargs.

Next, you simply 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()
An example of your experiment tracked using the WandbVisBackend
An example of your experiment tracked using the WandbVisBackend.

Using 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'
},
),
]
Was this page helpful?๐Ÿ‘๐Ÿ‘Ž