Skip to content
DeepForgeby svx
All problems
MediumDeep Learningdl-026

BatchNorm Inference

Problem

Inference-mode batch normalization using running statistics: y_i = gamma * (x_i - running_mean) / sqrt(running_var + eps) + beta.

The signature is batchnorm_inference(x, gamma, beta, running_mean, running_var, eps=1e-5).

Hint

At inference time no batch statistics are computed; use the stored running values.

Test cases

case 1
in: [[1,2],1,0,1.5,0.25]
expected: [-0.9999800006,0.9999800006]
case 2
in: [[0],1,0,0,1]
expected: [0]
case 3
in: [[1,2,3],2,1,2,4]
expected: [0.00000125,1,1.99999875]
case 4
in: [[4,6],2,1,5,1]
expected: [-0.9999900001,2.9999900001]
Starter codePython
import math
def batchnorm_inference(x, gamma, beta, running_mean, running_var, eps=1e-5):
    # Your code here
    pass

4 test cases · run your code against them in the editor