Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

why not call train_op directly? #84

Open
zhaowwenzhong opened this issue Apr 28, 2019 · 1 comment
Open

why not call train_op directly? #84

zhaowwenzhong opened this issue Apr 28, 2019 · 1 comment

Comments

@zhaowwenzhong
Copy link

# 3.7 define the optimize method
opt = tf.train.MomentumOptimizer(learning_rate=lr, momentum=args.momentum)
# 3.8 get train op
grads = opt.compute_gradients(total_loss)
update_ops = tf.get_collection(tf.GraphKeys.UPDATE_OPS)
with tf.control_dependencies(update_ops):
    train_op = opt.apply_gradients(grads, global_step=global_step)
# train_op = opt.minimize(total_loss, global_step=global_step)

what is difference between #3.8 and train_op??
why not call train_op directly?

@gouthamvgk
Copy link

Before updating the weights in every step the moving_mean and moving_variance of batchnorm layer has to be updated. This update operation is got by tf.GraphKeys.UPDATE_OPS and then run using the tf.control_dependencies which will execute it before running the context.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants