dl::GeneralEncoderModel
dl::GeneralEncoderModel
General-purpose encoder model for extracting spatial feature tensors from images. More…
#include <GeneralEncoderModel.hpp>
Inherits from dl::ModelBase
Public Functions
| Name | |
|---|---|
| int | inputChannels() const |
| int | inputHeight() const |
| int | inputWidth() const |
| std::vector< int64_t > const & | outputShape() const Raw encoder output shape reported by [outputSlots()](). |
| void | setInputResolution(int height, int width) Reconfigure the input resolution at runtime. |
| void | setOutputShape(std::vector< int64_t > output_shape) Reconfigure the raw encoder output shape at runtime. |
| GeneralEncoderModel() Construct with default resolution (3×224×224 input, 384×7×7 output). |
|
| GeneralEncoderModel(int input_channels, int input_height, int input_width, std::vector< int64_t > output_shape) Construct with custom input/output configuration. |
|
| ~GeneralEncoderModel() override | |
| GeneralEncoderModel(GeneralEncoderModel const & ) =delete | |
| GeneralEncoderModel & | operator=(GeneralEncoderModel const & ) =delete |
| GeneralEncoderModel(GeneralEncoderModel && ) | |
| GeneralEncoderModel & | operator=(GeneralEncoderModel && ) |
| virtual std::string | modelId() const override Unique string identifier for this model class (e.g. “neurosam”). |
| virtual std::string | displayName() const override Human-readable display name (e.g. “NeuroSAM”). |
| virtual std::string | description() const override Description for UI tooltip. |
| virtual std::vector< TensorSlotDescriptor > | inputSlots() const override Input slot descriptors (ordered). |
| virtual std::vector< TensorSlotDescriptor > | outputSlots() const override Output slot descriptors (ordered). |
| virtual std::string | recommendedPostEncoderModule() const override Recommended post-encoder module key for the UI (e.g. “global_avg_pool”). |
| virtual void | loadWeights(std::filesystem::path const & path) override Load weights from a file (e.g. a .pte ExecuTorch program or a TorchScript model). |
| virtual bool | isReady() const override Whether weights are loaded and model is ready for inference. |
| virtual int | preferredBatchSize() const override Preferred batch size. |
| virtual int | maxBatchSize() const override Maximum batch size the model supports. |
| virtual dl::BatchMode | batchMode() const override Batch mode describing the model’s batch-size constraints. |
| virtual std::unordered_map< std::string, at::Tensor > | forward(std::unordered_map< std::string, at::Tensor > const & inputs) override Run inference. |
Public Attributes
| Name | |
|---|---|
| char const * | kImageSlot |
| char const * | kFeaturesSlot |
Additional inherited members
Public Functions inherited from dl::ModelBase
| Name | |
|---|---|
| virtual | ~ModelBase() =default |
Detailed Description
class dl::GeneralEncoderModel;General-purpose encoder model for extracting spatial feature tensors from images.
Precondition: Input resolution and output shape must have positive dimensions.
Maps a single input image to a feature tensor using any backbone (e.g. ConvNeXt, ViT, ResNet). The input resolution, number of input channels, and output feature shape are configurable at construction time.
Input slots:
- “image” : [input_channels, height, width] — input image (RGB by default)
Output slots:
- “features” : [output_shape…] — extracted feature tensor
Batch mode: DynamicBatch{1, max} (supports arbitrary batch sizes).
Usage:
// Default: 3-channel 224x224 input → 384x7x7 output
dl::GeneralEncoderModel model;
// Custom resolution:
dl::GeneralEncoderModel model(3, 512, 512, {768, 16, 16});Public Functions Documentation
function inputChannels
inline int inputChannels() constfunction inputHeight
inline int inputHeight() constfunction inputWidth
inline int inputWidth() constfunction outputShape
inline std::vector< int64_t > const & outputShape() constRaw encoder output shape reported by [outputSlots()]().
function setInputResolution
void setInputResolution(
int height,
int width
)Reconfigure the input resolution at runtime.
Precondition:
- height > 0
- width > 0
This allows the same model instance to adapt to different encoder backbones that expect different spatial resolutions. Must be called before [loadWeights()](/api_generated/Classes/classdl_1_1GeneralEncoderModel.md#function-loadweights) or [forward()](/api_generated/Classes/classdl_1_1GeneralEncoderModel.md#function-forward).
function setOutputShape
void setOutputShape(
std::vector< int64_t > output_shape
)Reconfigure the raw encoder output shape at runtime.
Precondition: output_shape must not be empty and all dimensions must be > 0
This allows the same model instance to describe the output of different encoder backbones. Must be called before [forward()](/api_generated/Classes/classdl_1_1GeneralEncoderModel.md#function-forward).
function GeneralEncoderModel
GeneralEncoderModel()Construct with default resolution (3×224×224 input, 384×7×7 output).
function GeneralEncoderModel
GeneralEncoderModel(
int input_channels,
int input_height,
int input_width,
std::vector< int64_t > output_shape
)Construct with custom input/output configuration.
Parameters:
- input_channels Number of input channels (e.g. 3 for RGB).
- input_height Input image height in pixels.
- input_width Input image width in pixels.
- output_shape Output feature tensor shape (excluding batch dim).
Precondition:
- input_channels > 0
- input_height > 0
- input_width > 0
- output_shape must not be empty and all dimensions must be > 0
function ~GeneralEncoderModel
~GeneralEncoderModel() overridefunction GeneralEncoderModel
GeneralEncoderModel(
GeneralEncoderModel const &
) =deletefunction operator=
GeneralEncoderModel & operator=(
GeneralEncoderModel const &
) =deletefunction GeneralEncoderModel
GeneralEncoderModel(
GeneralEncoderModel &&
)function operator=
GeneralEncoderModel & operator=(
GeneralEncoderModel &&
)function modelId
virtual std::string modelId() const overrideUnique string identifier for this model class (e.g. “neurosam”).
Reimplements: dl::ModelBase::modelId
function displayName
virtual std::string displayName() const overrideHuman-readable display name (e.g. “NeuroSAM”).
Reimplements: dl::ModelBase::displayName
function description
virtual std::string description() const overrideDescription for UI tooltip.
Reimplements: dl::ModelBase::description
function inputSlots
virtual std::vector< TensorSlotDescriptor > inputSlots() const overrideInput slot descriptors (ordered).
Reimplements: dl::ModelBase::inputSlots
Each describes one named tensor the model expects. Does not include the batch dimension.
function outputSlots
virtual std::vector< TensorSlotDescriptor > outputSlots() const overrideOutput slot descriptors (ordered).
Reimplements: dl::ModelBase::outputSlots
Each describes one named tensor the model produces. Does not include the batch dimension.
function recommendedPostEncoderModule
virtual std::string recommendedPostEncoderModule() const overrideRecommended post-encoder module key for the UI (e.g. “global_avg_pool”).
Reimplements: dl::ModelBase::recommendedPostEncoderModule
Empty string means no post-encoder module is recommended. The UI pre-selects this but the user can override it.
function loadWeights
virtual void loadWeights(
std::filesystem::path const & path
) overrideLoad weights from a file (e.g. a .pte ExecuTorch program or a TorchScript model).
Reimplements: dl::ModelBase::loadWeights
function isReady
virtual bool isReady() const overrideWhether weights are loaded and model is ready for inference.
Reimplements: dl::ModelBase::isReady
function preferredBatchSize
virtual int preferredBatchSize() const overridePreferred batch size.
Reimplements: dl::ModelBase::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
virtual int maxBatchSize() const overrideMaximum batch size the model supports.
Reimplements: dl::ModelBase::maxBatchSize
0 = unlimited.
function batchMode
virtual dl::BatchMode batchMode() const overrideBatch mode describing the model’s batch-size constraints.
Reimplements: dl::ModelBase::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 forward
virtual std::unordered_map< std::string, at::Tensor > forward(
std::unordered_map< std::string, at::Tensor > const & inputs
) overrideRun inference.
Parameters:
- inputs Map of slot_name → Tensor, each with a leading batch dimension.
Return: Map of slot_name → Tensor for each output slot.
Reimplements: dl::ModelBase::forward
Tensors have a leading batch dimension whose size is controlled by the caller (and bounded by [maxBatchSize()](/api_generated/Classes/classdl_1_1GeneralEncoderModel.md#function-maxbatchsize)).
Public Attributes Documentation
variable kImageSlot
static char const * kImageSlot = "image";variable kFeaturesSlot
static char const * kFeaturesSlot = "features";Updated on 2026-11-13 at 20:25:42 +0000