Skip to content
class

EfficientDetForObjectDetection

extendsObjectDetectionModel
EfficientDetForObjectDetection(config: EfficientDetConfig)

EfficientDet object detector (Tan et al., CVPR 2020).

A family of compound-scaled single-stage detectors combining an EfficientNet backbone, a BiFPN (bidirectional weighted feature pyramid) neck, and shared classification + box regression heads applied to 5 feature levels (P3-P7). The family is parameterised by a compound coefficient φ∈{0,1,…,7}\varphi \in \{0, 1, \dots, 7\} that simultaneously scales backbone depth / width, BiFPN width and repeat count, head depth, and input resolution — yielding D0-D7 variants that span ~4M to ~52M parameters and trade speed for accuracy along a Pareto-optimal curve.

Parameters

Frozen architecture spec. Use the per-φ\varphi factories (efficientdet_d0 through efficientdet_d7) for the paper-cited compound-scaled variants.

Attributes

Stored copy of the config that built this model.
backbone_EfficientNetBackbone
EfficientNet trunk producing C3 / C4 / C5 features at strides 8 / 16 / 32.
p3_proj, p4_proj, p5_projnn.Sequential
1x1 conv + BatchNorm channel projections from backbone widths to config.fpn_channels.
p6_pool, p7_poolnn.MaxPool2d
2x downsamples producing P6 and P7 at strides 64 and 128.
config.fpn_repeats _BiFPNLayer blocks performing weighted bidirectional top-down + bottom-up feature fusion.
cls_head, box_head_PredictionHead
Shared per-level prediction heads with config.head_repeats 3x3 separable convolutions; outputs K * num_anchors and 4 * num_anchors channels respectively.
_anchor_genAnchorGenerator
Anchor generator covering 5 levels with ∣scales∣×∣ratios∣|\mathrm{scales}| \times |\mathrm{ratios}| anchors per cell.

Notes

See Tan et al., "EfficientDet: Scalable and Efficient Object Detection", CVPR 2020 (arXiv:1911.09070). The BiFPN's defining feature is weighted feature fusion at each node:

O=∑iwiϵ+∑jwj⋅Ii,O = \sum_{i} \frac{w_i}{\epsilon + \sum_j w_j} \cdot I_i,

with non-negative weights wiw_i learned end-to-end (the paper calls this "fast normalized fusion"). Compound scaling follows

WBiFPN=64⋅1.35φ,DBiFPN=3+φ,Dhead=3+⌊φ/3⌋,Rinput=512+128φ,\begin{aligned} W_\mathrm{BiFPN} &= 64 \cdot 1.35^\varphi, & D_\mathrm{BiFPN} &= 3 + \varphi, \\ D_\mathrm{head} &= 3 + \lfloor \varphi / 3 \rfloor, & R_\mathrm{input} &= 512 + 128\varphi, \end{aligned}

so D0 (φ=0\varphi = 0) trains on 512x512 inputs while D7 (φ=7\varphi = 7) uses 1536x1536. Training uses focal loss FL(pt)=−αt(1−pt)γlog⁡pt\mathrm{FL}(p_t) = -\alpha_t (1 - p_t)^\gamma \log p_t on the K-channel class output plus smooth-L1L_1 on box deltas.

Examples

>>> import lucid
>>> from lucid.models.vision.efficientdet import efficientdet_d0
>>> model = efficientdet_d0()
>>> x = lucid.randn(1, 3, 512, 512)
>>> out = model(x)
>>> out.logits.shape[-1], out.pred_boxes.shape[-1]
(80, 4)

Used by 2

Constructors

1
dunder

__init__

→None
__init__(config: EfficientDetConfig)

Instance methods

2
forward(x: Tensor, targets: list[dict[str, Tensor]] | None = None)

Run EfficientDet.

Parameters

(B, C, H, W) image batch.
targetslist[dict[str, Tensor]] | None= None
Optional training targets.

Returns

ObjectDetectionOutput

ObjectDetectionOutput: logits : (B, A, K) per-class sigmoid logits (A = total anchors). pred_boxes: (B, A, 4) decoded xyxy boxes. loss : focal + smooth-L1 when targets provided.

fn

postprocess

→list[dict[str, Tensor]]
postprocess(output: ObjectDetectionOutput)

Per-class NMS on raw sigmoid predictions.

Returns list of per-image result dicts with "boxes", "scores", "labels".