@@ -14,7 +14,7 @@ namespace coco_eval {
1414
1515namespace COCOeval {
1616template <typename T>
17- int64_t v_index (const std::vector<T> & v, const T & key) {
17+ int64_t v_index (const std::vector<T>& v, const T& key) {
1818 auto itr = std::find (v.begin (), v.end (), key);
1919
2020 if (itr != v.cend ()) {
@@ -29,8 +29,8 @@ int64_t v_index(const std::vector<T> &v, const T &key) {
2929// detection_instances[detection_sorted_indices[t+1]]. Use stable_sort to match
3030// original COCO API
3131void SortInstancesByDetectionScore (
32- const std::vector<InstanceAnnotation> & detection_instances,
33- std::vector<uint64_t > * detection_sorted_indices) {
32+ const std::vector<InstanceAnnotation>& detection_instances,
33+ std::vector<uint64_t >* detection_sorted_indices) {
3434 detection_sorted_indices->resize (detection_instances.size ());
3535 std::iota (detection_sorted_indices->begin (),
3636 detection_sorted_indices->end (), 0 );
@@ -45,10 +45,10 @@ void SortInstancesByDetectionScore(
4545// Partition the ground truth objects based on whether or not to ignore them
4646// based on area
4747void SortInstancesByIgnore (
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) {
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) {
5252 ignores->clear ();
5353 ignores->reserve (ground_truth_instances.size ());
5454 for (auto o : ground_truth_instances) {
@@ -70,29 +70,29 @@ void SortInstancesByIgnore(
7070// For each IOU threshold, greedily match each detected instance to a ground
7171// truth instance (if possible) and store the results
7272void MatchDetectionsToGroundTruth (
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) {
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) {
8181 // Initialize memory to store return data matches and ignore
8282 const int num_iou_thresholds = (const int )iou_thresholds.size ();
8383 const int num_ground_truth =
8484 (const int )ground_truth_sorted_indices.size ();
8585 const int num_detections = (const int )detection_sorted_indices.size ();
8686 // std::vector<uint64_t> ground_truth_matches(
8787 // num_iou_thresholds * num_ground_truth, 0);
88- std::vector<int64_t > & ground_truth_matches =
88+ std::vector<int64_t >& ground_truth_matches =
8989 results->ground_truth_matches ;
9090 ground_truth_matches.resize (num_iou_thresholds * num_ground_truth, 0 );
9191
92- std::vector<int64_t > & detection_matches = results->detection_matches ;
92+ std::vector<int64_t >& detection_matches = results->detection_matches ;
9393
94- std::vector<bool > & detection_ignores = results->detection_ignores ;
95- std::vector<bool > & ground_truth_ignores = results->ground_truth_ignores ;
94+ std::vector<bool >& detection_ignores = results->detection_ignores ;
95+ std::vector<bool >& ground_truth_ignores = results->ground_truth_ignores ;
9696 detection_matches.resize (num_iou_thresholds * num_detections, 0 );
9797 detection_ignores.resize (num_iou_thresholds * num_detections, false );
9898 ground_truth_ignores.resize (num_ground_truth);
@@ -166,7 +166,7 @@ void MatchDetectionsToGroundTruth(
166166
167167 // set unmatched detections outside of area range to
168168 // ignore
169- const InstanceAnnotation & detection =
169+ const InstanceAnnotation& detection =
170170 detection_instances[detection_sorted_indices[d]];
171171 detection_ignores[t * num_detections + d] =
172172 detection_ignores[t * num_detections + d] ||
@@ -186,11 +186,11 @@ void MatchDetectionsToGroundTruth(
186186}
187187
188188std::vector<ImageEvaluation> EvaluateImages (
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,
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,
194194 bool useCats) {
195195 const int num_area_ranges = (const int )area_ranges.size ();
196196 const int num_images = (const int )img_ids.size ();
@@ -298,7 +298,7 @@ std::vector<ImageEvaluation> EvaluateImages(
298298
299299// Convert a python list to a vector
300300template <typename T>
301- std::vector<T> list_to_vec (const py::list & l) {
301+ std::vector<T> list_to_vec (const py::list& l) {
302302 std::vector<T> v (py::len (l));
303303 for (int i = 0 ; i < (int )py::len (l); ++i) {
304304 v[i] = l[i].cast <T>();
@@ -318,13 +318,13 @@ std::vector<T> list_to_vec(const py::list &l) {
318318// and is the image_detection_indices[i]'th of the list of detections
319319// for the image containing i. detection_sorted_indices[] defines a sorted
320320// permutation of the 3 other outputs
321- int BuildSortedDetectionList (const std::vector<ImageEvaluation> & evaluations,
321+ int BuildSortedDetectionList (const std::vector<ImageEvaluation>& evaluations,
322322 const int64_t evaluation_index,
323323 const int64_t num_images, const int max_detections,
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) {
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) {
328328 assert (evaluations.size () >= evaluation_index + num_images);
329329
330330 // Extract a list of object instances of the applicable category, area
@@ -337,7 +337,7 @@ int BuildSortedDetectionList(const std::vector<ImageEvaluation> &evaluations,
337337 detection_scores->reserve (num_images * max_detections);
338338 int num_valid_ground_truth = 0 ;
339339 for (auto i = 0 ; i < num_images; ++i) {
340- const ImageEvaluation & evaluation =
340+ const ImageEvaluation& evaluation =
341341 evaluations[evaluation_index + i];
342342
343343 for (int d = 0 ; d < (int )evaluation.detection_scores .size () &&
@@ -382,16 +382,16 @@ int BuildSortedDetectionList(const std::vector<ImageEvaluation> &evaluations,
382382void ComputePrecisionRecallCurve (
383383 const int64_t precisions_out_index, const int64_t precisions_out_stride,
384384 const int64_t recalls_out_index,
385- const std::vector<double > & recall_thresholds, const int iou_threshold_index,
385+ const std::vector<double >& recall_thresholds, const int iou_threshold_index,
386386 const int num_iou_thresholds, const int num_valid_ground_truth,
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) {
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) {
395395 assert (recalls_out->size () > recalls_out_index);
396396
397397 // Compute precision/recall for each instance in the sorted list of
@@ -403,7 +403,7 @@ void ComputePrecisionRecallCurve(
403403 recalls->reserve (detection_sorted_indices.size ());
404404 assert (!evaluations.empty () || detection_sorted_indices.empty ());
405405 for (auto detection_sorted_index : detection_sorted_indices) {
406- const ImageEvaluation & evaluation =
406+ const ImageEvaluation& evaluation =
407407 evaluations[evaluation_indices[detection_sorted_index]];
408408 const auto num_detections =
409409 evaluation.detection_matches .size () / num_iou_thresholds;
@@ -473,8 +473,8 @@ void ComputePrecisionRecallCurve(
473473 }
474474 }
475475}
476- py::dict Accumulate (const py::object & params,
477- const std::vector<ImageEvaluation> & evaluations) {
476+ py::dict Accumulate (const py::object& params,
477+ const std::vector<ImageEvaluation>& evaluations) {
478478 const std::vector<double > recall_thresholds =
479479 list_to_vec<double >(params.attr (" recThrs" ));
480480 const std::vector<int > max_detections =
@@ -661,10 +661,10 @@ py::dict Accumulate(const py::object ¶ms,
661661}
662662
663663py::dict EvaluateAccumulate (
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,
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,
668668 bool useCats) {
669669 const std::vector<int > max_detections =
670670 list_to_vec<int >(params.attr (" maxDets" ));
@@ -686,8 +686,8 @@ py::dict EvaluateAccumulate(
686686// non-increasing. Arguments:
687687// recall_list: vector of recall values (must be sorted in increasing order)
688688// precision_list: vector of precision values (same size as recall_list)
689- long double calc_auc (const std::vector<long double > & recall_list,
690- const std::vector<long double > & precision_list) {
689+ long double calc_auc (const std::vector<long double >& recall_list,
690+ const std::vector<long double >& precision_list) {
691691 // Make a copy of precision_list to enforce monotonicity.
692692 std::vector<long double > mpre = precision_list;
693693
0 commit comments