Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow to return AP by class and mAP score #22

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions mean_average_precision/detection_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,3 +157,17 @@ def plot(self, interpolated=True):

plt.suptitle("Mean average precision : {:0.2f}".format(sum(mean_average_precision)/len(mean_average_precision)))
fig.tight_layout()

def compute_map(self, interpolated=True):
"""
Compute average precision per class and the mAP score.
:param interpolated: will compute the interpolated curve
:return: tuple: (dict of class -> AP, mAP score)
"""
ap_by_class = {}
for class_idx in range(self.n_class):
precisions, recalls = self.compute_precision_recall_(class_idx, interpolated=interpolated)
average_precision = self.compute_ap(precisions, recalls)
ap_by_class[class_idx] = average_precision
mAP = sum(ap_by_class.values()) / len(ap_by_class)
return ap_by_class, mAP