faster-coco-eval 1.6.4__tar.gz → 1.6.6__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {faster_coco_eval-1.6.4/faster_coco_eval.egg-info → faster_coco_eval-1.6.6}/PKG-INFO +22 -2
- {faster_coco_eval-1.6.4 → faster_coco_eval-1.6.6}/README.md +9 -0
- {faster_coco_eval-1.6.4 → faster_coco_eval-1.6.6}/csrc/faster_eval_api/coco_eval/cocoeval.cpp +29 -1
- {faster_coco_eval-1.6.4 → faster_coco_eval-1.6.6}/csrc/faster_eval_api/coco_eval/cocoeval.h +7 -1
- {faster_coco_eval-1.6.4 → faster_coco_eval-1.6.6}/csrc/faster_eval_api/faster_eval_api.cpp +41 -3
- {faster_coco_eval-1.6.4 → faster_coco_eval-1.6.6}/faster_coco_eval/core/coco.py +112 -25
- {faster_coco_eval-1.6.4 → faster_coco_eval-1.6.6}/faster_coco_eval/core/cocoeval.py +92 -38
- {faster_coco_eval-1.6.4 → faster_coco_eval-1.6.6}/faster_coco_eval/core/faster_eval_api.py +47 -31
- faster_coco_eval-1.6.6/faster_coco_eval/utils/__init__.py +0 -0
- faster_coco_eval-1.6.6/faster_coco_eval/utils/pytorch/__init__.py +4 -0
- faster_coco_eval-1.6.6/faster_coco_eval/utils/pytorch/coco_dataset.py +43 -0
- faster_coco_eval-1.6.6/faster_coco_eval/utils/pytorch/coco_eval.py +263 -0
- {faster_coco_eval-1.6.4 → faster_coco_eval-1.6.6}/faster_coco_eval/version.py +1 -1
- {faster_coco_eval-1.6.4 → faster_coco_eval-1.6.6/faster_coco_eval.egg-info}/PKG-INFO +22 -2
- {faster_coco_eval-1.6.4 → faster_coco_eval-1.6.6}/faster_coco_eval.egg-info/SOURCES.txt +7 -1
- {faster_coco_eval-1.6.4 → faster_coco_eval-1.6.6}/pyproject.toml +1 -0
- {faster_coco_eval-1.6.4 → faster_coco_eval-1.6.6}/tests/test_basic.py +7 -7
- {faster_coco_eval-1.6.4 → faster_coco_eval-1.6.6}/tests/test_boundary.py +3 -3
- faster_coco_eval-1.6.6/tests/test_crowdpose.py +53 -0
- {faster_coco_eval-1.6.4 → faster_coco_eval-1.6.6}/tests/test_torchmetrics.py +0 -2
- faster_coco_eval-1.6.6/tests/test_world_evalutor.py +82 -0
- {faster_coco_eval-1.6.4 → faster_coco_eval-1.6.6}/LICENSE +0 -0
- {faster_coco_eval-1.6.4 → faster_coco_eval-1.6.6}/MANIFEST.in +0 -0
- {faster_coco_eval-1.6.4 → faster_coco_eval-1.6.6}/csrc/mask_api/mask_api.cpp +0 -0
- {faster_coco_eval-1.6.4 → faster_coco_eval-1.6.6}/csrc/mask_api/src/mask.cpp +0 -0
- {faster_coco_eval-1.6.4 → faster_coco_eval-1.6.6}/csrc/mask_api/src/mask.h +0 -0
- {faster_coco_eval-1.6.4 → faster_coco_eval-1.6.6}/csrc/mask_api/src/rle.cpp +0 -0
- {faster_coco_eval-1.6.4 → faster_coco_eval-1.6.6}/faster_coco_eval/__init__.py +0 -0
- {faster_coco_eval-1.6.4 → faster_coco_eval-1.6.6}/faster_coco_eval/core/__init__.py +0 -0
- {faster_coco_eval-1.6.4 → faster_coco_eval-1.6.6}/faster_coco_eval/core/mask.py +0 -0
- {faster_coco_eval-1.6.4 → faster_coco_eval-1.6.6}/faster_coco_eval/extra/__init__.py +0 -0
- {faster_coco_eval-1.6.4 → faster_coco_eval-1.6.6}/faster_coco_eval/extra/curves.py +0 -0
- {faster_coco_eval-1.6.4 → faster_coco_eval-1.6.6}/faster_coco_eval/extra/display.py +0 -0
- {faster_coco_eval-1.6.4 → faster_coco_eval-1.6.6}/faster_coco_eval/extra/draw.py +0 -0
- {faster_coco_eval-1.6.4 → faster_coco_eval-1.6.6}/faster_coco_eval/extra/extra.py +0 -0
- {faster_coco_eval-1.6.4 → faster_coco_eval-1.6.6}/faster_coco_eval/extra/utils.py +0 -0
- {faster_coco_eval-1.6.4 → faster_coco_eval-1.6.6}/faster_coco_eval.egg-info/dependency_links.txt +0 -0
- {faster_coco_eval-1.6.4 → faster_coco_eval-1.6.6}/faster_coco_eval.egg-info/requires.txt +0 -0
- {faster_coco_eval-1.6.4 → faster_coco_eval-1.6.6}/faster_coco_eval.egg-info/top_level.txt +0 -0
- {faster_coco_eval-1.6.4 → faster_coco_eval-1.6.6}/requirements/extra.txt +0 -0
- {faster_coco_eval-1.6.4 → faster_coco_eval-1.6.6}/requirements/runtime.txt +0 -0
- {faster_coco_eval-1.6.4 → faster_coco_eval-1.6.6}/requirements/tests.txt +0 -0
- {faster_coco_eval-1.6.4 → faster_coco_eval-1.6.6}/setup.cfg +0 -0
- {faster_coco_eval-1.6.4 → faster_coco_eval-1.6.6}/setup.py +0 -0
- {faster_coco_eval-1.6.4 → faster_coco_eval-1.6.6}/tests/test_coco_metric.py +0 -0
- {faster_coco_eval-1.6.4 → faster_coco_eval-1.6.6}/tests/test_init_pycocotools.py +0 -0
- {faster_coco_eval-1.6.4 → faster_coco_eval-1.6.6}/tests/test_keypoints.py +0 -0
- {faster_coco_eval-1.6.4 → faster_coco_eval-1.6.6}/tests/test_lvis_metric.py +0 -0
- {faster_coco_eval-1.6.4 → faster_coco_eval-1.6.6}/tests/test_mask_api.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
Metadata-Version: 2.
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
2
|
Name: faster-coco-eval
|
|
3
|
-
Version: 1.6.
|
|
3
|
+
Version: 1.6.6
|
|
4
4
|
Summary: Faster interpretation of the original COCOEval
|
|
5
5
|
Home-page: https://github.com/MiXaiLL76/faster_coco_eval
|
|
6
6
|
Author: MiXaiLL76
|
|
@@ -40,12 +40,26 @@ Requires-Dist: pycocotools; extra == "tests"
|
|
|
40
40
|
Requires-Dist: pytest; extra == "tests"
|
|
41
41
|
Requires-Dist: pytest-cov; extra == "tests"
|
|
42
42
|
Requires-Dist: parameterized; extra == "tests"
|
|
43
|
+
Dynamic: author
|
|
44
|
+
Dynamic: author-email
|
|
45
|
+
Dynamic: classifier
|
|
46
|
+
Dynamic: description
|
|
47
|
+
Dynamic: description-content-type
|
|
48
|
+
Dynamic: home-page
|
|
49
|
+
Dynamic: license-file
|
|
50
|
+
Dynamic: provides-extra
|
|
51
|
+
Dynamic: requires-dist
|
|
52
|
+
Dynamic: requires-python
|
|
53
|
+
Dynamic: summary
|
|
43
54
|
|
|
44
55
|
# Faster-COCO-Eval
|
|
45
56
|
|
|
46
57
|
[](https://pypi.org/project/faster-coco-eval)
|
|
47
58
|
[](https://pypi.org/project/faster-coco-eval/)
|
|
48
59
|
|
|
60
|
+
[](https://anaconda.org/conda-forge/faster-coco-eval)
|
|
61
|
+
[](https://anaconda.org/conda-forge/faster-coco-eval)
|
|
62
|
+
|
|
49
63
|
[](https://github.com/MiXaiLL76/faster_coco_eval/wiki)
|
|
50
64
|
[](https://github.com/MiXaiLL76/faster_coco_eval/blob/main/LICENSE)
|
|
51
65
|
|
|
@@ -74,6 +88,12 @@ pip install faster-coco-eval
|
|
|
74
88
|
pip install faster-coco-eval[extra]
|
|
75
89
|
```
|
|
76
90
|
|
|
91
|
+
### Conda install
|
|
92
|
+
|
|
93
|
+
```bash
|
|
94
|
+
conda install conda-forge::faster-coco-eval
|
|
95
|
+
```
|
|
96
|
+
|
|
77
97
|
### Basic usage
|
|
78
98
|
|
|
79
99
|
```py
|
|
@@ -3,6 +3,9 @@
|
|
|
3
3
|
[](https://pypi.org/project/faster-coco-eval)
|
|
4
4
|
[](https://pypi.org/project/faster-coco-eval/)
|
|
5
5
|
|
|
6
|
+
[](https://anaconda.org/conda-forge/faster-coco-eval)
|
|
7
|
+
[](https://anaconda.org/conda-forge/faster-coco-eval)
|
|
8
|
+
|
|
6
9
|
[](https://github.com/MiXaiLL76/faster_coco_eval/wiki)
|
|
7
10
|
[](https://github.com/MiXaiLL76/faster_coco_eval/blob/main/LICENSE)
|
|
8
11
|
|
|
@@ -31,6 +34,12 @@ pip install faster-coco-eval
|
|
|
31
34
|
pip install faster-coco-eval[extra]
|
|
32
35
|
```
|
|
33
36
|
|
|
37
|
+
### Conda install
|
|
38
|
+
|
|
39
|
+
```bash
|
|
40
|
+
conda install conda-forge::faster-coco-eval
|
|
41
|
+
```
|
|
42
|
+
|
|
34
43
|
### Basic usage
|
|
35
44
|
|
|
36
45
|
```py
|
{faster_coco_eval-1.6.4 → faster_coco_eval-1.6.6}/csrc/faster_eval_api/coco_eval/cocoeval.cpp
RENAMED
|
@@ -629,6 +629,34 @@ namespace coco_eval
|
|
|
629
629
|
{
|
|
630
630
|
this->data[{img_id, cat_id}].emplace_back(ann);
|
|
631
631
|
}
|
|
632
|
+
|
|
633
|
+
void Dataset::clean(){
|
|
634
|
+
this->data.clear();
|
|
635
|
+
}
|
|
636
|
+
|
|
637
|
+
py::tuple Dataset::make_tuple() const {
|
|
638
|
+
std::vector<std::pair<int64_t, int64_t>> keys;
|
|
639
|
+
std::vector<std::vector<py::dict>> values;
|
|
640
|
+
|
|
641
|
+
for (const auto& [key, value] : this->data) {
|
|
642
|
+
keys.push_back(key);
|
|
643
|
+
values.push_back(value);
|
|
644
|
+
}
|
|
645
|
+
return py::make_tuple(keys, values);
|
|
646
|
+
}
|
|
647
|
+
|
|
648
|
+
void Dataset::load_tuple(py::tuple data){
|
|
649
|
+
if (data.size() != 2)
|
|
650
|
+
throw std::runtime_error("Invalid state!");
|
|
651
|
+
|
|
652
|
+
std::vector<std::pair<int64_t, int64_t>> keys = data[0].cast<std::vector<std::pair<int64_t, int64_t>>>();
|
|
653
|
+
std::vector<std::vector<py::dict>> values = data[1].cast<std::vector<std::vector<py::dict>>>();
|
|
654
|
+
|
|
655
|
+
for (size_t i = 0; i < keys.size(); i++) {
|
|
656
|
+
this->data[keys[i]] = values[i];
|
|
657
|
+
}
|
|
658
|
+
}
|
|
659
|
+
|
|
632
660
|
std::vector<py::dict> Dataset::get(const int64_t &img_id, const int64_t &cat_id)
|
|
633
661
|
{
|
|
634
662
|
std::pair<int64_t, int64_t> key(img_id, cat_id);
|
|
@@ -864,4 +892,4 @@ namespace coco_eval
|
|
|
864
892
|
|
|
865
893
|
} // namespace COCOeval
|
|
866
894
|
|
|
867
|
-
} // namespace coco_eval
|
|
895
|
+
} // namespace coco_eval
|
|
@@ -97,6 +97,12 @@ namespace coco_eval
|
|
|
97
97
|
// this->data.max_load_factor(0.25); // DECREASING MAX_LOAD_FACTOR
|
|
98
98
|
}
|
|
99
99
|
void append(int64_t img_id, int64_t cat_id, py::dict ann);
|
|
100
|
+
void clean();
|
|
101
|
+
|
|
102
|
+
// pickle
|
|
103
|
+
py::tuple make_tuple() const ;
|
|
104
|
+
void load_tuple(py::tuple data);
|
|
105
|
+
|
|
100
106
|
std::vector<py::dict> get(const int64_t &img_id, const int64_t &cat_id);
|
|
101
107
|
std::vector<InstanceAnnotation> get_cpp_annotations(
|
|
102
108
|
const int64_t &img_id, const int64_t &cat_id);
|
|
@@ -157,4 +163,4 @@ namespace coco_eval
|
|
|
157
163
|
long double calc_auc(const std::vector<long double> &recall_list, const std::vector<long double> &precision_list);
|
|
158
164
|
long double _summarize(const int &ap, const double &iouThr, const std::string &areaRng, const int &maxDet, const std::vector<int> &catIds, const py::object ¶ms, const std::vector<size_t> &counts, const py::object &nums_array);
|
|
159
165
|
} // namespace COCOeval
|
|
160
|
-
} // namespace coco_eval
|
|
166
|
+
} // namespace coco_eval
|
|
@@ -57,14 +57,52 @@ namespace coco_eval
|
|
|
57
57
|
pybind11::class_<COCOeval::InstanceAnnotation>(m, "InstanceAnnotation")
|
|
58
58
|
.def(pybind11::init<uint64_t, double, double, bool, bool, bool>());
|
|
59
59
|
|
|
60
|
-
pybind11::class_<COCOeval::ImageEvaluation>(m, "ImageEvaluation").def(pybind11::init<>())
|
|
60
|
+
pybind11::class_<COCOeval::ImageEvaluation>(m, "ImageEvaluation").def(pybind11::init<>())
|
|
61
|
+
.def(py::pickle(
|
|
62
|
+
[](const COCOeval::ImageEvaluation &p) {
|
|
63
|
+
|
|
64
|
+
std::vector<std::tuple<uint64_t, uint64_t, double>> matched_annotations;
|
|
65
|
+
for (size_t i = 0; i < p.matched_annotations.size(); i++) {
|
|
66
|
+
matched_annotations.push_back(std::make_tuple(p.matched_annotations[i].dt_id, p.matched_annotations[i].gt_id, p.matched_annotations[i].iou));
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
return py::make_tuple(p.detection_matches, p.ground_truth_matches, p.detection_scores, p.ground_truth_ignores, p.detection_ignores, matched_annotations);
|
|
70
|
+
},
|
|
71
|
+
[](py::tuple t) { // __setstate__
|
|
72
|
+
if (t.size() != 6)
|
|
73
|
+
throw std::runtime_error("Invalid state!");
|
|
74
|
+
|
|
75
|
+
COCOeval::ImageEvaluation p;
|
|
76
|
+
p.detection_matches = t[0].cast<std::vector<int64_t>>();
|
|
77
|
+
p.ground_truth_matches = t[1].cast<std::vector<int64_t>>();
|
|
78
|
+
p.detection_scores = t[2].cast<std::vector<double>>();
|
|
79
|
+
p.ground_truth_ignores = t[3].cast<std::vector<bool>>();
|
|
80
|
+
p.detection_ignores = t[4].cast<std::vector<bool>>();
|
|
81
|
+
std::vector<std::tuple<uint64_t, uint64_t, double>> matched_annotations = t[5].cast<std::vector<std::tuple<uint64_t, uint64_t, double>>>();
|
|
82
|
+
for (size_t i = 0; i < matched_annotations.size(); i++) {
|
|
83
|
+
p.matched_annotations.emplace_back(std::get<0>(matched_annotations[i]), std::get<1>(matched_annotations[i]), std::get<2>(matched_annotations[i]));
|
|
84
|
+
}
|
|
85
|
+
return p;
|
|
86
|
+
}
|
|
87
|
+
));
|
|
61
88
|
|
|
62
89
|
pybind11::class_<COCOeval::Dataset>(m, "Dataset").def(pybind11::init<>())
|
|
63
90
|
.def("append", &COCOeval::Dataset::append)
|
|
91
|
+
.def("clean", &COCOeval::Dataset::clean)
|
|
64
92
|
.def("get", &COCOeval::Dataset::get)
|
|
65
93
|
.def("get_instances", &COCOeval::Dataset::get_instances)
|
|
66
94
|
.def("get_cpp_annotations", &COCOeval::Dataset::get_cpp_annotations)
|
|
67
|
-
.def("get_cpp_instances", &COCOeval::Dataset::get_cpp_instances)
|
|
95
|
+
.def("get_cpp_instances", &COCOeval::Dataset::get_cpp_instances)
|
|
96
|
+
.def(py::pickle(
|
|
97
|
+
[](const COCOeval::Dataset &p) {
|
|
98
|
+
return p.make_tuple();
|
|
99
|
+
},
|
|
100
|
+
[](py::tuple t) { // __setstate__
|
|
101
|
+
COCOeval::Dataset p;
|
|
102
|
+
p.load_tuple(t);
|
|
103
|
+
return p;
|
|
104
|
+
}
|
|
105
|
+
));
|
|
68
106
|
|
|
69
107
|
#ifdef VERSION_INFO
|
|
70
108
|
m.attr("__version__") = MACRO_STRINGIFY(VERSION_INFO);
|
|
@@ -73,4 +111,4 @@ namespace coco_eval
|
|
|
73
111
|
#endif
|
|
74
112
|
}
|
|
75
113
|
|
|
76
|
-
} // namespace coco_eval
|
|
114
|
+
} // namespace coco_eval
|
|
@@ -9,7 +9,7 @@ import pathlib
|
|
|
9
9
|
import time
|
|
10
10
|
import warnings
|
|
11
11
|
from collections import defaultdict
|
|
12
|
-
from typing import List, Optional, Union
|
|
12
|
+
from typing import Callable, List, Optional, Union
|
|
13
13
|
|
|
14
14
|
import numpy as np
|
|
15
15
|
|
|
@@ -28,6 +28,7 @@ class COCO:
|
|
|
28
28
|
self,
|
|
29
29
|
annotation_file: Optional[Union[str, dict, os.PathLike, pathlib.PosixPath]] = None,
|
|
30
30
|
use_deepcopy: bool = False,
|
|
31
|
+
print_function: Callable = logger.debug,
|
|
31
32
|
):
|
|
32
33
|
"""Constructor of Microsoft COCO helper class.
|
|
33
34
|
|
|
@@ -45,21 +46,17 @@ class COCO:
|
|
|
45
46
|
{},
|
|
46
47
|
)
|
|
47
48
|
self.imgToAnns, self.catToImgs = defaultdict(list), defaultdict(list)
|
|
48
|
-
self.print_function =
|
|
49
|
+
self.print_function = print_function
|
|
49
50
|
self.use_deepcopy = use_deepcopy
|
|
51
|
+
self.annotation_file = annotation_file
|
|
50
52
|
|
|
51
53
|
if annotation_file is not None:
|
|
52
54
|
self._print_function("loading annotations into memory...")
|
|
53
55
|
tic = time.time()
|
|
54
|
-
if type(annotation_file) in [str, os.PathLike, pathlib.PosixPath]:
|
|
55
|
-
self.dataset =
|
|
56
|
-
elif type(annotation_file) is dict:
|
|
57
|
-
if self.use_deepcopy:
|
|
58
|
-
self.dataset = copy.deepcopy(annotation_file)
|
|
59
|
-
else:
|
|
60
|
-
self.dataset = annotation_file.copy()
|
|
56
|
+
if type(annotation_file) in [str, os.PathLike, pathlib.PosixPath, dict, list]:
|
|
57
|
+
self.dataset = COCO.load_json(annotation_file, self.use_deepcopy)
|
|
61
58
|
else:
|
|
62
|
-
|
|
59
|
+
raise TypeError(f"type {type(annotation_file)} is not supported")
|
|
63
60
|
|
|
64
61
|
assert type(self.dataset) is dict, f"annotation file format {type(self.dataset)} not supported"
|
|
65
62
|
self.print_function(f"Done (t={time.time() - tic:0.2f}s)")
|
|
@@ -290,29 +287,36 @@ class COCO:
|
|
|
290
287
|
return [self.imgs[ids]]
|
|
291
288
|
|
|
292
289
|
@staticmethod
|
|
293
|
-
def load_json(
|
|
290
|
+
def load_json(
|
|
291
|
+
json_file: Union[str, os.PathLike, pathlib.PosixPath, dict, list], use_deepcopy: Optional[bool] = False
|
|
292
|
+
) -> dict:
|
|
294
293
|
"""Load a json file.
|
|
295
294
|
|
|
296
295
|
Args:
|
|
297
|
-
json_file (str or os.PathLike): Path to the json file
|
|
296
|
+
json_file (str or os.PathLike or dict or list): Path to the json file or data dict
|
|
298
297
|
|
|
299
298
|
Return:
|
|
300
299
|
data (dict): Loaded json data
|
|
301
300
|
"""
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
301
|
+
if type(json_file) in [str, os.PathLike]:
|
|
302
|
+
with open(json_file) as io:
|
|
303
|
+
_data = json.load(io)
|
|
304
|
+
else:
|
|
305
|
+
if use_deepcopy:
|
|
306
|
+
return copy.deepcopy(json_file)
|
|
307
|
+
else:
|
|
308
|
+
return json_file.copy()
|
|
305
309
|
return _data
|
|
306
310
|
|
|
307
311
|
def loadRes(
|
|
308
312
|
self,
|
|
309
|
-
resFile: Union[str, os.PathLike, np.ndarray],
|
|
313
|
+
resFile: Union[str, os.PathLike, pathlib.PosixPath, dict, list, np.ndarray],
|
|
310
314
|
min_score: float = 0.0,
|
|
311
315
|
) -> "COCO":
|
|
312
316
|
"""Load result file and return a result api object.
|
|
313
317
|
|
|
314
318
|
Args:
|
|
315
|
-
resFile (str) : file name of result file
|
|
319
|
+
resFile (str or os.PathLike or dict or list) : file name of result file
|
|
316
320
|
min_score (float) : minimum score to consider a result
|
|
317
321
|
|
|
318
322
|
Return:
|
|
@@ -324,15 +328,12 @@ class COCO:
|
|
|
324
328
|
|
|
325
329
|
self.print_function("Loading and preparing results...")
|
|
326
330
|
tic = time.time()
|
|
327
|
-
if type(resFile) in [str, os.PathLike]:
|
|
328
|
-
anns =
|
|
331
|
+
if type(resFile) in [str, os.PathLike, pathlib.PosixPath, dict, list]:
|
|
332
|
+
anns = COCO.load_json(resFile, getattr(self, "use_deepcopy", False))
|
|
329
333
|
elif type(resFile) is np.ndarray:
|
|
330
334
|
anns = self.loadNumpyAnnotations(resFile)
|
|
331
335
|
else:
|
|
332
|
-
|
|
333
|
-
anns = copy.deepcopy(resFile)
|
|
334
|
-
else:
|
|
335
|
-
anns = resFile.copy()
|
|
336
|
+
raise TypeError(f"type {type(resFile)} is not supported")
|
|
336
337
|
|
|
337
338
|
assert type(anns) is list, "results in not an array of objects"
|
|
338
339
|
|
|
@@ -383,8 +384,94 @@ class COCO:
|
|
|
383
384
|
res.createIndex()
|
|
384
385
|
return res
|
|
385
386
|
|
|
386
|
-
def showAnns(self, anns, draw_bbox=False):
|
|
387
|
-
|
|
387
|
+
def showAnns(self, anns: List[dict], draw_bbox: Optional[bool] = False):
|
|
388
|
+
"""Display the specified annotations.
|
|
389
|
+
|
|
390
|
+
Args:
|
|
391
|
+
anns (List[dict]) : annotations to display
|
|
392
|
+
draw_bbox (bool) : display bbox
|
|
393
|
+
"""
|
|
394
|
+
|
|
395
|
+
if len(anns) == 0:
|
|
396
|
+
return 0
|
|
397
|
+
|
|
398
|
+
if "segmentation" in anns[0] or "keypoints" in anns[0]:
|
|
399
|
+
datasetType = "instances"
|
|
400
|
+
elif "caption" in anns[0]:
|
|
401
|
+
datasetType = "captions"
|
|
402
|
+
else:
|
|
403
|
+
raise Exception("datasetType not supported")
|
|
404
|
+
|
|
405
|
+
if datasetType == "instances":
|
|
406
|
+
import matplotlib.pyplot as plt
|
|
407
|
+
from matplotlib.collections import PatchCollection
|
|
408
|
+
from matplotlib.patches import Polygon
|
|
409
|
+
|
|
410
|
+
ax = plt.gca()
|
|
411
|
+
ax.set_autoscale_on(False)
|
|
412
|
+
polygons = []
|
|
413
|
+
color = []
|
|
414
|
+
for ann in anns:
|
|
415
|
+
c = (np.random.random((1, 3)) * 0.6 + 0.4).tolist()[0]
|
|
416
|
+
if "segmentation" in ann:
|
|
417
|
+
if isinstance(ann["segmentation"], list):
|
|
418
|
+
# polygon
|
|
419
|
+
for seg in ann["segmentation"]:
|
|
420
|
+
poly = np.array(seg).reshape((int(len(seg) / 2), 2))
|
|
421
|
+
polygons.append(Polygon(poly))
|
|
422
|
+
color.append(c)
|
|
423
|
+
else:
|
|
424
|
+
# mask
|
|
425
|
+
t = self.imgs[ann["image_id"]]
|
|
426
|
+
if isinstance(ann["segmentation"]["counts"], list):
|
|
427
|
+
rle = maskUtils.frPyObjects([ann["segmentation"]], t["height"], t["width"])
|
|
428
|
+
else:
|
|
429
|
+
rle = [ann["segmentation"]]
|
|
430
|
+
m = maskUtils.decode(rle)
|
|
431
|
+
img = np.ones((m.shape[0], m.shape[1], 3))
|
|
432
|
+
if ann["iscrowd"] == 1:
|
|
433
|
+
color_mask = np.array([2.0, 166.0, 101.0]) / 255
|
|
434
|
+
if ann["iscrowd"] == 0:
|
|
435
|
+
color_mask = np.random.random((1, 3)).tolist()[0]
|
|
436
|
+
for i in range(3):
|
|
437
|
+
img[:, :, i] = color_mask[i]
|
|
438
|
+
ax.imshow(np.dstack((img, m * 0.5)))
|
|
439
|
+
if "keypoints" in ann and isinstance(ann["keypoints"], list):
|
|
440
|
+
# turn skeleton into zero-based index
|
|
441
|
+
sks = np.array(self.loadCats(ann["category_id"])[0]["skeleton"]) - 1
|
|
442
|
+
kp = np.array(ann["keypoints"])
|
|
443
|
+
x = kp[0::3]
|
|
444
|
+
y = kp[1::3]
|
|
445
|
+
v = kp[2::3]
|
|
446
|
+
for sk in sks:
|
|
447
|
+
if np.all(v[sk] > 0):
|
|
448
|
+
plt.plot(x[sk], y[sk], linewidth=3, color=c)
|
|
449
|
+
plt.plot(
|
|
450
|
+
x[v > 0], y[v > 0], "o", markersize=8, markerfacecolor=c, markeredgecolor="k", markeredgewidth=2
|
|
451
|
+
)
|
|
452
|
+
plt.plot(
|
|
453
|
+
x[v > 1], y[v > 1], "o", markersize=8, markerfacecolor=c, markeredgecolor=c, markeredgewidth=2
|
|
454
|
+
)
|
|
455
|
+
|
|
456
|
+
if draw_bbox:
|
|
457
|
+
[bbox_x, bbox_y, bbox_w, bbox_h] = ann["bbox"]
|
|
458
|
+
poly = [
|
|
459
|
+
[bbox_x, bbox_y],
|
|
460
|
+
[bbox_x, bbox_y + bbox_h],
|
|
461
|
+
[bbox_x + bbox_w, bbox_y + bbox_h],
|
|
462
|
+
[bbox_x + bbox_w, bbox_y],
|
|
463
|
+
]
|
|
464
|
+
np_poly = np.array(poly).reshape((4, 2))
|
|
465
|
+
polygons.append(Polygon(np_poly))
|
|
466
|
+
color.append(c)
|
|
467
|
+
|
|
468
|
+
p = PatchCollection(polygons, facecolor=color, linewidths=0, alpha=0.4)
|
|
469
|
+
ax.add_collection(p)
|
|
470
|
+
p = PatchCollection(polygons, facecolor="none", edgecolors=color, linewidths=2)
|
|
471
|
+
ax.add_collection(p)
|
|
472
|
+
elif datasetType == "captions":
|
|
473
|
+
for ann in anns:
|
|
474
|
+
print(ann["caption"])
|
|
388
475
|
|
|
389
476
|
def download(self, tarDir=None, imgIds=[]):
|
|
390
477
|
warnings.warn("download deprecated in 1.3.0", DeprecationWarning)
|
|
@@ -10,7 +10,7 @@ from typing import Callable, List, Optional, Union
|
|
|
10
10
|
if sys.version_info >= (3, 8):
|
|
11
11
|
from typing import Literal
|
|
12
12
|
|
|
13
|
-
iouTypeT = Literal["segm", "bbox", "keypoints", "boundary"]
|
|
13
|
+
iouTypeT = Literal["segm", "bbox", "keypoints", "keypoints_crowd", "boundary"]
|
|
14
14
|
else:
|
|
15
15
|
iouTypeT = str
|
|
16
16
|
|
|
@@ -30,9 +30,10 @@ class COCOeval:
|
|
|
30
30
|
cocoGt: Optional[COCO] = None,
|
|
31
31
|
cocoDt: Optional[COCO] = None,
|
|
32
32
|
iouType: iouTypeT = "segm",
|
|
33
|
-
print_function: Callable = logger.
|
|
33
|
+
print_function: Callable = logger.info,
|
|
34
34
|
extra_calc: bool = False,
|
|
35
35
|
kpt_oks_sigmas: Optional[List[float]] = None,
|
|
36
|
+
use_area: Optional[bool] = True,
|
|
36
37
|
lvis_style: bool = False,
|
|
37
38
|
separate_eval: bool = False,
|
|
38
39
|
boundary_dilation_ratio: float = 0.02,
|
|
@@ -53,6 +54,8 @@ class COCOeval:
|
|
|
53
54
|
whether to perform extra calculations, defaults to False
|
|
54
55
|
kpt_oks_sigmas (None or list):
|
|
55
56
|
list of sigmas for keypoint evaluation, defaults to None
|
|
57
|
+
use_area (bool):
|
|
58
|
+
If gt annotations (eg. CrowdPose) do not have 'area', please set use_area=False.
|
|
56
59
|
lvis_style (bool):
|
|
57
60
|
whether to use LVIS style evaluation, defaults to False
|
|
58
61
|
separate_eval (bool):
|
|
@@ -81,6 +84,7 @@ class COCOeval:
|
|
|
81
84
|
self.separate_eval = separate_eval
|
|
82
85
|
self.boundary_dilation_ratio = boundary_dilation_ratio
|
|
83
86
|
self.boundary_cpu_count = boundary_cpu_count
|
|
87
|
+
self.use_area = use_area
|
|
84
88
|
|
|
85
89
|
if iouType == "keypoints" and self.lvis_style:
|
|
86
90
|
logger.warning("lvis_style not supported for keypoint evaluation")
|
|
@@ -119,6 +123,10 @@ class COCOeval:
|
|
|
119
123
|
params."""
|
|
120
124
|
p = self.params
|
|
121
125
|
|
|
126
|
+
# cleanup before create new
|
|
127
|
+
self.gt_dataset.clean()
|
|
128
|
+
self.dt_dataset.clean()
|
|
129
|
+
|
|
122
130
|
cat_ids = p.catIds if p.catIds else None
|
|
123
131
|
|
|
124
132
|
gts = self.cocoGt.loadAnns(self.cocoGt.getAnnIds(imgIds=p.imgIds, catIds=cat_ids))
|
|
@@ -128,8 +136,8 @@ class COCOeval:
|
|
|
128
136
|
for gt in gts:
|
|
129
137
|
gt["ignore"] = gt["ignore"] if "ignore" in gt else 0
|
|
130
138
|
gt["ignore"] = "iscrowd" in gt and gt["iscrowd"]
|
|
131
|
-
if p.iouType
|
|
132
|
-
gt["ignore"] = (gt.get("num_keypoints") == 0) or gt["ignore"]
|
|
139
|
+
if "keypoints" in p.iouType:
|
|
140
|
+
gt["ignore"] = (gt.get("num_keypoints", 0) == 0) or gt["ignore"]
|
|
133
141
|
|
|
134
142
|
img_pl = defaultdict(set) # per image list of categories present in image
|
|
135
143
|
img_nl = {} # per image map of categories not present in image
|
|
@@ -159,7 +167,6 @@ class COCOeval:
|
|
|
159
167
|
if img_sizes.get(image_id) is None:
|
|
160
168
|
t = dataset.imgs[image_id]
|
|
161
169
|
img_sizes[image_id] = t["height"], t["width"]
|
|
162
|
-
return img_sizes[image_id]
|
|
163
170
|
|
|
164
171
|
for gt in gts:
|
|
165
172
|
if p.compute_rle:
|
|
@@ -328,7 +335,13 @@ class COCOeval:
|
|
|
328
335
|
z = np.zeros(k)
|
|
329
336
|
dx = np.max((z, x0 - xd), axis=0) + np.max((z, xd - x1), axis=0)
|
|
330
337
|
dy = np.max((z, y0 - yd), axis=0) + np.max((z, yd - y1), axis=0)
|
|
331
|
-
|
|
338
|
+
|
|
339
|
+
if self.use_area:
|
|
340
|
+
e = (dx**2 + dy**2) / vars / (gt["area"] + np.spacing(1)) / 2
|
|
341
|
+
else:
|
|
342
|
+
tmparea = gt["bbox"][3] * gt["bbox"][2] * 0.53
|
|
343
|
+
e = (dx**2 + dy**2) / vars / (tmparea + np.spacing(1)) / 2
|
|
344
|
+
|
|
332
345
|
if k1 > 0:
|
|
333
346
|
e = e[vg > 0]
|
|
334
347
|
ious[i, j] = np.sum(np.exp(-e)) / e.shape[0]
|
|
@@ -362,30 +375,12 @@ class COCOeval:
|
|
|
362
375
|
iouStr = f"{p.iouThrs[0]:0.2f}:{p.iouThrs[-1]:0.2f}" if iouThr is None else f"{iouThr:0.2f}"
|
|
363
376
|
|
|
364
377
|
if catIds is not None:
|
|
365
|
-
# catNames = [
|
|
366
|
-
# self.cocoGt.cats[p.catIds[used_cat_idx]].get(
|
|
367
|
-
# "name", used_cat_idx
|
|
368
|
-
# )
|
|
369
|
-
# for used_cat_idx in catIds
|
|
370
|
-
# ]
|
|
371
378
|
freq_str = f"catIds=={str(catIds):>3s}"
|
|
372
379
|
|
|
373
380
|
if self.lvis_style and (freq_group_idx is not None):
|
|
374
381
|
catIds = self.freq_groups[freq_group_idx]
|
|
375
382
|
freq_str = f"catIds={p.imgCountLbl[freq_group_idx]:>3s}"
|
|
376
383
|
|
|
377
|
-
# In my case, C++ too slow...
|
|
378
|
-
# mean_s = _C._summarize(
|
|
379
|
-
# ap,
|
|
380
|
-
# (iouThr if iouThr else -1),
|
|
381
|
-
# areaRng,
|
|
382
|
-
# maxDets,
|
|
383
|
-
# catIds,
|
|
384
|
-
# p,
|
|
385
|
-
# self.eval["counts"],
|
|
386
|
-
# self.eval["precision"] if ap == 1 else self.eval["recall"],
|
|
387
|
-
# )
|
|
388
|
-
|
|
389
384
|
aind = p.areaRngLbl.index(areaRng)
|
|
390
385
|
mind = p.maxDets.index(maxDets)
|
|
391
386
|
|
|
@@ -440,6 +435,7 @@ class COCOeval:
|
|
|
440
435
|
def _summarizeDets():
|
|
441
436
|
_count = 17 if self.lvis_style else 14
|
|
442
437
|
stats = np.zeros((_count,))
|
|
438
|
+
|
|
443
439
|
stats[0] = self._summarize(1, maxDets=self.params.maxDets[-1]) # AP_all
|
|
444
440
|
stats[1] = self._summarize(1, iouThr=0.5, maxDets=self.params.maxDets[-1]) # AP_50
|
|
445
441
|
stats[2] = self._summarize(1, iouThr=0.75, maxDets=self.params.maxDets[-1]) # AP_75
|
|
@@ -452,8 +448,7 @@ class COCOeval:
|
|
|
452
448
|
stats[15] = self._summarize(1, maxDets=self.params.maxDets[-1], freq_group_idx=1) # APc
|
|
453
449
|
stats[16] = self._summarize(1, maxDets=self.params.maxDets[-1], freq_group_idx=2) # APf
|
|
454
450
|
|
|
455
|
-
# AR_first or AR_all
|
|
456
|
-
stats[6] = self._summarize(0, maxDets=self.params.maxDets[0])
|
|
451
|
+
stats[6] = self._summarize(0, maxDets=self.params.maxDets[0]) # AR_first or AR_all
|
|
457
452
|
if len(self.params.maxDets) >= 2:
|
|
458
453
|
stats[7] = self._summarize(0, maxDets=self.params.maxDets[1]) # AR_second
|
|
459
454
|
if len(self.params.maxDets) >= 3:
|
|
@@ -470,16 +465,42 @@ class COCOeval:
|
|
|
470
465
|
|
|
471
466
|
def _summarizeKps():
|
|
472
467
|
stats = np.zeros((10,))
|
|
473
|
-
stats[0] = self._summarize(1, maxDets=self.params.maxDets[-1])
|
|
474
|
-
stats[1] = self._summarize(1, maxDets=self.params.maxDets[-1], iouThr=0.5)
|
|
475
|
-
stats[2] = self._summarize(1, maxDets=self.params.maxDets[-1], iouThr=0.75)
|
|
476
|
-
stats[3] = self._summarize(1, maxDets=self.params.maxDets[-1], areaRng="medium")
|
|
477
|
-
stats[4] = self._summarize(1, maxDets=self.params.maxDets[-1], areaRng="large")
|
|
478
|
-
stats[5] = self._summarize(0, maxDets=self.params.maxDets[-1])
|
|
479
|
-
stats[6] = self._summarize(0, maxDets=self.params.maxDets[-1], iouThr=0.5)
|
|
480
|
-
stats[7] = self._summarize(0, maxDets=self.params.maxDets[-1], iouThr=0.75)
|
|
481
|
-
stats[8] = self._summarize(0, maxDets=self.params.maxDets[-1], areaRng="medium")
|
|
482
|
-
stats[9] = self._summarize(0, maxDets=self.params.maxDets[-1], areaRng="large")
|
|
468
|
+
stats[0] = self._summarize(1, maxDets=self.params.maxDets[-1]) # AP_all
|
|
469
|
+
stats[1] = self._summarize(1, maxDets=self.params.maxDets[-1], iouThr=0.5) # AP_50
|
|
470
|
+
stats[2] = self._summarize(1, maxDets=self.params.maxDets[-1], iouThr=0.75) # AP_75
|
|
471
|
+
stats[3] = self._summarize(1, maxDets=self.params.maxDets[-1], areaRng="medium") # AP_medium
|
|
472
|
+
stats[4] = self._summarize(1, maxDets=self.params.maxDets[-1], areaRng="large") # AP_large
|
|
473
|
+
stats[5] = self._summarize(0, maxDets=self.params.maxDets[-1]) # AR_all
|
|
474
|
+
stats[6] = self._summarize(0, maxDets=self.params.maxDets[-1], iouThr=0.5) # AR_50
|
|
475
|
+
stats[7] = self._summarize(0, maxDets=self.params.maxDets[-1], iouThr=0.75) # AR_75
|
|
476
|
+
stats[8] = self._summarize(0, maxDets=self.params.maxDets[-1], areaRng="medium") # AR_medium
|
|
477
|
+
stats[9] = self._summarize(0, maxDets=self.params.maxDets[-1], areaRng="large") # AR_large
|
|
478
|
+
return stats
|
|
479
|
+
|
|
480
|
+
def _summarizeKps_crowd():
|
|
481
|
+
stats = np.zeros((9,))
|
|
482
|
+
stats[0] = self._summarize(1, maxDets=self.params.maxDets[-1]) # AP_all
|
|
483
|
+
stats[1] = self._summarize(1, maxDets=self.params.maxDets[-1], iouThr=0.5) # AP_50
|
|
484
|
+
stats[2] = self._summarize(1, maxDets=self.params.maxDets[-1], iouThr=0.75) # AP_75
|
|
485
|
+
stats[3] = self._summarize(0, maxDets=self.params.maxDets[-1]) # AR_all
|
|
486
|
+
stats[4] = self._summarize(0, maxDets=self.params.maxDets[-1], iouThr=0.5) # AR_50
|
|
487
|
+
stats[5] = self._summarize(0, maxDets=self.params.maxDets[-1], iouThr=0.75) # AR_75
|
|
488
|
+
type_result = self.get_type_result(first=0.2, second=0.8)
|
|
489
|
+
|
|
490
|
+
p = self.params
|
|
491
|
+
iStr = " {:<18} {} @[ IoU={:<9} | type={:>6s} | maxDets={:>3d} ] = {:0.3f}"
|
|
492
|
+
titleStr = "Average Precision"
|
|
493
|
+
typeStr = "(AP)"
|
|
494
|
+
iouStr = f"{p.iouThrs[0]:0.2f}:{p.iouThrs[-1]:0.2f}"
|
|
495
|
+
self.print_function(iStr.format(titleStr, typeStr, iouStr, "easy", self.params.maxDets[-1], type_result[0]))
|
|
496
|
+
self.print_function(
|
|
497
|
+
iStr.format(titleStr, typeStr, iouStr, "medium", self.params.maxDets[-1], type_result[1])
|
|
498
|
+
)
|
|
499
|
+
self.print_function(iStr.format(titleStr, typeStr, iouStr, "hard", self.params.maxDets[-1], type_result[2]))
|
|
500
|
+
stats[6] = type_result[0] # AP_easy
|
|
501
|
+
stats[7] = type_result[1] # AP_medium
|
|
502
|
+
stats[8] = type_result[2] # AP_hard
|
|
503
|
+
|
|
483
504
|
return stats
|
|
484
505
|
|
|
485
506
|
if not self.eval:
|
|
@@ -491,12 +512,45 @@ class COCOeval:
|
|
|
491
512
|
summarize = _summarizeDets
|
|
492
513
|
elif iouType == "keypoints":
|
|
493
514
|
summarize = _summarizeKps
|
|
515
|
+
elif iouType == "keypoints_crowd":
|
|
516
|
+
summarize = _summarizeKps_crowd
|
|
494
517
|
else:
|
|
495
|
-
ValueError(f"iouType must be bbox, segm, boundary or keypoints. Get {iouType}")
|
|
518
|
+
ValueError(f"iouType must be bbox, segm, boundary or keypoints or keypoints_crowd. Get {iouType}")
|
|
496
519
|
|
|
497
520
|
self.all_stats = summarize()
|
|
498
521
|
self.stats = self.all_stats[:12]
|
|
499
522
|
|
|
523
|
+
def get_type_result(self, first=0.01, second=0.85):
|
|
524
|
+
easy, mid, hard = self.split(self.cocoGt.annotation_file, first, second)
|
|
525
|
+
res = []
|
|
526
|
+
prev_print = self.print_function
|
|
527
|
+
self.print_function = lambda *args, **kwargs: None
|
|
528
|
+
|
|
529
|
+
for curr_type in [easy, mid, hard]:
|
|
530
|
+
curr_list = curr_type
|
|
531
|
+
self.params.imgIds = curr_list
|
|
532
|
+
self.evaluate()
|
|
533
|
+
self.accumulate()
|
|
534
|
+
score = self.eval["precision"][:, :, :, 0, :]
|
|
535
|
+
res.append(round(np.mean(score), 4))
|
|
536
|
+
|
|
537
|
+
self.print_function = prev_print
|
|
538
|
+
return res
|
|
539
|
+
|
|
540
|
+
def split(self, gt_file, first=0.01, second=0.85):
|
|
541
|
+
data = COCO.load_json(gt_file, use_deepcopy=True)
|
|
542
|
+
easy = []
|
|
543
|
+
mid = []
|
|
544
|
+
hard = []
|
|
545
|
+
for item in data["images"]:
|
|
546
|
+
if item["crowdIndex"] < first:
|
|
547
|
+
easy.append(item["id"])
|
|
548
|
+
elif item["crowdIndex"] < second:
|
|
549
|
+
mid.append(item["id"])
|
|
550
|
+
else:
|
|
551
|
+
hard.append(item["id"])
|
|
552
|
+
return easy, mid, hard
|
|
553
|
+
|
|
500
554
|
def __str__(self):
|
|
501
555
|
self.summarize()
|
|
502
556
|
return str(self.__repr__())
|
|
@@ -574,7 +628,7 @@ class Params:
|
|
|
574
628
|
|
|
575
629
|
if iouType in set(["segm", "bbox", "boundary"]):
|
|
576
630
|
self.setDetParams()
|
|
577
|
-
elif
|
|
631
|
+
elif "keypoints" in iouType:
|
|
578
632
|
self.setKpParams()
|
|
579
633
|
if kpt_sigmas is not None:
|
|
580
634
|
self.kpt_oks_sigmas = np.array(kpt_sigmas)
|