Python ';非类型';对象没有属性';运行';张量流
我使用的是Windows 10 64位,在尝试安装TensorFlow时发现了问题,经过多次尝试,我创建了一个新环境,安装了python 3.7.3,并使用了以下命令Python ';非类型';对象没有属性';运行';张量流,python,tensorflow,Python,Tensorflow,我使用的是Windows 10 64位,在尝试安装TensorFlow时发现了问题,经过多次尝试,我创建了一个新环境,安装了python 3.7.3,并使用了以下命令 # conda create -n TensorFlow python=3.7.3 # conda activate TensorFlow # conda install tensorflow 最后,安装了TensorFlow。 当尝试以下代码时 # add_two_numbers_via_TensorFlow.py impo
# conda create -n TensorFlow python=3.7.3
# conda activate TensorFlow
# conda install tensorflow
最后,安装了TensorFlow。
当尝试以下代码时
# add_two_numbers_via_TensorFlow.py
import tensorflow.compat.v1 as tf
# import tensorflow as tf
# get the two numbers to add from the command prompt
intNum1 = int(input("enter num 1: "))
intNum2 = int(input("enter num 2: "))
# establish two tensors, one for each input number
num1 = tf.Variable(intNum1)
num2 = tf.Variable(intNum2)
# establish graph
sum = tf.add(num1, num2)
# note that this shows information about sum, but does NOT evaluate anything yet
print("sum = " + str(sum))
# instantiate a global variables initializer
globalVarsInitializer = tf.global_variables_initializer()
# globalVarsInitializer = tf.compat.v1.global_variables_initializer()
#globalVarsInitializer = tf.global_variables_initializer()
# finally we can run the graph (in a session)
with tf.Session() as sess:
globalVarsInitializer.run()
result = sum.eval()
# end with
# show the result
print("Result = " + str(result))
我遇到了以下问题
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-5-ba92b50d5523> in <module>
25 # finally we can run the graph (in a session)
26 with tf.Session() as sess:
---> 27 globalVarsInitializer.run()
28 result = sum.eval()
29 # end with
AttributeError: 'NoneType' object has no attribute 'run'
---------------------------------------------------------------------------
AttributeError回溯(最近一次呼叫上次)
在里面
25#最后我们可以运行图表(在会话中)
26将tf.Session()作为SES:
--->27 globalVarsInitializer.run()
28结果=sum.eval()
29#以
AttributeError:“非类型”对象没有属性“运行”
有什么帮助可以解决这样的问题吗?**在这一行
导入tensorflow.compat.v1作为tf
之后,我使用了这一行tf.disable\u eager\u execution()
**而不是这条线
globalVarsInitializer.run()
我使用了这一行sess.run(globalVarsInitializer)
这就解决了问题