Skip to content

Commit

Permalink
append lvis support
Browse files Browse the repository at this point in the history
  • Loading branch information
MiXaiLL76 committed Jun 19, 2024
1 parent c0dec59 commit 7791619
Show file tree
Hide file tree
Showing 11 changed files with 386 additions and 12 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ Code examples for using the library are available on the [Wiki](https://github.c
- [Eval example](https://nbviewer.org/github/MiXaiLL76/faster_coco_eval/blob/main/examples/eval_example.ipynb)
- [Curve example](https://nbviewer.org/github/MiXaiLL76/faster_coco_eval/blob/main/examples/curve_example.ipynb)
- [CED Keypoint example](https://nbviewer.org/github/MiXaiLL76/faster_coco_eval/blob/main/examples/ced_example.ipynb)
- [LVIS example](https://nbviewer.org/github/MiXaiLL76/faster_coco_eval/blob/main/examples/lvis_example.ipynb)

## Update history

Expand Down
4 changes: 2 additions & 2 deletions csrc/faster_eval_api/coco_eval/cocoeval.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,8 @@ namespace coco_eval
detection_instances[detection_sorted_indices[d]];
detection_ignores[t * num_detections + d] =
detection_ignores[t * num_detections + d] ||
(detection_matches[t * num_detections + d] == 0 &&
(detection.area < area_range[0] || detection.area > area_range[1]));
(detection_matches[t * num_detections + d] == 0 &&
(detection.area < area_range[0] || detection.area > area_range[1] || detection.lvis_mark));
}
}

Expand Down
6 changes: 4 additions & 2 deletions csrc/faster_eval_api/coco_eval/cocoeval.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,15 @@ namespace coco_eval
double score,
double area,
bool is_crowd,
bool ignore)
: id{id}, score{score}, area{area}, is_crowd{is_crowd}, ignore{ignore} {}
bool ignore,
bool lvis_mark)
: id{id}, score{score}, area{area}, is_crowd{is_crowd}, ignore{ignore}, lvis_mark{lvis_mark} {}
uint64_t id;
double score = 0.;
double area = 0.;
bool is_crowd = false;
bool ignore = false;
bool lvis_mark = false;
};

// Stores intermediate results for evaluating detection results for a single
Expand Down
2 changes: 1 addition & 1 deletion csrc/faster_eval_api/faster_eval_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ namespace coco_eval
m.def("get_compiler_version", &get_compiler_version, "get_compiler_version");
m.def("COCOevalAccumulate", &COCOeval::Accumulate, "COCOeval::Accumulate");
m.def("COCOevalEvaluateImages", &COCOeval::EvaluateImages, "COCOeval::EvaluateImages");
pybind11::class_<COCOeval::InstanceAnnotation>(m, "InstanceAnnotation").def(pybind11::init<uint64_t, double, double, bool, bool>());
pybind11::class_<COCOeval::InstanceAnnotation>(m, "InstanceAnnotation").def(pybind11::init<uint64_t, double, double, bool, bool, bool>());
pybind11::class_<COCOeval::ImageEvaluation>(m, "ImageEvaluation").def(pybind11::init<>());

#ifdef VERSION_INFO
Expand Down
159 changes: 159 additions & 0 deletions examples/lvis_example.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"faster_coco_eval.__version__='1.5.6'\n"
]
}
],
"source": [
"import numpy as np\n",
"import logging\n",
"import faster_coco_eval\n",
"from faster_coco_eval import COCO, COCOeval_faster\n",
"\n",
"print(f\"{faster_coco_eval.__version__=}\")\n",
"\n",
"logging.root.setLevel(\"INFO\")\n",
"logging.debug(\"Запись.\")"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"prepared_coco_in_dict = COCO.load_json(\"../tests/lvis_dataset/lvis_val_100.json\")\n",
"prepared_anns = COCO.load_json(\"../tests/lvis_dataset/lvis_results_100.json\")"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"iouType = \"segm\""
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Evaluate annotation type *segm*\n",
"COCOeval_opt.evaluate() finished...\n",
"DONE (t=1.43s).\n",
"Accumulating evaluation results...\n",
"COCOeval_opt.accumulate() finished...\n",
"DONE (t=0.39s).\n",
" Average Precision (AP) @[ IoU=0.50:0.95 | area= all | maxDets=300 catIds=all] = 0.132\n",
" Average Precision (AP) @[ IoU=0.50 | area= all | maxDets=300 catIds=all] = 0.373\n",
" Average Precision (AP) @[ IoU=0.75 | area= all | maxDets=300 catIds=all] = 0.069\n",
" Average Precision (AP) @[ IoU=0.50:0.95 | area= small | maxDets=300 catIds=all] = 0.090\n",
" Average Precision (AP) @[ IoU=0.50:0.95 | area=medium | maxDets=300 catIds=all] = 0.144\n",
" Average Precision (AP) @[ IoU=0.50:0.95 | area= large | maxDets=300 catIds=all] = 0.204\n",
" Average Precision (AP) @[ IoU=0.50:0.95 | area= all | maxDets=300 catIds= r] = 0.000\n",
" Average Precision (AP) @[ IoU=0.50:0.95 | area= all | maxDets=300 catIds= c] = 0.127\n",
" Average Precision (AP) @[ IoU=0.50:0.95 | area= all | maxDets=300 catIds= f] = 0.134\n",
" Average Recall (AR) @[ IoU=0.50:0.95 | area= all | maxDets=300 catIds=all] = 0.164\n",
" Average Recall (AR) @[ IoU=0.50:0.95 | area= small | maxDets=300 catIds=all] = 0.109\n",
" Average Recall (AR) @[ IoU=0.50:0.95 | area=medium | maxDets=300 catIds=all] = 0.176\n",
" Average Recall (AR) @[ IoU=0.50:0.95 | area= large | maxDets=300 catIds=all] = 0.249\n",
" Average Recall (AR) @[ IoU=0.50 | area= all | maxDets=300 catIds=all] = 0.449\n",
" Average Recall (AR) @[ IoU=0.75 | area= all | maxDets=300 catIds=all] = 0.092\n"
]
}
],
"source": [
"cocoGt = COCO(prepared_coco_in_dict)\n",
"cocoDt = cocoGt.loadRes(prepared_anns)\n",
"\n",
"cocoEval = COCOeval_faster(cocoGt, cocoDt, iouType, lvis_style=True, print_function=print)\n",
"cocoEval.params.maxDets = [300]\n",
"cocoEval.run()"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"INFO:lvis.lvis:Loading annotations.\n",
"INFO:lvis.lvis:Creating index.\n",
"INFO:lvis.lvis:Index created.\n",
"INFO:lvis.results:Loading and preparing results.\n",
"INFO:lvis.results:Creating index.\n",
"INFO:lvis.results:Index created.\n",
"INFO:lvis.eval:Running per image evaluation.\n",
"INFO:lvis.eval:Evaluate annotation type *segm*\n",
"INFO:lvis.eval:Accumulating evaluation results.\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
" Average Precision (AP) @[ IoU=0.50:0.95 | area= all | maxDets=300 catIds=all] = 0.132\n",
" Average Precision (AP) @[ IoU=0.50 | area= all | maxDets=300 catIds=all] = 0.373\n",
" Average Precision (AP) @[ IoU=0.75 | area= all | maxDets=300 catIds=all] = 0.069\n",
" Average Precision (AP) @[ IoU=0.50:0.95 | area= s | maxDets=300 catIds=all] = 0.090\n",
" Average Precision (AP) @[ IoU=0.50:0.95 | area= m | maxDets=300 catIds=all] = 0.144\n",
" Average Precision (AP) @[ IoU=0.50:0.95 | area= l | maxDets=300 catIds=all] = 0.204\n",
" Average Precision (AP) @[ IoU=0.50:0.95 | area= all | maxDets=300 catIds= r] = 0.000\n",
" Average Precision (AP) @[ IoU=0.50:0.95 | area= all | maxDets=300 catIds= c] = 0.127\n",
" Average Precision (AP) @[ IoU=0.50:0.95 | area= all | maxDets=300 catIds= f] = 0.134\n",
" Average Recall (AR) @[ IoU=0.50:0.95 | area= all | maxDets=300 catIds=all] = 0.164\n",
" Average Recall (AR) @[ IoU=0.50:0.95 | area= s | maxDets=300 catIds=all] = 0.109\n",
" Average Recall (AR) @[ IoU=0.50:0.95 | area= m | maxDets=300 catIds=all] = 0.176\n",
" Average Recall (AR) @[ IoU=0.50:0.95 | area= l | maxDets=300 catIds=all] = 0.249\n"
]
}
],
"source": [
"from lvis import LVISEval\n",
"\n",
"lvis_eval = LVISEval(\"../tests/lvis_dataset/lvis_val_100.json\", \"../tests/lvis_dataset/lvis_results_100.json\", \"segm\")\n",
"lvis_eval.run()\n",
"lvis_eval.print_results()"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.12"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Loading

0 comments on commit 7791619

Please sign in to comment.