Package: globox
Globox — Object Detection ToolboxThis framework can:parse all kinds of object detection datasets (ImageNet, COCO, YOLO, PascalVOC, OpenImage, CVAT, LabelMe, etc.) and show statistics,convert them to other formats (ImageNet, COCO, YOLO, PascalVOC, OpenImage, CVAT, LabelMe, etc.),and evaluate predictions using standard object detection metrics such as $AP_{[.5:.05:.95]}$, $AP_{50}$, $mAP$, $AR_{1}$, $AR_{10}$, $AR_{100}$.This framework can be used both as a library in your own code and as a command line tool. This tool is designed to be simple to use, fast and correct.InstallYou can install the package using pip:pipinstallgloboxUse as a LibraryParse AnnotationsThe library has three main components:BoundingBox: represents a bounding box with a label and an optional confidence scoreAnnotation: represent the bounding boxes annotations for one imageAnnotationSet: represents annotations for a set of images (a database)TheAnnotationSetclass contains static methods to read different dataset formats:# COCOcoco=AnnotationSet.from_coco(file_path="path/to/file.json")# YOLOv5yolo=AnnotationSet.from_yolo_v5(folder="path/to/files/",image_folder="path/to/images/")# Pascal VOCpascal=AnnotationSet.from_pascal_voc(folder="path/to/files/")Annotationoffers file-level granularity for compatible datasets:annotation=Annotation.from_labelme(file_path="path/to/file.xml")For more specific implementations theBoundingBoxclass contains lots of utilities to parse bounding boxes in different formats, like thecreate()method.AnnotationsSetsare set-like objects. They can be combined and annotations can be added:gts=coco|yologts.add(annotation)Inspect DatasetsIterators and efficient lookup byimage_id's are easy to use:ifannotationingts:print("This annotation is present.")if"image_123.jpg"ingts.image_ids:print("Annotation of image 'image_123.jpg' is present.")forboxingts.all_boxes:print(box.label,box.area,box.is_ground_truth)forannotationingts:nb_boxes=len(annotation.boxes)print(f"{annotation.image_id}:{nb_boxes}boxes")Datasets stats can printed to the console:coco_gts.show_stats()Database Stats         
┏━━━━━━━━━━━━━┳━━━━━━━━┳━━━━━━━┓
┃ Label       ┃ Images ┃ Boxes ┃
┡━━━━━━━━━━━━━╇━━━━━━━━╇━━━━━━━┩
│ aeroplane   │     10 │    15 │
│ bicycle     │      7 │    14 │
│ bird        │      4 │     6 │
│ boat        │      7 │    11 │
│ bottle      │      9 │    13 │
│ bus         │      5 │     6 │
│ car         │      6 │    14 │
│ cat         │      4 │     5 │
│ chair       │      9 │    15 │
│ cow         │      6 │    14 │
│ diningtable │      7 │     7 │
│ dog         │      6 │     8 │
│ horse       │      7 │     7 │
│ motorbike   │      3 │     5 │
│ person      │     41 │    91 │
│ pottedplant │      6 │     7 │
│ sheep       │      4 │    10 │
│ sofa        │     10 │    10 │
│ train       │      5 │     6 │
│ tvmonitor   │      8 │     9 │
├─────────────┼────────┼───────┤
│ Total       │    100 │   273 │
└─────────────┴────────┴───────┘Convert and Save to Many FormatsDatasets can be converted to and saved in other formats:# ImageNetgts.save_imagenet(save_dir="pascalVOC_db/")# YOLO Darknetgts.save_yolo_darknet(save_dir="yolo_train/",label_to_id={"cat":0,"dog":1,"racoon":2})# YOLOv5gts.save_yolo_v5(save_dir="yolo_train/",label_to_id={"cat":0,"dog":1,"racoon":2},)# CVATgts.save_cvat(path="train.xml")COCO EvaluationCOCO Evaluation is also supported:evaluator=COCOEvaluator(ground_truths=gts,predictions=dets)ap=evaluator.ap()ar_100=evaluator.ar_100()ap_75=evaluator.ap_75()ap_small=evaluator.ap_small()...All COCO standard metrics can be displayed in a pretty printed table with:evaluator.show_summary()which outputs:COCO Evaluation
┏━━━━━━━━━━━┳━━━━━━━━━━┳━━━━━━━━┳...┳━━━━━━━━┳━━━━━━━━┳━━━━━━━━┓
┃ Label     ┃ AP 50:95 ┃  AP 50 ┃   ┃   AR S ┃   AR M ┃   AR L ┃
┡━━━━━━━━━━━╇━━━━━━━━━━╇━━━━━━━━╇...╇━━━━━━━━╇━━━━━━━━╇━━━━━━━━┩
│ airplane  │    22.7% │  25.2% │   │   nan% │  90.0% │   0.0% │
│ apple     │    46.4% │  57.4% │   │  48.5% │   nan% │   nan% │
│ backpack  │    54.8% │  85.1% │   │ 100.0% │  72.0% │   0.0% │
│ banana    │    73.6% │  96.4% │   │   nan% │ 100.0% │  70.0% │
.           .          .        .   .        .        .        .
.           .          .        .   .        .        .        .
.           .          .        .   .        .        .        .
├───────────┼──────────┼────────┼...┼────────┼────────┼────────┤
│ Total     │    50.3% │  69.7% │   │  65.4% │  60.3% │  55.3% │
└───────────┴──────────┴────────┴...┴────────┴────────┴────────┘The array of results can be saved in CSV format:evaluator.save_csv("where/to/save/results.csv")Custom evaluations can be achieved with:evaluation=evaluator.evaluate(iou_threshold=0.33,max_detections=1_000,size_range=(0.0,10_000))ap=evaluation.ap()cat_ar=evaluation["cat"].arEvaluations are cached by(iou_threshold, max_detections, size_range)keys. This means that repetead queries to the evaluator are fast!Use in Command LineIf you only need to use Globox from the command line like an application, you can install the package throughpipx:pipxinstallgloboxGlobox will then be in your shell path and usable from anywhere.UsageGet a summary of annotations for one dataset:globoxsummary/yolo/folder/--formatyoloConvert annotations from one format to another one:globoxconvertinput/yolo/folder/output_coco_file_path.json--formatyolo--save_fmtcocoEvaluate a set of detections with COCO metrics, display them and save them in a CSV file:globoxevaluategroundtruths/predictions.json--formatyolo--format_detscoco-sresults.csvShow the help message for an exhaustive list of options:globoxsummary-h
globoxconvert-h
globoxevaluate-hRun TestsClone the repo with its test data:gitclonehttps://github.com/laclouis5/globox--recurse-submodules=tests/globox_test_datacdgloboxInstall with Poetry:poetryinstallRun the tests:poetryrunpytestSpeed BanchmarksSpeed benchmark can be executed with:pythontests/benchmark.py-n5The following speed test is performed using Python 3.11 andtimeitwith 5 iterations on a 2021 MacBook Pro 14" (M1 Pro 8 Cores and 16 GB of RAM). The dataset is COCO 2017 Validation which comprises 5k images and 36 781 bounding boxes.TaskCOCOCVATOpenImageLabelMePascalVOCYOLOTXTParsing0.22s0.12s0.44s0.60s0.97s1.45s1.12sSaving0.32s0.17s0.14s1.06s1.08s0.91s0.85sAnnotationSet.show_stats(): 0.02 sEvalaution: 0.05 sTodoBasic data structures and utilitiesParsers (ImageNet, COCO, YOLO, Pascal, OpenImage, CVAT, LabelMe)Parser testsDatabase summary and statsDatabase convertersVisualization optionsCOCO EvaluationTests with a huge load (5k images)CLI interfaceMakeimage_sizeoptional and raise err when required (bbox conversion)Make file saving atomic with a temporary to avoid file corruptionPip package!PascalVOC EvaluationParsers for TFRecord and TensorFlowUI interface?AcknowledgementThis repo is based on the work ofRafael Padilla.ContributionFeel free to contribute, any help you can offer with this project is most welcome.