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#

feature: Feature

The feature to evaluate and store.

key: Any

The key used to identify the stored output.

replace: bool, optional

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

**kwargs:: dict of str to 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.

_store: dict[Any, Image]

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

Methods#

get(_: Any, key: Any, replace: bool, **kwargs: dict[str, Any]) -> Any

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

Examples#

>>> import deeptrack as dt
>>> import numpy as np
>>> value_feature = dt.Value(lambda: np.random.rand())

Create a Store feature with a key: >>> store_feature = dt.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.

key: Any

The key used to identify the stored output.

replace: bool

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

**kwargs: Any

Additional keyword arguments passed to the feature.

Returns#

Any

The stored output or a newly computed result.