Papers › SAM2Long: Enhancing SAM 2 for Long Video Segmentation with a Training-Free Memory Tree

SAM2Long: Enhancing SAM 2 for Long Video Segmentation with a Training-Free Memory Tree

21 Oct 2024arXiv:2410.16268archive 2025-07-28

Shuangrui Ding, Rui Qian, Xiaoyi Dong, Pan Zhang, Yuhang Zang, Yuhang Cao, Yuwei Guo, Dahua Lin, Jiaqi Wang

The Segment Anything Model 2 (SAM 2) has emerged as a powerful foundation model for object segmentation in both images and videos, paving the way for various downstream video applications. The crucial design of SAM 2 for video segmentation is its memory module, which prompts object-aware memories from previous frames for current frame prediction. However, its greedy-selection memory design suffers from the "error accumulation" problem, where an errored or missed mask will cascade and influence the segmentation of the subsequent frames, which limits the performance of SAM 2 toward complex long-term videos. To this end, we introduce SAM2Long, an improved training-free video object segmentation strategy, which considers the segmentation uncertainty within each frame and chooses the video-level optimal results from multiple segmentation pathways in a constrained tree search manner. In practice, we maintain a fixed number of segmentation pathways throughout the video. For each frame, multiple masks are proposed based on the existing pathways, creating various candidate branches. We then select the same fixed number of branches with higher cumulative scores as the new pathways for the next frame. After processing the final frame, the pathway with the highest cumulative score is chosen as the final segmentation result. Benefiting from its heuristic search design, SAM2Long is robust toward occlusions and object reappearances, and can effectively segment and track objects for complex long-term videos. Notably, SAM2Long achieves an average improvement of 3.0 points across all 24 head-to-head comparisons, with gains of up to 5.3 points in J&F on long-term video object segmentation benchmarks such as SA-V and LVOS. The code is released at https://github.com/Mark12Ding/SAM2Long.

PaperPDFCodeCode Syntology ran

In Syntology Open this paper in Syntology's Atlas, the map of the papers in Syntology's graph and their citations.

For agents, Syntology's MCP tool lists every function and class Syntology harvested from this paper and whether it ran (how to connect): get_harvested_code_for_paper(arxiv_id="2410.16268")

Code

Syntology Ran 5 of 10 code samples harvested from 1 repository linked to this paper; 5 have no recorded run. Of those that ran: 1 ran · honoured contract; 1 ran · violated contract; 2 ran · our draft was wrong; 1 ran · fixture could not drive it.

By repository: official repository: 10 samples from 1 repository, 5 ran. The run record, sample by sample. “Ran” means executed on a synthesized input, not that the code is correct or reproduces the paper.

mark12ding/sam2long officialmentioned in papermentioned on GitHubpytorchNOASSERTION report

Repository list and official/mentioned flags are the archive's, frozen 2025-07-28. Reachability, where shown, is from one Syntology probe window (2026-09-16 to 2026-09-18); repositories not probed show nothing. GitHub stars are not tracked.

Code Syntology ran Syntology

10 samples harvested; 5 ran; 1 honoured the contract we drafted; 5 have no recorded run. Read from Syntology's graph 2026-09-24; that is when this build read the record, not when the samples ran.

1ran · honoured contract
1ran · violated contract
2ran · our draft was wrong
1ran · fixture could not drive it
5unverified

Licence: 10 of the 10 samples are pointer only, meaning Syntology does not serve that copy's text. This page shows no code text for any sample; each one links to its file in the repository.

Harvested from mark12ding/sam2long. “Ran” means the sample executed on a synthesized input. It does not mean the output is correct, and nothing here reproduces the paper's results. “Honoured” and “violated” refer to a contract Syntology drafted from the code itself; “our draft was wrong” and “fixture could not drive it” are failures of Syntology's instrument, not of the code.

Each sample ends with its code_sha256, Syntology's identity for that exact code. An agent fetches the stored sample with Syntology's MCP tool get_code(code_sha256="…") (how to connect); click an identity to copy that call.

Repository labels, per sample. official repository: The archive marks this repository official for the paper. named in the paper: The archive records that the paper mentions this repository; it is not marked official. community (archive-listed): In the archive's code links for this paper, not marked official and not recorded as mentioned in the paper. found in paper text by Syntology: Syntology found this repository in the paper's own text; whether it is the authors' implementation is not asserted. community: Not in the archive's code links for this paper; a community repository Syntology harvested. Samples from a repository marked official are listed first. Licence labels name the repository's licence as recorded at harvest. “Pointer only” means Syntology does not serve that copy's text, for one of four reasons: no licence file was found; the licence was not identified; the licence is recorded as permissive but that copy's record is not marked cleared; or the licence is outside the permissive list Syntology serves text under (MIT, Apache-2.0, BSD and similar). Some licences outside that list permit redistribution, such as WTFPL, and GPL-3.0 under its conditions; they are simply not on the list. Hover a licence label for the reason. File links open the file on GitHub at the default branch, which may have changed since the harvest.

compute_axial_cis mark12ding/sam2long/sam2/modeling/position_encoding.py official repository ran · violated contract no licence file found · pointer only · 7ceaad42da42edd5 · report
get_1d_sine_pe mark12ding/sam2long/sam2/modeling/sam2_utils.py official repository ran · our draft was wrong fingerprinted no licence file found · pointer only · a6c3974188a5ffb0 · report
init_t_xy mark12ding/sam2long/sam2/modeling/position_encoding.py official repository ran · honoured contract fingerprinted no licence file found · pointer only · bb060d29525f90eb · report
reshape_for_broadcast mark12ding/sam2long/sam2/modeling/position_encoding.py official repository ran · fixture could not drive it no licence file found · pointer only · f8f09f78b474ee7c · report
select_closest_cond_frames mark12ding/sam2long/sam2/modeling/sam2_utils.py official repository ran · our draft was wrong no licence file found · pointer only · 4ee20f090e58c425 · report
build_sam2 mark12ding/sam2long/sam2/build_sam.py official repository unverified no licence file found · pointer only · f9850c1d4acdbb5a · report
build_sam2_hf mark12ding/sam2long/sam2/build_sam.py official repository unverified no licence file found · pointer only · de8c2a625f263855 · report
build_sam2_video_predictor mark12ding/sam2long/sam2/build_sam.py official repository unverified no licence file found · pointer only · c1b9e144954a57e5 · report
do_pool mark12ding/sam2long/sam2/modeling/backbones/hieradet.py official repository unverified licence not identified · pointer only · d3df9ada3e05fa55 · report
get_activation_fn mark12ding/sam2long/sam2/modeling/sam2_utils.py official repository unverified no licence file found · pointer only · f2e72d81f39d65cd · report

Tasks

Heuristic SearchObjectSegmentationSemantic SegmentationVideo Object SegmentationVideo SegmentationVideo Semantic SegmentationVisual Object Tracking

Results from the paper archive 2025-07-28

TaskDatasetModelMetricValueRank at snapshotLeaderboardReport
Visual Object Tracking DiDi SAM2.1Long Tracking quality 0.646 #4 of 11 Archive leaderboard report

Ranks are positions in the archive's leaderboards as they stood at the 2025-07-28 snapshot. Results published since then are not among these rows, so a rank here is not a current standing.

Methods

SAM

Report a problem or propose a change · a person checks every report against the paper or source before anything changes; decisions are listed on /corrections