def test_match_non_unitary_at_01(self): matcher = MatchEngineIoU(0.1, 'non-unitary') assert np.all( matcher.match(detections, gt) == np.array( [[0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 1, 1], [0, 0, 0, 0, 1, 0], [0, 0, 0, 0, 0, 0], [1, 0, 0, 0, 0, 0], [1, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 1, 0, 0, 0]]))
def test_match_xview_at_005(self): matcher = MatchEngineIoU(0.05, 'xview') assert np.all( matcher.match(detections, gt, label_mean_area=gt_mean_area) == np. array([[0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 1], [0, 0, 0, 0, 1, 0], [0, 0, 0, 1, 0, 0], [1, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 1, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0]]))
def test_match_coco_at_005(self): matcher = MatchEngineIoU(0.05, 'coco') assert np.all( matcher.match(detections, gt) == np.array( [[0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 1], [0, 0, 0, 0, 1, 0], [0, 0, 0, 0, 0, 0], [1, 0, 0, 0, 0, 0], [0, 1, 0, 0, 0, 0], [0, 0, 1, 0, 0, 0], [0, 0, 0, 0, 0, 0]]))
def test_match_xview_at_01(self): matcher = MatchEngineIoU(0.1, 'xview') assert np.all( matcher.match(detections, gt) == np.array( [[0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 1], [0, 0, 0, 0, 1, 0], [0, 0, 0, 0, 0, 0], [1, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 1, 0, 0, 0]]))
def test_match_coco_at_01(self): matcher = MatchEngineIoU(0.1, 'coco') assert np.all( matcher.match(detections, gt, label_mean_area=gt_mean_area) == np. array([[0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 1], [0, 0, 0, 0, 1, 0], [0, 0, 0, 1, 0, 0], [1, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 1, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0]]))
def test_rtree_iou_matrix(self): matcher = MatchEngineIoU(0.1, 'coco') ref_iou = naive_compute_iou_matrix(sort_detection_by_confidence(detections), gt) iou = matcher.compute_similarity_matrix(detections, gt) print(iou) print(ref_iou) assert np.all(iou == ref_iou)
def test_rtree_iou_matrix(self): matcher = MatchEngineIoU(0.1, 'coco') ref_iou = naive_compute_iou_matrix(sort_detection_by_confidence(detections), gt) * \ (gt_mean_area / area(gt[:, 0])) iou = matcher.compute_similarity_matrix(detections, gt, label_mean_area=gt_mean_area) print(iou) print(ref_iou) assert np.all(iou[np.logical_not(np.isinf(iou))] == ref_iou[np.logical_not(np.isinf(iou))])
def test_threshold_property(self): class MatchEngine(MatchEngineBase): def compute_similarity_matrix(self, detections, ground_truths, label_mean_area=None): pass def trim_similarity_matrix(self, similarity_matrix, detections, ground_truths, label_mean_area=None): pass map_with_threshold = MeanAveragePrecisionMetric(0.5, 'coco', match_engine=MatchEngineIoU(0.5, 'coco')) map_without_threshold = MeanAveragePrecisionMetric(0.5, 'coco', match_engine=MatchEngine('coco')) assert map_with_threshold.threshold == 0.5 assert map_without_threshold.threshold is None
def test_match_xview_at_01(self): matcher_poly = MatchEngineIoU(0.1, 'xview') matcher_bbox = MatchEngineIoU(0.1, 'xview') assert \ np.all(matcher_bbox.match(detections_bbox, gt_bbox, label_mean_area=gt_mean_area) == matcher_poly.match(detections_poly, gt_poly, label_mean_area=gt_mean_area))
def test_match_coco_at_005(self): matcher_poly = MatchEngineIoU(0.05, 'coco') matcher_bbox = MatchEngineIoU(0.05, 'coco') assert \ np.all(matcher_bbox.match(detections_bbox, gt_bbox, label_mean_area=gt_mean_area) == matcher_poly.match(detections_poly, gt_poly, label_mean_area=gt_mean_area))
def test_rtree_iou_matrix(self): matcher_poly = MatchEngineIoU(0.1, 'coco') matcher_bbox = MatchEngineIoU(0.1, 'coco') iou_poly = matcher_poly.compute_similarity_matrix( detections_corr_poly, gt_corr_poly, label_mean_area=gt_mean_area) iou_bbox = matcher_bbox.compute_similarity_matrix( detections_bbox, gt_bbox, label_mean_area=gt_mean_area) print(iou_poly) print(iou_bbox) assert np.all(iou_poly == iou_bbox)
def test_match_xview_at_01(self): matcher_poly = MatchEngineIoU(0.1, 'xview') matcher_bbox = MatchEngineIoU(0.1, 'xview') assert np.all( matcher_bbox.match(detections_bbox, gt_bbox) == matcher_poly.match( detections_poly, gt_poly))
def test_match_algorithm_warning(self): with pytest.warns(RuntimeWarning, match='Discrepancy between user provided match_algorithm'): _ = MeanAveragePrecisionMetric(0.5, 'xview', match_engine=MatchEngineIoU(0.5, 'coco'))
def _make_scale_match(self, threshold, method): matcher = MatchEngineIoU(threshold, method) matcher.match(self.data_detect_conv, self.data_detect_conv[:, (True, False, True)])
def test_match_non_unitary_at_01(self): matcher_poly = MatchEngineIoU(0.1, 'non-unitary') matcher_bbox = MatchEngineIoU(0.1, 'non-unitary') assert np.all( matcher_bbox.match(detections_bbox, gt_bbox) == matcher_poly.match( detections_poly, gt_poly))
def test_match_coco_at_005(self): matcher_poly = MatchEngineIoU(0.05, 'coco') matcher_bbox = MatchEngineIoU(0.05, 'coco') assert np.all( matcher_bbox.match(detections_bbox, gt_bbox) == matcher_poly.match( detections_poly, gt_poly))
def test_threshold_warning(self): import warnings warnings.filterwarnings("always", category=RuntimeWarning) class MatchEngine(MatchEngineBase): def compute_similarity_matrix(self, detections, ground_truths, label_mean_area=None): pass def trim_similarity_matrix(self, similarity_matrix, detections, ground_truths, label_mean_area=None): pass with pytest.warns(RuntimeWarning, match='Discrepancy between user provided threshold'): map_with_threshold = MeanAveragePrecisionMetric(0.1, 'coco', match_engine=MatchEngineIoU(0.5, 'coco')) with pytest.warns(RuntimeWarning, match='Discrepancy between user provided threshold'): map_without_threshold = MeanAveragePrecisionMetric(0.1, 'coco', match_engine=MatchEngine('coco'))