ultralytics / ultralytics

Ultralytics YOLO11 ๐Ÿš€
https://docs.ultralytics.com
GNU Affero General Public License v3.0
33.07k stars 6.37k forks source link

Track fails on video with person switches #17304

Open weidong-z opened 3 weeks ago

weidong-z commented 3 weeks ago

Search before asking

Question

Hello there,

I have a video, and I think it is simple, when I do tracking, it fails with wrong id on person switches. I use example codes as

import cv2
import numpy as np
import os
import os.path as osp
from ultralytics import YOLO

# Load the YOLO11 model
model = YOLO("yolo11x.pt")

# Open the video file
video_path = "videos/drive3_t.mp4"
cap = cv2.VideoCapture(video_path)

# Loop through the video frames
idx = 0
while cap.isOpened():
    # Read a frame from the video
    success, frame = cap.read()

    if success:
        idx += 1
        # Run YOLO11 tracking on the frame, persisting tracks between frames
        results = model.track(frame, persist=True, classes=[0], conf=0.6,)

        # Visualize the results on the frame
        annotated_frame = results[0].plot()

        # Display the annotated frame
        cv2.imwrite(f'test/{idx:03}.png', annotated_frame)
    else:
        # Break the loop if the end of the video is reached
        break

I got wrong id when person switchs as shown in: 046 057

I attached my video here https://drive.google.com/file/d/1ZSmpVXOX2YaXEOYuv97WEnBABHFtuC5x/view?usp=sharing

https://github.com/user-attachments/assets/4760c065-aae3-4561-b235-1e6196d3848f

UltralyticsAssistant commented 3 weeks ago

๐Ÿ‘‹ Hello @weidong-z, thank you for reaching out to us at Ultralytics ๐Ÿš€! We appreciate your interest and the detailed description of the issue you're encountering.

To assist us in debugging this ๐Ÿ›, could you please provide a minimum reproducible example? This will help our team better understand the problem and identify any potential issues with the tracking functionality.

In the meantime, I recommend upgrading to the latest ultralytics package along with all requirements in a Python>=3.8 environment with PyTorch>=1.8 to ensure you're using the newest features and fixes:

pip install -U ultralytics

For additional context on improving your model's performance, particularly in custom training scenarios, you might find our Tips for Best Training Results beneficial.

If you're interested in discussing with others or need real-time help, join our Discord ๐ŸŽง or check out our Discourse for more in-depth discussions.

Rest assured, an Ultralytics engineer will review your issue soon to provide more tailored assistance.

Take care and looking forward to your minimum reproducible example! ๐Ÿ“น

Y-T-G commented 3 weeks ago

Tracking expects the camera to be static. Here the camera is switching between different views.