CV YOLO Real-Time Detection
YOLO stands for You Only Look Once. Joseph Redmon and colleagues introduced the idea in 2015, and the name describes the trick: the network examines the whole image in a single pass and predicts every object at once. Earlier detectors scanned thousands of candidate regions one by one. YOLO skips that slow loop and runs fast enough for live video.
The Grid Idea
Picture a chessboard laid over the photo. Each square takes responsibility for any object whose center falls inside it. Every square predicts a few boxes, a confidence score for each box, and class probabilities.
+----+----+----+----+ | | | | | +----+----+----+----+ | | *--+----+--* | * = center of the dog | | [ DOG ] | The square holding the center +----+----+----+----+ predicts the dog box | | | | | +----+----+----+----+
What the Network Predicts
- Box position: center x and center y
- Box size: width and height
- Confidence: how sure the model feels that a box holds an object
- Class scores: dog, car, person, and so on
A single forward pass fills a large table of such numbers. Post-processing turns the table into a clean list of detections.
Cleaning Up With Non-Maximum Suppression
Neighboring squares often predict the same object, so raw output contains many overlapping boxes. Non-maximum suppression, or NMS, keeps the best one.
Raw boxes on one dog: After NMS: [0.91] [0.84] [0.62] [0.91] overlapping stack single winner
- Sort boxes by confidence from high to low
- Keep the top box
- Remove every box whose IoU with the kept box exceeds a threshold, such as 0.5
- Repeat with the remaining boxes
Running YOLO in Python
The Ultralytics library packages pretrained YOLO models behind a short interface.
pip install ultralytics
from ultralytics import YOLO
model = YOLO("yolov8n.pt") # smallest and fastest size
results = model("street.jpg")
for box in results[0].boxes:
cls = int(box.cls[0])
conf = float(box.conf[0])
x1, y1, x2, y2 = box.xyxy[0].tolist()
print(model.names[cls], round(conf, 2), (x1, y1, x2, y2))
results[0].save("detected.jpg")Newer YOLO releases appear regularly, and the same interface usually works with updated model file names.
Model Sizes
YOLO families ship in several sizes. Pick the smallest model that meets the accuracy goal.
Size Letter Speed Accuracy Good for ------- ------ --------- --------- ------------------ Nano n fastest lowest phones, tiny boards Small s very fast good embedded cameras Medium m fast better desktop apps Large l moderate high servers Extra x slowest highest accuracy-first work
Training on Your Own Data
Custom detection needs labeled images. YOLO expects one text file per image, with one line per object.
class_id x_center y_center width height (all values from 0 to 1) 0 0.512 0.430 0.210 0.380
model = YOLO("yolov8n.pt")
model.train(data="mydata.yaml", epochs=50, imgsz=640)
metrics = model.val()The YAML file lists the image folders and class names. Fine-tuning from pretrained weights reaches good results with a few hundred labeled images.
Tuning the Confidence Threshold
Low thresholds find more objects and add false alarms. High thresholds cut false alarms and miss targets. A starting value near 0.25 suits exploration, and 0.5 or higher suits strict applications.
Strengths and Limits
- Strength: real-time speed on modest hardware
- Strength: simple pipeline from training to deployment
- Limit: tiny objects far from the camera can disappear after resizing
- Limit: crowded scenes with heavy overlap cause missed detections
Practical Tips
- Match training image size to deployment image size
- Label small objects carefully, since boxes only a few pixels wide hurt accuracy
- Include background photos without targets to reduce false alarms
- Review mAP and the confusion matrix after every training run
Practice Exercise
Run the nano model on ten photos from your phone. Record how many objects it finds and how many it misses. Move the confidence threshold from 0.25 to 0.6 and note how counts change. Run the same script on a webcam stream and measure frames per second.
Reading the Output Like a Pro
Each detection carries a class name, a confidence score, and four box numbers. Draw the box on the frame and print the label above it. Count detections per class to build simple analytics, such as the number of cars crossing a road in one minute. Save the annotated video to review mistakes later.
Frame 1: car 0.91 person 0.78 person 0.66 Frame 2: car 0.93 person 0.80 Frame 3: car 0.90 person 0.74 bicycle 0.58
Sudden confidence swings between frames hint at weak training examples for that class. Collect more photos that match the troubled scene and train again.
