2

I have an AttributeError: module 'tensorflow_core.python.keras.api._v2.keras.losses' has no attribute 'softmax_cross_entropy' error when using tf.losses.softmax_cross_entropy. Could someone help me?

3 Answers3

0

The tf.losses now point to tf.keras.losses. You can get identical behavior by using tf.losses.categorical_crossentropy with from_logits set to True

Srihari Humbarwadi
  • 2,532
  • 1
  • 10
  • 28
0

Sometimes we encounter this error, especially when running on online binders like jupyter notebook. Instead of writing

tf.losses.softmax_cross_entropy

try

loss = 'softmax_cross_entropy'

or either of the below

tf.keras.losses.CategoricalCrossentropy()
loss = 'categorical_crossentropy'

You may also want to use from_logits=True as an argument - which shall look like

tf.keras.losses.CategoricalCrossentropy(from_logits=True) 

while keep metrics something like

metrics=['accuracy']
Bhanu Chander
  • 390
  • 1
  • 6
  • 16
0

It might be loss=tf.keras.losses.BinaryCrossentropy()

aoyilmaz
  • 139
  • 1
  • 10