Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ByteTrack: Remove BaseTrack, refactor, add types, remove dead code, scope shared Kalman #1603

Open
wants to merge 8 commits into
base: develop
Choose a base branch
from

Conversation

LinasKo
Copy link
Collaborator

@LinasKo LinasKo commented Oct 17, 2024

Description

The code of ByteTrack is messy and hard to read. I've given it some attention to bring it closer to our repo standards. Behaviour is identical to previous iteration.

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • This change requires a documentation update

How has this change been tested, please provide a testcase or example of how you tested the change?

Ran tests, built docs, ran the following test code:

from supervision.assets import download_assets, VideoAssets
from ultralytics import YOLO
import supervision as sv
import cv2

video_path = VideoAssets.PEOPLE_WALKING.value
download_assets(VideoAssets.PEOPLE_WALKING)

video_info = sv.VideoInfo.from_video_path(video_path=video_path)
frames_generator = sv.get_video_frames_generator(source_path=video_path)

model = YOLO("yolov8s")
tracker_1 = sv.ByteTrack(frame_rate=video_info.fps)
tracker_2 = sv.ByteTrack(frame_rate=video_info.fps)
smoother = sv.DetectionsSmoother()

trace_annotator = sv.TraceAnnotator()
label_annotator = sv.LabelAnnotator()

with sv.VideoSink(target_path="out.mp4", video_info=video_info) as sink:
    for frame in frames_generator:
        results = model(frame, verbose=False)[0]
        detections = sv.Detections.from_ultralytics(results)

        annotated_frame = frame.copy()
        detections = tracker_1.update_with_detections(detections)
        
        detections = detections[detections.class_id == 0]
        assert isinstance(detections, sv.Detections)
        detections = tracker_2.update_with_detections(detections)

        detections = smoother.update_with_detections(detections)
        trace_annotator.annotate(annotated_frame, detections)

        assert detections.tracker_id is not None
        labels = [f"#{tracker_id}" for tracker_id in detections.tracker_id]
        annotated_frame = label_annotator.annotate(
            scene=annotated_frame, detections=detections, labels=labels
        )

        # The only state kalman has is the fixed update matrices!
        # print(tracker_1.shared_kalman.)
        # print()
        # print(tracker_2.shared_kalman._std_weight_velocity)
        # print("\n---\n")

        sink.write_frame(frame=annotated_frame)

Any specific deployment considerations

Notify others working on tracker about conflicts.

Docs

  • Docs updated? What were the changes:

@LinasKo
Copy link
Collaborator Author

LinasKo commented Oct 18, 2024

Hey @onuralpszr, I'm adding you as an optional reviewer.
Feel free to have a look if you have the time and motivation.

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.

1 participant