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

在这里插入图片描述

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

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

pytorch(python3.8)

pytorch命令指南
在这里插入图片描述

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失败,可以去上面链接下载对应的库包,本文的库链接如下:

下载下来执行:
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开源库
在这里插入图片描述
将上述库clone下来

MMDetection中文安装指南

在这里插入图片描述
上述mmcv-full的安装可以直接复制下面

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

在这里插入图片描述
第三步骤的安装是补充的,有需要可以安装
在这里插入图片描述

验证安装结果

在这里插入图片描述
下载上述代码指定的权重:
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
请添加图片描述

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值