Implement batchnorm2d(x, gamma, beta, eps=1e-5) that performs training-mode batch normalization for a 4-D input.
Shapes:
x has shape (N, C, H, W).gamma (scale) and beta (shift) each have shape (C,).For each channel independently, compute the mean and variance over the batch, height, and width dimensions, normalize, then scale and shift:
You do not need to track running statistics here - we only care about the training-mode forward pass.
keepdim=True when reducing so broadcasting against the original tensor works without manual reshapes.gamma and beta are 1-D; they need to be reshaped so they broadcast against (N, C, H, W).