首页 > 其他 > 详细

tensorflow op

时间:2020-04-22 15:25:37      阅读:43      评论:0      收藏:0      [点我收藏+]

tf.control_dependencies()

with tf.control_dependencies(control_inputs)
??exec_ops
在执行某些 exec_ops 之前,control_inputs得首先被运行。但是对于 Variable 的 identity op 会在 control dependence 后重新计算,但其它 op 都不会重新计算。

x = tf.Variable(0.0)
x_plus_1 = tf.assign_add(x, 1)

with tf.control_dependencies([x_plus_1]):
    y = x

init = tf.initialize_all_variables()
with tf.Session() as session:
    init.run()
    for i in xrange(5):
        print(y.eval())

print 0, 0, 0, 0, 0

x = tf.Variable(0.0)
x_plus_1 = tf.assign_add(x, 1)

with tf.control_dependencies([x_plus_1]):
    y = tf.identity(x)

init = tf.initialize_all_variables()
with tf.Session() as session:
    init.run()
    for i in xrange(5):
        print(y.eval())

prints 1, 2, 3, 4, 5

b = tf.identity(a)

返回一个tensor(b),这个tensor的size和shape与输入tensor(a)是相同的。
可以用于CPU和GPU等不同设备之间的数据传输,以及与 control_dependencies 配合使用。

tensorflow op

原文:https://www.cnblogs.com/qccz123456/p/12752260.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!