Prepare lean solver for hosted shipping
This commit is contained in:
parent
2c656908e9
commit
5f2a644906
35 changed files with 1839 additions and 1948 deletions
|
|
@ -10,14 +10,12 @@ from repixelizer.inference import (
|
|||
_consensus_autocorr_lag,
|
||||
_estimate_lattice_autocorr_details,
|
||||
_estimate_lattice_prior_details,
|
||||
_candidate_dims,
|
||||
_candidate_dims_from_autocorr_hints,
|
||||
_combine_axis_priors,
|
||||
_hint_target_sizes_from_autocorr,
|
||||
_resolve_candidate_dims_from_autocorr,
|
||||
_top_candidates_by_size,
|
||||
infer_autocorr_lattice,
|
||||
infer_fixed_lattice,
|
||||
infer_lattice,
|
||||
)
|
||||
from repixelizer.io import load_rgba
|
||||
from repixelizer.observe import PipelineCancelled
|
||||
|
|
@ -65,72 +63,27 @@ def test_autocorr_hints_can_add_dense_candidates_around_true_size() -> None:
|
|||
autocorr_y_estimate=estimate,
|
||||
shared_prior=8.0,
|
||||
)
|
||||
dims = _candidate_dims(1024, 1024, None, hinted_sizes=hinted_sizes)
|
||||
dims = _candidate_dims_from_autocorr_hints(1024, 1024, hinted_sizes=hinted_sizes)
|
||||
sizes = {width for width, _ in dims}
|
||||
assert 128 in sizes
|
||||
|
||||
|
||||
def test_autocorr_hints_can_break_major_axis_cap_for_dense_candidates() -> None:
|
||||
dims = _candidate_dims(1254, 1254, None, hinted_sizes=[418])
|
||||
dims = _candidate_dims_from_autocorr_hints(1254, 1254, hinted_sizes=[418])
|
||||
sizes = {width for width, _ in dims}
|
||||
assert 418 in sizes
|
||||
assert 416 in sizes
|
||||
assert 420 in sizes
|
||||
assert 512 not in sizes
|
||||
|
||||
|
||||
def test_consistent_autocorr_signal_can_collapse_candidate_search_to_single_size() -> None:
|
||||
dims = _resolve_candidate_dims_from_autocorr(
|
||||
1024,
|
||||
1024,
|
||||
None,
|
||||
hinted_sizes=[128],
|
||||
prior_reliability=0.85,
|
||||
)
|
||||
sizes = {width for width, _ in dims}
|
||||
assert sizes == {128}
|
||||
|
||||
|
||||
def test_divergent_autocorr_signal_keeps_candidate_search_wide_enough_for_badge() -> None:
|
||||
dims = _resolve_candidate_dims_from_autocorr(
|
||||
1024,
|
||||
1024,
|
||||
None,
|
||||
hinted_sizes=[114, 120, 125],
|
||||
prior_reliability=0.9,
|
||||
)
|
||||
sizes = {width for width, _ in dims}
|
||||
assert 126 in sizes
|
||||
assert any(abs(size - 114) <= 1 for size in sizes)
|
||||
assert any(abs(size - 125) <= 1 for size in sizes)
|
||||
|
||||
|
||||
def test_dense_landscape_candidate_search_keeps_autocorr_size() -> None:
|
||||
rgba = load_rgba(Path("tests/fixtures/real/dense-landscape.png"))
|
||||
autocorr_x, autocorr_y = _estimate_lattice_autocorr_details(rgba)
|
||||
prior_x, _prior_y, prior_reliability = _estimate_lattice_prior_details(rgba)
|
||||
hinted_sizes = _hint_target_sizes_from_autocorr(
|
||||
rgba.shape[1],
|
||||
rgba.shape[0],
|
||||
autocorr_x_estimate=autocorr_x,
|
||||
autocorr_y_estimate=autocorr_y,
|
||||
shared_prior=prior_x,
|
||||
)
|
||||
dims = _resolve_candidate_dims_from_autocorr(
|
||||
rgba.shape[1],
|
||||
rgba.shape[0],
|
||||
None,
|
||||
hinted_sizes=hinted_sizes,
|
||||
prior_reliability=prior_reliability,
|
||||
)
|
||||
sizes = {width for width, _ in dims}
|
||||
assert any(size > 256 for size in sizes)
|
||||
assert any(abs(size - 418) <= 1 for size in sizes)
|
||||
|
||||
|
||||
def test_badge_autocorr_consensus_stays_in_canonical_family() -> None:
|
||||
def test_badge_autocorr_candidates_stay_in_canonical_family() -> None:
|
||||
rgba = load_rgba(Path("tests/fixtures/real/ai-badge-cleaned.png"))
|
||||
result = infer_lattice(rgba, device="cpu")
|
||||
result = infer_autocorr_lattice(rgba, device="cpu")
|
||||
assert result.target_width in {125, 126}
|
||||
assert result.top_candidates
|
||||
assert result.top_candidates[0].target_width in {125, 126}
|
||||
|
|
@ -159,7 +112,7 @@ def test_top_candidates_are_diversified_by_size() -> None:
|
|||
]
|
||||
|
||||
|
||||
def test_infer_lattice_recovers_emblem_scale() -> None:
|
||||
def test_infer_autocorr_lattice_recovers_emblem_scale() -> None:
|
||||
source = make_emblem(32, 32)
|
||||
fake = fake_pixelize(
|
||||
source,
|
||||
|
|
@ -169,7 +122,7 @@ def test_infer_lattice_recovers_emblem_scale() -> None:
|
|||
warp_detail=6,
|
||||
seed=5,
|
||||
)
|
||||
result = infer_lattice(fake)
|
||||
result = infer_autocorr_lattice(fake)
|
||||
assert result.target_width in range(28, 37)
|
||||
assert result.target_height in range(28, 37)
|
||||
assert result.confidence >= 0.0
|
||||
|
|
@ -205,7 +158,7 @@ def test_infer_fixed_lattice_uses_canonical_cell_centers_within_pinned_size() ->
|
|||
assert all(candidate.target_height == 16 for candidate in result.top_candidates)
|
||||
|
||||
|
||||
def test_infer_lattice_honors_cooperative_cancellation(monkeypatch) -> None:
|
||||
def test_infer_autocorr_lattice_honors_cooperative_cancellation(monkeypatch) -> None:
|
||||
import repixelizer.inference as inference_module
|
||||
|
||||
class _FakeCuda:
|
||||
|
|
@ -234,7 +187,7 @@ def test_infer_lattice_honors_cooperative_cancellation(monkeypatch) -> None:
|
|||
monkeypatch.setattr(inference_module, "_estimate_lattice_prior_details", lambda rgba: (4.0, 4.0, 0.5))
|
||||
monkeypatch.setattr(
|
||||
inference_module,
|
||||
"_resolve_candidate_dims_from_autocorr",
|
||||
"_candidate_dims_from_autocorr_hints",
|
||||
lambda *args, **kwargs: [(10, 8), (12, 10)],
|
||||
)
|
||||
monkeypatch.setattr(
|
||||
|
|
@ -251,4 +204,4 @@ def test_infer_lattice_honors_cooperative_cancellation(monkeypatch) -> None:
|
|||
)
|
||||
|
||||
with pytest.raises(PipelineCancelled):
|
||||
inference_module.infer_lattice(np.zeros((16, 16, 4), dtype=np.float32), observer=CancelObserver())
|
||||
inference_module.infer_autocorr_lattice(np.zeros((16, 16, 4), dtype=np.float32), observer=CancelObserver())
|
||||
|
|
|
|||
Loading…
Reference in a new issue