Skip to main content

Calculates the mAP value in object detection tasks

Project description

mapcalc (mean average precision calculator)

Table of contents


For object detection in images the mAP (mean average precision) metric is often used to see how good the implementation is. As no packages that make the calculation for you were available at this time, I adapted the implementation from João Cartucho, which uses files which hold the detection results. It now can be installed as a package with pip and simply gives you the mAP value at a certain iou threshold.


The performance of your neural net will be judged using the mAP criterium defined in the PASCAL VOC 2012 competition. The code from official Matlab code was adapted into Python.


Packages needed:

  • numpy


from mapcalc import calculate_map, calculate_map_range

ground_truth = {
        [[60., 80., 66., 92.],
         [59., 94., 68., 97.],
         [70., 87., 81., 94.],
         [8., 34., 10., 36.]],

        [2, 2, 3, 4]}

result_dict = {
        [[57., 87., 66., 94.],
         [58., 94., 68., 95.],
         [70., 88., 81., 93.],
         [10., 37., 17., 40.]],

        [2, 3, 3, 4],

        [0.99056727, 0.98965424, 0.93990153, 0.9157755]}

# calculates the mAP for an IOU threshold of 0.5
print(calculate_map(ground_truth, result_dict, 0.5))

# calculates the mAP average for the IOU thresholds 0.05, 0.1, 0.15, ..., 0.90, 0.95.
print(calculate_map_range(ground_truth, result_dict, 0.05, 0.95, 0.05))

The methods expect two dicts:

  • ground_truth_dict with {boxes:, labels:}
  • result_dict with {boxes:, labels:, scores:}

Boxes: A list of [x1, y1, x2, y2] (or [u, v, u + w, v + h], where (u, v) is the bounding box corner and (w, h) is the shape of the bounding box, so width and height), each representing a box that was detected.

Labels: List of classes (int) the algorithm assigned to the box

Scores: List of scores (float) the algorithm generated. If not specified, scores will be set to 1.


Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for mapcalc, version 0.2.2
Filename, size File type Python version Upload date Hashes
Filename, size mapcalc-0.2.2-py3-none-any.whl (9.5 kB) File type Wheel Python version py3 Upload date Hashes View
Filename, size mapcalc-0.2.2.tar.gz (9.0 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor NVIDIA NVIDIA PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page