0

I'm using the Ultralytics YOLOv8 implementation to perform object detection on an image. However, when I try to retrieve the classification probabilities using the probs attribute from the results object, it returns None. Here's my code:

from ultralytics import YOLO

# Load a model
model = YOLO('yolov8n.pt')  # pretrained YOLOv8n model

# Run batched inference on a list of images
results = model('00000.png')  # return a list of Results objects

# Process results list
for result in results:
    boxes = result.boxes  # Boxes object for bbox outputs
    masks = result.masks  # Masks object for segmentation masks outputs
    keypoints = result.keypoints  # Keypoints object for pose outputs
    probs = result.probs  # Probs object for classification outputs

print(probs)

When I run the above code, the output for print(probs) is None. The remaining output is

image 1/1 00000.png: 640x640 1 person, 1 zebra, 7.8ms
Speed: 2.6ms preprocess, 7.8ms inference, 1.3ms postprocess per image at shape (1, 3, 640, 640)

Why is the probs attribute returning None, and how can I retrieve the classification probabilities for each detected object? Is there a specific design reason behind this behavior in the Ultralytics YOLOv8 implementation?

Christoph Rackwitz
  • 11,317
  • 4
  • 27
  • 36
hanugm
  • 1,127
  • 3
  • 13
  • 44

2 Answers2

1

I think you should be able to get the confidences with results[0].boxes.conf.

The probs property seems not to be working in Yolov8

Timothee W
  • 149
  • 7
  • 1
    The probs property is active as a result of the object classification task, and it is not generated during the implementation of object detection. – hanna_liavoshka Aug 14 '23 at 12:26
1

The problem is you are trying to get the classification probability values from the results of the detection task. In yolov8 object classification and object detection are the different tasks. Implementing object detection, you will get boxes with class IDs and their confidence. And you will get class IDs and their probs as the object classification result.

If you need exactly the classification probability values, do the object classification task. However, in this case, the hole image will be classified by the one class with the most probability, and no bounding boxes will be generated.

model = YOLO('yolov8n-cls.pt') # load a pretrained classification model
results = model('00000.png')

for result in results:
    probs = result.probs # Probs object for classification outputs
print(probs)

If you need to do object detection, you can access confidence values instead by boxes.conf, but they are not the same as classification probs.

model = YOLO('yolov8n.pt')  # load a pretrained detection model
results = model('00000.png')

for result in results:
    boxes = result.boxes  # Boxes object for bbox outputs
    confs = boxes.data[:, 4:6] # Confidence and class ID of the detected objects
print(confs)

More detailed about the Yolov8 tasks: https://docs.ultralytics.com/tasks/

hanna_liavoshka
  • 115
  • 1
  • 6