Chain#

class deeptrack.features.Chain(feature_1: Feature, feature_2: Feature, **kwargs: Any)#

Bases: StructuralFeature

Resolve two features sequentially.

Chain applies two features sequentially: the outputs of feature_1 are passed as inputs to feature_2. This allows combining simple operations into complex pipelines.

The use of Chain

>>> dt.Chain(A, B)

is equivalent to using the >> operator

>>> A >> B

Parameters#

feature_1: Feature

The first feature in the chain. Its outputs are passed to feature_2.

feature_2: Feature

The second feature in the chain proceses the outputs from feature_1.

**kwargs: Any, optional

Additional keyword arguments passed to the parent StructuralFeature (and, therefore, Feature).

Attributes#

feature_1: Feature

The first feature in the chain. Its outputs are passed to feature_2.

feature_2: Feature

The second feature in the chain processes the outputs from feature_1.

Methods#

get(inputs, _ID, **kwargs) -> Any

Apply the two features in sequence on the given inputs.

Examples#

>>> import deeptrack as dt

Create a feature chain where the first feature adds a constant offset, and the second feature multiplies the result by a constant:

>>> A = dt.Add(b=10)
>>> M = dt.Multiply(b=0.5)
>>>
>>> chain = A >> M

Equivalent to:

>>> chain = dt.Chain(A, M)

Create a dummy image:

>>> import numpy as np
>>>
>>> dummy_image = np.zeros((2, 4))

Apply the chained features:

>>> chain(dummy_image)
array([[5., 5., 5., 5.],
       [5., 5., 5., 5.]])

Methods Summary

get(inputs[, _ID])

Apply the two features sequentially to the given inputs.

Methods Documentation

get(inputs: Any, _ID: tuple[int, ...] = (), **kwargs: Any) Any#

Apply the two features sequentially to the given inputs.

This method first applies feature_1 to the inputs and then passes the outputs through feature_2.

Parameters#

inputs: Any

The input data to transform sequentially. Most typically, this is a NumPy array or a PyTorch tensor.

_ID: tuple[int, …], optional

A unique identifier for caching or parallel execution. Defaults to an empty tuple.

**kwargs: Any

Additional parameters passed to or sampled by the features. These are unused here, as each sub-feature fetches its required properties internally.

Returns#

Any

The final outputs after feature_1 and then feature_2 have processed the inputs.