Value#

class deeptrack.features.Value(value: Any | Callable[[...], Any], **kwargs: Any)#

Bases: Feature

Represent a constant value in a DeepTrack2 pipeline.

Value holds a constant value (e.g., a scalar or array) and supplies it on demand to other parts of the pipeline.

If called with an input, it ignores it and still returns the stored value.

Parameters#

value: PropertyLike[Any], optional

The value to store. Defaults to 0.

**kwargs: Any

Additional named properties passed to the Feature constructor.

Attributes#

__distributed__: bool

Set to False, indicating that this feature’s .get() method processes the entire input at once even if it is a list, rather than distributing calls for each item of the list.

Methods#

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

Returns the stored value, ignoring the inputs.

Examples#

>>> import deeptrack as dt

Initialize a constant value and retrieve it:

>>> value = dt.Value(42)
>>> value()
42

Override the value at call time:

>>> value(value=100)
100

Initialize a constant array value and retrieve it:

>>> import numpy as np
>>>
>>> arr_value = dt.Value(np.arange(4))
>>> arr_value()
array([0, 1, 2, 3])

Override the array value at call time:

>>> arr_value(value=np.array([10, 20, 30, 40]))
array([10, 20, 30, 40])

Initialize a constant PyTorch tensor value and retrieve it:

>>> import torch
>>>
>>> tensor_value = dt.Value(torch.tensor([1., 2., 3.]))
>>> tensor_value()
tensor([1., 2., 3.])

Override the tensor value at call time:

>>> tensor_value(value=torch.tensor([10., 20., 30.]))
tensor([10., 20., 30.])

Methods Summary

get(inputs, value, **kwargs)

Return the stored value, ignoring the inputs.

Methods Documentation

get(inputs: Any, value: Any, **kwargs: Any) Any#

Return the stored value, ignoring the inputs.

The .get() method simply returns the stored numerical value, allowing for dynamic overrides when the feature is called.

Parameters#

inputs: Any

Value ignores its input data.

value: Any

The current value to return. This may be the initial value or an overridden value supplied during the method call.

**kwargs: Any

Additional keyword arguments, which are ignored but included for consistency with the Feature interface.

Returns#

Any

The stored or overridden value, returned unchanged.