Error while using tf.keras.losses.BinaryCrossentropy

if I run this code, training happens without any errors:
model.compile(optimizer=tf.keras.optimizers.RMSprop(learning_rate=0.001),
loss=‘binary_crossentropy’,
metrics=[‘accuracy’])

however,
if I change the loss=tf.keras.losses.BinaryCrossentropy
training fails with an error

Are you using loss=tf.keras.losses.BinaryCrossentropy(), what does the error say?

2 Likes

I think @gent.spah has it exactly right, but the solution he provides may be too subtle to notice easily. Here is the relevant section of the Keras Model class documentation:

Loss function. May be a string (name of loss function), or a tf.keras.losses.Loss instance.

my emphasis added

Now compare the code producing the error

with @gent.spah’s

Which one is creating an object instance ?

2 Likes

Hello @ai_curious hope all is well! Yes i did that on purpose, to get them thinking…

1 Like

Sorry I spoiled it :cry:

No worries Kevin, have a nice day​:wave: