Confidence Scores
Every object detection model outputs a confidence score for each detection — a number from 0 to 1 representing how certain the model is that the detection is correct.
6 min•By Priygop Team•Updated 2026
Working with Confidence Scores
Working with Confidence Scores
import cv2
import numpy as np
def filter_detections(detections, confidence_threshold=0.5):
"""
Filter detections by confidence threshold.
Only keep detections where the model is confident enough.
"""
filtered = [d for d in detections if d["confidence"] >= confidence_threshold]
print(f"Before filtering: {len(detections)} detections")
print(f"After filtering (threshold={confidence_threshold}): {len(filtered)}")
return filtered
# Simulated detection output (confidence from a model)
raw_detections = [
{"class": "person", "confidence": 0.95, "bbox": (50, 30, 80, 200)},
{"class": "car", "confidence": 0.88, "bbox": (200, 100, 300, 180)},
{"class": "bicycle", "confidence": 0.45, "bbox": (150, 200, 70, 90)},
{"class": "dog", "confidence": 0.32, "bbox": (400, 300, 60, 80)},
{"class": "cat", "confidence": 0.71, "bbox": (320, 150, 50, 70)},
]
# Filter at different thresholds
strict = filter_detections(raw_detections, 0.8) # High confidence only
medium = filter_detections(raw_detections, 0.5) # Balanced
lenient = filter_detections(raw_detections, 0.3) # Accept more detections
# The confidence threshold trades off precision vs. recall:
# Higher threshold → fewer detections, fewer false positives
# Lower threshold → more detections, more false positives
print("\nGuideline: start with 0.5, adjust based on false positive rate")Diagram
Loading diagram…
Machine Learning follows a structured pipeline from data to deployment