roboflow / roboflow/notebooks

ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()

Open
#324 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
Jupyter Notebook
Stars
9.7k
Forks
1.5k
PR merge metrics
No merged PRs in 30d

Description

Search before asking
  • I have searched the Roboflow Notebooks issues and found no similar bug report.
Notebook name

YOLOv8 object tracking + ByteTrack + Supervision

Bug

Traceback (most recent call last):
File "C:\Users\khars\PycharmProjects\Bytetrack\main.py", line 33, in
results = model(frame)[0] # Pass the frame as a list
File "C:\Users\khars\PycharmProjects\Bytetrack\venv\lib\site-packages\ultralytics\yolo\engine\model.py", line 58, in call
return self.predict(source, **kwargs)
File "C:\Users\khars\PycharmProjects\Bytetrack\venv\lib\site-packages\torch\utils_contextlib.py", line 116, in decorate_context
return func(*args, **kwargs)
File "C:\Users\khars\PycharmProjects\Bytetrack\venv\lib\site-packages\ultralytics\yolo\engine\model.py", line 130, in predict
predictor.setup(model=self.model, source=source)
File "C:\Users\khars\PycharmProjects\Bytetrack\venv\lib\site-packages\ultralytics\yolo\engine\predictor.py", line 111, in setup
source = str(source or self.args.source)
ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()

Process finished with exit code 1

Environment

Local OS : Windows 11
python: 3.10.11

Minimal Reproducible Example

from ultralytics import YOLO
import cv2
import torch
from supervision.video.source import get_video_frames_generator
from supervision.notebook.utils import show_frame_in_notebook
from supervision.draw.color import ColorPalette
from supervision.tools.detections import Detections, BoxAnnotator
from supervision.video.sink import VideoSink
from supervision.video.dataclasses import VideoInfo

Load the YOLO model

MODEL = "yolov8x.pt"
model = YOLO(MODEL)
model.fuse()

source = "output5.mp4"

CLASS_NAMES_DICT = model.model.names
CLASS_ID = [0]

Generate video frames from the source

generator = get_video_frames_generator("output5.mp4")
iterator = iter(generator)

Initialize box annotator

box_annotator = BoxAnnotator(color=ColorPalette(), thickness=4, text_thickness=4, text_scale=2)

video_info = VideoInfo.from_video_path(source)

Get the first frame from the video

frame = next(iterator)

results = model(frame)[0] # Pass the frame as a list

detections = Detections(
xyxy=results.boxes.xyxy.cpu().numpy(),
confidence=results.boxes.conf.cpu().numpy(),
class_id=results.boxes.cls.cpu().numpy().astype(int)
)

labels = [
f"{CLASS_NAMES_DICT[class_id]} {confidence:0.2f}"
for _, confidence, class_id, tracker_id
in detections
]

frame = box_annotator.annotate(frame=frame, detections=detections, labels=labels)

show_frame_in_notebook(frame, (16,16))

Additional

I was following the roboflow tutorial from youtube and I faced this issue. I have tried many things search everywhere but not any success. I have also tried the new notebook but still the same error

Are you willing to submit a PR?
  • Yes I'd like to help by submitting a PR!

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the “YOLOv8 object tracking + ByteTrack + Supervision” notebook and reproduce the traceback at results = model(frame)[0] using the reported Python and Windows environment. Trace the model(frame) call into the installed Ultralytics predictor and compare it with the current notebook example. Done means the example runs past this call without the reported ValueError and displays the annotated frame.

Written by the indexing model from the issue text.

Assessment

Tech stack
jupyter-notebook, opencv, python, pytorch
Domain
computer-vision
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.