faster-coco-eval 1.7.0__tar.gz → 1.7.1__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.7.0/faster_coco_eval.egg-info → faster_coco_eval-1.7.1}/PKG-INFO +1 -1
- {faster_coco_eval-1.7.0 → faster_coco_eval-1.7.1}/csrc/faster_eval_api/coco_eval/cocoeval.cpp +50 -50
- {faster_coco_eval-1.7.0 → faster_coco_eval-1.7.1}/csrc/faster_eval_api/coco_eval/cocoeval.h +14 -14
- {faster_coco_eval-1.7.0 → faster_coco_eval-1.7.1}/csrc/faster_eval_api/coco_eval/dataset.cpp +17 -17
- {faster_coco_eval-1.7.0 → faster_coco_eval-1.7.1}/csrc/faster_eval_api/coco_eval/dataset.h +9 -9
- {faster_coco_eval-1.7.0 → faster_coco_eval-1.7.1}/csrc/faster_eval_api/faster_eval_api.cpp +5 -5
- {faster_coco_eval-1.7.0 → faster_coco_eval-1.7.1}/csrc/mask_api/mask_api.cpp +3 -3
- {faster_coco_eval-1.7.0 → faster_coco_eval-1.7.1}/csrc/mask_api/src/mask.cpp +63 -63
- {faster_coco_eval-1.7.0 → faster_coco_eval-1.7.1}/csrc/mask_api/src/mask.h +55 -55
- {faster_coco_eval-1.7.0 → faster_coco_eval-1.7.1}/csrc/mask_api/src/rle.cpp +9 -9
- {faster_coco_eval-1.7.0 → faster_coco_eval-1.7.1}/faster_coco_eval/core/coco.py +5 -5
- {faster_coco_eval-1.7.0 → faster_coco_eval-1.7.1}/faster_coco_eval/core/faster_eval_api.py +1 -1
- {faster_coco_eval-1.7.0 → faster_coco_eval-1.7.1}/faster_coco_eval/version.py +1 -1
- {faster_coco_eval-1.7.0 → faster_coco_eval-1.7.1/faster_coco_eval.egg-info}/PKG-INFO +1 -1
- {faster_coco_eval-1.7.0 → faster_coco_eval-1.7.1}/tests/test_dataset.py +1 -2
- {faster_coco_eval-1.7.0 → faster_coco_eval-1.7.1}/LICENSE +0 -0
- {faster_coco_eval-1.7.0 → faster_coco_eval-1.7.1}/MANIFEST.in +0 -0
- {faster_coco_eval-1.7.0 → faster_coco_eval-1.7.1}/README.md +0 -0
- {faster_coco_eval-1.7.0 → faster_coco_eval-1.7.1}/csrc/faster_eval_api/coco_eval/types.h +0 -0
- {faster_coco_eval-1.7.0 → faster_coco_eval-1.7.1}/faster_coco_eval/__init__.py +0 -0
- {faster_coco_eval-1.7.0 → faster_coco_eval-1.7.1}/faster_coco_eval/core/__init__.py +0 -0
- {faster_coco_eval-1.7.0 → faster_coco_eval-1.7.1}/faster_coco_eval/core/cocoeval.py +0 -0
- {faster_coco_eval-1.7.0 → faster_coco_eval-1.7.1}/faster_coco_eval/core/mask.py +0 -0
- {faster_coco_eval-1.7.0 → faster_coco_eval-1.7.1}/faster_coco_eval/extra/__init__.py +0 -0
- {faster_coco_eval-1.7.0 → faster_coco_eval-1.7.1}/faster_coco_eval/extra/curves.py +0 -0
- {faster_coco_eval-1.7.0 → faster_coco_eval-1.7.1}/faster_coco_eval/extra/display.py +0 -0
- {faster_coco_eval-1.7.0 → faster_coco_eval-1.7.1}/faster_coco_eval/extra/draw.py +0 -0
- {faster_coco_eval-1.7.0 → faster_coco_eval-1.7.1}/faster_coco_eval/extra/extra.py +0 -0
- {faster_coco_eval-1.7.0 → faster_coco_eval-1.7.1}/faster_coco_eval/extra/utils.py +0 -0
- {faster_coco_eval-1.7.0 → faster_coco_eval-1.7.1}/faster_coco_eval/utils/__init__.py +0 -0
- {faster_coco_eval-1.7.0 → faster_coco_eval-1.7.1}/faster_coco_eval/utils/pytorch/__init__.py +0 -0
- {faster_coco_eval-1.7.0 → faster_coco_eval-1.7.1}/faster_coco_eval/utils/pytorch/coco_dataset.py +0 -0
- {faster_coco_eval-1.7.0 → faster_coco_eval-1.7.1}/faster_coco_eval/utils/pytorch/coco_eval.py +0 -0
- {faster_coco_eval-1.7.0 → faster_coco_eval-1.7.1}/faster_coco_eval.egg-info/SOURCES.txt +0 -0
- {faster_coco_eval-1.7.0 → faster_coco_eval-1.7.1}/faster_coco_eval.egg-info/dependency_links.txt +0 -0
- {faster_coco_eval-1.7.0 → faster_coco_eval-1.7.1}/faster_coco_eval.egg-info/requires.txt +0 -0
- {faster_coco_eval-1.7.0 → faster_coco_eval-1.7.1}/faster_coco_eval.egg-info/top_level.txt +0 -0
- {faster_coco_eval-1.7.0 → faster_coco_eval-1.7.1}/pyproject.toml +0 -0
- {faster_coco_eval-1.7.0 → faster_coco_eval-1.7.1}/requirements/docs.txt +0 -0
- {faster_coco_eval-1.7.0 → faster_coco_eval-1.7.1}/requirements/extra.txt +0 -0
- {faster_coco_eval-1.7.0 → faster_coco_eval-1.7.1}/requirements/runtime.txt +0 -0
- {faster_coco_eval-1.7.0 → faster_coco_eval-1.7.1}/requirements/tests.txt +0 -0
- {faster_coco_eval-1.7.0 → faster_coco_eval-1.7.1}/setup.cfg +0 -0
- {faster_coco_eval-1.7.0 → faster_coco_eval-1.7.1}/setup.py +0 -0
- {faster_coco_eval-1.7.0 → faster_coco_eval-1.7.1}/tests/test_basic.py +0 -0
- {faster_coco_eval-1.7.0 → faster_coco_eval-1.7.1}/tests/test_boundary.py +0 -0
- {faster_coco_eval-1.7.0 → faster_coco_eval-1.7.1}/tests/test_coco_metric.py +0 -0
- {faster_coco_eval-1.7.0 → faster_coco_eval-1.7.1}/tests/test_cocoapi_fake_data.py +0 -0
- {faster_coco_eval-1.7.0 → faster_coco_eval-1.7.1}/tests/test_crowdpose.py +0 -0
- {faster_coco_eval-1.7.0 → faster_coco_eval-1.7.1}/tests/test_extra_draw.py +0 -0
- {faster_coco_eval-1.7.0 → faster_coco_eval-1.7.1}/tests/test_extra_utils.py +0 -0
- {faster_coco_eval-1.7.0 → faster_coco_eval-1.7.1}/tests/test_init_pycocotools.py +0 -0
- {faster_coco_eval-1.7.0 → faster_coco_eval-1.7.1}/tests/test_keypoints.py +0 -0
- {faster_coco_eval-1.7.0 → faster_coco_eval-1.7.1}/tests/test_lvis_metric.py +0 -0
- {faster_coco_eval-1.7.0 → faster_coco_eval-1.7.1}/tests/test_mask_api.py +1 -1
- {faster_coco_eval-1.7.0 → faster_coco_eval-1.7.1}/tests/test_ranges.py +0 -0
- {faster_coco_eval-1.7.0 → faster_coco_eval-1.7.1}/tests/test_simple_extra.py +0 -0
- {faster_coco_eval-1.7.0 → faster_coco_eval-1.7.1}/tests/test_torchmetrics.py +0 -0
- {faster_coco_eval-1.7.0 → faster_coco_eval-1.7.1}/tests/test_world_evalutor.py +0 -0
{faster_coco_eval-1.7.0 → faster_coco_eval-1.7.1}/csrc/faster_eval_api/coco_eval/cocoeval.cpp
RENAMED
|
@@ -14,7 +14,7 @@ namespace coco_eval {
|
|
|
14
14
|
|
|
15
15
|
namespace COCOeval {
|
|
16
16
|
template <typename T>
|
|
17
|
-
int64_t v_index(const std::vector<T
|
|
17
|
+
int64_t v_index(const std::vector<T>& v, const T& key) {
|
|
18
18
|
auto itr = std::find(v.begin(), v.end(), key);
|
|
19
19
|
|
|
20
20
|
if (itr != v.cend()) {
|
|
@@ -29,8 +29,8 @@ int64_t v_index(const std::vector<T> &v, const T &key) {
|
|
|
29
29
|
// detection_instances[detection_sorted_indices[t+1]]. Use stable_sort to match
|
|
30
30
|
// original COCO API
|
|
31
31
|
void SortInstancesByDetectionScore(
|
|
32
|
-
const std::vector<InstanceAnnotation
|
|
33
|
-
std::vector<uint64_t
|
|
32
|
+
const std::vector<InstanceAnnotation>& detection_instances,
|
|
33
|
+
std::vector<uint64_t>* detection_sorted_indices) {
|
|
34
34
|
detection_sorted_indices->resize(detection_instances.size());
|
|
35
35
|
std::iota(detection_sorted_indices->begin(),
|
|
36
36
|
detection_sorted_indices->end(), 0);
|
|
@@ -45,10 +45,10 @@ void SortInstancesByDetectionScore(
|
|
|
45
45
|
// Partition the ground truth objects based on whether or not to ignore them
|
|
46
46
|
// based on area
|
|
47
47
|
void SortInstancesByIgnore(
|
|
48
|
-
const std::array<double, 2
|
|
49
|
-
const std::vector<InstanceAnnotation
|
|
50
|
-
std::vector<uint64_t
|
|
51
|
-
std::vector<bool
|
|
48
|
+
const std::array<double, 2>& area_range,
|
|
49
|
+
const std::vector<InstanceAnnotation>& ground_truth_instances,
|
|
50
|
+
std::vector<uint64_t>* ground_truth_sorted_indices,
|
|
51
|
+
std::vector<bool>* ignores) {
|
|
52
52
|
ignores->clear();
|
|
53
53
|
ignores->reserve(ground_truth_instances.size());
|
|
54
54
|
for (auto o : ground_truth_instances) {
|
|
@@ -70,14 +70,14 @@ void SortInstancesByIgnore(
|
|
|
70
70
|
// For each IOU threshold, greedily match each detected instance to a ground
|
|
71
71
|
// truth instance (if possible) and store the results
|
|
72
72
|
void MatchDetectionsToGroundTruth(
|
|
73
|
-
const std::vector<InstanceAnnotation
|
|
74
|
-
const std::vector<uint64_t
|
|
75
|
-
const std::vector<InstanceAnnotation
|
|
76
|
-
const std::vector<uint64_t
|
|
77
|
-
const std::vector<bool
|
|
78
|
-
const std::vector<std::vector<double
|
|
79
|
-
const std::vector<double
|
|
80
|
-
const std::array<double, 2
|
|
73
|
+
const std::vector<InstanceAnnotation>& detection_instances,
|
|
74
|
+
const std::vector<uint64_t>& detection_sorted_indices,
|
|
75
|
+
const std::vector<InstanceAnnotation>& ground_truth_instances,
|
|
76
|
+
const std::vector<uint64_t>& ground_truth_sorted_indices,
|
|
77
|
+
const std::vector<bool>& ignores,
|
|
78
|
+
const std::vector<std::vector<double>>& ious,
|
|
79
|
+
const std::vector<double>& iou_thresholds,
|
|
80
|
+
const std::array<double, 2>& area_range, ImageEvaluation* results) {
|
|
81
81
|
// Initialize memory to store return data matches and ignore
|
|
82
82
|
const int num_iou_thresholds = (const int)iou_thresholds.size();
|
|
83
83
|
const int num_ground_truth =
|
|
@@ -85,14 +85,14 @@ void MatchDetectionsToGroundTruth(
|
|
|
85
85
|
const int num_detections = (const int)detection_sorted_indices.size();
|
|
86
86
|
// std::vector<uint64_t> ground_truth_matches(
|
|
87
87
|
// num_iou_thresholds * num_ground_truth, 0);
|
|
88
|
-
std::vector<int64_t
|
|
88
|
+
std::vector<int64_t>& ground_truth_matches =
|
|
89
89
|
results->ground_truth_matches;
|
|
90
90
|
ground_truth_matches.resize(num_iou_thresholds * num_ground_truth, 0);
|
|
91
91
|
|
|
92
|
-
std::vector<int64_t
|
|
92
|
+
std::vector<int64_t>& detection_matches = results->detection_matches;
|
|
93
93
|
|
|
94
|
-
std::vector<bool
|
|
95
|
-
std::vector<bool
|
|
94
|
+
std::vector<bool>& detection_ignores = results->detection_ignores;
|
|
95
|
+
std::vector<bool>& ground_truth_ignores = results->ground_truth_ignores;
|
|
96
96
|
detection_matches.resize(num_iou_thresholds * num_detections, 0);
|
|
97
97
|
detection_ignores.resize(num_iou_thresholds * num_detections, false);
|
|
98
98
|
ground_truth_ignores.resize(num_ground_truth);
|
|
@@ -166,7 +166,7 @@ void MatchDetectionsToGroundTruth(
|
|
|
166
166
|
|
|
167
167
|
// set unmatched detections outside of area range to
|
|
168
168
|
// ignore
|
|
169
|
-
const InstanceAnnotation
|
|
169
|
+
const InstanceAnnotation& detection =
|
|
170
170
|
detection_instances[detection_sorted_indices[d]];
|
|
171
171
|
detection_ignores[t * num_detections + d] =
|
|
172
172
|
detection_ignores[t * num_detections + d] ||
|
|
@@ -186,11 +186,11 @@ void MatchDetectionsToGroundTruth(
|
|
|
186
186
|
}
|
|
187
187
|
|
|
188
188
|
std::vector<ImageEvaluation> EvaluateImages(
|
|
189
|
-
const std::vector<std::array<double, 2
|
|
190
|
-
const std::vector<double
|
|
191
|
-
const ImageCategoryInstances<std::vector<double
|
|
192
|
-
const LightweightDataset
|
|
193
|
-
const std::vector<double
|
|
189
|
+
const std::vector<std::array<double, 2>>& area_ranges, int max_detections,
|
|
190
|
+
const std::vector<double>& iou_thresholds,
|
|
191
|
+
const ImageCategoryInstances<std::vector<double>>& image_category_ious,
|
|
192
|
+
const LightweightDataset& gt_dataset, const LightweightDataset& dt_dataset,
|
|
193
|
+
const std::vector<double>& img_ids, const std::vector<double>& cat_ids,
|
|
194
194
|
bool useCats) {
|
|
195
195
|
const int num_area_ranges = (const int)area_ranges.size();
|
|
196
196
|
const int num_images = (const int)img_ids.size();
|
|
@@ -298,7 +298,7 @@ std::vector<ImageEvaluation> EvaluateImages(
|
|
|
298
298
|
|
|
299
299
|
// Convert a python list to a vector
|
|
300
300
|
template <typename T>
|
|
301
|
-
std::vector<T> list_to_vec(const py::list
|
|
301
|
+
std::vector<T> list_to_vec(const py::list& l) {
|
|
302
302
|
std::vector<T> v(py::len(l));
|
|
303
303
|
for (int i = 0; i < (int)py::len(l); ++i) {
|
|
304
304
|
v[i] = l[i].cast<T>();
|
|
@@ -318,13 +318,13 @@ std::vector<T> list_to_vec(const py::list &l) {
|
|
|
318
318
|
// and is the image_detection_indices[i]'th of the list of detections
|
|
319
319
|
// for the image containing i. detection_sorted_indices[] defines a sorted
|
|
320
320
|
// permutation of the 3 other outputs
|
|
321
|
-
int BuildSortedDetectionList(const std::vector<ImageEvaluation
|
|
321
|
+
int BuildSortedDetectionList(const std::vector<ImageEvaluation>& evaluations,
|
|
322
322
|
const int64_t evaluation_index,
|
|
323
323
|
const int64_t num_images, const int max_detections,
|
|
324
|
-
std::vector<uint64_t
|
|
325
|
-
std::vector<double
|
|
326
|
-
std::vector<uint64_t
|
|
327
|
-
std::vector<uint64_t
|
|
324
|
+
std::vector<uint64_t>* evaluation_indices,
|
|
325
|
+
std::vector<double>* detection_scores,
|
|
326
|
+
std::vector<uint64_t>* detection_sorted_indices,
|
|
327
|
+
std::vector<uint64_t>* image_detection_indices) {
|
|
328
328
|
assert(evaluations.size() >= evaluation_index + num_images);
|
|
329
329
|
|
|
330
330
|
// Extract a list of object instances of the applicable category, area
|
|
@@ -337,7 +337,7 @@ int BuildSortedDetectionList(const std::vector<ImageEvaluation> &evaluations,
|
|
|
337
337
|
detection_scores->reserve(num_images * max_detections);
|
|
338
338
|
int num_valid_ground_truth = 0;
|
|
339
339
|
for (auto i = 0; i < num_images; ++i) {
|
|
340
|
-
const ImageEvaluation
|
|
340
|
+
const ImageEvaluation& evaluation =
|
|
341
341
|
evaluations[evaluation_index + i];
|
|
342
342
|
|
|
343
343
|
for (int d = 0; d < (int)evaluation.detection_scores.size() &&
|
|
@@ -382,16 +382,16 @@ int BuildSortedDetectionList(const std::vector<ImageEvaluation> &evaluations,
|
|
|
382
382
|
void ComputePrecisionRecallCurve(
|
|
383
383
|
const int64_t precisions_out_index, const int64_t precisions_out_stride,
|
|
384
384
|
const int64_t recalls_out_index,
|
|
385
|
-
const std::vector<double
|
|
385
|
+
const std::vector<double>& recall_thresholds, const int iou_threshold_index,
|
|
386
386
|
const int num_iou_thresholds, const int num_valid_ground_truth,
|
|
387
|
-
const std::vector<ImageEvaluation
|
|
388
|
-
const std::vector<uint64_t
|
|
389
|
-
const std::vector<double
|
|
390
|
-
const std::vector<uint64_t
|
|
391
|
-
const std::vector<uint64_t
|
|
392
|
-
std::vector<double
|
|
393
|
-
std::vector<double
|
|
394
|
-
std::vector<double
|
|
387
|
+
const std::vector<ImageEvaluation>& evaluations,
|
|
388
|
+
const std::vector<uint64_t>& evaluation_indices,
|
|
389
|
+
const std::vector<double>& detection_scores,
|
|
390
|
+
const std::vector<uint64_t>& detection_sorted_indices,
|
|
391
|
+
const std::vector<uint64_t>& image_detection_indices,
|
|
392
|
+
std::vector<double>* precisions, std::vector<double>* recalls,
|
|
393
|
+
std::vector<double>* precisions_out, std::vector<double>* scores_out,
|
|
394
|
+
std::vector<double>* recalls_out) {
|
|
395
395
|
assert(recalls_out->size() > recalls_out_index);
|
|
396
396
|
|
|
397
397
|
// Compute precision/recall for each instance in the sorted list of
|
|
@@ -403,7 +403,7 @@ void ComputePrecisionRecallCurve(
|
|
|
403
403
|
recalls->reserve(detection_sorted_indices.size());
|
|
404
404
|
assert(!evaluations.empty() || detection_sorted_indices.empty());
|
|
405
405
|
for (auto detection_sorted_index : detection_sorted_indices) {
|
|
406
|
-
const ImageEvaluation
|
|
406
|
+
const ImageEvaluation& evaluation =
|
|
407
407
|
evaluations[evaluation_indices[detection_sorted_index]];
|
|
408
408
|
const auto num_detections =
|
|
409
409
|
evaluation.detection_matches.size() / num_iou_thresholds;
|
|
@@ -473,8 +473,8 @@ void ComputePrecisionRecallCurve(
|
|
|
473
473
|
}
|
|
474
474
|
}
|
|
475
475
|
}
|
|
476
|
-
py::dict Accumulate(const py::object
|
|
477
|
-
const std::vector<ImageEvaluation
|
|
476
|
+
py::dict Accumulate(const py::object& params,
|
|
477
|
+
const std::vector<ImageEvaluation>& evaluations) {
|
|
478
478
|
const std::vector<double> recall_thresholds =
|
|
479
479
|
list_to_vec<double>(params.attr("recThrs"));
|
|
480
480
|
const std::vector<int> max_detections =
|
|
@@ -661,10 +661,10 @@ py::dict Accumulate(const py::object ¶ms,
|
|
|
661
661
|
}
|
|
662
662
|
|
|
663
663
|
py::dict EvaluateAccumulate(
|
|
664
|
-
const py::object
|
|
665
|
-
const ImageCategoryInstances<std::vector<double
|
|
666
|
-
const LightweightDataset
|
|
667
|
-
const std::vector<double
|
|
664
|
+
const py::object& params,
|
|
665
|
+
const ImageCategoryInstances<std::vector<double>>& image_category_ious,
|
|
666
|
+
const LightweightDataset& gt_dataset, const LightweightDataset& dt_dataset,
|
|
667
|
+
const std::vector<double>& img_ids, const std::vector<double>& cat_ids,
|
|
668
668
|
bool useCats) {
|
|
669
669
|
const std::vector<int> max_detections =
|
|
670
670
|
list_to_vec<int>(params.attr("maxDets"));
|
|
@@ -686,8 +686,8 @@ py::dict EvaluateAccumulate(
|
|
|
686
686
|
// non-increasing. Arguments:
|
|
687
687
|
// recall_list: vector of recall values (must be sorted in increasing order)
|
|
688
688
|
// precision_list: vector of precision values (same size as recall_list)
|
|
689
|
-
long double calc_auc(const std::vector<long double
|
|
690
|
-
const std::vector<long double
|
|
689
|
+
long double calc_auc(const std::vector<long double>& recall_list,
|
|
690
|
+
const std::vector<long double>& precision_list) {
|
|
691
691
|
// Make a copy of precision_list to enforce monotonicity.
|
|
692
692
|
std::vector<long double> mpre = precision_list;
|
|
693
693
|
|
|
@@ -59,12 +59,12 @@ using ImageCategoryInstances = std::vector<std::vector<std::vector<T>>>;
|
|
|
59
59
|
// image_category_detection_instances[i][c] is a vector of detected
|
|
60
60
|
// instances in image image_ids[i] of category category_ids[c]
|
|
61
61
|
std::vector<ImageEvaluation> EvaluateImages(
|
|
62
|
-
const std::vector<std::array<double, 2
|
|
63
|
-
|
|
64
|
-
int max_detections, const std::vector<double
|
|
65
|
-
const ImageCategoryInstances<std::vector<double
|
|
66
|
-
const LightweightDataset
|
|
67
|
-
const std::vector<double
|
|
62
|
+
const std::vector<std::array<double, 2>>&
|
|
63
|
+
area_ranges, // vector of 2-tuples
|
|
64
|
+
int max_detections, const std::vector<double>& iou_thresholds,
|
|
65
|
+
const ImageCategoryInstances<std::vector<double>>& image_category_ious,
|
|
66
|
+
const LightweightDataset& gt_dataset, const LightweightDataset& dt_dataset,
|
|
67
|
+
const std::vector<double>& img_ids, const std::vector<double>& cat_ids,
|
|
68
68
|
bool useCats);
|
|
69
69
|
|
|
70
70
|
// C++ implementation of COCOeval.accumulate(), which generates precision
|
|
@@ -72,17 +72,17 @@ std::vector<ImageEvaluation> EvaluateImages(
|
|
|
72
72
|
// and max number of detections parameters. It is assumed that the parameter
|
|
73
73
|
// evaluations is the return value of the functon COCOeval::EvaluateImages(),
|
|
74
74
|
// which was called with the same parameter settings params
|
|
75
|
-
py::dict Accumulate(const py::object
|
|
76
|
-
const std::vector<ImageEvaluation
|
|
75
|
+
py::dict Accumulate(const py::object& params,
|
|
76
|
+
const std::vector<ImageEvaluation>& evalutations);
|
|
77
77
|
|
|
78
78
|
py::dict EvaluateAccumulate(
|
|
79
|
-
const py::object
|
|
80
|
-
const ImageCategoryInstances<std::vector<double
|
|
81
|
-
const LightweightDataset
|
|
82
|
-
const std::vector<double
|
|
79
|
+
const py::object& params,
|
|
80
|
+
const ImageCategoryInstances<std::vector<double>>& image_category_ious,
|
|
81
|
+
const LightweightDataset& gt_dataset, const LightweightDataset& dt_dataset,
|
|
82
|
+
const std::vector<double>& img_ids, const std::vector<double>& cat_ids,
|
|
83
83
|
bool useCats);
|
|
84
84
|
|
|
85
|
-
long double calc_auc(const std::vector<long double
|
|
86
|
-
const std::vector<long double
|
|
85
|
+
long double calc_auc(const std::vector<long double>& recall_list,
|
|
86
|
+
const std::vector<long double>& precision_list);
|
|
87
87
|
} // namespace COCOeval
|
|
88
88
|
} // namespace coco_eval
|
{faster_coco_eval-1.7.0 → faster_coco_eval-1.7.1}/csrc/faster_eval_api/coco_eval/dataset.cpp
RENAMED
|
@@ -44,12 +44,12 @@ size_t LightweightDataset::size() const { return annotation_refs.size(); }
|
|
|
44
44
|
py::tuple LightweightDataset::make_tuple() const {
|
|
45
45
|
// Create a list of (img_id, cat_id, annotation_list) tuples
|
|
46
46
|
py::list serialized_data;
|
|
47
|
-
for (const auto
|
|
47
|
+
for (const auto& kv : annotation_refs) {
|
|
48
48
|
auto key = kv.first;
|
|
49
49
|
auto ann_list = kv.second;
|
|
50
50
|
|
|
51
51
|
py::list py_ann_list;
|
|
52
|
-
for (const auto
|
|
52
|
+
for (const auto& ann : ann_list) {
|
|
53
53
|
py_ann_list.append(ann);
|
|
54
54
|
}
|
|
55
55
|
|
|
@@ -108,7 +108,7 @@ std::vector<py::dict> LightweightDataset::get(double img_id, double cat_id) {
|
|
|
108
108
|
std::vector<py::dict> result;
|
|
109
109
|
result.reserve(it->second.size());
|
|
110
110
|
|
|
111
|
-
for (const auto
|
|
111
|
+
for (const auto& py_ann : it->second) {
|
|
112
112
|
// Convert py::object to py::dict
|
|
113
113
|
result.emplace_back(py_ann.cast<py::dict>());
|
|
114
114
|
}
|
|
@@ -121,7 +121,7 @@ std::vector<py::dict> LightweightDataset::get(double img_id, double cat_id) {
|
|
|
121
121
|
|
|
122
122
|
// Helper method to convert py::object to InstanceAnnotation
|
|
123
123
|
InstanceAnnotation LightweightDataset::parse_py_annotation(
|
|
124
|
-
const py::object
|
|
124
|
+
const py::object& ann) const {
|
|
125
125
|
uint64_t id = 0;
|
|
126
126
|
double score = 0.0;
|
|
127
127
|
double area = 0.0;
|
|
@@ -136,21 +136,21 @@ InstanceAnnotation LightweightDataset::parse_py_annotation(
|
|
|
136
136
|
if (ann_dict.contains("id")) {
|
|
137
137
|
id = ann_dict["id"].cast<uint64_t>();
|
|
138
138
|
}
|
|
139
|
-
} catch (const std::exception
|
|
139
|
+
} catch (const std::exception&) {
|
|
140
140
|
}
|
|
141
141
|
|
|
142
142
|
try {
|
|
143
143
|
if (ann_dict.contains("score")) {
|
|
144
144
|
score = ann_dict["score"].cast<double>();
|
|
145
145
|
}
|
|
146
|
-
} catch (const std::exception
|
|
146
|
+
} catch (const std::exception&) {
|
|
147
147
|
}
|
|
148
148
|
|
|
149
149
|
try {
|
|
150
150
|
if (ann_dict.contains("area")) {
|
|
151
151
|
area = ann_dict["area"].cast<double>();
|
|
152
152
|
}
|
|
153
|
-
} catch (const std::exception
|
|
153
|
+
} catch (const std::exception&) {
|
|
154
154
|
}
|
|
155
155
|
|
|
156
156
|
try {
|
|
@@ -159,21 +159,21 @@ InstanceAnnotation LightweightDataset::parse_py_annotation(
|
|
|
159
159
|
} else if (ann_dict.contains("iscrowd")) {
|
|
160
160
|
is_crowd = ann_dict["iscrowd"].cast<bool>();
|
|
161
161
|
}
|
|
162
|
-
} catch (const std::exception
|
|
162
|
+
} catch (const std::exception&) {
|
|
163
163
|
}
|
|
164
164
|
|
|
165
165
|
try {
|
|
166
166
|
if (ann_dict.contains("ignore")) {
|
|
167
167
|
ignore = ann_dict["ignore"].cast<bool>();
|
|
168
168
|
}
|
|
169
|
-
} catch (const std::exception
|
|
169
|
+
} catch (const std::exception&) {
|
|
170
170
|
}
|
|
171
171
|
|
|
172
172
|
try {
|
|
173
173
|
if (ann_dict.contains("lvis_mark")) {
|
|
174
174
|
lvis_mark = ann_dict["lvis_mark"].cast<bool>();
|
|
175
175
|
}
|
|
176
|
-
} catch (const std::exception
|
|
176
|
+
} catch (const std::exception&) {
|
|
177
177
|
}
|
|
178
178
|
|
|
179
179
|
// Construct and return the annotation.
|
|
@@ -199,7 +199,7 @@ std::vector<InstanceAnnotation> LightweightDataset::get_cpp_annotations(
|
|
|
199
199
|
result.reserve(it->second.size());
|
|
200
200
|
|
|
201
201
|
// Convert each Python annotation to InstanceAnnotation
|
|
202
|
-
for (const auto
|
|
202
|
+
for (const auto& py_ann : it->second) {
|
|
203
203
|
result.emplace_back(parse_py_annotation(py_ann));
|
|
204
204
|
}
|
|
205
205
|
|
|
@@ -220,9 +220,9 @@ void LightweightDataset::clear_cache_entry(double img_id, double cat_id) const {
|
|
|
220
220
|
|
|
221
221
|
// Get all C++ annotation objects for provided img_ids and cat_ids
|
|
222
222
|
std::vector<std::vector<std::vector<InstanceAnnotation>>>
|
|
223
|
-
LightweightDataset::get_cpp_instances(const std::vector<double
|
|
224
|
-
const std::vector<double
|
|
225
|
-
const bool
|
|
223
|
+
LightweightDataset::get_cpp_instances(const std::vector<double>& img_ids,
|
|
224
|
+
const std::vector<double>& cat_ids,
|
|
225
|
+
const bool& useCats) {
|
|
226
226
|
std::vector<std::vector<std::vector<InstanceAnnotation>>> result;
|
|
227
227
|
result.reserve(img_ids.size()); // Reserve space for image indices
|
|
228
228
|
|
|
@@ -263,9 +263,9 @@ LightweightDataset::get_cpp_instances(const std::vector<double> &img_ids,
|
|
|
263
263
|
|
|
264
264
|
// Get all Python dict annotations for provided img_ids and cat_ids
|
|
265
265
|
std::vector<std::vector<std::vector<py::dict>>>
|
|
266
|
-
LightweightDataset::get_instances(const std::vector<double
|
|
267
|
-
const std::vector<double
|
|
268
|
-
const bool
|
|
266
|
+
LightweightDataset::get_instances(const std::vector<double>& img_ids,
|
|
267
|
+
const std::vector<double>& cat_ids,
|
|
268
|
+
const bool& useCats) {
|
|
269
269
|
std::vector<std::vector<std::vector<py::dict>>> result;
|
|
270
270
|
result.reserve(img_ids.size()); // Reserve space for images
|
|
271
271
|
|
|
@@ -14,13 +14,13 @@ namespace coco_eval {
|
|
|
14
14
|
|
|
15
15
|
namespace COCOeval {
|
|
16
16
|
template <class T>
|
|
17
|
-
inline void hash_combine(std::size_t
|
|
17
|
+
inline void hash_combine(std::size_t& seed, const T& v) {
|
|
18
18
|
std::hash<T> hasher;
|
|
19
19
|
seed ^= hasher(v) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
|
|
20
20
|
}
|
|
21
21
|
|
|
22
22
|
struct hash_pair {
|
|
23
|
-
std::size_t operator()(const std::pair<int64_t, int64_t
|
|
23
|
+
std::size_t operator()(const std::pair<int64_t, int64_t>& p) const {
|
|
24
24
|
std::size_t h = 0;
|
|
25
25
|
hash_combine(h, p.first);
|
|
26
26
|
hash_combine(h, p.second);
|
|
@@ -62,18 +62,18 @@ class LightweightDataset {
|
|
|
62
62
|
|
|
63
63
|
// Get all C++ annotation objects for provided img_ids and cat_ids
|
|
64
64
|
std::vector<std::vector<std::vector<InstanceAnnotation>>>
|
|
65
|
-
get_cpp_instances(const std::vector<double
|
|
66
|
-
const std::vector<double
|
|
67
|
-
const bool
|
|
65
|
+
get_cpp_instances(const std::vector<double>& img_ids,
|
|
66
|
+
const std::vector<double>& cat_ids,
|
|
67
|
+
const bool& useCats);
|
|
68
68
|
|
|
69
69
|
// Get all Python dict annotations for provided img_ids and cat_ids
|
|
70
70
|
std::vector<std::vector<std::vector<py::dict>>> get_instances(
|
|
71
|
-
const std::vector<double
|
|
72
|
-
const std::vector<double
|
|
71
|
+
const std::vector<double>& img_ids,
|
|
72
|
+
const std::vector<double>& cat_ids, const bool& useCats);
|
|
73
73
|
|
|
74
74
|
// Legacy compatibility - same as append_ref but with different
|
|
75
75
|
// signature
|
|
76
|
-
void append(double img_id, double cat_id, const py::dict
|
|
76
|
+
void append(double img_id, double cat_id, const py::dict& ann) {
|
|
77
77
|
append_ref(img_id, cat_id, py::cast<py::object>(ann));
|
|
78
78
|
}
|
|
79
79
|
|
|
@@ -89,7 +89,7 @@ class LightweightDataset {
|
|
|
89
89
|
cpp_cache;
|
|
90
90
|
|
|
91
91
|
// Helper method to convert py::object to InstanceAnnotation
|
|
92
|
-
InstanceAnnotation parse_py_annotation(const py::object
|
|
92
|
+
InstanceAnnotation parse_py_annotation(const py::object& ann) const;
|
|
93
93
|
};
|
|
94
94
|
} // namespace COCOeval
|
|
95
95
|
} // namespace coco_eval
|
|
@@ -57,14 +57,14 @@ PYBIND11_MODULE(faster_eval_api_cpp, m) {
|
|
|
57
57
|
.def(pybind11::init<>())
|
|
58
58
|
.def(pybind11::pickle(
|
|
59
59
|
// __getstate__ for pickling
|
|
60
|
-
[](const COCOeval::ImageEvaluation
|
|
60
|
+
[](const COCOeval::ImageEvaluation& p) {
|
|
61
61
|
// Use reserve to avoid reallocations (performance
|
|
62
62
|
// optimization)
|
|
63
63
|
std::vector<std::tuple<uint64_t, uint64_t, double>>
|
|
64
64
|
matched_annotations;
|
|
65
65
|
matched_annotations.reserve(
|
|
66
66
|
p.matched_annotations.size());
|
|
67
|
-
for (const auto
|
|
67
|
+
for (const auto& ann : p.matched_annotations) {
|
|
68
68
|
matched_annotations.emplace_back(
|
|
69
69
|
ann.dt_id, ann.gt_id, ann.iou);
|
|
70
70
|
}
|
|
@@ -90,7 +90,7 @@ PYBIND11_MODULE(faster_eval_api_cpp, m) {
|
|
|
90
90
|
std::tuple<uint64_t, uint64_t, double>>>();
|
|
91
91
|
p.matched_annotations.reserve(
|
|
92
92
|
matched_annotations.size());
|
|
93
|
-
for (const auto
|
|
93
|
+
for (const auto& tup : matched_annotations) {
|
|
94
94
|
p.matched_annotations.emplace_back(
|
|
95
95
|
std::get<0>(tup), std::get<1>(tup),
|
|
96
96
|
std::get<2>(tup));
|
|
@@ -114,11 +114,11 @@ PYBIND11_MODULE(faster_eval_api_cpp, m) {
|
|
|
114
114
|
.def("get_cpp_instances",
|
|
115
115
|
&COCOeval::LightweightDataset::get_cpp_instances)
|
|
116
116
|
.def("__len__",
|
|
117
|
-
[](const COCOeval::LightweightDataset
|
|
117
|
+
[](const COCOeval::LightweightDataset& p) { return p.size(); })
|
|
118
118
|
.def("make_tuple", &COCOeval::LightweightDataset::make_tuple)
|
|
119
119
|
.def("load_tuple", &COCOeval::LightweightDataset::load_tuple)
|
|
120
120
|
.def(pybind11::pickle(
|
|
121
|
-
[](const COCOeval::LightweightDataset
|
|
121
|
+
[](const COCOeval::LightweightDataset& p) {
|
|
122
122
|
return p.make_tuple();
|
|
123
123
|
},
|
|
124
124
|
[](pybind11::tuple t) {
|
|
@@ -87,7 +87,7 @@ PYBIND11_MODULE(mask_api_new_cpp, m) {
|
|
|
87
87
|
py::call_guard<py::gil_scoped_release>())
|
|
88
88
|
.def("toDict", &Mask::RLE::toDict)
|
|
89
89
|
.def(py::pickle(
|
|
90
|
-
[](const Mask::RLE
|
|
90
|
+
[](const Mask::RLE& p) { // __getstate__
|
|
91
91
|
// Returns a tuple encoding all RLE fields.
|
|
92
92
|
return py::make_tuple(p.h, p.w, p.m, p.cnts);
|
|
93
93
|
},
|
|
@@ -158,11 +158,11 @@ PYBIND11_MODULE(mask_api_new_cpp, m) {
|
|
|
158
158
|
// representations.
|
|
159
159
|
m.def("toBbox", &Mask::toBbox, "Mask::toBbox");
|
|
160
160
|
m.def("merge",
|
|
161
|
-
py::overload_cast<const std::vector<py::dict
|
|
161
|
+
py::overload_cast<const std::vector<py::dict>&, const int&>(
|
|
162
162
|
&Mask::merge),
|
|
163
163
|
"Mask::merge");
|
|
164
164
|
m.def("merge",
|
|
165
|
-
py::overload_cast<const std::vector<py::dict
|
|
165
|
+
py::overload_cast<const std::vector<py::dict>&>(&Mask::merge),
|
|
166
166
|
"Mask::merge");
|
|
167
167
|
|
|
168
168
|
// Computes the area (number of nonzero pixels) of a mask.
|