Fix tile-graph empty cell extraction coverage

This commit is contained in:
Meta Vens 2026-04-23 03:00:51 +01:00
commit be2c36fbd4
5 changed files with 192 additions and 31 deletions

View file

@ -24,7 +24,7 @@ Verified:
- compare-mode smoke run against a real emblem image
- the cleaned real badge fixture in `tests/fixtures/real/ai-badge-cleaned.png` still beats naive resize on source-lattice consistency on the continuous path
- the latest full-emblem tile-graph atomic probe under `artifacts/full-emblem-tile-graph-atomic-v3-cuda/` lands at `0.0224` source-fidelity, beating the older full-emblem tile-graph CUDA baseline at `0.0283`
- the new algorithm map in `docs/tile-graph-algorithm-map.md` confirms that the pinned `126x126` tile-graph badge collapse is already present in the tile-graph initial assignment; the fixed-lattice pipeline path itself is reproducing that bad state faithfully rather than introducing it
- the new algorithm map in `docs/tile-graph-algorithm-map.md` confirms that the pinned `126x126` tile-graph badge collapse is already present in the tile-graph initial assignment; the fixed-lattice pipeline path itself is reproducing that bad state faithfully rather than introducing it, and the newer extraction coverage fix now guarantees that occupied output cells are not silently losing their source-region bucket under the corrected full-size lattice mapping
## Status after adjacency-first pass
@ -67,13 +67,14 @@ What landed:
- `tile_graph.py` now has a process-local model cache keyed by source content, lattice choice, device, and build-affecting tile-graph params
- `tests/test_inference.py`, `tests/test_pipeline.py`, `tests/test_tile_graph.py`, and `tests/test_cli.py` now cover fixed-lattice inference, rerank disabling, and cache reuse
- `docs/tile-graph-algorithm-map.md` now traces the tile-graph path stage by stage, including the exact variables that carry source data into connected components, region buckets, per-cell candidates, unary costs, and the initial assignment
- that map also records the current fixed-lattice failure anatomy on the cleaned badge: with pinned `126x126` / phase `(0.0, -0.2)`, about `50.4%` of output cells (`7999 / 15876`) have no extracted region candidate before fallback and the broken result is already bad at `tile_graph_initial_source_fidelity = 0.500884`
- that map now records the corrected fixed-lattice failure anatomy on the cleaned badge: with pinned `126x126` / phase `(0.0, -0.2)`, occupied output cells are no longer losing extracted region buckets after the new overlap fill pass, yet the broken result is still already bad at `tile_graph_initial_source_fidelity = 0.500884`
Current implementation note:
- the earlier profiling result still stands: on the searched badge path, the solver loop is not the problem; the heavy costs are `infer_lattice(...)`, low-confidence phase rerank probes, and `_extract_source_region_tiles(...)`
- the new direct-control path is specifically for dodging those costs during iteration when we already know which lattice we want to inspect
- on the cleaned badge at pinned `126x126` / phase `(0.0, -0.2)`, a fixed-lattice CUDA `tile-graph` run now took about `10.2s` on the first same-process run and about `2.1s` on the cached rerun, with the same output and a reported `tile_graph_model_cache_hit` on the second pass
- the current deep-dive diagnosis is that the fixed-lattice garbling is not a wrapper bug and not mainly a parity-solver bug; it is being born in lattice-conditioned reference building, source-region cutting/projection, candidate starvation, and the first unary argmin assignment
- the extraction coverage bug turned out to be real but secondary: the new `_extract_source_region_tiles(...)` overlap fill pass now guarantees that any output cell containing opaque sampled source pixels gets at least one extracted region bucket, but the pinned `126x126` badge output remains numerically unchanged (`0.4998626`), which narrows the remaining failure to candidate ranking and lattice-conditioned reference usage rather than empty region buckets
- the hybrid remains intentionally conservative: it only biases tile-graph's unary cost with the continuous prepass layout and does not yet replace the pairwise objective or the source-region builder
- on the cleaned badge, that conservative hybrid still helps: the latest run under `artifacts/badge-hybrid-v2-cuda/` lands at `0.1785`, improving on the current tile-graph badge baseline at `0.1832`
- the hybrid is still far behind the stronger continuous badge result (`0.0832`), so the seam looks promising but it is not yet enough to solve the real contour problem by itself

View file

@ -19,6 +19,7 @@ On the current broken badge run:
- phase: `(0.0, -0.2)`
- `tile_graph_initial_source_fidelity = 0.500884`
- `tile_graph_final_source_fidelity = 0.499863`
- every output cell that contains opaque sampled source pixels now does receive at least one extracted region candidate under the corrected full-size lattice mapping
That tiny change means the parity-update loop is not the main failure. The model build and initial assignment are.
@ -639,28 +640,17 @@ Directly measured on `tests/fixtures/real/ai-badge-cleaned.png` with pinned `126
- connected components after segmentation: `2499`
- output cells: `15876`
- edge cells by `source_reference.edge_strength`: `1610`
Region-bucket statistics before fallback:
- cells with no extracted source-region candidates at all: `7999 / 15876` (`50.4%`)
- edge cells with no extracted source-region candidates: `325 / 1610` (`20.2%`)
- mean raw region candidates per cell: `1.24`
- mean selected region candidates per cell before fallback: `0.93`
Selection histogram before fallback:
- `7999` cells: `0` region candidates survive
- `1829` cells: `1`
- `5496` cells: `2`
- `306` cells: `3`
- `181` cells: `4`
- `51` cells: `5`
- `14` cells: `6`
- output cells with any opaque sampled source pixel under the full-size lattice mapping: `8167`
- output cells with any extracted source-region bucket after the empty-cell fill pass: `8169`
- occupied output cells still missing extracted region buckets: `0`
- output cells with no extracted region bucket are now background-only cells by design: `7707`
What that means:
- about half the grid gets no source-region candidate at all and must fall back to lattice-derived anchors
- those anchors come from `source_reference`, which is itself conditioned on the pinned lattice
- connected-components still ignore pixels below the alpha threshold, so background-only cells do not get source-region buckets from this stage
- an earlier draft of this document overstated the loss by comparing sampled pixels against `lattice_indices(...)` on the downsampled grid instead of projecting sampled source coordinates back onto the full-size lattice; that comparison was wrong and has now been corrected
- the missing-bucket bug on occupied cells was real and is now fixed
- the fixed `126x126` output is still broken anyway, so empty extracted buckets were not the dominant cause of the collapse
So if the pinned lattice is poor for tile-graph, the fallback path is poisoned immediately.
@ -730,14 +720,20 @@ is tiny.
So the parity refinement loop is not "destroying" a good layout. It is starting from a bad one.
### 4. Half the grid falling back is a huge clue
### 4. The missing-bucket bug was real, but it was not the main collapse
When `7999` cells have no extracted region candidate:
The extraction stage did have a real bug:
- the model is not primarily selecting from source-owned cut tiles
- it is primarily leaning on lattice-derived fallback anchors
- it could emit source-region windows by center projection and still leave some occupied output cells without a source-region candidate
That makes the algorithm much more sensitive to lattice misfit than it looks from the outside.
That is now fixed by a final overlap-based fill pass, and with the corrected full-size lattice mapping:
- occupied output cells missing extracted buckets: `0`
But the fixed `126x126` output is still effectively unchanged after that fix.
That means the dominant collapse is not "foreground cells had no extracted region bucket at all."
It is happening later, through the way lattice-conditioned references and unary ranking choose between the candidates that do exist.
### 5. The fixed-126 run is harsher because it flips extraction stride
@ -777,10 +773,13 @@ It is not yet:
That distinction explains why fixing the lattice can collapse the result so dramatically.
## The Two Most Important Current Findings
## The Most Important Current Findings
1. The fixed-lattice pipeline path is correct.
The corruption is not being added by the wrapper.
2. The tile-graph initial assignment is already bad on the broken `126x126` case.
The problem lives in lattice-conditioned reference building, source-region cutting/projection, candidate starvation, or unary selection before pairwise refinement has much chance to help.
2. The extraction stage really did need an exhaustiveness fix.
Occupied output cells are no longer silently losing their source-region bucket under the corrected full-size lattice mapping.
3. The tile-graph initial assignment is still bad on the broken `126x126` case even after that fix.
So the remaining problem lives in lattice-conditioned reference building, candidate truncation, and unary selection before pairwise refinement has much chance to help.