首页 > 解决方案 > 模块“张量流”没有属性“运行”

问题描述

代码:

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                            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

解决方案


您必须首先创建一个会话才能运行, tf_t然后才能运行session.run(tf_t)


推荐阅读