sách gpt4 ăn đã đi

python - tf.control_dependencies(tf.get_collection(tf.GraphKeys.UPDATE_OPS)) 在 tensorflow 中

In lại 作者:太空狗 更新时间:2023-10-29 22:24:15 28 4
mua khóa gpt4 giày nike

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())

câu trả lời hay nhất

tf.control_dependencies 方法可以确保用作上下文管理器输入的操作在上下文管理器内部定义的操作之前运行。

Ví dụ:

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
với tf.Session() là 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/

28 4 0
Chứng chỉ ICP Bắc Kinh số 000000
Hợp tác quảng cáo: 1813099741@qq.com 6ren.com
Xem sitemap của VNExpress