c4dynamics.detectors.yolo3_opencv.yolov3.nms_th#
- property yolov3.nms_th: float#
Gets and sets the Non-Maximum Suppression (NMS) threshold.
Objects with confidence scores below this threshold are suppressed.
- Parameters:
nms_th (float) – The new threshold value for NMS during object detection. Defaults: nms_th = 0.5.
- Returns:
nms_th (float) – The threshold value used for NMS during object detection. Objects with confidence scores below this threshold are suppressed.
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 NMS threshold values to compare:
>>> yolo3 = c4d.detectors.yolov3() Fetched successfully >>> nms_thresholds = [0.1, 0.5, 0.9]
Run the detector on each threshold:
>>> _, axs = plt.subplots(1, 3) >>> for i, nms_threshold in enumerate(nms_thresholds): ... yolo3.nms_th = nms_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"NMS Threshold: {nms_threshold}", fontsize = 6) ... axs[i].axis('off')
A high value (0.9) for the Non-Maximum Suppression (NMS) threshold here leads to an increased number of bounding boxes around a single object. When the NMS threshold is high, it means that a significant overlap is required for two bounding boxes to be considered redundant, and one of them will be suppressed. To address this issue, it’s essential to choose an appropriate NMS threshold based on the characteristics of your dataset and the level of overlap between objects. A lower NMS threshold (e.g., 0.4 or 0.5) is commonly used to suppress redundant boxes effectively while retaining accurate detections. Experimenting with different threshold values and observing their impact on the results is crucial for optimizing the performance of object detection models.