Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix: num of augmentations and image meta not match when run TTA on CPU #276

Merged
merged 5 commits into from
Dec 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion mmseg/apis/inference.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def inference_segmentor(model, img):
# scatter to specified GPU
data = scatter(data, [device])[0]
else:
data['img_metas'] = data['img_metas'][0].data
data['img_metas'] = [i.data[0] for i in data['img_metas']]

# forward the model
with torch.no_grad():
Expand Down
29 changes: 29 additions & 0 deletions tests/test_inference.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import os.path as osp

import mmcv

from mmseg.apis import inference_segmentor, init_segmentor


def test_test_time_augmentation_on_cpu():
config_file = 'configs/pspnet/pspnet_r50-d8_512x1024_40k_cityscapes.py'
config = mmcv.Config.fromfile(config_file)
xvjiarui marked this conversation as resolved.
Show resolved Hide resolved

# Remove pretrain model download for testing
config.model.pretrained = None
# Replace SyncBN with BN to inference on CPU
norm_cfg = dict(type='BN', requires_grad=True)
config.model.backbone.norm_cfg = norm_cfg
config.model.decode_head.norm_cfg = norm_cfg
config.model.auxiliary_head.norm_cfg = norm_cfg

# Enable test time augmentation
config.data.test.pipeline[1].flip = True

checkpoint_file = None
model = init_segmentor(config, checkpoint_file, device='cpu')

img = mmcv.imread(
osp.join(osp.dirname(__file__), 'data/color.jpg'), 'color')
result = inference_segmentor(model, img)
assert result[0].shape == (288, 512)