环境配置:open-mmlab视觉库mmdetection

环境配置:open-mmlab视觉库mmdetection_第1张图片

windows系统下的环境配置(GPU版)

这里提供以下windows下CPU版本环境配置的教程:CPU-mmdetection
注:Ubuntu系统下的环境配置大同小异,甚至会简单点

pytorch(python3.8)

pytorch命令指南
环境配置:open-mmlab视觉库mmdetection_第2张图片

pip3 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失败的情况,大概率是网络不稳定造成的,

pytorch下载
如果上面因为网络原因pip失败,可以去上面链接下载对应的库包,本文的库链接如下:

  • cu111/torch-1.9.1%2Bcu111-cp38-cp38-win_amd64.whl
  • cu111/torchvision-0.10.1%2Bcu111-cp38-cp38-win_amd64.whl
  • torchaudio-0.9.1-cp38-cp38-win_amd64.whl

下载下来执行:
package_location:下载包的绝对地址

pip3 install {package_location}

CUDA11.1+CUDNN8.0.5

  1. CUDA Toolkit 11.1.1 (Oct 2020)
  2. cuDNN v8.0.5 (November 9th, 2020), for CUDA 11.1

上述CUDA TOOlkit默认安装完毕之后,将cuDNN解压出来文件夹里的许多文件复制到如下目录即可:C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.1

mmdetection(GPU)

open-mmlab-mmdetection开源库
环境配置:open-mmlab视觉库mmdetection_第3张图片
将上述库clone下来

MMDetection中文安装指南

环境配置:open-mmlab视觉库mmdetection_第4张图片
上述mmcv-full的安装可以直接复制下面

pip install mmcv-full=={1.3.9} -f https://download.openmmlab.com/mmcv/dist/cu111/torch1.9.1/index.html

环境配置:open-mmlab视觉库mmdetection_第5张图片
第三步骤的安装是补充的,有需要可以安装
环境配置:open-mmlab视觉库mmdetection_第6张图片

验证安装结果

环境配置:open-mmlab视觉库mmdetection_第7张图片
下载上述代码指定的权重:
faster-rcnn权重下载链接

from mmdet.apis import init_detector, inference_detector

config_file = '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 = 'checkpoints/faster_rcnn_r50_fpn_1x_coco_20200130-047c8118.pth'
device = 'cuda:0'
# 初始化检测器
model = init_detector(config_file, checkpoint_file, device=device)
# 推理演示图像
inference_detector(model, 'demo/demo.jpg')

复制上述代码到工程根目录运行,如果程序exit code为0,则环境配置完成

或者运行如下代码:

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 = './demo/demo.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')

如果exit code为0,根目录会出现result.jpg
环境配置:open-mmlab视觉库mmdetection_第8张图片

你可能感兴趣的:(深度学习,windows,pytorch,mmdetection,open-mmlab)