YOLOV2ForObjectDetection
PretrainedModelYOLOV2ForObjectDetection(config: YOLOV2Config)YOLOv2 / YOLO9000 object detector (Redmon & Farhadi, CVPR 2017).
The successor to YOLOv1 with several decisive upgrades: a deeper Darknet-19 backbone with batch normalisation, anchor boxes (5 k-means-clustered priors on COCO instead of YOLOv1's direct-regression "anchor-free" approach), and a passthrough layer that injects fine-grained stride-16 features into the stride-32 detection head via space-to-depth reorganisation. Anchors give per-cell predictions an inductive bias on shape that YOLOv1 lacks, and the passthrough recovers spatial detail lost in the final downsample — together they bump VOC 2007 mAP from 63.4% (YOLOv1) to 78.6% (paper Table 4).
The output tensor encodes anchors per cell with deltas plus class scores.
Parameters
configYOLOV2Configyolo_v2 or
yolo_v2_tiny for the standard variants.Attributes
configYOLOV2Configbackbone_Darknet19 or _Darknet19Tinydet1, det2, det3_conv_bn_lreludet3 consumes the concatenation
of the 2048-channel space-to-depth passthrough and the 1024-channel
det2 output.prednn.Conv2dNotes
See Redmon & Farhadi, "YOLO9000: Better, Faster, Stronger", CVPR 2017 (arXiv:1612.08242). Per-anchor box decoding uses the "direct location prediction" parameterisation:
where is the cell top-left in feature coords and is the anchor's prior size. The sigmoid-on- bounds the centre to lie inside the responsible cell — a stability win over YOLOv1's unbounded regression.
Examples
>>> import lucid
>>> from lucid.models.vision.yolo._v2 import yolo_v2
>>> model = yolo_v2()
>>> x = lucid.randn(1, 3, 416, 416)
>>> out = model(x)
>>> out.logits.shape[0]
1Used by 1
Constructors
1Instance methods
2forward(x: Tensor, targets: list[dict[str, Tensor]] | None = None, image_size: tuple[int, int] = (416, 416))Run YOLOv2 forward pass.
Parameters
"boxes": (M_i, 4) xyxy boxes normalised to [0,1].
- "labels": (M_i,) integer class indices.image_sizetuple[int, int]= (416, 416)Returns
ObjectDetectionOutputclass:~lucid.models._output.ObjectDetectionOutput with:
postprocess(output: ObjectDetectionOutput, image_size: tuple[int, int] = (416, 416))Per-class NMS on raw predictions.
Parameters
outputObjectDetectionOutputforward.image_sizetuple[int, int]= (416, 416)Returns
list[dict[str, Tensor]]List of per-image result dicts with "boxes", "scores",