MMDetection官方使用说明https://mmdetection.readthedocs.io/zh-cn/latest/get_started.html
1.基础环境
操作系统:Ubuntu 22.10
显卡:RTX 3080
我安装的是Python=3.8 cuda=11.7 pytorch=1.13.0 mmcv=2.0.0 mmdetection=3.0.0
2.环境搭建
先创建一个虚拟环境
conda create --name mmdetection python=3.8 -y
激活该环境
conda activate mmdetection
安装pytorch,官网地址https://pytorch.org/get-started/previous-versions/ pytorch版本需与安装的cuda版本对应
conda install pytorch==1.13.0 torchvision==0.14.0 torchaudio==0.13.0 pytorch-cuda=11.7 -c pytorch -c nvidia
上述代码安装失败换用以下代码:
pip install torch==1.13.0+cu117 torchvision==0.14.0+cu117 torchaudio==0.13.0 --extra-index-url https://download.pytorch.org/whl/cu117
安装mmcv,注意mmcv的版本要和pytorch和cuda的版本匹配,可通过官网查看https://mmcv.readthedocs.io/zh-cn/stable/get_started/installation.html
pip install -U openmim
mim install mmengine
mim install mmcv==2.0.0
接下来去github网站下载mmdetection源码即可https://github.com/open-mmlab/mmdetection
3.环境验证
先cd到mmdetection程序文件的根目录下再安装相关依赖
cd mmdetection
pip install -v -e . -i https://mirrors.aliyun.com/pypi/simple/
下载模型配置文件和权重文件
mim download mmdet --config rtmdet_tiny_8xb32-300e_coco --dest .
会有两个文件(rtmdet_tiny_8xb32-300e_coco.py 和 rtmdet_tiny_8xb32-300e_coco_20220902_112414-78e30dcc.pth)下载到你的工程文件夹中
接着对demo图片进行推理验证
python demo/image_demo.py demo/demo.jpg rtmdet_tiny_8xb32-300e_coco.py --weights rtmdet_tiny_8xb32-300e_coco_20220902_112414-78e30dcc.pth --device cuda
推理后的结果会放入outputs文件夹中,在 outputs/vis 文件夹中有包含网络预测的检测框的图片demo.jpg。
成功的结果图如下