|
a |
|
b/tests/test_inference.py |
|
|
1 |
# Copyright (c) OpenMMLab. All rights reserved. |
|
|
2 |
import os.path as osp |
|
|
3 |
|
|
|
4 |
import mmcv |
|
|
5 |
|
|
|
6 |
from mmseg.apis import inference_segmentor, init_segmentor |
|
|
7 |
|
|
|
8 |
|
|
|
9 |
def test_test_time_augmentation_on_cpu(): |
|
|
10 |
config_file = 'configs/pspnet/pspnet_r50-d8_512x1024_40k_cityscapes.py' |
|
|
11 |
config = mmcv.Config.fromfile(config_file) |
|
|
12 |
|
|
|
13 |
# Remove pretrain model download for testing |
|
|
14 |
config.model.pretrained = None |
|
|
15 |
# Replace SyncBN with BN to inference on CPU |
|
|
16 |
norm_cfg = dict(type='BN', requires_grad=True) |
|
|
17 |
config.model.backbone.norm_cfg = norm_cfg |
|
|
18 |
config.model.decode_head.norm_cfg = norm_cfg |
|
|
19 |
config.model.auxiliary_head.norm_cfg = norm_cfg |
|
|
20 |
|
|
|
21 |
# Enable test time augmentation |
|
|
22 |
config.data.test.pipeline[1].flip = True |
|
|
23 |
|
|
|
24 |
checkpoint_file = None |
|
|
25 |
model = init_segmentor(config, checkpoint_file, device='cpu') |
|
|
26 |
|
|
|
27 |
img = mmcv.imread( |
|
|
28 |
osp.join(osp.dirname(__file__), 'data/color.jpg'), 'color') |
|
|
29 |
result = inference_segmentor(model, img) |
|
|
30 |
assert result[0].shape == (288, 512) |