OneHot#
- class deeptrack.features.OneHot(num_classes: int, **kwargs: dict[str, Any])#
Bases:
FeatureConverts the input to a one-hot encoded array.
This feature takes an input array of integer class labels and converts it into a one-hot encoded array. The last dimension of the input is replaced by the one-hot encoding.
Parameters#
- num_classes: int
The total number of classes for the one-hot encoding.
- **kwargs:: dict of str to Any
Additional keyword arguments passed to the parent Feature class.
Methods#
- get(image: np.ndarray, num_classes: int, **kwargs: dict[str, Any]) -> np.ndarray
Convert the input array of class labels into a one-hot encoded array.
Examples#
>>> import deeptrack as dt >>> import numpy as np
Create an input array of class labels: >>> input_data = np.array([0, 1, 2])
Apply a OneHot feature: >>> one_hot_feature = dt.OneHot(num_classes=3) >>> one_hot_feature = dt.OneHot(num_classes=3) >>> one_hot_encoded = one_hot_feature.get(input_data, num_classes=3) >>> print(one_hot_encoded) [[1. 0. 0.]
[0. 1. 0.] [0. 0. 1.]]
Methods Summary
get(image, num_classes, **kwargs)Convert the input array of labels into a one-hot encoded array.
Methods Documentation
- get(image: ndarray, num_classes: int, **kwargs: dict[str, Any]) ndarray#
Convert the input array of labels into a one-hot encoded array.
Parameters#
- image: np.ndarray
The input array of class labels. The last dimension should contain integers representing class indices.
- num_classes: int
The total number of classes for the one-hot encoding.
- **kwargs: Any
Additional keyword arguments (unused here).
Returns#
- np.ndarray
The one-hot encoded array. The last dimension is replaced with one-hot vectors of length num_classes.