Spaces:
Paused
Paused
Download backend/experimental/selection.py from modventures/iris: direct link, hf CLI and curl.
- Browser
- Download file 2.17 kB
-
https://huggingface.co/spaces/modventures/iris/resolve/main/backend/experimental/selection.py
- Command line
-
hf download hf://spaces/modventures/iris/backend/experimental/selection.py
-
curl -L -o selection.py https://huggingface.co/spaces/modventures/iris/resolve/main/backend/experimental/selection.py
2.17 kB
| """Choose a refinement only with improvement on the same automatic anchor set. | |
| These scores select a candidate; they are not an independent final accuracy test. | |
| No sample IDs, client references, or manually finished images enter the decision. | |
| """ | |
| from .evaluation import common_evaluation, evaluate_correspondences | |
| def improves(baseline, candidate): | |
| if baseline['p95_px'] is None or candidate['p95_px'] is None: | |
| return False | |
| return (candidate['scored_count'] == candidate['count'] | |
| and candidate['count'] == baseline['count'] | |
| and candidate['p95_px'] < baseline['p95_px'] - max(.15, baseline['p95_px']*.03) | |
| and candidate['median_px'] <= baseline['median_px']*1.05) | |
| def select_correspondences(baseline, candidate, shape): | |
| a, b = baseline | |
| ca, cb = candidate | |
| base_evaluation = evaluate_correspondences(a, b, shape) | |
| candidate_evaluation = evaluate_correspondences(ca, cb, shape) | |
| diagnostics = dict(selected='single', reason='Baseline retained; alternative must improve common-point predictions.', | |
| candidate_verified_matches=len(ca), candidate_evaluation=candidate_evaluation, | |
| description='Automatic model-selection diagnostics, not an independent accuracy test.') | |
| # With insufficient baseline evidence we cannot claim a comparable improvement. | |
| if base_evaluation['p95_px'] is None or candidate_evaluation['p95_px'] is None or len(ca) < .8*len(a): | |
| return a, b, base_evaluation, diagnostics | |
| base_common = common_evaluation(a, b, a, b, shape) | |
| candidate_common = common_evaluation(ca, cb, a, b, shape) | |
| diagnostics.update(baseline_common=base_common, candidate_common=candidate_common) | |
| if (candidate_evaluation['p95_px'] < 12 and candidate_evaluation['median_px'] < 4 | |
| and improves(base_common, candidate_common)): | |
| diagnostics.update(selected='geometry', reason='Viewpoint correction improved tail error on the same held-out automatic points without worsening median error or losing substantial support.') | |
| return ca, cb, candidate_evaluation, diagnostics | |
| return a, b, base_evaluation, diagnostics | |