- global-avg-pool2d inputprocedure
Averages over the spatial dimensions.
- 3-D: (C, H, W) -> (C)
- 4-D: (N, C, H, W) -> (N, C)
The gradient is distributed uniformly over the spatial positions of each channel.
;; Batch of feature maps (define batch-features (make-tensor32 (make-f32vector (* 32 128 8 8)) '(32 128 8 8))) (define batch-pooled (global-avg-pool2d batch-features)) ; Shape: (32, 128) ;; Classification head (define logits (forward fc-layer batch-pooled)) ; Shape: (32, num_classes)
Global average pooling can replace a large fully connected layer at the end of a CNN, with far fewer parameters.