meddlr.ops.one_hot_to_categorical#

meddlr.ops.one_hot_to_categorical(x, channel_dim: int = 1, background=False)[source]#

Converts one-hot encoded predictions to categorical predictions.

Parameters
  • x (torch.Tensor | np.ndarray) – One-hot encoded predictions.

  • channel_dim (int, optional) – Channel dimension. Defaults to 1 (i.e. (B,C,...)).

  • background (bool, optional) – If True, assumes index 0 in the channel dimension is the background.

Returns

Categorical array or tensor. If background=False, the output will be 1-indexed such that 0 corresponds to the background.

Return type

torch.Tensor | np.ndarray