AttributeError: ‘builtfunction‘ object has no attribute numpy

label原来加载在CUDA,现在需要将label加载到cpu上然后进行numpy处理,出现了上述报错。

label = label.cpu.numpy()

网上找了找,方法包括,tensorflow版本太低,或者在import tf之后添加:

tf.compat.v1.disable_eager_execution()

试了一下发现都没有用。
最后无意中看到了代码:

prediction = prediction.cpu()
prediction = prediction.numpy()

于是我也把代码改成:

 label = label.cpu()
 label = label.label.numpy()

或者:

label = label.cpu().numpy()

试了一下竟然可以跑通,bug解决。原来是.cpu后面少加了个括号,导致我两个小时都没检查出来,太不细心了。

猜你喜欢

转载自blog.csdn.net/qq_43733107/article/details/128959867