Detecting objects using mAP metric:
def precision (relevant, retrieved) :
return len( list( set(relevant).intersection(retrieved) ) ) / len(list(retrieved))
def recall (relevant, retrieved) :
return len( list( set(relevant).intersection(retrieved) ) ) / len(list(retrieved))
def average_precision( precision, recall, retrieved, relevant, n ):
sum = 0
for rank in range(1, n+1):
precision_at_cutoff_k = precision ( get(sorted(retrieved), k)
delta_relevant = abs( relevant(get(retrieved, k)) – relevant(get(retrieved, k-1)) )
sum += precision_at_cutoff * delta_relevant
return sum / len(relevant)
def mean_average_precision (precision, recall, retrieved, relevant, n, queries): # map
sum = 0
if len(queries) == 0:
return 0
if len(queries) == 0:
return 0
for query in queries:
sum += average_precision( get_precision_for_query(precision, query),
get_recall_for_query(recall, query),
get_retrieved_for_query(retrieved, query),
get_relevant_for_query(relevant, query),
get_count_for_query(n, query))
return sum / len(queries)
No comments:
Post a Comment