This post explains difference between BinaryCrossentropy
and CategoricalCrossentropy
BinaryCrossentropy
is used for computing loss between true labels and predicted labelsBinaryCrossentropy
only when there are only two label classes.
For each example, there should be a single floating-point value per prediction
BinaryCrossentropy
in TensorFlow
import tensorflow as tf
y_true = [[0., 1.], [0., 0.]]
y_pred = [[0.6, 0.4], [0.4, 0.6]]
bce_loss = tf.keras.losses.BinaryCrossentropy()
bce_loss_value = bce_loss(y_true, y_pred).numpy()
print(bce_loss_value)
CategoricalCrossentropy
is used for computing loss between true labels and predicted labelsCategoricalCrossentropy
only when there are two or more label classes.
CategoricalCrossentropy
labels should be provided in a one_hot
representationCategoricalCrossentropy
in TensorFlow
import tensorflow as tf
y_true = [[0, 1, 0], [0, 0, 1]]
y_pred = [[0.05, 0.95, 0], [0.1, 0.8, 0.1]]
cce_loss = tf.keras.losses.CategoricalCrossentropy()
cce_loss_value = cce_loss(y_true, y_pred).numpy()
print(cce_loss_value)
Similar Articles