解决:'Tensor' object has no attribute 'numpy'
程序员文章站
2022-07-13 10:51:54
...
环境
- tensoflow >= 1.14
制造错误:
import tensorflow as tf
m = tf.keras.metrics.Accuracy()
m.update_state([1, 2, 3, 4], [1, 2, 3, 4])
print('Final result: ', m.result().numpy())
错误:
AttributeError: 'Tensor' object has no attribute 'numpy'
解决方式:(版本1.14后才有的特性)
import tensorflow as tf
tf.enable_eager_execution() # 关键
m = tf.keras.metrics.Accuracy()
m.update_state([1, 2, 3, 4], [1, 2, 3, 4])
print('Final result: ', m.result().numpy())
推荐阅读
-
module ‘seaborn‘ has no attribute ‘scatterplot‘解决方案
-
AttributeError: module ‘community‘ has no attribute ‘best_partition‘ 问题解决方法
-
module ‘community‘ has no attribute ‘best_partition‘ [已解决]
-
【python】解决AttributeError: module ‘scipy.misc‘ has no attribute ‘toimage‘问题
-
numpy.savetxt() 报错 Mismatch between array dtype (‘object‘) and format specifier (‘%.18e‘)的解决方法
-
AttributeError: 'module' object has no attribute 'main'
-
解决Keras报错AttributeError: 'NoneType' object has no attribute 'inbound_nodes'
-
解决'DataFrame' object has no attribute 'sort'
-
‘MyObject‘ object has no attribute ‘***‘
-
AttributeError: ‘NoneType‘ object has no attribute ‘origin‘解决办法