Exemple #1
0
 def compute(self, pos, neg):
     """
     compute loss
     """
     sigmoid = layers.SigmoidLayer()
     reduce_mean = layers.ReduceMeanLayer()
     loss = reduce_mean.ops(sigmoid.ops(neg - pos))
     return loss
 def compute(self, input, label):
     """
     compute loss
     """
     reduce_mean = layers.ReduceMeanLayer()
     cost = fluid.layers.cross_entropy(input=input, label=label)
     avg_cost = reduce_mean.ops(cost)
     return avg_cost
Exemple #3
0
 def compute(self, pos, neg):
     """
     compute loss
     """
     elementwise_max = layers.ElementwiseMaxLayer()
     elementwise_add = layers.ElementwiseAddLayer()
     elementwise_sub = layers.ElementwiseSubLayer()
     constant = layers.ConstantLayer()
     reduce_mean = layers.ReduceMeanLayer()
     loss = reduce_mean.ops(
         elementwise_max.ops(
             constant.ops(neg, neg.shape, "float32", 0.0),
             elementwise_add.ops(
                 elementwise_sub.ops(neg, pos),
                 constant.ops(neg, neg.shape, "float32", self.margin))))
     return loss