FasterRCNNConfig
ModelConfigFasterRCNNConfig(num_classes: int = 91, in_channels: int = 3, backbone_layers: tuple[int, int, int, int] = (3, 4, 6, 3), backbone_bn_eps: float = 0.0, fpn_out_channels: int = 256, rpn_anchor_sizes: tuple[int, ...] = (32, 64, 128, 256, 512), rpn_anchor_ratios: tuple[float, ...] = (0.5, 1.0, 2.0), rpn_pre_nms_top_n: int = 1000, rpn_post_nms_top_n: int = 1000, rpn_nms_thresh: float = 0.7, rpn_min_size: float = 0.001, rpn_score_thresh: float = 0.0, rpn_fg_iou_thresh: float = 0.7, rpn_bg_iou_thresh: float = 0.3, rpn_batch_size_per_image: int = 256, rpn_positive_fraction: float = 0.5, rpn_ignore_cross_boundary: bool = False, roi_size: int = 7, roi_sampling_ratio: int = 2, roi_representation_size: int = 1024, roi_fg_iou_thresh: float = 0.5, roi_bg_iou_thresh: float = 0.5, roi_batch_size_per_image: int = 512, roi_positive_fraction: float = 0.25, bbox_reg_weights: tuple[float, float, float, float] = (10.0, 10.0, 5.0, 5.0), canonical_scale: int = 224, canonical_level: int = 4, score_thresh: float = 0.05, nms_thresh: float = 0.5, max_detections: int = 100)Configuration for Faster R-CNN.
Faster R-CNN (Ren et al., NeurIPS 2015) replaces external proposal methods (selective search) with a learned Region Proposal Network (RPN) that shares convolutional features with the detection head. This makes the entire pipeline end-to-end trainable and near real-time.
Architecture overview (ResNet-50-FPN variant): Image → ResNet-50 backbone (frozen BN, C2-C5) → FPN (P2-P5 + pool) FPN levels → RPN head → region proposals (per-level top-k + NMS) FPN levels + proposals → MultiScale RoI Align (7×7) → TwoMLPHead (fc6/fc7) → FastRCNNPredictor (cls + per-class bbox)
Args: num_classes: Object classes incl. background (91 for COCO). in_channels: Input image channels.
-- Backbone -- backbone_layers: ResNet bottleneck counts (default 3,4,6,3 = R50). backbone_bn_eps: FrozenBatchNorm2d epsilon (reference uses 0). fpn_out_channels: Unified FPN channel count (256).
-- RPN hyper-parameters -- rpn_anchor_sizes: One anchor scale per FPN level (5 levels). rpn_anchor_ratios: Aspect ratios for anchor generation. rpn_pre_nms_top_n: Proposals kept per level before NMS (test 1000). rpn_post_nms_top_n: Proposals kept per image after NMS (test 1000). rpn_nms_thresh: RPN NMS IoU threshold. rpn_min_size: Minimum proposal side length (pixels). rpn_score_thresh: Minimum RPN objectness score. rpn_fg_iou_thresh: Anchor→GT IoU for foreground assignment. Inert — see the note on the field. rpn_bg_iou_thresh: Anchor→GT IoU upper bound for background. Inert — see the note on the field.
-- RoI head hyper-parameters -- roi_size: RoI Align output spatial size (7 → 7×7). roi_sampling_ratio: RoI Align sub-bin sampling ratio (2). roi_representation_size: TwoMLPHead hidden width (1024). roi_fg_iou_thresh: Proposal→GT IoU for fg assignment. Inert — see the note on the field. roi_bg_iou_thresh: Proposal→GT IoU upper bound for bg. Inert — see the note on the field. bbox_reg_weights: Per-component bbox delta scale (10,10,5,5). canonical_scale: FPN level-assignment canonical scale (224). canonical_level: FPN level-assignment canonical level (4).
-- Inference hyper-parameters -- score_thresh: Minimum final class score (0.05). nms_thresh: Per-class NMS IoU threshold (0.5). max_detections: Maximum detections returned per image (100).
Note:
Training. Pass
targetstoforwardto get the four-term loss — RPN objectness and box regression, plus the box head's classification and regression. Label assignment follows §3.1.2 (highest-IoU anchor per ground truth, or IoU over 0.7, as positive; under 0.3 as negative; the band between ignored) and the samplers follow §3.1.3. The one clause not on by default is cross-boundary anchor removal — seerpn_ignore_cross_boundary.
Examples
>>> from lucid.models.vision.faster_rcnn import FasterRCNNConfig
>>> cfg = FasterRCNNConfig()
>>> cfg.num_classes
91
>>> cfg.model_type
'faster_rcnn'Used by 3
Constructors
1__init__
→None__init__(num_classes: int = 91, in_channels: int = 3, backbone_layers: tuple[int, int, int, int] = (3, 4, 6, 3), backbone_bn_eps: float = 0.0, fpn_out_channels: int = 256, rpn_anchor_sizes: tuple[int, ...] = (32, 64, 128, 256, 512), rpn_anchor_ratios: tuple[float, ...] = (0.5, 1.0, 2.0), rpn_pre_nms_top_n: int = 1000, rpn_post_nms_top_n: int = 1000, rpn_nms_thresh: float = 0.7, rpn_min_size: float = 0.001, rpn_score_thresh: float = 0.0, rpn_fg_iou_thresh: float = 0.7, rpn_bg_iou_thresh: float = 0.3, rpn_batch_size_per_image: int = 256, rpn_positive_fraction: float = 0.5, rpn_ignore_cross_boundary: bool = False, roi_size: int = 7, roi_sampling_ratio: int = 2, roi_representation_size: int = 1024, roi_fg_iou_thresh: float = 0.5, roi_bg_iou_thresh: float = 0.5, roi_batch_size_per_image: int = 512, roi_positive_fraction: float = 0.25, bbox_reg_weights: tuple[float, float, float, float] = (10.0, 10.0, 5.0, 5.0), canonical_scale: int = 224, canonical_level: int = 4, score_thresh: float = 0.05, nms_thresh: float = 0.5, max_detections: int = 100)