Fast video segmentation models for surgery and endoscopy keep a small "memory" of past frames. Each new frame is interpreted in light of what the model has already seen, and the memory is kept small so the system can run at video rate (at least 30 frames per second). Deciding which past frames to keep is the cheap trick that makes these models real-time. Current systems make that choice from whole-frame statistics: how similar a frame looks to its neighbours overall, or how uncertain the model is about the frame as a whole. A rare instrument that briefly enters a corner of the view barely changes either statistic. So the frames that carry the only evidence about rare classes may be exactly the ones discarded as redundant.
We propose to test this suspected failure directly and, if it holds, to fix it with a memory policy that costs almost nothing at runtime. The policy would be driven by the model's own per-class predictions. Each class gets a guaranteed minimum share of memory slots. Redundancy is judged separately inside each class's predicted region rather than over the whole image. The claim is narrow and testable: part of the majority-class bias of streaming segmenters is created at inference time by the memory policy, not only during training. Removing it should raise rare-class accuracy while staying above 30 frames per second, something offline rebalancing methods cannot do because they act only on training data.
Where This Sits
Two literatures meet here without having spoken to each other. On the latency side, three real-time systems motivate the proposal, and they are also the systems we modify.
Efficient Global-Local Memory for Real-Time Instrument Segmentation of Robotic Surgical Video (DMNet) keeps a long-term memory bank filled by whole-frame entropy and feature diversity. It reaches 61.03% mean Dice on EndoVis17 at 38 FPS. Surgical SAM 2 (SurgSAM2) prunes frames whose overall cosine similarity to a sliding window is high. It lifts SAM 2 from about 29 to about 86 FPS and raises Challenge IoU on EndoVis18 from 82.2% to 84.4%. VPSentry gates updates to a binary foreground/background prototype bank with a continuity check. None of the three conditions its memory on class identity, and none reports per-class or rare-class accuracy. The eviction hazard is our hypothesis, not a published finding.
On the imbalance side, the strongest surgical methods constrain the design by showing what does not fit a real-time budget. Rethinking data imbalance in class incremental surgical instrument segmentation (SurgCSS) rebalances 18 instrument classes with an offline latent diffusion model, a generator that produces images by gradually removing noise. Mitigating Surgical Data Imbalance with Dual-Prediction Video Diffusion Model (SurgiFlowVid) synthesizes short clips of rare actions. Both act only before deployment, and SurgCSS lists real-time validation as future work.
Twin-branch designs separate positive and negative learning but double the backbone cost on static inputs. These include OCT-X and the two-stream vertebral fracture network.
Our proposal differs from all of these in where it intervenes. It changes neither the training data nor the network width. It changes only the runtime rule that decides what the model remembers.
Core Claim
At each frame the decoder already outputs a per-pixel class map. From it we compute, at negligible cost, the predicted pixel mass of each class and a class-masked pooled feature for each class present.
Admission and eviction then follow two rules. First, every class that has appeared in the video keeps at least $k$ memory slots. Its most recent confident sightings are protected from eviction until a newer sighting of the same class replaces them. Second, redundancy pruning in the style of SurgSAM2 or DMNet compares frames by class-masked features, not whole-frame features. A frame counts as "redundant" only if it adds nothing for any class it contains.
The total memory size stays fixed, so attention cost and latency are unchanged up to a histogram and a few masked poolings per frame. The prediction is that rare-class Dice improves, most visibly in the frames just after a rare instrument reappears, while majority-class accuracy and throughput stay within noise.
Research Program
The work proceeds in three stages. The first stage is decisive.
The first stage is a diagnosis. On EndoVis17 type segmentation with DMNet, and on EndoVis18 with SurgSAM2, we log every memory admission and eviction. We measure how often frames containing a tail class are evicted relative to their frequency. Tail classes are the bottom third of classes by training pixel frequency, computed from the data because the file reports no such breakdown.
We then run an oracle that uses ground-truth masks to protect tail-class frames, with the same memory size. If the oracle does not improve tail-class Dice, the bias is not a memory problem and we stop. In that case the result still stands as a negative finding that rules out memory-side fixes.
The second stage builds the prediction-driven policy described above and drops it into DMNet's global memory and SurgSAM2's frame pruning without retraining the backbone. We then test a lightly fine-tuned variant in which the memory modules see the new policy during training.
The third stage characterizes cost. We measure throughput and memory on the original desktop-class GPUs and on one low-power embedded board, since the file notes that embedded real-time behaviour is largely uncharacterized. We also test the policy on the "Small Objects" and "Fast-motion" attributes of SUN-SEG with VPSentry. That binary setting is one where the foreground is itself the minority, and continuity gating may drop it.
Baselines
The naive reference is the same MobileNetV2 backbone and decoder used per frame with no memory at all. It shows how much temporal memory helps rare classes in the first place.
The strongest existing real-time competitors are DMNet and SurgSAM2 run exactly as published. Their reported results are 61.03% mean Dice at 38 FPS on EndoVis17 for DMNet and 84.4% Challenge IoU at about 86 FPS with about 1.0 GB of memory on EndoVis18 for SurgSAM2. No reported result was found on Lacuna for per-class or rare-class accuracy of either system, so we will compute those ourselves from released checkpoints or faithful retraining.
Vanilla SAM 2 with full memory (82.2% Challenge IoU, about 29 FPS, 3.1 GB) serves as the "keep everything" reference. A first-in-first-out memory of equal size checks whether any principled eviction rule matters.
All methods share the same splits, backbone, memory size, input resolution, hardware, and hyperparameter search budget. Results are averaged over three seeds, with video-level bootstrap confidence intervals.
Beating the strongest baseline means three things together. Tail-class Dice must improve with confidence intervals excluding zero. Overall mean Dice or Challenge IoU must not fall below the published system's value. Throughput must stay at or above 30 FPS on the same GPU.
Ablations isolate the two ingredients: per-class slot quotas alone, class-masked similarity alone, and both together. The ground-truth oracle serves as the ceiling for any memory-side fix.
Why not just…?
Why not just train with a class-weighted or focal loss? Loss reweighting changes what the network learns, not what it remembers at test time. A rare frame that is pruned is lost however well the network was trained. The file is also cautious about loss-only fixes. The vertebral fracture work reports its decoupled model beating the margin-based LDAM loss, and SurgCSS reports large gains over loss-based continual learning, though neither isolates reweighting in streaming video. This is still a real competitor, so we include a reweighted-loss DMNet and a reweighted-loss DMNet combined with our policy. If reweighting alone closes the gap to the oracle, our policy is unnecessary.
Why not just keep more frames in memory? Vanilla SAM 2 already does this, and the cost is about 29 FPS and 3.1 GB. SurgSAM2 also reports that keeping everything lowered accuracy through attention dilution. We will nevertheless sweep memory size, so that any rare-class gain from our policy must exceed the gain from simply enlarging memory at matched FPS.
Why not just adjust class logits at inference? Post-hoc bias correction of the output layer is essentially free and could recover some tail sensitivity. It cannot, however, restore evidence that is no longer in memory. We run it as a baseline and in combination with our policy. If the two give additive gains, that confirms memory loss is a distinct source of error.
Why not just rebalance offline with synthetic data, as SurgCSS and SurgiFlowVid do? Those methods improve training data and are complementary to ours, but they leave the runtime eviction rule untouched. If the diagnosis stage shows rare frames being evicted, a better-trained model still runs into the same loss of evidence at test time. SurgiFlowVid also reports that merely duplicating rare clips gives no gain, which warns against cheap offline substitutes.
Decisive Checks
The proposal stands or falls on three measurements. The first is whether tail-class frames are evicted disproportionately under the published policies. The second is whether the ground-truth oracle recovers tail-class Dice at fixed memory size. The third is whether the prediction-driven policy captures a meaningful share of that oracle gain on EndoVis17 and EndoVis18 while keeping both overall accuracy and the 30 FPS floor.
A secondary metric captures the clinical failure most directly. Reacquisition delay is the number of frames after a rare instrument re-enters the view until it is segmented above a Dice threshold. A reduction in that delay, with throughput unchanged, would be the clearest evidence that latency-driven memory design has been creating majority-class bias and that it can be removed at almost no cost.
References
- Efficient Global-Local Memory for Real-time Instrument Segmentation of Robotic Surgical Video
- Surgical SAM 2: Real-time Segment Anything in Surgical Video by Efficient Frame Pruning
- VPSentry: Semi-supervised Video Polyp Segmentation via Sentry-guided Long-term Prototype Fusion with Correlation Dynamic Propagation
- Rethinking data imbalance in class incremental surgical instrument segmentation
- Mitigating Surgical Data Imbalance with Dual-Prediction Video Diffusion Model
- An integrated AI-enabled system using One Class Twin Cross Learning for early gastric cancer detection
- Two-Stream Compare and Contrast Network for Vertebral Compression Fracture Diagnosis