def test__apply_threshold(od_sample_detection_bboxes):
    """ Test `_apply_threshold` and verify it works at different thresholds. """
    det_bboxes = _apply_threshold(od_sample_detection_bboxes, threshold=0.5)
    assert len(det_bboxes) == 3
    det_bboxes = _apply_threshold(od_sample_detection_bboxes, threshold=0.01)
    assert len(det_bboxes) == 5
    det_bboxes = _apply_threshold(od_sample_detection_bboxes, threshold=0.995)
    assert len(det_bboxes) == 2
Пример #2
0
def od_sample_detection(od_sample_raw_preds, od_detection_mask_dataset):
    labels = ["one", "two", "three", "four"]
    detections = _extract_od_results(
        _apply_threshold(od_sample_raw_preds[0], threshold=0.001),
        labels,
        od_detection_mask_dataset.im_paths[0],
    )
    detections["idx"] = 0
    del detections["keypoints"]
    return detections
Пример #3
0
def test__apply_threshold(od_sample_output):
    """ Test `_apply_threshold` and verify it works at different thresholds. """
    # test cases: [(threshold, num, mask_pixels)]
    test_cases = [
        (0.5, 3, (21146, 28098, 28458)),
        (0.01, 5, (21146, 28098, 28458, 28356, 21311)),
        (0.995, 2, (21146, 28098)),
    ]
    res = {k: v.detach().cpu().numpy() for k, v in od_sample_output.items()}
    for threshold, num, mask_pixels in test_cases:
        pred = _apply_threshold(res, threshold=threshold)
        for v in pred.values():
            assert len(v) == num
        for mask, num_pixels in zip(pred["masks"], mask_pixels):
            assert np.sum(mask) == num_pixels