MCPcopy Create free account
hub / github.com/PABannier/sam3.cpp / sam2_maxpool_2d

Function sam2_maxpool_2d

sam3.cpp:4287–4296  ·  view source on GitHub ↗

MaxPool2d with kernel=2, stride=2 on spatial dims (ne[1]=W, ne[2]=H). Input: [C, W, H, B] -> output: [C, W/2, H/2, B] ggml_pool_2d operates on ne[0] and ne[1], so we permute to [W, H, C, B], pool, then permute back to [C, W/2, H/2, B].

Source from the content-addressed store, hash-verified

4285// ggml_pool_2d operates on ne[0] and ne[1], so we permute to [W, H, C, B],
4286// pool, then permute back to [C, W/2, H/2, B].
4287static struct ggml_tensor* sam2_maxpool_2d(struct ggml_context* ctx,
4288 struct ggml_tensor* x) {
4289 // [C, W, H, B] -> [W, H, C, B] (permute(2,0,1,3))
4290 auto* perm = ggml_cont(ctx, ggml_permute(ctx, x, 2, 0, 1, 3));
4291 // Pool on ne[0]=W, ne[1]=H -> [W/2, H/2, C, B]
4292 auto* pooled = ggml_pool_2d(ctx, perm, GGML_OP_POOL_MAX, 2, 2, 2, 2, 0, 0);
4293 // [W/2, H/2, C, B] -> [C, W/2, H/2, B] (permute(1,2,0,3))
4294 auto* out = ggml_cont(ctx, ggml_permute(ctx, pooled, 1, 2, 0, 3));
4295 return out;
4296}
4297
4298// Single Hiera MultiScaleBlock forward pass.
4299static struct ggml_tensor* sam2_hiera_block_forward(struct ggml_context* ctx,

Callers 1

sam2_hiera_block_forwardFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected