Skip to main content

dl::GlobalAvgPoolModule

dl::GlobalAvgPoolModule

Reduces a spatial feature map [B, C, H, W] to a global descriptor [B, C] by averaging over all spatial positions. More…

#include <GlobalAvgPoolModule.hpp>

Inherits from dl::PostEncoderModule

Public Functions

Name
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
Pool spatial dimensions to a single global average per channel.
virtual std::vector< int64_t > outputShape(std::vector< int64_t > const & input_shape) const override
Returns {C} where C is input_shape[0] (the channel dimension).

Additional inherited members

Public Functions inherited from dl::PostEncoderModule

Name
virtual ~PostEncoderModule() =default

Detailed Description

class dl::GlobalAvgPoolModule;

Reduces a spatial feature map [B, C, H, W] to a global descriptor [B, C] by averaging over all spatial positions.

This is the standard approach for converting a convolutional feature map into a compact fixed-size embedding suitable for classification or retrieval.

Implementation: adaptive_avg_pool2d(features, {1,1}).squeeze(-1).squeeze(-1)

Example:

dl::GlobalAvgPoolModule pool;
// features: [1, 384, 7, 7]
auto pooled = pool.apply(features);  // → [1, 384]

Public Functions Documentation

function name

virtual std::string name() const override

Human-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 override

Pool spatial dimensions to a single global average per channel.

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

Reimplements: dl::PostEncoderModule::apply

function outputShape

virtual std::vector< int64_t > outputShape(
    std::vector< int64_t > const & input_shape
) const override

Returns {C} where C is input_shape[0] (the channel dimension).

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


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