Predict a class from the results of a detected object of trained YOLOv8 model in python

I have a trained model and I have detected my required object using following code

import cv2
from PIL import Image
from ultralytics import YOLO

image = cv2.imread("screenshot.png")
model = YOLO('runs/detect/train4/weights/best.pt')
results = model.predict(image, show=True, stream=True, classes=0, imgsz=512)
for result in results:
    for box in result.boxes:
        class_id = result.names[box.cls[0].item()]
        if (class_id == "myclassname"): 
            cords = box.xyxy[0].tolist()
            cords = [round(x) for x in cords]
            conf = round(box.conf[0].item(), 2)
            print("Object type:", class_id)
            print("Coordinates:", cords)
            print("Probability:", conf)
            print("---")

From this detected portion of image I need to detect an other class how I can do that?

I have searched enough but I could not see any post for this.



Comments

Popular posts from this blog

Today Walkin 14th-Sept

Spring Elasticsearch Operations

Hibernate Search - Elasticsearch with JSON manipulation