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

Blu*_*unt 2 python eager spyder tensorflow jupyter-notebook

我试图对简单的代码执行急切的执行。

我在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.
Run Code Online (Sandbox Code Playgroud)

代码如下:

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.))
Run Code Online (Sandbox Code Playgroud)

Eka*_*ong 6

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