Skip to main content

mapcalc (mean average precision calculator)

Table of contents

Introduction

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.

Explanation

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.

Prerequisites

Packages needed:

  • numpy

Usage

from mapcalc import calculate_map, calculate_map_range

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

    'labels':
        [2, 2, 3, 4]}

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

    'labels':
        [2, 3, 3, 4],

    'scores':
        [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.

Authors:

Release files for mapcalc 0.2.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for mapcalc 0.2.2
File Size Uploaded
mapcalc-0.2.2.tar.gz 9.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for mapcalc 0.2.2
File Interpreter ABI Platform
mapcalc-0.2.2-py3-none-any.whl Python 3 none any Details

Total release size: 18.5 kB

Release files / mapcalc-0.2.2.tar.gz

Download URL mapcalc-0.2.2.tar.gz
Size 9.0 kB
Tags Source
SHA-256 checksum
How to use checksums
3f9462b52ed97e41b6895023f285d209b8edb46c86544989a20b3d0658cc20c2
BLAKE2b-256 checksum
How to use checksums
267ea44dd6d2e06250162dd9f0479cea687833d917e3cb95bd7ecdcb75c61098
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/4.6.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.1 CPython/3.9.4

Release files / mapcalc-0.2.2-py3-none-any.whl

Download URL mapcalc-0.2.2-py3-none-any.whl
Size 9.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
2629cdaadc569cbc21e6c94a40a37b577b4b02c32091e54364fe840b491fbef9
BLAKE2b-256 checksum
How to use checksums
c979449bfb5d999cfe38bb0277390766e228d9bce449e612f926dc95827427b1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/4.6.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.1 CPython/3.9.4

Release history Release notifications | RSS feed

This release

0.2.2 This release

2 release files

0.2.1

1 release file

0.2.0

1 release file

0.1.2

2 release files

0.1.1

1 release file

0.1

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page