栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

从创建conda环境再到安装mmcv及mmdet

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

从创建conda环境再到安装mmcv及mmdet

1、cuda和cudnn

网上有很多,后期有需要再出吧。以前也踩了不少坑!

2、conda环境

创建conda环境
conda create -n pytorch python=3.8
移除conda环境
conda remove -n pytorch --all
激活conda环境
conda activate pytorch

3、安装pytorch

(以cuda10.2,pytorch1.9,python3.8为例)
由于官网下载太慢,我直接把包下载下来安装。下载地址如下:https://download.pytorch.org/whl/torch_stable.html
也可以到pytorch官网:https://pytorch.org/命令行安装
pip install torchvision-0.10.0+cu102-cp38-cp38-win_amd64.whl
pip install torchaudio-0.9.0-cp38-cp38-win_amd64.whl
pip install torch-1.9.0+cu102-cp38-cp38-win_amd64.whl

安装验证

命令行输入:
python
import torch
print(torch.cuda.is_available())
出现true说明安装成功
然后输入exit()退出

4、安装mmcv

一句话安装mmcv: https://github.com/open-mmlab/mmcv#installation
pip install mmcv-full==1.4.0 -f https://download.openmmlab.com/mmcv/dist/cu102/torch1.9.0/index.html

5、安装mmdet

建议安装MMDetection和MIM,它会自动处理OpenMMLab项目的依赖,包括mmcv等python包。
先安装openmim
pip install openmim
然后安装mmdet
mim install mmdet
也可以自己git下来mmdet包,然后编译

git clone https://github.com/open-mmlab/mmdetection.git
cd mmdetection
pip install -r requirements/build.txt
pip install -v -e .  # or "python setup.py develop"
6、验证

1.在mmdetection文件夹中新建一个checkpoints文件夹
把这个网站下https://download.openmmlab.com/mmdetection/v2.0/faster_rcnn/faster_rcnn_r50_fpn_1x_coco/faster_rcnn_r50_fpn_1x_coco_20200130-047c8118.pth的文件放入其中。
2.把下面这段代码创建一个py文件到mmdetection文件夹中

from mmdet.apis import init_detector, inference_detector

config_file = 'configs/faster_rcnn/faster_rcnn_r50_fpn_1x_coco.py'
# download the checkpoint from model zoo and put it in `checkpoints/`
# url: https://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'
# init a detector
model = init_detector(config_file, checkpoint_file, device=device)
# inference the demo image
inference_detector(model, 'demo/demo.jpg')

3.cd 到mmdetection文件夹,并执行 python test.py

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/665738.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号