nn_bn_normalize_conv: Normalize a conv-shaped input over the batch and all spatial...

View source: R/nn_layers.R

nn_bn_normalize_convR Documentation

Normalize a conv-shaped input over the batch and all spatial positions

Description

Batch normalization pools its statistics per channel over the batch AND every spatial position. ggml_mean() only reduces ne[0], so the input is first rearranged to put all reduced axes into ne[0] and the channel into ne[1]. Both layouts fold adjacent axes, which is a pure view; only the one permute in the 4-D route costs a copy.

Usage

nn_bn_normalize_conv(ctx, input_tensor, layer, training, eps)

Arguments

training

Logical; use batch statistics (TRUE) or running estimates (FALSE).

Details

3-D [C, L, N]

channel is ne[0]. L and N are adjacent, so reshape to [C, L*N] then transpose to [L*N, C].

4-D [W, H, C, N]

channel is ne[2]. W and H are adjacent (reshape to [W*H, C, N]), then permute brings N beside W*H ([W*H, N, C]) so a second reshape folds both into [W*H*N, C].

At inference time the stored running estimates are used instead, broadcast along the channel axis, so a prediction does not depend on batch composition.

Value

A ggml_tensor with the same shape as input_tensor.


ggmlR documentation built on Oct. 23, 2026, 1:07 a.m.