如何在TensorFlow中设置重量成本强度? [英] How to set weight cost strength in TensorFlow?

查看:81
本文介绍了如何在TensorFlow中设置重量成本强度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将TensorFlow用于我的深度学习项目。

I'm trying to use TensorFlow with my deep learning project.

当我使用动量梯度下降法时,重量成本强度设置如何?

(此公式。)

When I use Momentum Gradient Descent, how is the weight cost strength set?
(The λ in this formula.)

推荐答案

重量成本/衰减这一术语在TensorFlow中不是优化程序的一部分。

The term for the weight cost/decay is not part of the optimizers in TensorFlow.

很容易将其包括在内,但是可以通过在成本函数中添加额外的罚款权重的L2损失:

It is easy to include, however, by adding the extra penalty to the cost function with the L2 loss on the weights:

C = <your initial cost function>
l2_loss = tf.add_n([tf.nn.l2_loss(v) for v in tf.trainable_variables()])
C = C + lambda * l2_loss

tf.nn.l2_loss(v) 链接只是 0.5 * tf.reduce_sum(v * v),各个权重的梯度将等于 lambda * w ,应等于链接的等式。

tf.nn.l2_loss(v) link is simply 0.5 * tf.reduce_sum(v * v) and the gradients for individual weights will be equal to lambda * w, which should be equivalent to your linked equation.

这篇关于如何在TensorFlow中设置重量成本强度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆