Seth Bowers
Seth Bowers

Reputation: 21

Yolov11 model running slow through webcam

I'm using yolov11 to train a model to recognize a toy truck. I followed the steps in this EXCELLENT youtube video, and I have a working model build off of yolov11m.pt.

I'm using the following admittedly naaive script to launch a stream from my webcam and pass captured images through the model

from ultralytics import YOLO
import cv2

# load hyper tuned model
model = YOLO('/home/ultralytics/runs/detect/train4/weights/best.pt')
model.to("cuda")

# establish and open webcam feed
cap = cv2.VideoCapture(2)

if not cap.isOpened():
    print("Cannot open camera")
    exit(1)

while True:
    ret, frame = cap.read()
    if not ret:
        print("Cannot read camera")
        exit(2)

    # pass frame through model
    frame_resized = cv2.resize(frame, (640, 480))
    res = model.predict(source=frame_resized, show=True, conf=0.45)

    #Display resulting frame
    cv2.imshow('Stream', res[0].plot())

    # Break loop on 'q' for quit
    if cv2.waitKey(1) == ord('q'):
        break

I can't help but notice just how agonizingly choppy the resulting feed looks. Can anyone tell me why?

For example, when I run the regular yolov5 repo using a simple call to detect.py, it seems flawlessly fast. I'm looking to build some intuition as to how i could render my model's detection boxes at a similar rate of speed. Any and all help is appreciated.

I've got a pretty heavy duty graphics card behind this which runs yolov5 flawlessly.

Upvotes: 2

Views: 241

Answers (0)

Related Questions