从创建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.6 -f https://download.openmmlab.com/mmcv/dist/cu113/torch1.10.0/index.html

5、安装mmdet

自己编译mmdet的话,你编译的当前mmdet的repo就是你运行的mmdet。如果使用 pip install mmdet 来安装的话,会变成一个包安装在环境的sitepackges里面。在你之后修改当前代码是无效的。你需要修改环境中的那个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"

最后使用pip list。
你会看到mmcv装上了。mmdet后面会带一个路径,就是你当前编译的路径。

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

kira_Y

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值