Comprehensive Guide to MMDetection Framework Installation and Usage

Introduction to MMDetection

MMDetection is an open-source object detection toolbox developed by SenseTime and The Chinese University of Hong Kong. Built on PyTorch, it implements a wide array of object detection algorithms, encapsulating dataset construction, model architecture, and training strategies into modular components. This modular design enables developers to implement new algorithms with minimal code, significantly improving code reusability. The OpenMMLab ecosystem includes specialized frameworks like MMTracking for object tracking and MMDetection3D for 3D object detection, all built upon PyTorch and MMCV. While PyTorch needs no introduction, MMCV serves as a fundamental computer vision library that provides: - A universal training framework for PyTorch - Registry, Runner, and Hook functionalities - Common I/O interfaces - Various CNN architectures - High-performance CUDA operator implementations Installation Process

Setting Up PyTorch Environment

First, install PyTorch and torchvision according to your system specifications and CUDA version compatibility. ### Installing MMEngine and MMCV

  1. Install OpenMIM for managing OpenMMLab packages: ``` pip install -U openmim
  2. Install MMEngine: ``` mim install mmengine
    
    For environments with specific requirements, you may need to install dependencies first: ```
    pip install --upgrade setuptools
    pip install numpy
    pip install scikit-build
    mim install mmengine
    
  3. Install MMCV (version 2.0.0 or higher): ``` pip install "mmcv>=2.0.0" -f https://download.openmmlab.com/mmcv/dist/{cu_version}/{torch_version}/index.html
    
    Verify installations with: ```
    pip list | grep -E "(mmcv|mmengine)"
    

Installing MMDetection

Clone the repository and install in development mode: ``` git clone https://github.com/open-mmlab/mmdetection.git cd mmdetection pip install -v -e .


The `-e` flag anables editable installation, allowing local code changes to take effect immediately without reinstallation. Usage Examples
--------------

### Verifying Installation

Download a pre-trained model to test the installation: ```
mim download mmdet --config rtmdet_tiny_8xb32-300e_coco --dest .

Run the demo script with the downloaded files: ``` python demo/image_demo.py
demo/demo.jpg
rtmdet_tiny_8xb32-300e_coco.py
--weights rtmdet_tiny_8xb32-300e_coco_20220902_112414-78e30dcc.pth
--show


Successful execution will display the image with detected objects. ### Training on COCO Dataset

#### Configuration Setup

Select a model configuration, for example: ```
configs/faster_rcnn/faster-rcnn_r50_fpn_1x_coco.py

When you first run training, MMDetection will create a working directory with the complete configuration file, allowing easy customization. #### Dataset Preparation

Download the COCO dataset (recommended: COCO2017) and place it in the project's data directory: ``` data/ ├── coco/ │ ├── annotations/ │ │ ├── instances_train2017.json │ │ └── instances_val2017.json │ ├── images/ │ │ ├── train2017/ │ │ └── val2017/


For custom datasets, ensure they follow the COCO format specification as documented in the official MMDetection guidelines. #### Training Execution

Initiate training with: ```
python tools/train.py configs/faster_rcnn/faster-rcnn_r50_fpn_1x_coco.py

The training process will display progress including: - System environment details - Model configuration - Training epochs with loss metrics - Validation results with mAP scores ### Model Evaluation

After training, evaluate the model using: ``` python tools/test.py
work_dirs/faster-rcnn_r50_fpn_1x_coco/faster-rcnn_r50_fpn_1x_coco.py
work_dirs/faster-rcnn_r50_fpn_1x_coco/latest.pth
--show-dir results


This will generate visualization results in the specified output directory. ### Example Training Output

During training, you'll see detailed logs including: ```
Epoch(train) [1][100/500]  lr: 0.0070  eta: 0:12:34  time: 0.2345  data_time: 0.0123
loss: 0.5678  loss_rpn_cls: 0.1234  loss_rpn_bbox: 0.0987  loss_cls: 0.2101  loss_bbox: 0.1356
acc: 87.5  memory: 7543MB

Validation metrics will appear as: ``` Average Precision (AP) @[ IoU=0.50:0.95 | area=all | maxDets=100] = 0.376 Average Precision (AP) @[ IoU=0.50 | area=all | maxDets=1000] = 0.582 Average Precision (AP) @[ IoU=0.75 | area=all | maxDets=1000] = 0.403


Advanced Configuration
----------------------

Modify the training process by adjusting parameters in the config file: - `model`: Define architecture components - `data\_root`: Set dataset path - `train\_dataloader`: Configure batch size and workers - `optim\_wrapper`: Adjust learning rate and optimizer settings - `train\_cfg`: Set training epochs and validation interval Example modification for custom dataset: ```
dataset_type = 'CustomDataset'
data_root = 'data/custom/'
train_dataloader = dict(
    batch_size=4,
    num_workers=4,
    dataset=dict(
        type='CustomDataset',
        data_root='data/custom/',
        ann_file='annotations/train.json',
        data_prefix=dict(img='images/')
    )
)

Tags: object-detection pytorch mmdetection computer-vision deep-learning

Posted on Thu, 13 Aug 2026 16:22:34 +0000 by Lauj