MCPcopy Create free account
hub / github.com/devinxzhang/MFuser / inference

Method inference

mmseg/models/segmentors/encoder_decoder.py:243–276  ·  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

241 return seg_logit
242
243 def inference(self, img, img_meta, rescale):
244 """Inference with slide/whole style.
245
246 Args:
247 img (Tensor): The input image of shape (N, 3, H, W).
248 img_meta (dict): Image info dict where each dict has: 'img_shape',
249 'scale_factor', 'flip', and may also contain
250 'filename', 'ori_shape', 'pad_shape', and 'img_norm_cfg'.
251 For details on the values of these keys see
252 `mmseg/datasets/pipelines/formatting.py:Collect`.
253 rescale (bool): Whether rescale back to original shape.
254
255 Returns:
256 Tensor: The output segmentation map.
257 """
258
259 assert self.test_cfg.mode in ['slide', 'whole']
260 ori_shape = img_meta[0]['ori_shape']
261 assert all(_['ori_shape'] == ori_shape for _ in img_meta)
262 if self.test_cfg.mode == 'slide':
263 seg_logit = self.slide_inference(img, img_meta, rescale)
264 else:
265 seg_logit = self.whole_inference(img, img_meta, rescale)
266 output = F.softmax(seg_logit, dim=1)
267 flip = img_meta[0]['flip']
268 if flip:
269 flip_direction = img_meta[0]['flip_direction']
270 assert flip_direction in ['horizontal', 'vertical']
271 if flip_direction == 'horizontal':
272 output = output.flip(dims=(3, ))
273 elif flip_direction == 'vertical':
274 output = output.flip(dims=(2, ))
275
276 return output
277
278 def simple_test(self, img, img_meta, rescale=True):
279 """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