YOLOV4ForObjectDetection
PretrainedModelYOLOV4ForObjectDetection(config: YOLOV4Config)YOLOv4 multi-scale object detector (Bochkovskiy et al., 2020).
A heavily engineered iteration over YOLOv3 that combines several independently-published improvements ("bag of freebies" and "bag of specials" in the paper's terminology) into a single high-throughput detector. The core architectural changes are:
- CSPDarknet-53 backbone — replaces residual blocks with Cross-Stage-Partial blocks that split and re-merge the feature stream, reducing FLOPs without hurting accuracy.
- SPP (Spatial Pyramid Pooling) module on the final backbone stage — fuses three max-pooled receptive fields plus the identity, widening the effective receptive field.
- PANet (Path Aggregation Network) neck — adds a bottom-up path on top of the FPN top-down path, giving each prediction level access to both fine and coarse features.
Heads remain YOLOv3-style (three scales, 3 anchors / scale), but training switches the box-regression loss to CIoU which couples centre distance, IoU, and aspect-ratio consistency in a single differentiable objective. COCO test-dev AP of 43.5% at 65 fps on a Tesla V100 (paper Table 8).
Parameters
configYOLOV4Configyolo_v4 for the standard
full-size model.Attributes
configYOLOV4Configbackbone_CSPDarknet53neck_PANetNeckp3_head, p4_head, p5_headnn.SequentialNotes
See Bochkovskiy et al., "YOLOv4: Optimal Speed and Accuracy of Object Detection", arXiv 2020 (arXiv:2004.10934). Complete-IoU (CIoU) loss is defined as
where is the Euclidean distance between box centres, is the diagonal of the smallest enclosing box, and is a balancing trade-off term. CIoU converges faster than IoU / GIoU and is the standard regression objective from YOLOv4 onwards.
Examples
>>> import lucid
>>> from lucid.models.vision.yolo._v4 import yolo_v4
>>> model = yolo_v4()
>>> x = lucid.randn(1, 3, 608, 608)
>>> out = model(x)
>>> out.logits.shape[0]
1Used by 1
Constructors
1Instance methods
2forward(x: Tensor, targets: list[dict[str, Tensor]] | None = None)Run YOLOv4.
Parameters
Returns
ObjectDetectionOutputObjectDetectionOutput:
logits : (B, total_anchors, C) raw class logits.
pred_boxes: (B, total_anchors, 4) xyxy decoded boxes.
loss : loss scalar when targets provided.
postprocess(output: ObjectDetectionOutput, image_sizes: list[tuple[int, int]])Filter by score, clip boxes, apply per-class NMS.
Parameters
outputObjectDetectionOutputimage_sizeslist[tuple[int, int]]Returns
list[dict[str, Tensor]]Per-image list of dicts with "boxes", "scores", "labels".