前提:
1.安装了CUDA,本人安装的CUDA10.0(PS:只要显卡驱动版本满足,CUDA10.0和CUDA10.1没有差别,可以通过nvidia-smi查看:)
2.安装了anaconda或者miniconda
进入正题:
0.环境准备
conda create -n mmdet python=3.6 -y#创建名为mmdet的环境
activete mmdet#创建好激活环境
conda install pytorch==1.7.0 torchvision==0.8.0 torchaudio==0.7.0 cudatoolkit=10.1 -c pytorch #安装pytorch1.7.0 不要安装1.7.1,因为没有对应的mmcv版本
#其中,安装cudatoolkit=10.1则可以认为是为环境配置CUDA10.1,只要显卡驱动版本满足条件
1.安装mmcv-full
'''
从该网站下载对应版本的mmcv:https://download.openmmlab.com/mmcv/dist/{cu_version}/{torch_version}/index.html
cu_version:CUDA版本号
torch_version:pytorch版本号
因此:https://download.openmmlab.com/mmcv/dist/cu101/torch1.7.0/index.html从下载mmcv_full-1.4.4-cp36-cp36m-win_amd64.whl
'''
pip install mmcv_full-1.4.4-cp36-cp36m-win_amd64.whl
2.安装mmdet
git clone https://github.com/open-mmlab/mmdetection.git
cd mmdetection
pip install -r requirements/build.txt
pip install mmdet==2.22.0
3.验证
模型权重下载:http://download.openmmlab.com/mmdetection/v2.0/faster_rcnn/faster_rcnn_r50_fpn_1x_coco/faster_rcnn_r50_fpn_1x_coco_20200130-047c8118.pth
from mmdet.apis import init_detector, inference_detector,show_result_pyplot
import mmcv
import os
absP='D:/mmdetection'#模型路径
config_file = os.path.join(absP,'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 = '../../data_processing_cache/faster_rcnn_r50_fpn_1x_coco_20200130-047c8118.pth'
device = 'cuda:0'
# 初始化检测器
model = init_detector(config_file, checkpoint_file, device=device)
# 推理演示图像
img=os.path.join(absP,'demo/demo.jpg')
result=inference_detector(model, img)
outImg=model.show_result(
img,
result)
#outImg1=show_result_pyplot(model,img,result)
mmcv.imshow(outImg,'a')
print(result)
检测结果:
?
|