6 Star 66 Fork 19

OpenMMLab/mmsegmentation

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
inference_demo.ipynb 217.98 KB
一键复制 编辑 原始数据 按行查看 历史
!mkdir ../checkpoints
!wget https://download.openmmlab.com/mmsegmentation/v0.5/pspnet/pspnet_r50-d8_512x1024_40k_cityscapes/pspnet_r50-d8_512x1024_40k_cityscapes_20200605_003338-2966598c.pth -P ../checkpoints
mkdir: ../checkpoints: File exists
--2023-02-23 19:23:01--  https://download.openmmlab.com/mmsegmentation/v0.5/pspnet/pspnet_r50-d8_512x1024_40k_cityscapes/pspnet_r50-d8_512x1024_40k_cityscapes_20200605_003338-2966598c.pth
正在解析主机 download.openmmlab.com (download.openmmlab.com)... 116.0.89.205, 116.0.89.209, 116.0.89.207, ...
正在连接 download.openmmlab.com (download.openmmlab.com)|116.0.89.205|:443... 已连接。
已发出 HTTP 请求,正在等待回应... 200 OK
长度:196205945 (187M) [application/octet-stream]
正在保存至: “../checkpoints/pspnet_r50-d8_512x1024_40k_cityscapes_20200605_003338-2966598c.pth.3”

pspnet_r50-d8_512x1 100%[===================>] 187.12M   861KB/s  用时 2m 56s    

2023-02-23 19:25:57 (1.06 MB/s) - 已保存 “../checkpoints/pspnet_r50-d8_512x1024_40k_cityscapes_20200605_003338-2966598c.pth.3” [196205945/196205945])

import torch
import mmcv
import matplotlib.pyplot as plt
from mmengine.model.utils import revert_sync_batchnorm
from mmseg.apis import init_model, inference_model, show_result_pyplot
config_file = '../configs/pspnet/pspnet_r50-d8_4xb2-40k_cityscapes-512x1024.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_model(config_file, checkpoint_file, device='cuda:0')
/Users/xxc/Desktop/pjlab/mmsegv2/mmseg/models/builder.py:36: UserWarning: ``build_loss`` would be deprecated soon, please use ``mmseg.registry.MODELS.build()`` 
  warnings.warn('``build_loss`` would be deprecated soon, please use '
/Users/xxc/Desktop/pjlab/mmsegv2/mmseg/models/losses/cross_entropy_loss.py:235: UserWarning: Default ``avg_non_ignore`` is False, if you would like to ignore the certain label and average loss over non-ignore labels, which is the same with PyTorch official cross_entropy, set ``avg_non_ignore=True``.
  warnings.warn(
Loads checkpoint by local backend from path: ../checkpoints/pspnet_r50-d8_512x1024_40k_cityscapes_20200605_003338-2966598c.pth
# test a single image
img = 'demo.png'
if not torch.cuda.is_available():
    model = revert_sync_batchnorm(model)
result = inference_model(model, img)
# show the results
vis_result = show_result_pyplot(model, img, result)
plt.imshow(mmcv.bgr2rgb(vis_result))
/opt/anaconda3/envs/pt1.13/lib/python3.10/site-packages/mmengine/visualization/visualizer.py:163: UserWarning: `Visualizer` backend is not initialized because save_dir is None.
  warnings.warn('`Visualizer` backend is not initialized '
<matplotlib.image.AxesImage at 0x7fbd89380160>
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/open-mmlab/mmsegmentation.git
git@gitee.com:open-mmlab/mmsegmentation.git
open-mmlab
mmsegmentation
mmsegmentation
main

搜索帮助