torchwrench.nn.functional.multiclass module¶
Helper functions for conversion between classes indices, onehot, names and probabilities for multiclass classification.
- torchwrench.nn.functional.multiclass.index_to_name(index: ~typing.Sequence[int] | ~torch.Tensor | ~numpy.ndarray | ~typing.Sequence, idx_to_name: ~typing.Mapping[int, __SPHINX_IMMATERIAL_TYPE_VAR__V_T_Name] | ~typing.Iterable[__SPHINX_IMMATERIAL_TYPE_VAR__V_T_Name], *, is_number_fn: ~typing.Callable[[~typing.Any], bool] = <function is_number_like>) list[T_Name][source]¶
Convert indices of labels to names using a mapping for multiclass classification.
- Args:
indices: List of list of label indices. idx_to_name: Mapping to convert a class index to its name. is_number_fn: Type guard to check if a value is a scalar number. defaults to is_number_like.
-
torchwrench.nn.functional.multiclass.index_to_onehot(index: Iterable[int], num_classes: int, *, padding_idx: int | None =
None, device: device | None | 'default' | 'cuda_if_available' | str | int =None) BoolTensor2D[source]¶ -
torchwrench.nn.functional.multiclass.index_to_onehot(index: Iterable[Iterable[int]], num_classes: int, *, padding_idx: int | None =
None, device: device | None | 'default' | 'cuda_if_available' | str | int =None) BoolTensor3D -
torchwrench.nn.functional.multiclass.index_to_onehot(index: Iterable, num_classes: int, *, padding_idx: int | None =
None, device: device | None | 'default' | 'cuda_if_available' | str | int =None, dtype: dtype | None | 'default' | str | DTypeEnum =torch.bool) Tensor Convert indices of labels to onehot boolean encoding for multiclass classification.
- Args:
- indices: List label indices.
Can be a nested list of indices, but it should be convertible to Tensor.
num_classes: Number maximal of unique classes. padding_idx: Class index to ignore. Output will contains only zeroes for this value. defaults to None. device: PyTorch device of the output tensor. dtype: PyTorch DType of the output tensor.
- torchwrench.nn.functional.multiclass.name_to_index(name: list[T_Name], idx_to_name: Mapping[int, T_Name] | Iterable[T_Name]) Tensor[source]¶
Convert names to indices of labels for multiclass classification.
- Args:
names: List of list of label names. idx_to_name: Mapping to convert a class index to its name.
-
torchwrench.nn.functional.multiclass.name_to_onehot(name: list[T_Name], idx_to_name: Mapping[int, T_Name] | SupportsIterLen[T_Name], *, device: device | None | 'default' | 'cuda_if_available' | str | int =
None, dtype: dtype | None | 'default' | str | DTypeEnum =torch.bool) Tensor[source]¶ Convert names to onehot boolean encoding for multiclass classification.
- Args:
names: List of list of label names. idx_to_name: Mapping to convert a class index to its name. device: PyTorch device of the output tensor. dtype: PyTorch DType of the output tensor.
-
torchwrench.nn.functional.multiclass.one_hot(index: Iterable, num_classes: int, *, padding_idx: int | None =
None, device: device | None | 'default' | 'cuda_if_available' | str | int =None, dtype: dtype | None | 'default' | str | DTypeEnum =torch.bool) Tensor[source]¶ Convert indices of labels to onehot boolean encoding for multiclass classification.
- Args:
- indices: List label indices.
Can be a nested list of indices, but it should be convertible to Tensor.
num_classes: Number maximal of unique classes. padding_idx: Class index to ignore. Output will contains only zeroes for this value. defaults to None. device: PyTorch device of the output tensor. dtype: PyTorch DType of the output tensor.
-
torchwrench.nn.functional.multiclass.onehot_to_index(onehot: T_TensorOrArray, *, padding_idx: int | None =
None, dim: int =-1) T_TensorOrArray[source]¶ Convert onehot boolean encoding to indices of labels for multiclass classification.
- Args:
onehot: Onehot labels encoded as 2D matrix. padding_idx: Class index placeholder when input contains only zeroes. defaults to None. dim: Dimension of classes. defaults to -1.
-
torchwrench.nn.functional.multiclass.onehot_to_name(onehot: Tensor, idx_to_name: Mapping[int, T_Name] | Iterable[T_Name], *, dim: int =
-1) list[T_Name][source]¶ Convert onehot boolean encoding to names using a mapping for multiclass classification.
- Args:
onehot: Onehot labels encoded as 2D matrix. idx_to_name: Mapping to convert a class index to its name. dim: Dimension of classes. defaults to -1.
-
torchwrench.nn.functional.multiclass.probs_to_index(probs: Tensor, *, dim: int =
-1) LongTensor[source]¶ Convert matrix of probabilities to indices of labels for multiclass classification.
- Args:
probs: Output probabilities for each classes. dim: Dimension of classes. defaults to -1.
-
torchwrench.nn.functional.multiclass.probs_to_name(probs: Tensor, idx_to_name: Mapping[int, T_Name] | Iterable[T_Name], *, dim: int =
-1) list[T_Name][source]¶ Convert matrix of probabilities to labels names for multiclass classification.
- Args:
probs: Output probabilities for each classes. idx_to_name: Mapping to convert a class index to its name. dim: Dimension of classes. defaults to -1.
-
torchwrench.nn.functional.multiclass.probs_to_onehot(probs: Tensor, *, dim: int =
-1, device: device | None | 'default' | 'cuda_if_available' | str | int =None, dtype: dtype | None | 'default' | str | DTypeEnum =torch.bool) Tensor[source]¶ Convert matrix of probabilities to onehot boolean encoding for multiclass classification.
- Args:
probs: Output probabilities for each classes. dim: Dimension of classes. defaults to -1. device: PyTorch device of the output tensor. dtype: PyTorch DType of the output tensor.