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

Function predict_segmentation

monai/networks/utils.py:223–240  ·  view source on GitHub ↗

Given the logits from a network, computing the segmentation by thresholding all values above 0 if multi-labels task, computing the `argmax` along the channel axis if multi-classes task, logits has shape `BCHW[D]`. Args: logits: raw data of model output. mutually_exc

(logits: torch.Tensor, mutually_exclusive: bool = False, threshold: float = 0.0)

Source from the content-addressed store, hash-verified

221
222
223def predict_segmentation(logits: torch.Tensor, mutually_exclusive: bool = False, threshold: float = 0.0) -> Any:
224 """
225 Given the logits from a network, computing the segmentation by thresholding all values above 0
226 if multi-labels task, computing the `argmax` along the channel axis if multi-classes task,
227 logits has shape `BCHW[D]`.
228
229 Args:
230 logits: raw data of model output.
231 mutually_exclusive: if True, `logits` will be converted into a binary matrix using
232 a combination of argmax, which is suitable for multi-classes task. Defaults to False.
233 threshold: thresholding the prediction values if multi-labels task.
234 """
235 if not mutually_exclusive:
236 return (logits >= threshold).int()
237 if logits.shape[1] == 1:
238 warnings.warn("single channel prediction, `mutually_exclusive=True` ignored, use threshold instead.")
239 return (logits >= threshold).int()
240 return logits.argmax(1, keepdim=True)
241
242
243def normalize_transform(

Callers 1

Calls

no outgoing calls

Tested by 1

Used in the wild real call sites across dependent graphs

searching dependent graphs…