core/nn/vision/pool2d library

2-D pooling for NCHW tensors — inference-friendly, autograd-lite.

Two ops we need for Inception-ResNet-V1:

  • MaxPool2d(kernel, stride, padding) — used once in the FaceNet stem (k=3, s=2, no padding).
  • AdaptiveAvgPool2d((1, 1)) — global average pool that collapses [N, C, H, W] to [N, C, 1, 1] (we return [N, C] for the downstream Linear).

Both are pure functions (no learnable state), so they're free helpers rather than Modules. Both run on the host; the input is downloaded via .toFloat32List() and the output is pushed back to the same device with Tensor.fromFloat32List. That's fine at inference-time and for training the head, since we don't need to propagate gradients through them.

Functions

globalAvgPool2d(Tensor x) → Tensor
Global average pool over the spatial axes: [N, C, H, W] -> [N, C].
maxPool2d(Tensor x, {required int kernel, required int stride, int padding = 0, bool ceilMode = false}) → Tensor
Max-pool [N, C, H, W] with kernel k, stride, padding (all spatially symmetric). Output shape [N, C, Hout, Wout] where Hout = (H + 2*p - k) / s + 1 (or ceil-divided if ceilMode).