安装MMsegmentation2.0.0以及过程中可能遇到的问题

参考(官方文档):开始使用:安装并运行 MMSeg — MMSegment 1.1.1 文档 (mmsegmentation.readthedocs.io)

前提是大家先有了深度学习一些基础的环境配置,比如anaconda或miniconda,cuda,pytorch等

首先就是得安装mmengine和mmcv分别使用以下三个命令:

pip install -U openmim
mim install mmengine
mim install "mmcv>=2.0.0"

不过对于第三条,也可以自定义进行安装,如果有需求也可以安装其他版本的mmcv,这里就以2.0.0为例(注意版本适配,不然后续会出现版本不兼容的报错)

点击进入mmcv版本选择:download.openmmlab.com/mmcv/dist/cu111/torch1.8.0/index.html

找到适合自己电脑和python版本的对应文件进行下载

再按住ctrl+R使用命令提示符窗口,进入虚拟环境,并切换到mmcv下载到的文件夹(进入文件夹后使用pip install mmcv按住tab键进行补全)

 至此mmengine和mmcv就已经安装好了

这里开始安装mmsegmentation:

方法一:推荐直接下载源码,连接在这里

GitHub - open-mmlab/mmsegmentation: OpenMMLab Semantic Segmentation Toolbox and Benchmark.

方法二:进行克隆仓库(如果失败多试几次,大概率是网络问题导致)

git clone -b main https://github.com/open-mmlab/mmsegmentation.git
cd mmsegmentation
pip install -v -e .

接下来就是验证是否安装完成的环节:

在刚刚的命令提示符窗口输入以下指令来下载权重文件和网络代码(最后有个点):

mim download mmsegmentation --config pspnet_r50-d8_4xb2-40k_cityscapes-512x1024 --dest .

注意这里网上有一些错误的验证命令,就会导致一些报错,错误命令主要是因为文件名不正确造成的。报错大概长这样:

意思就是说希望的配置文件名字在以下这一堆红字里面,不一样的话就会报错

代码执行完之后会在执行命令的目录下生成两个文件 :pspnet_r50-d8_4xb2-40k_cityscapes-512x1024.py 和 pspnet_r50-d8_512x1024_40k_cityscapes_20200605_003338-2966598c.pth

就说明下载好了已经

最后就是进行验证推理,使用命令:

python demo/image_demo.py demo/demo.png configs/pspnet/pspnet_r50-d8_4xb2-40k_cityscapes-512x1024.py pspnet_r50-d8_512x1024_40k_cityscapes_20200605_003338-2966598c.pth --device cuda:0 --out-file result.jpg

或者直接在pycharn中使用代码

from mmseg.apis import inference_model, init_model, show_result_pyplot
import mmcv

config_file = 'pspnet_r50-d8_4xb2-40k_cityscapes-512x1024.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_model(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_model(model, img)
# visualize the results in a new window
show_result_pyplot(model, 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].
show_result_pyplot(model, img, result, show=True, 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)
   show_result_pyplot(model, result, wait_time=1)

最后运行出这个效果就说明安装成功了!

 

  • 3
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值