Skip to content

Commit

Permalink
add equalScore param
Browse files Browse the repository at this point in the history
  • Loading branch information
MiXaiLL76 committed Oct 31, 2024
1 parent 1caac51 commit 752db8c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
21 changes: 15 additions & 6 deletions csrc/faster_eval_api/coco_eval/cocoeval.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,8 @@ namespace coco_eval
std::vector<double> *recalls,
std::vector<double> *precisions_out,
std::vector<double> *scores_out,
std::vector<double> *recalls_out)
std::vector<double> *recalls_out,
bool equal_score)
{
assert(recalls_out->size() > recalls_out_index);

Expand Down Expand Up @@ -391,9 +392,15 @@ namespace coco_eval
recalls->emplace_back(recall);
const int64_t num_valid_detections =
true_positives_sum + false_positives_sum;
const double precision = num_valid_detections > 0
? static_cast<double>(true_positives_sum) / num_valid_detections
: 0.0;

double precision = 0;
if(equal_score){
precision = num_valid_detections > 0 ? 1 : 0.0;
}else{
precision = num_valid_detections > 0
? static_cast<double>(true_positives_sum) / num_valid_detections
: 0.0;
}
precisions->emplace_back(precision);
}

Expand Down Expand Up @@ -445,6 +452,7 @@ namespace coco_eval
const int num_area_ranges = (const int) py::len(params.attr("areaRng"));
const int num_max_detections = (const int) py::len(params.attr("maxDets"));
const int num_images = (const int) py::len(params.attr("imgIds"));
bool equal_score = params.attr("equalScore").cast<bool>();

std::vector<double> precisions_out(
num_iou_thresholds * num_recall_thresholds * num_categories *
Expand Down Expand Up @@ -537,7 +545,8 @@ namespace coco_eval
&recalls,
&precisions_out,
&scores_out,
&recalls_out);
&recalls_out,
equal_score);
}
}
}
Expand Down Expand Up @@ -864,4 +873,4 @@ namespace coco_eval

} // namespace COCOeval

} // namespace coco_eval
} // namespace coco_eval
5 changes: 5 additions & 0 deletions faster_coco_eval/core/cocoeval.py
Original file line number Diff line number Diff line change
Expand Up @@ -593,6 +593,11 @@ def __init__(
# f: Frequent: >= 100
self.imgCountLbl = ["r", "c", "f"]

# https://github.com/MiXaiLL76/faster_coco_eval/issues/46
# mAP is wrong if all scores are equal (=not providing a score)
# set equalScore = True
self.equalScore = False

@property
def useSegm(self):
return int(self.iouType == "segm")
Expand Down

0 comments on commit 752db8c

Please sign in to comment.