官方說明書的例子其實特別簡單明了,
y_true = [[0., 1.], [0., 0.]]
y_pred = [[0.6, 0.4], [0.4, 0.6]]
# Using 'auto'/'sum_over_batch_size' reduction type.
bce = tf.keras.losses.BinaryCrossentropy()
bce(y_true, y_pred).numpy()
從這個例子也可以看出,BinaryCrossentropy
是支持one-hot編碼的。