Skip to content
DeepForgeby svx
All problems
MediumDeep Learningdl-071

Instance Norm Forward

Problem

Instance normalization: normalize each channel independently over its features using the biased mean and variance, then scale by gamma[c] and shift by beta[c].

The signature is instance_norm_forward(x, gamma, beta, eps=1e-5). x has shape (channels, features).

Hint

Instance norm is exactly group norm with one group per channel.

Test cases

case 1
in: [[[0,2],[4,6]],[1,1],[0,0]]
expected: [[-0.999995,0.999995],[-0.999995,0.999995]]
case 2
in: [[[1,2,3]],[2],[1]]
expected: [[-1.4494713718,1,3.4494713718]]
case 3
in: [[[1,1],[1,1]],[1,1],[0,0]]
expected: [[0,0],[0,0]]
case 4
in: [[[1,2],[3,4]],[0.5,2],[1,-1]]
expected: [[0.5000099997,1.4999900003],[-2.9999600012,0.9999600012]]
Starter codePython
import math
def instance_norm_forward(x, gamma, beta, eps=1e-5):
    # Your code here
    pass

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