擅长:python、mysql、java
<p>根据<a href="https://www.tensorflow.org/guide/graphs" rel="nofollow noreferrer">documentation</a>:</p>
<blockquote>
<p>TensorFlow uses the tf.Session class to represent a connection between
the client program -typically a Python program, although a similar
interface is available in other languages -and the C++ runtime.</p>
</blockquote>
<p>这意味着当你做<code>values = tf.constant([0, 1, 2, 0, 2], dtype=tf.float32)</code>时,你只是在你的tensorflow图中插入一个节点!由于Python是一个低级C++运行时的高级API,所以实际上需要一个会话来在这个低级运行时评估Python代码。在</p>
<p>这就是为什么每次需要计算或计算Tensorflow变量/方法/常量/等时,都需要在会话中使用<code>tf.Session().run(yournode)</code>运行它</p>
<p>我希望对你有帮助</p>