OneOfDict#
- class deeptrack.features.OneOfDict(collection: dict[Any, Feature], key: Any | None = None, **kwargs: dict[str, Any])#
Bases:
FeatureResolve one feature from a dictionary and apply it to an input.
This feature selects a feature from a dictionary and applies it to an input. The selection is made randomly by default, but it can be controlled using the key argument.
If key is not specified, a random key from the dictionary is selected, and the corresponding feature is applied. Otherwise, the feature mapped to key is resolved.
Parameters#
- collection: dict[Any, Feature]
A dictionary where keys are identifiers and values are features.
- key: Any | None, optional
The key of the feature to resolve from the dictionary. If None, a random key is selected.
- **kwargs: dict of str to Any
Additional parameters passed to the parent Feature class.
Attributes#
- __distributed__: bool
Indicates whether this feature distributes computation across inputs.
Methods#
- _process_properties(propertydict: dict) -> dict
Determines which feature to use based on key.
- get(image: Any, key: Any, _ID: tuple[int, …], **kwargs: dict[str, Any]) -> Any
Resolves the selected feature and applies it to the input image.
Examples#
>>> import deeptrack as dt >>> import numpy as np
Define a dictionary of features: >>> features_dict = { … “add”: dt.Add(value=10), … “multiply”: dt.Multiply(value=2), … } >>> one_of_dict_feature = dt.OneOfDict(features_dict)
Apply a randomly selected feature: >>> input_image = np.array([1, 2, 3]) >>> output_image = one_of_dict_feature(input_image) >>> print(output_image)
Use a specific key to apply a predefined feature: >>> controlled_feature = dt.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 the selected feature and apply it to the input.
Methods Documentation
- get(image: Any, key: Any, _ID: tuple[int, ...] = (), **kwargs: dict[str, Any]) Any#
Resolve the selected feature and apply it to the input.
Parameters#
- image: Any
The input image or data to be processed.
- key: Any
The key of the feature to apply from the dictionary.
- _ID: tuple[int, …], optional
A unique identifier for caching and parallel execution.
- **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.