At inference time a batch-norm layer uses frozen statistics, so it is an affine map per channel and can be merged into the convolution before it ("fused batchnorm"). For output channel :
where and are the running mean and variance.
Implement fold_bn(W, b, gamma, beta, running_mean, running_var, eps=1e-5):
W: convolution weights of shape (C_out, C_in, kh, kw); b: bias of shape (C_out,), or None for a convolution without bias.gamma, beta, running_mean, running_var: shape (C_out,).Return (W_fold, b_fold) such that a convolution with W_fold and b_fold gives exactly the output of the original convolution followed by the frozen batch norm, for any input. b_fold is always an array of shape (C_out,).