Skip to content

Commit 8a56b37

Browse files
Merge ad71d79 into 1fb54ac
2 parents 1fb54ac + ad71d79 commit 8a56b37

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

mmseg/apis/inference.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ def inference_segmentor(model, img):
8989
# scatter to specified GPU
9090
data = scatter(data, [device])[0]
9191
else:
92-
data['img_metas'] = data['img_metas'][0].data
92+
data['img_metas'] = [i.data[0] for i in data['img_metas']]
9393

9494
# forward the model
9595
with torch.no_grad():

tests/test_inference.py

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

0 commit comments

Comments
 (0)