supervision
supervision copied to clipboard
ByteTrack: Remove BaseTrack, refactor, add types, remove dead code, scope shared Kalman
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
- [x] 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:
Hey @onuralpszr, I'm adding you as an optional reviewer. Feel free to have a look if you have the time and motivation.