OneHot#
- class deeptrack.features.OneHot(num_classes: int, **kwargs: Dict[str, Any])#
Bases:
Feature
Converts 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_classesint
The total number of classes for the one-hot encoding.
- **kwargsDict[str, Any]
Additional keyword arguments passed to the parent Feature class.
Example#
>>> import numpy as np >>> from deeptrack.features import OneHot
Create an input array of class labels:
>>> input_data = np.array([0, 1, 2])
Apply a OneHot feature:
>>> one_hot_feature = 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 class 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 class labels into a one-hot encoded array.
Parameters#
- imagenp.ndarray
The input array of class labels. The last dimension should contain integers representing class indices.
- num_classesint
The total number of classes for the one-hot encoding.
- **kwargsAny
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.