import numpy as np
fake_preds = np.random.rand(10,768) # assuming predictions of some model (10 examples)
fake_labels = np.random.rand(10,1) # fake labels for 10 examples
loss1 = tf.keras.losses.BinaryCrossentropy(from_logits=True)
print(loss1(fake_labels, fake_preds).numpy())
--> Throws shape mismatch error:
ValueError: `logits` and `labels` must have the same shape, received ((10, 768) vs (10, 1)).
loss2 = tf.keras.losses.BinaryCrossentopy(from_logits=False)
print(loss2(fake_labels, fake_preds),numpy())
--> 0.998 (some value for random labels and preds), works well!
Why???
Keras Documentation statest the shape of logits and targets must be same for loss functions to work properly. Then why is it that there is no shape mismatch error on from_logits = False!