def compute(self, input, label):
     """
     compute loss
     """
     cross_entropy = layers.CrossEntropyLayer()
     reduce_mean = layers.ReduceMeanLayer()
     loss = reduce_mean.ops(cross_entropy.ops(input, label))
     return loss
Esempio n. 2
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
Esempio n. 3
0
 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
 def compute(self, input, label):
     """
     compute loss
     """
     softmax_with_cross_entropy = layers.SoftmaxWithCrossEntropyLayer()
     reduce_mean = layers.ReduceMeanLayer()
     cost = softmax_with_cross_entropy.ops(input, label)
     avg_cost = reduce_mean.ops(cost)
     return avg_cost
Esempio n. 5
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