Tensorflow图获取范围内的所有const

时间:2018-10-25 15:18:55

标签: tensorflow graph

我创建了一个图形,现在我想获取他们的操作,我该怎么做?

g = tf.Graph()

with g.as_default():
    # Define inputs
    with tf.name_scope("inputs"):
        a = tf.constant(2, tf.int32, name="a")
        b = tf.constant(3, tf.int32, name="b")

    # Ops
    with tf.name_scope("ops"):
        c = tf.multiply(a, b, name="c")
        d = tf.add(a, b, name="d")
        e = tf.subtract(c, d, name="e")

sess = tf.InteractiveSession()

_c, _d, _e = ... <-- (I need some code here!)

您能告诉我有关此文档的链接吗?

2 个答案:

答案 0 :(得分:1)

sess = tf.Session(graph=g)

_c, _d, _e = sess.run([c, d, e])
print("c =", _c)
print("d =", _d)
print("e =", _e)

这将解决您的问题:)

答案 1 :(得分:0)

Get_Operations()将完成工作

g = tf.Graph()
...

for ops in g.get_operations():
    print(ops)