losses.py 文件源码

python
阅读 17 收藏 0 点赞 0 评论 0

项目:polyaxon 作者: polyaxon 项目源码 文件源码
def huber_loss(weights=1.0, clip=0.0, name='HuberLoss', scope=None, collect=True):
    """Computes Huber Loss for DQN.

    [Wikipedia link](https://en.wikipedia.org/wiki/Huber_loss)
    [DeepMind link](https://sites.google.com/a/deepmind.com/dqn/)

    Args:
        weights: Coefficients for the loss a `scalar`.
        scope: scope to add the op to.
        name: name of the op.
        collect: add to losses collection.

    Returns:
        A scalar `Tensor` representing the loss value.

    Raises:
        ValueError: If `predictions` shape doesn't match `labels` shape, or `weights` is `None`.
    """

    def inner_loss(y_true, y_pred):
        delta = math_ops.abs(math_ops.subtract(y_pred, y_true))
        losses = math_ops.square(delta)
        if clip > 0.0:
            losses = tf.where(delta < clip, 0.5 * losses, delta - 0.5)

        return losses
    return built_loss(inner_loss, weights, name, scope, collect)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号