meddlr.ops.categorical_to_one_hot#
- meddlr.ops.categorical_to_one_hot(x, channel_dim: int = 1, background=0, num_categories=None, dtype=None)[source]#
Converts categorical predictions to one-hot encoded predictions.
- Parameters
x (torch.Tensor | np.ndarray) – Categorical array or tensor.
channel_dim (int, optional) – Channel dimension for output tensor.
background (int | NoneType, optional) – The numerical label of the background category. If
None, assumes that the background is a class that should be one-hot encoded.num_categories (int, optional) – Number of categories (excluding background). Defaults to the
max(x) + 1.dtype (type, optional) – Data type of the output. Defaults to boolean (
torch.boolornp.bool).
- Returns
One-hot encoded predictions.
- Return type
torch.Tensor | np.ndarray