MathGaron / mean_average_precision

Small and simple python/numpy utility to compute mean average precision (mAP) on detection task.
MIT License
117 stars 45 forks source link

Handle the No Prediction case #3

Closed MathGaron closed 6 years ago

MathGaron commented 6 years ago

The code crashes if there is no prediction :

the model instead does not predict any BB. In this case the pred_bb is an array with shape (0, 4) and the he code crashes in the intersect function with this error:

    _main_(args)
  File "predict.py", line 166, in _main_
    mAP.evaluate(pred_bb, pred_classes, pred_conf, gt_bb, gt_classes)
  File "../mean_average_precision/mean_average_precision/detection_map.py", line 42, in evaluate
    self.evaluate_(accumulators, pred_bb, pred_classes, pred_conf, gt_bb, gt_classes, r, self.overlap_threshold)
  File "../mean_average_precision/mean_average_precision/detection_map.py", line 49, in evaluate_
    IoU = jaccard(pred_bb, gt_bb)
  File "../mean_average_precision/mean_average_precision/bbox_utils.py", line 46, in jaccard
    inter = intersect(box_a, box_b)
  File "../mean_average_precision/mean_average_precision/bbox_utils.py", line 25, in intersect
    inter = np.clip(diff_xy, a_min=0, a_max=np.max(diff_xy))
  File "/Users/alessandro/Envs/tensor+kerasPy3/lib/python3.6/site-packages/numpy/core/fromnumeric.py", line 2272, in amax
    out=out, **kwargs)
  File "/Users/alessandro/Envs/tensor+kerasPy3/lib/python3.6/site-packages/numpy/core/_methods.py", line 26, in _amax
    return umr_maximum(a, axis, None, out, keepdims)
ValueError: zero-size array to reduction operation maximum which has no identity

reported in Issue #2

MathGaron commented 6 years ago

Just pushed a code update to handle the no prediction case. The only thing we update when there is no prediction is the False negatives (ground truth not found) and skip the rest.