def calculate_loss_postprocess(self, predictions, labels, **unused_params):
with tf.name_scope("loss_postprocess"):
float_labels = tf.cast(labels, tf.float32)
predictions_pos = predictions*float_labels + (1-float_labels)
predictions_neg = predictions*(1-float_labels)
min_pos = tf.stop_gradient(tf.reduce_min(predictions_pos))
max_neg = tf.stop_gradient(tf.reduce_max(predictions_neg))
predictions_pos_mistake = tf.nn.relu(max_neg-predictions_pos)-0.01*tf.nn.relu(predictions_pos-max_neg)
predictions_neg_mistake = tf.nn.relu(predictions_neg-min_pos)-0.01*tf.nn.relu(min_pos-predictions_neg)
postprocess_loss = predictions_pos_mistake + predictions_neg_mistake
return tf.reduce_mean(tf.reduce_sum(postprocess_loss, 1))
评论列表
文章目录