Skip to main content

Static Input Capture

Overview

Static (memory) model inputs resolve their tensor data through StaticInputSourceVariant:

  • DataManager — re-encode from a DataManager key at current_frame + time_offset on every assembleInputs() call.
  • DataBank — reuse a pre-encoded tensor from a named session bank entry.

The DataBank path avoids repeated encoding for reference frames that do not change across inference runs. Capture APIs populate the bank; binding metadata records which entry each static position uses.

See DataBank for storage types and Memory Frame Bindings for the binding model.

Capture API: src/WhiskerToolbox/DeepLearning_Widget/Core/SlotAssembler.hpp
Capture UI: src/WhiskerToolbox/DeepLearning_Widget/UI/DataBank/DataBankPropertiesWidget.hpp
Binding UI: src/WhiskerToolbox/DeepLearning_Widget/UI/Helpers/MemorySlotWidget.hpp

Static source configuration

In MemorySlotWidget

Each static position uses StaticFrameSourceForm:

static_source Fields Assembly behavior
DataManagerStaticSource data_key, time_offset Encode at current_frame + time_offset
DataBankStaticSource bank_entry_id Copy DataBank::getEncoded(bank_entry_id); when empty, resolvedBankEntryId() falls back to {slot_name}_{memory_index}

hasActiveStaticSource() requires a non-empty data_key (DataManager) or a resolvable bank entry ID (DataBank).

Default bank entry IDs

defaultBankEntryId(slot_name, memory_index) produces keys like memory_masks_0. DataBankPropertiesWidget uses this convention by default; MemorySlotWidget populates bank_entry_id combos from current bank contents via refreshBankEntries().

Capture API

captureToBank()

bool captureToBank(
    DataManager & dm,
    std::string const & bank_entry_id,
    dl::MemoryFrameBinding const & entry,
    int frame,
    ImageSize source_image_size);

Fetches geometry from DataManager, stores the raw source via DataBank::putSource(), then channel-encodes via DataBank::encodeEntry().

Requirements:

  • Model loaded (isModelReady())
  • bank_entry_id passes dl::validateEntryId()
  • dl::staticDataKey(entry) non-empty (entry must describe a DataManager source)
  • Target slot exists and is_static

DataBankPropertiesWidget builds a temporary binding with dl::makeCaptureBinding(slot_name, memory_index, data_key) and passes an explicit bank_entry_id.

captureStaticInput()

Convenience wrapper that calls captureToBank() using entry.resolvedBankEntryId() as the bank key. Used by recurrent StaticCaptureInit when no pre-existing bank tensor is available.

Preview API

The view panel queries SlotAssembler::dataBank():

  • ids() filtered by entries with encoded tensors — previewable entries
  • encodedShape() / encodedRange() — tensor metadata for display
  • DataBankEntryMetadata — provenance (data_key, captured_frame, source_image_size, encoder_factory_name)

DeepLearningPropertiesWidget::dataBankChanged triggers DeepLearningViewWidget::refreshDataBankView() and _refreshBankEntryCombos() on memory slot widgets.

Data flow

Properties-panel capture

1. User selects target slot + memory index in DataBankPropertiesWidget
2. Entry ID defaults to {slot_name}_{memory_index}
3. User chooses a DataManager data source
4. "Capture Current Frame" → captureToBank()
5. dataBankChanged → refresh view + bank_entry_id combos
6. User sets static position source to DataBank (or leaves default entry ID)
7. assembleInputs() copies getEncoded() — no re-encoding

Recurrent StaticCaptureInit

At t=0 of runRecurrentSequence(), StaticCaptureInit may use:

  • An existing DataBank tensor at the same memory_index (if a static binding points there), or
  • defaultBankEntryId, or
  • On-the-fly captureStaticInput() from the init’s data_key / frame

See Recurrent Inputs.

Cache invalidation

DataBank entries are invalidated when:

  1. Explicit removal — dataBank().remove(id) or clearDataBank()
  2. Re-capture — captureToBank() overwrites an existing entry with the same ID

resetModel() does not clear the DataBank (session-scoped across model switches).

Changing a static binding’s data_key or bank_entry_id in the UI does not automatically remove bank entries — stale entries remain until explicitly removed or overwritten.

Serialization

MemoryFrameBinding metadata (including nested StaticInputSourceVariant and RecurrentInitVariant) serializes via reflect-cpp as part of DeepLearningStateData::memory_frames.

Encoded tensors in the DataBank are not serialized — they must be re-captured after workspace restore.