# ResNet Block

> ResNet residual block with skip connections

Pick when you need a depth-friendly CV backbone. Stack 2–4 blocks for CIFAR, or use as the building block of ResNet-18/50 for ImageNet-scale.

- Category: Computer Vision
- Layers: 9
- Parameters: 74.0K
- Input shape (batchless): 64 × 32 × 32
- Output shape: 64 × 32 × 32
- Verifier verdict: pass
- Graph JSON: https://neurarch.com/templates/resnet-block/model.json
- Open on the canvas: https://neurarch.com/?template=resnet-block

## Structure

| # | 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 |

## Verifier findings

No finding. Shapes propagate end to end and no advisory rule fires.

## Exported PyTorch

```python
# 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')
```

## Machine access

- Every architecture: https://neurarch.com/a/index.json
- Verify a graph of your own: `POST https://www.neurarch.com/api/v1/check` (see https://neurarch.com/developer.html)
- MCP server, so an agent edits the graph with the checks in the loop: https://neurarch.com/docs/mcp.md
