MCPcopy Index your code
hub / github.com/Cartucho/mAP

github.com/Cartucho/mAP @v0.0

Chat with this repo
repository ↗ · DeepWiki ↗ · release v0.0 ↗ · + Follow
8 symbols 42 edges 6 files 1 documented · 12%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

mAP (mean Average Precision)

New GitHub stars

This code will evaluate the performance of your neural net for object recognition.

In practice, a higher mAP value indicates a better performance of your neural net, given your ground-truth and set of classes.

Table of contents

Explanation

The performance of your neural net will be judged using the mAP criterium defined in the PASCAL VOC 2012 competition. We simply adapted the official Matlab code into Python (in our tests they both give the same results).

First (1.), we calculate the Average Precision (AP), for each of the classes present in the ground-truth. Finally (2.), we calculate the mAP (mean Average Precision) value.

1. Calculate AP

For each class:

First, your neural net predicted objects are sorted by decreasing confidence and are assigned to ground-truth objects. We have "a match" when they share the same label and an IoU >= 0.5 (Intersection over Union greater than 50%). This "match" is considered a true positive if that ground-truth object has not been already used (to avoid multiple detections of the same object).

Using this criterium, we calculate the precision/recall curve. E.g:

Then we compute a version of the measured precision/recall curve with precision monotonically decreasing (shown in light red), by setting the precision for recall r to the maximum precision obtained for any recall r' > r.

Finally, we compute the AP as the area under this curve (shown in light blue) by numerical integration. No approximation is involved since the curve is piecewise constant.

2. Calculate mAP

We calculate the mean of all the AP's, resulting in an mAP value from 0 to 100%. E.g:

Prerequisites

You need to install: - Python

Optional: - plot the results by installing Matplotlib - Linux, macOS and Windows: 1. python -mpip install -U pip
2. python -mpip install -U matplotlib - show animation by installing OpenCV: 1. python -mpip install -U pip 2. python -mpip install -U opencv-python

Quick-start

To start using the mAP you need to clone the repo:

git clone https://github.com/Cartucho/mAP

Running the code

Step by step:

  1. Create the ground-truth files
  2. Move the ground-truth files into the folder ground-truth/
  3. Create the predicted objects files
  4. Move the predictions files into the folder predicted/
  5. Run the code: python main.py

Optional (if you want to see the animation):

  1. Insert the images into the folder images/

PASCAL VOC, Darkflow and YOLO users

In the extra folder you can find additional scripts to convert PASCAL VOC, darkflow and Yolo files into the required format.

Create the ground-truth files

  • Create a separate ground-truth text file for each image.
  • Use matching names (e.g. image: "image_1.jpg", ground-truth: "image_1.txt"; "image_2.jpg", "image_2.txt"...).
  • In these files, each line should be in the following format: <class_name> <left> <top> <right> <bottom> , where <class_name> must have no whitespaces between words.
  • E.g. "image_1.txt": tvmonitor 2 10 173 238 book 439 157 556 241 book 437 246 518 351 pottedplant 272 190 316 259

Create the predicted objects files

  • Create a separate predicted objects text file for each image.
  • Use matching names (e.g. image: "image_1.jpg", predicted: "image_1.txt"; "image_2.jpg", "image_2.txt"...).
  • In these files, each line should be in the following format: <class_name> <confidence> <left> <top> <right> <bottom> , where <class_name> must have no whitespaces between words.
  • E.g. "image_1.txt": tvmonitor 0.471781 0 13 174 244 cup 0.414941 274 226 301 265 book 0.460851 429 219 528 247 chair 0.292345 0 199 88 436 book 0.269833 433 260 506 336

Authors:

  • João Cartucho - Please give me your feedback: to.cartucho@gmail.com

    Feel free to contribute

    GitHub contributors

Core symbols most depended-on inside this repo

error
called by 9
main.py
draw_text_in_image
called by 5
main.py
draw_plot_func
called by 3
main.py
file_lines_to_list
called by 2
main.py
find_class
called by 2
extra/find_class.py
is_float_between_0_and_1
called by 1
main.py
voc_ap
called by 1
main.py
file_lines_to_list
called by 1
extra/remove_delimiter_char.py

Shape

Function 8

Languages

Python100%

Modules by API surface

main.py6 symbols
extra/remove_delimiter_char.py1 symbols
extra/find_class.py1 symbols

For agents

$ claude mcp add mAP \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact