all lessons / computer_vision / 09 · detection lesson 9 / 19

Object detection

目标检测

Lesson 08 named the whole image and asked whether to trust the number. But a single label cannot say where an object is or how many there are. Detection answers both: a class and a box per object. That one step forces three new first-principles tools — a way to measure box overlap (IoU), a way to deduplicate overlapping guesses (NMS), and a way to score a ranked list of boxes (mAP).

第 08 课为整幅图像命名,并追问是否该相信那个数字。但单个标签说不出物体在哪里,也说不出有几个。检测同时回答这两点:每个物体一个类别加一个框。这一步硬是逼出了三个新的第一性原理工具——一种度量框重叠程度的方法(IoU)、一种对重叠猜测去重的方法(NMS),以及一种为一串排好序的框打分的方法(mAP)。

The plan计划
Five moves. (1) Define the box, compute IoU by hand. (2) Solve assignment: anchors vs anchor-free, and why boxes are regressed as log-scale offsets. (3) Handle the foreground/background imbalance with focal loss, and lean on lesson 06's FPN for scale. (4) Collapse duplicate boxes with NMS as a mechanical algorithm — and meet DETR, which removes it via set prediction. (5) Score detectors with mAP, distinguishing VOC AP@0.5 from COCO AP@[.5:.95]. Then the modern landscape: open-vocabulary detection, RT-DETR, the YOLO line. A live IoU + NMS widget runs throughout. 五步走。(1) 定义边界框,手算 IoU。(2) 解决分配问题:锚框与无锚框,以及为什么框要以对数尺度偏移量来回归。(3) 用focal loss处理前景/背景不平衡,并借助第 06 课的 FPN 应对尺度。(4) 用NMS这一机械算法压掉重复的框——并认识DETR,它通过集合预测干脆去掉了 NMS。(5) 用 mAP 给检测器打分,区分 VOC 的 AP@0.5 与 COCO 的 AP@[.5:.95]。然后是现代格局:开放词表检测、RT-DETR、YOLO 系列。一个实时的 IoU + NMS 小部件贯穿始终。

1 · Boxes and IoU — measure overlap, by hand

1 · 边界框与 IoU——亲手度量重叠

A detection is a class score plus a box, usually (x1, y1, x2, y2) for the top-left and bottom-right corners. To say whether a predicted box matches a ground-truth box we need a single number for "how much do these overlap?" that is scale-free and symmetric. The answer is Intersection over Union (IoU) — the area they share divided by the area they jointly cover:

一次检测就是一个类别分数加一个框,通常用 (x1, y1, x2, y2) 表示左上角和右下角。要判断一个预测框是否与真值框匹配,我们需要一个既无关尺度又对称的单一数字来回答"它们重叠多少?"。答案就是交并比(Intersection over Union,IoU)——它们共享的面积除以它们共同覆盖的面积:

IoU = area(pred ∩ gt) / area(pred ∪ gt),    area(∪) = area(pred) + area(gt) − area(∩).
Worked example — compute it算例——动手算一遍
Predicted box A = (0, 0, 4, 4) → area 16. Ground truth B = (2, 1, 6, 5) → area 16.
Intersection corners: x: max(0,2)=2 … min(4,6)=4 (width 2); y: max(0,1)=1 … min(4,5)=4 (height 3). Intersection area = 2×3 = 6.
Union = 16 + 16 − 6 = 26.   IoU = 6 / 26 ≈ 0.231.
Below the usual 0.5 match threshold — these two boxes would not count as the same object.
预测框 A = (0, 0, 4, 4) → 面积 16。真值框 B = (2, 1, 6, 5) → 面积 16。
交集的角点:x: max(0,2)=2 … min(4,6)=4(宽 2);y: max(0,1)=1 … min(4,5)=4(高 3)。交集面积 = 2×3 = 6
并集 = 16 + 16 − 6 = 26。  IoU = 6 / 26 ≈ 0.231
低于通常的 0.5 匹配阈值——这两个框不会被算作同一个物体。

IoU shows up twice: at training time to decide which prediction is responsible for which target, and at evaluation time to decide whether a detection counts as correct. It is the spine of the whole lesson.

IoU 出现两次:在训练时用来决定哪个预测负责哪个目标,在评估时用来判断一次检测是否算正确。它是贯穿整节课的主心骨。

Detectors come in two shapes: two-stage (first propose a few hundred candidate regions, then classify and refine each) and one-stage (predict class and box densely at every location in one pass). Keep both in mind — the assignment and imbalance choices below split along this line.

检测器分为两种形态:两阶段(先提出几百个候选区域,再对每个区域分类并精修)与单阶段(一次前向就在每个位置稠密地预测类别和框)。把这两者都记在心里——下面关于分配和不平衡的取舍正是沿着这条线分开的。

2 · Assignment and box parameterization

2 · 分配与边界框参数化

The first hard problem is assignment: which of the model's many spatial predictions is responsible for a given ground-truth object? Two philosophies.

第一个难题是分配:在模型众多的空间预测中,究竟哪一个负责某个给定的真值物体?有两种理念。

Anchor-based detectors tile the image with reference boxes ("anchors") of several scales and aspect ratios at every feature location, then label each anchor positive / negative / ignore by its IoU with ground truth (e.g. ≥0.7 positive, ≤0.3 negative). The network learns to refine the nearest anchor. Anchor-free detectors drop the priors and predict directly from points or centers (FCOS, CenterNet), assigning by which locations fall inside an object with center sampling and per-level scale ranges. Anchor-free is the modern default — fewer hyperparameters, no anchor-tuning ritual.

基于锚框的检测器在每个特征位置上铺满若干尺度和长宽比的参考框("锚框"),再按每个锚框与真值的 IoU 把它标为正 / 负 / 忽略(例如 ≥0.7 为正,≤0.3 为负)。网络学习去精修最接近的锚框。无锚框检测器丢掉这些先验,直接从点或中心进行预测(FCOS、CenterNet),通过哪些位置落在物体内部,配合中心采样和逐层的尺度范围来做分配。无锚框是如今的默认选择——超参数更少,也不用做调锚框那套仪式。

Why log-scale offsets? A head (the small task-specific output sub-network on top of the backbone) does not regress raw pixel coordinates; it predicts a shift from its anchor/point and a log ratio of size:

为什么用对数尺度偏移量?检测头(骨干网络之上那个小型、任务专用的输出子网络)并不回归原始的像素坐标;它预测相对其锚框/点的平移量以及尺寸的对数比值

tx = (x − xa)/wa,   ty = (y − ya)/ha,   tw = log(w/wa),   th = log(h/ha).

Two reasons. The center shift is normalized by anchor size so a 5-pixel error means the same thing for a tiny box and a huge one. And size uses log because scale is multiplicative: predicting log(w/wa) makes doubling and halving a box symmetric (±log 2) and keeps width strictly positive after w = wa·etw. The target distribution becomes roughly zero-mean and scale-invariant — far easier to regress than raw coordinates spanning four orders of magnitude.

两个原因。中心平移量用锚框尺寸做了归一化,所以 5 个像素的误差对一个极小的框和一个极大的框意味着同一件事。尺寸则使用 log,因为尺度是乘性的:预测 log(w/wa) 使得把框放大一倍和缩小一半是对称的(±log 2),并且经过 w = wa·etw 之后宽度严格为正。这样目标分布就变得大致零均值且尺度不变——远比回归跨越四个数量级的原始坐标容易。

3 · Imbalance, focal loss, and FPN

3 · 不平衡、focal loss 与 FPN

A dense one-stage detector evaluates tens of thousands of locations per image, of which a handful contain objects. This foreground/background imbalance (often 1000:1) means easy background examples, each contributing a small loss, collectively swamp the gradient and the model learns to predict "background" everywhere. Two-stage detectors dodge this with a proposal stage that pre-filters; one-stage detectors need a direct fix.

一个稠密的单阶段检测器每张图要评估上万个位置,其中只有寥寥几个含有物体。这种前景/背景不平衡(常常是 1000:1)意味着大量简单的背景样本,虽然每个贡献的损失都很小,却集体淹没了梯度,于是模型学会了处处都预测"背景"。两阶段检测器靠一个预先筛选的候选阶段来规避这个问题;单阶段检测器则需要一个直接的修复办法。

Focal loss is that fix. Take standard cross-entropy −log pt (where pt is the probability of the true class) and multiply it by a modulating factor that down-weights well-classified examples:

Focal loss 就是这个修复办法。取标准交叉熵 −log pt(其中 pt 是真实类别的概率),再乘上一个降低易分类样本权重的调制因子:

FL(pt) = −(1 − pt)γ · log pt,    γ ≈ 2.

Mechanism: when an example is easy and confident (pt = 0.99), (1−0.99)2 = 0.0001 — its loss is scaled to almost nothing, so the 10,000 easy backgrounds stop dominating. A hard example (pt = 0.3) keeps (0.7)2 = 0.49 of its loss. So the easy example's loss is down-weighted by roughly 0.49/0.0001 ≈ 5000× relative to the hard one — versus equal weighting under plain cross-entropy. The gradient refocuses on the examples the model is actually getting wrong. It is the class-imbalance principle from lesson 07, sharpened into a loss. (Localization itself uses smooth-L1 on the offsets, or IoU-family losses — GIoU/DIoU/CIoU — that optimize overlap directly. Plain IoU loss fails when the two boxes do not overlap at all: IoU = 0 everywhere in the neighborhood, so the gradient is zero and the box gets no signal pointing it toward the target — it cannot tell "just missed" from "miles away." GIoU adds a penalty based on the smallest box enclosing both, which stays informative even under zero overlap and pulls the prediction toward the target.)

机制:当一个样本既简单又自信时(pt = 0.99),(1−0.99)2 = 0.0001——它的损失被缩放到几乎为零,于是那 10,000 个简单背景不再占主导。一个难样本(pt = 0.3)则保留了 (0.7)2 = 0.49 的损失。所以相对于难样本,简单样本的损失大约被降权了 0.49/0.0001 ≈ 5000×——而在普通交叉熵下二者是等权的。梯度于是重新聚焦到模型实际做错的样本上。这就是第 07 课的类别不平衡原理,被磨砺成了一个损失函数。(定位本身对偏移量用 smooth-L1,或用直接优化重叠的 IoU 系列损失——GIoU/DIoU/CIoU。当两个框完全不重叠时,朴素的 IoU 损失会失效:邻域内处处 IoU = 0,于是梯度为零,框得不到任何指向目标的信号——它分不清"差一点没中"和"差了十万八千里"。GIoU 加了一项基于包围两者的最小框的惩罚,即使在零重叠下也仍然有信息,能把预测拉向目标。)

Scale via FPN. Lesson 06 built the feature pyramid network: combine deep, semantic, low-resolution features with shallow, high-resolution ones via top-down + lateral connections. Detection uses it because objects appear at wildly different sizes — a detector predicts small objects from high-resolution early levels and large objects from coarse deep levels, each level responsible for its own scale band. Without FPN, small-object recall collapses.

用 FPN 处理尺度。第 06 课构建了特征金字塔网络:通过自顶向下 + 横向连接,把深层、语义强、低分辨率的特征与浅层、高分辨率的特征结合起来。检测之所以用它,是因为物体的尺寸差异极大——检测器从高分辨率的早期层预测小物体、从粗糙的深层预测大物体,每一层负责自己的那一段尺度。没有 FPN,小物体的召回率就会崩塌。

4 · NMS — collapse the duplicates (and DETR's escape)

4 · NMS——压掉重复的框(以及 DETR 的另辟蹊径)

Dense detectors fire many overlapping boxes on the same object — neighboring anchors all "see" the cat. Non-maximum suppression (NMS) is the mechanical post-process that keeps one per object. It is not optional cleanup; it is part of the model's output contract, and its threshold trades precision for recall.

稠密检测器会在同一个物体上打出许多重叠的框——相邻的锚框都"看见"了那只猫。非极大值抑制(Non-maximum suppression,NMS)就是那个机械式的后处理,为每个物体只保留一个框。它不是可有可无的收尾工作;它是模型输出契约的一部分,而它的阈值是在精确率和召回率之间做权衡。

NMS, as an algorithm把 NMS 当作一个算法
Per class:
1. Sort all boxes by confidence score, descending.
2. Pop the highest-scoring box; keep it.
3. Compute IoU of that kept box against every remaining box.
4. Suppress (discard) any remaining box with IoU > threshold τ — they are duplicates of what we just kept.
5. Repeat from step 2 with the boxes that survived, until none remain.
对每个类别:
1. 把所有框按置信度分数降序排序。
2. 弹出分数最高的框;保留它。
3. 计算这个被保留的框与其余每个框的 IoU。
4. 抑制(丢弃)任何 IoU > 阈值 τ 的剩余框——它们是我们刚保留那个框的重复项。
5. 对存活下来的框从第 2 步重复,直到一个不剩。

Set τ too high and duplicates survive (false positives); too low and two genuinely adjacent objects get merged (missed detection) — the classic NMS failure in crowds. Soft-NMS decays neighbor scores instead of hard-deleting them to soften this. The widget below steps through this exact loop.

τ 设得太高,重复框就会存活(误检);设得太低,两个确实相邻的物体就会被合并(漏检)——这正是 NMS 在密集人群里的经典失败。Soft-NMS 不硬删邻居,而是衰减它们的分数,以缓和这一点。下面的小部件会一步步走完这个循环。

DETR removes NMS entirely by reframing detection as set prediction. A transformer decodes a fixed set of N "object queries" into N (class, box) slots, and training uses bipartite matching (the Hungarian algorithm) to find the one-to-one assignment between predictions and ground-truth objects that minimizes total cost. The per-pair matching cost is a weighted sum of a classification term (does this query predict the right class?) and a box term (an L1 distance on coordinates plus a GIoU term on overlap). Because the assignment is strictly one-to-one — each ground-truth object is claimed by exactly one query — a second query that tries to cover the same object is matched to "no object" and penalized, so the model learns not to emit it; that is what removes duplicates without NMS. Because the loss is computed against a one-to-one matching, the model is directly penalized for emitting two boxes on one object — duplicates are trained away rather than filtered away, so no NMS is needed. The cost is slow convergence and a hunger for data and compute.

DETR 通过把检测重新表述为集合预测,彻底去掉了 NMS。一个 Transformer 把固定的一组 N 个"对象查询(object query)"解码成 N 个 (类别, 框) 槽位,训练时用二分图匹配(匈牙利算法)在预测与真值物体之间找到使总代价最小的一对一分配。每一对的匹配代价是一个分类项(这个查询预测的类别对不对?)与一个项(坐标上的 L1 距离加上重叠上的 GIoU 项)的加权和。因为分配严格是一对一的——每个真值物体只被恰好一个查询认领——试图覆盖同一物体的第二个查询会被匹配到"无物体"并被惩罚,于是模型学会了不去输出它;这正是不用 NMS 就能去重的原因。由于损失是针对一对一匹配来计算的,模型会因在一个物体上输出两个框而被直接惩罚——重复项是被训练掉的,而不是被过滤掉的,所以不需要 NMS。代价是收敛慢,以及对数据和算力的贪婪需求。

IoU + NMS — step through keep and suppress
IoU + NMS——一步步走完保留与抑制
Candidate boxes with scores (taller label = higher score) all clustered on two objects. Set the IoU threshold τ, then press Step NMS to run the algorithm one decision at a time: the current highest-scoring survivor is kept (green), boxes overlapping it past τ are suppressed (red, dashed). The KPI shows the IoU of the pair being compared. Lower τ suppresses more aggressively; raise it and duplicates survive.
带分数的候选框(标签越高 = 分数越高)全都聚在两个物体上。设定 IoU 阈值 τ,再按 Step NMS 让算法一次做一个决策:当前分数最高的存活框被保留(绿色),与它重叠超过 τ 的框被抑制(红色、虚线)。KPI 显示正在比较的这一对的 IoU。τ 越低,抑制越激进;调高它,重复框就会存活。
IoU threshold τ
IoU 阈值 τ
0.50
Boxes in
输入框数
Kept
保留数
0
Last pair IoU
最近一对 IoU
Show the core JS (≈20 lines)查看核心代码(约 20 行)
function iou(a, b){
  const ix = Math.max(0, Math.min(a.x2,b.x2) - Math.max(a.x1,b.x1));
  const iy = Math.max(0, Math.min(a.y2,b.y2) - Math.max(a.y1,b.y1));
  const inter = ix*iy;
  const areaA = (a.x2-a.x1)*(a.y2-a.y1), areaB = (b.x2-b.x1)*(b.y2-b.y1);
  return inter / (areaA + areaB - inter);
}
function nms(boxes, tau){
  const order = boxes.slice().sort((p,q)=> q.score - p.score); // sort by score desc
  const keep = [];
  const alive = order.map(()=> true);
  for (let i=0;i<order.length;i++){
    if (!alive[i]) continue;
    keep.push(order[i]);                  // highest surviving score -> keep
    for (let j=i+1;j<order.length;j++){   // suppress its duplicates
      if (alive[j] && iou(order[i], order[j]) > tau) alive[j] = false;
    }
  }
  return keep;
}

5 · mAP — scoring a ranked list of boxes

5 · mAP——为一串排好序的框打分

A detector outputs many boxes with scores; how good is it? Accuracy is meaningless here (there is no fixed denominator of "examples"). Instead we ask, across a confidence ranking: of the boxes we call positive, what fraction are correct (precision), and of the real objects, what fraction did we find (recall)? Sweep the confidence threshold from high to low and you trace a precision-recall curve: at a high threshold you predict only your surest boxes (high precision, low recall); lowering it surfaces more true objects but also more false positives.

检测器输出许多带分数的框;它到底有多好?准确率在这里毫无意义(没有一个固定的"样本"分母)。我们转而沿着一个置信度排名来问:在我们判为正的框里,有多大比例是正确的(精确率),以及在真实物体里,我们找到了多大比例(召回率)?把置信度阈值从高扫到低,你就描出一条精确率-召回率曲线:阈值高时你只预测最有把握的框(高精确率、低召回率);调低它会浮现更多真实物体,但也带来更多误检。

Average Precision (AP) is the area under that precision-recall curve for one class — a single number summarizing the whole precision/recall trade-off. It rewards ranking: putting true detections above false ones. A detection counts as a true positive only if its IoU with an unmatched ground-truth box exceeds a threshold. mAP ("mean AP") averages AP over classes.

平均精度(Average Precision,AP)是某一个类别那条精确率-召回率曲线下的面积——一个概括整个精确率/召回率取舍的单一数字。它奖励排序:把真检测排在假检测之上。一次检测只有当它与某个尚未被匹配的真值框的 IoU 超过阈值时,才算作真阳性。mAP("mean AP",平均 AP)把各类别的 AP 求平均。

Worked toy — compute the AP number. Two ground-truth objects; rank three predictions by confidence — TP, FP, TP. After box 1: precision 1/1 = 1.0, recall 1/2 = 0.5. After box 2 (a false positive): precision drops to 1/2 = 0.5, recall still 0.5. After box 3 (a true positive): precision 2/3 ≈ 0.67, recall 2/2 = 1.0. So the raw curve traces the points (R=0.5, P=1.0), (R=0.5, P=0.5), (R=1.0, P=0.67).

玩具算例——把 AP 这个数算出来。两个真值物体;把三个预测按置信度排序——TP、FP、TP。第 1 个框之后:精确率 1/1 = 1.0,召回率 1/2 = 0.5。第 2 个框(一个误检)之后:精确率降到 1/2 = 0.5,召回率仍是 0.5。第 3 个框(一个真阳性)之后:精确率 2/3 ≈ 0.67,召回率 2/2 = 1.0。于是原始曲线描出这些点 (R=0.5, P=1.0)(R=0.5, P=0.5)(R=1.0, P=0.67)

You do not integrate that zig-zag directly. The AP definition includes an interpolation step: at each recall level, replace the precision with the maximum precision achieved at that recall or any higher recall (pinterp(r) = maxr′ ≥ r p(r′)). This monotone "max precision to the right" envelope is part of what AP means (VOC's all-point / 11-point AP); it discards the dip caused by the false positive. Here the envelope is flat at 1.0 for recall in [0, 0.5] (the only point at recall ≥ that level with the highest precision is the first one, P=1.0) and flat at 0.67 for recall in (0.5, 1.0] (the only point that far right is the last one, P=0.67). Integrating that step function:

你不会直接对那条锯齿线积分。AP 的定义里包含一个插值步骤:在每个召回率水平上,用该召回率或任何更高召回率处所达到的最大精确率去替换该处的精确率(pinterp(r) = maxr′ ≥ r p(r′))。这条单调的"向右取最大精确率"的包络本身就是 AP 含义的一部分(VOC 的全点 / 11 点 AP);它抹掉了误检造成的那个凹陷。这里,对召回率在 [0, 0.5] 内,包络平在 1.0(在召回率 ≥ 该水平的点中精确率最高的只有第一个点,P=1.0),对召回率在 (0.5, 1.0] 内平在 0.67(那么靠右的点只有最后一个,P=0.67)。对这个阶梯函数积分:

AP = ∫01 pinterp(r) dr = (0.5 − 0)·1.0 + (1.0 − 0.5)·0.67 = 0.5 + 0.335 ≈ 0.83.

That is a concrete number you can check: the false positive in the middle cost the detector about 0.17 of a perfect AP of 1.0. AP near 1.0 would mean almost all your top-ranked boxes are correct before any false alarm appears.

这是一个你可以核对的具体数字:中间那个误检让检测器在满分 1.0 的 AP 上损失了约 0.17。AP 接近 1.0 就意味着在任何误报出现之前,你排名最靠前的框几乎全都正确。

Correctness: which mAP?较真:是哪个 mAP?
"mAP" is ambiguous and the IoU threshold is the reason. Pascal VOC reports AP@0.5 — a single IoU threshold of 0.5. COCO reports AP@[.5:.95] — AP computed at ten IoU thresholds from 0.50 to 0.95 in steps of 0.05, then averaged, which rewards tight localization, not just rough overlap. So "AP averaged over IoU thresholds" is the COCO convention, not the definition of AP — VOC's headline number uses one threshold. Always state which. "mAP"是含糊的,原因就在 IoU 阈值上。Pascal VOC 报告的是 AP@0.5——单一的 0.5 IoU 阈值。COCO 报告的是 AP@[.5:.95]——在从 0.50 到 0.95、步长 0.05 的十个 IoU 阈值上计算 AP 再求平均,它奖励贴合的定位,而不只是粗略的重叠。所以"在多个 IoU 阈值上求平均的 AP"是 COCO 的约定,而不是 AP 的定义——VOC 的头条数字用的是单一阈值。永远要说清楚是哪一个。

The ranking emphasis has a practical bite: a model with good boxes can still post low AP if its confidence ordering is bad — true detections ranked below false positives drag the precision down at every recall level. Calibration (lesson 08) is not just cosmetic here; it moves the curve.

这种对排序的强调有其现实的杀伤力:一个框画得不错的模型,若置信度排序很糟,仍然会得到很低的 AP——真检测被排在误检之下,会在每个召回率水平上把精确率往下拽。置信度校准(第 08 课)在这里绝不只是锦上添花;它会移动整条曲线。

6 · The modern landscape (2024–2026)

6 · 现代格局(2024–2026)

Family类别Examples代表Trade-off / why it matters now取舍 / 为何当下重要
Two-stage两阶段Faster R-CNN, Mask R-CNNProposals → refine. Strong accuracy, slower; still a research baseline.先提候选 → 再精修。精度强、速度慢;至今仍是研究基线。
One-stage anchor-free单阶段无锚框FCOS, modern YOLO (v8/v10/11-era), RTMDetDense, fast, NMS-based; anchor-free is today's default for real-time.稠密、快速、基于 NMS;无锚框是如今实时检测的默认选择。
Set prediction集合预测DETR, Deformable-DETR, RT-DETRBipartite matching, no NMS; RT-DETR makes it real-time, challenging YOLO.二分图匹配,无需 NMS;RT-DETR 让它达到实时,正面挑战 YOLO。
Open-vocabulary开放词表GLIP, OWL-ViT, GroundingDINODetect from a text prompt, not a fixed class list — zero-shot to new categories.文本提示检测,而非固定类别表——对新类别零样本。

Open-vocabulary detection is the biggest shift. Classic detectors have a frozen class list baked into the final layer. GLIP, OWL-ViT, and GroundingDINO instead align region features with text embeddings (the CLIP idea, lesson 15), so you detect "a red mug" or any phrase without retraining — grounding language to boxes. RT-DETR brought the DETR set-prediction formulation (no NMS) down to real-time latency, putting it head-to-head with the still-evolving YOLO line, which remains the practical default for edge and real-time deployment. The throughline: assignment, IoU, and the precision/recall scoring you learned here are unchanged — only the architecture around them moves.

开放词表检测是最大的转变。经典检测器在最后一层里烧死了一份固定的类别表。GLIP、OWL-ViT 和 GroundingDINO 转而把区域特征与文本嵌入对齐(CLIP 的思路,第 15 课),于是你无需重新训练就能检测"一个红色马克杯"或任意短语——把语言定位(grounding)到框上。RT-DETR 把 DETR 的集合预测表述(无 NMS)拉到了实时延迟,使它与仍在演进的 YOLO 系列正面交锋,而 YOLO 仍是边缘端和实时部署的实用默认选择。贯穿始终的一条线是:你在这里学到的分配、IoU 以及精确率/召回率打分并没有变——变的只是它们周围的架构。

Small objects小物体
Small-object detection is usually resolution-limited, not architecture-limited. Raise input resolution, lean on the high-resolution FPN levels, tile the image, and slice your mAP by object size (COCO's APsmall/medium/large) before swapping detector families. 小物体检测通常受限于分辨率,而非架构。在更换检测器家族之前,先提高输入分辨率、倚重高分辨率的 FPN 层、把图像切块(tile),并按物体尺寸拆分你的 mAP(COCO 的 APsmall/medium/large)。

Where this points next

这将指向何处

A box is a coarse answer: it says "an object is roughly here" but draws a rectangle around a curved, occluded, irregular thing. Many tasks need the boundary exactly — medical measurement, image editing, autonomous free-space. Lesson 10 pushes localization to its limit with segmentation: a class label at every pixel. That demands new machinery the box head never needed — encoder-decoder architectures, upsampling back to full resolution (transposed conv, bilinear+conv, unpooling), U-Net skip connections, and dense losses like Dice/IoU — plus the promptable frontier (SAM/SAM2) that echoes the open-vocabulary turn we just met. The detector's box head, in fact, becomes Mask R-CNN's first stage there.

框是一个粗糙的答案:它说"一个物体大致在这儿",却给一个弯曲、被遮挡、不规则的东西画了一个矩形。许多任务需要精确的边界——医学测量、图像编辑、自动驾驶的可行驶空间。第 10 课用分割把定位推到极限:给每个像素一个类别标签。这需要框头从来不需要的新机器——编码器-解码器架构、把分辨率上采样回全尺寸(转置卷积、双线性+卷积、反池化)、U-Net 的跳跃连接,以及 Dice/IoU 这类稠密损失——外加可提示(promptable)的前沿(SAM/SAM2),它呼应着我们刚刚遇到的开放词表转向。事实上,检测器的框头在那里会变成 Mask R-CNN 的第一阶段。

Takeaway要点
Detection = class + box per object. IoU = intersection/union scores overlap (worked: A=(0,0,4,4), B=(2,1,6,5) → 6/26 ≈ 0.23) and drives both training assignment and evaluation. Boxes are regressed as anchor-normalized center shifts + log-scale sizes so the target is scale-invariant and positive. The dense foreground/background imbalance is fixed by focal loss −(1−pt)γlog pt, which crushes easy-example loss; scale is handled by the FPN from lesson 06. NMS deduplicates by sort-keep-suppress-repeat at threshold τ; DETR avoids it with bipartite-matched set prediction. Score with mAP, stating whether you mean VOC AP@0.5 or COCO AP@[.5:.95] — both integrate a precision-recall curve, so confidence ranking (and calibration) moves the number. Anchor-free is the default; open-vocabulary detection grounds text to boxes; RT-DETR and the YOLO line define the real-time frontier. 检测 = 每个物体一个类别 + 一个框。IoU = 交集/并集,度量重叠(算例:A=(0,0,4,4)、B=(2,1,6,5) → 6/26 ≈ 0.23),并同时驱动训练时的分配和评估。框以用锚框归一化的中心平移量 + 对数尺度的尺寸来回归,因而目标尺度不变且为正。稠密的前景/背景不平衡由 focal loss −(1−pt)γlog pt 修复,它压碎了易样本的损失;尺度由第 06 课的 FPN 处理。NMS 通过在阈值 τ 下"排序-保留-抑制-重复"来去重;DETR 用二分图匹配的集合预测避开了它。用 mAP 打分,并说明你指的是 VOC 的 AP@0.5 还是 COCO 的 AP@[.5:.95]——两者都对一条精确率-召回率曲线积分,所以置信度排序(以及校准)会移动这个数字。无锚框是默认;开放词表检测把文本定位到框上;RT-DETR 与 YOLO 系列定义了实时的前沿。

Interview prompts

面试题