Commit Graph
3918 Commits
Author SHA1 Message Date
Kristian Myram 47e5fa436b SAM2: isolate model worker failures by selection generation 2026-10-30 08:43:33 +01:00
Kristian Myram 5a97729703 Roto Brush: exclude native SAM2 models from browser choices (#1539) 2026-10-30 08:43:33 +01:00
Kristian Myram c4dc558a98 Roto Brush: validate GPU layouts and align object outlines (#1539) 2026-10-30 08:43:33 +01:00
Kristian Myram 365abf0f2d Roto Brush: discard failed tracks and bound SAM2 caches (#1539) 2026-10-30 08:43:33 +01:00
Kristian Myram b148397d4e #1539: keep Show Object empty when its tracked matte is missing 2026-10-30 08:43:33 +01:00
Kristian Myram 31307d15dc #1539: bound saved tracking decoders by validated plane dimensions 2026-10-30 08:43:33 +01:00
Claude 36ed77820d Roto Brush: keep saved tracking when nothing is retracked, read saved object mattes under their own keys, let Freeze use complete saved tracking without its model
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01RDvxCS8xcR28VArjzn1x7U
2026-10-30 08:43:32 +01:00
Claude 92cd555440 Roto model loading: keep the stale-load helper test-only
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01RDvxCS8xcR28VArjzn1x7U
2026-10-30 08:43:32 +01:00
Claude 020d5cf980 Roto model loading: drop a load for an old choice, key viewer frames by the active model
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01RDvxCS8xcR28VArjzn1x7U
2026-10-30 08:43:32 +01:00
Claude 66d8e5e948 SAM 2 roto tracker: review fixes (direction-limited tracking, non-blocking model reload, per-object start passes, loader dispatch, CLI errors, hints)
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01RDvxCS8xcR28VArjzn1x7U
2026-10-30 08:43:32 +01:00
Kristian Myram 6d10a6e932 S2.75: propagate saved tracking with the newly selected model 2026-10-30 08:43:32 +01:00
Kristian Myram 8a6d48cdc8 S2.74: bound pending multi-object tracking masks 2026-10-30 08:43:32 +01:00
Kristian MyramandClaude Sonnet 5.5 a0ec3e2da4 S2.73: Tiny is the recommended size (benchmarked per size); stroke count and remove button per object; download test
bench --roto per size: no larger size tracked better on the synthetic clips and
Large lost the object after it re-entered; the hints say what was measured.
The bar shows the current object's stroke count and can remove its strokes.
An env-gated test runs the in-app download of a size.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-30 08:43:32 +01:00
Kristian MyramandClaude Sonnet 5.5 ba6fee9863 S2.72: the install test covers all four SAM 2 sizes from their files
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-30 08:43:32 +01:00
Kristian MyramandClaude Sonnet 5.5 4e2b2b7e5d S2.71: the boundary view outlines each object in its own colour
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-30 08:43:32 +01:00
Kristian MyramandClaude Sonnet 5.5 f67a17e765 S2.70: each object keeps its own matte; Show Object outputs one of them
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-30 08:43:32 +01:00
Kristian MyramandClaude Sonnet 5.5 08bf6e43fe S2.69: several objects in one Roto Brush instance, tracked in one SAM 2 pass
Strokes carry an object (0 for older projects, nothing written for 0). The
tracker follows every object in one pass and the mattes are united; the
confidence of a frame is the least sure object's. Object picker in the Layer
panel's bar; roto.options/stroke/clearStrokes/status take or report objects.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-30 08:43:32 +01:00
Kristian MyramandClaude Sonnet 5.5 fd1d6e623f S2.68: document the recommended size, half-precision weights and the decoder measurements
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-30 08:43:32 +01:00
Kristian MyramandClaude Sonnet 5.5 2dfe1b8dbe S2.67: optional half-precision GPU weights (EFFECTCRAFT_SAM2_F16=1)
Halves the weight memory (Large: about 900 MB to 450 MB). Off by default: the
video logit error grows from about 0.003 to 0.06-0.12 (masks unchanged) for a
speed gain of under 10 percent.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-30 08:43:32 +01:00
Kristian MyramandClaude Sonnet 5.5 e30db42493 S2.66: Settings suggests the SAM 2 size that suits this computer
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-30 08:43:32 +01:00
Kristian MyramandClaude Sonnet 5.5 ac8765bf67 S2.65: help and bench follow all four SAM 2 sizes; tests for the size configs and detection
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-30 08:43:31 +01:00
Kristian MyramandClaude Sonnet 5.5 2acd0ca1a8 S2.64: SAM 2.1 Small, Base+ and Large, each checked against PyTorch
Hiera configs and size detection from the weights, registry entries pinned to
commits with verified SHA-256, the loader picks the size by checksum. The GPU
encoder submits once per block so Large fits in memory, and uploads no longer
panic on a lost device. Reference tests run per size on the CPU and GPU.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-30 08:43:31 +01:00
Kristian MyramandClaude Sonnet 5.5 066bb2d031 S2.44: the span bar's confidence colours, checked in a real render
egui_kittest test: a scripted tracker (sure, doubtful, unsure, absent, sure again)
tracks a layer and the Layer panel is rendered; the strip's pixels are green, amber,
red, slate and green at the right frames. ROTO_SPAN_SNAPSHOT saves the panel image.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-30 08:43:31 +01:00
Kristian MyramandClaude Sonnet 5.5 65c5eda39a S2.53: bench --roto takes the user's own clips and reports peak memory
--clip FRAMES_DIR --truth MASKS_DIR runs the trackers on image sequences with true
mattes (strokes made from the truth; nothing is bundled or copied), tested end to end.
Trackers report the most memory their banks held (peakMB column).

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-30 08:43:31 +01:00
Kristian MyramandClaude Sonnet 5.5 a39cee8104 S2.51: bench --roto --fixes counts the corrections each tracker needs
Simulated user paints a foreground stroke through the true object and a background
stroke on the biggest false positive on the first frame under IoU 0.9, up to 6
rounds. SAM 2 needs none on every clip; classical and MobileSAM need more than 6 on
occlusion and re-entry. All trackers now take strokes on any frame.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-30 08:43:31 +01:00
Kristian MyramandClaude Sonnet 5.5 7f56fd8709 S2.52: refreshed benchmark (24 frames, SAM 2 on the GPU)
Occlusion 0.491 classical / 0.494 MobileSAM / 0.989 SAM 2; re-entry 0.618 / 0.620 / 0.982.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-30 08:43:31 +01:00
Kristian MyramandClaude Sonnet 5.5 ee3498b24d S2.63: GPU memory attention and memory encoder; one shared device; CPU fallback
Memory attention (1.8e-5 vs PyTorch) and the memory encoder (2.6e-6) as wgpu kernels,
convolution and layer-norm+GELU kernels, VideoModel::load_auto picks the GPU when
there is one (EFFECTCRAFT_SAM2_DEVICE overrides) and falls back to the CPU on any GPU
error; disable_gpu switches it off mid-clip. One process-wide device (several at once
crashed the Vulkan loader). A tracked frame: 4.3 s CPU, 0.7 s on the RX 7900 GRE.
Clips tracked on the GPU match Sam2VideoModel (worst logit error 0.0032).

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-30 08:43:31 +01:00
Kristian MyramandClaude Sonnet 5.5 5c7eb3c2ae S2.62: GPU encoder (wgpu): Hiera + neck on any GPU, matches PyTorch to 7e-6
Strided batched matmul with bias, GELU/ReLU and residual in the epilogue, layer
norm, softmax, window partition, pooling, patch embedding, RoPE and neck kernels
(WGSL, all tested against CPU definitions). GpuEncoder keeps activations on the
GPU and returns the 64x64 level and the decoder's skip features. On the RX 7900
GRE one frame encodes in 0.29 s (debug build) against 2.1 s on the CPU in release;
errors 6.8e-6 vs PyTorch, 1.2e-5 vs the CPU path.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-30 08:43:31 +01:00
Kristian MyramandClaude Sonnet 5.5 921bb00ba6 S2.61: parallel bias add fused with GELU; GPU matmul spike
Candle adds a bias on one thread; the Linear layers now add it (and apply GELU
for the MLP in) in one parallel pass. Encode 2.4 s -> 2.1 s, memory attention
2.4 -> 2.3 s; reference tests unchanged. gpu_matmul example: a tiled WGSL
matmul on the RX 7900 GRE reaches 1.9-3.6 TFLOPS against 0.16-0.47 for the CPU.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-30 08:43:31 +01:00
Kristian MyramandClaude Sonnet 5.5 d6fcd4a62b S2.60: measured tracked-frame cost; bench times memory attention
A tracked frame is the encode (2.4 s) plus memory attention (2.4 s with a full
bank), about 5 s on 16 threads, not one encode as the docs said. Docs corrected;
chunked attention tried and reverted.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-30 08:43:31 +01:00
Kristian MyramandClaude Sonnet 5.5 b7c78065db S2.61: cache the sine positions, pool without permutes
Sine position encodings depend only on the sizes: built once (150 ms of a frame).
do_pool takes the maximum over grouped cells instead of permute + max_pool2d +
permute (tested equal, odd sizes included). Encode 2.6 s -> 2.4 s per frame in
release on 16 threads (3.4 s at the start of the speed work); reference tests
unchanged. Chunked global attention was tried and did not help.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-30 08:43:31 +01:00
Kristian MyramandClaude Sonnet 5.5 aab00e43fe S2.60: parallel exact GELU: encode 3.4 s -> 2.6 s per frame
Candle's gelu_erf runs on one thread and was a third of the Hiera block time.
A rayon CustomOp1 calls the same erf per element (bit-identical, tested). All
reference tests unchanged. op_bench example times the block's operations.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-30 08:43:31 +01:00
Kristian MyramandClaude Sonnet 5.5 6ecd6793a4 S2.32: unload an idle Roto Brush model after ten minutes
MaskModel::idle_secs (SAM 2 tracks its use); the engine frees a model idle for
ten minutes when no job runs, keeps the choice, and reloads it before a stroke
or a Propagate needs it. Docs: memory and limits.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-30 08:43:31 +01:00
Kristian MyramandClaude Sonnet 5.5 378dc97d7f S2.32: tracker memory and time budgets; determinism test
VideoTracker::set_budget (default 2 GiB of state, optional seconds per
propagate call) stops with Error::Budget; state_bytes reports what it holds.
Two runs of the same prompts give bit-identical masks.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-30 08:43:31 +01:00
Kristian MyramandClaude Sonnet 5.5 81faf5b4b5 S2.66: mask prompts match Sam2VideoModel
Antialiased bilinear resize as PyTorch does it, the reference's mask-as-output
path (mask is the frame's output, the decoder makes the object pointer),
VideoTracker::prompt_mask, and mask-only prompts through the tracker interface.
Prompt frame logits exact, tracking forwards and backwards within 0.0019.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-30 08:43:31 +01:00
Kristian MyramandClaude Sonnet 5.5 1ae5bb9839 S2.44: confidence on the Roto Brush span bar
Frames a tracker followed are coloured by its confidence (green, amber, red;
slate where the object was absent) and drawn taller; roto_trust reports them.
Not checked visually: no headless way to track without weights in a snapshot.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-30 08:43:31 +01:00
Kristian MyramandClaude Sonnet 5.5 0e0db685bf S2.45: a correction stroke re-tracks only the frames it changes
Chain::track tracks the frames of the span without a tracked result, in a window
that restarts at the nearest prompted frame; unchanged spans are not tracked
again. Test with a recording tracker: first pass 0..20, no second pass, then a
correction on frame 8 tracks 8..20 with that prompt only.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-30 08:43:31 +01:00
Kristian MyramandClaude Sonnet 5.5 7eb91ca44c S2.43: track several objects in one SAM 2 pass
TrackRequest takes a list of objects (each with its prompts on its frames) and
the tracker reports (object, frame, result); frame encodings are shared, objects
may start on different frames. VideoTracker::propagate_objects runs a subset.
Limits: 32 objects. Test: two discs, one prompted on frame 0 and one on frame 2.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-30 08:43:31 +01:00
Kristian MyramandClaude Sonnet 5.5 1fb51600d5 S2.65: prompt SAM 2 with a box from the classic matte on stroke frames
On real footage the stroke frame came out partial (clicks make SAM 2 pick a
part of the object). Measured on a multi-part figure: clicks only IoU 0.41,
with a box around the figure IoU 1.00. Chain::track now adds the box of the
classic engine's matte of the strokes to each prompt; a box stroke wins.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-30 08:43:31 +01:00
Claude 1eee687ebc Roto Brush: save the tracked frames in the project
The tracked frames lived only in memory, so a saved project lost them: a render in another
process (effectcraft-cli render-frame) segmented the frames again with the classic engine.
A propagate with a tracker now saves the frames it followed with the instance, in a hidden
parameter beside Freeze's (TrackCache: each frame's matte, Refine Edge band, colour models and
confidence, keyed by the inputs it was tracked from).

- They apply while the strokes and span they came from are unchanged, whichever model Settings
  choose, so a project renders the same when it reopens, without the model loaded or chosen.
- A stroke or span change makes them stale until the next Propagate. A Propagate replaces them;
  with the classic engine it leaves none.
- roto.status reports tracker.saved (the model they came from) and a notice when Settings
  choose another model.
- The save at job completion is not an undo step (the frames are a cache of the strokes) and is
  skipped if the strokes changed while tracking. Decoding checks the saved size, so a corrupt
  project is ignored rather than overflowing.

Object Matte saves nothing. Projects saved before this change open unchanged (the parameter is
filled in on open).

Tests: a saved project reopens with the model unloaded and renders the saved frames through
Chain::ensure; choosing the classic engine keeps them until a classic Propagate replaces them; a
stroke change makes them stale. The SAM 2 tests and the failing-tracker test take the Roto test
lock.

Claude-Session: https://claude.ai/code/session_0136kZtXrYo5VUWEFxWduwUD
2026-10-30 08:43:30 +01:00
Claude a7417b578d Roto Brush: don't run the classic engine silently under a selected model
With SAM 2 (or MobileSAM) chosen, a propagate that started before the model had loaded ran
the whole job on the classic engine and reported nothing. The chosen model is now in use
before a job that segments with it starts (Roto Brush 2.0 / 3.0 and Object Matte):

- roto.propagate and the other Roto jobs wait for a load or download under way when called with
  wait: true (bounded to 10 minutes). Without wait they refuse while the model is still loading,
  and start the load in the background. A model that is not installed, or failed to load, is
  refused either way.
- roto.status reports model {selected, installed, active, loading, error} and a notice while the
  chosen model is not the one in use. source is "model" for a frame the model segmented on its own,
  instead of "classical".
- Auto-propagate keeps edited instances pending while the model loads, and shows errors as toasts
  instead of dropping them.
- Docs: what propagate does now; tracked frames live in the session that ran propagate and are not
  saved in the project file, so a separate render process does not show them; roto.model.select
  lists sam2.1-hiera-tiny.

Tests: a selected model that is not installed refuses to propagate (no weights needed); SAM 2
selected without wait is loaded before propagate (EFFECTCRAFT_SAM2). The SAM 2 tests and the
failing-tracker test take the Roto test lock, since they share the process-wide model slot.

Claude-Session: https://claude.ai/code/session_0136kZtXrYo5VUWEFxWduwUD
2026-10-30 08:43:30 +01:00
Kristian MyramandClaude Sonnet 5.5 60ad10abeb S2.42: without a tracker the chain is exactly the classic engine
Bit-for-bit test: every frame of the Roto Brush chain equals a direct
segment_with / propagate_with call with no model.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-30 08:43:30 +01:00
Kristian MyramandClaude Sonnet 5.5 b72637bb55 S2.50: bench --roto compares classical, MobileSAM and SAM 2
--mobilesam FILE; results recorded in docs/roto-brush-sam2.md (re-entry clip:
0.632 classical, 0.499 MobileSAM, 0.975 SAM 2).

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-30 08:43:30 +01:00
Kristian MyramandClaude Sonnet 5.5 371e67f51e S2.46: document Roto Brush with SAM 2
How to install and use it, how the port was verified, speed and the benchmark.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-30 08:43:30 +01:00
Kristian MyramandClaude Sonnet 5.5 a4c0a2b9c7 S2.42: a failing tracker falls back to the classic engine
Test with a tracker that always errors: roto.propagate completes, every frame
comes from the classic engine (status source: classical), IoU unchanged.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-30 08:43:30 +01:00
Kristian MyramandClaude Sonnet 5.5 4655425d01 S2.50: bench --roto adds the SAM 2 tracker column
run_tracker follows the object with the model's video tracker on the same
synthetic clips (--sam2 FILE or the installed weights). 12 frames, dev build:
re-entry clip mean IoU 0.632 classical vs 0.975 SAM 2 (0.000 vs 0.967 after
the object returns); the other clips 0.98 vs 0.99.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-30 08:43:30 +01:00
Kristian MyramandClaude Sonnet 5.5 c1f5ff9f7d S2.41: Roto Brush follows the object with SAM 2
When the chosen model has a tracker, roto.propagate runs one tracking pass over
the span: prompts from the strokes (a handful of points, which SAM 2 trusts),
the clip tracked both ways, each frame's probability map refined by the same
graph cut with the strokes as hard constraints. Results are cached under their
own keys with a per-frame confidence and an occluded flag; roto.status reports
them (source: tracker|classical). Without a tracker nothing changes.
Real weights: IoU 0.98 on all 21 frames, confidence 0.99.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-30 08:43:30 +01:00
Kristian MyramandClaude Sonnet 5.5 a62d59da4b S2.40: SAM 2 as the Roto Brush object tracker
ObjectTracker interface in the segment crate (prompts on some frames, the
clip tracked both ways, each frame streamed with confidence and an occluded
flag), implemented by SAM 2. MaskModel::tracker() is None for other models.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-30 08:43:30 +01:00
Kristian MyramandClaude Sonnet 5.5 92ac189a49 S2.31: load SAM 2 through the install flow; SAM 2 as a MaskModel
Sam2Mask wraps the image path behind the Roto Brush's MaskModel interface
(cached frame encoding, bilinear mask resize). The engine loads the verified
weights natively (not on wasm). Checked with the real file: install, notice,
load, use by Roto Brush 3.0, deselect.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-30 08:43:30 +01:00
Kristian MyramandClaude Sonnet 5.5 e5842c0c92 S2.30: SAM 2.1 Tiny in the model registry
Apache-2.0 entry pinned to a Hugging Face commit with its SHA-256 and size,
listed in Settings > Roto Brush and installable with the existing verified
install flow. No weights are bundled.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-30 08:43:30 +01:00