OneOfDict#
- class deeptrack.features.OneOfDict(collection: Dict[Any, Feature], key: Any | None = None, **kwargs: Dict[str, Any])#
Bases:
Feature
Resolve one feature from a dictionary.
This feature selects one feature from a dictionary of features and applies it to the input. By default, the selection is made randomly from the dictionary’s values, but it can be controlled by specifying a key.
Its default behaviour is to sample the values diction uniformly random. This can be controlled by the key argument, where the feature resolved is chosen as collection[key].
Parameters#
- collectionDict[Any, Feature]
A dictionary where keys are identifiers and values are features to choose from.
- keyOptional[Any], optional
The key of the feature to resolve from the dictionary. If not provided, a key is selected randomly.
- **kwargsDict[str, Any]
Additional keyword arguments passed to the parent Feature class.
Attributes#
- collectionDict[Any, Feature]
The dictionary of features to choose from.
Methods#
- get(image, key, _ID=(), **kwargs)
Resolves the selected feature from the dictionary and applies it to the input image.
Example#
>>> import numpy as np >>> from deeptrack.features import OneOfDict, Add, Multiply
Create a dictionary of features:
>>> features_dict = { ... "add": Add(value=10), ... "multiply": Multiply(value=2), ... } >>> one_of_dict_feature = OneOfDict(features_dict)
Apply the feature randomly to an input image:
>>> input_image = np.array([1, 2, 3]) >>> output_image = one_of_dict_feature(input_image) >>> print(output_image) # Output depends on randomly selected feature.
Specify a key to control the selected feature:
>>> controlled_feature = OneOfDict(features_dict, key="add") >>> output_image = controlled_feature(input_image) >>> print(output_image) # Adds 10 to each element.
Methods Summary
get
(image, key[, _ID])Resolve selected feature and applies it to the input image.
Methods Documentation
- get(image: Any, key: Any, _ID: Tuple[int, ...] = (), **kwargs: Dict[str, Any]) Any #
Resolve selected feature and applies it to the input image.
This method resolves the selected feature from the dictionary and applies it to the input image.
Parameters#
- imageAny
The input image to process.
- keyAny
The key of the feature to apply from the dictionary.
- _IDTuple[int, …], optional
A unique identifier for caching and parallel processing.
- **kwargsAny
Additional keyword arguments.
Returns#
- Any
The output of the selected feature applied to the input image.