Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix bug of evaluation only on frames with detections #36

Merged
merged 1 commit into from
Dec 19, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions ACAR-Net/calc_mAP.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,12 @@ def read_json(json_file, class_whitelist=None, load_score=False):
scores = defaultdict(list)
ann_dict = json.load(json_file)
for video in ann_dict['db'].keys():
# filter ground-truth of validation set only
if 'val_1' not in ann_dict['db'][video]['split_ids']:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

only val_1, should be a changeable param

continue
for frame in ann_dict['db'][video]['frames'].values():
if not frame['annotated'] or len(frame['annos']) == 0:
# only load ground-truth of annotated frames
if not frame['annotated']:
continue
image_key = make_image_key(video, frame['input_image_id'])
for annon in frame['annos'].values():
Expand Down Expand Up @@ -183,8 +187,13 @@ def run_evaluation(labelmap, groundtruth, detections, exclusions, logger):

start = time.time()
for image_key in gt_boxes:
# pred_boxes do not include frames with no detections
# to handle frames with no detections, add empty detections to those frames
if image_key not in pred_boxes.keys():
continue
pred_boxes[image_key] = np.empty(shape=[0, 4], dtype=float)
pred_labels[image_key] = np.array([], dtype=int)
pred_scores[image_key] =np.array([], dtype=float)
Comment on lines +193 to +195
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this what the pascal_evaluator expects in the case of no detection? Or where did you get this idea

Copy link
Contributor Author

@liqq010 liqq010 Jul 7, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I read the code of evaluation details. Before calculation of tp/fp, invalid detection boxes will be removed. The empty detection boxes we provide will be removed.

detected_boxes, detected_scores, detected_class_labels, detected_masks = (
self._remove_invalid_boxes(detected_boxes, detected_scores,
detected_class_labels, detected_masks))

Then N detection boxes and M ground-truth boxes will be used to calculate tp/fp. I think everything else is correct after this step and this follows the evaluation process of pascal_evaluator.

If we don't provide the empty detection boxes, before the step described above, less images will be evaluated according to this part of code.

if image_key in self.groundtruth_boxes:
groundtruth_boxes = self.groundtruth_boxes[image_key]
groundtruth_class_labels = self.groundtruth_class_labels[image_key]
# Masks are popped instead of look up. The reason is that we do not want
# to keep all masks in memory which can cause memory overflow.
groundtruth_masks = self.groundtruth_masks.pop(image_key)
groundtruth_is_difficult_list = self.groundtruth_is_difficult_list[
image_key]
groundtruth_is_group_of_list = self.groundtruth_is_group_of_list[
image_key]
else:
groundtruth_boxes = np.empty(shape=[0, 4], dtype=float)
groundtruth_class_labels = np.array([], dtype=int)
if detected_masks is None:
groundtruth_masks = None
else:
groundtruth_masks = np.empty(shape=[0, 1, 1], dtype=float)
groundtruth_is_difficult_list = np.array([], dtype=bool)
groundtruth_is_group_of_list = np.array([], dtype=bool)
scores, tp_fp_labels = (
self.per_image_eval.compute_object_detection_metrics(
detected_boxes=detected_boxes,
detected_scores=detected_scores,
detected_class_labels=detected_class_labels,
groundtruth_boxes=groundtruth_boxes,
groundtruth_class_labels=groundtruth_class_labels,
groundtruth_is_difficult_list=groundtruth_is_difficult_list,
groundtruth_is_group_of_list=groundtruth_is_group_of_list,
detected_masks=detected_masks,
groundtruth_masks=groundtruth_masks))


pascal_evaluator.add_single_ground_truth_image_info(
image_key, {
standard_fields.InputDataFields.groundtruth_boxes:
Expand All @@ -199,6 +208,7 @@ def run_evaluation(labelmap, groundtruth, detections, exclusions, logger):
start = time.time()
num_pred_ignored = 0
for image_key in pred_boxes:
# ignore frames without ground-truth annotations
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is this comment referring to?

if image_key not in gt_boxes.keys():
logger.info(("Found excluded timestamp in detections: %s. "
"It will be ignored."), image_key)
Expand Down