# create python virtual environment
python3 -m venv venv
# install dependencies
pip install -r requirements.txt
python3 -m main
I'm getting the following error for line 32,
labels = [ ValueError: too many values to unpack (expected 4)
How can i change the resolution ?
I created a custom dataset and trained the yolov8 model to receive best.pt weights as shown in one of the youtube videos on the roboflow channel. when inserting the custom best.pt file in place of the yolov8n.pt file in the code the detections are not shown in the second window with the line counter. The detections are shown only in the first window and are not shown window with the line counter. the standard yolov8 model is unable to make any detections in my particular use case. When using the provided code without changing the weights file. Any detection made is displayed in both windows. Due to this, the line based counter is not working and I can't use the custom-trained model weights.
hi thank you for your work
the work is excellent on webcam , but when i make changes on the code to make it work on video
this is the modified code
import cv2
from ultralytics import YOLO
import supervision as sv
import numpy as np
LINE_START = sv.Point(320, 0)
LINE_END = sv.Point(320, 480)
def main():
line_counter = sv.LineZone(start=LINE_START, end=LINE_END)
line_annotator = sv.LineZoneAnnotator(thickness=2, text_thickness=1, text_scale=0.5)
box_annotator = sv.BoxAnnotator(
thickness=2,
text_thickness=1,
text_scale=0.5
)
model = YOLO("yolov8l.pt")
# Define the codec and create a VideoWriter object
fourcc = cv2.VideoWriter_fourcc(*'mp4v') # Be sure to use lower case
out = cv2.VideoWriter('Outputvideo.mp4', fourcc, 20.0, (640, 480))
for result in model.track(source='your_video_file.mp4', show=False, stream=False, agnostic_nms=True):
frame = result.orig_img
detections = sv.Detections.from_yolov8(result)
if result.boxes.id is not None:
detections.tracker_id = result.boxes.id.cpu().numpy().astype(int)
detections = detections[(detections.class_id != 60) & (detections.class_id != 0)]
labels = [
f"{tracker_id} {model.model.names[class_id]} {confidence:0.2f}"
for _, confidence, class_id, tracker_id
in detections
]
frame = box_annotator.annotate(
scene=frame,
detections=detections,
labels=labels
)
line_counter.trigger(detections=detections)
line_annotator.annotate(frame=frame, line_counter=line_counter)
# Write the frame to the output file
out.write(frame)
# Release the VideoWriter and VideoCapture objects
out.release()
if __name__ == "__main__":
main()
but when i change it to video i have this error
ValueError Traceback (most recent call last)
<ipython-input-10-fe39b167ccdf> in <cell line: 58>()
57
58 if __name__ == "__main__":
---> 59 main()
1 frames
<ipython-input-10-fe39b167ccdf> in <listcomp>(.0)
37 labels = [
38 f"{tracker_id} {model.model.names[class_id]} {confidence:0.2f}"
---> 39 for _, confidence, class_id, tracker_id
40 in detections
41 ]
ValueError: too many values to unpack (expected 4)
i wish you can help me solving the problem
error when looping the labels
my code:
from supervision.dataset.formats.yolo import detections_to_yolo_annotations
for result in model.track(source=f"{HOME}/Recording_2023-05-04_09_41_20_Camera - 1of8.mp4", stream=True):
frame = result.orig_img
detections = sv.Detections.from_yolov8(result)
if result.boxes.id is not None:
detections.tracker_id = result.boxes.id.cpu().numpy().astype(int)
print(f"{detections.class_id}")
detections = detections[(detections.class_id !=0)]
labels = [
f"{tracker_id} {model.model.names[class_id]} {confidence:0.2f}"
for _, confidence, class_id, tracker_id
in detections
]
frame = box_annotator.annotate(scene=frame, detections=detections, labels=labels)
error message : ValueError Traceback (most recent call last)
in <cell line: 2>()
10 detections = detections[(detections.class_id !=0)]
11
---> 12 labels = [
13 f"{tracker_id} {model.model.names[class_id]} {confidence:0.2f}"
14 for _, confidence, class_id, tracker_id
in (.0)
12 labels = [
13 f"{tracker_id} {model.model.names[class_id]} {confidence:0.2f}"
---> 14 for _, confidence, class_id, tracker_id
15 in detections
16 ]
ValueError: too many values to unpack (expected 4)
source = "test.mp4" # my input video resolution is (2304 * 1296)
The source is being used in the following code line:
for result in model.track(source=source, show=False, stream=True, agnostic_nms=True):#verbose=False):
I want to resize it like - frame = imutils.resize(frame, width=600) before passing input to the frame. Can you please help with this?
I am working with 5 cameras in my project. When I frame a single camera, there is no problem, but when I try to track for 5 cameras, the tracker_ids return to none. What could this be about?
while True:
for i in range(cam_no):
ret[i], frame[i] = cap[i].read()
for result in model.track(source=frame[i], show=True, stream=True, agnostic_nms=True):
tracking_frame = result.orig_img
detections = sv.Detections.from_yolov8(result)
if result.boxes.id is not None:
detections.tracker_id = result.boxes.id.cpu().numpy().astype(int)
detections = detections[(detections.class_id != 60) & (detections.class_id != 0)]
print("tracker id ",detections.tracker_id)
...
...
Many thanks for your blogs and notebook.
I ran you notebook for track and count cars and trucks it works fine
I the tried to follow your blog and replaced
!git clone https://github.com/ifzhang/ByteTrack.git
with
!pip install bytetrack
But I got an error message
Collecting bytetrack
Using cached bytetrack-0.0.1.tar.gz (100 kB)
Preparing metadata (setup.py) ... done
Building wheels for collected packages: bytetrack
error: subprocess-exited-with-error
ร python setup.py bdist_wheel did not run successfully.
โ exit code: 1
โฐโ> See above for output.
note: This error originates from a subprocess, and is likely not a problem with pip.
Building wheel for bytetrack (setup.py) ... error
ERROR: Failed building wheel for bytetrack
Running setup.py clean for bytetrack
Failed to build bytetrack
Installing collected packages: bytetrack
error: subprocess-exited-with-error
ร Running setup.py install for bytetrack did not run successfully.
โ exit code: 1
โฐโ> See above for output.
note: This error originates from a subprocess, and is likely not a problem with pip.
Running setup.py install for bytetrack ... error
error: legacy-install-failure
ร Encountered error while trying to install package.
โฐโ> bytetrack
note: This is an issue with the package mentioned above, not pip.
hint: See above for output from the failure.
An idea how to fix it ?
Thanks for your help
Instead of counting the no of transitions in and out how to do the class transition count
I'm using my own trained model with custom data set and I dont know why I get this error. Also I'm tracking over a video not from the webcam.
I also wonder if there is any chance to put the results inside a csv file or something when the video stops. Like the total amount counted is 10 for example, and also to count separate things like 2 apples and 3 oranges for example.
i was using you given code and resized it's frame to (640,480) then the object detection is not working. so what can i do ?
When running main.py only the default bounding boxes from cv2 are shown. Editing sv.BoxAnnotator does not do anything.
I tried uninstalling and reinstalling the packages and it still persists.
My OS is Windows.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.