MMdetection安装教程(Ubuntu)

1、下载工程

自行去 Github 下载代码
在下载好代码之后,打开里面的安装文档,查看一下要安装的 Python 最低版本和 Pytorch最低版本

  • Python 3.6+
  • PyTorch 1.3+
  • CUDA 9.2+ (如果基于 PyTorch 源码安装,也能够支持 CUDA 9.0)

2、新建虚拟环境

conda create -n mmdetection python=3.7 -y

新建成功后,进入虚拟环境里面

source activate mmdetection

3、安装Pytorch

我这里安装的是 Pytorch1.7.0+cu101 版本

pip install torch==1.7.0+cu101 torchvision==0.8.1+cu101 torchaudio==0.7.0 -f https://download.pytorch.org/whl/torch_stable.html

4、安装 mmcv-full

mmcv-full安装命令文档
去上面这个网址,查看一下对应 Pytorch版本 和 对应 CUDA版本 的安装命令,我这里安装的版本是
mmcv-full>=1.3.17

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

5、以上都安装成功后

从模型网址:模型网址
下载预训练模型,并放在指定文件夹
然后在主工程目录下,新建 demo.py 文件,运行即可
如果有报错,缺库文件,根据提示直接安装,就好了。

from mmdet.apis import init_detector, inference_detector, show_result_pyplot

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 = 'cpu'
# 初始化检测器
model = init_detector(config_file, checkpoint_file, device=device)
# 推理演示图像
result = inference_detector(model, './demo/demo.jpg')
show_result_pyplot(model=model, img='demo/demo.jpg', result=result, score_thr=0.9)

猜你喜欢

转载自blog.csdn.net/Sir666888/article/details/124555779
今日推荐