def calculate_loss_max(self, predictions, predictions_experts, labels, **unused_params):
with tf.name_scope("loss_max"):
epsilon = 10e-6
shape = predictions_experts.get_shape().as_list()
float_labels = tf.cast(labels, tf.float32)
cross_entropy_loss = float_labels * tf.log(predictions + epsilon) + (
1 - float_labels) * tf.log(1 - predictions + epsilon)
float_exprts = tf.tile(tf.reshape(float_labels,[-1,shape[1],1]),[1,1,shape[2]])
cross_entropy_experts = float_exprts * tf.log(predictions_experts + epsilon) + (
1 - float_exprts) * tf.log(1 - predictions_experts + epsilon)
cross_entropy_loss = tf.negative(cross_entropy_loss)
cross_entropy_experts = tf.negative(tf.reduce_mean(cross_entropy_experts,axis=2))
return tf.reduce_mean(tf.reduce_sum(cross_entropy_loss, 1)) + tf.reduce_mean(tf.reduce_sum(cross_entropy_experts, 1))
评论列表
文章目录