MaskRCNNConfig
ModelConfigMaskRCNNConfig(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, roi_det_size: int = 7, roi_sampling_ratio: int = 2, roi_representation: 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, roi_mask_size: int = 14, mask_hidden_channels: int = 256, mask_num_convs: int = 4, mask_predictor_hidden: int = 256, score_thresh: float = 0.05, nms_thresh: float = 0.5, max_detections: int = 100, mask_thresh: float = 0.5)Configuration for Mask R-CNN.
Mask R-CNN (He et al., ICCV 2017) extends Faster R-CNN with:
- Feature Pyramid Network (FPN) backbone replacing single-scale VGG16.
- RoI Align replacing RoI Pool (eliminating quantisation misalignment).
- A parallel mask branch predicting K binary segmentation masks per RoI.
Architecture overview: Image → ResNet-50 (C2–C5, strides 4/8/16/32) ↓ FPN (lateral convs + top-down merging) → [P2, P3, P4, P5, P6] (256ch) P2–P6 → RPN → proposals P2–P5 + proposals → FPN-level assignment → RoI Align (7×7) → 2-FC head → RoI Align (14×14) → Mask head
Args: num_classes: Foreground categories (background = class 0). in_channels: Input image channels.
-- Backbone/FPN -- backbone_layers: ResNet layer counts (default ResNet-50 = 3,4,6,3). backbone_bn_eps: FrozenBatchNorm2d epsilon (reference uses 0). fpn_out_channels: Channel width of every FPN output level.
-- RPN hyper-parameters -- rpn_anchor_sizes: One anchor size per FPN level (P2–P6). rpn_anchor_ratios: Aspect ratios shared across all levels. rpn_pre_nms_top_n: Proposals kept per level before NMS. rpn_post_nms_top_n: Proposals kept per image after NMS. rpn_nms_thresh: RPN NMS IoU threshold. rpn_min_size: Minimum proposal side length (feature pixels). rpn_score_thresh: Minimum objectness score (post-sigmoid). rpn_fg_iou_thresh: Anchor→GT IoU for foreground label. rpn_bg_iou_thresh: Anchor→GT IoU upper bound for background.
-- Detection head -- roi_det_size: RoI Align output for detection (7 → 7×7). roi_sampling_ratio: RoI Align sub-bin sampling ratio (2). roi_representation: Hidden size of the 2-FC detection head. roi_fg_iou_thresh: Proposal→GT IoU for fg assignment. roi_bg_iou_thresh: Proposal→GT IoU upper bound for bg. bbox_reg_weights: Per-component bbox delta scale. canonical_scale: FPN level-assignment canonical scale (224). canonical_level: FPN level-assignment canonical level (4).
-- Mask head -- roi_mask_size: RoI Align output for the mask branch (14 → 14×14). mask_hidden_channels: Channel width inside the mask FCN. mask_num_convs: Number of 3×3 convs in the mask head (4). mask_predictor_hidden: Channel width of the deconv upsampler (256).
-- Inference -- score_thresh: Minimum final class score. nms_thresh: Per-class NMS IoU threshold. max_detections: Maximum detections returned per image. mask_thresh: Binarisation threshold applied to mask sigmoid output.
Note:
Training. Pass
targetstoforwardfor §3's multi-task objectiveL = L_cls + L_box + L_maskon top of the inherited RPN terms.L_maskis the per-pixel sigmoid BCE on the ground-truth class's mask channel only, with targets from RoI-aligning the ground-truth masks onto the sampled proposals."masks"may be omitted from a target to train the detector alone.
Examples
>>> from lucid.models.vision.mask_rcnn import MaskRCNNConfig
>>> cfg = MaskRCNNConfig()
>>> cfg.num_classes
91
>>> cfg.model_type
'mask_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, roi_det_size: int = 7, roi_sampling_ratio: int = 2, roi_representation: 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, roi_mask_size: int = 14, mask_hidden_channels: int = 256, mask_num_convs: int = 4, mask_predictor_hidden: int = 256, score_thresh: float = 0.05, nms_thresh: float = 0.5, max_detections: int = 100, mask_thresh: float = 0.5)