一、简介
参考:https://blog.youkuaiyun.com/Adam897/article/details/127534510
MMDetection是MMLab家族的一员,是由香港中文大学和商汤科技共同推出的,以一个统一的架构支撑了15个大方向的研究领域。MMDetection依赖Pytorch和MMCV,因此安装之前需要先安装这两个库。MMCV有两mmcv-full和mmcv两个版本,两者差别在于是否包含CUDA操作,如果不需要使用CUDA可以安装mmcv,不过官方还是推荐安装完整版的mmcv-full。还有MMDetection3D,后续使用到再做研究。
二、安装
参考:https://blog.youkuaiyun.com/ArthurHai521/article/details/138356084
1、在线安装
pip install mmcv
pip install mmdet
2、离线安装
git clone https://github.com/open-mmlab/mmdetection.git
cd mmdetection
pip install -v -e .
去官网指定下载地址https://download.openmmlab.com/mmcv/dist/cu118/torch2.1/index.html下载对应版本mmcv:
mmcv-2.1.0-cp310-cp310-manylinux1_x86_64.whl
安装:pip install mmcv-2.1.0-cp310-cp310-manylinux1_x86_64.whl
验证是否安装成功
// An highlighted block
import os
from mmdet.apis import init_detector, inference_detector
def demo_mmdet():
base_dir = r'D:\Program Files\Third_Part_Lib\mmdetection' # mmdetection的安装目录
config_file = os.path.join(base_dir, r'configs\faster_rcnn\faster_rcnn_r50_fpn_1x_coco.py')
# download the checkpoint from model zoo and put it in `checkpoints/`
# url: https://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 = r'checkpoints\faster_rcnn_r50_fpn_1x_coco_20200130-047c8118.pth'
# 根据配置文件和 checkpoint 文件构建模型
model = init_detector(config_file, checkpoint_file, device='cuda:0')
# 测试单张图片并展示结果
img = os.path.join(base_dir, r'demo\demo.jpg') # 或者 img = mmcv.imread(img),这样图片仅会被读一次
result = inference_detector(model, img)
# 在一个新的窗口中将结果可视化
model.show_result(img, result, out_file=None, show=True) ##有的版本可能报错没有show_result,就使用https://blog.youkuaiyun.com/csy1021/article/details/132080887方法
if __name__ == '__main__':
demo_mmdet()
三、使用
1、添加自定义模型
https://blog.youkuaiyun.com/qq_41627642/article/details/124754147