def _get_valid_sample_fraction(labels, p=0):
"""return fraction of non-negative examples, the ignored examples have been marked as negative"""
num_valid = tf.reduce_sum(tf.cast(tf.greater_equal(labels, p), tf.float32))
num_example = tf.cast(tf.size(labels), tf.float32)
frac = tf.cond(tf.greater(num_example, 0), lambda:num_valid / num_example,
lambda: tf.cast(0, tf.float32))
frac_ = tf.cond(tf.greater(num_valid, 0), lambda:num_example / num_valid,
lambda: tf.cast(0, tf.float32))
return frac, frac_
评论列表
文章目录