提交 a80555a3 编写于 作者: C ceci3

test=develop, change import

上级 d35367d2
......@@ -32,8 +32,6 @@ from .. import unique_name
from functools import reduce
from .. import core
from ..imperative import layers
from .control_flow import equal
from .ops import square
__all__ = [
'fc',
......@@ -10656,6 +10654,10 @@ def tree_conv(nodes_vector,
return helper.append_activation(pre_activation)
from control_flow import equal
from ops import square
def npair_loss(anchor, positive, labels, l2_reg=0.002):
'''
**Npair Loss Layer**
......@@ -10693,11 +10695,13 @@ def npair_loss(anchor, positive, labels, l2_reg=0.002):
labels = reshape(labels, shape=[batch_size, 1], inplace=True)
labels = expand(labels, expand_times=[1, batch_size])
labels = equal(labels, transpose(labels, perm=[1, 0])).astype('float32')
labels = control_flow.equal(
labels, transpose(
labels, perm=[1, 0])).astype('float32')
labels = labels / reduce_sum(labels, dim=1, keep_dim=True)
l2loss = reduce_mean(reduce_sum(square(anchor), 1)) \
+ reduce_mean(reduce_sum(square(positive), 1))
l2loss = reduce_mean(reduce_sum(ops.square(anchor), 1)) \
+ reduce_mean(reduce_sum(ops.square(positive), 1))
l2loss = l2loss * Beta * l2_reg
similarity_matrix = matmul(
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册