OneOf#

class deeptrack.features.OneOf(collection: Iterable[Feature], key: int | None = None, **kwargs: Dict[str, Any])#

Bases: Feature

Resolves one feature from a collection on the input.

Valid collections are any object that can be iterated (such as lists, tuples, and sets). Internally, the collection is converted to a tuple.

The default behavior is to sample the collection uniformly random. This can be controlled by the key argument, where the feature resolved is chosen as tuple(collection)[key].

Parameters#

collectionIterable[Feature]

A collection of features to choose from.

keyOptional[int], optional

The index of the feature to resolve from the collection. If not provided, a feature is selected randomly.

**kwargsDict[str, Any]

Additional keyword arguments passed to the parent Feature class.

Attributes#

collectionTuple[Feature, …]

The collection of features to choose from, stored as a tuple.

Methods#

get(image, key, _ID=(), **kwargs)

Resolves the selected feature on the input image.

Example#

>>> import numpy as np
>>> from deeptrack.features import OneOf, Add, Multiply

Create a collection of features:

>>> feature_1 = Add(value=10)
>>> feature_2 = Multiply(value=2)
>>> one_of_feature = OneOf([feature_1, feature_2])

Apply the feature randomly to an input image:

>>> input_image = np.array([1, 2, 3])
>>> output_image = one_of_feature(input_image)
>>> print(output_image)  # Output depends on randomly selected feature.

Specify a key to control the selected feature:

>>> controlled_feature = 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])

Resolve the selected feature on the input image.

Methods Documentation

get(image: Any, key: int, _ID: Tuple[int, ...] = (), **kwargs: Dict[str, Any])#

Resolve the selected feature on the input image.

Parameters#

imageAny

The input image to process.

keyint

The index of the feature to apply from the collection.

_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.