Skip to content
Snippets Groups Projects
Commit f290b6ef authored by tgupta6's avatar tgupta6
Browse files

added metrics for object classification performance

parent a0c4b8aa
No related branches found
No related tags found
No related merge requests found
def fraction_in_top_k(y, y_pred):
y_list = tf.unpack(y)
y_pred_list = tf.unpack(y_pred)
accuracy = 0.0
for y_, y_pred_ in zip(y_list, y_pred_list):
k = tf.reduce_sum(y_)
pos_label_ids = tf.nn.top_k(y_,k)
pos_label_ids_list = tf.unpack(pos_label_ids)
num_pos_labels_in_top_k = 0.0
for pos_label_id in pos_label_ids_list:
is_present = tf.nn.in_top_k(y_pred_,pos_label_id,k)
num_pos_labels_in_top_k += tf.cast(is_present, tf.float32)
frac_pos_labels_in_top_k = num_pos_labels_in_top_k/tf.maximum(k,1e-5)
accuracy += frac_pos_labels_in_top_k
accuracy /= len(y_list)
return accuracy
def presence_in_top_k(y, y_pred, k):
max_ids = tf.argmax(y,1)
is_present = tf.nn.in_top_k(y_pred, max_ids, k)
is_present = tf.cast(is_present, tf.float32)
return tf.reduce_mean(is_present)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment