必须仅在SPYDER IDE中的程序启动时调用tf.enable_eager_execution

时间:2018-08-22 13:26:04

标签: python tensorflow jupyter-notebook spyder eager

我试图执行简单的代码。

我在Jupyter Notebook和Spyder IDE上都尝试过。 使用Jupyter,我没有问题,但是当我在Spyder中执行代码时,它将返回错误:

File "C:\...\lib\site-packages\tensorflow\python\framework\ops.py", line 5496, in enable_eager_execution "tf.enable_eager_execution must be called at program startup.")
ValueError: tf.enable_eager_execution must be called at program startup.

,代码如下:

import tensorflow as tf
tf.enable_eager_execution ()
import tensorflow.contrib.eager as tfe
def square (x):
     return tf.multiply (x, x)

grad = tfe.gradients_function (square)

print (grad (3.))

1 个答案:

答案 0 :(得分:6)

输入Command + .(在Mac上)或Ctrl + .(在Windows上)重新启动Spyder内核。