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

Method inference

mmseg/models/segmentors/encoder_decoder.py:228–261  ·  view source on GitHub ↗

Inference with slide/whole style. Args: img (Tensor): The input image of shape (N, 3, H, W). img_meta (dict): Image info dict where each dict has: 'img_shape', 'scale_factor', 'flip', and may also contain 'filename', 'ori_shape', 'pad_

(self, img, img_meta, rescale)

Source from the content-addressed store, hash-verified

226 return seg_logit
227
228 def inference(self, img, img_meta, rescale):
229 """Inference with slide/whole style.
230
231 Args:
232 img (Tensor): The input image of shape (N, 3, H, W).
233 img_meta (dict): Image info dict where each dict has: 'img_shape',
234 'scale_factor', 'flip', and may also contain
235 'filename', 'ori_shape', 'pad_shape', and 'img_norm_cfg'.
236 For details on the values of these keys see
237 `mmseg/datasets/pipelines/formatting.py:Collect`.
238 rescale (bool): Whether rescale back to original shape.
239
240 Returns:
241 Tensor: The output segmentation map.
242 """
243
244 assert self.test_cfg.mode in ['slide', 'whole']
245 ori_shape = img_meta[0]['ori_shape']
246 assert all(_['ori_shape'] == ori_shape for _ in img_meta)
247 if self.test_cfg.mode == 'slide':
248 seg_logit = self.slide_inference(img, img_meta, rescale)
249 else:
250 seg_logit = self.whole_inference(img, img_meta, rescale)
251 output = F.softmax(seg_logit, dim=1)
252 flip = img_meta[0]['flip']
253 if flip:
254 flip_direction = img_meta[0]['flip_direction']
255 assert flip_direction in ['horizontal', 'vertical']
256 if flip_direction == 'horizontal':
257 output = output.flip(dims=(3, ))
258 elif flip_direction == 'vertical':
259 output = output.flip(dims=(2, ))
260
261 return output
262
263 def simple_test(self, img, img_meta, rescale=True):
264 """Simple test with single image."""

Callers 2

simple_testMethod · 0.95
aug_testMethod · 0.95

Calls 2

slide_inferenceMethod · 0.95
whole_inferenceMethod · 0.95

Tested by

no test coverage detected