All problems
Batch-Norm Inference
Problem
Apply batch normalization at inference time to an H x W x C tensor.
mean, var, gamma and beta are per-channel lists. For each pixel and channel compute gamma[c] * (x - mean[c]) / sqrt(var[c] + eps) + beta[c], rounded to 4 decimal places.
Hint
Normalize with the running statistics and then apply the per-channel affine transform.
Test cases
case 1
in: [[[[1,2],[3,4]]],[1,2],[1,4],[1,0.5],[0,1],0.00001]
expected: [[[0,1],[2,1.5]]]
case 2
in: [[[[5,5]]],[5,5],[4,4],[2,2],[1,1],0]
expected: [[[1,1]]]
case 3
in: [[[[0,0],[2,2]]],[1,1],[1,1],[1,3],[0,0],0]
expected: [[[-1,-3],[1,3]]]
Starter codePython
def batchnorm_inference(x, mean, var, gamma, beta, eps):
# Your code here
pass3 test cases · run your code against them in the editor