Roboflow Trackers

repository·develop·Indexed 25 days ago

https://github.com/roboflow/trackers

A detector-agnostic Python library providing clean-room implementations of multi-object tracking (MOT) algorithms, including SORT, ByteTrack, OC-SORT, BoT-SORT, C-BIoU, and McByte. It integrates natively with the supervision ecosystem and includes a CLI for tracking, tools for downloading benchmark datasets like MOT17 and SportsMOT, and utilities for evaluating performance using HOTA, IDF1, and MOTA metrics.

Tokens
23.9K
Snippets
55
Records
134
Agent score
86%

What's inside Roboflow Trackers

  1. Overview of BoT-SORT Tracker

    develop
    BoT-SORT is an extension of ByteTrack designed for moving cameras and dynamic scenes. It improves identity stability by using Camera Motion Compensation (CMC) to estimate geometric transforms between frames, reducing ID switches caused by camera ego-motion. It utilizes a two-stage association strategy (high-confidence matching followed by low-confidence recovery) and combines IoU similarity with detection confidence for more robust matching.
  2. Overview of Roboflow Trackers

    develop

    Roboflow Trackers is an open-source Python library providing clean-room implementations of multi-object tracking (MOT) algorithms, including SORT, ByteTrack, OC-SORT, and BoT-SORT.

    Key features include:

    • Integration: Designed to plug into object detection models via the supervision library using a single tracker.update(detections) call.
    • Consistency: All algorithms share a common interface and consistent parameter naming.
    • Evaluation: Built-in tools for calculating HOTA, IDF1, and MOTA metrics.
    • CLI: A command-line interface for running trackers on video files.
    • Datasets: Utilities for downloading standard MOT benchmark datasets.
  3. Overview of SORT Tracker

    develop

    SORT (Simple Online and Realtime Tracking) is a fast, lightweight tracking-by-detection method. It uses a Kalman filter for motion prediction and the Hungarian algorithm for data association based on Intersection over Union (IoU).

    Key Characteristics:

    • Speed: Extremely fast, capable of hundreds of frames per second.
    • Mechanism: Uses only geometric cues from bounding boxes; it does not use appearance features.
    • Limitations: Because it lacks re-identification (ReID) capabilities, it is prone to identity switches and fragmented tracks during long occlusions or heavy crowding.
    • Use Case: Best for high-speed applications where computational resources are limited and objects are clearly distinguishable by geometry.
  4. Overview of McByte Tracker

    develop

    McByte is a mask-conditioned multi-object tracking (MOT) algorithm that extends the BoT-SORT tracking-by-detection pipeline. It uses temporally propagated segmentation masks (via SAM and Cutie) as an additional matching cue to resolve ambiguous or isolated IoU-based matches.

    Key characteristics:

    • No per-video tuning required: Uses general-purpose pre-trained models.
    • Optional Mask Management: Masking is disabled by default. Without it, McByte behaves as a variant of ByteTrack/BoT-SORT using only IoU.
    • Clear-match locking: Unambiguous matches are locked before mask evidence is considered to prevent mask data from disturbing certain matches.
  5. Understand State Estimators

    develop

    State estimators wrap a Kalman filter to define how bounding boxes are encoded into the filter's state vector. This controls how the filter predicts the next position of a tracked object.

    Both available estimators accept [x1, y1, x2, y2] bounding boxes on input and produce [x1, y1, x2, y2] bounding boxes on output. The difference lies in the internal motion modeling:

    EstimatorState DimensionsRepresentationAspect Ratio
    XYXYStateEstimator8Top-left and bottom-right corners + velocitiesCan change
    XCYCSRStateEstimator7Center point, area, velocities, and aspect ratioHeld constant
  6. Available Tracking Algorithms

    develop

    trackers provides clean-room implementations of several multi-object tracking algorithms. Each is a faithful implementation of its original paper.

    AlgorithmDescription
    SORTKalman filter + Hungarian matching baseline.
    ByteTrackTwo-stage association using high and low confidence detections.
    OC-SORTObservation-centric recovery for lost tracks.
    BoT-SORTCamera motion compensation (handles moving cameras natively).
    C-BIoUCascaded buffered IoU matching for fast or irregular motion.

    Additionally, trackers includes McByte, a mask-conditioned tracker that extends BoT-SORT-style association with temporally propagated SAM/Cutie segmentation masks. McByte requires additional dependencies (torch, SAM, Cutie).

  7. Optimize McByte performance via mask resolution and SAM model

    develop

    McByte's performance is heavily influenced by the mask pipeline. You can optimize speed by adjusting the following parameters:

    1. Reduce Cutie's internal mask resolution: Set max_internal_size within the eval_config to a specific value (e.g., 540 for a 1920x1080 input). This forces Cutie to propagate masks at a lower resolution (e.g., 960x540) before resizing them back, reducing computational cost at the expense of precision.
    2. Use a lighter SAM model: Use McByteMaskConfig(sam_model_type=...) to select a smaller SAM variant. This reduces the cost of initial mask creation when new tracklets appear.
    3. Disable the mask manager: Setting enable_mask_manager=False removes the mask pipeline overhead entirely, creating a mask-free configuration.
  8. Enable Dynamic Frame Rate tracking

    develop

    To handle irregular frame timing (e.g., dropped frames, sparse sampling, or variable FPS), pass an optional timestamp (in seconds) to the update() method of your tracker. This allows the tracker to scale Kalman predictions and track pruning based on the actual elapsed time between captured frames rather than assuming a constant frame rate.

    Supported trackers:

    • SORTTracker
    • ByteTrackTracker
    • OCSORTTracker
    • BoTSORTTracker
    • CBIoUTracker

    Important Requirements:

    • Monotonicity: Timestamps must be non-decreasing. If a timestamp is less than the previous call, the tracker will warn and skip the step (outputting IDs as -1).
    • Ordering: Always call update() in non-decreasing capture time order. If processing frames out-of-order, sort them by capture time or frame index before updating.
    • Resetting: Call tracker.reset() when switching to a new video to prevent the last timestamp from the previous video from affecting the new one.
    # Example: Using ByteTrackTracker with timestamps from OpenCV
    import cv2
    import supervision as sv
    from inference import get_model
    from trackers import ByteTrackTracker
    
    model = get_model("rfdetr-medium")
    tracker = ByteTrackTracker(frame_rate=30.0, lost_track_buffer=30)
    
    cap = cv2.VideoCapture("source.mp4")
    while True:
        ret, frame = cap.read()
        if not ret:
            break
    
        # Get timestamp in seconds
        timestamp = cap.get(cv2.CAP_PROP_POS_MSEC) / 1000.0
    
        result = model.infer(frame)[0]
        detections = sv.Detections.from_inference(result)
        # Pass timestamp to enable dynamic rate mode
        detections = tracker.update(detections, timestamp=timestamp)