tf.enable_eager_execution must be called at program startup ONLY in SPYDER IDE

馋奶兔 提交于 2021-02-10 03:17:59

问题


I have tried to perform an eager execution of a simple code.

I've tried it on both Jupyter Notebook and Spyder IDE. With Jupyter I have no problem but when I execute the code in Spyder it returns an error:

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.

and the code is as follows:

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:


Type Command + . (on Mac), or Ctrl + . (on Windows) to restart your Spyder kernel.



来源:https://stackoverflow.com/questions/51967975/tf-enable-eager-execution-must-be-called-at-program-startup-only-in-spyder-ide

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!