1、创建虚拟环境
conda create -n openmmlab python=3.7 -y conda activate openmmlab
2、安装pytorch,需要安装与显卡相适应的版本
这里以3080为例
conda install pytorch==1.8.0 torchvision==0.9.0 torchaudio==0.8.0 cudatoolkit=11.1 -c pytorch -c conda-forge
注意:pytorch版本不要太新,否则和后面mmcv版本不匹配
3、安装mmcv-full
https://github.com/open-mmlab/mmcv#install-with-pip其他版本参考官网
pip install mmcv-full -f https://download.openmmlab.com/mmcv/dist/cu111/torch1.8.0/index.html
有cuda的建议安装mmcv-full,千万不能mmcv和mmcv-full同时安装
4、安装MMDetection
从官网上下载https://github.com/open-mmlab/mmdetection
cd mmdetection pip install -r requirements/build.txt python setup.py develop
5、测试
from mmdet.apis import init_detector, inference_detector import mmcv # Specify the path to model config and checkpoint file config_file = 'configs/faster_rcnn/faster_rcnn_r50_fpn_1x_coco.py' checkpoint_file = 'checkpoints/faster_rcnn_r50_fpn_1x_coco_20200130-047c8118.pth' # build the model from a config file and a checkpoint file model = init_detector(config_file, checkpoint_file, device='cuda:0') # test a single image and show the results img = 'test.jpg' # or img = mmcv.imread(img), which will only load it once result = inference_detector(model, img) # visualize the results in a new window model.show_result(img, result) # or save the visualization results to image files model.show_result(img, result, out_file='result.jpg')
其中checkpoint_file文件下载地址
https://download.openmmlab.com/mmdetection/v2.0/faster_rcnn/faster_rcnn_r50_fpn_1x_coco/faster_rcnn_r50_fpn_1x_coco_20200130-047c8118.pth
6、测试结果



