安装mmcv

一、先决条件

MMSegmentation 适用于 Linux、Windows 和 macOS。它需要 Python 3.6+、CUDA 9.2+ 和 PyTorch 1.3+。

Pytorch的配置教程可以参考我的另一篇文章。

Anaconda下载安装及配置pytorch环境_anaconda3 pytorch 安装-CSDN博客

二、最佳实践

步骤 0。使用 MIM 安装 MMCV

pip install -U openmim
mim install mmcv-full

即可安装 pip install -U openmim

 可以安装自己需要的版本 mim install mmcv-full==1.3.17

 

步骤 1。安装 MMSegmentation。

案例 a:如果直接开发和运行 mmseg,请从源代码安装它:

git clone https://github.com/open-mmlab/mmsegmentation.git
cd mmsegmentation
pip install -v -e .
# "-v" means verbose, or more output
# "-e" means installing a project in editable mode,
# thus any local modifications made to the code will take effect without reinstallation.

案例 b:如果使用 mmsegmentation 作为依赖项或第三方包,请使用 pip 安装它:

pip install mmsegmentation

注意:如果您想使用 albumentations,我们建议使用 pip install -U albumentations --no-binary qudida,albumentations。如果你只是使用 pip install albumentations>=0.3.2,它将同时安装 opencv-python-headless(即使你已经安装了 opencv-python)。我们建议在安装 albumentations 后检查环境,以确保 opencv-python 和 opencv-python-headless 不会同时安装,因为如果同时安装它们可能会导致意外问题。有关详细信息,请参阅官方文档

三、验证安装

为了验证 MMSegmentation 是否正确安装,我们提供了一些示例代码来运行推理演示。

步骤 1。我们需要下载配置和检查点文件。

mim download mmsegmentation --config pspnet_r50-d8_512x1024_40k_cityscapes --dest .

下载将需要几秒钟或更长时间,具体取决于您的网络环境。完成后,您将在当前文件夹中找到两个文件。pspnet_r50-d8_512x1024_40k_cityscapes.pypspnet_r50-d8_512x1024_40k_cityscapes_20200605_003338-2966598c.pth

第2步。验证推理演示。

选项(a)。如果从源代码安装 mmsegmentation,只需运行以下命令即可。

python demo/image_demo.py demo/demo.png configs/pspnet/pspnet_r50-d8_512x1024_40k_cityscapes.py pspnet_r50-d8_512x1024_40k_cityscapes_20200605_003338-2966598c.pth --device cuda:0 --out-file result.jpg

您将在当前文件夹中看到一个新图像,其中所有对象都覆盖了分割蒙版。result.jpg

选项(b)。如果使用 pip 安装 mmsegmentation,请打开 python 解释器并复制粘贴以下代码。

from mmseg.apis import inference_segmentor, init_segmentor
import mmcv

config_file = 'pspnet_r50-d8_512x1024_40k_cityscapes.py'
checkpoint_file = '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 = 'test.jpg'  # 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)

# test a video and show the results
video = mmcv.VideoReader('video.mp4')
for frame in video:
   result = inference_segmentor(model, frame)
   model.show_result(frame, result, wait_time=1)

您可以修改上面的代码来测试单个图像或视频,这两个选项都可以验证安装是否成功。

  • 21
    点赞
  • 21
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
安装mmcv-full,首先需要查看你的pytorch和cuda版本。你可以使用以下命令查看你的pytorch版本: import torch print(torch.__version__) 要查看你的cuda版本,你可以使用以下命令: nvcc --version 然后,你可以使用一个自动匹配版本的工具来安装mmcv-full。你可以找到这个工具,并根据你的环境版本输入相应的命令进行安装。这个工具会自动选择与你的pytorch和cuda版本匹配的mmcv-full版本进行安装。 一旦你找到了合适的mmcv-full安装命令,你可以将其复制到终端中并执行安装命令。安装完成后,你就成功安装mmcv-full。如果在安装过程中遇到了opencv-python安装失败的问题,你可以去百度上找到预编译的whl文件并进行手动安装。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *2* [踩雷日记:Pytorch mmcv-full简易安装](https://blog.csdn.net/weixin_44796609/article/details/129145725)[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_1"}}] [.reference_item style="max-width: 50%"] - *3* [Windows mmcv-full 1.5.0 详细安装过程](https://blog.csdn.net/qq_41300185/article/details/124889927)[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_1"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值