dl::SpatialPointExtractModule
dl::SpatialPointExtractModule
Extracts the feature vector at a 2D point location within the feature map. More…
#include <SpatialPointExtractModule.hpp>
Inherits from dl::PostEncoderModule
Public Functions
| Name | |
|---|---|
| SpatialPointExtractModule(ImageSize source_image_size, SpatialPointModuleParams params ={}) Construct a spatial point extraction module. |
|
| virtual std::string | name() const override Human-readable identifier for this module (e.g. “global_avg_pool”). |
| virtual at::Tensor | apply(at::Tensor const & features) const override Extract the feature vector at the current query point. |
| virtual std::vector< int64_t > | outputShape(std::vector< int64_t > const & input_shape) const override Returns {C} where C is input_shape[0]. |
| void | setPoint(Point2D< float > point) Update the query point (in source-image coordinates) for the next frame. |
| Point2D< float > | currentPoint() const The current query point in source-image coordinates. |
| ImageSize | sourceImageSize() const The source image size used for coordinate scaling. |
| InterpolationMode | interpolationMode() const The interpolation mode. |
| std::string const & | pointKey() const DataManager key for per-frame PointData lookup. |
Additional inherited members
Public Functions inherited from dl::PostEncoderModule
| Name | |
|---|---|
| virtual | ~PostEncoderModule() =default |
Detailed Description
class dl::SpatialPointExtractModule;Extracts the feature vector at a 2D point location within the feature map.
Given a point in source-image coordinates, this module:
- Scales the point from source-image space to feature-map space.
- Extracts
features[:, :, y_feat, x_feat]→[B, C].
Two interpolation modes are supported:
- Nearest: rounds to the nearest integer grid location.
- Bilinear: uses
torch::nn::functional::grid_samplefor sub-pixel accuracy (requires[B, C, H, W]4D input).
The current query point must be set via [setPoint()](/api_generated/Classes/classdl_1_1SpatialPointExtractModule.md#function-setpoint) before each [apply()](/api_generated/Classes/classdl_1_1SpatialPointExtractModule.md#function-apply).
Example:
dl::SpatialPointExtractModule extractor(
{640, 480},
dl::SpatialPointModuleParams{.interpolation = dl::InterpolationMode::Bilinear});
extractor.setPoint({320.0f, 240.0f}); // centre pixel
auto vec = extractor.apply(features); // → [B, C]Public Functions Documentation
function SpatialPointExtractModule
explicit SpatialPointExtractModule(
ImageSize source_image_size,
SpatialPointModuleParams params ={}
)Construct a spatial point extraction module.
Parameters:
- source_image_size Dimensions of the original source image (before any encoding/resizing). Used for coordinate scaling.
- params User-configurable module parameters (interpolation, point_key).
Precondition:
- source_image_size.width > 0
- source_image_size.height > 0
function name
virtual std::string name() const overrideHuman-readable identifier for this module (e.g. “global_avg_pool”).
Reimplements: dl::PostEncoderModule::name
function apply
virtual at::Tensor apply(
at::Tensor const & features
) const overrideExtract the feature vector at the current query point.
Parameters:
- features Input tensor of shape
[B, C, H, W].
Return: Tensor of shape [B, C].
Precondition:
- features is defined
- features.dim() == 4 (layout
[B, C, H, W]) - features.size(0) >= 1
- features.size(1) >= 1
- features.size(2) >= 1 and features.size(3) >= 1
- for bilinear mode: features.size(2) >= 2 and features.size(3) >= 2
- setPoint() should have been called before apply(); default
{0, 0}is used otherwise
Reimplements: dl::PostEncoderModule::apply
function outputShape
virtual std::vector< int64_t > outputShape(
std::vector< int64_t > const & input_shape
) const overrideReturns {C} where C is input_shape[0].
Parameters:
- input_shape Encoder output shape
[C, H, W]excluding the batch dimension.
Precondition:
- input_shape is not empty
- input_shape[0] >= 1
Reimplements: dl::PostEncoderModule::outputShape
function setPoint
void setPoint(
Point2D< float > point
)Update the query point (in source-image coordinates) for the next frame.
Parameters:
- point Query location in pixel coordinates of the source image. (0, 0) is the top-left corner.
function currentPoint
inline Point2D< float > currentPoint() constThe current query point in source-image coordinates.
function sourceImageSize
inline ImageSize sourceImageSize() constThe source image size used for coordinate scaling.
function interpolationMode
inline InterpolationMode interpolationMode() constThe interpolation mode.
function pointKey
inline std::string const & pointKey() constDataManager key for per-frame PointData lookup.
Updated on 2026-11-13 at 20:25:42 +0000