一、步骤
step1:
conda create -n openmmlab python=3.9 -y
step2:
source activate openmmlab
step3:
pip install torch=1.9.1+cu111 torchvision==0.10.1+cu111 torchaudio==0.9.1 -f https://download.pytorch.org/whl/torch_stable.html
注:我自己的服务器还将pip进行了永久换源为了豆瓣源
step4:
pip install -U openmim
注:我自己的服务器还将pip进行了永久换源为了豆瓣源
step5:
mim install mmcv-full==1.5.3
这里注意:mim方式与pip方式都可以,其中mim方式是mmdet官方github上自己推荐的
step6:
cd /home/wt-yjy/project/code
git clone https://github.com/open-mmlab/mmdetection.git
cd mmdetection/
pip install -v -e .
注:也可以采用pip install mmdet直接不用git clone后再安装这种模式了
二、验证是否安装ok
(方式一)If you install mmdetection from source, just run the following command.
mim download mmdet --config yolov3_mobilenetv2_320_300e_coco --dest .
那么,修改python环境中/lib/python3.9/site-packages/mim/commands/search.py文件,这个文件在抱错时也会提示392行抛出异常,修改390行为:
if collection_name and collection_name in name2collection.keys():
运行测试脚本:
python demo/image_demo.py demo/demo.jpg yolov3_mobilenetv2_320_300e_coco.py yolov3_mobilenetv2_320_300e_coco_20210719_215349-d18dff72.pth --device cpu --out-file result.jpg
结果如下:
(方式二) If you install mmdetection with pip, open you python interpreter and copy&paste the following codes.
from mmdet.apis import init_detector, inference_detector,show_result_pyplot
config_file = '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 = 'checkpoints/faster_rcnn_r50_fpn_1x_coco_20200130-047c8118.pth'
device = 'cuda:0'
# init a detector
model = init_detector(config_file, checkpoint_file, device=device)
# inference the demo image
img = 'demo/demo.jpg'
result = inference_detector(model, img)
show_result_pyplot(model,img,result)
from mmdet.apis import init_detector, inference_detector
config_file = 'yolov3_mobilenetv2_320_300e_coco.py'
checkpoint_file = 'yolov3_mobilenetv2_320_300e_coco_20210719_215349-d18dff72.pth'
model = init_detector(config_file, checkpoint_file, device='cpu') # or device='cuda:0'
inference_detector(model, 'demo/cat.jpg')
出现检测结果即为成功。
三、注意
(1)要注意mmdet和mmcv的版本匹配问题
这个文档里面就有匹配列表:
我安装的mmcv-full 版本是1.5.3,mmdet版本为2.25.0,根据上图可以看到是满足要求的。此外我的cudatoolkit是cu11的。
(2)mmcv和mmcv-full二者的使用场景区别
在安装mmcv时,我们往往纠结是安装mmcv还是mmcv-full。
如果你需要调用mmcv里面实现的cuda或者cpu算子,就需要安装mmcv-full,并且为了不影响后续的部署,最好还是尽可能的安装mmcv-full,其功能更全。
补充:
如果要是更新了pytorch和cuda版本,要重新先卸载mmcv:min uninstall mmcv-full==1.5.3
最后再重新:min install mmcv-full==1.5.3,再去pip install -v -e .
参考:
GitHub - open-mmlab/mmcv: OpenMMLab Computer Vision Foundation
KeyError: ‘Cascade Mask R-CNN‘_Coding的叶子的博客-CSDN博客
mmdetection/get_started.md at master · open-mmlab/mmdetection · GitHub
Previous PyTorch Versions | PyTorch