MMDection学习记录(一)之环境配置

在这里插入图片描述

Linux下环境配置(torch1.12)

Linux下环境配置(torch1.7)

创建环境并激活

conda create --name openmmlab python=3.7 -y
conda activate openmmlab

安装Pytorch

建议使用pip命令安装,否则会报错:

symbol free_gemm_select version libcublasLt.so.11 not defined in file
libcublasLt.so.11 with link time reference

pip install torch==1.7.0+cu110 torchvision==0.8.1+cu110 torchaudio==0.7.0 -f https://download.pytorch.org/whl/torch_stable.html
conda install pytorch==1.7.0 torchvision==0.8.0 torchaudio==0.7.0 cudatoolkit=11.0 -c pytorch

MMDetection安装

建议使用 MIM 来安装 MMDetection:

pip install openmim
mim install mmdet

MIM 能够自动地安装 OpenMMLab 的项目以及对应的依赖包。
或者可进行手动安装
安装MMCV需要对应CUDA和torch,安装命令要符合下面格式

pip install mmcv-full -f https://download.openmmlab.com/mmcv/dist/{
    
    cu_version}/{
    
    torch_version}/index.html

如安装CUDA1.0,pytorch=1.7.0:

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

简单测试

from mmdet.apis import init_detector, inference_detector
config_file = '/data/programs/mmdetection/mmdetection/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 = '/data/programs/mmdetection/mmdetection/checkpoint/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')

Windows下环境配置

步骤与Linux安装基本相同
创建环境并激活

conda create --name openmmlab python=3.7 -y
conda activate openmmlab

安装Pytorch

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

安装MMDetection

使用下面命令:

git clone https://github.com/open-mmlab/mmdetection.git   
cd mmdetection   
pip install -r requirements/build.txt   
pip install -v -e . 

在这里插入图片描述
下面这几种方法理论上也是可行的,但博主却失败了。

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

如果执行pip install openmim可能会报下方错误

to fix this you could try to: 1. loosen the range of package versions
you’ve specified 2. remove package versions to allow pip attempt to
solve the dependency conflict

否则会报错超时,依旧报错

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

安装MMCV

下载链接

在这里插入图片描述

pip install mmcv==2.0.0rc4 -f https://download.openmmlab.com/mmcv/dist/cu101/torch1.7/index.html

安装MMCV-full

这里一定要对应好版本,先前博主一致安装的是cuda110,一直报错,直到改为cu101才能够成果安装。

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

在这里插入图片描述

其他问题

torch1.7版本以下不支持分布式训练,故需要安装torch1.7以上

报错1:

ext = importlib.import_module(‘mmcv.’ + name) File
“D:\Anaconda\envs\openmmlab\lib\importlib_init_.py”, line 127, in
import_module
return _bootstrap._gcd_import(name[level:], package, level) ImportError: DLL load failed: 找不到指定的模块。

猜你喜欢

转载自blog.csdn.net/pengxiang1998/article/details/131053945