adjacency-first fidelity pass
This commit is contained in:
parent
f543f2fa5a
commit
a61a160d09
13 changed files with 798 additions and 135 deletions
|
|
@ -1,8 +1,13 @@
|
|||
from __future__ import annotations
|
||||
|
||||
import numpy as np
|
||||
import torch
|
||||
|
||||
from repixelizer.continuous import _exemplar_colors, _line_pattern_loss
|
||||
from repixelizer.analysis import analyze_source
|
||||
from repixelizer.continuous import _exemplar_colors, _line_pattern_loss, optimize_uv_field
|
||||
from repixelizer.metrics import source_lattice_consistency_breakdown
|
||||
from repixelizer.synthetic import fake_pixelize
|
||||
from repixelizer.types import InferenceResult
|
||||
|
||||
|
||||
def test_line_pattern_loss_penalizes_wobbling_line() -> None:
|
||||
|
|
@ -41,3 +46,58 @@ def test_exemplar_colors_selects_an_actual_patch_sample() -> None:
|
|||
options = patches[0, 0, 0]
|
||||
|
||||
assert any(torch.allclose(exemplar, option) for option in options)
|
||||
|
||||
|
||||
def test_optimize_uv_field_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_uv_field(
|
||||
fake,
|
||||
inference=inference,
|
||||
analysis=analyze_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
|
||||
|
|
|
|||
Loading…
Reference in a new issue