【发布时间】:2019-01-24 19:29:06
【问题描述】:
刚刚使用 Python 3.6.6 和 CUDA 9.0 在 Win10 上安装了 tensorflow-gpu 1.10 在https://colab.research.google.com/github/tensorflow/tensorflow/blob/master/tensorflow/contrib/eager/python/examples/notebooks/custom_training.ipynb#scrollTo=_WRu7Pze7wk8尝试示例代码
问题就在顶部:
class Model(object): def __init__(self):
# Initialize variable to (5.0, 0.0)
# In practice, these should be initialized to random values.
self.W = tf.Variable(5.0)
self.b = tf.Variable(0.0)
def __call__(self, x):
return self.W * x + self.b model = Model()
assert model(3.0).numpy() == 15.0
在 Google Notebook 上运行时会失败并显示
RuntimeError: 启用急切执行时不支持 tf.Variable。请改用 tf.contrib.eager.Variable
你应该解决这个问题。修复后,代码在 Notebook 上运行不会出错。
但是,当我将它复制到本地 .py 文件并运行它时,我得到了这个非常意外的错误:
Traceback(最近一次调用最后一次): 文件“linear.py”,第 15 行,在 断言模型(3.0).numpy()== 15.0 AttributeError:“张量”对象没有属性“numpy”
但是在 Python 的交互模式下...
>>> import tensorflow as tf
>>> tf.enable_eager_execution()
>>> v = tf.contrib.eager.Variable(4.7)
>>> print( v.numpy() )
4.7
>>>
什么给了? (请记住,我是一个完全的 Python 和 tensorflow 菜鸟)
【问题讨论】:
标签: python tensorflow