Architectures / Computer Vision
๐ ResNet Block
ResNet residual block with skip connections
From He et al. (2015). Deep Residual Learning for Image Recognition. CVPR 2016. This page is the graph, not the PDF: open it, edit it, verify it, export it.
Every number on this page is computed from the graph by the same functions the app runs, not written by hand.
When to pick it
Structure
9 layers. Output shapes are propagated from the input shape, batch dimension excluded.
| Layer | Type | Parameters | Output shape | |
|---|---|---|---|---|
| 1 | Input | Input | shape=[64, 32, 32] | 64 ร 32 ร 32 |
| 2 | Conv2D_1 | Conv2D | outChannels=64, kernelSize=3, stride=1 | 64 ร 32 ร 32 |
| 3 | BatchNorm_1 | BatchNorm | 64 ร 32 ร 32 | |
| 4 | ReLU_1 | ReLU | 64 ร 32 ร 32 | |
| 5 | Conv2D_2 | Conv2D | outChannels=64, kernelSize=3, stride=1 | 64 ร 32 ร 32 |
| 6 | BatchNorm_2 | BatchNorm | 64 ร 32 ร 32 | |
| 7 | Add | Add | 64 ร 32 ร 32 | |
| 8 | ReLU_2 | ReLU | 64 ร 32 ร 32 | |
| 9 | Output | Output | 64 ร 32 ร 32 |
What the verifier says
The same 43 single-graph checks that run on every edit in the app, on this graph.
No finding. Shapes propagate end to end, every divisibility condition holds, and no advisory rule fires. See the checks.
The PyTorch it exports
Generated from the graph above.
# Architecture designed with Neurarch: https://neurarch.com
# PyTorch: compatible with Python 3.8+ and torch>=1.12
# Colab: pip install torch torchvision (usually pre-installed)
import torch
import torch.nn as nn
import torch.nn.functional as F
from typing import Tuple
class ResNetBlock(nn.Module):
def __init__(self):
super().__init__()
self.conv2d_1 = nn.Conv2d(64, 64, kernel_size=3, stride=1, padding=1)
self.batchNorm_1 = nn.BatchNorm2d(64)
self.conv2d_2 = nn.Conv2d(64, 64, kernel_size=3, stride=1, padding=1)
self.batchNorm_2 = nn.BatchNorm2d(64)
def forward(self, x):
# Input shape: [64,32,32]
conv2d_nv2d_1 = self.conv2d_1(x)
batch_norm_Norm_1 = self.batchNorm_1(conv2d_nv2d_1)
relu_relu_1 = F.relu(batch_norm_Norm_1)
conv2d_nv2d_2 = self.conv2d_2(relu_relu_1)
batch_norm_Norm_2 = self.batchNorm_2(conv2d_nv2d_2)
add_add_1 = batch_norm_Norm_2
relu_relu_2 = F.relu(add_add_1)
# Output
return relu_relu_2
if __name__ == '__main__':
model = ResNetBlock()
model.eval()
x = torch.randn(1, 64, 32, 32) # (batch, channels, height, width)
with torch.no_grad():
output = model(x)
print(f'Input shape : {tuple(x.shape)}')
print(f'Output shape : {tuple(output.shape)}')
total = sum(p.numel() for p in model.parameters())
trainable = sum(p.numel() for p in model.parameters() if p.requires_grad)
print(f'Parameters : {total:,} total, {trainable:,} trainable')
For agents
This architecture is machine-readable end to end. An agent can list the set, fetch this graph, edit it, and have the edit verified before any GPU time is spent.