# MMDetection

**MMDetection** 是 [OpenMMLab](https://www.edgepedia.org/zh/openmmlab) 团队基于 PyTorch 构建的开源目标检测工具箱与基准测试平台。它提供训练与推理代码、预训练权重，以及用于目标检测、[实例分割](https://www.edgepedia.org/zh/instance-segmentation)和全景分割的模块化组件，其源头是赢得 2018 年 COCO 挑战赛检测赛道的 MMDet 团队的代码库。<sup>[1](https://arxiv.org/abs/1906.07155)</sup> 该项目以 [Apache License](https://www.edgepedia.org/zh/apache-license) 2.0 发布，并以 `mmdet` 包的形式在 PyPI 上分发。<sup>[2](https://pypi.org/project/mmdet/)</sup>

| 关键事实 | 详情 |
|---|---|
| 起源 | 始于赢得 COCO 挑战赛 2018 检测赛道的 MMDet 团队代码库；在 2019 年技术报告《MMDetection: Open MMLab Detection Toolbox and Benchmark》中介绍<sup>[1](https://arxiv.org/abs/1906.07155)</sup> |
| 覆盖任务 | 目标检测、实例分割和全景分割，另有旋转检测、蒸馏和半监督检测<sup>[3](https://github.com/open-mmlab/mmdetection/blob/main/README.md?plain=1)</sup> |
| 环境要求 | Linux、Windows 和 macOS；Python 3.7+、CUDA 9.2+ 和 PyTorch 1.8+<sup>[4](https://github.com/open-mmlab/mmdetection/blob/main/docs/en/get_started.md)</sup> |
| 依赖 | 训练运行器与配置系统依赖 MMEngine，计算机视觉算子依赖 MMCV（2.x 版本）<sup>[5](https://github.com/open-mmlab/mmdetection/blob/main/docs/en/user_guides/config.md)</sup><sup> • </sup><sup>[4](https://github.com/open-mmlab/mmdetection/blob/main/docs/en/get_started.md)</sup> |
| 版本发布 | 3.0.0 版于 2023 年 4 月 6 日发布；3.3.0 版于 2024 年 1 月 5 日发布，为 PyPI 最新版本<sup>[2](https://pypi.org/project/mmdet/)</sup> |
| PyTorch 2.0 | 自 3.0.0rc7 起，绝大多数算法支持 PyTorch 2.0 和 `torch.compile`，通过 `--cfg-options compile=True` 启用<sup>[6](https://github.com/open-mmlab/mmdetection/blob/main/docs/en/notes/faq.md)</sup> |
| 生态角色 | 是 MMDetection3D、MMTracking 等其他 OpenMMLab 工具箱的基础<sup>[7](https://www.youtube.com/watch?v=qmmlRUMbb9M)</sup> |

## 范围与模型库

MMDetection 覆盖三大视觉任务。目标检测用边界框定位并分类物体；实例分割额外预测每个物体实例的精确像素边界；全景分割将实例分割与背景“物质”及可数“物体”的语义分割统一起来。<sup>[3](https://github.com/open-mmlab/mmdetection/blob/main/README.md?plain=1)</sup>

模型库纵贯该领域的历史。检测模型包括 Faster R-CNN（NeurIPS 2015）、SSD（ECCV 2016）、[RetinaNet](https://www.edgepedia.org/zh/retinanet)（ICCV 2017）、Cascade R-CNN（CVPR 2018）、YOLOv3、FCOS、ATSS、DETR 系列（DETR、Deformable DETR、DAB-DETR、DINO）、YOLOX、RTMDet、GLIP、DDQ 和 CO-DETR。实例分割模型包括 [Mask R-CNN](https://www.edgepedia.org/zh/mask-r-cnn)、Hybrid Task Cascade、YOLACT、SOLO 与 SOLOv2、PointRend、QueryInst 和 Mask2Former。全景分割由 Panoptic FPN、MaskFormer、Mask2Former 和 XDecoder 覆盖。代码库还附带各类组件，如骨干网络（ResNet、Swin、ConvNeXt、PVT）、颈部（FPN 变体、DyHead）、损失函数（Generalized Focal Loss、Seesaw Loss），以及蒸馏和基于 Soft Teacher 的半监督目标检测等训练技术。<sup>[3](https://github.com/open-mmlab/mmdetection/blob/main/README.md?plain=1)</sup> 2019 年的原始报告已提供 200 多个网络模型的权重。<sup>[1](https://arxiv.org/abs/1906.07155)</sup>

旋转目标检测通过 Rotated RetinaNet、Rotated FCOS 和 Oriented RepPoints 等模型支持，面向地理空间分析和文档处理。<sup>[8](https://mmdetection.com/which-detection-algorithms-are-implemented-in-mmdetection/)</sup>

## 架构与配置

MMDetection 采用模块化设计，检测器的每个功能部件都通过配置文件进行配置。模型配置指定检测器类型，以及 `data_preprocessor`、`backbone` 和 `neck` 等神经网络组件，还有存放训练与测试超参数的 `train_cfg` 和 `test_cfg` 部分。数据集、数据加载器和评估器设置、训练循环以及优化封装是独立的配置字段。配置遵循 MMEngine 的模块化、基于继承的配置系统，为各 OpenMMLab 代码库共用。<sup>[5](https://github.com/open-mmlab/mmdetection/blob/main/docs/en/user_guides/config.md)</sup>

配置文件名以固定风格编码完整配方，例如 `算法名_组件名_训练设置_数据集`。训练设置部分记录 GPU 数量和批大小（如 `8xb2`）、数据增强、损失技巧、调度器和调度长度，其中 `1x` 和 `2x` 分别表示 12 和 24 个 epoch，学习率在固定 epoch 处衰减为原来的十分之一。<sup>[5](https://github.com/open-mmlab/mmdetection/blob/main/docs/en/user_guides/config.md)</sup>

训练通过 `tools/train.py` 运行，它将日志和检查点保存到由 `work_dir` 或 `--work-dir` 设定的工作目录，按可配置的间隔在验证集上评估，并支持从最新或指定检查点恢复训练。配置文件中的默认学习率假定批大小为 16（8 块 GPU，每块 2 个样本），可通过 `auto_scale_lr` 设置启用相对于该基线的学习率自动缩放，默认关闭。<sup>[9](https://github.com/open-mmlab/mmdetection/blob/main/docs/en/user_guides/train.md)</sup>

自定义数据集有三种支持方式：将标注整理为 COCO 格式、整理为中间格式，或实现新的数据集类；推荐 COCO 方式，因其最为简便。自 MMDetection 3.0 起，数据集与指标解耦（CityScapes 除外），因此任何受支持的指标都可评估任何数据集格式，例如用 VOC 指标评估 COCO 数据。<sup>[9](https://github.com/open-mmlab/mmdetection/blob/main/docs/en/user_guides/train.md)</sup>

## 推理

高层推理接口是 `DetInferencer`，它统一了各 OpenMMLab 库的推理操作。模型由配置文件加检查点文件定义；传入预训练模型名称会自动从 OpenMMLab 模型库下载权重，也可改为提供自定义配置和权重路径。推理器接受图像路径或 URL、BGR numpy 数组、此类输入的列表，或图像目录，返回一个字典，其中 `predictions` 为 JSON 可序列化形式，按需还包含 `visualization` 图像；结果也可转储到输出目录。推理设备可显式选择，例如 `cuda:1` 或 `cpu`。<sup>[10](https://github.com/open-mmlab/mmdetection/blob/main/docs/en/user_guides/inference.md)</sup>

## 安装与版本兼容性

推荐的安装方式使用 OpenMMLab 的包管理器 MIM，先安装 MMEngine 和 MMCV，再安装 MMDetection 本身，既可为了开发从源码以可编辑模式安装，也可通过 `mim install mmdet` 作为依赖安装。<sup>[4](https://github.com/open-mmlab/mmdetection/blob/main/docs/en/get_started.md)</sup> 版本匹配很重要：每个 MMDetection 发行版对应特定的 MMCV 范围，例如 MMDetection 3.3.0 要求 `mmcv>=2.0.0, <2.2.0` 和 `mmengine>=0.7.1, <1.0.0`，而在 MMCV 2.x 中，原 `mmcv-full` 包更名为 `mmcv`，`mmcv-lite` 提供不含 CUDA 算子的构建。<sup>[6](https://github.com/open-mmlab/mmdetection/blob/main/docs/en/notes/faq.md)</sup>

文档记录的环境陷阱包括：MMCV/MMDetection 版本不匹配；安装 lite 构建时缺少 `mmcv.ops` 或 `mmcv._ext` 模块；Windows 版 pycocotools 需要 [Microsoft Visual C++](https://www.edgepedia.org/zh/microsoft-visual-c) 生成工具；RTX 30 系列显卡在 CUDA 工具包 11.0 下无法构建 MMCV，因为该工具包不支持 sm_86 架构；文档给出的变通办法是改为针对架构相似的 sm_80（A100）编译。<sup>[6](https://github.com/open-mmlab/mmdetection/blob/main/docs/en/notes/faq.md)</sup>

## 在研究与基准测试中的使用

MMDetection 被广泛用作检测实验的参考实现。针对自然分布偏移下目标检测器的 COCO-O 基准测试，在一致的训练配置下用 mmdetection 实现了其全部实验，以保证公平比较。<sup>[11](https://openaccess.thecvf.com/content/ICCV2023/papers/Mao_COCO-O_A_Benchmark_for_Object_Detectors_under_Natural_Distribution_Shifts_ICCV_2023_paper.pdf)</sup> 一项 2024 年对实时检测器（DETR、RTMDet、ViTDet 和 YOLOv7，基于 MS COCO 2017）的复现研究，基于 MMDetection 的特性构建了统一的训练与评估流水线；研究发现，复现的 RTMDet 和 YOLOv7 能达到原论文声称的精度和速度，而其 DETR 和 ViTDet 复现则不能，且 MMDetection 预训练模型在有限计算资源上速度严重下降。<sup>[12](https://arxiv.org/abs/2405.06911)</sup> 领域特定的基准测试，如用于机器人拾取的水下目标检测数据集和 X 射线安检成像数据集，也用该框架实现了其检测模型。<sup>[13](https://arxiv.org/abs/2106.05681)</sup><sup> • </sup><sup>[14](https://www.nature.com/articles/s41597-026-07263-7)</sup>

该工具箱还是其他 OpenMMLab 项目的基础，包括用于三维检测的 MMDetection3D 和用于视频感知的 MMTracking，其检测器已通过 Lagent 框架接入基于大语言模型的智能体。<sup>[7](https://www.youtube.com/watch?v=qmmlRUMbb9M)</sup>

## References

1. [Kai Chen et al. (2019). MMDetection: Open MMLab Detection Toolbox and Benchmark. arXiv:1906.07155.](https://arxiv.org/abs/1906.07155)
2. [mmdet · PyPI](https://pypi.org/project/mmdet/)
3. [MMDetection README, open-mmlab/mmdetection, GitHub](https://github.com/open-mmlab/mmdetection/blob/main/README.md?plain=1)
4. [Get Started, MMDetection documentation](https://github.com/open-mmlab/mmdetection/blob/main/docs/en/get_started.md)
5. [Learn about Configs, MMDetection documentation](https://github.com/open-mmlab/mmdetection/blob/main/docs/en/user_guides/config.md)
6. [Frequently Asked Questions, MMDetection documentation](https://github.com/open-mmlab/mmdetection/blob/main/docs/en/notes/faq.md)
7. [General Object Detection with MMDetection 3.0, OpenMMLab tutorial](https://www.youtube.com/watch?v=qmmlRUMbb9M)
8. [Which detection algorithms are implemented in MMDetection?](https://mmdetection.com/which-detection-algorithms-are-implemented-in-mmdetection/)
9. [Train predefined models, MMDetection documentation](https://github.com/open-mmlab/mmdetection/blob/main/docs/en/user_guides/train.md)
10. [Inference with existing models, MMDetection documentation](https://github.com/open-mmlab/mmdetection/blob/main/docs/en/user_guides/inference.md)
11. [COCO-O: A Benchmark for Object Detectors under Natural Distribution Shifts, ICCV 2023](https://openaccess.thecvf.com/content/ICCV2023/papers/Mao_COCO-O_A_Benchmark_for_Object_Detectors_under_Natural_Distribution_Shifts_ICCV_2023_paper.pdf)
12. [Asselin et al. (2024). Replication Study and Benchmarking of Real-Time Object Detection Models. arXiv:2405.06911.](https://arxiv.org/abs/2405.06911)
13. [Liu et al. (2021). A Dataset and Benchmark of Underwater Object Detection for Robot Picking. arXiv:2106.05681.](https://arxiv.org/abs/2106.05681)
14. [A Benchmark Dataset for Concealed Improvised Explosive Device Detection in X-ray Security Imaging, Scientific Data](https://www.nature.com/articles/s41597-026-07263-7)

---
*Initially written Oct 15, 2026*

Topic: 技术与人造世界 › 计算技术与数字系统 › 人工智能与数据 › Language and vision AI › Computer vision › Vision datasets, software, and community › CV software and toolkits

Copyright 2026 Edgepedia

License: Edgepedia Community License 1.0, https://www.edgepedia.org/edgepedia/license

Source: https://www.edgepedia.org/zh/mmdetection

English original: https://www.edgepedia.org/mmdetection
