torchwrench.nn.functional.multilabel module¶
Helper functions for conversion between classes indices, multihot, multi-names and probabilities for multilabel classification.
-
torchwrench.nn.functional.multilabel.indices_to_multihot(indices: 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 multihot boolean encoding for multilabel classification.
- Args:
indices: List of list of label indices. Values should be integers in range [0..num_classes-1] num_classes: Number maximal of unique classes. padding_idx: Optional pad value to ignore. device: PyTorch device of the output tensor. dtype: PyTorch DType of the output tensor.
-
torchwrench.nn.functional.multilabel.indices_to_multinames(indices: Iterable[int | Iterable[int] | Tensor | ndarray] | Tensor | ndarray, idx_to_name: Mapping[int, T_Name] | SupportsGetitemLen[T_Name, Any], *, padding_idx: int | None =
None) list[source]¶ Convert indices of labels to names using a mapping for multilabel classification.
- Args:
indices: List of list of label indices. idx_to_name: Mapping to convert a class index to its name. padding_idx: Optional pad value to ignore.
-
torchwrench.nn.functional.multilabel.multi_indices_to_multihot(indices: Iterable[int], num_classes: int, *, padding_idx: int | None =
None, device: device | None | 'default' | 'cuda_if_available' | str | int =None) BoolTensor1D[source]¶ -
torchwrench.nn.functional.multilabel.multi_indices_to_multihot(indices: Iterable[Iterable[int]], num_classes: int, *, padding_idx: int | None =
None, device: device | None | 'default' | 'cuda_if_available' | str | int =None) BoolTensor2D -
torchwrench.nn.functional.multilabel.multi_indices_to_multihot(indices: 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 multihot boolean encoding for multilabel classification.
- Args:
indices: List of list of label indices. Values should be integers in range [0..num_classes-1] num_classes: Number maximal of unique classes. padding_idx: Optional pad value to ignore. device: PyTorch device of the output tensor. dtype: PyTorch DType of the output tensor.
-
torchwrench.nn.functional.multilabel.multi_indices_to_multinames(indices: Iterable[int], idx_to_name: Mapping[int, T_Name] | SupportsGetitemLen[T_Name, Any], *, padding_idx: int | None =
None) list[T_Name][source]¶ -
torchwrench.nn.functional.multilabel.multi_indices_to_multinames(indices: Iterable[Iterable[int]], idx_to_name: Mapping[int, T_Name] | SupportsGetitemLen[T_Name, Any], *, padding_idx: int | None =
None) list[list[T_Name]] -
torchwrench.nn.functional.multilabel.multi_indices_to_multinames(indices: Iterable[Iterable[int] | Tensor | ndarray] | Tensor | ndarray, idx_to_name: Mapping[int, T_Name] | SupportsGetitemLen[T_Name, Any], *, padding_idx: int | None =
None) list Convert indices of labels to names using a mapping for multilabel classification.
- Args:
indices: List of list of label indices. idx_to_name: Mapping to convert a class index to its name. padding_idx: Optional pad value to ignore.
-
torchwrench.nn.functional.multilabel.multihot_to_indices(multihot: Tensor | ndarray | Iterable[Tensor | ndarray] | Iterable[bool] | Iterable[Iterable[bool]], *, keep_tensor: bool =
False, padding_idx: int | None =None, dim: int =-1) list | LongTensor | LongTensor1D[source]¶ Convert multihot boolean encoding to indices of labels for multilabel classification.
- Args:
multihot: Multihot labels encoded as 2D matrix. Must be convertible to Tensor. keep_tensor: If True, output will be converted to a tensor if possible. defaults to False. padding_idx: Class index fill value. When none, output will not be padded. defaults to None. dim: Dimension of classes. defaults to -1.
-
torchwrench.nn.functional.multilabel.multihot_to_multi_indices(multihot: Iterable[bool], *, keep_tensor: False =
False, padding_idx: int | None =None, dim: int =-1) list[int][source]¶ -
torchwrench.nn.functional.multilabel.multihot_to_multi_indices(multihot: Iterable[bool], *, keep_tensor: True, padding_idx: int | None =
None, dim: int =-1) LongTensor1D -
torchwrench.nn.functional.multilabel.multihot_to_multi_indices(multihot: Iterable[Iterable[bool]], *, keep_tensor: False =
False, padding_idx: int | None =None, dim: int =-1) list[list[int]] -
torchwrench.nn.functional.multilabel.multihot_to_multi_indices(multihot: Tensor | ndarray | Iterable[Tensor | ndarray], *, keep_tensor: bool =
False, padding_idx: int | None =None, dim: int =-1) list | LongTensor Convert multihot boolean encoding to indices of labels for multilabel classification.
- Args:
multihot: Multihot labels encoded as 2D matrix. Must be convertible to Tensor. keep_tensor: If True, output will be converted to a tensor if possible. defaults to False. padding_idx: Class index fill value. When none, output will not be padded. defaults to None. dim: Dimension of classes. defaults to -1.
-
torchwrench.nn.functional.multilabel.multihot_to_multinames(multihot: Tensor | ndarray | Iterable[Tensor | ndarray] | Iterable[bool] | Iterable[Iterable[bool]], idx_to_name: Mapping[int, T_Name] | Sequence[T_Name], *, dim: int =
-1) list[source]¶ Convert multihot boolean encoding to names using a mapping for multilabel classification.
- Args:
multihot: Multihot 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.multilabel.multinames_to_indices(names: list[list[T_Name]], idx_to_name: Mapping[int, T_Name] | Sequence[T_Name]) list[list[int]][source]¶
Convert names to indices of labels for multilabel classification.
- Args:
names: List of list of label names. idx_to_name: Mapping to convert a class index to its name.
- torchwrench.nn.functional.multilabel.multinames_to_multi_indices(names: list[list[T_Name]], idx_to_name: Mapping[int, T_Name] | Sequence[T_Name]) list[list[int]][source]¶
Convert names to indices of labels for multilabel classification.
- Args:
names: List of list of label names. idx_to_name: Mapping to convert a class index to its name.
-
torchwrench.nn.functional.multilabel.multinames_to_multihot(names: list[list[T_Name]], idx_to_name: Mapping[int, T_Name] | Sequence[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 multihot boolean encoding for multilabel 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.multilabel.probs_to_indices(probs: Tensor | ndarray, threshold: float | Sequence[float] | Tensor | ndarray, *, padding_idx: int | None =
None, dim: int =-1) list | LongTensor[source]¶ Convert matrix of probabilities to indices of labels for multilabel classification.
- Args:
probs: Output probabilities for each classes. threshold: Threshold(s) to binarize probabilities. Can be a scalar or a sequence of (num_classes,) thresholds. padding_idx: Class index fill value. When none, output will not be padded. defaults to None. dim: Dimension of classes. defaults to -1.
-
torchwrench.nn.functional.multilabel.probs_to_multi_indices(probs: Tensor | ndarray, threshold: float | Sequence[float] | Tensor | ndarray, *, padding_idx: int | None =
None, dim: int =-1) list | LongTensor[source]¶ Convert matrix of probabilities to indices of labels for multilabel classification.
- Args:
probs: Output probabilities for each classes. threshold: Threshold(s) to binarize probabilities. Can be a scalar or a sequence of (num_classes,) thresholds. padding_idx: Class index fill value. When none, output will not be padded. defaults to None. dim: Dimension of classes. defaults to -1.
-
torchwrench.nn.functional.multilabel.probs_to_multihot(probs: Tensor | ndarray, threshold: float | Sequence[float] | Tensor | ndarray, *, 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 multihot boolean encoding for multilabel classification.
- Args:
probs: Output probabilities for each class. threshold: Threshold(s) to binarize probabilities. Can be a scalar or a sequence of (num_classes,) thresholds. dim: Dimension of classes. defaults to -1. device: PyTorch device of the output tensor. dtype: PyTorch DType of the output tensor.
- torchwrench.nn.functional.multilabel.probs_to_multinames(probs: Tensor | ndarray, threshold: float | Sequence[float] | Tensor | ndarray, idx_to_name: Mapping[int, T_Name] | Sequence[T_Name]) list[list[T_Name]][source]¶
Convert matrix of probabilities to labels names for multilabel classification.
- Args:
probs: Output probabilities for each classes. threshold: Threshold(s) to binarize probabilities. Can be a scalar or a sequence of (num_classes,) thresholds. idx_to_name: Mapping to convert a class index to its name.