objectives.py 文件源码

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

项目:tflearn 作者: tflearn 项目源码 文件源码
def contrastive_loss(y_pred, y_true, margin = 1.0):
    """ Contrastive Loss.

        Computes the constrative loss between y_pred (logits) and
        y_true (labels).

        http://yann.lecun.com/exdb/publis/pdf/chopra-05.pdf
        Sumit Chopra, Raia Hadsell and Yann LeCun (2005).
        Learning a Similarity Metric Discriminatively, with Application to Face Verification.

        Arguments:
            y_pred: `Tensor`. Predicted values.
            y_true: `Tensor`. Targets (labels).
            margin: . A self-set parameters that indicate the distance between the expected different identity features. Defaults 1.
    """

    with tf.name_scope("ContrastiveLoss"):
        dis1 = y_true * tf.square(y_pred)
        dis2 = (1 - y_true) * tf.square(tf.maximum((margin - y_pred), 0))
        return tf.reduce_sum(dis1 +dis2) / 2.
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号