Repository navigation
A segmentation model for Object Selection, a fill model for Content-Aware Fill - #75
Merged
Merged
Conversation
…tent-Aware Fill The two tools that were still heuristics run models now, and neither model is Adobe's. Object Selection runs U^2-Net over a crop around the box you drew, because a box round an object is a picture whose subject is that object, which is the one question that network answers. The map comes back soft and at the resolution it thinks in, so the boundary is then settled against the picture's own colours: the two sides of a real edge are two colours, and each uncertain pixel belongs to the one it is nearer. The map is deliberately *not* stretched over its own range the way the reference implementation stretches it -- a selection tool has to be able to come back empty, and a stretch turns a picture of nothing into a map of noise. When it does come back empty the old reading of the box, its border as a sample of the background, runs instead. Content-Aware Fill is three stages, each doing what the next cannot. A 723k-parameter network trained here predicts the region back and gets the layout -- a horizon that continues, a wall that stays a wall. Exemplar-based patch synthesis (Criminisi) then rebuilds the hole out of patches of the photograph itself, scored against the network's answer where there is no evidence, so the texture in a filled hole is real texture from this picture rather than a network's average of every picture. Finally the mismatch round the seam is measured and relaxed across the hole, which is the one thing the old diffusion was always good at. Diffusion is still there as the seed when the model cannot run, and as the whole answer when there is nothing to copy from either. The fill network trained on 17,746 CC BY photographs from Open Images and four hundred thousand holes -- rectangles and free-form strokes, because those are the shapes people draw. Held-out error in the hole 0.074. Also: `Model` reads its input's channel count from the graph rather than assuming three, because an inpainting model needs a fourth plane for the mask -- "black" and "gone" are otherwise the same pixel. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
IAmJSD
force-pushed
the
t3code/segment-and-fill
branch
from
August 29, 2026 23:05
32c47d5 to
e3d74c1
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The last two things in the README that were heuristics rather than models. Both run networks now, and neither network is Adobe's. The bullet is gone; what each one does is described where the feature is.
Object Selection
Runs U^2-Net (4.6 MB, Apache-2.0, fetched from Filter ▸ Neural Filters ▸ Manage Models) over a crop around the box you drew — a box round an object is a picture whose subject is that object, which is the one question a salient-object network answers, and it is why the network gets a crop rather than the layer.
Two things differ from the reference implementation, both because a selection tool has different needs from a background remover:
Verified in the running application: the ants trace a boxer's ears, muzzle and collar chain, not a colour threshold.
Content-Aware Fill
Three stages, each doing the part the next one cannot.
Diffusion is still there: as the seed when the model cannot run, and as the whole answer when there is nothing to copy from either.
The fill network trained on 17,746 CC BY photographs from Open Images and about four hundred thousand holes — half rectangles, half free-form strokes, because those are the shapes people draw round signage and wires. Held-out error in the hole 0.074, and the held-out detail measure is tracked alongside it, because a network that has given up and is filling holes with the average of their edges scores a respectable error and a gradient of nearly nothing.
Also
Modelreads its input's channel count from the ONNX graph rather than assuming three. An inpainting model needs a fourth plane for the mask, because "black" and "gone" are otherwise the same pixel and a network cannot be expected to guess which.run_framed's output resampling is now shared with the inpainting path.Performance
A 600×500 hole in a 1400×1400 picture fills in 3 s (it was 28 s before the hole boundary was tracked incrementally rather than rescanned per patch, and the candidate search parallelised). Ordinary fills are a few hundred milliseconds. Object Selection is about 1.5 s per drag, which is the network.
Checks
cargo fmt,cargo clippy --workspace --all-targetsandcargo test --workspaceare clean. Six new tests, including two that need no photograph in the repository: the segmentation model has to cut round a disc on a field, and it has to find nothing in fine grain — the second is what the fallback depends on. Content-Aware Fill is pinned by measuring the roughness inside a filled hole against the roughness of the real pixels round it, which is the assertion the old diffusion fill could never have passed.Both were verified in the running application, headlessly.
🤖 Generated with Claude Code