ResNet-18
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.
ResNet-18
Classification, 224 × 224 input, 1,000 classes. Tensor sizes exclude batch.
LibreYOLO
ResNet-18
Classification, 224 × 224 input, 1,000 classes. Tensor sizes exclude batch.
Network
Input
3 × 224 × 224
Conv2d 7×7 / 2
64 × 112 × 112, p=3
BatchNorm2d
64 × 112 × 112
ReLU
64 × 112 × 112
MaxPool2d 3×3 / 2
64 × 56 × 56, p=1
Layer 1: BasicBlock
64 × 56 × 56, repeats=2
Identity blocks only
Layer 2: BasicBlock
128 × 28 × 28, repeats=2
First block downsamples
Layer 3: BasicBlock
256 × 14 × 14, repeats=2
First block downsamples
Layer 4: BasicBlock
512 × 7 × 7, repeats=2
First block downsamples
AdaptiveAvgPool2d
512 × 1 × 1
Flatten (from dim 1)
512
Linear + bias
512 inputs, 1,000 logits
BasicBlock definitions
Conv2d bias=False. k=kernel, s=stride, p=padding. ReLU follows each addition.
Layer 1
Identity block (n=2)
Input 64 × 56 × 56
Conv2d 3×3
64 to 64, s=1, p=1
BatchNorm2d
64 × 56 × 56
ReLU
64 × 56 × 56
Conv2d 3×3
64 to 64, s=1, p=1
BatchNorm2d
64 × 56 × 56
+
identity
ReLU
64 × 56 × 56
Output 64 × 56 × 56
Stage repeats
Variant
n1
n2
n3
n4
ResNet-18
2
2
2
2
ResNet-34
3
4
6
3
n1..n4: total BasicBlocks per layer.
Widths are fixed at 64, 128, 256, 512.
Only repeat counts vary in this pair.
ResNet-50/101 use Bottleneck blocks
and are outside this shared topology.
Outputs are logits from model.forward.
Softmax is outside this network.
Layer 2
Projection block (n=1)
Input 64 × 56 × 56
Conv2d 3×3
64 to 128, s=2, p=1
BatchNorm2d
128 × 28 × 28
ReLU
128 × 28 × 28
Conv2d 3×3
128 to 128, s=1, p=1
BatchNorm2d
128 × 28 × 28
+
Conv2d 1×1 / 2
64 to 128, p=0
BatchNorm2d
128 × 28 × 28
ReLU
128 × 28 × 28
Output 128 × 28 × 28
Identity block (n=1)
Input 128 × 28 × 28
Conv2d 3×3
128 to 128, s=1, p=1
BatchNorm2d
128 × 28 × 28
ReLU
128 × 28 × 28
Conv2d 3×3
128 to 128, s=1, p=1
BatchNorm2d
128 × 28 × 28
+
identity
ReLU
128 × 28 × 28
Output 128 × 28 × 28
Then repeat the identity block below.
Layer 3
Projection block (n=1)
Input 128 × 28 × 28
Conv2d 3×3
128 to 256, s=2, p=1
BatchNorm2d
256 × 14 × 14
ReLU
256 × 14 × 14
Conv2d 3×3
256 to 256, s=1, p=1
BatchNorm2d
256 × 14 × 14
+
Conv2d 1×1 / 2
128 to 256, p=0
BatchNorm2d
256 × 14 × 14
ReLU
256 × 14 × 14
Output 256 × 14 × 14
Identity block (n=1)
Input 256 × 14 × 14
Conv2d 3×3
256 to 256, s=1, p=1
BatchNorm2d
256 × 14 × 14
ReLU
256 × 14 × 14
Conv2d 3×3
256 to 256, s=1, p=1
BatchNorm2d
256 × 14 × 14
+
identity
ReLU
256 × 14 × 14
Output 256 × 14 × 14
Then repeat the identity block below.
Layer 4
Projection block (n=1)
Input 256 × 14 × 14
Conv2d 3×3
256 to 512, s=2, p=1
BatchNorm2d
512 × 7 × 7
ReLU
512 × 7 × 7
Conv2d 3×3
512 to 512, s=1, p=1
BatchNorm2d
512 × 7 × 7
+
Conv2d 1×1 / 2
256 to 512, p=0
BatchNorm2d
512 × 7 × 7
ReLU
512 × 7 × 7
Output 512 × 7 × 7
Identity block (n=1)
Input 512 × 7 × 7
Conv2d 3×3
512 to 512, s=1, p=1
BatchNorm2d
512 × 7 × 7
ReLU
512 × 7 × 7
Conv2d 3×3
512 to 512, s=1, p=1
BatchNorm2d
512 × 7 × 7
+
identity
ReLU
512 × 7 × 7
Output 512 × 7 × 7
Then repeat the identity block below.
Original diagram from LibreYOLO MIT source. Unfused inference graph.
Source: libreyolo/models/resnet/nn.py. Revision a4d0ecc9e17f.
libreyolo.com