dl::TensorToFeatureVector
dl::TensorToFeatureVector
Decodes a [B, C] (or [C]) feature tensor into a flat std::vector<float>. More…
#include <TensorToFeatureVector.hpp>
Inherits from dl::ChannelDecoder
Public Functions
| Name | |
|---|---|
| virtual std::string | name() const override |
| virtual std::string | outputTypeName() const override |
| std::vector< float > | decode(at::Tensor const & tensor, DecoderContext const & ctx, FeatureVectorDecoderParams const & params) Extract a flat feature vector from the tensor. |
Additional inherited members
Public Functions inherited from dl::ChannelDecoder
| Name | |
|---|---|
| virtual | ~ChannelDecoder() =default |
Detailed Description
class dl::TensorToFeatureVector;Decodes a [B, C] (or [C]) feature tensor into a flat std::vector<float>.
Intended for use after a post-encoder module (e.g. [GlobalAvgPoolModule](/api_generated/Classes/classdl_1_1GlobalAvgPoolModule.md)) has reduced a spatial feature map to a global descriptor. Extracts the feature vector for a single batch element.
Supported input shapes:
[C]— single unbatched vector; returns all C values.[B, C]— batched; returns the vector atctx.batch_index.
dl::TensorToFeatureVector dec;
dl::DecoderContext ctx;
ctx.batch_index = 0;
dl::FeatureVectorDecoderParams params;
auto vec = dec.decode(features, ctx, params);Public Functions Documentation
function name
virtual std::string name() const overrideReimplements: dl::ChannelDecoder::name
function outputTypeName
virtual std::string outputTypeName() const overrideReimplements: dl::ChannelDecoder::outputTypeName
function decode
static std::vector< float > decode(
at::Tensor const & tensor,
DecoderContext const & ctx,
FeatureVectorDecoderParams const & params
)Extract a flat feature vector from the tensor.
Parameters:
- tensor Input tensor, shape
[C]or[B, C]. - ctx
ctx.batch_indexselects the batch element for[B, C]inputs. - params Feature vector decoder params (currently empty).
Return: Feature values as a flat std::vector<float>.
Precondition:
- tensor is defined
- tensor.dim() == 1 (layout
[C]) or tensor.dim() == 2 (layout[B, C]) - for 2D inputs: 0 <= ctx.batch_index < tensor.size(0)
Postcondition: Returned vector length equals tensor.size(-1).
Updated on 2026-11-13 at 20:25:42 +0000