0:00Intro: MOFUSA Tech Academy
Welcome to MOFUSA Tech Academy. Beyond learning, towards mastery.
0:09Not just 'mug': show me where
Last episode's network looks at a photo and says one word: "mug". But Dev's warehouse photos have dozens of products on every shelf. He needs to know how many mugs, and where each one is: to count stock, spot empty gaps, and guide a picking robot. That requires a network that does two things at once: recognise each object, and locate it, with a box around it, or even a precise outline that follows its edges. Today: object detection and segmentation. How networks draw boxes, how we measure whether a box is right, how they clean up duplicate guesses, and how they label every single pixel.
0:53Where we are on the map
Season Two, Module Eight, final stop: object detection and segmentation.
1:00The ladder of vision tasks
Computer vision tasks form a ladder. Classification gives one label for the whole image. Localisation finds one object and draws a box around it. Object detection finds every object: a box, a label and a confidence score for each. Semantic segmentation labels every pixel with a class, so all mugs share one colour. And instance segmentation goes further, separating each individual object: this mug, that mug, the one behind it.
1:31Bounding boxes and IoU, by hand
A bounding box is just four numbers, for example the top-left and bottom-right corners. So predicting a box is a regression problem, like the ones in Season One, sitting alongside a classification of what's inside it. But how do we judge whether a predicted box is good? We measure its overlap with the true box using intersection over union, or I-O-U: the area where they overlap, divided by the total area they cover together. Here's the true box for a mug, and a prediction shifted one unit to the right. They overlap in an area of twelve, and together cover twenty.
IoU: zero point six. A prediction shifted further, diagonally, overlaps only four out of twenty-eight: about zero point one four. A common rule counts a detection as correct when its IoU is at least a half. Some benchmarks are stricter, and average over several thresholds.
2:32How detectors predict: anchor boxes
How does a network produce many boxes at once? A common approach divides the image into a grid. At every grid cell, the network considers a few template boxes of different shapes, called anchor boxes: tall ones for bottles, wide ones for boxes, square ones for mugs. For each anchor, it predicts three things: is there an object here at all, what class is it, and how should this template be shifted and stretched to fit the object tightly. Remember that a CNN's feature map is itself a grid, where each cell describes its own region of the image.
That makes this a natural fit. Newer detectors sometimes drop anchors altogether, predicting object centres directly or using attention, but the core idea is the same: dense predictions, plus box regression.
3:26Two-stage vs one-stage detectors (R-CNN, YOLO)
Detectors come in two main families. Two-stage detectors, like the R-CNN family, first propose regions that might contain an object, then classify and refine each proposal carefully. They were long the accuracy leaders. One-stage detectors, like YOLO, which stands for "you only look once", predict all the boxes and classes in a single pass through the network. That makes them fast enough for real-time video, like a robot moving through the warehouse. Over the years, the gap between the two families has narrowed a lot, and modern versions of both are widely used.
Keep in mind that details like these change fast. They were correct when this video was published, so treat them as a snapshot, not a permanent fact.
4:17Non-maximum suppression
Because predictions are dense, a single mug usually gets many overlapping boxes, all fairly confident. We need just one. The standard clean-up step is non-maximum suppression. Take the most confident box, here zero point nine, and keep it. Remove every other box that overlaps it heavily, with an IoU of a half or more. The zero point eight box overlaps it with an IoU of zero point six, so it's a duplicate, and it's removed. The zero point seven box doesn't overlap at all, so it must be a different object, and it stays.
Repeat until no boxes are left to check. In very crowded scenes, two real objects can overlap so much that one gets wrongly suppressed. That's why the threshold is tuned for each application, and why some newer detectors avoid this step entirely.
5:14Measuring detectors: AP and mAP
How do we score a detector? With the precision and recall from episode twelve, adapted to boxes. A detection is a true positive if it matches a real object with enough IoU, and a false positive otherwise. Say an image has four mugs. Sort the detector's guesses by confidence. The first is correct: precision one, recall a quarter. The second, correct: precision one, recall a half. The third is a kettle mistaken for a mug: precision falls to two thirds. The fourth is correct: precision three quarters, recall three quarters.
One mug is never found. Plot precision against recall and measure the area under the staircase. That's the average precision: here about zero point six nine. Average it over every class, and often over several IoU thresholds, and you get the headline number in detection research: the mean average precision, or m-A-P.
6:15Segmentation: a label for every pixel (U-Net)
Segmentation asks for even more: a label for every single pixel. That's a challenge, because a CNN shrinks the image as it goes deeper. By the end, a large photo might be represented by a seven-by-seven grid. Great for knowing what is there, poor for knowing exactly where. The solution is an encoder–decoder. The encoder is a normal CNN that shrinks the image and builds up understanding. The decoder then grows it back to full size, step by step, using learned upsampling. The most famous design, U-Net, from two thousand fifteen, adds skip connections that bridge from each level of the encoder straight across to the matching level of the decoder, carrying fine detail like sharp edges.
It was invented for medical images, and its U shape is now everywhere. The output is a class probability for every pixel, trained with cross-entropy at every pixel. And to separate individual objects, instance segmentation methods like Mask R-CNN add a small mask predictor to a detector, giving each detected box its own pixel outline. For Brightcart, that means automatically cutting each product out of its background for the shop's product pages.
7:38Try it yourself: two IoU puzzles
Two quick IoU puzzles. First: the true box covers a four-by-four square, and the prediction covers only its left half. What's the IoU? Pause. The overlap is eight, the union is sixteen: exactly a half, right on the usual threshold. Second: the prediction is the same size as the true box, but shifted one unit right and one unit down.
The overlap is three by three, nine. The union is sixteen plus sixteen minus nine, twenty-three. The IoU is about zero point three nine, below a half, so a detector would count it as a miss. A tiny diagonal shift costs more than you might expect, which is why precise box regression matters.
8:34Training a detector: two losses at once
How is a detector trained? Each prediction that's matched to a real object gets two losses at once: a classification loss, saying what the object is, and a regression loss on the box coordinates, often based on IoU itself. Predictions that don't match any object are trained to say "background". And because most locations in an image contain nothing, detectors use special techniques to stop the flood of easy background examples from drowning out the rare, informative ones.
9:06Counting stock from shelf photos
Let's make it concrete. Dev photographs warehouse shelves every morning. The detector boxes every product, the boxes are counted per product, and the counts are compared with the inventory system. Gaps, or items on the wrong shelf, trigger alerts. The real-world challenges: products hidden behind others, near-identical designs, and changing light and angles. A sensible system routes uncertain detections to a person, and measures what the business actually cares about, the counting error per shelf, alongside mAP.
9:43Segmentation in more detail
A few more details about segmentation. To grow the feature maps back to full size, decoders use either learned transposed convolutions or simple interpolation followed by convolution, which tends to produce fewer artefacts. Skip connections bring back the fine detail. The loss is computed at every pixel, and when the object is small compared with the background, it's often combined with an overlap-based loss so the background doesn't dominate. And segmentation is scored with IoU again, this time over pixels, averaged across classes.
10:22Choosing the right task
Choose the simplest task that answers your question, because labelling costs rise steeply up the ladder. If you only need to know whether a photo contains a mug, classification is enough, and labels are quick. If you need counts and positions, you need boxes. If you need exact outlines, for removing backgrounds, you need pixel masks, which are much slower to label. And separating each individual object takes even more. Labelling cost often decides which approach is practical.
10:55Video and tracking, briefly
Finally, video. Run a detector on every frame, then link the boxes from one frame to the next so each object keeps its identity, a parcel labelled "number forty-two" all the way along the conveyor belt. That's tracking, and it lets Brightcart count parcels and monitor robots. Keeping things consistent from frame to frame is a challenge we'll meet again when we study video generation in Season Three.
11:22Try it yourself: non-maximum suppression
Let's run non-maximum suppression by hand. The detector has produced four boxes for mugs, with scores zero point nine, zero point eight, zero point seven and zero point six. Our threshold is an IoU of a half. How many mugs will we report? Pause.
Start with the most confident box, A, and keep it. Box B overlaps A with an IoU of zero point seven five, above a half, so it's a duplicate: remove it. Box D overlaps A at zero point six: also removed. Box C doesn't touch A at all, so it stays. Two boxes survive, and the shelf really does have two mugs. Set the threshold too low, though, and two mugs standing side by side could merge into one.
12:19The trouble with small objects
Small objects are the hardest. A barcode twenty pixels wide shrinks to about a single cell after the feature maps have been halved four times, so there's barely any information left. Detectors fight back with feature pyramids, detecting small objects on the sharper, early maps and large objects on the coarse, later ones. Raising the input resolution helps, and so does cutting huge images into overlapping tiles. That's why detection results are often reported separately for small, medium and large objects.
12:57Myth vs Fact
Myth: a detector with a great benchmark score will work in my warehouse. Fact: benchmarks use their own kinds of photos. Different lighting, unusual angles and products hidden behind each other can make performance drop sharply. Always evaluate on images from your real setting, and fine-tune on them if needed.
13:19Recap
Let's recap. Vision tasks climb from classification to detection to segmentation. A box is four numbers, and IoU measures how well two boxes overlap. Detectors make dense predictions, in one stage or two, then non-maximum suppression removes duplicates, and average precision measures how good they are. Segmentation uses encoder–decoder networks like U-Net, whose skip connections restore fine detail, to label every pixel. One sentence to remember: find it, box it, keep the best box, then colour every pixel.
13:56Next: recurrent neural networks
Mission complete. Dev's warehouse photos now come back with every product boxed, labelled and counted, and the product pages get clean cut-outs. And that completes Module Eight, computer vision. Next, a new kind of data, where order matters: sentences, reviews, time series. "Not good" and "good, not bad" contain similar words but mean very different things. To read them, networks need memory. Welcome to recurrent neural networks. See you on the map.