Narrow lattice search from strong spacing hints

This commit is contained in:
Meta Vens 2026-04-24 20:14:07 +01:00
commit a7c55663a7
4 changed files with 104 additions and 6 deletions

View file

@ -100,7 +100,7 @@ def test_infer_lattice_emits_search_progress_events(monkeypatch) -> None:
monkeypatch.setattr(inference_module, "_require_torch", lambda: (_FakeTorch(), object()))
monkeypatch.setattr(inference_module, "_estimate_lattice_spacing", lambda rgba: ((None, 0.0), (None, 0.0)))
monkeypatch.setattr(inference_module, "_hint_target_sizes_from_spacing", lambda width, height, spacing_x, spacing_y: [])
monkeypatch.setattr(inference_module, "_estimate_lattice_prior_details", lambda rgba: (4.0, 4.0, 0.5))
monkeypatch.setattr(inference_module, "_estimate_lattice_prior_details", lambda rgba, **kwargs: (4.0, 4.0, 0.5))
monkeypatch.setattr(
inference_module,
"_candidate_dims",

View file

@ -5,6 +5,7 @@ from repixelizer.inference import (
_candidate_dims,
_combine_axis_priors,
_hint_target_sizes_from_spacing,
_resolve_candidate_dims_from_spacing,
_top_candidates_by_size,
infer_fixed_lattice,
infer_lattice,
@ -37,6 +38,35 @@ def test_spacing_hints_can_add_dense_candidates_around_true_size() -> None:
assert 128 in sizes
def test_strong_spacing_signal_can_collapse_candidate_search_to_single_size() -> None:
dims = _resolve_candidate_dims_from_spacing(
1024,
1024,
None,
hinted_sizes=[128],
spacing_x=(8.0, 0.82),
spacing_y=(8.02, 0.78),
prior_reliability=0.74,
)
sizes = {width for width, _ in dims}
assert sizes == {128}
def test_weak_spacing_signal_keeps_broad_candidate_search() -> None:
dims = _resolve_candidate_dims_from_spacing(
1024,
1024,
None,
hinted_sizes=[128],
spacing_x=(8.0, 0.18),
spacing_y=(8.1, 0.12),
prior_reliability=0.24,
)
sizes = {width for width, _ in dims}
assert 128 in sizes
assert len(sizes) > 10
def test_top_candidates_are_diversified_by_size() -> None:
candidates = [
InferenceCandidate(target_width=113, target_height=113, phase_x=0.0, phase_y=0.0, score=0.90, breakdown={}),