Skip to content

[McByte part 7] Mask manager delayed mask creation#491

Open
tstanczyk95 wants to merge 4 commits into
dev/mcbytefrom
feat/mcbyte-mask-manager-delayed-creation
Open

[McByte part 7] Mask manager delayed mask creation#491
tstanczyk95 wants to merge 4 commits into
dev/mcbytefrom
feat/mcbyte-mask-manager-delayed-creation

Conversation

@tstanczyk95

Copy link
Copy Markdown
Collaborator

What does this PR do?

This PR extends MaskManager with robust delayed mask creation, reproducing the original McByte behavior for heavily occluded tracklets.

Instead of creating masks immediately for every newly detected tracklet, MaskManager now postpones mask generation for tracklets whose bounding boxes are strongly occluded. Delayed tracklets are maintained in a shared pending pool and are automatically retried on subsequent frames using their most recent tracker state until a suitable bounding box becomes available.

The same delayed mask creation logic is consistently applied both during the initial CutieMaskPropagator initialization and during subsequent dynamic mask additions.

Main additions:

  • Added delayed mask creation based on bounding-box overlap
  • Introduced a shared pending tracklet pool used for both initialization and dynamic mask addition
  • Implemented automatic retry of pending tracklets using their most recent tracker state
  • Added support for late MaskManager initialization when no suitable tracklets are available during the first frames
  • Ensured pending tracklets are removed when terminated by the tracker
  • Added unit tests covering delayed initialization, delayed mask addition and pending-tracklet lifecycle
  • Added a new visual integration script (visualize_mask_manager_from_gt.py) replaying ground-truth tracklets to validate delayed mask creation on complete video sequences
  • Updated docstrings of the MaskManager

Type of Change

  • New feature (non-breaking change that adds functionality)

Testing

  • I have tested this change locally
  • I have added/updated tests for this change

Test details:

Added and updated unit tests covering:

  • Delayed initialization of heavily occluded tracklets
  • Automatic initialization retry once a suitable bounding box becomes available
  • Delayed mask addition after MaskManager initialization
  • Automatic retry of pending tracklets using their latest tracker state
  • Removal of pending tracklets after tracker termination
  • Late MaskManager initialization after multiple initial frames without suitable tracklets
  • Existing lifecycle behavior after the delayed mask creation changes

Manual validation:

  • Verified delayed mask creation using the new GT-driven visual integration script
  • Verified initialization retry after occlusion disappears
  • Verified delayed mask addition after initialization
  • Verified pending-tracklet lifecycle on complete SoccerNet-tracking sequences
  • Verified visual consistency of generated masks throughout long sequences
  • Verified tracker timing remains consistent with the original McByte implementation

Checklist

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code where necessary, particularly in hard-to-understand areas
  • My changes generate no new warnings or errors
  • [McByte as a whole is still in the development phase] I have updated the documentation accordingly (if applicable)

Additional Context

This PR builds directly on the previous MaskManager integration PR (#481) and extends it with the delayed mask creation strategy used by the original McByte implementation.

To facilitate the validation of the introduced functionality, a new visualization script (visualize_mask_manager_from_gt.py) has been added. Unlike the previous visualization utility, which manually specified lifecycle events, the new script replays complete MOT-style ground-truth annotations and emulates the original McByte execution order:

Ground-truth tracklets ---> Tracker state replay ---> MaskManager (frame t using tracker state from frame t-1) ---> SAMBoxMaskGenerator ---> CutieMaskPropagator ---> Visualization

This allows delayed initialization, delayed mask addition, pending-tracklet retry, and late initialization to be inspected over complete video sequences.

No additional external dependencies beyond those introduced by the previous Cutie integration PR #452 (section Additional Context) are required.

Tested on CPU (very slow, not recommended) and on GPU (CUDA 12.6) using separate Anaconda environments.

Visual validation was performed on all 49 SoccerNet-tracking test sequences.

Example test run:

python visual_tests/visualize_mask_manager_from_gt.py \
  --image-dir your_dataset_path/SoccerNet/tracking/test/SNMOT-122/img1 \
  --gt-file your_dataset_path/SoccerNet/tracking/test/SNMOT-122/gt/gt.txt \
  --start-frame 1 \
  --end-frame 750 \
  --tracklet-id all \
  --device cuda

The --tracklet-id argument can be repeated to visualize selected tracklets only. If omitted, or when --tracklet-id all is specified, all tracklets from the ground-truth file are replayed.

As described in #452 (at the end of the PR description), the required model weights are downloaded automatically.

@tstanczyk95 tstanczyk95 requested a review from SkalskiP as a code owner July 7, 2026 15:37
@tstanczyk95 tstanczyk95 changed the title Feat/mcbyte mask manager delayed creation [McByte part 7] Mask manager delayed creation Jul 7, 2026
@tstanczyk95 tstanczyk95 changed the title [McByte part 7] Mask manager delayed creation [McByte part 7] Mask manager delayed mask creation Jul 7, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR extends the McByte MaskManager to support delayed mask creation for heavily occluded tracklets by maintaining a shared “pending tracklets” pool and retrying mask creation when tracklets become suitable, aligning behavior with the original McByte design. It also adds automated tests and a GT-replay visual script to validate the lifecycle across longer sequences.

Changes:

  • Added overlap-based delayed mask creation with a shared pending-tracklet pool and retry logic in MaskManager.
  • Expanded unit tests to cover delayed initialization/addition and pending-tracklet lifecycle behavior.
  • Added a ground-truth replay visualization script to sanity-check delayed creation end-to-end over sequences.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
src/trackers/core/mcbyte/mask_manager.py Implements delayed mask creation, pending pool management, and retry logic based on bbox overlap.
tests/core/test_mcbyte_mask_manager.py Adds unit tests for delayed initialization/addition, retry behavior, and pending removal on termination.
visual_tests/visualize_mask_manager_from_gt.py Adds GT-driven visual integration script to replay tracklets and inspect delayed creation behavior across sequences.

Comment on lines 147 to +160
if previous_frame is None:
return None

if not self._initialized and len(previous_tracklets) == 0:
return None

if self.mask_propagator is None:
return None

new_tracklets = [] if new_tracklets is None else new_tracklets
removed_tracklet_ids = [] if removed_tracklet_ids is None else removed_tracklet_ids

self._remove_pending_tracklets(removed_tracklet_ids)

Comment on lines 85 to +89
self.mask_generator = mask_generator
self.mask_propagator = mask_propagator
self.mask_creation_bbox_overlap_threshold = mask_creation_bbox_overlap_threshold
self._initialized = False
self._pending_tracklet_ids: set[int] = set()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants