faster-coco-eval 1.6.0__tar.gz → 1.6.2__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.0/faster_coco_eval.egg-info → faster_coco_eval-1.6.2}/PKG-INFO +1 -1
- {faster_coco_eval-1.6.0 → faster_coco_eval-1.6.2}/csrc/faster_eval_api/coco_eval/cocoeval.cpp +16 -19
- {faster_coco_eval-1.6.0 → faster_coco_eval-1.6.2}/csrc/mask_api/src/mask.cpp +42 -20
- {faster_coco_eval-1.6.0 → faster_coco_eval-1.6.2}/csrc/mask_api/src/mask.h +2 -0
- {faster_coco_eval-1.6.0 → faster_coco_eval-1.6.2}/csrc/mask_api/src/rle.cpp +6 -6
- {faster_coco_eval-1.6.0 → faster_coco_eval-1.6.2}/faster_coco_eval/core/cocoeval.py +4 -4
- {faster_coco_eval-1.6.0 → faster_coco_eval-1.6.2}/faster_coco_eval/core/mask.py +1 -1
- {faster_coco_eval-1.6.0 → faster_coco_eval-1.6.2}/faster_coco_eval/version.py +1 -1
- {faster_coco_eval-1.6.0 → faster_coco_eval-1.6.2/faster_coco_eval.egg-info}/PKG-INFO +1 -1
- {faster_coco_eval-1.6.0 → faster_coco_eval-1.6.2}/setup.py +14 -7
- {faster_coco_eval-1.6.0 → faster_coco_eval-1.6.2}/tests/test_coco_metric.py +13 -2
- {faster_coco_eval-1.6.0 → faster_coco_eval-1.6.2}/tests/test_keypoints.py +10 -2
- faster_coco_eval-1.6.2/tests/test_torchmetrics.py +305 -0
- faster_coco_eval-1.6.0/tests/test_torchmetrics.py +0 -103
- {faster_coco_eval-1.6.0 → faster_coco_eval-1.6.2}/LICENSE +0 -0
- {faster_coco_eval-1.6.0 → faster_coco_eval-1.6.2}/MANIFEST.in +0 -0
- {faster_coco_eval-1.6.0 → faster_coco_eval-1.6.2}/README.md +0 -0
- {faster_coco_eval-1.6.0 → faster_coco_eval-1.6.2}/csrc/faster_eval_api/coco_eval/cocoeval.h +0 -0
- {faster_coco_eval-1.6.0 → faster_coco_eval-1.6.2}/csrc/faster_eval_api/faster_eval_api.cpp +0 -0
- {faster_coco_eval-1.6.0 → faster_coco_eval-1.6.2}/csrc/mask_api/mask_api.cpp +0 -0
- {faster_coco_eval-1.6.0 → faster_coco_eval-1.6.2}/faster_coco_eval/__init__.py +0 -0
- {faster_coco_eval-1.6.0 → faster_coco_eval-1.6.2}/faster_coco_eval/core/__init__.py +0 -0
- {faster_coco_eval-1.6.0 → faster_coco_eval-1.6.2}/faster_coco_eval/core/coco.py +0 -0
- {faster_coco_eval-1.6.0 → faster_coco_eval-1.6.2}/faster_coco_eval/core/faster_eval_api.py +0 -0
- {faster_coco_eval-1.6.0 → faster_coco_eval-1.6.2}/faster_coco_eval/extra/__init__.py +0 -0
- {faster_coco_eval-1.6.0 → faster_coco_eval-1.6.2}/faster_coco_eval/extra/curves.py +0 -0
- {faster_coco_eval-1.6.0 → faster_coco_eval-1.6.2}/faster_coco_eval/extra/display.py +0 -0
- {faster_coco_eval-1.6.0 → faster_coco_eval-1.6.2}/faster_coco_eval/extra/draw.py +0 -0
- {faster_coco_eval-1.6.0 → faster_coco_eval-1.6.2}/faster_coco_eval/extra/extra.py +0 -0
- {faster_coco_eval-1.6.0 → faster_coco_eval-1.6.2}/faster_coco_eval/extra/utils.py +0 -0
- {faster_coco_eval-1.6.0 → faster_coco_eval-1.6.2}/faster_coco_eval.egg-info/SOURCES.txt +0 -0
- {faster_coco_eval-1.6.0 → faster_coco_eval-1.6.2}/faster_coco_eval.egg-info/dependency_links.txt +0 -0
- {faster_coco_eval-1.6.0 → faster_coco_eval-1.6.2}/faster_coco_eval.egg-info/requires.txt +0 -0
- {faster_coco_eval-1.6.0 → faster_coco_eval-1.6.2}/faster_coco_eval.egg-info/top_level.txt +0 -0
- {faster_coco_eval-1.6.0 → faster_coco_eval-1.6.2}/pyproject.toml +0 -0
- {faster_coco_eval-1.6.0 → faster_coco_eval-1.6.2}/requirements/extra.txt +0 -0
- {faster_coco_eval-1.6.0 → faster_coco_eval-1.6.2}/requirements/runtime.txt +0 -0
- {faster_coco_eval-1.6.0 → faster_coco_eval-1.6.2}/requirements/tests.txt +0 -0
- {faster_coco_eval-1.6.0 → faster_coco_eval-1.6.2}/setup.cfg +0 -0
- {faster_coco_eval-1.6.0 → faster_coco_eval-1.6.2}/tests/test_basic.py +0 -0
- {faster_coco_eval-1.6.0 → faster_coco_eval-1.6.2}/tests/test_boundary.py +0 -0
- {faster_coco_eval-1.6.0 → faster_coco_eval-1.6.2}/tests/test_init_pycocotools.py +0 -0
- {faster_coco_eval-1.6.0 → faster_coco_eval-1.6.2}/tests/test_lvis_metric.py +0 -0
- {faster_coco_eval-1.6.0 → faster_coco_eval-1.6.2}/tests/test_mask_api.py +0 -0
{faster_coco_eval-1.6.0 → faster_coco_eval-1.6.2}/csrc/faster_eval_api/coco_eval/cocoeval.cpp
RENAMED
|
@@ -12,7 +12,7 @@ namespace coco_eval
|
|
|
12
12
|
namespace COCOeval
|
|
13
13
|
{
|
|
14
14
|
template <typename T>
|
|
15
|
-
|
|
15
|
+
int64_t v_index(const std::vector<T> &v, const T &key)
|
|
16
16
|
{
|
|
17
17
|
auto itr = std::find(v.begin(), v.end(), key);
|
|
18
18
|
|
|
@@ -90,9 +90,9 @@ namespace coco_eval
|
|
|
90
90
|
ImageEvaluation *results)
|
|
91
91
|
{
|
|
92
92
|
// Initialize memory to store return data matches and ignore
|
|
93
|
-
const int num_iou_thresholds = iou_thresholds.size();
|
|
94
|
-
const int num_ground_truth = ground_truth_sorted_indices.size();
|
|
95
|
-
const int num_detections = detection_sorted_indices.size();
|
|
93
|
+
const int num_iou_thresholds = (const int) iou_thresholds.size();
|
|
94
|
+
const int num_ground_truth = (const int) ground_truth_sorted_indices.size();
|
|
95
|
+
const int num_detections = (const int) detection_sorted_indices.size();
|
|
96
96
|
// std::vector<uint64_t> ground_truth_matches(
|
|
97
97
|
// num_iou_thresholds * num_ground_truth, 0);
|
|
98
98
|
std::vector<int64_t> &ground_truth_matches = results->ground_truth_matches;
|
|
@@ -189,10 +189,9 @@ namespace coco_eval
|
|
|
189
189
|
const ImageCategoryInstances<InstanceAnnotation> &
|
|
190
190
|
image_category_detection_instances)
|
|
191
191
|
{
|
|
192
|
-
const int num_area_ranges = area_ranges.size();
|
|
193
|
-
const int num_images = image_category_ground_truth_instances.size();
|
|
194
|
-
const int num_categories =
|
|
195
|
-
image_category_ious.size() > 0 ? image_category_ious[0].size() : 0;
|
|
192
|
+
const int num_area_ranges = (const int) area_ranges.size();
|
|
193
|
+
const int num_images = (const int) image_category_ground_truth_instances.size();
|
|
194
|
+
const int num_categories = (const int) (image_category_ious.size() > 0 ? image_category_ious[0].size() : 0);
|
|
196
195
|
std::vector<uint64_t> detection_sorted_indices;
|
|
197
196
|
std::vector<uint64_t> ground_truth_sorted_indices;
|
|
198
197
|
std::vector<bool> ignores;
|
|
@@ -440,14 +439,12 @@ namespace coco_eval
|
|
|
440
439
|
list_to_vec<double>(params.attr("recThrs"));
|
|
441
440
|
const std::vector<int> max_detections =
|
|
442
441
|
list_to_vec<int>(params.attr("maxDets"));
|
|
443
|
-
const int num_iou_thresholds = py::len(params.attr("iouThrs"));
|
|
444
|
-
const int num_recall_thresholds = py::len(params.attr("recThrs"));
|
|
445
|
-
const int num_categories = params.attr("useCats").cast<int>() == 1
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
const int
|
|
449
|
-
const int num_max_detections = py::len(params.attr("maxDets"));
|
|
450
|
-
const int num_images = py::len(params.attr("imgIds"));
|
|
442
|
+
const int num_iou_thresholds = (const int) py::len(params.attr("iouThrs"));
|
|
443
|
+
const int num_recall_thresholds = (const int) py::len(params.attr("recThrs"));
|
|
444
|
+
const int num_categories = (const int)(params.attr("useCats").cast<int>() == 1 ? py::len(params.attr("catIds")) : 1);
|
|
445
|
+
const int num_area_ranges = (const int) py::len(params.attr("areaRng"));
|
|
446
|
+
const int num_max_detections = (const int) py::len(params.attr("maxDets"));
|
|
447
|
+
const int num_images = (const int) py::len(params.attr("imgIds"));
|
|
451
448
|
|
|
452
449
|
std::vector<double> precisions_out(
|
|
453
450
|
num_iou_thresholds * num_recall_thresholds * num_categories *
|
|
@@ -793,9 +790,9 @@ namespace coco_eval
|
|
|
793
790
|
|
|
794
791
|
std::vector<int> _catIds;
|
|
795
792
|
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
793
|
+
int64_t iou_ind = v_index(iouThrs, iouThr);
|
|
794
|
+
int64_t aind = v_index(areaRngLbl, areaRng);
|
|
795
|
+
int64_t mind = v_index(maxDets, maxDet);
|
|
799
796
|
|
|
800
797
|
if (catIds.size() == 0)
|
|
801
798
|
{
|
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
#include <iostream>
|
|
8
8
|
#include <execution>
|
|
9
9
|
#include <future>
|
|
10
|
+
#include <thread>
|
|
10
11
|
|
|
11
12
|
using namespace pybind11::literals;
|
|
12
13
|
|
|
@@ -141,7 +142,8 @@ namespace mask_api
|
|
|
141
142
|
if (n > 0)
|
|
142
143
|
{
|
|
143
144
|
uint64_t h = (R[0].h), w = (R[0].w);
|
|
144
|
-
|
|
145
|
+
|
|
146
|
+
py::array_t<uint8_t> M({h, w, n});
|
|
145
147
|
auto mask = M.mutable_unchecked();
|
|
146
148
|
uint64_t s = h * w * n;
|
|
147
149
|
|
|
@@ -535,7 +537,7 @@ namespace mask_api
|
|
|
535
537
|
{
|
|
536
538
|
return frUncompressedRLE(pyobj.cast<std::vector<py::dict>>());
|
|
537
539
|
}
|
|
538
|
-
else if (sub_type == "<class 'list'>"
|
|
540
|
+
else if ((sub_type == "<class 'list'>") || (sub_type == "<class 'numpy.ndarray'>"))
|
|
539
541
|
{
|
|
540
542
|
std::vector<std::vector<double>> numpy_array = pyobj.cast<std::vector<std::vector<double>>>();
|
|
541
543
|
if (numpy_array[0].size() == 4)
|
|
@@ -547,7 +549,7 @@ namespace mask_api
|
|
|
547
549
|
return frPoly(numpy_array, h, w);
|
|
548
550
|
}
|
|
549
551
|
}
|
|
550
|
-
else if (sub_type == "<class 'float'>"
|
|
552
|
+
else if ((sub_type == "<class 'float'>") || (sub_type == "<class 'int'>"))
|
|
551
553
|
{
|
|
552
554
|
std::vector<double> array = pyobj.cast<std::vector<double>>();
|
|
553
555
|
if (array.size() == 4)
|
|
@@ -595,27 +597,44 @@ namespace mask_api
|
|
|
595
597
|
py::gil_scoped_release release;
|
|
596
598
|
std::vector<std::tuple<uint64_t, uint64_t, std::string>> result(rles.size());
|
|
597
599
|
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
600
|
+
// Windows not support async
|
|
601
|
+
#ifndef _WIN32
|
|
602
|
+
auto process = [&rles, &result](size_t s, size_t e, double d) mutable
|
|
601
603
|
{
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
604
|
+
for (size_t i = s; i < e; ++i)
|
|
605
|
+
{
|
|
606
|
+
result[i] = rles[i].toBoundary(d).toTuple();
|
|
607
|
+
}
|
|
608
|
+
std::this_thread::sleep_for(std::chrono::milliseconds(1));
|
|
609
|
+
};
|
|
610
|
+
#endif
|
|
606
611
|
|
|
607
612
|
size_t start = 0;
|
|
608
613
|
size_t step = 1000;
|
|
609
614
|
size_t end = step;
|
|
610
615
|
|
|
616
|
+
if (end > rles.size())
|
|
617
|
+
{
|
|
618
|
+
end = rles.size();
|
|
619
|
+
}
|
|
620
|
+
|
|
611
621
|
while (start < rles.size())
|
|
612
622
|
{
|
|
613
|
-
|
|
623
|
+
#ifndef _WIN32
|
|
624
|
+
std::vector<std::future<void>> rle_futures(cpu_count);
|
|
625
|
+
#endif
|
|
614
626
|
|
|
615
627
|
size_t thread = 0;
|
|
616
|
-
for (thread = 0; thread <
|
|
628
|
+
for (thread = 0; thread < cpu_count; thread++)
|
|
617
629
|
{
|
|
618
|
-
|
|
630
|
+
#ifdef _WIN32
|
|
631
|
+
for (size_t i = start; i < end; ++i)
|
|
632
|
+
{
|
|
633
|
+
result[i] = rles[i].toBoundary(dilation_ratio).toTuple();
|
|
634
|
+
}
|
|
635
|
+
#else
|
|
636
|
+
rle_futures[thread] = std::async(std::launch::async, process, start, end, dilation_ratio);
|
|
637
|
+
#endif
|
|
619
638
|
|
|
620
639
|
start += step;
|
|
621
640
|
end += step;
|
|
@@ -630,13 +649,15 @@ namespace mask_api
|
|
|
630
649
|
break;
|
|
631
650
|
}
|
|
632
651
|
}
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
652
|
+
|
|
653
|
+
#ifndef _WIN32
|
|
654
|
+
for (size_t i = 0; i < thread; i++)
|
|
655
|
+
{
|
|
656
|
+
rle_futures[i].wait();
|
|
657
|
+
}
|
|
658
|
+
rle_futures.clear();
|
|
659
|
+
rle_futures.shrink_to_fit();
|
|
660
|
+
#endif
|
|
640
661
|
}
|
|
641
662
|
|
|
642
663
|
py::gil_scoped_acquire acquire;
|
|
@@ -677,6 +698,7 @@ namespace mask_api
|
|
|
677
698
|
|
|
678
699
|
if (compute_boundary)
|
|
679
700
|
{
|
|
701
|
+
|
|
680
702
|
boundary_array = processRleToBoundary(rles, dilation_ratio, cpu_count);
|
|
681
703
|
}
|
|
682
704
|
|
|
@@ -81,7 +81,7 @@ namespace mask_api
|
|
|
81
81
|
x += cnts[cnts.size() - 2];
|
|
82
82
|
}
|
|
83
83
|
|
|
84
|
-
cnts.emplace_back(x);
|
|
84
|
+
cnts.emplace_back((uint)x);
|
|
85
85
|
}
|
|
86
86
|
|
|
87
87
|
return RLE(h, w, cnts.size(), cnts);
|
|
@@ -208,7 +208,7 @@ namespace mask_api
|
|
|
208
208
|
if (yd < 0)
|
|
209
209
|
yd = 0;
|
|
210
210
|
else if (yd > h)
|
|
211
|
-
yd = h;
|
|
211
|
+
yd = (double)h;
|
|
212
212
|
|
|
213
213
|
yd = ceil(yd);
|
|
214
214
|
x.emplace_back((int)xd);
|
|
@@ -259,7 +259,7 @@ namespace mask_api
|
|
|
259
259
|
RLE RLE::erode_3x3(int dilation) const
|
|
260
260
|
{
|
|
261
261
|
bool v = false;
|
|
262
|
-
long max_len = this->w * this->h;
|
|
262
|
+
long max_len = (long)(this->w * this->h);
|
|
263
263
|
std::vector<bool> _counts(max_len, false);
|
|
264
264
|
std::vector<bool>::iterator ptr = _counts.begin();
|
|
265
265
|
std::for_each(this->cnts.begin(), this->cnts.end(), [&v, &ptr](uint count)
|
|
@@ -285,7 +285,7 @@ namespace mask_api
|
|
|
285
285
|
}
|
|
286
286
|
if (i > 0)
|
|
287
287
|
{
|
|
288
|
-
ofsvec.push_back(i * this->h + j);
|
|
288
|
+
ofsvec.push_back((int)(i * this->h + j));
|
|
289
289
|
}
|
|
290
290
|
else
|
|
291
291
|
{
|
|
@@ -296,7 +296,7 @@ namespace mask_api
|
|
|
296
296
|
|
|
297
297
|
for (int i = dilation; i >= -dilation; i--)
|
|
298
298
|
{
|
|
299
|
-
ofsvec_bottom.push_back(i * this->h + dilation);
|
|
299
|
+
ofsvec_bottom.push_back((int)(i * this->h + dilation));
|
|
300
300
|
}
|
|
301
301
|
|
|
302
302
|
long c = 0;
|
|
@@ -304,7 +304,7 @@ namespace mask_api
|
|
|
304
304
|
long ic = 0;
|
|
305
305
|
std::vector<uint> cnts;
|
|
306
306
|
bool _min = false, _prev_min = false;
|
|
307
|
-
long rle_h = this->h;
|
|
307
|
+
long rle_h = (long)this->h;
|
|
308
308
|
|
|
309
309
|
v = true;
|
|
310
310
|
for (uint j : this->cnts)
|
|
@@ -169,15 +169,15 @@ class COCOeval:
|
|
|
169
169
|
|
|
170
170
|
img_sizes = defaultdict(tuple)
|
|
171
171
|
|
|
172
|
-
def get_img_size_by_id(image_id) -> tuple:
|
|
172
|
+
def get_img_size_by_id(image_id, dataset: COCO) -> tuple:
|
|
173
173
|
if img_sizes.get(image_id) is None:
|
|
174
|
-
t =
|
|
174
|
+
t = dataset.imgs[image_id]
|
|
175
175
|
img_sizes[image_id] = t["height"], t["width"]
|
|
176
176
|
return img_sizes[image_id]
|
|
177
177
|
|
|
178
178
|
for gt in gts:
|
|
179
179
|
if p.compute_rle:
|
|
180
|
-
get_img_size_by_id(gt["image_id"])
|
|
180
|
+
get_img_size_by_id(gt["image_id"], self.cocoGt)
|
|
181
181
|
|
|
182
182
|
maskUtils.calculateRleForAllAnnotations(
|
|
183
183
|
gts,
|
|
@@ -206,7 +206,7 @@ class COCOeval:
|
|
|
206
206
|
)
|
|
207
207
|
|
|
208
208
|
if p.compute_rle:
|
|
209
|
-
get_img_size_by_id(dt["image_id"])
|
|
209
|
+
get_img_size_by_id(dt["image_id"], self.cocoDt)
|
|
210
210
|
|
|
211
211
|
maskUtils.calculateRleForAllAnnotations(
|
|
212
212
|
dts,
|
|
@@ -116,7 +116,7 @@ def calculateRleForAllAnnotations(
|
|
|
116
116
|
boundary_cpu_count (int): number of CPUs to use for boundary computation
|
|
117
117
|
|
|
118
118
|
"""
|
|
119
|
-
|
|
119
|
+
_mask.calculateRleForAllAnnotations(
|
|
120
120
|
anns,
|
|
121
121
|
img_sizes,
|
|
122
122
|
compute_rle,
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
__version__ = "1.6.
|
|
1
|
+
__version__ = "1.6.2"
|
|
2
2
|
__author__ = "MiXaiLL76"
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/python3
|
|
2
2
|
|
|
3
3
|
import glob
|
|
4
|
+
import os
|
|
4
5
|
|
|
5
6
|
import setuptools
|
|
6
7
|
from pybind11.setup_helpers import ParallelCompile, Pybind11Extension, build_ext
|
|
@@ -107,13 +108,19 @@ def get_extensions(version_info):
|
|
|
107
108
|
]
|
|
108
109
|
print("Sources: {}".format(sources))
|
|
109
110
|
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
111
|
+
if os.name == "nt":
|
|
112
|
+
extra_compile_args = [
|
|
113
|
+
"/std:c++17",
|
|
114
|
+
"/fp:fast",
|
|
115
|
+
]
|
|
116
|
+
else:
|
|
117
|
+
extra_compile_args = [
|
|
118
|
+
"-std=c++17",
|
|
119
|
+
"-fPIC",
|
|
120
|
+
"-ffinite-math-only",
|
|
121
|
+
"-fno-signed-zeros",
|
|
122
|
+
"-ftree-vectorize",
|
|
123
|
+
]
|
|
117
124
|
|
|
118
125
|
ext_modules += [
|
|
119
126
|
Pybind11Extension(
|
|
@@ -6,8 +6,13 @@ from unittest import TestCase
|
|
|
6
6
|
|
|
7
7
|
import numpy as np
|
|
8
8
|
from parameterized import parameterized
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
|
|
10
|
+
try:
|
|
11
|
+
from pycocotools.coco import COCO as origCOCO
|
|
12
|
+
from pycocotools.cocoeval import COCOeval as origCOCOeval
|
|
13
|
+
except ImportError:
|
|
14
|
+
origCOCO = None
|
|
15
|
+
origCOCOeval = None
|
|
11
16
|
|
|
12
17
|
import faster_coco_eval.core.mask as mask_util
|
|
13
18
|
from faster_coco_eval import COCO, COCOeval_faster
|
|
@@ -136,6 +141,9 @@ class TestCocoMetric(TestCase):
|
|
|
136
141
|
|
|
137
142
|
@parameterized.expand([(COCO, COCOeval_faster), (origCOCO, origCOCOeval)])
|
|
138
143
|
def test_evaluate(self, coco_cls, cocoeval_cls):
|
|
144
|
+
if coco_cls is None:
|
|
145
|
+
raise unittest.SkipTest("Skipping pycocotools test.")
|
|
146
|
+
|
|
139
147
|
# create dummy data
|
|
140
148
|
fake_json_file = osp.join(self.tmp_dir.name, "fake_data.json")
|
|
141
149
|
self._create_dummy_coco_json(fake_json_file)
|
|
@@ -190,6 +198,9 @@ class TestCocoMetric(TestCase):
|
|
|
190
198
|
|
|
191
199
|
@parameterized.expand([(COCO, COCOeval_faster), (origCOCO, origCOCOeval)])
|
|
192
200
|
def test_detectron2_eval(self, coco_cls, cocoeval_cls):
|
|
201
|
+
if coco_cls is None:
|
|
202
|
+
raise unittest.SkipTest("Skipping pycocotools test.")
|
|
203
|
+
|
|
193
204
|
# https://github.com/facebookresearch/detectron2/blob/main/tests/data/test_coco_evaluation.py
|
|
194
205
|
# A small set of images/categories from COCO val
|
|
195
206
|
# fmt: off
|
|
@@ -3,8 +3,13 @@ import unittest
|
|
|
3
3
|
from unittest import TestCase
|
|
4
4
|
|
|
5
5
|
from parameterized import parameterized
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
|
|
7
|
+
try:
|
|
8
|
+
from pycocotools.coco import COCO as origCOCO
|
|
9
|
+
from pycocotools.cocoeval import COCOeval as origCOCOeval
|
|
10
|
+
except ImportError:
|
|
11
|
+
origCOCO = None
|
|
12
|
+
origCOCOeval = None
|
|
8
13
|
|
|
9
14
|
from faster_coco_eval import COCO, COCOeval_faster
|
|
10
15
|
|
|
@@ -32,6 +37,9 @@ class TestKeypointsMetric(TestCase):
|
|
|
32
37
|
|
|
33
38
|
@parameterized.expand([(COCO, COCOeval_faster), (origCOCO, origCOCOeval)])
|
|
34
39
|
def test_evaluate(self, coco_cls, cocoeval_cls):
|
|
40
|
+
if coco_cls is None:
|
|
41
|
+
raise unittest.SkipTest("Skipping pycocotools test.")
|
|
42
|
+
|
|
35
43
|
cocoGt = coco_cls(self.gt_file)
|
|
36
44
|
cocoGt.info()
|
|
37
45
|
|
|
@@ -0,0 +1,305 @@
|
|
|
1
|
+
import unittest
|
|
2
|
+
from copy import deepcopy
|
|
3
|
+
from unittest import TestCase
|
|
4
|
+
|
|
5
|
+
from parameterized import parameterized
|
|
6
|
+
|
|
7
|
+
try:
|
|
8
|
+
import torch
|
|
9
|
+
from lightning_utilities import apply_to_collection
|
|
10
|
+
from torch import BoolTensor, IntTensor, Tensor
|
|
11
|
+
from torchmetrics.detection.mean_ap import MeanAveragePrecision
|
|
12
|
+
except ImportError:
|
|
13
|
+
raise unittest.SkipTest("Skipping all tests for torchmetrics.")
|
|
14
|
+
|
|
15
|
+
# fmt: off
|
|
16
|
+
_inputs = {
|
|
17
|
+
"preds": [
|
|
18
|
+
[
|
|
19
|
+
{
|
|
20
|
+
"boxes": Tensor([[258.15, 41.29, 606.41, 285.07]]),
|
|
21
|
+
"scores": Tensor([0.236]),
|
|
22
|
+
"labels": IntTensor([4]),
|
|
23
|
+
}, # coco image id 42
|
|
24
|
+
{
|
|
25
|
+
"boxes": Tensor([
|
|
26
|
+
[61.00, 22.75, 565.00, 632.42],
|
|
27
|
+
[12.66, 3.32, 281.26, 275.23]]),
|
|
28
|
+
"scores": Tensor([0.318, 0.726]),
|
|
29
|
+
"labels": IntTensor([3, 2]),
|
|
30
|
+
}, # coco image id 73
|
|
31
|
+
],
|
|
32
|
+
[
|
|
33
|
+
{
|
|
34
|
+
"boxes": Tensor([
|
|
35
|
+
[87.87, 276.25, 384.29, 379.43],
|
|
36
|
+
[0.00, 3.66, 142.15, 316.06],
|
|
37
|
+
[296.55, 93.96, 314.97, 152.79],
|
|
38
|
+
[328.94, 97.05, 342.49, 122.98],
|
|
39
|
+
[356.62, 95.47, 372.33, 147.55],
|
|
40
|
+
[464.08, 105.09, 495.74, 146.99],
|
|
41
|
+
[276.11, 103.84, 291.44, 150.72],
|
|
42
|
+
]),
|
|
43
|
+
"scores": Tensor([0.546, 0.3, 0.407,
|
|
44
|
+
0.611, 0.335, 0.805, 0.953]),
|
|
45
|
+
"labels": IntTensor([4, 1, 0, 0, 0, 0, 0]),
|
|
46
|
+
}, # coco image id 74
|
|
47
|
+
{
|
|
48
|
+
"boxes": Tensor([
|
|
49
|
+
[72.92, 45.96, 91.23, 80.57],
|
|
50
|
+
[45.17, 45.34, 66.28, 79.83],
|
|
51
|
+
[82.28, 47.04, 99.66, 78.50],
|
|
52
|
+
[59.96, 46.17, 80.35, 80.48],
|
|
53
|
+
[75.29, 23.01, 91.85, 50.85],
|
|
54
|
+
[71.14, 1.10, 96.96, 28.33],
|
|
55
|
+
[61.34, 55.23, 77.14, 79.57],
|
|
56
|
+
[41.17, 45.78, 60.99, 78.48],
|
|
57
|
+
[56.18, 44.80, 64.42, 56.25],
|
|
58
|
+
]),
|
|
59
|
+
"scores": Tensor([
|
|
60
|
+
0.532,
|
|
61
|
+
0.204,
|
|
62
|
+
0.782,
|
|
63
|
+
0.202,
|
|
64
|
+
0.883,
|
|
65
|
+
0.271,
|
|
66
|
+
0.561,
|
|
67
|
+
0.204 + 1e-8, # There are some problems with sorting at the moment. When sorting score with the same values, they give different indexes. # noqa: E501
|
|
68
|
+
0.349
|
|
69
|
+
]),
|
|
70
|
+
"labels": IntTensor([
|
|
71
|
+
49,
|
|
72
|
+
49,
|
|
73
|
+
49,
|
|
74
|
+
49,
|
|
75
|
+
49,
|
|
76
|
+
49,
|
|
77
|
+
49,
|
|
78
|
+
49,
|
|
79
|
+
49
|
|
80
|
+
]),
|
|
81
|
+
}, # coco image id 987 category_id 49
|
|
82
|
+
],
|
|
83
|
+
],
|
|
84
|
+
"target": [
|
|
85
|
+
[
|
|
86
|
+
{
|
|
87
|
+
"boxes": Tensor([[214.1500, 41.2900, 562.4100, 285.0700]]),
|
|
88
|
+
"labels": IntTensor([4]),
|
|
89
|
+
}, # coco image id 42
|
|
90
|
+
{
|
|
91
|
+
"boxes": Tensor([
|
|
92
|
+
[13.00, 22.75, 548.98, 632.42],
|
|
93
|
+
[1.66, 3.32, 270.26, 275.23],
|
|
94
|
+
]),
|
|
95
|
+
"labels": IntTensor([2, 2]),
|
|
96
|
+
}, # coco image id 73
|
|
97
|
+
],
|
|
98
|
+
[
|
|
99
|
+
{
|
|
100
|
+
"boxes": Tensor([
|
|
101
|
+
[61.87, 276.25, 358.29, 379.43],
|
|
102
|
+
[2.75, 3.66, 162.15, 316.06],
|
|
103
|
+
[295.55, 93.96, 313.97, 152.79],
|
|
104
|
+
[326.94, 97.05, 340.49, 122.98],
|
|
105
|
+
[356.62, 95.47, 372.33, 147.55],
|
|
106
|
+
[462.08, 105.09, 493.74, 146.99],
|
|
107
|
+
[277.11, 103.84, 292.44, 150.72],
|
|
108
|
+
]),
|
|
109
|
+
"labels": IntTensor([4, 1, 0, 0, 0, 0, 0]),
|
|
110
|
+
}, # coco image id 74
|
|
111
|
+
{
|
|
112
|
+
"boxes": Tensor([
|
|
113
|
+
[72.92, 45.96, 91.23, 80.57],
|
|
114
|
+
[50.17, 45.34, 71.28, 79.83],
|
|
115
|
+
[81.28, 47.04, 98.66, 78.50],
|
|
116
|
+
[63.96, 46.17, 84.35, 80.48],
|
|
117
|
+
[75.29, 23.01, 91.85, 50.85],
|
|
118
|
+
[56.39, 21.65, 75.66, 45.54],
|
|
119
|
+
[73.14, 1.10, 98.96, 28.33],
|
|
120
|
+
[62.34, 55.23, 78.14, 79.57],
|
|
121
|
+
[44.17, 45.78, 63.99, 78.48],
|
|
122
|
+
[58.18, 44.80, 66.42, 56.25],
|
|
123
|
+
]),
|
|
124
|
+
"labels": IntTensor([
|
|
125
|
+
49,
|
|
126
|
+
49,
|
|
127
|
+
49,
|
|
128
|
+
49,
|
|
129
|
+
49,
|
|
130
|
+
49,
|
|
131
|
+
49,
|
|
132
|
+
49,
|
|
133
|
+
49,
|
|
134
|
+
49
|
|
135
|
+
]),
|
|
136
|
+
}, # coco image id 987 category_id 49
|
|
137
|
+
],
|
|
138
|
+
],
|
|
139
|
+
}
|
|
140
|
+
# fmt: on
|
|
141
|
+
|
|
142
|
+
|
|
143
|
+
class TestTorchmetricsLib(TestCase):
|
|
144
|
+
def setUp(self):
|
|
145
|
+
# Preds should be a list of elements, where each element is a dict
|
|
146
|
+
# containing 3 keys: boxes, scores, labels
|
|
147
|
+
mask_pred = [
|
|
148
|
+
[0, 0, 0, 0, 0],
|
|
149
|
+
[0, 0, 1, 1, 0],
|
|
150
|
+
[0, 0, 1, 1, 0],
|
|
151
|
+
[0, 0, 0, 0, 0],
|
|
152
|
+
[0, 0, 0, 0, 0],
|
|
153
|
+
]
|
|
154
|
+
self.preds = [
|
|
155
|
+
{
|
|
156
|
+
# The boxes keyword should contain an [N,4] tensor,
|
|
157
|
+
# where N is the number of detected \
|
|
158
|
+
# boxes with boxes of the format
|
|
159
|
+
# [xmin, ymin, xmax, ymax] in absolute \
|
|
160
|
+
# image coordinates
|
|
161
|
+
"boxes": Tensor([[258.0, 41.0, 606.0, 285.0]]),
|
|
162
|
+
# The scores keyword should contain an [N,] \
|
|
163
|
+
# tensor where
|
|
164
|
+
# each element is confidence score between 0 and 1
|
|
165
|
+
"scores": Tensor([0.536]),
|
|
166
|
+
# The labels keyword should contain an [N,] tensor
|
|
167
|
+
# with integers of the predicted classes
|
|
168
|
+
"labels": IntTensor([0]),
|
|
169
|
+
# The masks keyword should contain an [N,H,W] tensor,
|
|
170
|
+
# where H and W are the image height and width, \
|
|
171
|
+
# respectively,
|
|
172
|
+
# with boolean masks. This is only required \
|
|
173
|
+
# when iou_type is `segm`.
|
|
174
|
+
"masks": BoolTensor([mask_pred]),
|
|
175
|
+
}
|
|
176
|
+
]
|
|
177
|
+
|
|
178
|
+
# Target should be a list of elements, where each element is a dict
|
|
179
|
+
# containing 2 keys: boxes and labels \
|
|
180
|
+
# (and masks, if iou_type is `segm`).
|
|
181
|
+
# Each keyword should be formatted similar to the preds argument.
|
|
182
|
+
# The number of elements in preds and target need to match
|
|
183
|
+
mask_tgt = [
|
|
184
|
+
[0, 0, 0, 0, 0],
|
|
185
|
+
[0, 0, 1, 0, 0],
|
|
186
|
+
[0, 0, 1, 1, 0],
|
|
187
|
+
[0, 0, 1, 0, 0],
|
|
188
|
+
[0, 0, 0, 0, 0],
|
|
189
|
+
]
|
|
190
|
+
self.target = [
|
|
191
|
+
{
|
|
192
|
+
"boxes": Tensor([[214.0, 41.0, 562.0, 285.0]]),
|
|
193
|
+
"labels": IntTensor([0]),
|
|
194
|
+
"masks": BoolTensor([mask_tgt]),
|
|
195
|
+
}
|
|
196
|
+
]
|
|
197
|
+
|
|
198
|
+
self.valid_result = {
|
|
199
|
+
"map": torch.tensor(0.6000),
|
|
200
|
+
"map_50": torch.tensor(1.0),
|
|
201
|
+
"map_75": torch.tensor(1.0),
|
|
202
|
+
"map_small": torch.tensor(-1.0),
|
|
203
|
+
"map_medium": torch.tensor(-1.0),
|
|
204
|
+
"map_large": torch.tensor(0.6000),
|
|
205
|
+
"mar_1": torch.tensor(0.6000),
|
|
206
|
+
"mar_10": torch.tensor(0.6000),
|
|
207
|
+
"mar_100": torch.tensor(0.6000),
|
|
208
|
+
"mar_small": torch.tensor(-1.0),
|
|
209
|
+
"mar_medium": torch.tensor(-1.0),
|
|
210
|
+
"mar_large": torch.tensor(0.6000),
|
|
211
|
+
"map_per_class": torch.tensor(-1.0),
|
|
212
|
+
"mar_100_per_class": torch.tensor(-1.0),
|
|
213
|
+
"classes": torch.tensor(0, dtype=torch.int32),
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
def test_evaluate(self):
|
|
217
|
+
# Initialize metric
|
|
218
|
+
metric = MeanAveragePrecision(
|
|
219
|
+
iou_type="bbox", backend="faster_coco_eval"
|
|
220
|
+
)
|
|
221
|
+
|
|
222
|
+
# Update metric with predictions and respective ground truth
|
|
223
|
+
metric.update(self.preds, self.target)
|
|
224
|
+
|
|
225
|
+
self.assertEqual(metric.backend, "faster_coco_eval")
|
|
226
|
+
|
|
227
|
+
# Compute the results
|
|
228
|
+
result = metric.compute()
|
|
229
|
+
|
|
230
|
+
self.assertDictEqual(result, self.valid_result)
|
|
231
|
+
|
|
232
|
+
def test_segm_iou_empty_gt_mask(self):
|
|
233
|
+
"""Test empty ground truths."""
|
|
234
|
+
backend = "faster_coco_eval"
|
|
235
|
+
metric = MeanAveragePrecision(iou_type="segm", backend=backend)
|
|
236
|
+
metric.update(
|
|
237
|
+
[
|
|
238
|
+
{
|
|
239
|
+
"masks": torch.randint(0, 1, (1, 10, 10)).bool(),
|
|
240
|
+
"scores": Tensor([0.5]),
|
|
241
|
+
"labels": IntTensor([4]),
|
|
242
|
+
}
|
|
243
|
+
],
|
|
244
|
+
[{"masks": Tensor([]), "labels": IntTensor([])}],
|
|
245
|
+
)
|
|
246
|
+
metric.compute()
|
|
247
|
+
|
|
248
|
+
@parameterized.expand([False, True])
|
|
249
|
+
def test_average_argument(self, class_metrics):
|
|
250
|
+
"""Test that average argument works.
|
|
251
|
+
|
|
252
|
+
Calculating macro on inputs that only have one label should be
|
|
253
|
+
the same as micro. Calculating class metrics should be the same
|
|
254
|
+
regardless of average argument.
|
|
255
|
+
|
|
256
|
+
"""
|
|
257
|
+
backend = "pycocotools"
|
|
258
|
+
backend = "faster_coco_eval"
|
|
259
|
+
|
|
260
|
+
if class_metrics:
|
|
261
|
+
_preds = _inputs["preds"]
|
|
262
|
+
_target = _inputs["target"]
|
|
263
|
+
else:
|
|
264
|
+
_preds = apply_to_collection(
|
|
265
|
+
deepcopy(_inputs["preds"]),
|
|
266
|
+
IntTensor,
|
|
267
|
+
lambda x: torch.ones_like(x),
|
|
268
|
+
)
|
|
269
|
+
_target = apply_to_collection(
|
|
270
|
+
deepcopy(_inputs["target"]),
|
|
271
|
+
IntTensor,
|
|
272
|
+
lambda x: torch.ones_like(x),
|
|
273
|
+
)
|
|
274
|
+
|
|
275
|
+
metric_macro = MeanAveragePrecision(
|
|
276
|
+
average="macro", class_metrics=class_metrics, backend=backend
|
|
277
|
+
)
|
|
278
|
+
metric_macro.update(_preds[0], _target[0])
|
|
279
|
+
metric_macro.update(_preds[1], _target[1])
|
|
280
|
+
result_macro = metric_macro.compute()
|
|
281
|
+
|
|
282
|
+
metric_micro = MeanAveragePrecision(
|
|
283
|
+
average="micro", class_metrics=class_metrics, backend=backend
|
|
284
|
+
)
|
|
285
|
+
metric_micro.update(_inputs["preds"][0], _inputs["target"][0])
|
|
286
|
+
metric_micro.update(_inputs["preds"][1], _inputs["target"][1])
|
|
287
|
+
result_micro = metric_micro.compute()
|
|
288
|
+
|
|
289
|
+
if class_metrics:
|
|
290
|
+
assert torch.allclose(
|
|
291
|
+
result_macro["map_per_class"], result_micro["map_per_class"]
|
|
292
|
+
)
|
|
293
|
+
assert torch.allclose(
|
|
294
|
+
result_macro["mar_100_per_class"],
|
|
295
|
+
result_micro["mar_100_per_class"],
|
|
296
|
+
)
|
|
297
|
+
else:
|
|
298
|
+
for key in result_macro:
|
|
299
|
+
if key == "classes":
|
|
300
|
+
continue
|
|
301
|
+
assert torch.allclose(result_macro[key], result_micro[key])
|
|
302
|
+
|
|
303
|
+
|
|
304
|
+
if __name__ == "__main__":
|
|
305
|
+
unittest.main()
|
|
@@ -1,103 +0,0 @@
|
|
|
1
|
-
import unittest
|
|
2
|
-
from unittest import TestCase
|
|
3
|
-
|
|
4
|
-
try:
|
|
5
|
-
import torch
|
|
6
|
-
from torch import BoolTensor, IntTensor, Tensor
|
|
7
|
-
from torchmetrics.detection.mean_ap import MeanAveragePrecision
|
|
8
|
-
except ImportError:
|
|
9
|
-
raise unittest.SkipTest("Skipping all tests for torchmetrics.")
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
class TestTorchmetricsLib(TestCase):
|
|
13
|
-
def setUp(self):
|
|
14
|
-
# Preds should be a list of elements, where each element is a dict
|
|
15
|
-
# containing 3 keys: boxes, scores, labels
|
|
16
|
-
mask_pred = [
|
|
17
|
-
[0, 0, 0, 0, 0],
|
|
18
|
-
[0, 0, 1, 1, 0],
|
|
19
|
-
[0, 0, 1, 1, 0],
|
|
20
|
-
[0, 0, 0, 0, 0],
|
|
21
|
-
[0, 0, 0, 0, 0],
|
|
22
|
-
]
|
|
23
|
-
self.preds = [
|
|
24
|
-
{
|
|
25
|
-
# The boxes keyword should contain an [N,4] tensor,
|
|
26
|
-
# where N is the number of detected \
|
|
27
|
-
# boxes with boxes of the format
|
|
28
|
-
# [xmin, ymin, xmax, ymax] in absolute \
|
|
29
|
-
# image coordinates
|
|
30
|
-
"boxes": Tensor([[258.0, 41.0, 606.0, 285.0]]),
|
|
31
|
-
# The scores keyword should contain an [N,] \
|
|
32
|
-
# tensor where
|
|
33
|
-
# each element is confidence score between 0 and 1
|
|
34
|
-
"scores": Tensor([0.536]),
|
|
35
|
-
# The labels keyword should contain an [N,] tensor
|
|
36
|
-
# with integers of the predicted classes
|
|
37
|
-
"labels": IntTensor([0]),
|
|
38
|
-
# The masks keyword should contain an [N,H,W] tensor,
|
|
39
|
-
# where H and W are the image height and width, \
|
|
40
|
-
# respectively,
|
|
41
|
-
# with boolean masks. This is only required \
|
|
42
|
-
# when iou_type is `segm`.
|
|
43
|
-
"masks": BoolTensor([mask_pred]),
|
|
44
|
-
}
|
|
45
|
-
]
|
|
46
|
-
|
|
47
|
-
# Target should be a list of elements, where each element is a dict
|
|
48
|
-
# containing 2 keys: boxes and labels \
|
|
49
|
-
# (and masks, if iou_type is `segm`).
|
|
50
|
-
# Each keyword should be formatted similar to the preds argument.
|
|
51
|
-
# The number of elements in preds and target need to match
|
|
52
|
-
mask_tgt = [
|
|
53
|
-
[0, 0, 0, 0, 0],
|
|
54
|
-
[0, 0, 1, 0, 0],
|
|
55
|
-
[0, 0, 1, 1, 0],
|
|
56
|
-
[0, 0, 1, 0, 0],
|
|
57
|
-
[0, 0, 0, 0, 0],
|
|
58
|
-
]
|
|
59
|
-
self.target = [
|
|
60
|
-
{
|
|
61
|
-
"boxes": Tensor([[214.0, 41.0, 562.0, 285.0]]),
|
|
62
|
-
"labels": IntTensor([0]),
|
|
63
|
-
"masks": BoolTensor([mask_tgt]),
|
|
64
|
-
}
|
|
65
|
-
]
|
|
66
|
-
|
|
67
|
-
self.valid_result = {
|
|
68
|
-
"map": torch.tensor(0.6000),
|
|
69
|
-
"map_50": torch.tensor(1.0),
|
|
70
|
-
"map_75": torch.tensor(1.0),
|
|
71
|
-
"map_small": torch.tensor(-1.0),
|
|
72
|
-
"map_medium": torch.tensor(-1.0),
|
|
73
|
-
"map_large": torch.tensor(0.6000),
|
|
74
|
-
"mar_1": torch.tensor(0.6000),
|
|
75
|
-
"mar_10": torch.tensor(0.6000),
|
|
76
|
-
"mar_100": torch.tensor(0.6000),
|
|
77
|
-
"mar_small": torch.tensor(-1.0),
|
|
78
|
-
"mar_medium": torch.tensor(-1.0),
|
|
79
|
-
"mar_large": torch.tensor(0.6000),
|
|
80
|
-
"map_per_class": torch.tensor(-1.0),
|
|
81
|
-
"mar_100_per_class": torch.tensor(-1.0),
|
|
82
|
-
"classes": torch.tensor(0, dtype=torch.int32),
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
def test_evaluate(self):
|
|
86
|
-
# Initialize metric
|
|
87
|
-
metric = MeanAveragePrecision(
|
|
88
|
-
iou_type="bbox", backend="faster_coco_eval"
|
|
89
|
-
)
|
|
90
|
-
|
|
91
|
-
# Update metric with predictions and respective ground truth
|
|
92
|
-
metric.update(self.preds, self.target)
|
|
93
|
-
|
|
94
|
-
self.assertEqual(metric.backend, "faster_coco_eval")
|
|
95
|
-
|
|
96
|
-
# Compute the results
|
|
97
|
-
result = metric.compute()
|
|
98
|
-
|
|
99
|
-
self.assertDictEqual(result, self.valid_result)
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
if __name__ == "__main__":
|
|
103
|
-
unittest.main()
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{faster_coco_eval-1.6.0 → faster_coco_eval-1.6.2}/faster_coco_eval.egg-info/dependency_links.txt
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|