语义分割学习笔记3——运行语义分割程序
- 一、linux安装依赖环境
-
- 1、创建open-mmlab环境
- 2、安装pytorch
- 3、 安装 MMCV
- 4、安装 MMSegmentation
- 三、测试是否安装成功
- 二、windows安装依赖环境
准备运行经典的open-mmlab mmsegmentation框架
源码地址:https://github.com/open-mmlab/mmsegmentation
安装说明:https://github.com/open-mmlab/mmsegmentation/blob/master/README_zh-CN.md
cat /usr/local/cuda/version.txt
or
deepstream-app --version-all
deepstream-app version 5.0.0
CUDA Runtime Version: 10.2
这里我省略了。
语义分割学习笔记2——Jetson Xavier安装pytorch
pip install mmcv-full -f https://download.openmmlab.com/mmcv/dist/cu102/torch1.6.0/index.html

pip install mmsegmentation
三、测试是否安装成功
下载需要的模型
https://github.com/open-mmlab/mmsegmentation/tree/master/configs
下载下文源码中对应的cfg和checkpoint文件。
from mmseg.apis import inference_segmentor, init_segmentor
import mmcv
config_file = 'configs/pspnet/pspnet_r50-d8_512x1024_40k_cityscapes.py'
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 = '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)
python demo/image_demo.py demo/demo.jpg configs/pspnet/pspnet_r50-d8_512x1024_40k_cityscapes.py \
checkpoints/pspnet_r50-d8_512x1024_40k_cityscapes_20200605_003338-2966598c.pth --device cuda:0 --palette cityscapes