代码问题1:出现AttributeError: RefVariable object has no attribute numpy
2020-05-25 20:16
826 查看
Tensorflow出现AttributeError: ‘RefVariable’ object has no attribute 'numpy’如下错误信息
代码中使用x.numpy()输出信息时报错
import tensorflow as tf ignition = tf.Variable(451, tf.int16) print(ignition.numpy()) AttributeError Traceback (most recent call last) <ipython-input-10-3e5e7544b714> in <module> 1 ----> 2 print(ignition.numpy()) AttributeError: 'RefVariable' object has no attribute 'numpy'
这个错误一般出现在tensorflow1.x版本中,2.0版本不会出现
解决办法:
在程序初始时加入如下代码,报错信息即可消除。
tf.enable_eager_execution( config=None, device_policy=None, execution_mode=None )
加入上述代码之后,有时会接着出现如下错误:
ValueError: tf.enable_eager_execution must be called at program startup.
这是由于使用jupyter notebook这类编辑器引起的,这个时候只需要重新运行一下 kernel 就可以了,restart 即可消除错误。
相关文章推荐
- Python3网络爬虫开发实战(崔庆才)笔记——ProxyPool的代码问题:AttributeError: 'int' object has no attribute 'item及相关问题的处理
- python问题:爬虫出现“AttributeError: 'str' object has no attribute 'sleep'”
- Tensorflow 解决AttributeError: 'RefVariable' object has no attribute 'numpy'报错信息
- 用python3连接MySQL数据库出现问题“AttributeError: 'str' object has no attribute 'decode'“解决办法
- 使用旧版本tensorflow出现了negative等报错的问题,AttributeError: 'module' object has no attribute 'xxx'"
- Python 保存数组至.mat文件,报错:AttributeError: 'numpy.ndarray' object has no attribute 'items'
- 出现错误如下:AttributeError: 'module' object has no attribute 'SSL_ST_INIT'
- AttributeError: 'module' object has no attribute 'handlers'--Python子模块导入问题
- 解决Pycharm更新package出现的问题:AttributeError:module 'pip' has no attribute 'main'
- Python连接字符串,join出现问题:python 'list' object has no attribute
- scrapy:使用response.follow()方法时出现AttributeError: 'HtmlResponse' object has no attribute 'follow'
- AttributeError 'module' object has no attribute 'handlers'--Python子模块导入问题
- 关于python里运行出现'module' object has no attribute 'xxxx'等问题解决方法
- ubuntu18.04+anaconda安装opencv出现AttributeError: type object 'numpy.ndarray' has no attribute '__array_
- AttributeError: 'dict' object has no attribute 'items' 问题
- python问题请教:大佬们 AttributeError: 'int' object has no attribute 'save_bullet'
- 执行《机器学习实战》15章代码15-3出现AttributeError: 'MRmean' object has no attribute 'mr'
- 机器学习实战:KNN代码报错“AttributeError: 'dict' object has no attribute 'iteritems'”
- Python爬虫——xpath出现错误 AttributeError: 'NoneType' object has no attribute 'xpath'
- 解决 AttributeError: 'module' object has no attribute 'LBPHFaceRecognizer_create' 问题