Code Monkey home page Code Monkey logo

mean-average-precision-for-boxes's Introduction

Function to calculate mean average precision (mAP) for set of boxes. Useful for object detection pipelines.

Requirements

python 3.*, numpy, pandas

Installation

pip install map-boxes

Usage example:

You can provide paths to CSV-files:

from map_boxes import mean_average_precision_for_boxes

annotations_file = 'example/annotations.csv'
detections_file = 'example/detections.csv'
mean_ap, average_precisions = mean_average_precision_for_boxes(annotations_file, detections_file)

or you can pass directly numpy arrays of shapes (N, 6) and (M, 7). Be careful about order of variables in arrays!:

from map_boxes import mean_average_precision_for_boxes
import pandas as pd

ann = pd.read_csv('example/annotations.csv')
det = pd.read_csv('example/detections.csv')
ann = ann[['ImageID', 'LabelName', 'XMin', 'XMax', 'YMin', 'YMax']].values
det = det[['ImageID', 'LabelName', 'Conf', 'XMin', 'XMax', 'YMin', 'YMax']].values
mean_ap, average_precisions = mean_average_precision_for_boxes(ann, det)

Input files format

Boxes must be in normalized form e.g. coordinates must be in range: [0, 1]. To normalize pixel values you need to recalculate them as: x_norm = x / width, y_norm = y / height

  • Annotation CSV-file:
ImageID,LabelName,XMin,XMax,YMin,YMax
i0.jpg,Shellfish,0.0875,0.8171875,0.35625,0.8958333
i0.jpg,Seafood,0.0875,0.8171875,0.35625,0.8958333
i1.jpg,Tin can,0.1296875,0.3375,0.31875,0.68958336
i1.jpg,Drink,0.4234375,0.546875,0.58958334,0.92083335
i1.jpg,Drink,0.5375,0.7375,0.16666667,0.575
...
  • Detection CSV-file:
ImageID,LabelName,Conf,XMin,XMax,YMin,YMax
i0.jpg,Turtle,0.41471,0.1382,0.7440,0.3585,0.8951
i0.jpg,Reptile,0.32093,0.1391,0.7439,0.3582,0.8944
i0.jpg,Seahorse,0.11860,0.1393,0.7434,0.3589,0.8943
i0.jpg,Caterpillar,0.11275,0.1390,0.7438,0.3588,0.8948
i1.jpg,Personal care,0.42326,0.2624,0.5473,0.1112,0.7274
i1.jpg,Personal care,0.31120,0.1318,0.3381,0.3149,0.6863
i1.jpg,Personal care,0.34866,0.4277,0.5446,0.5861,0.9211
i1.jpg,Blender,0.10578,0.7678,0.9476,0.2674,0.5847
...

mean-average-precision-for-boxes's People

Contributors

devnjw avatar idmippm avatar jeonchangmin avatar zfturbo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

mean-average-precision-for-boxes's Issues

ValueError in average_precisions.items() unpack

`---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
in
----> 1 mean_ap, average_precisions = mean_average_precision_for_boxes('/kaggle/working/ground_truths.csv','/kaggle/working/predictions.csv')

in mean_average_precision_for_boxes(ann, pred, iou_threshold, exclude_not_in_annotations, verbose)
115 present_classes = 0
116 precision = 0
--> 117 for label, (average_precision, num_annotations, _, _) in average_precisions.items():
118 if num_annotations > 0:
119 present_classes += 1

ValueError: not enough values to unpack (expected 4, got 2)`

Sanity check is not working

Hi,

I have just run a simple sanity check on your code in command line and I got the following:

from map_boxes import mean_average_precision_for_boxes
/Users/nicolas/.pyxbld/temp.macosx-10.15-x86_64-3.7/pyrex/map_boxes/compute_overlap.c:598:10: fatal error: 'numpy/arrayobject.h' file not found
#include "numpy/arrayobject.h"
         ^~~~~~~~~~~~~~~~~~~~~
1 error generated.
Couldn't import fast version of function compute_overlap, will use slow one. Check cython intallation
ann = [[str(1), 'bla', 0.0, 0.0, 0.1, 0.1]]
det = [[str(1), 'bla', 0.9, 0.0, 0.0, 0.1, 0.1]]
mean_ap, average_precisions = mean_average_precision_for_boxes(ann, det)
Number of files in annotations: 1
Number of files in predictions: 1
Unique classes: 1
Detections length: 1
Annotations length: 1
bla                            | 0.000000 |       1
mAP: 0.000000

I assume the AP should be 1 in this case. Is it possible that there is a bug in your code, or am I doing something wrong with the input format?

Looking forward to your reply!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.