Skip to content

Boxes, overlap and duplicates: IoU, NMS, R-CNN and YOLO

How a detector writes a box, how intersection over union decides what counts as found, how non-maximum suppression removes duplicates, and how R-CNN and YOLO built detectors on them.

Applied ~15 min9 steps

What runs in CodeSplash

You will be able to

  • Convert between corner, corner-plus-size and center box formats
  • Compute the intersection over union of two boxes
  • Trace non-maximum suppression on a few scored boxes
  • Contrast R-CNN's proposals-then-classify pipeline with YOLO's single pass

Read first

01

Writing down a box

Read

A box is four numbers, in one of three common layouts:

  • Corners: top-left and bottom-right, (x0, y0, x1, y1).
  • Corner plus size: top-left, width and height. COCO files use this.
  • Center plus size: (cx, cy, w, h). YOLO files use this, often divided by the image size.

Image y grows downward. Reading one layout as another still produces boxes, all in the wrong places, so convert explicitly and draw a few on their images before training or scoring. CodeSplash's boxes tableBoxes and masks tableOne row per object: image id, box corners in pixels, class, score, mask (COCO RLE), area and source (annotation or prediction). stores corners in pixels, one row per box.

02

Overlap: intersection over union

Read

IoUIntersection over union (IoU) of boxesThe area two boxes share divided by the area they cover together: 1 for the same box, 0 when they don't touch. is the area two boxes share divided by the area they cover together. The R-CNN program compares three candidate boxes with one labeled box from (0, 0) to (2, 2): the same box scores 1, a copy moved one unit right and down scores 0.143 (shared 1, covered 4 + 4 − 1 = 7), and a distant box 0.

Python
import numpy as np

def iou(a, b):
    """Boxes as (x0, y0, x1, y1)."""
    w = max(0.0, min(a[2], b[2]) - max(a[0], b[0]))
    h = max(0.0, min(a[3], b[3]) - max(a[1], b[1]))
    inter = w * h
    area = lambda r: (r[2] - r[0]) * (r[3] - r[1])
    return inter / (area(a) + area(b) - inter)

label = (0, 0, 2, 2)
print([iou(c, label) for c in [(0, 0, 2, 2), (1, 1, 3, 3), (4, 4, 5, 5)]])
R
iou <- function(a, b) {
  # boxes as c(x0, y0, x1, y1)
  w <- max(0, min(a[3], b[3]) - max(a[1], b[1]))
  h <- max(0, min(a[4], b[4]) - max(a[2], b[2]))
  inter <- w * h
  area <- function(r) (r[3] - r[1]) * (r[4] - r[2])
  inter / (area(a) + area(b) - inter)
}
label <- c(0, 0, 2, 2)
print(sapply(list(c(0, 0, 2, 2), c(1, 1, 3, 3), c(4, 4, 5, 5)), iou, b = label))
03

Slide one box

Predict

Predict first

Two 2 × 2 boxes; the second is moved one unit to the right only. What is their IoU?

About a halfAbout a thirdAbout a seventh
Reveal

A third. They share a 1 × 2 strip (area 2) and cover 4 + 4 − 2 = 6. A diagonal move of the same length gives a seventh: IoU drops fast as boxes slide apart.

04

R-CNN: propose, then classify

Read
Reference · VIS001 · Explained hereR-CNNR-CNN detects objects by classifying externally proposed image regions using convolutional features. It is historically important because it connected pretrained image representations to localization;

R-CNN took about 2,000 region proposalsRegion proposalA candidate box that might hold an object, made before classification. A detector can't find what no proposal covers. per image from an outside algorithm, warped each to the CNN's input size, ran the CNN on every one and scored the features with one linear SVM per class. A proposal counted as a positive training example when its IoU with a labeled box reached 0.5.

In the program, the shifted box (IoU below 0.5) is a negative that scored above zero, so its hinge loss is 1.20; the distant box scored below zero but inside the margin and costs 0.200. Two limits follow: no proposal, no detection; and one CNN pass per proposal made it slow.

05

YOLO: one look

Read
Reference · VIS005 · Explained hereYOLO detection familyYOLO denotes a broad family of one-pass object detectors. The original model jointly predicted boxes and classes over an image grid; subsequent versions materially changed heads, matching, losses and postprocessing.

YOLO drops proposals. It lays a grid over the image; each cell predicts a few boxes, an objectness score and class probabilities, all in one network pass. A box's class score is objectness times class probability: the program's three boxes score 0.810, 0.720 and 0.560.

Later versions changed the backbone, anchors and losses; the single pass stayed, which is why YOLO runs in real time. Recent Ultralytics YOLO code and weights are under the AGPL license, so CodeSplash doesn’t ship them.

06

Remove the duplicates

Read

A detector fires several boxes on one object. Non-maximum suppressionNon-maximum suppression (NMS)Of two boxes of one class overlapping more than a set intersection over union, only the higher-scoring one is kept. sorts boxes by score, keeps the best, deletes boxes of the same class that overlap it by more than a threshold, and repeats with what's left.

In the YOLO program the two top boxes cover nearly the same area, so the second is deleted; the distant third box survives. The kept boxes are numbers 0 and 2, counting from zero.

DExplorable · Boxes, IoU, non-maximum suppression and average precision

How does a detector turn a cloud of overlapping guesses into one box per object, and how is it scored?

After NMS at this threshold, will every object still have at least one box?

How sure?

Scene

Three well-separated objects, two people standing close together plus one more, or four small objects.

0.70

A box is dropped when it overlaps a higher-scoring kept box by more than this IoU.

0.30

Candidates scoring below this are dropped before NMS.

IoU to count a hit

A kept box counts as a true positive when it overlaps an unmatched object by at least this much.

0.08

How far the detector's guesses wander from each true box, as a share of its size.

1230.990.990.860.750.740.710.690.580.31

Numbers on the kept boxes are their scores. AP averages the best precision reachable at 101 recall levels, so a false positive ranked above a hit costs more than one ranked last.

Commit your prediction above to see the result

Make your prediction first; the figure appears when you commit.

Make your prediction to see the result.

07

Boxes in CodeSplash

Read

The Object detection method runs a pretrained Faster R-CNN with NMS built in, and writes its boxes to a boxes table you can count, filter and score:

Object detection (Faster R-CNN, COCO)Recorded · Python and R agreeRecorded 2026-11-25 · 26 values compared
R

3 objects in 3 of 5 images; most common: cat (1).

Objects
3
Images
5
Classes found
3
Objects per image
0.6000

Plots

Detected objectsWhat did the detector or segmenter find in each image, and where exactly?
View data
Height (px)ImageClassMedia idScoreWidth (px)x0x1y0y1
160cat.pngcat0eaeb6793ad08de630a090bbf7b187aa30acbc292e63d298d3ff0338cec02a500.99452404.049210.150.2764158.14
160cup.pngcup0f2f46f52111cb7dc1a71df8df67fa7af376bf66c5304888c767b881a4c9c6a60.975624065.684168.947.390123.73
192astronaut.pngpersonf37291cf2c47100683468e90bd3810c1f03d64d8eb9c51f8972c9160a9de5d220.89181926.176141.005.883190.94
150shapes.png—fb6409af86ab2ef69eff6ef058e1227929f5a75ad407435a729a370097b2578c—200————
48flat.png—81d0ef9f87003b2a8f4726bd99d84744e070a37fc2ba0a63f1537fd951587a11—64————
Objects by classHow often does each category occur?
View data
Class
cat
cup
person

Assumptions

  • COCO's 80 classes — Only COCO's everyday classes (people, vehicles, animals, household objects) can be found; anything else is missed or given the nearest class.
  • Score threshold — Objects scored below 0.5 are dropped. Lower it to find more objects (and more false ones).
  • Photos like COCO's — The model learned from everyday photos; drawings, microscopy, aerial or medical images need a model trained on them.
  • People in images — 1 images show people. Treat them as personal data; results stay on this computer.

Objects by class

ClassObjectsImagesMean scoreHighest score
cat110.99450.9945
cup110.97560.9756
person110.89180.8918

Objects per image

RowFileObjectsClasses
1cat.png1cat
2cup.png1cup
3astronaut.png1person
4shapes.png0
5flat.png0
  • 1 rows have no path and are left out.
  • 1 files could not be decoded and are left out.
The exact R script · R R version 4.5.1 (2025-06-13)
# Object detection (Faster R-CNN, COCO)
# Generated by CodeSplash Analytics 1.0.0 on 2026-11-09 · method detect.objects 1.0.1 · spec 8b376c52a30d1405
# Dataset: img3_photos (version 1)
# Runs on its own: outside the app, cs_publish() writes $CS_RESULT_PATH or prints the result JSON.

# %% Setup
library(codesplashr)

ARCH <- "fasterrcnn_mobilenet_v3_large_fpn"
# %% Images listed in the path column
PATH <- "path"
df <- as.data.frame(nanoparquet::read_parquet("tests/parity/fixtures/img3_photos.parquet", col_select = PATH))
if (!nrow(df)) cs_error("CS_E_NO_ROWS")
warnings <- character(0)
# %% Media files (image column path)
# In the app the files were decoded once into float32 arrays (media.json in the run folder). Elsewhere they are
# decoded here the same way: PNG and WAV give the app's values; JPEG, MP3 and other lossy files can differ slightly.
media <- cs_media_setup(jsonlite::fromJSON("{\"ids_column\":\"media_id\",\"kind\":\"image\",\"path_column\":\"path\",\"role\":\"image\",\"transform\":{\"filter\":\"triangle\",\"fit\":\"within\",\"mode\":\"rgb\",\"normalize\":\"none\",\"size\":[1333,1333]}}", simplifyVector = FALSE), "target/academy-parity/run-8142/detect.objects/fast_defaults_small/out-r", df,
                        "tests/parity/fixtures/img3_photos.parquet")
media_ids <- cs_media_ids(media, df)

text_ <- function(v) { v <- as.character(v); v[!is.na(v) & !nzchar(v)] <- NA_character_; v }
paths_ <- text_(df[[PATH]])
has_id <- which(!is.na(media_ids) & !is.na(paths_))
if (!length(has_id)) cs_error("CS_E_ALL_MISSING", column = PATH)
status_ <- cs_media_status(media, media_ids[has_id])
ok <- has_id[is.na(status_)]
n_no_path <- nrow(df) - length(has_id)
n_unreadable <- length(has_id) - length(ok)
if (!length(ok)) cs_error("CS_E_INVALID_VALUES", column = PATH, requirement = "an image file that can be decoded", count = length(has_id))
if (n_no_path) warnings <- c(warnings, sprintf("%d rows have no path and are left out.", n_no_path))
if (n_unreadable) warnings <- c(warnings, sprintf("%d files could not be decoded and are left out.", n_unreadable))
items <- lapply(ok, function(k) list(media_id = media_ids[k], file = basename(paths_[k]), row = k - 1L))

# One decoded image (3, h, w) on 0-1 and its size before decoding (orientation applied).
load_image <- function(mid) {
  a <- cs_media_load(media, mid)
  list(image = array(a, dim = dim(a)[-1]), size = cs_media_source_size(media, mid)[[1]])
}

# %% Pretrained model and compute profile
cs_deep_profile_configure(list(profile = "parity"))
cs_deep_torch()
model <- cs_vis_load(ARCH, dtype = cs_deep_profile_current()$dtype)

# %% Detect objects (torchvision fasterrcnn_mobilenet_v3_large_fpn on the converted COCO weights)
SCORE <- 0.5
MIN_SIZE <- 320
CLASSES <- unlist(c())
run <- cs_vis_detect_images(model, items, load_image, masks = FALSE, min_size = MIN_SIZE, max_size = 1333,
                            score_threshold = SCORE, nms_threshold = 0.5,
                            max_detections = 100, classes = CLASSES)
table <- run$table
s <- cs_vis_summarize(table, run$images)
values <- c(list(n_rows = nrow(df), n_no_path = n_no_path, n_unreadable = n_unreadable), s$values,
            list(model = cs_vis_model_info(ARCH)$label, min_size = MIN_SIZE, score_threshold = SCORE))

# %% Artifacts: the boxes table (one row per object) and one row per image
out <- cs_ml_out_dir("target/academy-parity/run-8142/detect.objects/fast_defaults_small/out-r")
cs_boxes_write(table, file.path(out, "boxes.parquet"))
per <- data.frame(row = vapply(run$images, function(r) r$row + 1L, 0L),
                  media_id = vapply(run$images, function(r) r$media_id, ""),
                  file = vapply(run$images, function(r) r$file, ""),
                  width = vapply(run$images, function(r) r$width, 0L),
                  height = vapply(run$images, function(r) r$height, 0L),
                  objects = vapply(run$images, function(r) as.integer(r$objects), 0L), stringsAsFactors = FALSE)
nanoparquet::write_parquet(per, file.path(out, "images.parquet"))

# %% Result
ov <- cs_vis_overlay_columns(table, run$images)
charts <- list(cs_chart("overlay", "image-overlay", "Detected objects", list(
  image = cs_col("Image", ov$image, "categorical"),
  media_id = cs_col("Media id", ov$media_id, "categorical"),
  x0 = cs_col("x0", ov$x0, "numeric"), y0 = cs_col("y0", ov$y0, "numeric"),
  x1 = cs_col("x1", ov$x1, "numeric"), y1 = cs_col("y1", ov$y1, "numeric"),
  label = cs_col("Class", ov$label, "categorical"),
  score = cs_col("Score", ov$score, "numeric"),
  width = cs_col("Width (px)", ov$width, "numeric"), height = cs_col("Height (px)", ov$height, "numeric")
), controls = list(threshold = SCORE)))
if (nrow(table)) {
  charts[[length(charts) + 1L]] <- cs_chart("classes", "bar", "Objects by class", list(
    x = cs_col("Class", as.character(table$label), "categorical", s$order)))
}
n_person <- if (is.null(values[["n[person]"]])) 0L else values[["n[person]"]]
img_person <- if (is.null(values[["images[person]"]])) 0L else values[["images[person]"]]
assumptions <- c(list(
  list(key = "coco_classes", label = "COCO's 80 classes", status = "info",
       detail = "Only COCO's everyday classes (people, vehicles, animals, household objects) can be found; anything else is missed or given the nearest class."),
  list(key = "threshold", label = "Score threshold", status = "info",
       detail = sprintf("Objects scored below %s are dropped. Lower it to find more objects (and more false ones).", format(SCORE))),
  list(key = "domain", label = "Photos like COCO's", status = "info",
       detail = "The model learned from everyday photos; drawings, microscopy, aerial or medical images need a model trained on them."),
  list(key = "people", label = "People in images", status = if (n_person > 0) "warn" else "pass",
       detail = if (n_person > 0) sprintf("%d images show people. Treat them as personal data; results stay on this computer.", img_person) else "No person was detected.")
), cs_deep_profile_warning_rows())
image_cols <- list(list(key = "row", label = "Row", type = "integer"), list(key = "file", label = "File"),
                   list(key = "objects", label = "Objects", type = "integer"), list(key = "classes", label = "Classes"))
class_cols <- list(list(key = "class", label = "Class"), list(key = "objects", label = "Objects", type = "integer"),
                   list(key = "images", label = "Images", type = "integer"), list(key = "mean_score", label = "Mean score", type = "number"),
                   list(key = "max_score", label = "Highest score", type = "number"))
cs_publish(list(
  title = "Object detection (Faster R-CNN, COCO)",
  engine = cs_engine_info("torch", "torchvision", "safetensors", "nanoparquet", "codesplashr"),
  n = values$n_images,
  summary = paste0(sprintf("%d objects in %d of %d images", values$n_objects, values$n_images_with_objects, values$n_images),
                   if (length(s$order)) sprintf("; most common: %s (%d).", s$order[1], values[[sprintf("n[%s]", s$order[1])]]) else "."),
  statistics = list(
    list(key = "n_objects", label = "Objects", value = values$n_objects, format = "integer"),
    list(key = "n_images", label = "Images", value = values$n_images, format = "integer"),
    list(key = "n_classes", label = "Classes found", value = values$n_classes, format = "integer"),
    list(key = "objects_per_image", label = "Objects per image", value = values$objects_per_image)
  ),
  tables = list(
    list(key = "classes", title = "Objects by class", columns = class_cols, rows = s$classes),
    list(key = "images", title = "Objects per image", columns = image_cols, rows = s$images[seq_len(min(200L, length(s$images)))])
  ),
  assumptions = assumptions,
  charts = charts,
  values = values,
  warnings = as.list(warnings),
  artifacts = list(list(key = "boxes", path = file.path(out, "boxes.parquet"), format = "parquet"),
                   list(key = "images", path = file.path(out, "images.parquet"), format = "parquet"))
))
Python

3 objects in 3 of 5 images; most common: cat (1).

Objects
3
Images
5
Classes found
3
Objects per image
0.6000

To keep this page light, the plots are shown once, under the R tab.

Assumptions

  • COCO's 80 classes — Only COCO's everyday classes (people, vehicles, animals, household objects) can be found; anything else is missed or given the nearest class.
  • Score threshold — Objects scored below 0.5 are dropped. Lower it to find more objects (and more false ones).
  • Photos like COCO's — The model learned from everyday photos; drawings, microscopy, aerial or medical images need a model trained on them.
  • People in images — 1 images show people. Treat them as personal data; results stay on this computer.

Objects by class

ClassObjectsImagesMean scoreHighest score
cat110.99450.9945
cup110.97560.9756
person110.89180.8918

Objects per image

RowFileObjectsClasses
1cat.png1cat
2cup.png1cup
3astronaut.png1person
4shapes.png0
5flat.png0
  • 1 rows have no path and are left out.
  • 1 files could not be decoded and are left out.
The exact Python script · Python Python 3.13.5 · scipy 1.18.1 · pandas 3.1.0
# Object detection (Faster R-CNN, COCO)
# Generated by CodeSplash Analytics 1.0.0 on 2026-11-09 · method detect.objects 1.0.1 · spec 8b376c52a30d1405
# Dataset: img3_photos (version 1)
# Runs on its own: outside the app, cs.publish() writes $CS_RESULT_PATH or prints the result JSON.
# %% Setup
import os

import numpy as np
import pandas as pd

import codesplash as cs
from codesplash import media as cs_media
from codesplash import ml as csml
from codesplash.deep import core as cs_core
from codesplash.deep import profile as cs_profile
from codesplash.vision import boxes as vbox
from codesplash.vision import detect as vdet

ARCH = "fasterrcnn_mobilenet_v3_large_fpn"
# %% Images listed in the path column
PATH = "path"
df = pd.read_parquet("tests/parity/fixtures/img3_photos.parquet", columns=[PATH])
if not len(df):
    cs.cs_error("CS_E_NO_ROWS")
warnings = []
# %% Media files (image column path)
# In the app the files were decoded once into float32 arrays (media.json in the run folder). Elsewhere they are
# decoded here the same way: PNG and WAV give the app's values; JPEG, MP3 and other lossy files can differ slightly.
import json as _media_json
from codesplash import media as cs_media
media = cs_media.setup(_media_json.loads("{\"ids_column\":\"media_id\",\"kind\":\"image\",\"path_column\":\"path\",\"role\":\"image\",\"transform\":{\"filter\":\"triangle\",\"fit\":\"within\",\"mode\":\"rgb\",\"normalize\":\"none\",\"size\":[1333,1333]}}"), "target/academy-parity/run-8142/detect.objects/fast_defaults_small/out-python", df, "tests/parity/fixtures/img3_photos.parquet")
media_ids = cs_media.ids_of(media, df)


def _text(v):
    return None if pd.isna(v) else str(v)  # None, NaN, pd.NA


has_id = [k for k, m in enumerate(media_ids) if m is not None and _text(df[PATH].iloc[k]) not in (None, "")]
if not has_id:
    cs.cs_error("CS_E_ALL_MISSING", column=PATH)
_status = cs_media.status(media, [media_ids[k] for k in has_id])
ok = [k for k, s in zip(has_id, _status) if s is None]
n_no_path = len(df) - len(has_id)
n_unreadable = len(has_id) - len(ok)
if not ok:
    cs.cs_error("CS_E_INVALID_VALUES", column=PATH, requirement="an image file that can be decoded", count=len(has_id))
if n_no_path:
    warnings.append(f"{n_no_path} rows have no path and are left out.")
if n_unreadable:
    warnings.append(f"{n_unreadable} files could not be decoded and are left out.")
items = [{"media_id": media_ids[k], "file": os.path.basename(str(df[PATH].iloc[k])), "row": k} for k in ok]


def load_image(mid):
    """One decoded image (3, h, w) on 0–1 and its size before decoding (orientation applied)."""
    return cs_media.load(media, [mid])[0], tuple(cs_media.source_size(media, [mid])[0])


# %% Pretrained model and compute profile
cs_profile.configure({"profile": "parity"})
cs_core.torch_init()
model = vdet.load(ARCH, dtype=cs_profile.current().dtype)

# %% Detect objects (torchvision fasterrcnn_mobilenet_v3_large_fpn on the converted COCO weights)
SCORE = 0.5
MIN_SIZE = 320
CLASSES = [] or None
run = vdet.detect_images(model, items, load_image, masks=False, min_size=MIN_SIZE, max_size=1333, score_threshold=SCORE,
                         nms_threshold=0.5, max_detections=100, classes=CLASSES)
table = run["table"]
s = vdet.summarize(table, run["images"])
values = {"n_rows": len(df), "n_no_path": n_no_path, "n_unreadable": n_unreadable, **s["values"],
          "model": vdet.MODELS[ARCH]["label"], "min_size": MIN_SIZE, "score_threshold": SCORE}

# %% Artifacts: the boxes table (one row per object) and one row per image
out = csml.out_dir("target/academy-parity/run-8142/detect.objects/fast_defaults_small/out-python")
vbox.write(table, os.path.join(out, "boxes.parquet"))
per = pd.DataFrame([{"row": r["row"] + 1, "media_id": r["media_id"], "file": r["file"], "width": r["width"],
                     "height": r["height"], "objects": r["objects"]} for r in run["images"]],
                   columns=["row", "media_id", "file", "width", "height", "objects"])
per.to_parquet(os.path.join(out, "images.parquet"), index=False)

# %% Result
ov = vdet.overlay_columns(table, run["images"])
charts = [cs.chart("overlay", "image-overlay", "Detected objects", {
    "image": cs.col("Image", ov["image"], "categorical"),
    "media_id": cs.col("Media id", ov["media_id"], "categorical"),
    "x0": cs.col("x0", ov["x0"], "numeric"), "y0": cs.col("y0", ov["y0"], "numeric"),
    "x1": cs.col("x1", ov["x1"], "numeric"), "y1": cs.col("y1", ov["y1"], "numeric"),
    "label": cs.col("Class", ov["label"], "categorical"),
    "score": cs.col("Score", ov["score"], "numeric"),
    "width": cs.col("Width (px)", ov["width"], "numeric"), "height": cs.col("Height (px)", ov["height"], "numeric"),
}, controls={"threshold": SCORE})]
if len(table):
    charts.append(cs.chart("classes", "bar", "Objects by class", {
        "x": cs.col("Class", [str(v) for v in table["label"].tolist()], "categorical", s["order"])}))
assumptions = [
    {"key": "coco_classes", "label": "COCO's 80 classes", "status": "info",
     "detail": "Only COCO's everyday classes (people, vehicles, animals, household objects) can be found; anything else is missed or given the nearest class."},
    {"key": "threshold", "label": "Score threshold", "status": "info",
     "detail": f"Objects scored below {SCORE:g} are dropped. Lower it to find more objects (and more false ones)."},
    {"key": "domain", "label": "Photos like COCO's", "status": "info",
     "detail": "The model learned from everyday photos; drawings, microscopy, aerial or medical images need a model trained on them."},
    {"key": "people", "label": "People in images", "status": "warn" if values.get("n[person]", 0) else "pass",
     "detail": f"{values.get('images[person]', 0)} images show people. Treat them as personal data; results stay on this computer." if values.get("n[person]", 0) else "No person was detected."},
] + cs_profile.warning_rows()
image_cols = [{"key": "row", "label": "Row", "type": "integer"}, {"key": "file", "label": "File"},
              {"key": "objects", "label": "Objects", "type": "integer"}, {"key": "classes", "label": "Classes"}]
class_cols = [{"key": "class", "label": "Class"}, {"key": "objects", "label": "Objects", "type": "integer"},
              {"key": "images", "label": "Images", "type": "integer"}, {"key": "mean_score", "label": "Mean score", "type": "number"},
              {"key": "max_score", "label": "Highest score", "type": "number"}]
cs.publish({
    "title": "Object detection (Faster R-CNN, COCO)",
    "engine": cs.engine_info("torch", "torchvision", "numpy", "pandas"),
    "n": values["n_images"],
    "summary": f"{values['n_objects']} objects in {values['n_images_with_objects']} of {values['n_images']} images"
               + (f"; most common: {s['order'][0]} ({values['n[' + s['order'][0] + ']']})." if s["order"] else "."),
    "statistics": [
        {"key": "n_objects", "label": "Objects", "value": values["n_objects"], "format": "integer"},
        {"key": "n_images", "label": "Images", "value": values["n_images"], "format": "integer"},
        {"key": "n_classes", "label": "Classes found", "value": values["n_classes"], "format": "integer"},
        {"key": "objects_per_image", "label": "Objects per image", "value": values["objects_per_image"]},
    ],
    "tables": [
        {"key": "classes", "title": "Objects by class", "columns": class_cols, "rows": s["classes"]},
        {"key": "images", "title": "Objects per image", "columns": image_cols, "rows": s["images"][:200]},
    ],
    "assumptions": assumptions,
    "charts": charts,
    "values": values,
    "warnings": warnings,
    "artifacts": [{"key": "boxes", "path": os.path.join(out, "boxes.parquet"), "format": "parquet"},
                  {"key": "images", "path": os.path.join(out, "images.parquet"), "format": "parquet"}],
})
08

Check: boxes and duplicates

Checkpoint

Check yourself

Box A runs from (0, 0) to (4, 2) and box B from (2, 0) to (6, 2). What is their IoU?

Show the answer

Answer: 0.3333

They share a 2 × 2 square (area 4) and cover 8 + 8 − 4 = 12, so IoU = 4/12 = 0.333.

Check yourself

R-CNN's proposal algorithm never draws a box around a small sign in the corner. What can the per-class SVMs do about it?

Show the answer

Answer: a

Proposal recall caps detection recall. That is why later detectors learned their proposals or dropped them.

Check yourself

Why was the original R-CNN slow at test time?

Show the answer

Answer: b

The features of overlapping proposals were recomputed again and again. Fast R-CNN computed them once per image.

Check yourself

A YOLO box has objectness 0.9 and probability 0.8 for the class "dog". What is its dog score?

Show the answer

Answer: 0.72

The class score is objectness × class probability: 0.9 × 0.8 = 0.72.

Check yourself

What mainly separates YOLO from R-CNN?

Show the answer

Answer: a

One pass over a grid is what makes it fast. It still needs NMS to remove duplicate boxes.

Check yourself

Put the steps of non-maximum suppression in order.

  1. 1Keep the highest-scoring box
  2. 2Delete the boxes that overlap it by more than the threshold
  3. 3Repeat with the boxes that remain
  4. 4Sort the boxes of one class by score

Show the answer

The order:

  1. Sort the boxes of one class by score
  2. Keep the highest-scoring box
  3. Delete the boxes that overlap it by more than the threshold
  4. Repeat with the boxes that remain

The loop ends when no boxes remain; the kept boxes are the detections.

Check yourself

In a crowd photo, two people's boxes overlap with IoU 0.6, and NMS uses a threshold of 0.5. What happens?

Show the answer

Answer: a

NMS can't tell a duplicate from a neighbor. In crowded scenes, tune the threshold on validation images like yours.

09

Recap

Recap
  • Know which box layout a file uses; convert explicitly and draw a few boxes to check.
  • IoU = shared area / covered area; it falls fast as boxes slide apart.
  • R-CNN classified proposals one CNN pass at a time; missed proposals are missed objects.
  • YOLO predicts every grid cell's boxes in one pass; NMS then removes duplicates, at a threshold that matters.

Concepts in this lesson