- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
tensorflow 中 tf.control_dependencies(tf.get_collection(tf.GraphKeys.UPDATE_OPS))
的目的是什么?
更多上下文:
optimizer = tf.train.AdamOptimizer(FLAGS.learning_rate)
with tf.control_dependencies(tf.get_collection(tf.GraphKeys.UPDATE_OPS)):
train_op = optimizer.minimize(loss_fn, var_list=tf.trainable_variables())
最佳答案
tf.control_dependencies
方法可以确保用作上下文管理器输入的操作在上下文管理器内部定义的操作之前运行。
例如:
count = tf.get_variable("count", shape=(), initializer=tf.constant_initializer(1), trainable=False)
count_increment = tf.assign_add(count, 1)
c = tf.constant(2.)
with tf.control_dependencies([count_increment]):
d = c + 3
with tf.Session() as sess:
sess.run(tf.global_variables_initializer())
print("eval count", count.eval())
print("eval d", d.eval())
print("eval count", count.eval())
这打印:
eval count 1
eval d 5.0 # Running d make count_increment operation being run
eval count 2 # count_increment operation has be run and now count hold 2.
因此,在您的情况下,每次运行 train_op
操作时,它将首先运行 tf.GraphKeys.UPDATE_OPS
集合中定义的所有操作。
关于python - tf.control_dependencies(tf.get_collection(tf.GraphKeys.UPDATE_OPS)) 在 tensorflow 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53772787/
我想要一个例子来说明 tf.control_dependencies 函数的使用。 .例如,我想创建两个张量 X 和 Y 并且如果它们相等,则执行或打印某些内容。 import tensorflow
我运行一段代码两次得到两个不同的结果 代码: import tensorflow as tf x = tf.placeholder(tf.int32, shape=[], name='x') y =
除了 tf.control_dependencies作为上下文管理器(即与 Python with 一起使用), tf.group 之间有什么区别?和 tf.control_dependencies
我正在尝试构建一个具有两个损失函数的神经网络,它们像加权和一样组合在一起。第一个简单地计算 mean square error密集层和给定标签的线性输出,但另一个大量使用嵌套 tf.map_fn 。有
tensorflow 中 tf.control_dependencies(tf.get_collection(tf.GraphKeys.UPDATE_OPS)) 的目的是什么? 更多上下文:
我是一名优秀的程序员,十分优秀!