c4dynamics.detectors.yolo3_opencv.yolov3.confidence_th#
- property yolov3.confidence_th: float#
Gets and sets the confidence threshold used in the object detection.
Detected objects with confidence scores below this threshold are filtered out.
- Parameters:
confidence_th (float) – The new confidence threshold for object detection. Defaults: confidence_th = 0.5.
- Returns:
confidence_th (float) – The confidence threshold for object detection. Detected objects with confidence scores below this threshold are filtered out.
Example
Import required packages:
>>> import c4dynamics as c4d >>> from matplotlib import pyplot as plt >>> import cv2
Fetch ‘planes.png’ using the c4dynamics’ datasets module (see
c4dynamics.datasets
):>>> impath = c4d.datasets.image('planes') Fetched successfully
Load YOLOv3 detector and set 3 confidence threshold values to compare:
>>> yolo3 = c4d.detectors.yolov3() Fetched successfully >>> confidence_thresholds = [0.9, 0.95, 0.99]
Run the detector on each threshold:
>>> _, axs = plt.subplots(1, 3) >>> for i, confidence_threshold in enumerate(confidence_thresholds): ... yolo3.confidence_th = confidence_threshold ... img = cv2.imread(impath) ... pts = yolo3.detect(img) ... for p in pts: ... cv2.rectangle(img, p.box[0], p.box[1], [0, 255, 0], 2) ... axs[i].imshow(cv2.cvtColor(img, cv2.COLOR_BGR2RGB)) ... axs[i].set_title(f"Confidence Threshold: {confidence_threshold}", fontsize = 6) ... axs[i].axis('off')
A single object being missed, particularly when setting the confidence threshold to 0.99, suggests that the model is highly confident in its predictions. This level of performance is typically achievable when the model has been trained on a diverse and representative dataset, encompassing a wide variety of object instances, backgrounds, and conditions.