MM-Detection Logs —— 环境搭建及安装(Linux)

MM-Detection Logs(2022.04.01)

使用 conda 新建虚拟环境,命名为”open-mmlab”,终端输入命令:

conda create -n open-mmlab python=3.7 -y
  1. 激活环境

激活”open-mmlab”,切换到”open-mmlab”环境,终端输入命令:

source activate open-mmlab
  1. 安装PyTorch

PyTorch 官网:link

基于 PyTorch 官网安装 PyTorch 和 torchvision,”open-mmlab”环境下,终端输入命令:

conda install pytorch==1.7.1 torchvision==0.8.2 torchaudio==0.7.2 cudatoolkit=10.1 -c pytorch

备注:这里推荐PyTorch 1.7.1版本,我的环境是CUDA 10.1

  1. 安装MMDetection依赖包

安装 mmcv-full,”open-mmlab”环境下,终端输入命令:

pip install mmcv-full

我们建议使用预构建包来安装,如下:

pip install mmcv-full -f https://download.openmmlab.com/mmcv/dist/cu101/torch1.7.0/index.html

备注:”pip install mmcv-full -f https://download.openmmlab.com/mmcv/dist/{cu_version}/{torch_version}/index.html”中需要把命令行中的 {cu_version} 和 {torch_version} 替换成对应的版本。例如:上述代码对应的是 CUDA 10.1 和 PyTorch 1.7.1 的环境。PyTorch可忽略小版本,1.7.x都可以用1.7.0。

  1. 安装MMDetection

”open-mmlab”环境下,终端输入命令:

pip install mmdet
  1. 打开mmdetection项目

下载并在PyCharm中打开。项目地址:link

  1. 在PyCharm中配置”open-mmlab”环境

MM-Detection Logs —— 环境搭建及安装(Linux)

; 7. 验证

为了验证是否正确安装了 MMDetection 和所需的环境,我们可以运行示例的 Python 代码来初始化检测器并推理一个演示图像:

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)
推理演示图像
result = inference_detector(model, 'demo/demo.jpg')
model.show_result('demo/demo.jpg', result, out_file='result.jpg')

备注:查看result.jpg正常即可。

MM-Detection Logs —— 环境搭建及安装(Linux)

Original: https://blog.csdn.net/qq_39430450/article/details/123957082
Author: Royhh1990
Title: MM-Detection Logs —— 环境搭建及安装(Linux)

原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/687738/

转载文章受原作者版权保护。转载请注明原作者出处!

(0)

大家都在看

亲爱的 Coder【最近整理,可免费获取】👉 最新必读书单  | 👏 面试题下载  | 🌎 免费的AI知识星球