Skip to main content

SlotAssembler

SlotAssembler

Bridge between DataManager data and model tensor I/O. More…

#include <SlotAssembler.hpp>

Public Classes

Name
struct Impl

Public Types

Name
using std::function< void(int current_frame, int total_frames)> ProgressCallback
Callback type for progress reporting during recurrent inference.
using std::function< void(std::vector< FrameResult >)> ResultCallback
Callback invoked per-frame with decoded results for progressive delivery. When provided to runBatchRangeOffline(), results are pushed via this callback instead of accumulating in BatchInferenceResult::results.

Public Functions

Name
SlotAssembler()
~SlotAssembler()
SlotAssembler(SlotAssembler && )
SlotAssembler & operator=(SlotAssembler && )
bool loadModel(std::string const & model_id)
Load a model by ID from the registry. Resets previous weights.
bool loadWeights(std::string const & weights_path)
Load weights from a file path into the current model.
std::string validateWeights()
Run a dummy forward pass to validate weight compatibility.
bool isModelReady() const
Whether a model is loaded AND its weights are active.
std::string const & currentModelId() const
Currently loaded model ID, or empty.
void resetModel()
Clear the current model and free resources.
void runSingleFrame(DataManager & dm, std::vector< SlotBindingData > const & input_bindings, std::vector< dl::MemoryFrameBinding > const & memory_frames, std::vector< OutputBindingData > const & output_bindings, int current_frame, ImageSize source_image_size)
Run a single-frame inference pipeline: assemble inputs → forward → decode outputs.
void runBatchRange(DataManager & dm, std::vector< SlotBindingData > const & input_bindings, std::vector< dl::MemoryFrameBinding > const & memory_frames, std::vector< OutputBindingData > const & output_bindings, int start_frame, int end_frame, ImageSize source_image_size, int batch_size =1, ProgressCallback const & progress =[nullptr])
Run independent (non-recurrent) inference over a range of frames.
BatchInferenceResult runBatchRangeOffline(DataManager & dm, MediaOverrides const & media_overrides, std::vector< SlotBindingData > const & input_bindings, std::vector< dl::MemoryFrameBinding > const & memory_frames, std::vector< OutputBindingData > const & output_bindings, int start_frame, int end_frame, ImageSize source_image_size, std::atomic< bool > const & cancel_requested, int batch_size =1, ProgressCallback const & progress =[nullptr], ResultCallback const & result_callback =[nullptr])
Run independent inference over a frame range without writing to DataManager.
void runRecurrentSequence(DataManager & dm, std::vector< SlotBindingData > const & input_bindings, std::vector< dl::MemoryFrameBinding > const & memory_frames, std::vector< OutputBindingData > const & output_bindings, int start_frame, int frame_count, ImageSize source_image_size, ProgressCallback const & progress =[nullptr])
Run sequential recurrent inference over a range of frames.
dl::DataBank & dataBank()
Named store of geometry sources and channel-encoded tensors.
dl::DataBank const & dataBank() const
void clearDataBank()
Remove all entries from the DataBank.
bool captureToBank(DataManager & dm, std::string const & bank_entry_id, dl::MemoryFrameBinding const & entry, int frame, ImageSize source_image_size)
Capture a static input into a named DataBank entry.
bool captureStaticInput(DataManager & dm, dl::MemoryFrameBinding const & entry, int frame, ImageSize source_image_size)
Capture a static input at a specific frame into the DataBank.
void clearRecurrentCache()
Clear the recurrent tensor cache.
std::optional< dl::ModelInfo > currentModelInfo() const
Get metadata from the currently loaded model instance.
void configurePostEncoderModule(dl::PostEncoderStepDescriptor const & params, ImageSize source_image_size ={})
Configure the post-encoder pipeline stage for the current model.
void applyModelConfiguration(std::string const & configuration_json)
Apply persisted model configuration JSON to the current model.
bool isCudaAvailable()
Whether CUDA is available on this system (compile-time + runtime).
std::string currentDeviceName()
Human-readable name of the active device (“GPU (CUDA)” or “CPU”).
void setDeviceByName(std::string const & name)
Set the active device by name: “cuda” or “cpu”.
void initDeviceForCurrentThread()
Initialize the deep-learning device context on the calling thread.
std::vector< std::string > availableModelIds()
List all registered model IDs.
std::optional< dl::ModelInfo > getModelInfo(std::string const & model_id)
Get metadata for a registered model.
std::vector< std::string > availableEncoders()
Available encoder names (e.g. “ImageEncoder”, “Point2DEncoder”, …).
std::vector< std::string > availableDecoders()
Available decoder names (e.g. “TensorToMask2D”, …).
std::string dataTypeForEncoder(dl::EncoderVariant const & encoder)
Map encoder params → DataManager data type name for combo filtering.
std::string dataTypeForEncoder(std::string const & factory_name)
Map encoder factory name → DataManager data type name.
std::string dataTypeForDecoder(dl::DecoderVariant const & decoder)
Map decoder params → DataManager data type name for combo filtering.
std::string dataTypeForDecoder(std::string const & decoder_factory_name)
Map decoder factory name → DataManager data type name.

Detailed Description

class SlotAssembler;

Bridge between DataManager data and model tensor I/O.

Owns a cached ModelBase instance behind a PIMPL to prevent libtorch headers from leaking into Qt translation units.

Public Types Documentation

using ProgressCallback

using SlotAssembler::ProgressCallback =  std::function<void(int current_frame, int total_frames)>;

Callback type for progress reporting during recurrent inference.

Parameters:

  • current_frame 0-based index of the frame being processed
  • total_frames Total number of frames to process

using ResultCallback

using SlotAssembler::ResultCallback =  std::function<void(std::vector<FrameResult>)>;

Callback invoked per-frame with decoded results for progressive delivery. When provided to runBatchRangeOffline(), results are pushed via this callback instead of accumulating in BatchInferenceResult::results.

Public Functions Documentation

function SlotAssembler

SlotAssembler()

function ~SlotAssembler

~SlotAssembler()

function SlotAssembler

SlotAssembler(
    SlotAssembler && 
)

function operator=

SlotAssembler & operator=(
    SlotAssembler && 
)

function loadModel

bool loadModel(
    std::string const & model_id
)

Load a model by ID from the registry. Resets previous weights.

Parameters:

  • model_id Model ID to load.

Return: true if the model ID was found and instantiated.

function loadWeights

bool loadWeights(
    std::string const & weights_path
)

Load weights from a file path into the current model.

Parameters:

  • weights_path Path to the weights file.

Return: true on success.

function validateWeights

std::string validateWeights()

Run a dummy forward pass to validate weight compatibility.

Return: Empty string on success, or a diagnostic message on mismatch.

Precondition: isModelReady() must be true.

Creates zero-filled input tensors matching each input slot’s shape (batch_size=1), calls forward(), and checks that outputs are produced. Uses torch::NoGradGuard to avoid unnecessary gradient computation.

function isModelReady

bool isModelReady() const

Whether a model is loaded AND its weights are active.

function currentModelId

std::string const & currentModelId() const

Currently loaded model ID, or empty.

function resetModel

void resetModel()

Clear the current model and free resources.

function runSingleFrame

void runSingleFrame(
    DataManager & dm,
    std::vector< SlotBindingData > const & input_bindings,
    std::vector< dl::MemoryFrameBinding > const & memory_frames,
    std::vector< OutputBindingData > const & output_bindings,
    int current_frame,
    ImageSize source_image_size
)

Run a single-frame inference pipeline: assemble inputs → forward → decode outputs.

Parameters:

  • dm DataManager for encoding inputs / writing outputs
  • input_bindings Dynamic input slot bindings
  • memory_frames Memory frame bindings
  • output_bindings Output slot bindings
  • current_frame Current frame index
  • source_image_size Original image dimensions

Exceptions:

  • std::runtime_error on failure.

function runBatchRange

void runBatchRange(
    DataManager & dm,
    std::vector< SlotBindingData > const & input_bindings,
    std::vector< dl::MemoryFrameBinding > const & memory_frames,
    std::vector< OutputBindingData > const & output_bindings,
    int start_frame,
    int end_frame,
    ImageSize source_image_size,
    int batch_size =1,
    ProgressCallback const & progress =nullptr
)

Run independent (non-recurrent) inference over a range of frames.

Parameters:

  • dm DataManager for encoding inputs / writing outputs
  • input_bindings Dynamic input slot bindings
  • memory_frames Memory frame bindings
  • output_bindings Output slot bindings
  • start_frame First frame to process (inclusive)
  • end_frame Last frame to process (inclusive)
  • source_image_size Original image dimensions
  • batch_size Number of frames to process per forward pass.
  • progress Optional callback for progress reporting

Exceptions:

  • std::runtime_error on inference failure

function runBatchRangeOffline

BatchInferenceResult runBatchRangeOffline(
    DataManager & dm,
    MediaOverrides const & media_overrides,
    std::vector< SlotBindingData > const & input_bindings,
    std::vector< dl::MemoryFrameBinding > const & memory_frames,
    std::vector< OutputBindingData > const & output_bindings,
    int start_frame,
    int end_frame,
    ImageSize source_image_size,
    std::atomic< bool > const & cancel_requested,
    int batch_size =1,
    ProgressCallback const & progress =nullptr,
    ResultCallback const & result_callback =nullptr
)

Run independent inference over a frame range without writing to DataManager.

Parameters:

  • dm DataManager for non-media input encoding (masks, points, lines)
  • media_overrides Cloned MediaData instances keyed by data_key
  • input_bindings Dynamic input slot bindings
  • memory_frames Memory frame bindings
  • output_bindings Output slot bindings
  • start_frame First frame to process (inclusive)
  • end_frame Last frame to process (inclusive)
  • source_image_size Original image dimensions
  • cancel_requested Checked before each frame; stops early if true
  • batch_size Number of frames to process per forward pass. Must be >= 1. The last chunk may contain fewer frames.
  • progress Optional callback for progress reporting
  • result_callback Optional per-frame result callback for progressive delivery. When non-null, decoded outputs are pushed via this callback and NOT accumulated in BatchInferenceResult::results.

Return: Accumulated decoded results (may be partial on cancellation). If result_callback is set, the results vector will be empty.

Identical to runBatchRange() except:

  • Uses media_overrides for MediaData lookups (thread-safe clone).
  • Returns decoded results in a BatchInferenceResult instead of calling addAtTime() on DataManager.
  • Checks cancel_requested before each frame for early exit.

function runRecurrentSequence

void runRecurrentSequence(
    DataManager & dm,
    std::vector< SlotBindingData > const & input_bindings,
    std::vector< dl::MemoryFrameBinding > const & memory_frames,
    std::vector< OutputBindingData > const & output_bindings,
    int start_frame,
    int frame_count,
    ImageSize source_image_size,
    ProgressCallback const & progress =nullptr
)

Run sequential recurrent inference over a range of frames.

Parameters:

  • dm DataManager for encoding inputs / writing outputs
  • input_bindings Dynamic input slot bindings
  • memory_frames Memory frame bindings
  • output_bindings Output slot bindings
  • start_frame First frame to process
  • frame_count Number of frames to process
  • source_image_size Original image dimensions
  • progress Optional callback for progress reporting

Exceptions:

  • std::runtime_error on inference failure

For each frame in [start_frame, start_frame + frame_count):

  1. Assemble dynamic + static inputs
  2. Inject recurrent tensors (output from previous frame) into the corresponding input slots
  3. Call forward()
  4. Decode outputs into DataManager
  5. Cache output tensors for the next frame’s recurrent inputs

Batch size is forced to 1 during recurrent inference.

function dataBank

dl::DataBank & dataBank()

Named store of geometry sources and channel-encoded tensors.

Session-scoped: survives model switches via resetModel().

function dataBank

dl::DataBank const & dataBank() const

function clearDataBank

void clearDataBank()

Remove all entries from the DataBank.

function captureToBank

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

Capture a static input into a named DataBank entry.

Precondition:

Fetches geometry/image data from DataManager, stores the source in the DataBank, and channel-encodes it for the static slot.

function captureStaticInput

bool captureStaticInput(
    DataManager & dm,
    dl::MemoryFrameBinding const & entry,
    int frame,
    ImageSize source_image_size
)

Capture a static input at a specific frame into the DataBank.

Precondition: entry.resolvedBankEntryId() must be non-empty

Uses entry.resolvedBankEntryId() as the bank key. Encodes data from DataManager at the given frame using the model’s recommended encoder.

function clearRecurrentCache

void clearRecurrentCache()

Clear the recurrent tensor cache.

Call when changing models, starting a new sequence, or clearing state.

function currentModelInfo

std::optional< dl::ModelInfo > currentModelInfo() const

Get metadata from the currently loaded model instance.

Unlike the static [getModelInfo()](/api_generated/Classes/classSlotAssembler.md#function-getmodelinfo), this reflects any runtime reconfiguration (e.g. changed input resolution or output shape).

function configurePostEncoderModule

void configurePostEncoderModule(
    dl::PostEncoderStepDescriptor const & params,
    ImageSize source_image_size ={}
)

Configure the post-encoder pipeline stage for the current model.

Parameters:

  • params Registry-driven module key and JSON parameters.
  • source_image_size Source image size used for spatial_point coordinate scaling.

Applies to the first model output slot between forward() and decoding. Cleared when the model is loaded or reset.

function applyModelConfiguration

void applyModelConfiguration(
    std::string const & configuration_json
)

Apply persisted model configuration JSON to the current model.

Precondition: A model must be loaded.

function isCudaAvailable

static bool isCudaAvailable()

Whether CUDA is available on this system (compile-time + runtime).

function currentDeviceName

static std::string currentDeviceName()

Human-readable name of the active device (“GPU (CUDA)” or “CPU”).

function setDeviceByName

static void setDeviceByName(
    std::string const & name
)

Set the active device by name: “cuda” or “cpu”.

function initDeviceForCurrentThread

static void initDeviceForCurrentThread()

Initialize the deep-learning device context on the calling thread.

On CUDA builds this ensures the CUDA runtime context is set for the current thread — required on Windows where CUDA per-thread state is not inherited from the main thread. Safe to call from any thread; no-op when the active device is CPU.

Call at the start of worker thread run() methods before any libtorch operations.

function availableModelIds

static std::vector< std::string > availableModelIds()

List all registered model IDs.

function getModelInfo

static std::optional< dl::ModelInfo > getModelInfo(
    std::string const & model_id
)

Get metadata for a registered model.

function availableEncoders

static std::vector< std::string > availableEncoders()

Available encoder names (e.g. “ImageEncoder”, “Point2DEncoder”, …).

function availableDecoders

static std::vector< std::string > availableDecoders()

Available decoder names (e.g. “TensorToMask2D”, …).

function dataTypeForEncoder

static std::string dataTypeForEncoder(
    dl::EncoderVariant const & encoder
)

Map encoder params → DataManager data type name for combo filtering.

Return: “MediaData”, “PointData”, “MaskData”, “LineData”, or ““.

function dataTypeForEncoder

static std::string dataTypeForEncoder(
    std::string const & factory_name
)

Map encoder factory name → DataManager data type name.

Used for model metadata recommended_encoder hints.

function dataTypeForDecoder

static std::string dataTypeForDecoder(
    dl::DecoderVariant const & decoder
)

Map decoder params → DataManager data type name for combo filtering.

function dataTypeForDecoder

static std::string dataTypeForDecoder(
    std::string const & decoder_factory_name
)

Map decoder factory name → DataManager data type name.

Used for model metadata recommended_decoder hints.


Updated on 2026-11-13 at 20:25:39 +0000