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

L2 regularization for the gradient #1

Closed
YukeWang96 opened this issue May 5, 2018 · 1 comment
Closed

L2 regularization for the gradient #1

YukeWang96 opened this issue May 5, 2018 · 1 comment

Comments

@YukeWang96
Copy link

hello,

I just wonder whether the L2 regularization for gradient should also be considered in the third question of NetworkVisualization-TensorFlow. Otherwise, the variable Xi remains unused. The computed gradient should be like dx[0] - 2 * l2_reg * Xi instead of dx[0]

@MahanFathi
Copy link
Owner

MahanFathi commented Jul 25, 2018

Hey,

That's correct. The regularization should have a share of the gradient, and that's what's actually happening here. TensorFlow calculates this automatically, hence the name of 'auto diff.' Correct me if I'm looking at the wrong piece of code:

loss = model.classifier[0, target_y] - l2_reg * tf.nn.l2_loss(model.image) # scalar loss
grad = tf.gradients(loss, model.image) # gradient of loss with respect to model.image, same
dx = sess.run(grad, feed_dict={model.image: X})
X += dx[0] * learning_rate

Best,
Mahan

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