Store#

class deeptrack.features.Store(feature: Feature, key: Any, replace: bool = False, **kwargs: Dict[str, Any])#

Bases: Feature

Stores the output of a feature for reuse.

The Store feature evaluates a given feature and stores its output in an internal dictionary. Subsequent calls with the same key will return the stored value unless the replace parameter is set to True. This enables caching and reuse of computed feature outputs.

Parameters#

featureFeature

The feature to evaluate and store.

keyAny

The key used to identify the stored output.

replacebool, optional

If True, replaces the stored value with a new computation. Defaults to False.

**kwargsDict[str, Any]

Additional keyword arguments passed to the parent Feature class.

Attributes#

__distributed__bool

Indicates whether this feature distributes computation across inputs. Always False for Store, as it handles caching locally.

_storeDict[Any, Image]

A dictionary used to store the outputs of the evaluated feature.

Example#

>>> import numpy as np
>>> from deeptrack.features import Store, Value
>>> value_feature = Value(lambda: np.random.rand())

Create a Store feature with a key:

>>> store_feature = Store(feature=value_feature, key="example")

Retrieve and store the value:

>>> output = store_feature(None, key="example", replace=False)

Retrieve the stored value without recomputing:

>>> value_feature.update()
>>> cached_output = store_feature(None, key="example", replace=False)
>>> print(cached_output == output)
True

Retrieve the stored value recomputing:

>>> value_feature.update()
>>> cached_output = store_feature(None, key="example", replace=True)
>>> print(cached_output == output)
False

Methods Summary

get(_, key, replace, **kwargs)

Evaluate and store the feature output, or return the cached result.

Methods Documentation

get(_: Any, key: Any, replace: bool, **kwargs: Dict[str, Any]) Any#

Evaluate and store the feature output, or return the cached result.

Parameters#

_Any

Placeholder for unused image input.

keyAny

The key used to identify the stored output.

replacebool

If True, replaces the stored value with a new computation.

**kwargsAny

Additional keyword arguments passed to the feature.

Returns#

Any

The stored output or a newly computed result.