MMDetection亲测安装教程

MMDetection是一个基于 PyTorch 的目标检测开源工具箱。接下来就安装看看吧。

本人安装环境:

  • 系统环境:Ubuntu 20.04.2 LTS
  • cuda版本:11.0
  • cudnn版本:8.0.5
  • torch版本:1.7.0
  • torchvision版本:0.8.0

在Linux下查看cuda和cudnn的版本:

cat /usr/local/cuda/version.txt
cat /usr/local/cuda/include/cudnn_version.h | grep CUDNN_MAJOR -A 2

【注】新版本的cudnn的版本文件不在cudnn.h文件里,而是在cudnn_version.h,所以使用 cat /usr/local/cuda/include/cudnn.h | grep CUDNN_MAJOR -A 2 命令没有输出。

进入安装正题!

1.创建虚拟环境,并激活虚拟环境

conda create -n mmdetection python=3.7
conda acitvate mmdetection

2.安装pytorch

pytorch根据自己的cuda和要安装的版本在PyTorch官网可以找到命令。

conda install pytorch==1.7.0 torchvision==0.8.0 torchaudio==0.7.0 cudatoolkit=11.0 -c pytorch

3.安装 mmcv-full

MMDetection 和 MMCV 版本兼容性见github说明,需要安装正确的 MMCV 版本以避免安装出现问题。

参考 MMCV 获取不同版本的 MMCV 所兼容的的不同的 PyTorch 和 CUDA 版本。
在这里插入图片描述
例如:在 CUDA 11 和 PyTorch 1.7.0 的环境下,可以使用下面命令安装最新版本的 MMCV:

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

4.安装mmdetection

pip install mmdet -i https://pypi.tuna.tsinghua.edu.cn/simple

5.测试mmdetection是否安装成功

在mmdetection目录下新建test.py和checkpoints文件夹,打开网址下载好权重文件放在checkpoints文件夹下,运行以下代码即可。

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)
# 推理演示图像
img = 'demo/demo.jpg'
result = inference_detector(model, img)
model.show_result(img, result)
# 将推理的结果保存
model.show_result(img, result, out_file='result.jpg')

运行虽然没错,但出现了一个警告:

UserWarning: “ImageToTensor” pipeline is replaced by “DefaultFormatBundle” for batch inference. It is recommended to manually replace it in the test data pipeline in your config file. ‘data pipeline in your config file.’, UserWarning)

解决方案:官方文档也给出了修改。在mmdetection/configs/_ base_/datasets/coco_detection.py下面修改test_pipeline。只修改了一行,把ImageToTensor改为DefaultFormatBundle,并将后面的keys=[‘img’]删掉。之后再运行就没有警告了。
在这里插入图片描述

在这里插入图片描述
如果成功安装 MMDetection,则上面的代码可以完整地运行。

6.安装其他依赖包

进入到mmdetection项目目录中

cd mmdetection
pip install -r requirements/build.txt

可看到,一共有四个安装依赖文件:build.txt, optional.txt, runtime.txt, tests.txt。

  • 24
    点赞
  • 110
    收藏
    觉得还不错? 一键收藏
  • 22
    评论
以下是在Linux系统上安装mmdetection的步骤: 1. 首先,进入到mmdetection项目的目录中。可以使用命令`cd mmdetection`来切换到该目录。 2. 然后,使用pip安装所需的依赖库。可以使用命令`pip install -r requirements/build.txt`来安装这些依赖库。这些依赖库会在安装过程中被自动下载和安装。 3. 接下来,创建一个虚拟环境,并激活该虚拟环境。可以使用以下命令创建一个名为mmdetection的虚拟环境:`conda create -n mmdetection python=3.7`。创建完成后,使用命令`conda activate mmdetection`来激活该虚拟环境。 4. 然后,安装PyTorch。可以根据自己的需求选择合适的PyTorch版本进行安装。具体安装命令可以参考PyTorch官方文档提供的指引。 5. 最后,根据mmdetection的GitHub说明,确保安装正确的MMCV版本以避免出现问题。可以使用命令`pip install -r requirements.txt`来安装正确的MMCV版本。 请按照上述步骤执行,即可成功在Linux系统上安装mmdetection。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *2* *3* [MMDetection安装教程](https://blog.csdn.net/qq_45057749/article/details/122964020)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 100%"] [ .reference_list ]

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值