首页 > 解决方案 > 启用 Eager Execution 时,Tensor.graph 毫无意义

问题描述

a = tf.compat.v1.constant(5.0)
b = tf.compat.v1.constant(6.0)

sum1 = a + b
g = tf.compat.v1.Graph()
with g.as_default():
    # Define operations and tensors in `g`.
    hello = tf.compat.v1.constant('hello')
    assert hello.graph is g

sess = tf.compat.v1.Session(graph=g)

print(sess.run(sum1))


tensorflow-gpu2.0 我不知道为什么。我是张量流的初学者

标签: pythontensorflow

解决方案


导入 tensorflow 后需要禁用急切执行,如下所示:

import tensorflow as tf
tf.compat.v1.disable_eager_execution()

它对我有用。


推荐阅读