Cut portrait ballast from tile-graph core

This commit is contained in:
Meta Vens 2026-04-23 04:59:15 +01:00
commit 8be09a5786
10 changed files with 677 additions and 1040 deletions

View file

@ -154,7 +154,7 @@ def test_fixed_tile_graph_pipeline_output_matches_refactor_baseline(tmp_path: Pa
)
output_hash = hashlib.sha256(np.ascontiguousarray(result.output_rgba).view(np.uint8)).hexdigest()
assert output_hash == "31e3bc2cbb802a8d11bf00fbeb73772f7fa4934e5f187888d6f0d5b356f36ae9"
assert output_hash == "9dea6030fc17cec03703ef0efac076255b925e90d4bc381cd2185229ed8006d6"
def test_fixed_continuous_pipeline_output_matches_refactor_baseline(tmp_path: Path) -> None:

View file

@ -2,7 +2,7 @@ from __future__ import annotations
import numpy as np
from repixelizer.source_reference import build_source_lattice_reference, build_tile_graph_source_reference
from repixelizer.source_reference import build_source_lattice_reference
def test_source_lattice_reference_recovers_stable_cell_colors() -> None:
@ -56,35 +56,6 @@ def test_source_lattice_reference_tracks_edge_peaks_and_gradients() -> None:
assert np.all(reference.edge_grad_x[:, 0] == 1.0)
assert np.all(reference.edge_grad_y[:, 0] == 0.0)
def test_tile_graph_source_reference_matches_continuous_anchor_fields() -> None:
source = np.zeros((6, 6, 4), dtype=np.float32)
source[..., 3] = 1.0
source[:, 2, :3] = 1.0
full = build_source_lattice_reference(
source,
target_width=2,
target_height=2,
phase_x=0.0,
phase_y=0.0,
)
tile = build_tile_graph_source_reference(
source,
target_width=2,
target_height=2,
phase_x=0.0,
phase_y=0.0,
)
assert np.allclose(tile.sharp_rgba, full.sharp_rgba, atol=1e-5)
assert np.array_equal(tile.sharp_x, full.sharp_x)
assert np.array_equal(tile.sharp_y, full.sharp_y)
assert np.array_equal(tile.edge_peak_x, full.edge_peak_x)
assert np.array_equal(tile.edge_peak_y, full.edge_peak_y)
assert np.allclose(tile.edge_strength, full.edge_strength, atol=1e-5)
def test_source_lattice_reference_cpu_device_matches_default_path() -> None:
source = np.zeros((8, 8, 4), dtype=np.float32)
source[..., 3] = 1.0

View file

@ -44,6 +44,9 @@ def test_tile_graph_model_extracts_candidates_and_adjacency_from_lattice_proposa
)
assert model.candidate_rgba.shape[0] > 4
assert model.candidate_neighbor_rgba.shape[1:] == (4, 4)
assert model.candidate_neighbor_mask.shape[1:] == (4,)
assert bool(np.any(model.candidate_neighbor_mask))
choice_counts = np.diff(model.cell_candidate_offsets)
assert choice_counts.shape[0] == inference.target_width * inference.target_height
assert np.all(choice_counts >= 1)
@ -161,20 +164,19 @@ def test_tile_graph_region_extraction_covers_every_occupied_output_cell() -> Non
analysis = analyze_tile_graph_source(source, device="cpu")
cell_h = source.shape[0] / inference.target_height
cell_w = source.shape[1] / inference.target_width
source_region_stride = 2
sampled_rgba = source[::source_region_stride, ::source_region_stride].astype(np.float32)
sampled_edge = analysis.edge_map[::source_region_stride, ::source_region_stride].astype(np.float32)
sampled_y_coords = np.arange(0, source.shape[0], source_region_stride, dtype=np.int32)
sampled_x_coords = np.arange(0, source.shape[1], source_region_stride, dtype=np.int32)
sampled_y_grid, sampled_x_grid = np.meshgrid(sampled_y_coords, sampled_x_coords, indexing="ij")
sampled_flat_rgba = sampled_rgba.reshape(-1, sampled_rgba.shape[-1]).astype(np.float32)
sampled_flat_edge = sampled_edge.reshape(-1).astype(np.float32)
sampled_flat_y = sampled_y_grid.reshape(-1).astype(np.int32)
sampled_flat_x = sampled_x_grid.reshape(-1).astype(np.int32)
full_y_grid, full_x_grid = np.meshgrid(
np.arange(source.shape[0], dtype=np.int32),
np.arange(source.shape[1], dtype=np.int32),
indexing="ij",
)
flat_rgba = source.reshape(-1, source.shape[-1]).astype(np.float32)
flat_edge = analysis.edge_map.reshape(-1).astype(np.float32)
flat_y = full_y_grid.reshape(-1).astype(np.int32)
flat_x = full_x_grid.reshape(-1).astype(np.int32)
components = _segment_atomic_source_regions(
source_rgba=sampled_rgba,
edge_map=sampled_edge,
source_rgba=source,
edge_map=analysis.edge_map,
alpha_floor=params.alpha_transparent_threshold,
color_threshold=params.tile_graph_component_color_threshold,
alpha_threshold=params.tile_graph_component_alpha_threshold,
@ -182,13 +184,12 @@ def test_tile_graph_region_extraction_covers_every_occupied_output_cell() -> Non
)
region_buckets = _extract_source_region_tiles(
components=components,
flat_rgba=sampled_flat_rgba,
flat_edge=sampled_flat_edge,
flat_x=sampled_flat_x,
flat_y=sampled_flat_y,
flat_rgba=flat_rgba,
flat_edge=flat_edge,
flat_x=flat_x,
flat_y=flat_y,
cell_w=cell_w,
cell_h=cell_h,
sample_area=float(source_region_stride * source_region_stride),
target_width=inference.target_width,
target_height=inference.target_height,
phase_x=inference.phase_x,
@ -200,14 +201,14 @@ def test_tile_graph_region_extraction_covers_every_occupied_output_cell() -> Non
stroke_minor_limit_scale=params.tile_graph_stroke_minor_limit_scale,
)
opaque = sampled_flat_rgba[:, 3] >= params.alpha_transparent_threshold
opaque = flat_rgba[:, 3] >= params.alpha_transparent_threshold
coord_x = np.clip(
np.floor((sampled_flat_x.astype(np.float32) + 0.5) / cell_w - inference.phase_x).astype(np.int32),
np.floor((flat_x.astype(np.float32) + 0.5) / cell_w - inference.phase_x).astype(np.int32),
0,
inference.target_width - 1,
)
coord_y = np.clip(
np.floor((sampled_flat_y.astype(np.float32) + 0.5) / cell_h - inference.phase_y).astype(np.int32),
np.floor((flat_y.astype(np.float32) + 0.5) / cell_h - inference.phase_y).astype(np.int32),
0,
inference.target_height - 1,
)