OneOf#
- class deeptrack.features.OneOf(collection: Iterable[Feature], key: int | None = None, **kwargs: dict[str, Any])#
Bases:
FeatureResolves one feature from a given collection.
This feature selects and applies one of multiple features from a given collection. The default behavior selects a feature randomly, but this behavior can be controlled by specifying a key, which determines the index of the feature to apply.
The collection should be an iterable (e.g., list, tuple, or set), and it will be converted to a tuple internally to ensure consistent indexing.
Parameters#
- collection: Iterable[Feature]
A collection of features to choose from.
- key: int | None, optional
The index of the feature to resolve from the collection. If not provided, a feature is selected randomly at each execution.
- **kwargs: dict of str to Any
Additional keyword arguments passed to the parent Feature class.
Attributes#
- __distributed__: bool
Indicates whether this feature distributes computation across inputs.
Methods#
- _process_properties(propertydict: dict) -> dict
Processes the properties to determine the selected feature index.
- get(image: Any, key: int, _ID: tuple[int, …], **kwargs: dict[str, Any]) -> Any
Applies the selected feature to the input image.
Examples#
>>> import deeptrack as dt >>> import numpy as np
Define multiple features: >>> feature_1 = dt.Add(value=10) >>> feature_2 = dt.Multiply(value=2)
Create a OneOf feature that randomly selects a transformation: >>> one_of_feature = dt.OneOf([feature_1, feature_2])
Apply it to an input image: >>> input_image = np.array([1, 2, 3]) >>> output_image = one_of_feature(input_image) >>> print(output_image) # The output depends on the randomly selected feature.
Use a key to apply a specific feature: >>> controlled_feature = dt.OneOf([feature_1, feature_2], key=0) >>> output_image = controlled_feature(input_image) >>> print(output_image) # Adds 10 to each element.
Methods Summary
get(image, key[, _ID])Apply the selected feature to the input image.
Methods Documentation
- get(image: Any, key: int, _ID: tuple[int, ...] = (), **kwargs: dict[str, Any]) Any#
Apply the selected feature to the input image.
Parameters#
- image: Any
The input image or data to process.
- key: int
The index of the feature to apply from the collection.
- _ID: tuple[int, …], optional
A unique identifier for caching and parallel processing.
- **kwargs: dict of str to Any
Additional parameters passed to the selected feature.
Returns#
- Any
The output of the selected feature applied to the input image.