Skip to main content

DeepLearning Widget Helpers

Overview

The DeepLearning_Widget/UI/Helpers/ directory contains reusable utility classes extracted from the monolithic DeepLearningPropertiesWidget during the widget refactoring (helper extraction and schema-driven sub-panels).

Source: src/WhiskerToolbox/DeepLearning_Widget/UI/Helpers/

DataSourceComboHelper

Header: DeepLearning_Widget/UI/Helpers/DataSourceComboHelper.hpp

Centralises QComboBox population and auto-refresh for DataManager-aware combo boxes. Replaces the hand-written _populateDataSourceCombo / _refreshDataSourceCombos methods that were previously inlined in the properties widget.

Key features

  • One-shot population via populateCombo(combo, types) — clears the combo, adds a (None) sentinel, then appends all DataManager keys matching the requested DM_DataType filter. Preserves the user’s current selection if it is still valid after repopulation.
  • Tracking via track(combo, types) / untrack(combo) — registers a combo for batch refresh when refreshAll() is called (typically from a DataManager observer callback). Tracked combos auto-untrack on QObject::destroyed to avoid dangling pointers.
  • Type hint conversion via the static typesFromHint(string) — translates SlotAssembler type-hint strings (e.g. "PointData", "MediaData") to a std::vector<DM_DataType> suitable for the filter parameter.

Typical usage

auto helper = std::make_unique<DataSourceComboHelper>(data_manager, this);

// One-shot
helper->populateCombo(my_combo, DM_DataType::Points);

// Track for auto-refresh
helper->track(my_combo, "PointData");
dm->addObserver([&]{ helper->refreshAll(); });

DynamicInputSlotWidget

Header: DeepLearning_Widget/UI/Helpers/DynamicInputSlotWidget.hpp

A self-contained widget for configuring one dynamic (per-frame) input slot. It replaces the hand-built _buildDynamicInputGroup() panel with a schema-driven AutoParamWidget form.

Architecture

The widget is driven by dl::DynamicInputBindingForm from BindingParamSchemas.hpp:

struct DynamicInputBindingForm {
    std::string data_key;
    EncoderVariant encoder = ImageEncoderParams{};
    int time_offset = 0;
};

AutoParamWidget generates the data-source combo, encoder tagged-union selector with per-encoder sub-forms, and the time-offset spin box. The widget exposes full SlotBindingData via binding() / setBinding().

The panel shows shape and dtype (e.g. uint8 vs float32). For image slots whose model descriptor uses TensorDType::Byte, applyDynamicInputSlotSchemaConstraints() marks ImageEncoder Normalize as ParameterFieldDescriptor::is_hidden so AutoParamWidget still emits it in JSON (rfl round-trip) but does not show the control; a short explanatory note is shown in the panel.

Cross-field constraints

When the encoder selection changes, the widget uses SlotAssembler::dataTypeForEncoder() and DataSourceComboHelper::typesFromHint() to filter the data_key combo to compatible DataManager keys (encoder → source direction).

Typical usage

auto* slot_widget = new DynamicInputSlotWidget(slot_descriptor, data_manager, this);
layout->addWidget(slot_widget);

connect(slot_widget, &DynamicInputSlotWidget::bindingChanged, this, [&]() {
    auto binding = slot_widget->binding();
    // Update state...
});

dm_observer_callback = [slot_widget]() {
    slot_widget->refreshDataSources();
};

OutputSlotWidget

Header: DeepLearning_Widget/UI/Helpers/OutputSlotWidget.hpp

See OutputSlotWidget for the per-output binding editor.

PostEncoderWidget

Header: DeepLearning_Widget/UI/Helpers/PostEncoderWidget.hpp

A self-contained widget for configuring the post-encoder module section. It replaces the hand-built _buildPostEncoderSection() panel with a module combo (from PostEncoderModuleRegistry) and a schema-driven AutoParamWidget form.

Architecture

The widget is driven by dl::PostEncoderStepDescriptor (module_key + parameters_json):

struct PostEncoderStepDescriptor {
    std::string module_key = "none";
    std::string parameters_json = "{}";
};
using PostEncoderSlotParams = PostEncoderStepDescriptor;

UI structure:

  • Module combo — from PostEncoderModuleRegistry::moduleKeys() + (None)
  • Parameter panel — AutoParamWidget with schema from getSchema(module_key)
  • point_key — dynamic combo when spatial_point is selected

UI hints for SpatialPointModuleParams live in DeepLearning/post_encoder/PostEncoderParamSchemas.hpp.

Signals

Signal Emitted when
bindingChanged() Any parameter change (after state and assembler are updated)

Typical usage

auto * post_encoder = new PostEncoderWidget(state, dm, assembler, this);
layout->addWidget(post_encoder);

connect(post_encoder, &PostEncoderWidget::bindingChanged, this, [&]() {
    // Coordinator reacts to module or point_key changes
});

dm_observer_callback = [post_encoder]() {
    post_encoder->refreshDataSources();
};

State and apply path

  • Read: params() returns PostEncoderStepDescriptor.
  • Write: setParams(p) updates the UI from saved state.
  • Persist: DeepLearningState::postEncoderParams() is the workspace source of truth (embedded in DeepLearningStateData via reflect-cpp).
  • Apply: coordinator calls setPostEncoderParams(), then SlotAssembler::configurePostEncoderModule(params, ...) when the model is ready.
  • Re-sync: syncToAssembler() re-applies params after loadModel() clears the assembler module (called from _loadModelIfReady() and _enforcePostEncoderDecoderConsistency()).

Comparison with TransformsV2_Widget

PostEncoderWidget is the simple schema-driven pattern (one fixed struct, one form). For runtime catalogs, ordered multi-step composition, and JSON-as-state, see Schema-Driven Forms, which documents how TransformsV2_Widget extends the same primitives.

MemorySlotWidget

Header: DeepLearning_Widget/UI/Helpers/MemorySlotWidget.hpp

A self-contained widget for configuring memory (static) input slots. Replaces the former StaticInputSlotWidget, SequenceSlotWidget, and RecurrentBindingWidget.

Architecture

Each slot position is configured via MemoryFrameBinding in session state. The widget exposes a Frame kind combo (Static / Recurrent) and stacked AutoParamWidget forms backed by StaticFrameSourceForm and RecurrentFrameSourceForm from BindingParamSchemas.hpp.

// Read back bindings for this slot only
std::vector<dl::MemoryFrameBinding> frames = widget.bindings();

// Restore from session state (filters by slot_name)
widget.setBindings(state->memoryFrames());

Sequence slots (sequence_dim >= 0) support multiple position rows with Add/Remove controls up to the model sequence length. Single-frame slots use one row.

The group header shows dtype and gray help text for image memory slots: static/DataBank capture uses factory ImageEncoder parameters (not the encoder_image dynamic binding). For uint8 slots this matches in-model scaling.

Signals

Signal Emitted when
bindingChanged() Any frame kind, static source, or recurrent parameter changes

Typical usage

auto * memory = new MemorySlotWidget(slot_descriptor, data_manager,
                                     output_slot_names, this);
layout->addWidget(memory);

connect(memory, &MemorySlotWidget::bindingChanged, this, [&]() {
    _syncBindingsFromUi();
});

memory->setBindings(_state->memoryFrames());
memory->refreshDataSources();
memory->refreshBankEntries(bank_entry_ids);
memory->refreshOutputSlots(output_slot_names);

See Memory Frame Bindings for the core data model.