Mask R-CNN R50 segmentation
Fit diagram
Read at 100%
Clear selection
Download SVG
Download PNG
Click a block to read its description, or select it with Tab and Enter.
Mask R-CNN R50 segmentation
800 × 800 RGB canvas; batch 1; eval. COCO: 91 internal slots mapped to 80 classes. R and N are data-dependent counts.
LibreYOLO
Mask R-CNN R50 segmentation
800 × 800 RGB canvas; batch 1; eval. COCO: 91 internal slots mapped to 80 classes. R and N are data-dependent counts.
Input transform
RGB image
Values in [0,1]
Channel normalization
Mean .485/.456/.406; std .229/.224/.225
Bilinear resize
Min edge 800; max edge 1333
Pad right/bottom to multiple of 32
Canvas unchanged for the selected square input
ResNet-50 backbone
Input
3 × 800 × 800
Conv2d 7×7, s=2, p=3
64 × 400 × 400; no bias
BatchNorm2d + ReLU
64 × 400 × 400; eps=0.00001
MaxPool2d 3×3, s=2, p=1
64 × 200 × 200
C2: 1 projection + 2 identity blocks
256 × 200 × 200; hidden 64
C3: 1 projection + 3 identity blocks
512 × 100 × 100; hidden 128
C4: 1 projection + 5 identity blocks
1024 × 50 × 50; hidden 256
C5: 1 projection + 2 identity blocks
2048 × 25 × 25; hidden 512
Projection strides: C2=1, C3/C4/C5=2.
The stride is in the bottleneck 3×3 convolution.
Feature pyramid
C5: Conv2d 1×1 + BN
2048 input; 256 × 25 square
Conv2d 3×3, p=1 + BN
F3: 256 × 25 square
C4: Conv2d 1×1 + BN
1024 input; 256 × 50 square
Conv2d 3×3, p=1 + BN
F2: 256 × 50 square
+
Nearest resize
256 × 50 square
C3: Conv2d 1×1 + BN
512 input; 256 × 100 square
Conv2d 3×3, p=1 + BN
F1: 256 × 100 square
+
Nearest resize
256 × 100 square
C2: Conv2d 1×1 + BN
256 input; 256 × 200 square
Conv2d 3×3, p=1 + BN
F0: 256 × 200 square
+
Nearest resize
256 × 200 square
F3 continuation
256 × 25 × 25
MaxPool2d 1×1, s=2
pool: 256 × 13 × 13
RPN receives 5 feature maps. RoIAlign excludes the extra pooled map.
FPN normalization: BatchNorm2d, eps=0.00001; no activation.
Region Proposal Network (RPN)
Each FPN feature independently
256 channels; shared RPN weights
Conv2d 3×3 + ReLU
256 channels; repeat 2; no norm
Conv2d 1×1
3 objectness logits/location
Conv2d 1×1
12 box deltas/location
Top-K per level, then sigmoid
1000 pre-NMS proposals per level
Flatten anchor rows
Weights for box delta decode: 1,1,1,1
Generate anchors
3 per location; one size per level
Decode anchor-relative deltas
Center shift; exp sizes; clip log-scale
Filter proposals and level-wise NMS
score ≥ 0.0; NMS IoU 0.7
Retain at most 1000 proposals
R × 4 boxes; R varies with image values
Anchor ratios: 0.5, 1, 2. Sizes: 32, 64, 128, 256, 512.
Raw anchor rows on this canvas: 159,882.
Clip to canvas; remove boxes smaller than 0.001 pixels.
Box size exponent clamp: log(1000/16).
Box RoI head and final detection selection
Selected FPN features
F0/F1/F2/F3 (strides4/8/16/32)
RPN proposals
R × 4 boxes
MultiScaleRoIAlign
R × 256 × 7 × 7; sampling_ratio=2
Conv3×3 + BatchNorm + ReLU ×4
R × 256 × 7 × 7; eps=0.00001
Flatten; Linear 12544 to 1024; ReLU
R × 1024
Linear 1024 to 91
R × 91 class logits
Linear 1024 to 364
R × 91 × 4 class-specific deltas
Softmax across 91 slots
Drop background slot 0
Decode against proposals
Box coder weights 10,10,5,5; clip to canvas
Score > 0.05; remove tiny boxes; class NMS 0.5; top 100
N ≤100 boxes, labels and scores; invert input resize
R and N are dynamic. Their upper limits are fixed:
R ≤1000 and N ≤100. All per-RoI dimensions are resolved.
Model outputs use 91-class IDs; the library maps valid COCO IDs to 80.
Conv2d 3×3, p=1
256 channels; bias=False
BatchNorm2d
eps=0.00001
ReLU
RoI conv unit
Mask branch after box selection
RoIAlign on selected detection boxes
N × 256 × 14 × 14; sampling_ratio=2
Conv3×3 + BatchNorm + ReLU ×4
N × 256 × 14 × 14
ConvTranspose2d 2×2, s=2 + ReLU
N × 256 × 28 × 28
Conv2d 1×1
N × 91 × 28 × 28 logits
Sigmoid and select each detection class
N × 1 × 28 × 28
Pad masks 1 pixel and expand boxes
30 × 30 masks; box scale 30/28
Bilinear resize to each expanded box
align_corners=False; dynamic box width/height
Clip and paste onto original canvas
N × 1 × 800 × 800
The mask branch reuses FPN features and the final boxes from the box head. It does not rerun the backbone.
91 mask channels are architectural slots; each detection selects its predicted class channel before pasting.
Conv2d 3×3, p=1, no bias
256 input/output channels
BatchNorm2d
eps=0.00001
ReLU
Per-RoI spatial size preserved
Projection bottleneck
Stage order: C2 / C3 / C4 / C5.
Input
64 / 256 / 512 / 1024 ch
Conv2d 1×1
64 / 128 / 256 / 512 output channels
BatchNorm2d
64 / 128 / 256 / 512 channels
ReLU
Conv2d 3×3, p=1
s=1/2/2/2
BatchNorm2d
64 / 128 / 256 / 512 channels
ReLU
Conv2d 1×1
256 / 512 / 1024 / 2048 output channels
BatchNorm2d
No activation before addition
+
ReLU
Block output
Conv2d 1×1
256 / 512 / 1024 / 2048 ch
BatchNorm2d
Stride 1 / 2 / 2 / 2
Identity bottleneck
Stage order: C2 / C3 / C4 / C5.
Input
256 / 512 / 1024 / 2048 ch
Conv2d 1×1
64 / 128 / 256 / 512 output channels
BatchNorm2d
64 / 128 / 256 / 512 channels
ReLU
Conv2d 3×3, p=1
s=1
BatchNorm2d
64 / 128 / 256 / 512 channels
ReLU
Conv2d 1×1
256 / 512 / 1024 / 2048 output channels
BatchNorm2d
No activation before addition
+
ReLU
Block output
identity
Normalization and RoIAlign
BatchNorm2d
eps=0.00001; stored statistics in eval
ReLU or Hardswish
Hardswish(x) = x × clamp(x + 3, 0, 6) / 6
RPN repeated unit (no normalization)
Conv2d 3×3, p=1
256 channels; bias=True
ReLU
Preserve spatial dimensions
Choose a feature level per proposal
floor(4 + log2(sqrt(box area) / 224)); clip level range
RoIAlign: scale box to feature coordinates
Aligned=False; bilinear samples; sampling_ratio=2
Average 2 × 2 samples in every bin
7 × 7 bins for boxes; 14 × 14 bins for masks
R is proposal count and N is final detection count.
These dimensions depend on image values, even at fixed input size.
ResNet box/mask RoIAlign selects among P2...P5.
Complete native inference path with random-weight CPU validation. Data-dependent selection counts are not fixed tensor dimensions.
Source: models/mask_rcnn/nn.py; models/faster_rcnn/nn.py. Revision a4d0ecc9e17f.
libreyolo.com