def errors(logits, labels, name=None):
"""Compute error mean and whether each unlabeled example is erroneous
Assume unlabeled examples have label == -1.
Compute the mean error over unlabeled examples.
Mean error is NaN if there are no unlabeled examples.
Note that unlabeled examples are treated differently in cost calculation.
"""
with tf.name_scope(name, "errors") as scope:
applicable = tf.not_equal(labels, -1)
labels = tf.boolean_mask(labels, applicable)
logits = tf.boolean_mask(logits, applicable)
predictions = tf.argmax(logits, -1)
labels = tf.cast(labels, tf.int64)
per_sample = tf.to_float(tf.not_equal(predictions, labels))
mean = tf.reduce_mean(per_sample, name=scope)
return mean, per_sample
评论列表
文章目录