DataBank
Overview
dl::DataBank provides a DataManager-independent named store for geometry sources and channel-encoded tensors. It holds pre-encoded static (memory) model inputs that can be reused across inference runs without re-fetching from DataManager on every forward pass.
Encoded tensors use libtorch (at::Tensor); geometry sources use EncodingSourceVariant from EncoderDispatch.
Location: src/DeepLearning/storage/
| File | Role |
|---|---|
DataBankEntry.hpp |
DataBankEntry, DataBankEntryMetadata |
DataBank.hpp / DataBank.cpp |
Named entry library |
DataBankEncode.hpp / DataBankEncode.cpp |
Standalone encoding helpers |
Types
DataBankEntryMetadata
Provenance recorded at capture time:
| Field | Purpose |
|---|---|
label |
Optional UI display name |
data_key |
DataManager key the source was captured from |
captured_frame |
Frame index in that object’s timebase (-1 if unknown) |
source_image_size |
Original image dimensions for geometry scaling |
encoder_factory_name |
Encoder used when encoding (e.g. "Mask2DEncoder") |
DataBankEntry
| Member | Purpose |
|---|---|
source |
Optional raw EncodingSourceVariant (mask, point, line, image) |
encoded |
Optional channel-encoded tensor with batch dimension = 1 |
metadata |
Provenance fields above |
DataBank
Keyed library of entries. Default capacity: kDefaultMaxEntries (64). New put* operations fail when the limit is reached (unless overwriting an existing ID).
Entry ID validation
validateEntryId(id) rejects:
- Empty strings
- Whitespace-only strings
- Any internal whitespace
:(reserved for legacy slot-bound cache keys)
Returns std::optional<std::string> — engaged value is an error message.
API
| Method | Purpose |
|---|---|
contains(id) |
Whether an entry exists |
get(id) |
Copy of full entry |
getEncoded(id) / getSource(id) |
Lookup helpers |
putSource(id, source, metadata) |
Store raw geometry/image only |
putEncoded(id, tensor, metadata, source?) |
Store encoded tensor; optional source retained |
encodeEntry(id, slot, encoder_params) |
Encode stored source in place via EncoderDispatch |
remove(id) / clear() |
Delete one or all entries |
ids() / size() / maxEntries() |
Inventory |
encodedShape(id) / encodedRange(id) |
UI preview helpers |
putEncoded requires the tensor to be defined with leading batch size 1.
Encoding helpers (DataBankEncode.hpp)
Free functions usable without storing in a bank:
| Function | Purpose |
|---|---|
perElementShape(slot) |
Shape of one sequence element (requires sequence_dim >= 0) |
encodingShapeForSlot(slot) |
Shape passed to encoders (strips sequence axis when present) |
makeEncoderContext(slot, batch_index) |
Build EncoderContext from encoding shape |
encodeSourceToTensor(source, slot, encoder, source_image_size) |
Allocate {1, ...} tensor and encode |
Provenance
metadata.data_key and metadata.captured_frame record where an entry was captured. Widget code can use these to re-fetch the same DataManager object when refreshing UI, even though the bank itself does not depend on DataManager at read time.
Session binding
Static memory positions choose a source via StaticInputSourceVariant (see Memory frame bindings):
| Source | Binding fields | Assembly behaviour |
|---|---|---|
DataManager |
data_key, time_offset |
Re-encode from DataManager each run |
DataBank |
bank_entry_id (or default {slot_name}_{memory_index}) |
Copy DataBank::getEncoded() into the input tensor |
Helpers in DeepLearningBindingData.hpp:
defaultBankEntryId(slot_name, memory_index)resolvedBankEntryId(binding)— explicit ID or default when in DataBank modehasActiveStaticSource(binding)— DataBank mode needs a resolved entry ID; DataManager mode needs a non-emptydata_key
SlotAssembler owns a session-scoped dl::DataBank via dataBank(). resetModel() does not clear it; call clearDataBank() explicitly.
SlotAssembler integration
Capture
| Method | Role |
|---|---|
captureToBank(dm, bank_entry_id, entry, frame, source_image_size) |
Fetch from DataManager using staticDataKey(entry), putSource(), then encodeEntry() with the slot’s recommended_encoder |
captureStaticInput(dm, entry, frame, source_image_size) |
Same as captureToBank() using resolvedBankEntryId(entry) as the bank key |
captureToBank() requirements:
- Model loaded (
isModelReady()) bank_entry_idpassesvalidateEntryId()staticDataKey(entry)non-empty- Target slot exists,
is_static == true - Slot
recommended_encoderresolves viaEncoderFactory
Properties-panel capture (DataBankPropertiesWidget) calls captureToBank() with a user-selected DataManager source and the resolved entry ID for the chosen static slot / memory index.
Assembly
assembleInputs() fills static slots from memory-frame bindings:
- DataBank —
getBankCachedTensor()copiesgetEncoded()and expands batch dimension whenbatch_size > 1. Missing encoded data logs an error and leaves zeros. - DataManager — re-encodes at
current_frame + time_offseteach run.
At inference time, DataBank bindings use the cached encoded tensor, not a live re-encode from getSource() (source is retained for capture, encodeEntry(), and potential future refresh paths).
Recurrent StaticCapture init
At t=0, runRecurrentSequence() seeds recurrent cache by:
- Matching static
MemoryFrameBindingat the same slot/index with DataBank source →getBankCachedTensor() - Else
getEncoded(defaultBankEntryId(slot, index)) - Else capture from
StaticCaptureInitdata_key/frameinto the default bank entry viacaptureStaticInput() - Else fall back to zeros
UI
Widget triplets under DeepLearning_Widget/UI/DataBank/:
| Widget | Zone | Role |
|---|---|---|
DataBankPropertiesWidget |
Properties | Capture: target slot, memory index, DataManager source, capture button — details |
DataBankViewWidget |
View | Preview cards (shape, value range, provenance) — details |
DeepLearningPropertiesWidget embeds the properties widget above the dynamic slot area and refreshes bank-entry combo boxes from dataBank().ids(). DeepLearningViewWidget embeds the view widget and calls refreshDataBankView() on bank changes.
Static memory slot widgets (MemorySlotWidget) configure DataManager vs DataBank bindings only; capture is centralized in DataBankPropertiesWidget.
Tests
tests/DeepLearning/storage/DataBank.test.cpp — tagged [storage][DataBank].
See also
- Memory frame bindings —
MemoryFrameBinding, DataBank vs DataManager sources - Static input capture — capture workflow and assembly sourcing
- Encoder dispatch —
EncodingSourceVariant,encodeToTensor