From 24fbe6d6109b5db9bfa4d4d2445d0b4b89746091 Mon Sep 17 00:00:00 2001 From: ceci3 <592712189@qq.com> Date: Mon, 11 Mar 2019 04:05:25 +0000 Subject: [PATCH] test=develop, replace sce --- python/paddle/fluid/layers/nn.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/python/paddle/fluid/layers/nn.py b/python/paddle/fluid/layers/nn.py index 9d1d5fe09..d0bff52e4 100644 --- a/python/paddle/fluid/layers/nn.py +++ b/python/paddle/fluid/layers/nn.py @@ -10704,8 +10704,9 @@ def npair_loss(anchor, positive, labels, l2_reg=0.002): similarity_matrix = matmul( anchor, positive, transpose_x=False, transpose_y=True) - softmax_value = softmax(similarity_matrix) - cross_entropy = -1 * reduce_sum(labels * log(softmax_value), 0) + softmax_ce = softmax_with_cross_entropy( + logits=similarity_matrix, label=labels, soft_label=True) + cross_entropy = reduce_sum(labels * softmax_ce, 0) celoss = reduce_mean(cross_entropy) return l2loss + celoss -- GitLab