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.