Repository navigation
refactor: share propagation between sam3_track_frame and sam3_propagate_frame - #25
Merged
Merged
Conversation
…te_frame Move the duplicated code into static helpers: active/pending masklet propagation, memory encode + object pointer store, active commit + tracker update, mask-to-detection, and the post-processing. Call order and behavior are unchanged in both functions. track_frame keeps its pending masks in a scratch map, as before. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01M2qLmQ9ag49hT61V6i9qAq
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.
What / why
sam3_track_frameandsam3_propagate_framerepeated the same code almost line for line: propagating active masklets, propagating pending masklets (including memory encoding and storing the object pointer), memory encoding for active masklets,sam3_update_tracker, theadd_mask_to_resultlambda, and the resolve_overlaps / fill_holes / remove_sprinkles post-processing. This PR moves that shared code into static helpers that both public functions call.sam3_propagate_frameis now 9 statements.Helper split
sam3_propagate_masklets(tracker, state, model, masklets, fi, pm, po): propagates each masklet that has memory, updates score / last_seen / MDS, and writes the binarized mask intopm. Withposet (active masklets), the raw outputs are kept. Withnullptr(pending masklets), memory is encoded right away, one masklet at a time as before.sam3_store_propagated_memory:sam3_encode_memory+sam3_extract_obj_ptr_cpu+sam3_store_obj_ptr.sam3_commit_active_masklets: memory-encodes the active masklets inpo, then callssam3_update_tracker.sam3_add_mask_detection(was the lambda) andsam3_add_masklet_detections(loops over a masklet list and emits masks found inpm).sam3_finish_tracked_frame: resolve_overlaps, fill_holes, remove_sprinkles, thenframe_index++.Call order is unchanged in both functions. In
sam3_track_frame, pending masklets are still memory-encoded before PCS detection, and new pending masklets are still memory-encoded before the active masklets. Theno_obj_ptrF16/F32 read block has not changed at all. ThefprintfandSAM3_LOGcalls stay in the public functions, so__func__in the logs is unchanged.Verification
Parity tool (byte-compare against deterministic origin/main baselines; covers encode_image, segment_pvs, visual tracker add_instance + propagate_frame over 3 frames):
Full Release build: no errors, no new warnings. The only warnings come from ggml/stb and were already there.
sam3_track_frameis only compile-tested. There is no full SAM3 model locally. I checked its diff line by line against the original instead.Existing discrepancy (kept as is, likely a bug)
In
sam3_track_frame, the pending-masklet loop never wrote the propagated mask intopm.sam3_propagate_framedoes. So insam3_track_frame, pending masklets from earlier frames are never emitted in the result, and theirall_tracked_masksentries passed tosam3_match_detectionsare empty. This also applies to masklets promoted to active on this frame. This PR keeps that behavior on purpose:track_framepasses a scratchpending_pmmap, with a comment at the call site. Fixing it (passingpm) should be a separate PR.Diff
🤖 Generated with Claude Code
https://claude.ai/code/session_01M2qLmQ9ag49hT61V6i9qAq