简介

简单实现了auc loss,还未验证,仅供参考。

all_logits = tf.reshape(self.logits, [-1])
all_label = tf.reshape(self.label, [-1])
pos_label_indices = tf.reshape(tf.where(tf.equal(all_label, tf.ones_like(all_label))), [-1])
neg_label_indices = tf.reshape(tf.where(tf.equal(all_label, tf.zeros_like(all_label))), [-1])
pos_logits = tf.gather(all_logits, pos_label_indices)
neg_logits = tf.gather(all_logits, neg_label_indices)
pos_logits_tile = tf.tile(pos_logits, [tf.shape(neg_logits)[-1]])
neg_logits_tile = tf.tile(neg_logits, [tf.shape(pos_logits)[-1]])
self.pos_logits = pos_logits
self.neg_logits = neg_logits
self.diff_logits = pos_logits_tile - neg_logits_tile
self.auc_loss = tf.reduce_mean(-tf.log(1./(1.+tf.exp(-self.diff_logits))))
self.loss = self.auc_loss + self.reg_loss