[我只是简单地输入了tf.Tensor Tensorflow 2.2.0中给出的代码,这是我的代码:请为错误提供解决方案

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了[我只是简单地输入了tf.Tensor Tensorflow 2.2.0中给出的代码,这是我的代码:请为错误提供解决方案相关的知识,希望对你有一定的参考价值。

我只是简单地输入了tf.Tensor Tensorflow 2.2.0中给出的代码,这是我的代码:请提供解决此错误的方法!

print(tf.__version__)
a=2
b=3
c=tf.add(a,b,name='add')
print(c)
sess = tf.Session()
print(sess.run(c))
sess.close()

输出

2.2.0
tf.Tensor(5, shape=(), dtype=int32)


  ---------------------------------------------------------------------------

AttributeError                            Traceback (most recent call last)

<ipython-input-34-0f2b1dd0c6d9> in <module>()
      4 c=tf.add(a,b,name='add')
      5 print(c)
----> 6 sess = tf.Session()
      7 print(sess.run(c))
      8 sess.close()

AttributeError: module 'tensorflow' has no attribute 'Session'
答案

使用之前导入tensorflow

import tensorflow as tf
a=2
b=3
c=tf.add(a,b,name='add')
print(c)
sess = tf.Session()
print(sess.run(c))
sess.close()

以上是关于[我只是简单地输入了tf.Tensor Tensorflow 2.2.0中给出的代码,这是我的代码:请为错误提供解决方案的主要内容,如果未能解决你的问题,请参考以下文章

TensorFlow tf.sparse_tensor_dense_matmul

仅评估 tf.Tensor 的非零值

TensorFlow:TypeError:不允许使用 `tf.Tensor` 作为 Python `bool`

python str to tensorflow tf.string tensor

Tensorflow 类型错误:不允许使用 `tf.Tensor` 作为 Python `bool`。

如何使用提供的需要 tf.Tensor 的 preprocess_input 函数预处理 tf.data.Dataset?