File tree Expand file tree Collapse file tree 2 files changed +30
-1
lines changed Expand file tree Collapse file tree 2 files changed +30
-1
lines changed Original file line number Diff line number Diff 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 ():
Original file line number Diff line number Diff line change 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 )
You can’t perform that action at this time.
0 commit comments