FasterRCNNForObjectDetection
PretrainedModelFasterRCNNForObjectDetection(config: FasterRCNNConfig)Faster R-CNN with a ResNet-50-FPN backbone (Ren et al., NeurIPS 2015).
The two-stage anchor-based detector in its modern reference
configuration: a ResNet-50 trunk with frozen batch-norm feeds a
Feature Pyramid Network, a Region Proposal Network emits per-image
proposals from five pyramid levels, and a Fast R-CNN-style RoI head
classifies + refines RoI-aligned crops. The submodule layout mirrors
the reference detector so the COCO box AP 37.0 checkpoint loads
strict and reproduces inference.
Parameters
configFasterRCNNConfigfaster_rcnn_resnet50_fpn
factory for the COCO-pretrained configuration (num_classes = 91).Attributes
configFasterRCNNConfigbackbone_BackboneWithFPNbody + fpn producing five feature maps
[P2, P3, P4, P5, pool] at strides 4/8/16/32/64.rpn_RegionProposalNetworkroi_heads_RoIHeadsbox_head (TwoMLPHead) + box_predictor (FastRCNNPredictor).Notes
See Ren et al., "Faster R-CNN: Towards Real-Time Object Detection with
Region Proposal Networks", NeurIPS 2015 (arXiv:1506.01497) and Lin et
al., "Feature Pyramid Networks for Object Detection", CVPR 2017. The
model expects an already resized + normalised image batch; final
detections come from postprocess.
Examples
>>> import lucid
>>> from lucid.models.vision.faster_rcnn import faster_rcnn_resnet50_fpn
>>> model = faster_rcnn_resnet50_fpn()
>>> model.eval()
>>> x = lucid.randn(1, 3, 224, 224)
>>> out = model(x)
>>> out.logits.shape[-1] # num_classes
91
>>> dets = model.postprocess(out, image_sizes=[(224, 224)])
>>> sorted(dets[0].keys())
['boxes', 'labels', 'scores']Used by 3
Constructors
1Instance methods
2forward(x: Tensor, proposals: list[Tensor] | None = None)Run Faster R-CNN on a (pre-processed) image batch.
Parameters
Returns
ObjectDetectionOutputObjectDetectionOutput with raw RoI-head outputs:
logits : (Σ proposals, num_classes) class logits.
pred_boxes : (Σ proposals, num_classes, 4) per-class boxes.
proposals : per-image proposal tensors.
postprocess
→list of dictpostprocess(output: ObjectDetectionOutput, image_sizes: list[tuple[int, int]] | None = None, proposals: list[Tensor] | None = None)Softmax → per-class score filter → per-class NMS → top-k.
Mirrors the reference postprocess_detections: drops the
background class (slot 0), score-thresholds, removes empty boxes,
runs per-class NMS, and keeps the top max_detections scores.
Parameters
outputObjectDetectionOutputforward.image_sizeslist of (H, W)= Noneoutput.proposals.Returns
list of dictOne dict per image with "boxes" (D, 4), "scores"
(D,), "labels" (D,) int64.