KL 散度
l o s s = 正 确 值 × l o g ( 正 确 值 / 预 测 值 ) loss = 正确值 \times log(正确值/预测值) loss=正确值×log(正确值/预测值)
import tensorflow as tf
y_true = [[0, 1], [0, 0]]
y_pred = [[0.6, 0.4], [0.4, 0.6]]
# Using 'auto'/'sum_over_batch_size' reduction type.
kl = tf.keras.losses.KLDivergence()
kl(y_true, y_pred).numpy()
0.45814306