实验1代码,不加model.show_result:
%reload_ext autoreload
%autoreload 2
%matplotlib inline
from mmseg.apis import inference_segmentor, init_segmentor
import mmcv
import os
os.environ[“KMP_DUPLICATE_LIB_OK”]=“TRUE”
config_file = ‘mmsegmentation/configs/unet/fcn_unet_s5-d16_4x4_512x1024_160k_cityscapes.py’
checkpoint_file = ‘mmsegmentation/checkpoints/fcn_unet_s5-d16_4x4_512x1024_160k_cityscapes_20211210_145204-6860854e.pth’
model = init_segmentor(config_file, checkpoint_file, device=‘cuda:2’)
img = ‘adjust20151019205737_FK108_1_6300_180000_B1_G3__noise0.02__flipv.png’ # or img = mmcv.imread(img), which will only load it once
result = inference_segmentor(model, img)
jupyte lab正常运行!!
实验2代码:
%reload_ext autoreload
%autoreload 2
%matplotlib inline
from mmseg.apis import inference_segmentor, init_segmentor
import mmcv
import os
os.environ[“KMP_DUPLICATE_LIB_OK”]=“TRUE”
config_file = ‘mmsegmentation/configs/unet/fcn_unet_s5-d16_4x4_512x1024_160k_cityscapes.py’
checkpoint_file = ‘mmsegmentation/checkpoints/fcn_unet_s5-d16_4x4_512x1024_160k_cityscapes_20211210_145204-6860854e.pth’
model = init_segmentor(config_file, checkpoint_file, device=‘cuda:2’)
img = ‘adjust20151019205737_FK108_1_6300_180000_B1_G3__noise0.02__flipv.png’ # or img = mmcv.imread(img), which will only load it once
result = inference_segmentor(model, img)
model.show_result(img, result, show=True)
model.show_result(img, result, out_file=‘result3.jpg’, opacity=0.5)
jupyter lab提示服务似乎挂掉,但会立刻重启
实验代码3,注释掉model.show_result(img, result, show=True):
%reload_ext autoreload
%autoreload 2
%matplotlib inline
from mmseg.apis import inference_segmentor, init_segmentor
import mmcv
import os
os.environ[“KMP_DUPLICATE_LIB_OK”]=“TRUE”
config_file = ‘mmsegmentation/configs/unet/fcn_unet_s5-d16_4x4_512x1024_160k_cityscapes.py’
checkpoint_file = ‘mmsegmentation/checkpoints/fcn_unet_s5-d16_4x4_512x1024_160k_cityscapes_20211210_145204-6860854e.pth’
model = init_segmentor(config_file, checkpoint_file, device=‘cuda:2’)
img = ‘adjust20151019205737_FK108_1_6300_180000_B1_G3__noise0.02__flipv.png’ # or img = mmcv.imread(img), which will only load it once
result = inference_segmentor(model, img)
#model.show_result(img, result, show=True)
model.show_result(img, result, out_file=‘result3.jpg’, opacity=0.5)
代码运行正常,生成result3.jpg
可见model.show_result(img, result, show=True)是导致jupyter lab服务挂掉的原因
其他替代方法:show_result_pyplot
%reload_ext autoreload
%autoreload 2
%matplotlib inline
from mmseg.apis import inference_segmentor, init_segmentor,show_result_pyplot
from mmseg.core.evaluation import get_palette
import mmcv
import os
os.environ[“KMP_DUPLICATE_LIB_OK”]=“TRUE”
config_file = ‘mmsegmentation/configs/unet/fcn_unet_s5-d16_4x4_512x1024_160k_cityscapes.py’
checkpoint_file = ‘mmsegmentation/checkpoints/fcn_unet_s5-d16_4x4_512x1024_160k_cityscapes_20211210_145204-6860854e.pth’
model = init_segmentor(config_file, checkpoint_file, device=‘cuda:2’)
img = ‘adjust20151019205737_FK108_1_6300_180000_B1_G3__noise0.02__flipv.png’ # or img = mmcv.imread(img), which will only load it once
result = inference_segmentor(model, img)
model.show_result(img, result, out_file=‘result4.jpg’, opacity=0.5)
show_result_pyplot(model, img, result, get_palette(‘cityscapes’))