mmdetection环境搭建(cuda=11.3, pytorch=1.11, mmcv-full=1.6.0)

创建新环境(mmdet)环境:

conda create -n mmdet python==3.7

安装cudatoolkit:

conda install cudatoolkit=11.3

安装cudnn:

conda install cudatoolkit=11.3

安装pytorch和torchvision:

conda install pytorch=1.11 torchvision -c pytorch

安装mmcv-full:

pip install mmcv-full==1.6.0 -f https://download.openmmlab.com/mmcv/dist/cu113/torch1.11/index.html

安装mmdet包:

pip install mmdet

下载mmdetection项目:

git clone https://github.com/open-mmlab/mmdetection.git

创建文件夹checkpoints并下载权重文件:

mkdir checkpoints
wget https://download.openmmlab.com/mmdetection/v2.0/faster_rcnn/faster_rcnn_r50_fpn_1x_coco/faster_rcnn_r50_fpn_1x_coco_20200130-047c8118.pth

进入mmdetecion/demo并新建文件env_test.py

from mmdet.apis import init_detector, inference_detector, show_result_pyplot
import mmcv
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'
# 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
img = 'demo.jpg'
result = inference_detector(model, img)
# show the results
show_result_pyplot(model, img, result,out_file="result.jpg")

你可能感兴趣的:(mmdetection,深度学习,python)