monai.networks.utils module¶
Utilities and types for defining networks, these depend on PyTorch.
-
one_hot
(labels, num_classes)[source]¶ For a tensor labels of dimensions B1[spatial_dims], return a tensor of dimensions BN[spatial_dims] for num_classes N number of classes.
Example
For every value v = labels[b,1,h,w], the value in the result at [b,v,h,w] will be 1 and all others 0. Note that this will include the background label, thus a binary mask should be treated as having 2 classes.
-
predict_segmentation
(logits, mutually_exclusive=False, threshold=0)[source]¶ 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].
- Parameters
logits (Tensor) – raw data of model output.
mutually_exclusive (bool) – if True, logits will be converted into a binary matrix using a combination of argmax, which is suitable for multi-classes task. Defaults to False.
threshold (float) – thresholding the prediction values if multi-labels task.