MCPcopy Create free account
hub / github.com/VCIP-RGBD/DFormer / inference

Method inference

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

207 return seg_logit
208
209 def inference(self, img, img_meta, rescale):
210 """Inference with slide/whole style.
211
212 Args:
213 img (Tensor): The input image of shape (N, 3, H, W).
214 img_meta (dict): Image info dict where each dict has: 'img_shape',
215 'scale_factor', 'flip', and may also contain
216 'filename', 'ori_shape', 'pad_shape', and 'img_norm_cfg'.
217 For details on the values of these keys see
218 `mmseg/datasets/pipelines/formatting.py:Collect`.
219 rescale (bool): Whether rescale back to original shape.
220
221 Returns:
222 Tensor: The output segmentation map.
223 """
224
225 assert self.test_cfg.mode in ["slide", "whole"]
226 ori_shape = img_meta[0]["ori_shape"]
227 assert all(_["ori_shape"] == ori_shape for _ in img_meta)
228 if self.test_cfg.mode == "slide":
229 seg_logit = self.slide_inference(img, img_meta, rescale)
230 else:
231 seg_logit = self.whole_inference(img, img_meta, rescale)
232 if self.out_channels == 1:
233 output = F.sigmoid(seg_logit)
234 else:
235 output = F.softmax(seg_logit, dim=1)
236 flip = img_meta[0]["flip"]
237 if flip:
238 flip_direction = img_meta[0]["flip_direction"]
239 assert flip_direction in ["horizontal", "vertical"]
240 if flip_direction == "horizontal":
241 output = output.flip(dims=(3,))
242 elif flip_direction == "vertical":
243 output = output.flip(dims=(2,))
244
245 return output
246
247 def simple_test(self, img, img_meta, rescale=True):
248 """Simple test with single image."""

Callers 4

simple_testMethod · 0.95
simple_test_logitsMethod · 0.95
aug_testMethod · 0.95
aug_test_logitsMethod · 0.95

Calls 2

slide_inferenceMethod · 0.95
whole_inferenceMethod · 0.95

Tested by

no test coverage detected