https://mmdetection.readthedocs.io/zh_CN/latest/
https://github.com/open-mmlab/mmdetection
1、创建虚拟环境

2、激活虚拟环境
conda activate open-mmlab

3、安装cython

4、基于Pytorch官网安装 PyTorch 和 torchvision

5、根据cuda与torch版本安装mmcv

6、安装mmdet

7、各包版本

8、测试
在demo文件夹下新建test.py文件

from mmdet.apis import init_detector, inference_detector
config_file = '../configs/faster_rcnn/faster_rcnn_r50_fpn_1x_coco.py'
# 从 model zoo 下载 checkpoint 并放在 `checkpoints/` 文件下
# 网址为: http://download.openmmlab.com/mmdetection/v2.0/faster_rcnn/faster_rcnn_r50_fpn_1x_coco/faster_rcnn_r50_fpn_1x_coco_20200130-047c8118.pth
checkpoint_file = '../checkpoints/faster_rcnn_r50_fpn_1x_coco_20200130-047c8118.pth'
device = 'cuda:0'
# 初始化检测器
model = init_detector(config_file, checkpoint_file, device=device)
# 推理演示图像
inference_detector(model, 'demo.jpg')
出现报错

打开configs/base/models
打开faster_rcnn_r50_fpn.py


如上修改后运行成功

本文详细介绍了如何利用MMDetection构建目标检测模型。首先创建并激活虚拟环境,接着安装必要的依赖,包括Cython、PyTorch和torchvision。然后,根据CUDA和PyTorch版本安装mmcv,再安装mmdet。配置文件和预训练模型下载后,通过init_detector和inference_detector进行模型初始化和推理。经过错误排查和代码调整,最终成功运行并进行了测试。
354





