Sources#

class deeptrack.sources.base.Sources(*sources: Source)#

Bases: object

Join multiple sources into a single dynamic access point.

Sources is used to combine multiple Source objects into one logical interface. It enables multiple independent sources to share the same features dynamically. This is particularly useful in cases like training/ validation/test splits, where features are defined once and evaluated on different datasets.

When any item from one of the joined sources is activated (i.e., called), the corresponding fields in the Sources object are updated and propagated through the computational graph via SourceDeepTrackNode.

Fields that are not present in the activated item remain unchanged (or None if never set).

Aliased as Join for semantic clarity in different contexts.

Parameters#

*sources: Source

One or more Source instances to join. Each source must have compatible field names (e.g., all sources used with a common feature must define that feature’s required fields).

Attributes#

sources: tuple[Source, …]

The tuple of joined source instances.

_dict: dict[str, Any]

Dictionary used internally to store the currently active values for each field.

Methods#

_callback(item) -> None

Internal method triggered on activation. Updates dynamic fields with the activated item values.

Examples#

>>> import deeptrack as dt
>>> from deeptrack.sources import Source, Sources

Create two disjoint sources:

>>> train = Source(a=[1, 2], b=[10, 20])
>>> val = Source(a=[3, 4], b=[30, 40])

Join them together:

>>> joined = Sources(train, val)

Create a shared feature:

>>> feature = dt.Value(joined.a) + dt.Value(joined.b)

Evaluate on items from different sources:

>>> feature(train[0])
11
>>> feature(train[1])
22
>>> feature(val[0])
33
>>> feature(val[1])
44