@@ -149,3 +149,41 @@ def test_multi_scale_flip_aug():
149149 assert tta_results ['scale' ] == [(256 , 256 ), (256 , 256 ), (512 , 512 ),
150150 (512 , 512 ), (1024 , 1024 ), (1024 , 1024 )]
151151 assert tta_results ['flip' ] == [False , True , False , True , False , True ]
152+
153+ # test assertion if flip is True and Pad executed before RandomFlip
154+ with pytest .raises (AssertionError ):
155+ tta_transform = dict (
156+ type = 'MultiScaleFlipAug' ,
157+ img_scale = [(256 , 256 ), (512 , 512 ), (1024 , 1024 )],
158+ img_ratios = None ,
159+ flip = True ,
160+ transforms = [
161+ dict (type = 'Resize' , keep_ratio = False ),
162+ dict (type = 'Pad' , size_divisor = 32 ),
163+ dict (type = 'RandomFlip' ),
164+ ])
165+ tta_module = build_from_cfg (tta_transform , PIPELINES )
166+
167+ tta_transform = dict (
168+ type = 'MultiScaleFlipAug' ,
169+ img_scale = [(256 , 256 ), (512 , 512 ), (1024 , 1024 )],
170+ img_ratios = None ,
171+ flip = True ,
172+ transforms = [
173+ dict (type = 'Resize' , keep_ratio = True ),
174+ dict (type = 'RandomFlip' ),
175+ dict (type = 'Pad' , size_divisor = 32 ),
176+ ])
177+ tta_module = build_from_cfg (tta_transform , PIPELINES )
178+ tta_results = tta_module (results .copy ())
179+ assert tta_results ['scale' ] == [(256 , 256 ), (256 , 256 ), (512 , 512 ),
180+ (512 , 512 ), (1024 , 1024 ), (1024 , 1024 )]
181+ assert tta_results ['flip' ] == [False , True , False , True , False , True ]
182+ assert tta_results ['img_shape' ] == [(144 , 256 , 3 ), (144 , 256 , 3 ),
183+ (288 , 512 , 3 ), (288 , 512 , 3 ),
184+ (576 , 1024 , 3 ), (576 , 1024 , 3 )]
185+ assert tta_results ['pad_shape' ] == [(160 , 256 , 3 ), (160 , 256 , 3 ),
186+ (288 , 512 , 3 ), (288 , 512 , 3 ),
187+ (576 , 1024 , 3 ), (576 , 1024 , 3 )]
188+ for i in range (len (tta_results ['img' ])):
189+ assert tta_results ['img' ][i ].shape == tta_results ['pad_shape' ][i ]
0 commit comments