MCPcopy Create free account
hub / github.com/NVlabs/SegFormer / _test_encoder_decoder_forward

Function _test_encoder_decoder_forward

tests/test_models/test_forward.py:211–250  ·  view source on GitHub ↗
(cfg_file)

Source from the content-addressed store, hash-verified

209 _check_input_dim)
210@patch('torch.distributed.get_world_size', get_world_size)
211def _test_encoder_decoder_forward(cfg_file):
212 model = _get_segmentor_cfg(cfg_file)
213 model['pretrained'] = None
214 model['test_cfg']['mode'] = 'whole'
215
216 from mmseg.models import build_segmentor
217 segmentor = build_segmentor(model)
218
219 if isinstance(segmentor.decode_head, nn.ModuleList):
220 num_classes = segmentor.decode_head[-1].num_classes
221 else:
222 num_classes = segmentor.decode_head.num_classes
223 # batch_size=2 for BatchNorm
224 input_shape = (2, 3, 32, 32)
225 mm_inputs = _demo_mm_inputs(input_shape, num_classes=num_classes)
226
227 imgs = mm_inputs.pop('imgs')
228 img_metas = mm_inputs.pop('img_metas')
229 gt_semantic_seg = mm_inputs['gt_semantic_seg']
230
231 # convert to cuda Tensor if applicable
232 if torch.cuda.is_available():
233 segmentor = segmentor.cuda()
234 imgs = imgs.cuda()
235 gt_semantic_seg = gt_semantic_seg.cuda()
236 else:
237 segmentor = _convert_batchnorm(segmentor)
238
239 # Test forward train
240 losses = segmentor.forward(
241 imgs, img_metas, gt_semantic_seg=gt_semantic_seg, return_loss=True)
242 assert isinstance(losses, dict)
243
244 # Test forward test
245 with torch.no_grad():
246 segmentor.eval()
247 # pack into lists
248 img_list = [img[None, :] for img in imgs]
249 img_meta_list = [[img_meta] for img_meta in img_metas]
250 segmentor.forward(img_list, img_meta_list, return_loss=False)

Callers 15

test_pspnet_forwardFunction · 0.85
test_fcn_forwardFunction · 0.85
test_deeplabv3_forwardFunction · 0.85
test_gcnet_forwardFunction · 0.85
test_ann_forwardFunction · 0.85
test_ccnet_forwardFunction · 0.85
test_danet_forwardFunction · 0.85
test_upernet_forwardFunction · 0.85
test_hrnet_forwardFunction · 0.85
test_ocrnet_forwardFunction · 0.85

Calls 5

build_segmentorFunction · 0.90
_get_segmentor_cfgFunction · 0.85
_demo_mm_inputsFunction · 0.70
_convert_batchnormFunction · 0.70
forwardMethod · 0.45

Tested by

no test coverage detected