当前位置:   article > 正文

【MMSegmentation 环境配置】

【MMSegmentation 环境配置】

1. 创建python 环境

conda create --name openmmlab python=3.8 -y
conda activate openmmlab
  • 1
  • 2

2. 安装pytorch

On GPU platforms:
conda install pytorch torchvision -c pytorch
On CPU platforms:
conda install pytorch torchvision cpuonly -c pytorch
  • 1
  • 2
  • 3
  • 4
感觉慢的可以通过清华镜像离线下载进行安装,
下载的时候下载对应的torch,torchvision,torchaudio
download.pytorch.org/whl/torch_stable.html
  • 1
  • 2
  • 3

3. 安装MMCV

pip install -U openmim
mim install mmengine
mim install "mmcv>=2.0.0"
  • 1
  • 2
  • 3

4. 安装 MMSegmentation.

git clone -b main 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 reinstallati
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

如果不从源码编译可以直接安装:

pip install "mmsegmentation>=1.0.0"
  • 1

5. 测试是否安装成功

mim download mmsegmentation --config pspnet_r50-d8_4xb2-40k_cityscapes-512x1024 --dest .
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
  • 1
  • 2

如果报numpy版本高,需要对numpy降版本

pip install numpy==1.26.4
  • 1

出现AssertionError: MMCV==2.2.0 is used but incompatible. Please install mmcv>=2.0.0rc4.
安装对应的提示版本即可:

pip install mmcv==2.0.0rc4 -f https://download.openmmlab.com/mmcv/dist/cu117/torch1.13/index.html
  • 1

安装其他依赖

pip install ftfy
pip install regex
  • 1
  • 2

测试代码

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_model(model, frame)
   show_result_pyplot(model, frame, result, wait_time=1)
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22

请添加图片描述

声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:【wpsshop博客】
推荐阅读
相关标签
  

闽ICP备14008679号