neuralmagic / deepsparse

Sparsity-aware deep learning inference runtime for CPUs
https://neuralmagic.com/deepsparse/
Other
2.94k stars 169 forks source link

YOLOv8 - Display bounding boxes and classes names in image using python. #1641

Closed guiaugustoga987 closed 2 months ago

guiaugustoga987 commented 3 months ago

Hello,

Using yolov8 I can get detect the objects and annotate the results in the image using the code below as example :

from ultralytics import YOLO
import cv2

while True:
    _, img = cap.read()

    # BGR to RGB conversion is performed under the hood
    # see: https://github.com/ultralytics/ultralytics/issues/2575
    results = model.predict(img)

    for r in results:

        annotator = Annotator(img)

        boxes = r.boxes
        for box in boxes:

            b = box.xyxy[0]  # get box coordinates in (left, top, right, bottom) format
            c = box.cls
            annotator.box_label(b, model.names[int(c)])

    img = annotator.result()  
    cv2.imshow('YOLO V8 Detection', img)     
    if cv2.waitKey(1) & 0xFF == ord(' '):
        break

Is there a similar approach using deepsparse with Pipeline in Python ?

Thanks.

bfineran commented 3 months ago

Hi @guiaugustoga987 take a look here for our yolov8 script: https://github.com/neuralmagic/deepsparse/blob/main/src/deepsparse/yolov8/annotate.py

and here for our shared annotation tooling: https://github.com/neuralmagic/deepsparse/blob/main/src/deepsparse/utils/annotate.py

jeanniefinks commented 2 months ago

Hello @guiaugustoga987 As there are no further comments here, I am going to go ahead and close out this issue. Feel free to re-open if you would like to continue the conversation. Regards, Jeannie / Neural Magic

piaoyaoi commented 1 month ago

Yes, we need an example, based on yolov8, or do we have no idea how to write it