MCPcopy Create free account
hub / github.com/Project-MONAI/MONAI / _initialize_mergers

Method _initialize_mergers

monai/inferers/inferer.py:252–278  ·  view source on GitHub ↗
(self, inputs, outputs, patches, batch_size)

Source from the content-addressed store, hash-verified

250 return self._ensure_tuple_outputs(outputs)
251
252 def _initialize_mergers(self, inputs, outputs, patches, batch_size):
253 in_patch = torch.chunk(patches, batch_size)[0]
254 mergers = []
255 ratios = []
256 for out_patch_batch in outputs:
257 out_patch = torch.chunk(out_patch_batch, batch_size)[0]
258 # calculate the ratio of input and output patch sizes
259 ratio = tuple(op / ip for ip, op in zip(in_patch.shape[2:], out_patch.shape[2:]))
260
261 # calculate merged_shape and cropped_shape
262 merger_kwargs = self.merger_kwargs.copy()
263 cropped_shape, merged_shape = self._get_merged_shapes(inputs, out_patch, ratio)
264 if "merged_shape" not in merger_kwargs:
265 merger_kwargs["merged_shape"] = merged_shape
266 if merger_kwargs["merged_shape"] is None:
267 raise ValueError("`merged_shape` cannot be `None`.")
268 if "cropped_shape" not in merger_kwargs:
269 merger_kwargs["cropped_shape"] = cropped_shape
270
271 # initialize the merger
272 merger = self.merger_cls(**merger_kwargs)
273
274 # store mergers and input/output ratios
275 mergers.append(merger)
276 ratios.append(ratio)
277
278 return mergers, ratios
279
280 def _aggregate(self, outputs, locations, batch_size, mergers, ratios):
281 for output_patches, merger, ratio in zip(outputs, mergers, ratios):

Callers 1

__call__Method · 0.95

Calls 2

_get_merged_shapesMethod · 0.95
appendMethod · 0.45

Tested by

no test coverage detected