Skip to content

Track Objects on Video (inference) example not retrieving class name correctly #1827

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

Open
2 tasks done
fmousinho opened this issue Apr 23, 2025 · 0 comments
Open
2 tasks done
Labels
bug Something isn't working

Comments

@fmousinho
Copy link

fmousinho commented Apr 23, 2025

Search before asking

  • I have searched the Supervision issues and found no similar bug report.

Bug

In the example in # https://supervision.roboflow.com/develop/how_to/track_objects/#annotate-video-with-tracking-ids, we see label array assignment below. However, "results" does not have the attribute "names" which yields an error when running the code.

labels = [
        f"#{tracker_id} {results.names[class_id]}"
        for class_id, tracker_id
        in zip(detections.class_id, detections.tracker_id)
    ]

I was able to solve this by using the data attribute instead:

  labels = [
        f"#{tracker_id} {class_name}"
        for class_name, tracker_id
        in zip(detections.data['class_name'], detections.tracker_id)
    ]

Traceback:

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Cell In[23], line 26
     21     annotated_frame = box_annotator.annotate(
     22         frame.copy(), detections=detections)
     23     return label_annotator.annotate(
     24         annotated_frame, detections=detections, labels=labels)
---> 26 sv.process_video(
     27     source_path=VIDEO_URL,
     28     target_path="./result.mp4",
     29     callback=callback
     30 )

File ~/Documents/Learning_to_Code/roboflow/roboenv/lib/python3.12/site-packages/supervision/utils/video.py:230, in process_video(source_path, target_path, callback)
    226 with VideoSink(target_path=target_path, video_info=source_video_info) as sink:
    227     for index, frame in enumerate(
    228         get_video_frames_generator(source_path=source_path)
    229     ):
--> 230         result_frame = callback(frame, index)
    231         sink.write_frame(frame=result_frame)

Cell In[23], line 16, in callback(frame, _)
     12 detections = sv.Detections.from_inference(results)
     13 detections = tracker.update_with_detections(detections)
     15 labels = [
---> 16     f"#{tracker_id} {results.names[class_id]}"
     17     for class_id, tracker_id
     18     in zip(detections.class_id, detections.tracker_id)
     19 ]
     21 annotated_frame = box_annotator.annotate(
     22     frame.copy(), detections=detections)
     23 return label_annotator.annotate(
     24     annotated_frame, detections=detections, labels=labels)

File ~/Documents/Learning_to_Code/roboflow/roboenv/lib/python3.12/site-packages/pydantic/main.py:994, in BaseModel.__getattr__(self, item)
    991     return super().__getattribute__(item)  # Raises AttributeError if appropriate
    992 else:
    993     # this is the current error
--> 994     raise AttributeError(f'{type(self).__name__!r} object has no attribute {item!r}')

AttributeError: 'ObjectDetectionInferenceResponse' object has no attribute 'names'

Environment

  • Supervision: 0.25.1
  • OS: MacOS 15.4.1
  • Python 3.12.10

Minimal Reproducible Example

Use code in doc example at # https://supervision.roboflow.com/develop/how_to/track_objects/#annotate-video-with-tracking-ids

Additional

First time I file a bug.. Constructive criticism welcome!

Are you willing to submit a PR?

  • Yes I'd like to help by submitting a PR!
@fmousinho fmousinho added the bug Something isn't working label Apr 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant