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?
Asked
Active
Viewed 9,892 times
2
-
Hey, Could you post a code example describing how you got this error ? – Bruce Swain Mar 13 '20 at 13:07
-
1Well, I think I should use this: tf.compat.v1.losses.softmax_cross_entropy – Mar 13 '20 at 13:32
3 Answers
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