![](/img/trans.png)
[英]Tensorflow: AttributeError: module 'tensorflow.python.ops.nn' has no attribute 'softmax_cross_entropy_with_logits_v2'
[英]AttributeError: module 'tensorflow_core.python.keras.api._v2.keras.losses' has no attribute 'softmax_cross_entropy'
我有一个 AttributeError: module 'tensorflow_core.python.keras.api._v2.keras.losses' has no attribute 'softmax_cross_entropy' 使用 tf.losses.softmax_cross_entropy 时出错。 有人可以帮助我吗?
tf.losses
现在指向tf.keras.losses
。 您可以通过使用tf.losses.categorical_crossentropy
并将from_logits
设置为True
来获得相同的行为
有时我们会遇到此错误,尤其是在 jupyter notebook 等在线活页夹上运行时。 而不是写作
tf.losses.softmax_cross_entropy
尝试
loss = 'softmax_cross_entropy'
或以下任一项
tf.keras.losses.CategoricalCrossentropy()
loss = 'categorical_crossentropy'
您可能还想使用 from_logits=True 作为参数 - 看起来像
tf.keras.losses.CategoricalCrossentropy(from_logits=True)
同时保持指标类似
metrics=['accuracy']
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.