roboflow / supervision

We write your reusable computer vision tools. 💜
https://supervision.roboflow.com
MIT License
23.54k stars 1.76k forks source link

too many values to unpack (expected 5) #1558

Closed 0xD4rky closed 1 week ago

0xD4rky commented 1 week ago

Search before asking

Bug

I was using Supervision for an inference of yolov8 model on a sample video data. When I am trying to run the program using the code below, its showing me this error:

for _, _, confidence, class_id, _
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ValueError: too many values to unpack (expected 5)

I have went through the updated code in the Detections/core.py but haven't found out exactly why this error is coming up.

Screenshot from 2024-10-01 00-03-56

I have also referred to downgrading the supervision version to 0.3.0 but that has created more clashes as python versions and pytorch versions also clash.

Environment

Minimal Reproducible Example

import numpy as np
from ultralytics import YOLO

video_path = r'det/data/football.mp4'

model = YOLO("yolov8s.pt")
video_info = sv.VideoInfo.from_video_path(video_path)

def process_frame(frame: np.ndarray,_) -> np.ndarray:

    results = model(frame,imgsz = 1280)[0]
    detections = sv.Detections.from_ultralytics(results)
    box_annotator = sv.BoundingBoxAnnotator()

    labels = [
    f"{model.names[class_id]} {confidence:0.2f}"
    for _, _, confidence, class_id, _
    in detections
    ]
    frame = box_annotator.annotate(scene=frame, detections=detections, labels=labels)

    return frame

sv.process_video(source_path=video_path, target_path=f"result.mp4", callback=process_frame)

Additional

No response

Are you willing to submit a PR?

LinasKo commented 1 week ago

Hi @0xD4rky 👋

This happens because the detections __iter__ iterators used to produce less values in the past. In recent supervision versions you will have 6 values:

labels = [
    f"{model.names[class_id]} {confidence:0.2f}"
    for xyxy, mask, confidence, class_id, tracker_id, data_slice
    in detections
    ]
LinasKo commented 1 week ago

Closing as I'm certain it's the solution 😉

0xD4rky commented 1 week ago

Thanks a lot @LinasKo for clearing out, was stuck in this problem for some time!

LinasKo commented 1 week ago

Glad to help!