AI Computer Institute
Expert-curated CS & AI curriculum aligned to CBSE standards. A bharath.ai initiative. About Us

YOLO: Real-Time Object Detection

📚 Computer Vision⏱️ 25 min read🎓 Grade 10
✍️ AI Computer Institute Editorial Team Updated: September 2026 CBSE-aligned · Peer-reviewed · 25 min read
Content curated by subject matter experts with IIT/NIT backgrounds. All chapters are fact-checked against official CBSE/NCERT syllabi.

At a busy junction in Hyderabad or Bengaluru, an overhead camera watches the signal around the clock. Two-wheelers cross every few seconds, some carrying one rider, some two, occasionally three. A traffic constable stationed at that corner could never check every rider's head, read every number plate, and log every violation in real time, not at that volume, not for sixteen hours a day. Yet several Indian cities now run exactly this check automatically. A camera feed goes into a computer, and within a fraction of a second the system has located every vehicle in the frame, found every rider's head, decided whether a helmet is present, and cropped out the number plate for an e-challan, all before that motorbike has left the frame.

This is object detection: finding every instance of every object in an image and marking exactly where each one sits, for however many objects happen to be in frame. Do this on a single still photograph and there are a few hundred milliseconds to spare. Do it on live video and the budget collapses. A standard camera feed delivers 24 to 30 frames every second, so a real-time system has to find the objects, classify them, and draw their boxes in under roughly 40 milliseconds per frame. Miss that budget and the video stutters, or the system quietly falls behind the feed it is supposed to be watching. YOLO (You Only Look Once) is the family of neural network architectures built to hit that budget, by treating detection as something a single pass through a network could do directly. This chapter works through why that idea mattered and the exact arithmetic YOLO uses to turn a flood of raw guesses into one clean answer per object.

From Classification to Detection

An image classifier answers one question about an entire image: is this a cat, is this a helmet, is this a red signal. It outputs a single label, or a probability for each possible label, and nothing about position. That is enough when a picture has been cropped to contain exactly one subject. A traffic camera frame is nothing like that. A single frame might contain three motorbikes, five people (two wearing helmets, three not), one car, and an auto-rickshaw, all at once, at different distances from the lens and different sizes on screen.

Object detection has to answer two questions for every object it finds, not one: what is it, and where is it. The "where" is usually expressed as a bounding box, the smallest rectangle that encloses the object, described with four numbers. One common convention is (x1, y1, x2, y2), the pixel coordinates of the box's top-left and bottom-right corners. Detection means finding an unknown number of objects, of possibly different classes, scattered anywhere in the frame, and localizing and labelling every one of them in a single pass over a single image.

The Two-Stage Bottleneck

The most direct way to search an image for objects is to check every possible location by brute force: slide a small window across the image, run a classifier on whatever is inside it, then repeat with larger windows to catch bigger objects. This works, in the sense that it eventually looks everywhere, but it is wasteful in the extreme. Most windows contain no object at all, and the classifier has no way to skip them; it has to evaluate each one anyway.

The generation of detectors that came before YOLO improved on this by splitting the job into two stages. R-CNN, introduced by Ross Girshick and colleagues in 2014, first used a separate algorithm to propose roughly two thousand candidate regions in an image that might contain an object, then ran a full convolutional neural network on each region, one at a time, to classify it. Running a CNN two thousand times on a single image took on the order of tens of seconds, hopelessly slow for anything live. Fast R-CNN, from the following year, shared computation across regions instead of repeating it, which helped considerably, but it still depended on a separate, CPU-bound proposal step outside the network. Faster R-CNN closed that gap by folding proposal generation into the network itself, as a second small network trained alongside the classifier. It was faster still, but a frame had to pass through two networks in sequence, a proposal network and a classification network, and the whole pipeline managed only a handful of frames per second on the hardware of the time. None of these came close to the real-time bar of 24 to 30 frames per second that live video demands.

YOLO's Idea: One Look, One Pass

In 2015, Joseph Redmon, Santosh Divvala, Ross Girshick, and Ali Farhadi proposed a different way to frame the whole problem, formally published the following year at the Conference on Computer Vision and Pattern Recognition (CVPR 2016). Instead of first proposing regions and then classifying each one, why not train a single network to look at the full image exactly once and output every box and every class label directly? Their paper, "You Only Look Once: Unified, Real-Time Object Detection," treated detection as one regression problem: raw pixels go in, box coordinates and class probabilities come out, computed in a single forward pass.

YOLO does this by dividing the input image into an S × S grid. In the original version, S = 7, so a 448 × 448 pixel input image is split into 49 cells, each covering a 64 × 64 pixel patch (448 divided by 7 is exactly 64). Every cell is responsible for detecting any object whose centre falls inside it, regardless of how large that object's box actually is; a helmet's box can extend well beyond the borders of the single cell that "owns" it. Each cell predicts B bounding boxes (B = 2 in the original design), and for each box it outputs five numbers: the box's centre coordinates, its width and height, and a confidence score. On top of that, each cell predicts one set of class probabilities, covering the 20 object categories in the PASCAL VOC dataset the original model was trained on. Multiply it out and the network's entire output for one image is a 7 × 7 × 30 tensor: 49 cells, each holding 2 boxes of 5 numbers (10 numbers) plus 20 class probabilities, for 30 numbers per cell.

The confidence score attached to each box is not arbitrary. It is defined as Pr(Object) × IoU(pred, truth), the probability that an object is actually present in that box, multiplied by how well the box overlaps the true object when one exists. Combine that with the class probabilities and each box ends up with a class-specific confidence: how likely the box contains, say, a helmet, and how tightly the box fits it. Because the whole grid is processed in one forward pass through one convolutional network, the base model could run at 45 frames per second, and a smaller variant, Fast YOLO, at roughly 155 frames per second on the hardware available at the time, comfortably inside the real-time budget that two-stage detectors could not reach.

Measuring Overlap: Intersection over Union

That confidence formula leans on a quantity that shows up everywhere in object detection: Intersection over Union, or IoU. IoU measures how well two boxes overlap, on a scale from 0 (no overlap at all) to 1 (identical boxes). It is defined as the area where the two boxes overlap, divided by the total area the two boxes cover between them:

IoU = (area of intersection) / (area of union)

Consider two candidate boxes a detector has drawn around the same rider's head, given as (x1, y1, x2, y2) pixel coordinates:

  • Box A: (200, 80, 260, 140)
  • Box B: (210, 90, 270, 150)

Each box is 60 pixels wide and 60 pixels tall, so each has an area of 60 × 60 = 3600 square pixels. To find where they overlap, take the innermost edges on each side: the overlap's left edge is the larger of the two left edges, max(200, 210) = 210; its right edge is the smaller of the two right edges, min(260, 270) = 260. That gives an overlap width of 260 - 210 = 50 pixels. The same logic on the vertical axis gives an overlap top of max(80, 90) = 90, a bottom of min(140, 150) = 140, and a height of 140 - 90 = 50 pixels. The intersection area is 50 × 50 = 2500 square pixels.

The union is the two areas combined, minus the overlap counted twice: 3600 + 3600 - 2500 = 4700 square pixels. So:

IoU(A, B) = 2500 / 4700 = 0.53

As code, the same calculation looks like this:

def compute_iou(box1, box2):
    # each box is (x1, y1, x2, y2)
    x1 = max(box1[0], box2[0])
    y1 = max(box1[1], box2[1])
    x2 = min(box1[2], box2[2])
    y2 = min(box1[3], box2[3])

    inter_width = max(0, x2 - x1)
    inter_height = max(0, y2 - y1)
    intersection = inter_width * inter_height

    area1 = (box1[2] - box1[0]) * (box1[3] - box1[1])
    area2 = (box2[2] - box2[0]) * (box2[3] - box2[1])
    union = area1 + area2 - intersection

    return intersection / union

box_a = (200, 80, 260, 140)
box_b = (210, 90, 270, 150)
print(round(compute_iou(box_a, box_b), 2))   # 0.53

The max(0, ...) guards matter for boxes that do not overlap at all: if the computed width or height would come out negative, the function reports zero intersection instead, which keeps the IoU correctly at 0 rather than some nonsensical negative area. During training, YOLO uses IoU to check how good a predicted box is against the hand-labelled ground truth box for that object. During actual detection, it uses IoU for a different job: deciding when two predicted boxes are really the same object seen twice.

Too Many Boxes: Non-Maximum Suppression

A 7 × 7 grid gives 49 cells, each proposing multiple boxes, which means a single real object rarely produces just one detection. A rider's head sitting near the boundary between two grid cells can easily trigger box predictions from both neighbouring cells, each fairly confident, each describing more or less the same patch of the image. Reported as-is, the system would flag one bare head as two or three separate violations. Non-Maximum Suppression (NMS) is the cleanup step that collapses these duplicates down to one box per real object.

The algorithm is a simple greedy procedure. Sort every candidate box for a given class by its confidence score, highest first. Take the highest-confidence box, keep it as a final detection, then compare it against every remaining box using IoU: any box whose IoU with the one just kept exceeds a chosen threshold (0.5 is a common choice) is judged to be describing the same object and is discarded. Repeat with whatever boxes are left, until none remain.

Suppose the "no helmet" detector on that junction camera proposes four overlapping candidate boxes for one frame, each a 60 × 60 pixel box around a head-shaped region:

  • Box A, confidence 0.91, at (200, 80, 260, 140)
  • Box B, confidence 0.85, at (210, 90, 270, 150)
  • Box C, confidence 0.78, at (205, 85, 265, 145)
  • Box D, confidence 0.30, at (400, 80, 460, 140), a second rider further along in the same frame

Sorted by confidence, the order is already A, B, C, D. NMS picks A first and keeps it. Comparing A against the rest: IoU(A, B) = 0.53, computed exactly as in the previous section, which is above the 0.5 threshold, so B is suppressed as a duplicate of A. IoU(A, C) works out to 3025 / 4175 ≈ 0.72 (the overlap between A's 60 × 60 box and C's 60 × 60 box, offset by only 5 pixels in each direction), also above the threshold, so C is suppressed too. IoU(A, D) is 0, since A spans x-coordinates 200 to 260 and D spans 400 to 460, with no overlap at all, so D survives this round. One box remains in the pool, D, and since there is nothing left to compare it against, NMS keeps it as well.

The final output is two boxes, not four: A at 0.91 confidence and D at 0.30. Read correctly, that means two riders without helmets in the frame, most likely the driver and a pillion passenger on the same bike, not four. Written as code, reusing the compute_iou function above:

def non_max_suppression(boxes, iou_threshold=0.5):
    # boxes: list of (confidence, x1, y1, x2, y2)
    boxes = sorted(boxes, key=lambda b: b[0], reverse=True)
    kept = []

    while boxes:
        best = boxes.pop(0)
        kept.append(best)
        boxes = [b for b in boxes
                 if compute_iou(best[1:], b[1:]) <= iou_threshold]

    return kept

candidates = [
    (0.91, 200, 80, 260, 140),
    (0.85, 210, 90, 270, 150),
    (0.78, 205, 85, 265, 145),
    (0.30, 400, 80, 460, 140),
]

for confidence, x1, y1, x2, y2 in non_max_suppression(candidates):
    print(f"kept: confidence={confidence:.2f}, box=({x1}, {y1}, {x2}, {y2})")
# kept: confidence=0.91, box=(200, 80, 260, 140)
# kept: confidence=0.30, box=(400, 80, 460, 140)

Trace it by hand and it matches the code exactly: the loop pops A first (highest confidence), keeps it, and filters the remaining list down to only boxes with IoU no greater than 0.5 against A, which removes B and C but keeps D. The next iteration pops D, keeps it, and finds nothing left to filter. This exact arithmetic, IoU followed by NMS, is what stands between a raw neural network output and a challan that names the correct number of riders.

How the Network Learns to See

None of these box predictions are hand-coded. YOLO learns them from thousands of labelled training images, each one marked up in advance with the true bounding boxes and class for every object a human annotator identified. During training, every prediction the network makes is compared against these ground-truth boxes, and the difference is measured by a loss function with three parts: how far off the predicted box coordinates are, how wrong the confidence score is, and how wrong the predicted class is.

Two details from the original loss function are worth knowing because they solve real, practical problems. First, localization error is weighted five times more heavily than classification error, because getting the box position right matters more to a detector's usefulness than getting the label exactly right, and without this the network tends to under-invest in precise coordinates. Second, the vast majority of grid cells in any training image contain no object at all; left unchecked, a network could earn a very low loss simply by predicting "nothing here" everywhere and ignoring the few cells that matter. The original loss function down-weights the confidence error for object-free cells by a factor of 0.5, so the rare cells that do contain something are not drowned out by the many that do not. The network also predicts the square root of a box's width and height rather than the raw pixel values, a small trick that makes a 10-pixel error matter more for a small object than for a large one, since 10 pixels is a much bigger fraction of a helmet than of a bus.

From YOLOv1 to Today's YOLO

The original paper was followed by YOLOv2 (also called YOLO9000) in 2017, which added anchor boxes, pre-defined box shapes the network learns to adjust rather than predicting raw coordinates from nothing, along with batch normalization and a training scheme that combined classification and detection datasets so the model could recognise over 9000 categories, far beyond the 20 classes of PASCAL VOC. YOLOv3, in 2018, moved to a deeper backbone network called Darknet-53 and predicted boxes at three different scales instead of one, which noticeably improved detection of small, distant objects, exactly the kind of case a wide-shot traffic camera runs into constantly.

In February 2020, Redmon announced that he had stopped his computer vision research, citing discomfort with how the technology he had helped build was being used for military and surveillance purposes. Development of the YOLO line continued under other teams: YOLOv4 came from Alexey Bochkovskiy and colleagues later that year, and Ultralytics released YOLOv5 soon after as an easier-to-use PyTorch implementation, which is largely why most YOLO code written today, including the examples in this chapter, targets that ecosystem rather than the original Darknet framework. Later releases such as YOLOv8 and YOLO11 have continued refining the same core idea, with anchor-free prediction and stronger backbones, while keeping the single-pass principle Redmon's team introduced. A practical example of using a modern, pretrained model looks like this:

from ultralytics import YOLO

model = YOLO("yolov8n.pt")          # "n" = nano, the smallest, fastest variant
results = model("junction_frame.jpg")

for box in results[0].boxes:
    class_name = model.names[int(box.cls[0])]
    confidence = float(box.conf[0])
    x1, y1, x2, y2 = box.xyxy[0].tolist()
    print(f"{class_name}: {confidence:.2f} at ({x1:.0f}, {y1:.0f}, {x2:.0f}, {y2:.0f})")

Under the surface, the same core ideas are running: a grid-like scan of the image in one pass, confidence scores, and non-maximum suppression cleaning up the output before it ever reaches that for loop.

One-Stage vs Two-Stage, at a Glance

  • Sliding window: checks every location and every scale by brute force, with no learning of where to look. Simple to describe, far too slow for anything beyond small, controlled images.
  • Two-stage detectors (the R-CNN family): propose candidate regions first, then classify each one separately. Historically strong on accuracy, especially for small or unusual objects, but slower, since two networks run one after the other.
  • One-stage detectors (YOLO, and SSD, released the same year by Wei Liu and colleagues): predict every box and class in a single pass. Fast enough for live video from the start; early versions traded away some accuracy on small or crowded objects for that speed, a gap that later YOLO generations have steadily closed.

YOLO Beyond the Traffic Signal

Helmet and number-plate detection is one visible use of this technology on Indian roads, but the same single-pass architecture shows up well beyond traffic enforcement. Crowd-monitoring systems at large public gatherings, such as the Kumbh Mela, use camera-based detection to estimate crowd density in real time and help authorities spot dangerously packed areas before they turn into crushes. In agriculture, drones fitted with cameras run detection models over farmland to count fruit on trees or flag early signs of pest damage across a field too large to inspect row by row. Wildlife researchers use camera-trap footage and detection models to spot and count animals such as tigers or leopards in Indian forest reserves. This cuts down the hours it once took to sort through that footage by hand. Cricket broadcasts increasingly use similar detection and tracking pipelines to follow the ball and players across a frame in real time for on-screen graphics.

What YOLO Still Gets Wrong

YOLO's grid has a real cost. In the original design, each grid cell predicts only one set of class probabilities, no matter how many boxes that cell proposes. If two different, small objects happen to have their centres in the same cell, such as several two-wheelers packed tightly at a red light, one of them can simply get missed, since the cell has no way to represent two different classes at once. This is precisely the kind of dense, small-object scene that pushed later YOLO versions toward predicting at multiple scales rather than a single grid.

Detection models are also only as good as the conditions they were trained on. A camera view that is well lit and roughly front-on tends to perform far better than one fighting monsoon glare, night-time headlights, or heavy rain, none of which are unusual for an outdoor camera running through an Indian summer and monsoon. And no matter how the architecture is tuned, a YOLO model still needs a large set of correctly labelled example images to learn from; it has no built-in understanding of traffic law or what a helmet is beyond the visual patterns it was shown during training.

Back to the Junction

Dozens of times a second, the camera on that pole runs a frame through a network that slices the image into a grid and proposes boxes with confidence scores. Then it applies exactly the arithmetic worked through above, IoU to measure overlap and non-maximum suppression to collapse duplicates, turning a noisy set of guesses into one clean count of riders and one clean judgement of helmet or no helmet, all inside a budget of a few dozen milliseconds. What made this possible was a smarter formulation of the problem: Redmon and his co-authors reframed detection as a single regression problem that one network could solve in one look, instead of the slower, more cautious two-stage pipeline everyone had been building until then. The specific numbers in that reframing, a 7 × 7 grid, an IoU threshold of 0.5, a confidence score with a precise formula, are what turn a still-experimental idea into something that can run unattended on a traffic pole through an Indian afternoon and get the count right.

Think About It

Think about this: How would you explain yolo: real-time object detection to a friend who has never seen a computer? What real-world analogy would you use? Imagine you had to build a system using these concepts — what would be your first step? Try this: before moving on, write down three things you learned and one question you still have.

Practice Exercises

Now it is time to practice! Complete these challenges to solidify your understanding:

  • Exercise 1: Write a short program that demonstrates the core concept from this chapter. Test it with at least 3 different inputs.
  • Exercise 2: Find a real-world example where yolo: real-time object detection is used in an Indian company (like TCS, Infosys, Flipkart, or ISRO). Write a paragraph explaining the connection.
  • Exercise 3: Create a mind-map connecting yolo: real-time object detection to at least 3 other topics you have studied.

Key Takeaways — Summary and Recap

Let us recap what we covered: the core ideas behind yolo: real-time object detection, how they connect to real-world applications, and why they matter for your journey in computer science. Remember these key points as you move forward. For competitive exam preparation (CBSE, JEE, BITSAT), focus on understanding the WHY behind each concept, not just the WHAT.

← Image Classification: Teaching Machines to SeeImage Segmentation: Pixel-Level Classification →

Found this useful? Share it!

📱 WhatsApp 🐦 Twitter 💼 LinkedIn