Skip to content

Commit

Permalink
[feat] implement 'batchnorm_forward' function #1
Browse files Browse the repository at this point in the history
  • Loading branch information
jeongjae96 committed Feb 28, 2023
1 parent 156886f commit c1977d5
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions cs231n_2022/assignment2/cs231n/layers.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,13 @@ def batchnorm_forward(x, gamma, beta, bn_param):
#######################################################################
# *****START OF YOUR CODE (DO NOT DELETE/MODIFY THIS LINE)*****

pass
sample_mean = np.mean(x, axis=0)
sample_var = np.var(x, axis = 0)
normalized_x = (x - sample_mean) / (np.sqrt(sample_var + eps))
out = gamma * normalized_x + beta
cache = (x, sample_mean, sample_var, eps, normalized_x, gamma)
running_mean = momentum * running_mean + (1 - momentum) * sample_mean
running_var = momentum * running_var + (1 - momentum) * sample_var

# *****END OF YOUR CODE (DO NOT DELETE/MODIFY THIS LINE)*****
#######################################################################
Expand All @@ -242,7 +248,8 @@ def batchnorm_forward(x, gamma, beta, bn_param):
#######################################################################
# *****START OF YOUR CODE (DO NOT DELETE/MODIFY THIS LINE)*****

pass
normalized_x = (x - running_mean) / np.sqrt(eps + running_var)
out = gamma * normalized_x + beta

# *****END OF YOUR CODE (DO NOT DELETE/MODIFY THIS LINE)*****
#######################################################################
Expand Down

0 comments on commit c1977d5

Please sign in to comment.