Skip to content

Commit

Permalink
Unify BN behavior in TF and Theano
Browse files Browse the repository at this point in the history
  • Loading branch information
fchollet committed Aug 3, 2016
1 parent 5367a44 commit 97d2a73
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
4 changes: 3 additions & 1 deletion keras/backend/tensorflow_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -649,7 +649,9 @@ def normalize_batch_in_training(x, gamma, beta,


def batch_normalization(x, mean, std, beta, gamma, epsilon=0.0001):
'''Apply batch normalization on x given mean, std, beta and gamma.
'''Apply batch normalization on x given mean, std, beta and gamma:
output = (x - mean) / (sqrt(std) + epsilon) * gamma + beta
'''
return tf.nn.batch_normalization(x, mean, std, beta, gamma, epsilon)

Expand Down
3 changes: 2 additions & 1 deletion keras/backend/theano_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,8 @@ def normalize_batch_in_training(x, gamma, beta,
def batch_normalization(x, mean, std, beta, gamma, epsilon=0.0001):
'''Apply batch normalization on x given mean, std, beta and gamma.
'''
normed = T.nnet.bn.batch_normalization(x, gamma, beta, mean, std + epsilon,
normed = T.nnet.bn.batch_normalization(x, gamma, beta, mean,
sqrt(std) + epsilon,
mode='high_mem')
return normed

Expand Down

0 comments on commit 97d2a73

Please sign in to comment.