Tensorflow图获取范围中的所有常量
我创建了一个图,现在我想获取他们的ops,我该怎么做Tensorflow图获取范围中的所有常量,tensorflow,graph,Tensorflow,Graph,我创建了一个图,现在我想获取他们的ops,我该怎么做 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
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!)
g=tf.Graph()
使用g.as_default():
#定义输入
使用tf.name_范围(“输入”):
a=tf.constant(2,tf.int32,name=“a”)
b=tf.constant(3,tf.int32,name=“b”)
#老年退休金
使用tf.name_范围(“ops”):
c=tf.乘法(a,b,name=“c”)
d=tf.add(a,b,name=“d”)
e=tf.减去(c,d,name=“e”)
sess=tf.InteractiveSession()
_c、 _d,_e= 我会做好的
g = tf.Graph()
...
for ops in g.get_operations():
print(ops)
这将解决您的问题:)
sess = tf.Session(graph=g)
_c, _d, _e = sess.run([c, d, e])
print("c =", _c)
print("d =", _d)
print("e =", _e)