Skip to main content

Calculates the mAP value in object detection tasks

Project description

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, x2, y1, y2], 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:

Project details


Download files

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

Source Distribution

mapcalc-0.2.1.tar.gz (5.1 kB view details)

Uploaded Source

File details

Details for the file mapcalc-0.2.1.tar.gz.

File metadata

  • Download URL: mapcalc-0.2.1.tar.gz
  • Upload date:
  • Size: 5.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/54.1.1 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.8.5

File hashes

Hashes for mapcalc-0.2.1.tar.gz
Algorithm Hash digest
SHA256 2447e0d0ea374d57139dd638ef9e580f1c9b14b12bb4a46120dbe5a407e33a86
MD5 584b4af0567f8d8340cf793293cefd9d
BLAKE2b-256 151c64415b4f6ac8116dbd48344261290807a03973e36071f292bd2bd8020635

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page