Skip to main content

dl::ModelBase

dl::ModelBase

Abstract base class for all v2 deep-learning model wrappers. More…

#include <ModelBase.hpp>

Inherited by dl::GeneralEncoderModel, dl::NeuroSAMModel, dl::RuntimeModel

Public Functions

Name
virtual ~ModelBase() =default
virtual std::string modelId() const =0
Unique string identifier for this model class (e.g. “neurosam”).
virtual std::string displayName() const =0
Human-readable display name (e.g. “NeuroSAM”).
virtual std::string description() const =0
Description for UI tooltip.
virtual std::vector< TensorSlotDescriptor > inputSlots() const =0
Input slot descriptors (ordered).
virtual std::vector< TensorSlotDescriptor > outputSlots() const =0
Output slot descriptors (ordered).
virtual void loadWeights(std::filesystem::path const & path) =0
Load weights from a file (e.g. a .pte ExecuTorch program or a TorchScript model).
virtual bool isReady() const =0
Whether weights are loaded and model is ready for inference.
virtual int preferredBatchSize() const
Preferred batch size.
virtual int maxBatchSize() const
Maximum batch size the model supports.
virtual BatchMode batchMode() const
Batch mode describing the model’s batch-size constraints.
virtual std::string recommendedPostEncoderModule() const
Recommended post-encoder module key for the UI (e.g. “global_avg_pool”).
virtual std::unordered_map< std::string, at::Tensor > forward(std::unordered_map< std::string, at::Tensor > const & inputs) =0
Run inference.

Detailed Description

class dl::ModelBase;

Abstract base class for all v2 deep-learning model wrappers.

A ModelBase subclass declares its expected input and output tensor slots via [inputSlots()](/api_generated/Classes/classdl_1_1ModelBase.md#function-inputslots) and [outputSlots()](/api_generated/Classes/classdl_1_1ModelBase.md#function-outputslots). The caller allocates and fills input tensors (using ChannelEncoders), invokes [forward()](/api_generated/Classes/classdl_1_1ModelBase.md#function-forward), and decodes the output tensors (using ChannelDecoders).

Tensors always have a leading batch dimension. The model advertises [preferredBatchSize()](/api_generated/Classes/classdl_1_1ModelBase.md#function-preferredbatchsize) and [maxBatchSize()](/api_generated/Classes/classdl_1_1ModelBase.md#function-maxbatchsize) so the UI can choose how many frames to process per call.

Public Functions Documentation

function ~ModelBase

virtual ~ModelBase() =default

function modelId

virtual std::string modelId() const =0

Unique string identifier for this model class (e.g. “neurosam”).

Reimplemented by: dl::GeneralEncoderModel::modelId, dl::NeuroSAMModel::modelId, dl::RuntimeModel::modelId

function displayName

virtual std::string displayName() const =0

Human-readable display name (e.g. “NeuroSAM”).

Reimplemented by: dl::GeneralEncoderModel::displayName, dl::NeuroSAMModel::displayName, dl::RuntimeModel::displayName

function description

virtual std::string description() const =0

Description for UI tooltip.

Reimplemented by: dl::GeneralEncoderModel::description, dl::NeuroSAMModel::description, dl::RuntimeModel::description

function inputSlots

virtual std::vector< TensorSlotDescriptor > inputSlots() const =0

Input slot descriptors (ordered).

Reimplemented by: dl::GeneralEncoderModel::inputSlots, dl::NeuroSAMModel::inputSlots, dl::RuntimeModel::inputSlots

Each describes one named tensor the model expects. Does not include the batch dimension.

function outputSlots

virtual std::vector< TensorSlotDescriptor > outputSlots() const =0

Output slot descriptors (ordered).

Reimplemented by: dl::GeneralEncoderModel::outputSlots, dl::NeuroSAMModel::outputSlots, dl::RuntimeModel::outputSlots

Each describes one named tensor the model produces. Does not include the batch dimension.

function loadWeights

virtual void loadWeights(
    std::filesystem::path const & path
) =0

Load weights from a file (e.g. a .pte ExecuTorch program or a TorchScript model).

Reimplemented by: dl::GeneralEncoderModel::loadWeights, dl::NeuroSAMModel::loadWeights, dl::RuntimeModel::loadWeights

function isReady

virtual bool isReady() const =0

Whether weights are loaded and model is ready for inference.

Reimplemented by: dl::GeneralEncoderModel::isReady, dl::NeuroSAMModel::isReady, dl::RuntimeModel::isReady

function preferredBatchSize

inline virtual int preferredBatchSize() const

Preferred batch size.

Reimplemented by: dl::GeneralEncoderModel::preferredBatchSize, dl::NeuroSAMModel::preferredBatchSize, dl::RuntimeModel::preferredBatchSize

0 = model decides; 1 = single-frame (e.g. NeuroSAM with output→input feedback); N = process N frames at once. UI uses this as the default for the “Batch Size” spinbox.

function maxBatchSize

inline virtual int maxBatchSize() const

Maximum batch size the model supports.

Reimplemented by: dl::GeneralEncoderModel::maxBatchSize, dl::NeuroSAMModel::maxBatchSize, dl::RuntimeModel::maxBatchSize

0 = unlimited.

function batchMode

inline virtual BatchMode batchMode() const

Batch mode describing the model’s batch-size constraints.

Reimplemented by: dl::GeneralEncoderModel::batchMode, dl::NeuroSAMModel::batchMode, dl::RuntimeModel::batchMode

The default returns [DynamicBatch](/api_generated/Classes/structdl_1_1DynamicBatch.md){1, 0} (any batch size). Override in subclasses to report [FixedBatch](/api_generated/Classes/structdl_1_1FixedBatch.md), [RecurrentOnlyBatch](/api_generated/Classes/structdl_1_1RecurrentOnlyBatch.md), or a [DynamicBatch](/api_generated/Classes/structdl_1_1DynamicBatch.md) with specific limits.

The widget uses this to configure the batch-size spinbox and to auto-select the correct weights variant for multi-variant models.

function recommendedPostEncoderModule

inline virtual std::string recommendedPostEncoderModule() const

Recommended post-encoder module key for the UI (e.g. “global_avg_pool”).

Reimplemented by: dl::GeneralEncoderModel::recommendedPostEncoderModule, dl::RuntimeModel::recommendedPostEncoderModule

Empty string means no post-encoder module is recommended. The UI pre-selects this but the user can override it.

function forward

virtual std::unordered_map< std::string, at::Tensor > forward(
    std::unordered_map< std::string, at::Tensor > const & inputs
) =0

Run inference.

Parameters:

  • inputs Map of slot_name → Tensor, each with a leading batch dimension.

Return: Map of slot_name → Tensor for each output slot.

Reimplemented by: dl::GeneralEncoderModel::forward, dl::NeuroSAMModel::forward, dl::RuntimeModel::forward

Tensors have a leading batch dimension whose size is controlled by the caller (and bounded by [maxBatchSize()](/api_generated/Classes/classdl_1_1ModelBase.md#function-maxbatchsize)).


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