-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bugfix: num of augmentations and image meta not match when run TTA on…
… CPU (#276) * add inference test * fix E501 line too long (81 > 79 characters * fix wrong config path * fix num of augmentations (2) != num of image meta (1) * Update test_inference.py Co-authored-by: Jerry Jiarui XU <xvjiarui0826@gmail.com>
- Loading branch information
1 parent
1fb54ac
commit 7970e0f
Showing
2 changed files
with
30 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
|
||
# 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) |