tf.keras.losses.KLD
Stay organized with collections
Save and categorize content based on your preferences.
Computes Kullback-Leibler divergence loss between y_true
and y_pred
.
View aliases
Main aliases
tf.keras.losses.kl_divergence
, tf.keras.losses.kld
, tf.keras.losses.kullback_leibler_divergence
, tf.keras.metrics.KLD
, tf.keras.metrics.kl_divergence
, tf.keras.metrics.kld
, tf.keras.metrics.kullback_leibler_divergence
, tf.losses.KLD
, tf.losses.kl_divergence
, tf.losses.kld
, tf.losses.kullback_leibler_divergence
, tf.metrics.KLD
, tf.metrics.kl_divergence
, tf.metrics.kld
, tf.metrics.kullback_leibler_divergence
Compat aliases for migration
See
Migration guide for
more details.
tf.compat.v1.keras.losses.KLD
, tf.compat.v1.keras.losses.kl_divergence
, tf.compat.v1.keras.losses.kld
, tf.compat.v1.keras.losses.kullback_leibler_divergence
, tf.compat.v1.keras.metrics.KLD
, tf.compat.v1.keras.metrics.kl_divergence
, tf.compat.v1.keras.metrics.kld
, tf.compat.v1.keras.metrics.kullback_leibler_divergence
tf.keras.losses.KLD(
y_true, y_pred
)
loss = y_true * log(y_true / y_pred)
See: https://en.wikipedia.org/wiki/Kullback%E2%80%93Leibler_divergence
Standalone usage:
y_true = np.random.randint(0, 2, size=(2, 3)).astype(np.float64)
y_pred = np.random.random(size=(2, 3))
loss = tf.keras.losses.kullback_leibler_divergence(y_true, y_pred)
assert loss.shape == (2,)
y_true = tf.keras.backend.clip(y_true, 1e-7, 1)
y_pred = tf.keras.backend.clip(y_pred, 1e-7, 1)
assert np.array_equal(
loss.numpy(), np.sum(y_true * np.log(y_true / y_pred), axis=-1))
Args |
y_true
|
Tensor of true targets.
|
y_pred
|
Tensor of predicted targets.
|
Returns |
A Tensor with loss.
|
Raises |
TypeError
|
If y_true cannot be cast to the y_pred.dtype .
|
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2020-10-01 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2020-10-01 UTC."],[],[]]