Let the model say what a thing is and the watershed say where it ends
Local masking needs to know where an image's regions are. The watershed spike (S15 arm A) found the boundaries but had no idea what any of them enclosed; its coarse levels were geometric accidents. This adds the other half and the thing that joins them. `core/dr-segment` is where region reasoning now lives — the hierarchy moves out of `dr-gpu`, which keeps only the pixel passes that are genuinely shaders. The new crate is device-free and, without its default features, model-free too: 20 of its tests need neither an adapter nor 11 MB of weights. Arm B runs YOLO26n-seg through `ort`. D13 framed inference as a choice between `ort`'s C++ runtime and the pure-Rust dependency policy; that was a false choice. `ort`'s `alternative-backend` feature unlinks the C entirely and `ort-tract` supplies the API from tract, which is pure Rust. Measured before committing to it: zero unsupported operators, 420 ms for 640x640, and correct masks on bus.jpg. No NDK problem to solve, so D13's largest tolerated exception is not needed. Arm C is `prior.rs`, and it ships because the two arms fail in opposite directions. Instance membership re-weights the merge saddles, so region pairs the model believes share an object merge early and pairs straddling its edge merge late. No boundary moves — only the order in which they dissolve — which is how the result stays pixel-accurate at every level while its coarse levels become named things. Two things the spec assumed that turned out to be false, both recorded in models/LICENCE.md: there is no usable ADE20K-trained YOLO, so the shipped vocabulary is COCO's 80 subjects and *stuff* like sky and foliage must come from arm A; and tract cannot parse a dynamic-shape export, so the graph's input is fixed and tiling is the only route to more semantic resolution. Weights are AGPL-3.0, which GPLv3 §13 permits and which makes the combined work effectively AGPL. Deliberate, not accidental. They live in Git LFS, and a build script fails with an instruction rather than embedding a pointer file when the clone lacks them.
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
//!
|
||||
//! Runs the five passes in `shaders/watershed.wgsl` over a demosaiced image
|
||||
//! and leaves a basin label per pixel on the GPU. The hierarchy built from
|
||||
//! those labels lives in [`crate::hierarchy`], which needs no device.
|
||||
//! those labels lives in [`dr_segment`], which needs no device.
|
||||
//!
|
||||
//! # Cost
|
||||
//!
|
||||
@@ -453,7 +453,7 @@ pub struct Segmentation {
|
||||
width: u32,
|
||||
height: u32,
|
||||
/// Per pixel, the linear index of its basin root. Sparse — compacted by
|
||||
/// [`crate::hierarchy::RegionField::from_roots`].
|
||||
/// [`dr_segment::RegionField::from_roots`].
|
||||
labels: wgpu::Buffer,
|
||||
/// As with `ctx` above: read only by [`Self::read_field`].
|
||||
#[cfg_attr(not(any(test, feature = "readback")), allow(dead_code))]
|
||||
@@ -475,11 +475,11 @@ impl Segmentation {
|
||||
/// **Not a shipping path** — see this module's header. Gated so it cannot
|
||||
/// be reached from a production build by accident.
|
||||
#[cfg(any(test, feature = "readback"))]
|
||||
pub fn read_field(&self) -> Result<crate::hierarchy::RegionField, GpuError> {
|
||||
pub fn read_field(&self) -> Result<dr_segment::RegionField, GpuError> {
|
||||
let n = (self.width * self.height) as usize;
|
||||
let roots: Vec<u32> = read_buffer(&self.ctx, &self.labels, n)?;
|
||||
let gradient: Vec<f32> = read_buffer(&self.ctx, &self.gradient, n)?;
|
||||
Ok(crate::hierarchy::RegionField::from_roots(
|
||||
Ok(dr_segment::RegionField::from_roots(
|
||||
&roots,
|
||||
&gradient,
|
||||
self.width as usize,
|
||||
@@ -591,7 +591,7 @@ fn read_buffer<T: bytemuck::Pod>(
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::hierarchy::MergeTree;
|
||||
use dr_segment::MergeTree;
|
||||
|
||||
fn ctx() -> Option<GpuContext> {
|
||||
match pollster::block_on(GpuContext::new_headless()) {
|
||||
|
||||
Reference in New Issue
Block a user