DecoderDispatch
Overview
DecoderDispatch provides type-safe dispatch from DecoderVariant parameter alternatives to static TensorTo* decode() calls. It centralizes factory-name and DataManager-type mapping used by SlotAssembler, OutputSlotWidget, and model metadata (recommended_decoder hints).
Location: src/DeepLearning/channel_decoding/DecoderDispatch.hpp
Implementation: src/DeepLearning/channel_decoding/DecoderDispatch.cpp
Concrete decoders register via DecoderFactory (DecoderFactory.hpp) for name-based lookup; DecoderDispatch is the params-variant entry point used during inference.
Spatial scaling contract
All decoders created through DecoderFactory must upsample from tensor (H, W) to DecoderContext::target_image_size using the same convention as the encoders in EncoderFactory:
| Decoder | Target convention |
|---|---|
TensorToMask2D |
Pixel-center inverse NN raster (see map_dest_to_source / resize_mask) |
TensorToPoint2D / TensorToLine2D |
Pixel-center continuous inverse of encoder mapping |
TensorToFeatureVector |
No spatial resize |
Encode and decode must be paired inverses per data type (continuous vs mask raster). See mask_utils.qmd for pixel-center vs legacy edge-aligned formulas.
Pipeline position
encoder output [B, C, H, W]
→ (optional) PostEncoderModule::apply() // torch → torch
→ decodeToGeometry() / TensorTo*::decode() // torch → geometry / vector
→ DataManager write
DecoderContext (in ChannelDecoder.hpp) carries runtime indexing and coordinate scaling. Per-decoder user settings live in *DecoderParams structs in the same header.
Decoder registry mapping
| Params struct | Factory name | dataTypeForDecoder() |
Spatial 4D? | Output type |
|---|---|---|---|---|
MaskDecoderParams |
TensorToMask2D |
MaskData |
yes | Mask2D |
PointDecoderParams |
TensorToPoint2D |
PointData |
yes | Point2D<float> |
LineDecoderParams |
TensorToLine2D |
LineData |
yes | Line2D |
FeatureVectorDecoderParams |
TensorToFeatureVector |
TensorData |
no | std::vector<float> |
See the per-decoder pages for algorithm details: TensorToMask2D, TensorToPoint2D, TensorToLine2D, TensorToFeatureVector.
API
| Function | Purpose |
|---|---|
decodeToGeometry(tensor, ctx, params) |
Decode using typed params or DecoderVariant |
isSpatialDecoderParams<Params>() |
Compile-time: params need 4D [B,C,H,W] input |
isSpatialDecoder(params) |
Runtime variant of the above |
dataTypeForDecoderParams<Params>() / dataTypeForDecoder(params) |
Map to MaskData, PointData, etc. |
decoderFactoryName<Params>() / decoderFactoryName(params) |
Map to TensorToMask2D, etc. |
decoderParamsFromFactoryName(name) |
Default params from model recommended_decoder hint |
Types
DecoderVariant—rfl::TaggedUnionof all*DecoderParamsstructs (defined inbindings/EncoderDecoderBindingTypes.hpp)DecodedGeometryVariant—std::variant<Mask2D, Point2D<float>, Line2D, std::vector<float>>
DecodedOutputVariant in BatchInferenceResult.hpp aliases DecodedGeometryVariant.
decodeToGeometry() always calls each decoder’s primary decode() method. TensorToPoint2D::decodeMultiple() is available for multi-peak extraction but is not wired through dispatch or SlotAssembler today.
SlotAssembler integration
SlotAssembler::makeDecoderContext() populates DecoderContext from output slot metadata:
source_channel— fixed at0(first channel)batch_index— current batch elementheight/width— last two entries of the slot shape whenshape.size() >= 2target_image_size— source image size for coordinate upscaling
Spatial decoders are skipped (with a logged error) when the output tensor rank is less than 4.
Tests
tests/DeepLearning/channel_decoding/DecoderDispatch.test.cpp — factory-name mapping, DataManager type mapping, decoderParamsFromFactoryName round-trip, isSpatialDecoder, and end-to-end mask decode via decodeToGeometry.
Filter with ctest -R "decoder_dispatch".