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

Bugfix: Tracker reset fails #1638

Merged
merged 1 commit into from
Oct 31, 2024
Merged

Bugfix: Tracker reset fails #1638

merged 1 commit into from
Oct 31, 2024

Conversation

LinasKo
Copy link
Contributor

@LinasKo LinasKo commented Oct 31, 2024

Description

Resetting the tracker would fail. This was noticed on Develop.

Type of change

Please delete options that are not relevant.

  • 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?

YOUR_ANSWER

Any specific deployment considerations

For example, documentation changes, usability, usage/costs, secrets, etc.

Docs

  • Docs updated? What were the changes:

@LinasKo
Copy link
Contributor Author

LinasKo commented Oct 31, 2024

Noticed when running test code:

import sys
import os
import cv2
import time
import numpy as np

import supervision as sv
from ultralytics import YOLO
import torch
from torch.nn import functional as F


VIDEO_ROOT = "people_walking.mp4"
VIDEO_OUT = "people_walking_out.mp4"


device = "cuda" if torch.cuda.is_available() else "cpu"
# model = YOLO('yolov8x-seg.pt').to(device)
model = YOLO("yolov8n.pt").to(device)

mask_annotator = sv.MaskAnnotator()
box_annotator = sv.BoxAnnotator(thickness=1)
track_annotator = sv.TraceAnnotator()
label_annotator = sv.LabelAnnotator()

video_info = sv.VideoInfo.from_video_path(video_path=VIDEO_ROOT)
frame_generator = sv.get_video_frames_generator(source_path=VIDEO_ROOT)
byte_tracker = sv.ByteTrack(minimum_consecutive_frames=10)
byte_tracker.reset()

with sv.VideoSink(VIDEO_OUT, video_info=video_info) as sink:

    for frame in frame_generator:

        result = model(frame, imgsz = 1280,verbose=False)[0]
        pre_track_detections = sv.Detections.from_ultralytics(result)
        # pre_track_detections = detections.copy()
        detections = byte_tracker.update_with_detections(pre_track_detections)
        try:
          print(f"largest detection id: {np.max(detections.tracker_id)}")
          print(f"number of detections: {detections.tracker_id.shape[0]}")
          # print(f"pre track detections: {pre_track_detections}")
          print('YOLO bbox: ', result.boxes.cpu().xyxy if len(result.boxes.cpu().xyxy)>0 else [])
          print(f"post track detections: {detections}")

        except ValueError:
          pass

        labels = [
            f"#{tracker_id} {model.model.names[class_id]} {confidence:0.2f}"
            for _, _, confidence, class_id, tracker_id, _
            in detections
        ]

        annotated_frame = box_annotator.annotate(
            scene=frame.copy(),
            detections=detections)
        annotated_frame = track_annotator.annotate(
            scene=annotated_frame.copy(),
            detections=detections)
        annotated_frame = mask_annotator.annotate(
            scene=annotated_frame.copy(),
            detections=detections)
        annotated_frame = label_annotator.annotate(
            scene=annotated_frame.copy(),
            labels=labels,
            detections=detections
        )


        sink.write_frame(frame=annotated_frame)

@LinasKo LinasKo merged commit 37cacec into develop Oct 31, 2024
11 checks passed
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