mmcv安装,使用步骤

环境配置文件步骤

我的电脑版本:

Python 3.7.6 (anaconda 虚拟环境)
PyTorch 1.8.0
CUDA 11.1
VS 2019 (需要在path设置环境变量)
MMCV 1.4.0
mmdetection  2.19.0
mmsegmentation  0.19.0

CUDA环境下载步骤:https://blog.csdn.net/qq_46107892/article/details/121469597?spm=1001.2014.3001.5501在这里插入图片描述

在这里插入图片描述

torch1.80下载

pip install torch==1.8.0+cu111 torchvision==0.9.0+cu111 torchaudio==0.8.0 -f https://download.pytorch.org/whl/torch_stable.html

cl查看vs版本

cl

在这里插入图片描述

ls env:查看cuda版本

ls env:

在这里插入图片描述

下载安装mmcv

git clone https://github.com/open-mmlab/mmcv.git
$env:CUDA_HOME = "E:\USEAPP\CUDA111\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.1"
$env:CUDA_HOME = $env:CUDA_PATH_V11_1 # if CUDA_PATH_V11_1 is in envs:
$env:TORCH_CUDA_ARCH_LIST="8.6"                  #算力
$env:MMCV_WITH_OPS = 1
$env:MAX_JOBS = 8               

进行编译

python setup.py build_ext

在这里插入图片描述

进行安装

python setup.py develop

在这里插入图片描述
在这里插入图片描述

下载安装:mmdetection

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

在这里插入图片描述

from mmdet.apis import init_detector, inference_detector, show_result_pyplot

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

在这里插入图片描述

下载:mmsegmentation

git clone https://github.com/open-mmlab/mmsegmentation.git
pip install -e .

代码测试:

模型地址:https://download.openmmlab.com/mmsegmentation/v0.5/pspnet/pspnet_r50-d8_512x1024_40k_cityscapes/pspnet_r50-d8_512x1024_40k_cityscapes_20200605_003338-2966598c.pth

from mmseg.apis import inference_segmentor, init_segmentor

import mmcv

config_file = 'configs/pspnet/pspnet_r50-d8_512x1024_40k_cityscapes.py'
#https://download.openmmlab.com/mmsegmentation/v0.5/pspnet/pspnet_r50-d8_512x1024_40k_cityscapes/pspnet_r50-d8_512x1024_40k_cityscapes_20200605_003338-2966598c.pth
checkpoint_file = 'checkpoints/pspnet_r50-d8_512x1024_40k_cityscapes_20200605_003338-2966598c.pth'

# build the model from a config file and a checkpoint file
model = init_segmentor(config_file, checkpoint_file, device='cuda:0')

# test a single image and show the results
img = 'demo/demo.png'  # or img = mmcv.imread(img), which will only load it once

result = inference_segmentor(model, img)

# visualize the results in a new window
model.show_result(img, result, show=True)

# or save the visualization results to image files
# you can change the opacity of the painted segmentation map in (0, 1].
model.show_result(img, result, out_file='result.jpg', opacity=0.5)

在这里插入图片描述

  • 0
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

枭玉龙

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

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

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

打赏作者

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

抵扣说明:

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

余额充值