def test_iou_threshold(self): evaluator = MeanAveragePrecisionEvaluatorForSingleIOU(iou=0.5) predictions = [[ [0, 1.0, 0.5, 0.5, 1, 1], # IOU 0.25 [1, 1.0, 0.5, 0.5, 1, 1] ]] targets = [[[0, 0, 0, 1, 1], [1, 0.5, 0.5, 1, 1]]] evaluator.add_predictions(predictions, targets) report = evaluator.get_report() self.assertEqual(report["mAP_50"], 0.5) self.assertTrue(isinstance(report["mAP_50"], float)) evaluator = MeanAveragePrecisionEvaluatorForSingleIOU(iou=0.2) predictions = [[ [0, 1.0, 0.5, 0.5, 1, 1], # IOU 0.25 [1, 1.0, 0.5, 0.5, 1, 1] ]] targets = [[[0, 0, 0, 1, 1], [1, 0.5, 0.5, 1, 1]]] evaluator.add_predictions(predictions, targets) report = evaluator.get_report() self.assertEqual(report["mAP_20"], 1.0) self.assertTrue(isinstance(report["mAP_20"], float))
def test_no_predictions(self): evaluator = MeanAveragePrecisionEvaluatorForSingleIOU(iou=0.5) predictions = [[]] targets = [[[0, 0, 0, 1, 1], [1, 0.5, 0.5, 1, 1], [2, 0.1, 0.1, 0.5, 0.5]]] evaluator.add_predictions(predictions, targets) report = evaluator.get_report() self.assertEqual(report["mAP_50"], 0.0) self.assertTrue(isinstance(report["mAP_50"], float))
def test_perfect_one_image_absolute_coordinates(self): evaluator = MeanAveragePrecisionEvaluatorForSingleIOU(iou=0.5) predictions = [[[0, 1.0, 0, 0, 10, 10], [1, 1.0, 5, 5, 10, 10], [2, 1.0, 1, 1, 5, 5]]] targets = [[[0, 0, 0, 10, 10], [1, 5, 5, 10, 10], [2, 1, 1, 5, 5]]] evaluator.add_predictions(predictions, targets) report = evaluator.get_report() self.assertEqual(report["mAP_50"], 1.0) self.assertTrue(isinstance(report["mAP_50"], float))
def test_two_batches(self): evaluator = MeanAveragePrecisionEvaluatorForSingleIOU(iou=0.5, report_tag_wise=True) predictions = [[[0, 1.0, 0, 0, 1, 1], [1, 1.0, 0.5, 0.5, 1, 1]], [[2, 1.0, 0.1, 0.1, 0.5, 0.5]]] targets = [[[0, 0, 0, 1, 1], [1, 0.5, 0.5, 1, 1]], [[2, 0.1, 0.1, 0.5, 0.5]]] evaluator.add_predictions(predictions, targets) predictions = [[[0, 1.0, 0.9, 0.9, 1, 1], # Wrong [1, 1.0, 0.5, 0.5, 1, 1]], [[2, 1.0, 0.1, 0.1, 0.5, 0.5]]] targets = [[[0, 0, 0, 1, 1], [1, 0.5, 0.5, 1, 1]], [[2, 0.1, 0.1, 0.5, 0.5]]] evaluator.add_predictions(predictions, targets) report = evaluator.get_report() self.assertEqual(report["mAP_50"], 0.75) self.assertTrue(isinstance(report["mAP_50"], float)) self.assertEqual(len(report["tag_wise_AP_50"]), 3)
def test_empty_result(self): evaluator = MeanAveragePrecisionEvaluatorForSingleIOU(iou=0.5) report = evaluator.get_report() self.assertIn('mAP_50', report) self.assertEqual(report["mAP_50"], 0.0) self.assertTrue(isinstance(report["mAP_50"], float))