如题,本人新手,安装tensorflow 后执行官网示例,输入sess =Session ()后无反应,重装tensorflow 后还是这样,请问这要怎么解决?
import tensorflow as tf
tf.compat.v1.disable_eager_execution()
hello = tf.constant('hello,tensorflow')
sess= tf.compat.v1.Session()
print(sess.run(hello))
参考stackoverflow
这样试试:
import os
import tensorflow as tf
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2'
tf.compat.v1.disable_eager_execution()
hello = tf.constant("Hello, TensorFlow!")
session = tf.compat.v1.Session()
print(session.run(hello))
session.close()
你下载的tensorflow应该是2,tensorflow2里面没有Session这个功能所有要去调用1里面的功能
import os
import tensorflow as tf
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2'
tf.compat.v1.disable_eager_execution()
hello = tf.constant("Hello, TensorFlow!")
session = tf.compat.v1.Session()
print(session.run(hello))
print("Hello Anaconda")
print("==============")
session.close()
无反应没报错说明是正在执行 等几分钟试试
看看环境是不是有问题
解决了吗,我也出先了这个问题,我输入tf.Session() as sess: 在pycharm里,他没有主动提示Session, 运行也是在这里出问题,tensorflow已经成功安装了
最上面回答的对,就是这样的
import os
import tensorflow as tf
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2'
tf.compat.v1.disable_eager_execution()
hello = tf.constant("Hello, TensorFlow!")
session = tf.compat.v1.Session()
print(session.run(hello))
print("Hello Anaconda")
print("==============")
session.close()