Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
lvapeab committed Feb 20, 2020
1 parent 83501a0 commit 252d094
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions keras/backend/tensorflow_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -4113,8 +4113,16 @@ def binary_crossentropy(target, output, from_logits=False):
# Returns
A tensor.
"""
return tf_keras_backend.binary_crossentropy(
target, output, from_logits=from_logits)
# Note: tf.nn.sigmoid_cross_entropy_with_logits
# expects logits, Keras expects probabilities.
if not from_logits:
# transform back to logits
_epsilon = _to_tensor(epsilon(), output.dtype.base_dtype)
output = tf.clip_by_value(output, _epsilon, 1 - _epsilon)
output = tf.log(output / (1 - output))

return tf.nn.sigmoid_cross_entropy_with_logits(labels=target,
logits=output)


def weighted_binary_crossentropy(target, output, from_logits=False, lambda_w_rec=1.0, lambda_w_pre=1.0):
Expand Down

0 comments on commit 252d094

Please sign in to comment.