Closed RustyRaptor closed 7 months ago
Ok I figured it out. It's quite simple it was just kinda weird because it's stored in the Boxes object and the variable names aren't very descriptive. Anyhow...
Boxes.cls is the class id which you can find in result.names Boxes.conf is the confidence level associated with said class.
Hence you can zip them to get a nice pairing of each. Additionally you can use the names field to fetch the actual class name.
from ultralytics import YOLO
model = YOLO("yolov8n.pt") # initialize model
results = model(source='./dogs.mp4', show=True, conf=0.4, stream=True) # detect video stream
for result in results:
boxes = result.boxes
confidences = list(zip(boxes.cls, boxes.conf))
names = result.names
if len(boxes) > 0:
print("Class and Confidence", confidences)
print(names)
print("---------------------------------------------------")
Here is an example output for a frame detecting a person and a dog.