Remove legacy continuous optimizer
This commit is contained in:
parent
d9fa411daf
commit
0808271d05
19 changed files with 360 additions and 3434 deletions
|
|
@ -2,16 +2,16 @@ from __future__ import annotations
|
|||
|
||||
import numpy as np
|
||||
|
||||
from repixelizer.analysis import analyze_continuous_source, analyze_tile_graph_source
|
||||
from repixelizer.analysis import analyze_phase_field_source, analyze_tile_graph_source
|
||||
|
||||
|
||||
def test_continuous_source_analysis_cpu_device_matches_default_path() -> None:
|
||||
def test_phase_field_source_analysis_cpu_device_matches_default_path() -> None:
|
||||
source = np.zeros((8, 8, 4), dtype=np.float32)
|
||||
source[..., 3] = 1.0
|
||||
source[2:6, 3:5, :3] = np.asarray([1.0, 0.8, 0.2], dtype=np.float32)
|
||||
|
||||
default = analyze_continuous_source(source, seed=7)
|
||||
accelerated = analyze_continuous_source(source, seed=7, device="cpu")
|
||||
default = analyze_phase_field_source(source, seed=7)
|
||||
accelerated = analyze_phase_field_source(source, seed=7, device="cpu")
|
||||
|
||||
assert np.allclose(accelerated.edge_map, default.edge_map, atol=1e-5)
|
||||
assert not hasattr(accelerated, "cluster_map")
|
||||
|
|
|
|||
|
|
@ -1,188 +0,0 @@
|
|||
from __future__ import annotations
|
||||
|
||||
import numpy as np
|
||||
import torch
|
||||
|
||||
from repixelizer.analysis import analyze_continuous_source
|
||||
from repixelizer.continuous import (
|
||||
_build_candidate_positions,
|
||||
_build_source_reliability,
|
||||
_line_pattern_loss,
|
||||
_make_regular_uv,
|
||||
optimize_lattice_pixels,
|
||||
)
|
||||
from repixelizer.metrics import source_lattice_consistency_breakdown
|
||||
from repixelizer.params import SolverHyperParams
|
||||
from repixelizer.source_reference import build_source_lattice_reference
|
||||
from repixelizer.synthetic import fake_pixelize
|
||||
from repixelizer.types import InferenceResult
|
||||
|
||||
|
||||
def test_line_pattern_loss_penalizes_wobbling_line() -> None:
|
||||
reference = torch.zeros((1, 5, 5, 4), dtype=torch.float32)
|
||||
reference[:, :, 2, :] = 1.0
|
||||
|
||||
good = reference.clone()
|
||||
bad = reference.clone()
|
||||
bad[:, 2, 2, :] = 0.0
|
||||
bad[:, 2, 3, :] = 1.0
|
||||
|
||||
good_loss = float(_line_pattern_loss(torch, good, reference).item())
|
||||
bad_loss = float(_line_pattern_loss(torch, bad, reference).item())
|
||||
|
||||
assert good_loss <= 1e-6
|
||||
assert bad_loss > good_loss + 0.01
|
||||
|
||||
|
||||
def test_source_reliability_stays_high_for_high_contrast_edge_cells() -> None:
|
||||
source = np.zeros((8, 8, 4), dtype=np.float32)
|
||||
source[..., 3] = 1.0
|
||||
source[:, 1, :3] = 1.0
|
||||
|
||||
analysis = analyze_continuous_source(source, seed=3)
|
||||
reference = build_source_lattice_reference(
|
||||
source,
|
||||
target_width=4,
|
||||
target_height=4,
|
||||
phase_x=0.0,
|
||||
phase_y=0.0,
|
||||
edge_hint=analysis.edge_map,
|
||||
edge_grad_x_hint=np.gradient(analysis.edge_map, axis=1).astype(np.float32),
|
||||
edge_grad_y_hint=np.gradient(analysis.edge_map, axis=0).astype(np.float32),
|
||||
)
|
||||
|
||||
reliability = _build_source_reliability(reference, SolverHyperParams())
|
||||
|
||||
assert reference.cell_dispersion[1, 0] > reference.dispersion
|
||||
assert reference.edge_strength[1, 0] > 0.0
|
||||
assert reliability[1, 0] >= 0.7
|
||||
|
||||
|
||||
def test_candidate_positions_include_sharp_and_edge_guided_samples() -> None:
|
||||
source = np.zeros((6, 6, 4), dtype=np.float32)
|
||||
source[..., 3] = 1.0
|
||||
source[1:5, 2, :3] = 1.0
|
||||
|
||||
edge_hint = np.zeros((6, 6), dtype=np.float32)
|
||||
edge_hint[1:5, 2] = 1.0
|
||||
edge_grad_x = np.zeros((6, 6), dtype=np.float32)
|
||||
edge_grad_x[1:5, 2] = 1.0
|
||||
edge_grad_y = np.zeros((6, 6), dtype=np.float32)
|
||||
|
||||
reference = build_source_lattice_reference(
|
||||
source,
|
||||
target_width=2,
|
||||
target_height=2,
|
||||
phase_x=0.0,
|
||||
phase_y=0.0,
|
||||
edge_hint=edge_hint,
|
||||
edge_grad_x_hint=edge_grad_x,
|
||||
edge_grad_y_hint=edge_grad_y,
|
||||
)
|
||||
uv = torch.from_numpy(_make_regular_uv(6, 6, 2, 2, 0.0, 0.0)).to(dtype=torch.float32)
|
||||
|
||||
candidate_x, candidate_y, _, _ = _build_candidate_positions(
|
||||
torch,
|
||||
uv,
|
||||
reference,
|
||||
SolverHyperParams(),
|
||||
width=6,
|
||||
height=6,
|
||||
cell_x=3.0,
|
||||
cell_y=3.0,
|
||||
base_fraction_values=np.asarray([0.0], dtype=np.float32),
|
||||
)
|
||||
|
||||
cell_candidates = {
|
||||
(int(y), int(x))
|
||||
for y, x in zip(candidate_y[0, 0].cpu().tolist(), candidate_x[0, 0].cpu().tolist())
|
||||
}
|
||||
|
||||
assert (int(reference.edge_peak_y[0, 0]), int(reference.edge_peak_x[0, 0])) in cell_candidates
|
||||
assert len(cell_candidates) > 2
|
||||
|
||||
|
||||
def test_optimize_lattice_pixels_does_not_regress_from_snap_on_thin_feature_case() -> None:
|
||||
source = np.zeros((16, 16, 4), dtype=np.float32)
|
||||
source[4:12, 8] = np.asarray([0.95, 0.95, 0.95, 1.0], dtype=np.float32)
|
||||
source[4, 7:10] = np.asarray([0.95, 0.95, 0.95, 1.0], dtype=np.float32)
|
||||
source[11, 7] = np.asarray([0.95, 0.95, 0.95, 1.0], dtype=np.float32)
|
||||
source[10, 6] = np.asarray([0.95, 0.95, 0.95, 1.0], dtype=np.float32)
|
||||
source[9, 5] = np.asarray([0.95, 0.95, 0.95, 1.0], dtype=np.float32)
|
||||
|
||||
fake = fake_pixelize(
|
||||
source,
|
||||
upscale=9,
|
||||
phase_x=0.18,
|
||||
phase_y=-0.12,
|
||||
blur_radius=0.45,
|
||||
warp_strength=0.2,
|
||||
warp_detail=5,
|
||||
seed=11,
|
||||
)
|
||||
inference = InferenceResult(
|
||||
target_width=16,
|
||||
target_height=16,
|
||||
phase_x=0.18,
|
||||
phase_y=-0.12,
|
||||
confidence=1.0,
|
||||
top_candidates=[],
|
||||
)
|
||||
artifacts = optimize_lattice_pixels(
|
||||
fake,
|
||||
inference=inference,
|
||||
analysis=analyze_continuous_source(fake, seed=7),
|
||||
steps=4,
|
||||
seed=7,
|
||||
device="cpu",
|
||||
)
|
||||
|
||||
snap_score = source_lattice_consistency_breakdown(
|
||||
fake,
|
||||
artifacts.initial_rgba,
|
||||
target_width=16,
|
||||
target_height=16,
|
||||
phase_x=0.18,
|
||||
phase_y=-0.12,
|
||||
)["score"]
|
||||
final_score = source_lattice_consistency_breakdown(
|
||||
fake,
|
||||
artifacts.target_rgba,
|
||||
target_width=16,
|
||||
target_height=16,
|
||||
phase_x=0.18,
|
||||
phase_y=-0.12,
|
||||
)["score"]
|
||||
|
||||
assert final_score <= snap_score + 1e-6
|
||||
|
||||
|
||||
def test_optimize_lattice_pixels_emits_displacement_diagnostics() -> None:
|
||||
source = np.zeros((12, 12, 4), dtype=np.float32)
|
||||
source[..., 3] = 1.0
|
||||
source[3:9, 6, :3] = 1.0
|
||||
|
||||
inference = InferenceResult(
|
||||
target_width=6,
|
||||
target_height=6,
|
||||
phase_x=0.0,
|
||||
phase_y=0.0,
|
||||
confidence=1.0,
|
||||
top_candidates=[],
|
||||
)
|
||||
artifacts = optimize_lattice_pixels(
|
||||
source,
|
||||
inference=inference,
|
||||
analysis=analyze_continuous_source(source, seed=7),
|
||||
steps=2,
|
||||
seed=7,
|
||||
device="cpu",
|
||||
)
|
||||
|
||||
displacement = artifacts.stage_diagnostics["displacements"]
|
||||
assert {"snap", "relax_handoff", "relax_mode", "final_output"} <= set(displacement.keys())
|
||||
for stage_name in ("snap", "relax_handoff", "final_output"):
|
||||
payload = displacement[stage_name]
|
||||
assert payload["displacement_x"].shape == (6, 6)
|
||||
assert payload["displacement_y"].shape == (6, 6)
|
||||
assert payload["orthogonal_jitter_px"] >= 0.0
|
||||
|
|
@ -2,7 +2,7 @@ from __future__ import annotations
|
|||
|
||||
import numpy as np
|
||||
|
||||
from repixelizer.analysis import analyze_continuous_source
|
||||
from repixelizer.analysis import analyze_phase_field_source
|
||||
from repixelizer.phase_field import optimize_phase_field
|
||||
from repixelizer.synthetic import fake_pixelize, make_emblem
|
||||
from repixelizer.types import InferenceResult
|
||||
|
|
@ -25,7 +25,7 @@ def test_optimize_phase_field_emits_displacement_diagnostics_and_source_colors()
|
|||
artifacts = optimize_phase_field(
|
||||
source,
|
||||
inference=inference,
|
||||
analysis=analyze_continuous_source(source, seed=7),
|
||||
analysis=analyze_phase_field_source(source, seed=7),
|
||||
steps=4,
|
||||
seed=7,
|
||||
device="cpu",
|
||||
|
|
@ -65,7 +65,7 @@ def test_optimize_phase_field_moves_off_zero_when_phase_is_wrong() -> None:
|
|||
artifacts = optimize_phase_field(
|
||||
fake,
|
||||
inference=inference,
|
||||
analysis=analyze_continuous_source(fake, seed=7),
|
||||
analysis=analyze_phase_field_source(fake, seed=7),
|
||||
steps=6,
|
||||
seed=7,
|
||||
device="cpu",
|
||||
|
|
|
|||
|
|
@ -5,13 +5,13 @@ from pathlib import Path
|
|||
|
||||
import numpy as np
|
||||
|
||||
from repixelizer.analysis import analyze_continuous_source
|
||||
from repixelizer.analysis import analyze_phase_field_source
|
||||
from repixelizer.baselines import naive_resize_baseline
|
||||
from repixelizer.continuous import optimize_lattice_pixels
|
||||
from repixelizer.metrics import coherence_breakdown, foreground_reconstruction_error, source_lattice_consistency_breakdown
|
||||
from repixelizer.params import SolverHyperParams
|
||||
from repixelizer.pipeline import _run_reconstruction, _select_phase_candidate, run_pipeline
|
||||
from repixelizer.io import load_rgba, nearest_resize
|
||||
from repixelizer.phase_field import optimize_phase_field
|
||||
from repixelizer.io import nearest_resize
|
||||
from repixelizer.synthetic import fake_pixelize, make_emblem, make_sprite
|
||||
from repixelizer.types import InferenceCandidate, InferenceResult, SolverArtifacts
|
||||
|
||||
|
|
@ -30,8 +30,8 @@ def test_pipeline_writes_output_and_diagnostics(tmp_path: Path) -> None:
|
|||
assert output_path.exists()
|
||||
assert (diagnostics_dir / "run.json").exists()
|
||||
assert (diagnostics_dir / "output-preview.png").exists()
|
||||
assert (diagnostics_dir / "displacement-snap.png").exists()
|
||||
assert (diagnostics_dir / "displacement-snap-preview.png").exists()
|
||||
assert (diagnostics_dir / "displacement-initial_output.png").exists()
|
||||
assert (diagnostics_dir / "displacement-initial_output-preview.png").exists()
|
||||
import json
|
||||
|
||||
run_json = json.loads((diagnostics_dir / "run.json").read_text(encoding="utf-8"))
|
||||
|
|
@ -39,7 +39,7 @@ def test_pipeline_writes_output_and_diagnostics(tmp_path: Path) -> None:
|
|||
assert "source_structure" in run_json
|
||||
assert {"edge_f1", "exact_match_ratio", "score"} <= set(run_json["source_structure"].keys())
|
||||
assert "phase_rerank_candidates" in run_json
|
||||
assert {"snap", "relax_handoff", "relax_mode", "final_output"} <= set(run_json["optimizer_displacement"].keys())
|
||||
assert {"initial_output", "final_output"} <= set(run_json["optimizer_displacement"].keys())
|
||||
assert result.output_rgba.shape[0] == result.inference.target_height
|
||||
assert result.output_rgba.shape[1] == result.inference.target_width
|
||||
|
||||
|
|
@ -162,7 +162,7 @@ def test_fixed_tile_graph_pipeline_output_matches_refactor_baseline(tmp_path: Pa
|
|||
assert output_hash == "1f6d497a65953ab60a37fce98e69b101955e5f0e5a06a1e32167c6b8582a23f6"
|
||||
|
||||
|
||||
def test_fixed_continuous_pipeline_output_matches_refactor_baseline(tmp_path: Path) -> None:
|
||||
def test_fixed_phase_field_pipeline_output_matches_refactor_baseline(tmp_path: Path) -> None:
|
||||
source = make_emblem(24, 24)
|
||||
fake = fake_pixelize(
|
||||
source,
|
||||
|
|
@ -174,8 +174,8 @@ def test_fixed_continuous_pipeline_output_matches_refactor_baseline(tmp_path: Pa
|
|||
warp_detail=4,
|
||||
seed=9,
|
||||
)
|
||||
input_path = tmp_path / "continuous-baseline-input.png"
|
||||
output_path = tmp_path / "continuous-baseline-output.png"
|
||||
input_path = tmp_path / "phase-field-baseline-input.png"
|
||||
output_path = tmp_path / "phase-field-baseline-output.png"
|
||||
|
||||
from repixelizer.io import save_rgba
|
||||
|
||||
|
|
@ -183,7 +183,7 @@ def test_fixed_continuous_pipeline_output_matches_refactor_baseline(tmp_path: Pa
|
|||
result = run_pipeline(
|
||||
input_path,
|
||||
output_path,
|
||||
reconstruction_mode="continuous",
|
||||
reconstruction_mode="phase-field",
|
||||
target_width=24,
|
||||
target_height=24,
|
||||
phase_x=0.1,
|
||||
|
|
@ -194,7 +194,7 @@ def test_fixed_continuous_pipeline_output_matches_refactor_baseline(tmp_path: Pa
|
|||
)
|
||||
|
||||
output_hash = hashlib.sha256(np.ascontiguousarray(result.output_rgba).view(np.uint8)).hexdigest()
|
||||
assert output_hash == "404748af3c7241a6602cb91fdfed1fd7e116dd14098827e33e78c7da5e3d7903"
|
||||
assert output_hash == "9e01caa4ee4b508876d9a8360e5c8471f5ab07baf8ed1e5a08e76b9d3533c58e"
|
||||
|
||||
|
||||
def test_phase_rerank_can_override_low_confidence_inference_pick(monkeypatch) -> None:
|
||||
|
|
@ -219,11 +219,11 @@ def test_phase_rerank_can_override_low_confidence_inference_pick(monkeypatch) ->
|
|||
def __init__(self, rgba: np.ndarray) -> None:
|
||||
self.target_rgba = rgba
|
||||
|
||||
def fake_optimize_lattice_pixels(source_rgba, inference, analysis, steps, seed, device, solver_params=None):
|
||||
def fake_optimize_phase_field(source_rgba, inference, analysis, steps, seed, device, solver_params=None):
|
||||
assert steps == 0
|
||||
return DummyArtifacts(outputs[(inference.phase_x, inference.phase_y)])
|
||||
|
||||
monkeypatch.setattr("repixelizer.pipeline.optimize_lattice_pixels", fake_optimize_lattice_pixels)
|
||||
monkeypatch.setattr("repixelizer.pipeline.optimize_phase_field", fake_optimize_phase_field)
|
||||
|
||||
selected = _select_phase_candidate(source, inference, analysis=object(), seed=7, device="cpu")
|
||||
assert selected.phase_x == candidate_b.phase_x
|
||||
|
|
@ -247,7 +247,7 @@ def test_phase_rerank_can_override_to_better_size_candidate(monkeypatch) -> None
|
|||
def __init__(self, rgba: np.ndarray) -> None:
|
||||
self.target_rgba = rgba
|
||||
|
||||
def fake_optimize_lattice_pixels(source_rgba, inference, analysis, steps, seed, device, solver_params=None):
|
||||
def fake_optimize_phase_field(source_rgba, inference, analysis, steps, seed, device, solver_params=None):
|
||||
rgba = np.zeros((inference.target_height, inference.target_width, 4), dtype=np.float32)
|
||||
return DummyArtifacts(rgba)
|
||||
|
||||
|
|
@ -256,7 +256,7 @@ def test_phase_rerank_can_override_to_better_size_candidate(monkeypatch) -> None
|
|||
return {"score": 0.10}
|
||||
return {"score": 0.01}
|
||||
|
||||
monkeypatch.setattr("repixelizer.pipeline.optimize_lattice_pixels", fake_optimize_lattice_pixels)
|
||||
monkeypatch.setattr("repixelizer.pipeline.optimize_phase_field", fake_optimize_phase_field)
|
||||
monkeypatch.setattr("repixelizer.pipeline.source_lattice_consistency_breakdown", fake_support)
|
||||
|
||||
selected = _select_phase_candidate(source, inference, analysis=object(), seed=7, device="cpu")
|
||||
|
|
@ -281,7 +281,7 @@ def test_phase_rerank_rejects_large_size_jump(monkeypatch) -> None:
|
|||
def __init__(self, rgba: np.ndarray) -> None:
|
||||
self.target_rgba = rgba
|
||||
|
||||
def fake_optimize_lattice_pixels(source_rgba, inference, analysis, steps, seed, device, solver_params=None):
|
||||
def fake_optimize_phase_field(source_rgba, inference, analysis, steps, seed, device, solver_params=None):
|
||||
rgba = np.zeros((inference.target_height, inference.target_width, 4), dtype=np.float32)
|
||||
return DummyArtifacts(rgba)
|
||||
|
||||
|
|
@ -290,7 +290,7 @@ def test_phase_rerank_rejects_large_size_jump(monkeypatch) -> None:
|
|||
return {"score": 0.10}
|
||||
return {"score": 0.01}
|
||||
|
||||
monkeypatch.setattr("repixelizer.pipeline.optimize_lattice_pixels", fake_optimize_lattice_pixels)
|
||||
monkeypatch.setattr("repixelizer.pipeline.optimize_phase_field", fake_optimize_phase_field)
|
||||
monkeypatch.setattr("repixelizer.pipeline.source_lattice_consistency_breakdown", fake_support)
|
||||
|
||||
selected = _select_phase_candidate(source, inference, analysis=object(), seed=7, device="cpu")
|
||||
|
|
@ -314,7 +314,7 @@ def test_select_phase_candidate_can_skip_phase_rerank(monkeypatch) -> None:
|
|||
def fail(*args, **kwargs):
|
||||
raise AssertionError("phase rerank probe should not run when disabled")
|
||||
|
||||
monkeypatch.setattr("repixelizer.pipeline.optimize_lattice_pixels", fail)
|
||||
monkeypatch.setattr("repixelizer.pipeline.optimize_phase_field", fail)
|
||||
selected = _select_phase_candidate(
|
||||
source,
|
||||
inference,
|
||||
|
|
@ -356,35 +356,6 @@ def test_select_phase_candidate_skips_phase_rerank_for_tile_graph(monkeypatch) -
|
|||
assert selected.target_height == candidate_a.target_height
|
||||
|
||||
|
||||
def test_select_phase_candidate_skips_phase_rerank_for_phase_field(monkeypatch) -> None:
|
||||
source = np.zeros((8, 8, 4), dtype=np.float32)
|
||||
candidate_a = InferenceCandidate(target_width=8, target_height=8, phase_x=0.0, phase_y=0.0, score=0.9, breakdown={})
|
||||
candidate_b = InferenceCandidate(target_width=10, target_height=10, phase_x=0.2, phase_y=0.2, score=0.89, breakdown={})
|
||||
inference = InferenceResult(
|
||||
target_width=8,
|
||||
target_height=8,
|
||||
phase_x=0.0,
|
||||
phase_y=0.0,
|
||||
confidence=0.0,
|
||||
top_candidates=[candidate_a, candidate_b],
|
||||
)
|
||||
|
||||
def fail(*args, **kwargs):
|
||||
raise AssertionError("phase-field phase rerank probe should not run")
|
||||
|
||||
monkeypatch.setattr("repixelizer.pipeline.optimize_phase_field", fail)
|
||||
selected = _select_phase_candidate(
|
||||
source,
|
||||
inference,
|
||||
analysis=object(),
|
||||
seed=7,
|
||||
device="cpu",
|
||||
reconstruction_mode="phase-field",
|
||||
)
|
||||
assert selected.target_width == candidate_a.target_width
|
||||
assert selected.target_height == candidate_a.target_height
|
||||
|
||||
|
||||
def test_pipeline_runs_tile_graph_once_without_phase_probe_reuse(tmp_path: Path, monkeypatch) -> None:
|
||||
source = np.zeros((6, 6, 4), dtype=np.float32)
|
||||
source[..., 3] = 1.0
|
||||
|
|
@ -502,7 +473,7 @@ def test_pipeline_runs_phase_field_mode(tmp_path: Path, monkeypatch) -> None:
|
|||
)
|
||||
|
||||
monkeypatch.setattr("repixelizer.pipeline.infer_lattice", lambda *args, **kwargs: inference)
|
||||
monkeypatch.setattr("repixelizer.pipeline.analyze_continuous_source", lambda *args, **kwargs: DummyAnalysis())
|
||||
monkeypatch.setattr("repixelizer.pipeline.analyze_phase_field_source", lambda *args, **kwargs: DummyAnalysis())
|
||||
monkeypatch.setattr("repixelizer.pipeline.optimize_phase_field", fake_optimize_phase_field)
|
||||
|
||||
result = run_pipeline(
|
||||
|
|
@ -546,7 +517,7 @@ def test_pipeline_fixed_target_and_phase_skip_search_inference(tmp_path: Path, m
|
|||
def fake_infer_fixed(*args, **kwargs):
|
||||
return inference
|
||||
|
||||
def fake_optimize_lattice_pixels(source_rgba, inference, analysis, steps, seed, device, solver_params=None):
|
||||
def fake_optimize_phase_field(source_rgba, inference, analysis, steps, seed, device, solver_params=None):
|
||||
rgba = np.zeros((inference.target_height, inference.target_width, 4), dtype=np.float32)
|
||||
rgba[..., 3] = 1.0
|
||||
return SolverArtifacts(
|
||||
|
|
@ -559,8 +530,8 @@ def test_pipeline_fixed_target_and_phase_skip_search_inference(tmp_path: Path, m
|
|||
|
||||
monkeypatch.setattr("repixelizer.pipeline.infer_lattice", fail_infer)
|
||||
monkeypatch.setattr("repixelizer.pipeline.infer_fixed_lattice", fake_infer_fixed)
|
||||
monkeypatch.setattr("repixelizer.pipeline.analyze_continuous_source", lambda *args, **kwargs: DummyAnalysis())
|
||||
monkeypatch.setattr("repixelizer.pipeline.optimize_lattice_pixels", fake_optimize_lattice_pixels)
|
||||
monkeypatch.setattr("repixelizer.pipeline.analyze_phase_field_source", lambda *args, **kwargs: DummyAnalysis())
|
||||
monkeypatch.setattr("repixelizer.pipeline.optimize_phase_field", fake_optimize_phase_field)
|
||||
|
||||
result = run_pipeline(
|
||||
input_path,
|
||||
|
|
@ -603,7 +574,7 @@ def test_phase_rerank_can_accept_low_confidence_size_jump_with_strong_support(mo
|
|||
candidate_b.target_width: np.ones((candidate_b.target_height, candidate_b.target_width, 4), dtype=np.float32),
|
||||
}
|
||||
|
||||
def fake_optimize_lattice_pixels(source_rgba, inference, analysis, steps, seed, device, solver_params=None):
|
||||
def fake_optimize_phase_field(source_rgba, inference, analysis, steps, seed, device, solver_params=None):
|
||||
return DummyArtifacts(outputs[inference.target_width])
|
||||
|
||||
def fake_support(source_rgba, output_rgba, *, target_width, target_height, phase_x, phase_y):
|
||||
|
|
@ -618,7 +589,7 @@ def test_phase_rerank_can_accept_low_confidence_size_jump_with_strong_support(mo
|
|||
def fake_concentration(rgba):
|
||||
return 0.18 if np.mean(rgba) < 0.1 else 0.31
|
||||
|
||||
monkeypatch.setattr("repixelizer.pipeline.optimize_lattice_pixels", fake_optimize_lattice_pixels)
|
||||
monkeypatch.setattr("repixelizer.pipeline.optimize_phase_field", fake_optimize_phase_field)
|
||||
monkeypatch.setattr("repixelizer.pipeline.source_lattice_consistency_breakdown", fake_support)
|
||||
monkeypatch.setattr("repixelizer.pipeline.foreground_edge_position_error", fake_edge_position)
|
||||
monkeypatch.setattr("repixelizer.pipeline.foreground_stroke_wobble_error", fake_wobble)
|
||||
|
|
@ -645,7 +616,7 @@ def test_phase_rerank_keeps_high_confidence_candidate_without_probe(monkeypatch)
|
|||
def fail(*args, **kwargs):
|
||||
raise AssertionError("rerank probe should not run for high-confidence inference")
|
||||
|
||||
monkeypatch.setattr("repixelizer.pipeline.optimize_lattice_pixels", fail)
|
||||
monkeypatch.setattr("repixelizer.pipeline.optimize_phase_field", fail)
|
||||
selected = _select_phase_candidate(source, inference, analysis=object(), seed=7, device="cpu")
|
||||
assert selected.target_width == candidate_a.target_width
|
||||
assert selected.target_height == candidate_a.target_height
|
||||
|
|
@ -685,10 +656,10 @@ def test_phase_rerank_can_prefer_better_line_metrics(monkeypatch) -> None:
|
|||
candidate_b.phase_x: np.ones((2, 2, 4), dtype=np.float32),
|
||||
}
|
||||
|
||||
def fake_optimize_lattice_pixels(source_rgba, inference, analysis, steps, seed, device, solver_params=None):
|
||||
def fake_optimize_phase_field(source_rgba, inference, analysis, steps, seed, device, solver_params=None):
|
||||
return DummyArtifacts(outputs[inference.phase_x])
|
||||
|
||||
monkeypatch.setattr("repixelizer.pipeline.optimize_lattice_pixels", fake_optimize_lattice_pixels)
|
||||
monkeypatch.setattr("repixelizer.pipeline.optimize_phase_field", fake_optimize_phase_field)
|
||||
monkeypatch.setattr("repixelizer.pipeline.source_lattice_consistency_breakdown", fake_support)
|
||||
monkeypatch.setattr("repixelizer.pipeline.foreground_edge_position_error", fake_edge_position)
|
||||
monkeypatch.setattr("repixelizer.pipeline.foreground_stroke_wobble_error", fake_wobble)
|
||||
|
|
@ -697,44 +668,3 @@ def test_phase_rerank_can_prefer_better_line_metrics(monkeypatch) -> None:
|
|||
selected = _select_phase_candidate(source, inference, analysis=object(), seed=7, device="cpu")
|
||||
assert selected.phase_x == candidate_b.phase_x
|
||||
assert selected.phase_y == candidate_b.phase_y
|
||||
|
||||
|
||||
def test_badge_fixture_candidate_beats_previous_source_fidelity_baselines() -> None:
|
||||
source = load_rgba("tests/fixtures/real/ai-badge-cleaned.png")
|
||||
inference = InferenceResult(
|
||||
target_width=170,
|
||||
target_height=170,
|
||||
phase_x=-0.2,
|
||||
phase_y=0.2,
|
||||
confidence=0.0,
|
||||
top_candidates=[],
|
||||
)
|
||||
artifacts = optimize_lattice_pixels(
|
||||
source,
|
||||
inference=inference,
|
||||
analysis=analyze_continuous_source(source, seed=7),
|
||||
steps=2,
|
||||
seed=7,
|
||||
device="cpu",
|
||||
)
|
||||
|
||||
snap_consistency = source_lattice_consistency_breakdown(
|
||||
source,
|
||||
artifacts.initial_rgba,
|
||||
target_width=170,
|
||||
target_height=170,
|
||||
phase_x=-0.2,
|
||||
phase_y=0.2,
|
||||
)["score"]
|
||||
final_consistency = source_lattice_consistency_breakdown(
|
||||
source,
|
||||
artifacts.target_rgba,
|
||||
target_width=170,
|
||||
target_height=170,
|
||||
phase_x=-0.2,
|
||||
phase_y=0.2,
|
||||
)["score"]
|
||||
|
||||
assert final_consistency <= 0.1494
|
||||
assert final_consistency <= 0.1369
|
||||
assert final_consistency <= snap_consistency + 1e-6
|
||||
|
|
|
|||
Loading…
Reference in a new issue