模块';tensorflow';没有属性';运行';

模块';tensorflow';没有属性';运行';,tensorflow,Tensorflow,代码: 运行此程序时,出现以下错误: 错误: import numpy as np import tensorflow as tf a3dim = np.array([[[1,2],[3,4]], [[5,6],[7,8]] ]) print("a3dim Shape: ", a3dim.shape) tf_t=tf.convert_to_tensor(a3dim,dtype=tf.float64) print('t

代码:

运行此程序时,出现以下错误:

错误:

import numpy as np
import tensorflow as tf


a3dim = np.array([[[1,2],[3,4]],
                  [[5,6],[7,8]]
                 ])

print("a3dim Shape: ", a3dim.shape)

tf_t=tf.convert_to_tensor(a3dim,dtype=tf.float64)

print('tf_t : ',tf_t)
print('tf_t[0][0][0] : ',tf_t[0][0][0])
print('tf_t[1][1][1] : ',tf_t[1][1][1])

print('run(tf_t) : \n', tf.run(tf_t))
AttributeError回溯(最近一次调用)
在()
15印刷品('tf_t[1][1][1]:',tf_t[1][1][1])
16
--->17打印('run(tfu t):\n',tf.run(tfu t))
AttributeError:模块“tensorflow”没有属性“run”
如何解决这个tensorflow问题?
这是版本问题吗?

您必须首先创建一个会话来运行
tf\u t
,然后类似于
session.run(tf\u t)
的东西才能工作

AttributeError                            Traceback (most recent call last)
<ipython-input-9-3506c45f6784> in <module>()
     15 print('tf_t[1][1][1] : ',tf_t[1][1][1])
     16 
---> 17 print('run(tf_t) : \n', tf.run(tf_t))

AttributeError: module 'tensorflow' has no attribute 'run'
Tensorflow需要图形和会话来计算。启动图的第一步是创建会话对象。如果没有创建参数,会话生成器将启动默认图形。会话管理TensorFlow程序运行时的所有资源。完成所有计算后,需要关闭会话,以帮助系统回收资源,否则可能会出现资源泄漏问题。

将tf_t.Session()添加为tfs print('run(tf_t):\n',tfs.run(tf_t)),我现在有一个错误:文件“”,第17行,tf_t.Session()as tfs^语法错误:无效语法
import numpy as np
import tensorflow as tf


a3dim = np.array([[[1,2],[3,4]],
                  [[5,6],[7,8]]
                 ])

print("a3dim Shape: ", a3dim.shape)

tf_t=tf.convert_to_tensor(a3dim,dtype=tf.float64)

print('tf_t : ',tf_t)
print('tf_t[0][0][0] : ',tf_t[0][0][0])
print('tf_t[1][1][1] : ',tf_t[1][1][1])
sess=tf.Session()#create session
print('run(tf_t) : \n', sess.run(tf_t))
sess.close()#close session