losses.py 文件源码

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

项目:tefla 作者: openAGI 项目源码 文件源码
def decov_loss(xs, name='decov_loss'):
    """Decov loss as described in https://arxiv.org/pdf/1511.06068.pdf
    'Reducing Overfitting In Deep Networks by Decorrelating Representation'

    Args:
        xs: 4-D `tensor` [batch_size, height, width, channels], input

    Returns:
        a `float` decov loss
    """
    with tf.name_scope(name):
        x = tf.reshape(xs, [int(xs.get_shape()[0]), -1])
        m = tf.reduce_mean(x, 0, True)
        z = tf.expand_dims(x - m, 2)
        corr = tf.reduce_mean(tf.matmul(z, tf.transpose(z, perm=[0, 2, 1])), 0)
        corr_frob_sqr = tf.reduce_sum(tf.square(corr))
        corr_diag_sqr = tf.reduce_sum(tf.square(tf.diag_part(corr)))
        loss = 0.5 * (corr_frob_sqr - corr_diag_sqr)
        return loss
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号