Skip to content

Commit

Permalink
Make sure output sum equals 1
Browse files Browse the repository at this point in the history
  • Loading branch information
Frightera committed Mar 9, 2023
1 parent 40e547f commit d3dd32f
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion keras/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -5585,7 +5585,7 @@ def categorical_focal_crossentropy(
from_logits=False,
axis=-1,
):

output, from_logits = _get_logits(
output, from_logits, "Softmax", "categorical_focal_crossentropy"
)
Expand All @@ -5596,6 +5596,8 @@ def categorical_focal_crossentropy(
lambda: output,
)

output = output / tf.reduce_sum(output, axis=axis, keepdims=True)

epsilon_ = _constant_to_tensor(epsilon(), output.dtype.base_dtype)
output = tf.clip_by_value(output, epsilon_, 1.0 - epsilon_)

Expand Down

0 comments on commit d3dd32f

Please sign in to comment.