Prepare lean solver for hosted shipping
This commit is contained in:
parent
2c656908e9
commit
5f2a644906
35 changed files with 1839 additions and 1948 deletions
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
## What this file is
|
||||
|
||||
This file is the forward plan and active hypothesis ledger for Repixelizer.
|
||||
This file is the forward plan for Repixelizer.
|
||||
|
||||
It is not the authoritative stage-by-stage control-flow map. That lives in
|
||||
`docs/lean-optimizer-algorithm-map.md`.
|
||||
|
|
@ -13,142 +13,118 @@ intent.
|
|||
|
||||
## Current machine
|
||||
|
||||
Repixelizer now has one live reconstruction engine:
|
||||
Repixelizer has one live reconstruction engine:
|
||||
|
||||
- `phase-field`: the canonical reconstruction engine in `src/repixelizer/phase_field.py`
|
||||
|
||||
The live pipeline is:
|
||||
|
||||
`source image -> lattice inference -> edge analysis -> phase-field reconstruction -> cleanup -> optional palette fit -> diagnostics`
|
||||
`source image -> lattice inference -> diagnostic edge preview -> fixed lattice centers -> hierarchical flatness signal -> explicit local search + lattice relaxation -> nearest source sample -> cleanup -> optional palette fit -> diagnostics`
|
||||
|
||||
Inference now splits three ways:
|
||||
Inference splits two ways:
|
||||
|
||||
- fixed lattice when the caller pins size explicitly
|
||||
- searched lattice for the full local workflow
|
||||
- direct autocorr lattice for the hosted demo path: one consensus size, no size search, no candidate rerank
|
||||
- autocorr lattice when size is inferred automatically; autocorr can surface multiple candidates, and low-confidence candidates can be preview-reranked
|
||||
|
||||
The hosted web shell now also has an auth seam:
|
||||
The hosted web shell has an auth seam:
|
||||
|
||||
- `src/repixelizer/access.py` owns the app-local access boundary and local ownership checks
|
||||
- `src/repixelizer/gui.py` owns hosted route policy, landing-page behavior, and queue/job stamping
|
||||
- `GC_ACCESS_MODE=heimdall` now lands the first real shared-auth consumer path there: provider start, backend callback receipt, local JWT verification, and httpOnly session adoption
|
||||
- `GC_ACCESS_MODE=heimdall` supports provider start, backend callback receipt, local JWT verification, and httpOnly session adoption
|
||||
- self-host and local runs stay permissive by default unless `GC_ACCESS_*` turns the seam on
|
||||
|
||||
## What is working
|
||||
|
||||
- lattice size inference are still shared and still CUDA-capable
|
||||
- `phase-field` is the only canonical reconstruction path and produces the best-looking badge result in the repo so far
|
||||
- compare mode, benchmark mode, diagnostics writing, and tuning all still work after the optimizer cutover
|
||||
- the repo now reports both:
|
||||
- `source_fidelity`: agreement with the inferred lattice portrait
|
||||
- `source_structure`: visible structural agreement at source size
|
||||
- `phase-field` is the only canonical reconstruction path.
|
||||
- The current explicit solver is fast enough for hosted interaction.
|
||||
- Compare mode, benchmark mode, diagnostics writing, GUI observer previews, and tuning harnesses exist.
|
||||
- The repo reports both `source_fidelity` and `source_structure` because lattice-only scoring can slander better-looking output.
|
||||
- Hosted landing/app flow is in place and should be the immediate product path.
|
||||
|
||||
That second metric exists because the first one was happily slandering the better-looking output.
|
||||
## Current solver shipping state
|
||||
|
||||
## Current evidence
|
||||
The current solver config is shippable, not final.
|
||||
|
||||
### Phase-field
|
||||
Useful current values:
|
||||
|
||||
Pinned badge case:
|
||||
- `phase_field_grid_alignment_weight=4.75`
|
||||
- `phase_field_local_search_radius_ratio=0.215`
|
||||
- `phase_field_local_search_blend=0.24`
|
||||
- `phase_field_local_search_move_weight=0.09`
|
||||
- `phase_field_signal_energy_power=1.4`
|
||||
- `phase_field_signal_peak_power=3.25`
|
||||
|
||||
- fixture: `tests/fixtures/real/ai-badge-cleaned.png`
|
||||
- lattice: `126x126`
|
||||
- initial lattice centers: canonical
|
||||
- steps: `48`
|
||||
Tuning lesson:
|
||||
|
||||
Useful artifacts:
|
||||
- broad local-search radius caused samples to poach neighboring features
|
||||
- the focused useful radius basin is around `0.20-0.22`
|
||||
- at that tighter radius, stronger blend became useful
|
||||
- signal knobs were not fully explored around the new basin
|
||||
|
||||
- first pinned badge run: `artifacts/phase-field-v1-badge-126/`
|
||||
- tip-focused follow-up: `artifacts/phase-field-v2-badge-126/`
|
||||
- structure-metric sanity check: `artifacts/phase-field-metric-check/`
|
||||
|
||||
What we know:
|
||||
|
||||
- the output preserves the important badge structure better than the deleted optimizer did
|
||||
- the tracked blemish is now narrow and specific: the sword-tip stroke widens too much in one local region
|
||||
- the tracked focus fixture is `tests/fixtures/real/ai-badge-tip-focus.json`
|
||||
|
||||
## Maps
|
||||
|
||||
The repo now keeps the living map:
|
||||
|
||||
- `docs/lean-optimizer-algorithm-map.md`
|
||||
|
||||
If a future pass cannot be explained cleanly against that map, it should not land.
|
||||
Detailed tuning notes live in `docs/solver-tuning-lessons-2026-04-29.md`.
|
||||
|
||||
## Current priorities
|
||||
|
||||
### 1. Fix the phase-field sword-tip blemish
|
||||
### 1. Ship the hosted experiment
|
||||
|
||||
Goal:
|
||||
|
||||
- keep the current structural win
|
||||
- stop widening the dark contour near the tapered sword tip
|
||||
- get Repixelizer online
|
||||
- stop blocking Heimdall
|
||||
- stop Heimdall from blocking StreamPixels
|
||||
|
||||
Current hypothesis:
|
||||
Practical stance:
|
||||
|
||||
- scalar weight nudges are not enough
|
||||
- the field needs better anisotropic behavior near sharp tapered contours
|
||||
- it likely needs to distinguish motion along a stroke from motion across a stroke
|
||||
|
||||
What we just learned:
|
||||
|
||||
- the later `d9fa411` phase-field tuning pass was a real regression, not paranoia
|
||||
- that pass strengthened the local edge penalty, added a spacing loss plus upper-spacing clamp, and made edge gating more aggressive
|
||||
- on the pinned badge case, it removed internal linework and changed `2433 / 15876` output cells relative to the original good `phase-field` run
|
||||
- reverting that tuning pass restores the original good badge result exactly; the fresh fixed run under `artifacts/phase-field-regression-fix-badge-126/` is byte-identical to the original `artifacts/phase-field-v1-recheck-badge-126/`
|
||||
|
||||
Tracked fixture:
|
||||
|
||||
- `tests/fixtures/real/ai-badge-tip-focus.json`
|
||||
- do not spend more time polishing solver knobs before hosted launch unless a blocking quality regression appears
|
||||
- keep hosted auth and access work isolated to `src/repixelizer/access.py` and `src/repixelizer/gui.py`
|
||||
- keep solver and pipeline code out of auth work
|
||||
|
||||
### 2. Keep lattice inference honest
|
||||
|
||||
Current stance:
|
||||
|
||||
- keep the shipped searched path grounded in autocorrelation only
|
||||
- keep automatic inference grounded in autocorrelation
|
||||
- let autocorr keep a small near-best lag plateau and use cross-axis consensus before collapsing to one lattice family
|
||||
- the hosted demo path now skips multi-size search entirely and uses one autocorr-consensus size , capped by the hosted output limit
|
||||
- do not trust the old pixel-walk / change-interval spacing path; it was cut after it kept pruning the badge away from the `126` family
|
||||
- do not keep the projected edge-energy spectral pass; it floor-hugged to `2px` / `626`-family nonsense on the dense landscape fixture and did not earn its keep
|
||||
- keep hosted demo inference on the autocorr path with candidate rerank available when confidence is low
|
||||
- do not revive the old pixel-walk / change-interval spacing path
|
||||
- do not revive the projected edge-energy spectral pass
|
||||
- treat candidate rerank as optional scaffolding, not sacred machinery
|
||||
|
||||
Future options worth exploring, if autocorr stops carrying its weight:
|
||||
### 3. Later: retune the phase-field solver deliberately
|
||||
|
||||
- distance-transform / medial-radius blob sizing on softened interiors
|
||||
- small scale-space blob-size detection (`LoG` / `DoG`)
|
||||
- blur-aware correction of observed blob width before converting to lattice size
|
||||
- tiny learned size prior trained on synthetic fake-pixel-art fixtures
|
||||
The next solver pass should begin from the current live config, not from the old
|
||||
wide-radius geometry.
|
||||
|
||||
### 3. Keep phase-field honest
|
||||
Recommended order:
|
||||
|
||||
Rules:
|
||||
1. Sweep signal knobs around `radius=0.215, blend=0.24`.
|
||||
2. Sweep movement/coherence knobs around the best signal candidate.
|
||||
3. Test combinations only after single-knob effects are understood.
|
||||
4. Validate on focused artificial cases, real character glint/symbol cases, and the badge fixture.
|
||||
5. Run full-corpus validation at the end, not during every exploratory twitch.
|
||||
|
||||
- do not reintroduce portrait layers, candidate trays, or solver-stage religions
|
||||
- if a new term lands, it must belong cleanly in the one-field objective
|
||||
- if a result looks better and the metrics disagree, fix the metrics rather than worshipping them
|
||||
Knobs still underexplored in the new basin:
|
||||
|
||||
### 4. Keep hosted auth surgery out of the solver
|
||||
|
||||
Current stance:
|
||||
|
||||
- Heimdall integration belongs in the hosted web layer, not in the reconstruction pipeline
|
||||
- queued jobs now resolve ownership from local session/account metadata instead of provider ids
|
||||
- `GC_ACCESS_MODE=heimdall` is now the real hosted path: Repixelizer creates auth attempts, asks Heimdall to start provider OAuth, accepts direct backend callbacks, verifies Heimdall Ed25519 access tokens locally, and adopts local cookie sessions without dragging provider tokens through browser URLs
|
||||
- `GC_ACCESS_MODE=trusted-header` still exists as the cheap ingress seam for local route-policy tests and reverse-proxy experiments
|
||||
- future auth work still belongs in `src/repixelizer/access.py` and `src/repixelizer/gui.py`, not in `src/repixelizer/pipeline.py`, `src/repixelizer/inference.py`, or the solver stack
|
||||
|
||||
Immediate auth follow-ups, if the user wants them:
|
||||
|
||||
- add more providers or policy bindings without changing the solver
|
||||
- surface session/logout state inside `/app/` if hosted UX needs it
|
||||
- decide whether auth attempts or adopted sessions need persistence beyond this single-process hosted runtime
|
||||
- `phase_field_signal_weight`
|
||||
- `phase_field_signal_gradient_weight`
|
||||
- `phase_field_signal_curvature_weight`
|
||||
- `phase_field_signal_level_decay`
|
||||
- `phase_field_signal_pyramid_levels`
|
||||
- `phase_field_signal_energy_power`
|
||||
- `phase_field_signal_peak_power`
|
||||
- `phase_field_local_search_move_weight`
|
||||
- `phase_field_grid_alignment_weight`
|
||||
- `phase_field_local_search_grid_weight`
|
||||
|
||||
## Guardrails
|
||||
|
||||
- prefer one clear hypothesis per pass
|
||||
- show the output after every real reconstruction run
|
||||
- keep the maps updated
|
||||
- revert or delete machinery that does not visibly earn its keep
|
||||
- Prefer one clear hypothesis per pass.
|
||||
- Show the output after every real reconstruction run when doing visual tuning.
|
||||
- Keep maps updated after code changes.
|
||||
- Revert or delete machinery that does not visibly earn its keep.
|
||||
- Do not reintroduce lattice phase, portrait layers, candidate trays, or solver-stage religions casually.
|
||||
- If a new term lands, it must belong cleanly in the one-field / one-signal / one-relaxation model.
|
||||
- If a result looks better and the metrics disagree, fix the metrics rather than worshipping them.
|
||||
|
||||
This repo already spent enough time as a Jenga tower of maybe-useful cleverness. The machine has to deserve every part.
|
||||
This repo already spent enough time as a Jenga tower of maybe-useful cleverness.
|
||||
The machine has to deserve every part.
|
||||
|
|
|
|||
|
|
@ -2,9 +2,11 @@
|
|||
|
||||
## What this file is
|
||||
|
||||
This is a map of the live `phase-field` machine in the repo right now.
|
||||
This is the source-grounded map of the live `phase-field` reconstruction machine.
|
||||
|
||||
`source image -> lattice inference -> edge scout -> fixed lattice centers -> projected displacement-field optimization -> nearest source sample -> cleanup / diagnostics`
|
||||
The current spine is:
|
||||
|
||||
`source image -> lattice inference -> diagnostic edge preview -> fixed lattice centers -> hierarchical flatness signal -> explicit local search + lattice relaxation -> nearest source sample -> cleanup / diagnostics`
|
||||
|
||||
The relevant source lives in:
|
||||
|
||||
|
|
@ -18,18 +20,19 @@ The relevant source lives in:
|
|||
|
||||
## One-sentence machine
|
||||
|
||||
The solver nails a regular grid over the source, gives every output cell a tiny `(dx, dy)` shove vector, nudges those shoves until the cells settle into quieter paint while staying in order, then samples the source once and goes home.
|
||||
The solver lays a regular grid over the source, lets each cell look in a small local window for the flattest nearby source position, blends toward that local preference, relaxes the lattice back toward coherent spacing, then samples real source pixels once and goes home.
|
||||
|
||||
## Core state
|
||||
|
||||
These are the pieces that actually matter:
|
||||
|
||||
- `inference`: chosen lattice width, height, confidence, and optional top candidates
|
||||
- `edge_map`: one normalized scout map of where the source image has strong luminance/alpha changes
|
||||
- `uv0_px`: the fixed source-space center for each output cell before any optimization
|
||||
- `disp_t`: the live displacement field, one `(dx, dy)` vector per output cell
|
||||
- `pos_px = uv0_px + disp_t`: the current sample positions in source pixel space
|
||||
- `target_rgba`: the final output grid after nearest-source sampling
|
||||
- `InferenceResult`: chosen lattice width, height, confidence, and optional top candidates
|
||||
- `edge_map`: normalized luminance/alpha diagnostic preview from `analysis.py`
|
||||
- `uv0_px`: fixed source-space center for each output cell before movement
|
||||
- `signal_map`: hierarchical flatness map built in `phase_field.py`
|
||||
- `pos`: live source-space sample positions, initialized from `uv0_px`
|
||||
- `disp = pos - uv0_px`: reported displacement field derived from live positions
|
||||
- `target_rgba`: final output grid after nearest-source sampling
|
||||
|
||||
Everything else is support scaffolding.
|
||||
|
||||
|
|
@ -37,26 +40,28 @@ Everything else is support scaffolding.
|
|||
|
||||
```mermaid
|
||||
flowchart TD
|
||||
A["Source RGBA"] --> B["Stage 0: Lattice inference<br/>pipeline.py + inference.py"]
|
||||
B --> C["Stage 1: Edge scout<br/>analysis.py"]
|
||||
C --> D["Stage 2: Phase-field prep<br/>phase_field._prepare_phase_field"]
|
||||
D --> E["uv0_px (fixed centers)<br/>disp_t = 0"]
|
||||
E --> F["Stage 3-5: Optimization loop<br/>sample patch -> compute loss -> Adam step -> project"]
|
||||
F -->|repeat for steps| F
|
||||
F --> G["Stage 6: Final nearest source sample<br/>target_rgba"]
|
||||
G --> H["Stage 7: Cleanup / palette / diagnostics<br/>pipeline.py"]
|
||||
H --> I["Output image + comparison + run.json"]
|
||||
A["Source RGBA"] --> B["Stage 0: Lattice inference"]
|
||||
B --> C["Stage 1: Diagnostic edge preview"]
|
||||
C --> D["Stage 2: Prep fixed centers + signal"]
|
||||
D --> E["uv0_px fixed centers<br/>pos = uv0_px + tiny seed noise"]
|
||||
E --> F["Stage 3: Local candidate search<br/>25 nearby positions per cell"]
|
||||
F --> G["Stage 4: Blend toward preferred positions"]
|
||||
G --> H["Stage 5: Lattice spring relaxation"]
|
||||
H -->|repeat for solver steps| F
|
||||
H --> I["Stage 6: Final nearest source sample"]
|
||||
I --> J["Stage 7: Cleanup / palette / diagnostics"]
|
||||
```
|
||||
|
||||
## How to read this machine
|
||||
## Stable core
|
||||
|
||||
The machine has one honest variable: the displacement field.
|
||||
- one chosen ruler after inference
|
||||
- one live position field
|
||||
- one direct hierarchical flatness signal
|
||||
- one local candidate choice per cell per step
|
||||
- one lattice relaxation pass to keep spacing coherent
|
||||
- honest final nearest-source sampling
|
||||
|
||||
- `uv0_px` is fixed after inference
|
||||
- `disp_t` is optimized
|
||||
- the final image comes from rounding `uv0_px + disp_t` to real source pixels
|
||||
|
||||
That means the solver is not maintaining alternate per-cell candidate sets or separate reference images during optimization. It is one field moving under one loss, with projection after each step to stop it from folding into paste.
|
||||
The current live solver is not projected Adam anymore. The old differentiable loss scaffolding has been removed; `optimize_phase_field(...)` is the explicit NumPy local-search path.
|
||||
|
||||
## Stage 0: The pipeline chooses the ruler
|
||||
|
||||
|
|
@ -64,383 +69,212 @@ That means the solver is not maintaining alternate per-cell candidate sets or se
|
|||
|
||||
- `run_pipeline(...)` in `src/repixelizer/pipeline.py`
|
||||
- `_resolve_requested_target_dims(...)` in `src/repixelizer/pipeline.py`
|
||||
- `infer_lattice(...)` and `infer_fixed_lattice(...)` in `src/repixelizer/inference.py`
|
||||
- `infer_fixed_lattice(...)` and `infer_autocorr_lattice(...)` in `src/repixelizer/inference.py`
|
||||
- `_select_candidate_with_reconstruction(...)` in `src/repixelizer/pipeline.py`
|
||||
|
||||
### Inputs
|
||||
|
||||
- source RGBA image
|
||||
- optional pinned target size / width / height
|
||||
- optional `--skip-candidate-rerank`
|
||||
- optional candidate rerank for low-confidence autocorr candidates
|
||||
|
||||
### Outputs
|
||||
|
||||
- `InferenceResult`
|
||||
- `target_width`
|
||||
- `target_height`
|
||||
- `confidence`
|
||||
- `confidence`
|
||||
- `top_candidates`
|
||||
|
||||
### What the source actually does
|
||||
|
||||
The pipeline first decides whether the lattice is:
|
||||
The pipeline decides whether the lattice is:
|
||||
|
||||
- fixed explicitly by the caller, using `infer_fixed_lattice(...)`, or
|
||||
- inferred directly from autocorr consensus, using `infer_autocorr_lattice(...)`, or
|
||||
- searched automatically by `infer_lattice(...)`
|
||||
- fixed explicitly by the caller, using `infer_fixed_lattice(...)`
|
||||
- inferred from autocorr consensus, using `infer_autocorr_lattice(...)`
|
||||
|
||||
The two automatic paths split like this:
|
||||
The automatic path estimates rough cell spacing from source edge-profile autocorrelation, keeps a tiny near-best lag plateau long enough to find cross-axis consensus, then surfaces multiple candidate lattice sizes.
|
||||
|
||||
- both paths estimate rough cell spacing from source edge-profile autocorrelation
|
||||
- both paths keep a tiny near-best lag plateau long enough to find cross-axis consensus instead of collapsing instantly to one lag
|
||||
- `infer_autocorr_lattice(...)` takes one consensus size, scores the canonical center-grid size check, and stops there
|
||||
- `infer_lattice(...)` still builds a small candidate size family, scores the canonical center-grid size check for each size, and keeps the best candidate plus top alternates
|
||||
|
||||
After that, candidate rerank may still happen, but only for `phase-field`, only when confidence is low, and only when rerank is enabled. The rerank probe is a short preview solve. It calls `_run_reconstruction(...)` with a small bounded step count, capped by both the requested solver steps and `candidate_rerank_preview_steps`.
|
||||
|
||||
That part matters. The pipeline is effectively asking:
|
||||
|
||||
`before the field starts wiggling, which lattice already looks most plausible?`
|
||||
Low-confidence autocorr candidates can still be reranked through a short preview solve. There is no separate searched-inference path in the live pipeline.
|
||||
|
||||
### Metaphor
|
||||
|
||||
This is the survey crew laying down the ruler and arguing about where the graph paper should go.
|
||||
This is the survey crew laying graph paper over the mural. Autocorr proposes a small pile of plausible rulers; the preview reranker may make them argue before the workers show up.
|
||||
|
||||
If the user pinned the lattice, the argument is over. If the hosted path is active, the crew makes one fast autocorr-backed call and moves on. If not, the crew drags the ruler around, checks a small pile of plausible alignments, and picks the one that seems most plausible before the real workers show up.
|
||||
|
||||
## Stage 1: The edge scout builds a danger map
|
||||
## Stage 1: The diagnostic edge preview builds a gauge
|
||||
|
||||
### Source
|
||||
|
||||
- `analyze_phase_field_source(...)` in `src/repixelizer/analysis.py`
|
||||
- `_compute_edge_map(...)` and `_compute_edge_map_torch(...)` in `src/repixelizer/analysis.py`
|
||||
|
||||
### Inputs
|
||||
|
||||
- source RGBA image
|
||||
- optional torch device
|
||||
|
||||
### Outputs
|
||||
|
||||
- `PhaseFieldSourceAnalysis(edge_map=...)`
|
||||
|
||||
### What the source actually does
|
||||
|
||||
The analysis stage computes a single normalized `edge_map`:
|
||||
|
||||
- luminance is derived from RGB
|
||||
- alpha is kept as a separate structure cue
|
||||
- horizontal and vertical absolute differences are measured for both luminance and alpha
|
||||
- those differences are combined into a magnitude map
|
||||
- the map is normalized to `[0, 1]`
|
||||
|
||||
That is all. The analysis output for this solver is only one edge map: a report about where the source is calm and where it is breaking into edges.
|
||||
|
||||
The map is used in two places later:
|
||||
|
||||
- inside the loss, to penalize landing on edgy regions
|
||||
- inside the smoothness term, to weaken neighbor springs across real edges
|
||||
The analysis stage computes one normalized `edge_map` from luminance and alpha differences. It marks where the source breaks into edges for diagnostics and GUI preview. It does not steer the solver; the active local-search solver follows the separate hierarchical flatness signal built directly from the source image.
|
||||
|
||||
### Metaphor
|
||||
|
||||
This stage walks the mural with a bucket of chalk and circles every crack, seam, and paint jump.
|
||||
This stage walks the mural with chalk and circles cracks, seams, and paint jumps.
|
||||
|
||||
It does not tell the solver what color to choose. It tells the solver where the floorboards are creaking.
|
||||
|
||||
## Stage 2: Prep converts the source into field-ready cargo
|
||||
## Stage 2: Prep builds fixed centers and the flatness signal
|
||||
|
||||
### Source
|
||||
|
||||
- `_prepare_phase_field(...)` in `src/repixelizer/phase_field.py`
|
||||
- `_make_regular_uv_px(...)` in `src/repixelizer/phase_field.py`
|
||||
- `_source_signal_map_np(...)` in `src/repixelizer/phase_field.py`
|
||||
- `premultiply(...)` in `src/repixelizer/io.py`
|
||||
|
||||
### Inputs
|
||||
|
||||
- source RGBA
|
||||
- chosen `InferenceResult`
|
||||
- `PhaseFieldSourceAnalysis`
|
||||
- `SolverHyperParams`
|
||||
- torch device
|
||||
|
||||
### Outputs
|
||||
|
||||
- `_PhaseFieldPrep`
|
||||
- `source_t`
|
||||
- `edge_t`
|
||||
- `uv0_px_t`
|
||||
- `uv0_norm`
|
||||
- `base_x_t`
|
||||
- `base_y_t`
|
||||
- `guidance`
|
||||
- `cell_x`, `cell_y`
|
||||
- `patch_offsets_t`
|
||||
- `width`, `height`
|
||||
|
||||
### What the source actually does
|
||||
|
||||
Prep does a few brutally practical things:
|
||||
Prep:
|
||||
|
||||
1. Premultiplies the source RGBA.
|
||||
- This makes later color differences respect alpha instead of hallucinating invisible color as if it mattered equally.
|
||||
1. Premultiplies source RGBA so transparent color does not lie.
|
||||
2. Computes `cell_x` and `cell_y` from source size and target size.
|
||||
3. Places canonical fixed centers in `uv0_px`.
|
||||
4. Builds support tensors used by diagnostics and observer snapshots.
|
||||
5. Builds `signal_map`, the live local-search attraction field.
|
||||
|
||||
2. Builds the fixed lattice centers with `_make_regular_uv_px(...)`.
|
||||
- `cell_x = source_width / target_width`
|
||||
- `cell_y = source_height / target_height`
|
||||
- centers are placed at the canonical middle of each inferred output cell before clipping to image bounds
|
||||
The current signal path is intentionally simple:
|
||||
|
||||
3. Converts the source, edge map, and lattice centers to torch tensors.
|
||||
- compute derivative energy from luminance gradient plus Laplacian magnitude at each pyramid level
|
||||
- upsample each level back to source resolution
|
||||
- accumulate the levels with `phase_field_signal_level_decay`
|
||||
- normalize the accumulated derivative energy once
|
||||
- invert it so low-gradient / low-curvature regions become attractive flatness
|
||||
- sharpen the flatness map with `phase_field_signal_peak_power`
|
||||
|
||||
4. Builds a tiny 9-point patch stencil from `phase_field_patch_extent`.
|
||||
- center
|
||||
- left / right / up / down
|
||||
- four diagonals
|
||||
What no longer happens:
|
||||
|
||||
5. Downscales the edge map to output resolution and stores it as `guidance`.
|
||||
- This is not part of the optimizer proper.
|
||||
- It is later passed into `cleanup_pixels(...)` so postprocessing can avoid sanding down high-edge regions.
|
||||
- no boundary-context reward
|
||||
- no wall mask
|
||||
- no distance transform
|
||||
- no ring/context/self-penalty signal knobs
|
||||
- no lattice phase concept
|
||||
|
||||
### Metaphor
|
||||
|
||||
This is the loading dock.
|
||||
This is the loading dock. The source gets wrapped, the ruler becomes fixed anchor points, and the solver gets a heat map where quiet paint is warm and edges are cold.
|
||||
|
||||
The source gets wrapped so transparent paint stops lying about its weight. The ruler gets converted into a neat grid of scaffold anchors. Then the solver gets handed a tiny feeler gauge: one center probe and eight little taps around it so it can ask, "am I standing in a quiet patch, or on the lip of a mess?"
|
||||
|
||||
## Stage 3: The field starts at stillness
|
||||
## Stage 3: The field starts from the ruler
|
||||
|
||||
### Source
|
||||
|
||||
- `optimize_phase_field(...)` in `src/repixelizer/phase_field.py`
|
||||
- `_nearest_source_rgba(...)` in `src/repixelizer/phase_field.py`
|
||||
|
||||
### Inputs
|
||||
|
||||
- `_PhaseFieldPrep`
|
||||
- `SolverHyperParams`
|
||||
- `steps`
|
||||
- `seed`
|
||||
|
||||
### Outputs
|
||||
|
||||
- `disp_t` initialized to zero
|
||||
- `initial_rgba`
|
||||
|
||||
### What the source actually does
|
||||
|
||||
The solver initializes:
|
||||
The live position field starts as:
|
||||
|
||||
- `disp_t = 0` everywhere
|
||||
- Adam optimizer over that tensor
|
||||
- `pos = uv0_px`
|
||||
|
||||
Then it immediately computes a baseline image by rounding the fixed lattice centers to nearest integer source pixels:
|
||||
|
||||
- `initial_x = round(uv0_px[..., 0])`
|
||||
- `initial_y = round(uv0_px[..., 1])`
|
||||
- `initial_rgba = source[initial_y, initial_x]`
|
||||
|
||||
This is the zero-displacement output. Diagnostics call this `initial_output`. It is simply "the field before it moves."
|
||||
Diagnostics emit the zero-displacement image from those canonical centers. Then a tiny seeded noise is added to `pos` so ties in the local search do not all break in perfectly identical ways.
|
||||
|
||||
### Metaphor
|
||||
|
||||
Every output cell begins with its boots directly under its shoulders.
|
||||
Every worker starts with boots under shoulders, then gets the slightest shove so a perfectly symmetric room does not trap everyone in the same argument forever.
|
||||
|
||||
Each cell starts from the lattice center and only moves if the loss gives it a reason to move.
|
||||
|
||||
## Stage 4: The loss samples the current hypothesis
|
||||
## Stage 4: Local search chooses preferred positions
|
||||
|
||||
### Source
|
||||
|
||||
- `_phase_field_loss(...)` in `src/repixelizer/phase_field.py`
|
||||
- `_sample_rgba(...)`
|
||||
- `_sample_scalar(...)`
|
||||
- `_sample_patch_rgba(...)`
|
||||
- `_sample_patch_scalar(...)`
|
||||
|
||||
### Inputs
|
||||
|
||||
- current `disp_t`
|
||||
- `_PhaseFieldPrep`
|
||||
- `SolverHyperParams`
|
||||
|
||||
### Outputs
|
||||
|
||||
- scalar loss
|
||||
- sampled RGBA at current positions
|
||||
- per-term diagnostics
|
||||
- `_choose_local_preferred_positions_np(...)` in `src/repixelizer/phase_field.py`
|
||||
- `_candidate_grid_score_np(...)` in `src/repixelizer/phase_field.py`
|
||||
|
||||
### What the source actually does
|
||||
|
||||
The live sample positions are:
|
||||
Every `phase_field_local_search_interval` steps, each sample checks a 5x5 candidate grid around its current position.
|
||||
|
||||
- `pos_px = uv0_px_t + disp_t`
|
||||
The candidate window size is:
|
||||
|
||||
The loss then samples two things around those positions:
|
||||
- `radius_x = phase_field_local_search_radius_ratio * cell_x`
|
||||
- `radius_y = phase_field_local_search_radius_ratio * cell_y`
|
||||
|
||||
- premultiplied RGBA from `source_t`
|
||||
- edge values from `edge_t`
|
||||
Each candidate is scored as:
|
||||
|
||||
Sampling is bilinear during optimization because the loss needs gradients.
|
||||
|
||||
It then computes five terms.
|
||||
|
||||
#### 4A. Local coherence
|
||||
|
||||
Code:
|
||||
|
||||
- `local_coherence = (neighbor_rgba - center_rgba[..., None, :]).abs().mean()`
|
||||
```text
|
||||
move_score * phase_field_local_search_move_weight
|
||||
+ grid_score * phase_field_local_search_grid_weight
|
||||
- signal_score * phase_field_signal_weight
|
||||
```
|
||||
|
||||
Meaning:
|
||||
|
||||
The center sample is compared against the eight patch samples around it. If the patch is internally quiet, this term stays small. If the center sits on a messy boundary or mixed cell, it rises.
|
||||
- `signal_score` rewards candidates in flat coherent source regions
|
||||
- `move_score` discourages jumping to the edge of the search window just because it can
|
||||
- `grid_score` optionally asks candidates to preserve local row/column coherence relative to immediate neighbors
|
||||
|
||||
#### 4B. Local edge penalty
|
||||
|
||||
Code:
|
||||
|
||||
- `local_edge = patch_edge.mean()`
|
||||
|
||||
Meaning:
|
||||
|
||||
The same 9-point patch is sampled from the edge map. Quiet interior regions score low; sharp edges and alpha jumps score high.
|
||||
|
||||
This is the direct shove away from "standing on a line."
|
||||
|
||||
#### 4C. Edge-aware smoothness
|
||||
|
||||
Code:
|
||||
|
||||
- midpoints between neighboring sample positions are computed
|
||||
- edge strength is sampled at those midpoints
|
||||
- weights are `exp(-edge_gate_strength * edge_mid)`
|
||||
- neighbor displacement deltas are measured in normalized cell units
|
||||
|
||||
Meaning:
|
||||
|
||||
Neighboring cells are tied together by springs, but the springs weaken when the midpoint between them crosses a real edge. So the field prefers drifting together in flat regions and breaking rank at actual structure.
|
||||
|
||||
#### 4D. Collapse penalty
|
||||
|
||||
Code:
|
||||
|
||||
- neighboring sample positions along x and y must stay at least `min_spacing_ratio * cell_size` apart
|
||||
- violations are squared with `relu(min_step - actual_step)^2`
|
||||
|
||||
Meaning:
|
||||
|
||||
This is the anti-crumple term. It stops adjacent output cells from collapsing onto the same source pixels or overtaking one another.
|
||||
|
||||
#### 4E. Magnitude prior
|
||||
|
||||
Code:
|
||||
|
||||
- normalized displacement length squared, averaged over the field
|
||||
|
||||
Meaning:
|
||||
|
||||
The field pays a small tax for wandering too far. Motion has to earn its keep, but the leash is long enough to recover from moderate starting-grid error instead of dying half a cell short of the right blob.
|
||||
The best candidate becomes that cell's preferred position.
|
||||
|
||||
### Metaphor
|
||||
|
||||
Each worker is standing on a spring-loaded square of graph paper, poking the wall in a 3x3 halo around their boot.
|
||||
Each worker looks around a tiny voting booth, asks which nearby floor tile feels calmest, and points at that tile. If the booth is too large, workers poach each other's snacks. If it is too small, nobody reaches the useful tile.
|
||||
|
||||
- If the halo feels like one calm slab of paint, good.
|
||||
- If it feels jagged and noisy, bad.
|
||||
- If neighboring workers want to drift together across a smooth region, fine.
|
||||
- If they all try to collapse into the same footprint, the constraint pushes them apart.
|
||||
|
||||
## Stage 5: Adam moves the sheet, then projection slaps it back into order
|
||||
## Stage 5: Blend and lattice relaxation move the field
|
||||
|
||||
### Source
|
||||
|
||||
- the optimization loop in `optimize_phase_field(...)`
|
||||
- `_project_displacements_in_place(...)` in `src/repixelizer/phase_field.py`
|
||||
|
||||
### Inputs
|
||||
|
||||
- current `disp_t`
|
||||
- gradients from `_phase_field_loss(...)`
|
||||
- min spacing
|
||||
- max displacement bounds
|
||||
|
||||
### Outputs
|
||||
|
||||
- updated, projected `disp_t`
|
||||
- `loss_history`
|
||||
- `optimize_phase_field(...)` in `src/repixelizer/phase_field.py`
|
||||
- `_relax_lattice_springs_np(...)` in `src/repixelizer/phase_field.py`
|
||||
- `_explicit_solver_terms_np(...)` in `src/repixelizer/phase_field.py`
|
||||
|
||||
### What the source actually does
|
||||
|
||||
For each step:
|
||||
After preferred positions are chosen:
|
||||
|
||||
1. Zero optimizer gradients.
|
||||
2. Compute the loss and its term breakdown.
|
||||
3. Backpropagate through the bilinear samples.
|
||||
4. Take an Adam step on `disp_t`.
|
||||
5. Immediately project the resulting field back into a valid shape.
|
||||
```text
|
||||
pos = pos * (1 - phase_field_local_search_blend) + preferred * phase_field_local_search_blend
|
||||
```
|
||||
|
||||
Projection is not decorative. `_project_displacements_in_place(...)` enforces:
|
||||
Then `_relax_lattice_springs_np(...)` runs three spring iterations. Horizontal neighbors are pushed toward one `cell_x` of x-spacing and same-row y-alignment. Vertical neighbors are pushed toward one `cell_y` of y-spacing and same-column x-alignment.
|
||||
|
||||
- left-to-right order with minimum x spacing
|
||||
- top-to-bottom order with minimum y spacing
|
||||
- displacement clamps of `[-max_dx, max_dx]` and `[-max_dy, max_dy]`
|
||||
- image-bound clamping on the live sample positions
|
||||
The spring step is capped:
|
||||
|
||||
So the live machine is not "pure unconstrained gradient descent." It is projected Adam on a constrained displacement sheet.
|
||||
```text
|
||||
spring_step = min(0.22, phase_field_grid_alignment_weight * 0.06)
|
||||
```
|
||||
|
||||
So grid weights above the cap are equivalent for spring strength, though they still appear in diagnostic loss terms.
|
||||
|
||||
`_explicit_solver_terms_np(...)` records a compact diagnostic loss:
|
||||
|
||||
```text
|
||||
grid_alignment * phase_field_grid_alignment_weight
|
||||
- local_signal * phase_field_signal_weight
|
||||
```
|
||||
|
||||
This is feedback for the GUI and logs. It is not a differentiable Adam objective.
|
||||
|
||||
### Metaphor
|
||||
|
||||
Adam is the part of the crew that says, "fine, slide a little left, slide a little down."
|
||||
Workers take a measured step toward their preferred tile. Then the graph paper tugs everyone back into rows and columns before the next vote.
|
||||
|
||||
Projection is the guide rail saying:
|
||||
|
||||
- you two still need to stay in order
|
||||
- nobody gets to leave the mural
|
||||
- nobody stretches farther than the leash allows
|
||||
|
||||
Without that guide rail, the field would drift into invalid configurations.
|
||||
|
||||
## Stage 6: Final sampling throws away the bilinear training wheels
|
||||
## Stage 6: Final sampling uses real source pixels
|
||||
|
||||
### Source
|
||||
|
||||
- final section of `optimize_phase_field(...)`
|
||||
- `_nearest_source_rgba(...)`
|
||||
|
||||
### Inputs
|
||||
|
||||
- final `disp_t`
|
||||
- fixed `uv0_px`
|
||||
- original source RGBA
|
||||
|
||||
### Outputs
|
||||
|
||||
- `target_rgba`
|
||||
- final `uv_field`
|
||||
- stage diagnostics
|
||||
- `_nearest_source_rgba(...)` in `src/repixelizer/phase_field.py`
|
||||
|
||||
### What the source actually does
|
||||
|
||||
After the loop:
|
||||
|
||||
1. Compute `final_px = uv0_px + disp_t`.
|
||||
2. Round those positions to integer source pixels.
|
||||
3. Index the original source RGBA with those integer positions.
|
||||
1. Round final `pos` to integer source pixels.
|
||||
2. Index the original source RGBA.
|
||||
3. Report `final_disp = pos - uv0_px` and normalized `uv_field`.
|
||||
|
||||
That last part matters. The final image is not bilinear soup. Bilinear sampling is only used inside the loss so the field can be optimized. The emitted image is made of actual source pixels.
|
||||
|
||||
The solver also packages:
|
||||
|
||||
- `uv_field` in normalized coordinates
|
||||
- `loss_history`
|
||||
- displacement diagnostics for the initial and final states
|
||||
- summary phase-field metrics like mean displacement, max displacement, and final loss terms
|
||||
The emitted image is made of actual source pixels, not bilinear soup.
|
||||
|
||||
### Metaphor
|
||||
|
||||
During training, the workers are allowed to squint and interpolate.
|
||||
During solving, workers can consider nearby tiles. At the end, everyone must plant a flag on one real brick in the wall.
|
||||
|
||||
At the end, that privilege is revoked. They must plant the flag on a real brick in the wall. The final output is a direct source-pixel choice.
|
||||
|
||||
## Stage 7: The pipeline does the boring adult work
|
||||
## Stage 7: The pipeline does cleanup, palette, and diagnostics
|
||||
|
||||
### Source
|
||||
|
||||
|
|
@ -448,41 +282,15 @@ At the end, that privilege is revoked. They must plant the flag on a real brick
|
|||
- palette handling in `src/repixelizer/pipeline.py` and `src/repixelizer/palette.py`
|
||||
- diagnostics writing in `src/repixelizer/diagnostics.py`
|
||||
|
||||
### Inputs
|
||||
|
||||
- `target_rgba`
|
||||
- `guidance_strength`
|
||||
- optional palette settings
|
||||
- diagnostics directory
|
||||
|
||||
### Outputs
|
||||
|
||||
- final saved output
|
||||
- optional palette-constrained output
|
||||
- comparison sheets
|
||||
- displacement previews
|
||||
- `run.json`
|
||||
|
||||
### What the source actually does
|
||||
|
||||
After reconstruction:
|
||||
|
||||
1. `cleanup_pixels(...)` is called.
|
||||
- Right now the default is `iterations=0`, so cleanup is usually a no-op.
|
||||
- If enabled later, it tries tiny local replacements except in high-guidance regions.
|
||||
|
||||
1. `cleanup_pixels(...)` may run, though defaults usually leave cleanup as a no-op.
|
||||
2. Optional palette quantization runs.
|
||||
3. Diagnostics are written: comparisons, overlays, alpha preview, displacement previews, and `run.json`.
|
||||
|
||||
3. Diagnostics are written:
|
||||
- source/output comparison
|
||||
- lattice overlay
|
||||
- alpha preview
|
||||
- displacement previews
|
||||
- `run.json` summary
|
||||
|
||||
### Metaphor
|
||||
|
||||
The main machine is done. This stage is just sweeping the floor, labeling the crates, and taking pictures for the insurance claim.
|
||||
Cleanup is secondary. It is not the real solver.
|
||||
|
||||
## Stage 8: The machine judges itself
|
||||
|
||||
|
|
@ -493,100 +301,46 @@ The main machine is done. This stage is just sweeping the floor, labeling the cr
|
|||
- `source_structure_breakdown(...)` in `src/repixelizer/metrics.py`
|
||||
- `_displacement_diagnostics(...)` in `src/repixelizer/phase_field.py`
|
||||
|
||||
### Inputs
|
||||
|
||||
- source image
|
||||
- initial output
|
||||
- final output
|
||||
- final displacement field
|
||||
|
||||
### Outputs
|
||||
|
||||
- `source_fidelity`
|
||||
- `source_structure`
|
||||
- displacement summaries
|
||||
- coherence summaries
|
||||
|
||||
### What the source actually does
|
||||
|
||||
The repo keeps two families of score now:
|
||||
The repo keeps two score families:
|
||||
|
||||
- `source_fidelity`
|
||||
- compares the output against a lattice-derived reference raster built from the source
|
||||
- useful, but limited by the quality of that reference
|
||||
- `source_fidelity`: agreement with a lattice-derived source reference
|
||||
- `source_structure`: visible structural agreement at source size
|
||||
|
||||
- `source_structure`
|
||||
- cares about foreground reconstruction, edge placement, wobble, edge support, and exact matches
|
||||
- closer to visible structure in the source image
|
||||
|
||||
The solver also reports displacement statistics like:
|
||||
|
||||
- mean magnitude
|
||||
- orthogonal jitter
|
||||
- local residual
|
||||
- dominant offset ratio
|
||||
|
||||
Those are the closest thing this machine has to an X-ray of its field drift.
|
||||
The solver also reports displacement statistics and the explicit local-search terms.
|
||||
|
||||
### Metaphor
|
||||
|
||||
This is the inspection bench.
|
||||
The inspection bench judges both whether the output agrees with the inferred grid and whether visible linework survived the trip.
|
||||
|
||||
The machine gets judged two ways:
|
||||
## Current tuned surface
|
||||
|
||||
- by a lattice-derived reference, which measures agreement with the inferred grid interpretation
|
||||
- by a structure-oriented view, which measures whether visible linework and edges survived the trip
|
||||
The current shippable trial config is documented in `docs/solver-tuning-lessons-2026-04-29.md` and lives in `config/solver_params.json`.
|
||||
|
||||
## Stable core
|
||||
The important tuning lesson:
|
||||
|
||||
- one fixed ruler after inference
|
||||
- one real optimization variable
|
||||
- one compact loss
|
||||
- honest final nearest-source sampling
|
||||
- explicit order-preserving projection after every step
|
||||
|
||||
These pieces all belong to the same model of the machine.
|
||||
|
||||
## Current seams
|
||||
|
||||
- low-confidence candidate rerank uses only a short preview solve, not the full optimized field
|
||||
- the edge scout only knows edge magnitude, not direction, so the solver still struggles with along-stroke versus across-stroke behavior near tapered contours
|
||||
|
||||
These are the places where the current implementation is still a little awkward or incomplete.
|
||||
- wide local-search windows caused feature poaching
|
||||
- the useful radius basin is around `0.20-0.22`
|
||||
- `radius=0.215` and `blend=0.24` are the current focused winner
|
||||
- signal knobs still need a disciplined follow-up pass around that new motion basin
|
||||
|
||||
## Guardrails
|
||||
|
||||
These are the categories of complexity that would change the nature of the solver if they came back:
|
||||
These categories of complexity should not come back casually:
|
||||
|
||||
- extra per-cell reference rasters used during optimization
|
||||
- source-derived reference images that steer the field directly
|
||||
- candidate sets or candidate trays for each cell
|
||||
- multiple sequential solver stages with separate objectives
|
||||
- repeated structural score families that appear in more than one stage
|
||||
- lattice phase search or explicit lattice phase controls
|
||||
- per-cell candidate trays that persist across stages
|
||||
- extra source-derived reference rasters steering the field directly
|
||||
- multiple sequential solver religions with separate objectives
|
||||
- cleanup pretending to be the real reconstruction engine
|
||||
|
||||
The whole point of this machine is that it stays one field, one loss, one final sample.
|
||||
The point of this machine is still one ruler, one position field, one local signal, one lattice relaxation, and one final source sample.
|
||||
|
||||
## Audit Result
|
||||
|
||||
This map is compatible with the current Epiphany workflow as long as it keeps
|
||||
doing one job: describing the live machine the repo actually runs.
|
||||
|
||||
Right now it passes that test:
|
||||
|
||||
- it names the current pipeline instead of a future fantasy machine
|
||||
- it anchors every stage to real source files
|
||||
- it keeps the prose explanation attached to the control flow instead of
|
||||
replacing it
|
||||
- it identifies the current seams and the forbidden complexity that would turn
|
||||
the solver back into a Jenga tower
|
||||
|
||||
The important boundary is simple:
|
||||
## Documentation boundaries
|
||||
|
||||
- live control-flow truth belongs here
|
||||
- active hypotheses and next cuts belong in `docs/implementation-plan.md`
|
||||
- compact re-entry instructions belong in `notes/fresh-workspace-handoff.md`
|
||||
- current shipping state and re-entry instructions belong in `notes/fresh-workspace-handoff.md`
|
||||
- durable project truth belongs in `state/map.yaml`
|
||||
|
||||
If a future pass adds directional edge awareness, anisotropic behavior, or
|
||||
another real control-flow change, update this map after the code lands. If the
|
||||
change is still a hypothesis, keep it out of this file.
|
||||
- detailed tuning lessons belong in `docs/solver-tuning-lessons-2026-04-29.md`
|
||||
- forward work belongs in `docs/implementation-plan.md`
|
||||
|
|
|
|||
Binary file not shown.
|
Before Width: | Height: | Size: 741 KiB After Width: | Height: | Size: 726 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 36 KiB After Width: | Height: | Size: 36 KiB |
266
docs/solver-tuning-lessons-2026-04-29.md
Normal file
266
docs/solver-tuning-lessons-2026-04-29.md
Normal file
|
|
@ -0,0 +1,266 @@
|
|||
# Solver tuning lessons - 2026-04-29
|
||||
|
||||
This note records what the tuning pass actually taught us, what it did not
|
||||
teach us, and how the next pass should be run without constructing another
|
||||
beautiful little swamp.
|
||||
|
||||
## Shipping state
|
||||
|
||||
The current shipped trial config is intentionally usable, not final:
|
||||
|
||||
```json
|
||||
{
|
||||
"phase_field_grid_alignment_weight": 4.75,
|
||||
"phase_field_local_search_radius_ratio": 0.215,
|
||||
"phase_field_local_search_blend": 0.24,
|
||||
"phase_field_local_search_move_weight": 0.09,
|
||||
"phase_field_signal_energy_power": 1.4,
|
||||
"phase_field_signal_peak_power": 3.25
|
||||
}
|
||||
```
|
||||
|
||||
Everything else in `config/solver_params.json` remains as previously configured.
|
||||
|
||||
The important caveat: this is a motion-geometry win, not a full signal-shape
|
||||
optimum. It is acceptable for shipping the hosted experiment, but it should not
|
||||
be treated as the final form of the phase-field solver.
|
||||
|
||||
## What the pass proved
|
||||
|
||||
The most useful discovery was that the local-search radius was much too large.
|
||||
The solver was not merely underpowered; it was letting samples inspect too much
|
||||
neighboring territory. Adjacent samples could chase the same feature, which
|
||||
looked like feature attraction but behaved like poaching.
|
||||
|
||||
Recent focused artificial results, all with:
|
||||
|
||||
```text
|
||||
grid=4.75
|
||||
blend=0.18 unless noted
|
||||
move=0.09
|
||||
energy=1.4
|
||||
peak=3.25
|
||||
```
|
||||
|
||||
showed this radius curve:
|
||||
|
||||
| Run | Radius | Score | Mean | P90 | Worst | Read |
|
||||
| --- | ---: | ---: | ---: | ---: | ---: | --- |
|
||||
| 068 | 0.40 | 0.187047 | 0.073598 | 0.278124 | 0.445583 | Previous best before lower bracket |
|
||||
| 071 | 0.32 | 0.144824 | 0.056821 | 0.169920 | 0.363593 | Big improvement; radius was still too large |
|
||||
| 075 | 0.24 | 0.128386 | 0.046622 | 0.126980 | 0.341534 | Better again |
|
||||
| 080 | 0.20 | 0.119077 | 0.046775 | 0.121492 | 0.306095 | Strong lower shoulder |
|
||||
| 081 | 0.22 | 0.116976 | 0.044065 | 0.116555 | 0.306714 | Strong local center |
|
||||
| 084 | 0.215 | 0.116584 | 0.044071 | 0.117496 | 0.304752 | Best radius point tested |
|
||||
| 085 | 0.225 | 0.121924 | 0.045445 | 0.131808 | 0.316814 | Upper side already regresses |
|
||||
|
||||
The model this supports:
|
||||
|
||||
- `radius` is the gatekeeper for whether samples solve locally or poach.
|
||||
- Very small radius eventually starves movement, as seen at `0.16`.
|
||||
- The useful basin is narrow, roughly `0.20-0.22`, with `0.215` best in the focused pass.
|
||||
- Once the search window is tight, stronger blend becomes useful because samples can move without wandering into the neighbor's lunch.
|
||||
|
||||
Blend sweep at `radius=0.215`:
|
||||
|
||||
| Run | Blend | Score | Mean | P90 | Worst | Read |
|
||||
| --- | ---: | ---: | ---: | ---: | ---: | --- |
|
||||
| 087 | 0.12 | 0.161612 | 0.062461 | 0.197631 | 0.404997 | Too timid |
|
||||
| 088 | 0.15 | 0.136534 | 0.050632 | 0.145291 | 0.356375 | Still timid |
|
||||
| 084 | 0.18 | 0.116584 | 0.044071 | 0.117496 | 0.304752 | Radius-only best |
|
||||
| 089 | 0.20 | 0.111183 | 0.041232 | 0.112633 | 0.292477 | Better |
|
||||
| 090 | 0.24 | 0.103754 | 0.038329 | 0.100917 | 0.274995 | Current focused winner |
|
||||
|
||||
The model this supports:
|
||||
|
||||
- After radius is tightened, blend must be retuned.
|
||||
- Low blend was compensating for an over-wide search area.
|
||||
- At the new radius, `0.24` is better than `0.18` on focused metrics.
|
||||
- We did not yet find the upper blend cliff. `0.24` won the tested set, but values above it still need bracketing later.
|
||||
|
||||
## What the pass did not prove
|
||||
|
||||
The pass did not exhaustively model the entire system.
|
||||
|
||||
Specifically, after finding the new `radius/blend` basin, the later tuning did
|
||||
not sweep:
|
||||
|
||||
- `phase_field_signal_weight`
|
||||
- `phase_field_signal_gradient_weight`
|
||||
- `phase_field_signal_curvature_weight`
|
||||
- `phase_field_signal_level_decay`
|
||||
- `phase_field_signal_pyramid_levels`
|
||||
- `phase_field_signal_energy_power` around the new basin
|
||||
- `phase_field_signal_peak_power` around the new basin
|
||||
- `phase_field_local_search_move_weight` around the new basin
|
||||
- `phase_field_grid_alignment_weight` around the new basin
|
||||
- `phase_field_local_search_grid_weight` around the new basin
|
||||
|
||||
Earlier experiments touched some of these in older regimes, but those results
|
||||
should not be treated as final because they were gathered before the current
|
||||
motion geometry was discovered. A signal knob can look useless when the solver
|
||||
cannot move into the signal correctly. That is exactly how we wasted time
|
||||
before.
|
||||
|
||||
The correct summary is:
|
||||
|
||||
- Current config is shippable.
|
||||
- Motion geometry is much better understood.
|
||||
- Signal shape remains underexplored in the new basin.
|
||||
- The next tuning pass should start from `radius=0.215, blend=0.24`, not from the old wide-radius config.
|
||||
|
||||
## Current mental model
|
||||
|
||||
The phase-field solver now looks like this:
|
||||
|
||||
1. Build a hierarchical flatness signal from the source image.
|
||||
2. Give each lattice sample a small local candidate window.
|
||||
3. Let it choose the locally most comfortable source position.
|
||||
4. Blend toward that local preference.
|
||||
5. Use lattice coherence pressure to keep neighboring samples from tearing the grid apart.
|
||||
|
||||
The important part is the scale separation:
|
||||
|
||||
- The signal says where coherent source positions are.
|
||||
- The local search radius says which nearby positions a sample is allowed to consider.
|
||||
- The blend says how fast the sample moves toward the chosen position.
|
||||
- The lattice coherence force says how much the grid resists local deformation.
|
||||
|
||||
The mistake was treating signal strength as the main issue while the search
|
||||
window was still too broad. A broad search window turns a good signal into a
|
||||
poaching contest.
|
||||
|
||||
## Config intents we can currently generate
|
||||
|
||||
These are educated starting points, not final recommendations:
|
||||
|
||||
### Hot focused winner
|
||||
|
||||
Use when the goal is maximum focused artificial metric improvement and the live
|
||||
visual does not look too twitchy.
|
||||
|
||||
```json
|
||||
{
|
||||
"phase_field_grid_alignment_weight": 4.75,
|
||||
"phase_field_local_search_radius_ratio": 0.215,
|
||||
"phase_field_local_search_blend": 0.24,
|
||||
"phase_field_local_search_move_weight": 0.09,
|
||||
"phase_field_signal_energy_power": 1.4,
|
||||
"phase_field_signal_peak_power": 3.25
|
||||
}
|
||||
```
|
||||
|
||||
### Balanced live trial
|
||||
|
||||
Use if the hot winner looks over-eager on real AI cases.
|
||||
|
||||
```json
|
||||
{
|
||||
"phase_field_grid_alignment_weight": 4.75,
|
||||
"phase_field_local_search_radius_ratio": 0.215,
|
||||
"phase_field_local_search_blend": 0.20,
|
||||
"phase_field_local_search_move_weight": 0.09,
|
||||
"phase_field_signal_energy_power": 1.4,
|
||||
"phase_field_signal_peak_power": 3.25
|
||||
}
|
||||
```
|
||||
|
||||
### Conservative control
|
||||
|
||||
Use if the solver starts visibly over-moving or damaging tiny details.
|
||||
|
||||
```json
|
||||
{
|
||||
"phase_field_grid_alignment_weight": 4.75,
|
||||
"phase_field_local_search_radius_ratio": 0.20,
|
||||
"phase_field_local_search_blend": 0.18,
|
||||
"phase_field_local_search_move_weight": 0.09,
|
||||
"phase_field_signal_energy_power": 1.4,
|
||||
"phase_field_signal_peak_power": 3.25
|
||||
}
|
||||
```
|
||||
|
||||
## Next tuning protocol
|
||||
|
||||
The next pass should not repeat the failed "long campaign then hope" shape.
|
||||
|
||||
Run it in phases:
|
||||
|
||||
1. Lock the current motion baseline:
|
||||
|
||||
```text
|
||||
radius=0.215
|
||||
blend=0.24
|
||||
move=0.09
|
||||
grid=4.75
|
||||
energy=1.4
|
||||
peak=3.25
|
||||
```
|
||||
|
||||
2. Sweep every signal knob once against that baseline:
|
||||
|
||||
```text
|
||||
signal_weight
|
||||
gradient_weight
|
||||
curvature_weight
|
||||
level_decay
|
||||
pyramid_levels
|
||||
energy_power
|
||||
peak_power
|
||||
```
|
||||
|
||||
3. Sweep movement/coherence knobs once against the best signal candidate:
|
||||
|
||||
```text
|
||||
move_weight
|
||||
grid_alignment_weight
|
||||
local_search_grid_weight
|
||||
local_search_interval
|
||||
max_displacement_ratio
|
||||
```
|
||||
|
||||
4. Only then test combinations.
|
||||
|
||||
5. Persist every experiment immediately with:
|
||||
|
||||
```text
|
||||
hypothesis
|
||||
patch
|
||||
score
|
||||
mean
|
||||
p90
|
||||
worst
|
||||
case-specific regressions
|
||||
interpretation
|
||||
next hypothesis
|
||||
```
|
||||
|
||||
6. Run full-corpus validation only after focused cases stop moving.
|
||||
|
||||
7. Do visual checks on real cases before shipping:
|
||||
|
||||
```text
|
||||
character eye glint
|
||||
biohazard symbol
|
||||
badge sword-tip focus
|
||||
simple crisp artificial cases
|
||||
soft artificial cases
|
||||
AI-distorted artificial cases
|
||||
```
|
||||
|
||||
## Failure mode from this pass
|
||||
|
||||
The user asked for every knob and combination to be touched first. That did not
|
||||
happen. The pass found a real, valuable motion-geometry basin, but it then
|
||||
declared too much confidence from too little coverage.
|
||||
|
||||
Do not repeat that.
|
||||
|
||||
The next agent should treat this note as a partial model:
|
||||
|
||||
- strong evidence for radius/blend behavior
|
||||
- weak evidence for signal behavior in the new basin
|
||||
- no final evidence for all-knob interactions
|
||||
|
||||
Ship the current config because the project needs to unblock Heimdall and
|
||||
StreamPixels. Come back later with a disciplined signal-first pass.
|
||||
60
docs/spec.md
60
docs/spec.md
|
|
@ -57,13 +57,14 @@ Repixelizer treats this as lattice inference plus reconstruction rather than a r
|
|||
The canonical workflow should be fully automatic:
|
||||
|
||||
1. load the source image
|
||||
2. infer lattice size
|
||||
3. analyze source structure
|
||||
4. run the `phase-field` reconstruction over the inferred lattice
|
||||
5. project that result to a real pixel grid
|
||||
6. clean up obvious discrete-grid artifacts
|
||||
7. optionally quantize to a palette
|
||||
8. write output and diagnostics
|
||||
2. infer lattice size from autocorrelation candidates, unless the caller pins it
|
||||
3. render a diagnostic edge preview
|
||||
4. build the solver's hierarchical flatness signal from the source
|
||||
5. run the `phase-field` reconstruction over the inferred lattice
|
||||
6. sample real source pixels from the final source-position field
|
||||
7. snap alpha to the final discrete mask
|
||||
8. optionally quantize to a palette
|
||||
9. write output and diagnostics
|
||||
|
||||
No manual masks or user-authored region hints are assumed in v1.
|
||||
|
||||
|
|
@ -81,6 +82,8 @@ repixelize compare input.png --out output.png
|
|||
|
||||
Supported flags:
|
||||
- `--target-size`
|
||||
- `--target-width`
|
||||
- `--target-height`
|
||||
- `--palette`
|
||||
- `--palette-mode off|fit|strict`
|
||||
- `--diagnostics-dir`
|
||||
|
|
@ -103,11 +106,11 @@ Palette constraints are optional because many generated fake-pixel-art images do
|
|||
The tool must estimate the resolution of the fake lattice being mimicked.
|
||||
|
||||
Requirements:
|
||||
- search over candidate target sizes
|
||||
- infer candidate target sizes from autocorrelation hints
|
||||
- use canonical cell centers for each candidate
|
||||
- score candidates using coherence-oriented metrics rather than reconstruction alone
|
||||
- expose the top-ranked alternatives in diagnostics
|
||||
- if `--target-size` is provided, skip size search
|
||||
- if `--target-size`, `--target-width`, or `--target-height` is provided, skip automatic inference
|
||||
|
||||
Scoring goals:
|
||||
- low isolated-pixel rate
|
||||
|
|
@ -117,42 +120,39 @@ Scoring goals:
|
|||
- lower local color chatter
|
||||
- reasonable agreement with source-derived periodicity priors
|
||||
|
||||
### 2. Source analysis
|
||||
### 2. Diagnostic analysis and solver signal
|
||||
|
||||
The solver should derive automatic guidance from the image itself:
|
||||
- edge map
|
||||
- alpha-aware source structure
|
||||
The pipeline keeps two source-derived views separate:
|
||||
|
||||
This guidance is used to preserve important boundaries while allowing smoother regions to settle into cleaner pixel clusters.
|
||||
- a diagnostic edge preview for GUI and run inspection
|
||||
- a hierarchical flatness signal that actually steers the solver
|
||||
|
||||
### 3. Phase-field optimization
|
||||
The live solver signal is built from multiscale luminance gradient and curvature energy. It rewards calm local source regions while leaving edge preview as a gauge, not a hidden steering wheel.
|
||||
|
||||
The optimizer represents each output pixel by a base lattice center plus one learned displacement vector.
|
||||
### 3. Phase-field reconstruction
|
||||
|
||||
The solver represents each output pixel as one live source-space sample position initialized at a fixed lattice center.
|
||||
|
||||
Requirements:
|
||||
- operate in premultiplied RGBA space
|
||||
- use PyTorch autograd
|
||||
- optimize a displacement field initialized at zero from the inferred lattice
|
||||
- preserve local adjacency instead of letting the sample field collapse or fold
|
||||
- initialize from canonical fixed lattice centers
|
||||
- let each sample choose from a small local candidate window
|
||||
- blend toward the locally preferred flatter source position
|
||||
- relax row and column springs so the sample field stays coherent
|
||||
- nearest-sample the original source pixels for final output
|
||||
|
||||
Loss components should include:
|
||||
- local coherence / solidity so samples settle inside fake-pixel interiors
|
||||
- edge-aware smoothing so hard boundaries stay crisp
|
||||
- anti-collapse spacing so neighboring cells do not stack onto the same source pixel
|
||||
- bounded displacement so the field does not wander off into the weeds
|
||||
The current implementation is explicit NumPy local search plus spring relaxation. It is not the old PyTorch autograd / projected-Adam displacement solver.
|
||||
|
||||
### 4. Discrete projection and cleanup
|
||||
|
||||
After the phase-field stage, the result must be treated as a true pixel grid.
|
||||
|
||||
The discrete stage should:
|
||||
- evaluate local neighborhoods
|
||||
- remove orphan pixels where possible
|
||||
- merge obvious micro-clusters
|
||||
- reduce accidental highlight static
|
||||
- avoid damaging strong guided boundaries
|
||||
- preserve source-sampled RGBA values
|
||||
- snap alpha to an opaque/transparent mask
|
||||
- leave structural repair to the solver rather than hiding confusion with a cleanup pass
|
||||
|
||||
This stage is intentionally heuristic and local in v1.
|
||||
Cleanup is intentionally small in v1. It should not become a second solver wearing a trench coat.
|
||||
|
||||
### 5. Baselines and comparison mode
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue