节点与操作之间的区别

时间:2019-05-06 15:10:07

标签: tensorflow

我不明白Tensorflow中的节点和操作之间有什么区别。

例如:

with open('myfile_1','w') as myfile:
     for n in tf.get_default_graph().as_graph_def().node:
         myfile.write(n.name+'\n')



with open('myfile_2','w') as myfile:
     for op in tf.get_default_graph().get_operations():
         myfile.write(op.name+'\n')

什么进入myfile_1,什么进入myfile_2?和类/文件所属的变量?

我们可以全部将其称为“张量器”吗?我对这里的术语有些困惑...

根据评论中的建议,我在此处添加一个简单图形上的结果:

tf.reset_default_graph()
x=tf.placeholder(tf.float32,[1])
y=2*x
z=tf.constant(3.0,dtype=tf.float32)
w=tf.get_variable('w',[2,3], initializer = tf.zeros_initializer())

with open('myfile_1','w') as myfile:
     for n in tf.get_default_graph().as_graph_def().node:
         myfile.write(n.name+'\n')

with open('myfile_2','w') as myfile:
     for op in tf.get_default_graph().get_operations():
         myfile.write(op.name+'\n')

with tf.Session() as sess:
     print(sess.run(y,feed_dict={x : [3]}))

在这种情况下,myfile_1和myfile_2都等于:

Placeholder
mul/x
mul
Const
w/Initializer/zeros
w
w/Assign
w/read

2 个答案:

答案 0 :(得分:1)

Tensorflow图是有向图,使得:

  • 节点-操作(操作)。
  • 有向边-张量。

例如,当您定义时:

SELECT 
    f.name, 
    CONCAT(CONCAT( m.firstname, ' '), m.surname ) AS mem_name
FROM  `Bookings` b
JOIN  `Members` m ON m.memid = b.memid
JOIN  `Facilities` f ON b.facid = f.facid
WHERE f.name LIKE  '%Tennis%'
LIMIT 0, 30

x = tf.placeholder(tf.float32, shape=(None, 2)) 是张量,它是x op的输出:

Placeholder

print(x.op.type) # Placeholder 返回图的SERIALIZED版本(认为是文本版本)。 as_graph_def()返回实际操作,而不是其序列化表示。当您打印这些操作(或将它们写入文件)时,您将获得相同的值,因为操作的get_operation()方法返回其序列化形式。

您不会总是得到相同的值。例如:

__str__()

有关更多信息,您可以参考原始的张量流paper

答案 1 :(得分:0)

我将直接回答问题:

操作是它们只进行计算的节点。

操作(tensorflow):操作是TensorFlow图中的一个节点,该节点将零个或多个Tensor对象作为输入,并产生零个或多个Tensor对象作为输出。

您可以看到this

相关问题