GithubHelp home page GithubHelp logo

yolov8-native-tracking's Introduction

YOLOv8 NATIVE TRACKING

๐Ÿ’ป Install

# create python virtual environment
python3 -m venv venv

# install dependencies
pip install -r requirements.txt

๐Ÿ“ธ Execute

python3 -m main

yolov8-native-tracking's People

Contributors

skalskip avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

yolov8-native-tracking's Issues

Custom trained model weights not being used in the yolov8 window

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.

error when change to video

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

too many values to unpack (expected 4)

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)

Resize input source before tracking

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?

Tracker_ids return none when working with multiple sources

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)
         ...
         ...

issue with pip install bytetrack on google collab

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

I recive the next error inside the for loop ValueError: too many values to unpack (expected 4)

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.