Architectures / Biosignal
๐ง EEGNet
Compact CNN for EEG/BCI โ depthwise + separable convs make it 10ร lighter than standard CNNs (Lawhern 2018)
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
16 layers. Output shapes are propagated from the input shape, batch dimension excluded.
| Layer | Type | Parameters | Output shape | |
|---|---|---|---|---|
| 1 | eeg_window | Input | shape=[1, 22, 1000] | 1 ร 22 ร 1000 |
| 2 | temporal_conv | Conv2D | outChannels=8, kernelSize=[1, 64], stride=1 | 8 ร 22 ร 1001 |
| 3 | norm | BatchNorm | normalizedShape=8 | 8 ร 22 ร 1001 |
| 4 | spatial_depthwise | DepthwiseConv2D | outChannels=16, kernelSize=[22, 1], stride=1 | 16 ร 1 ร 1001 |
| 5 | norm | BatchNorm | normalizedShape=16 | 16 ร 1 ร 1001 |
| 6 | act | ELU | 16 ร 1 ร 1001 | |
| 7 | pool | AvgPool2D | kernelSize=[1, 4], stride=[1, 4] | 16 ร 1 ร 250 |
| 8 | drop | Dropout | p=0.25 | 16 ร 1 ร 250 |
| 9 | separable_conv | SeparableConv2D | outChannels=16, kernelSize=[1, 16], stride=1 | 16 ร 1 ร 251 |
| 10 | norm | BatchNorm | normalizedShape=16 | 16 ร 1 ร 251 |
| 11 | act | ELU | 16 ร 1 ร 251 | |
| 12 | pool | AvgPool2D | kernelSize=[1, 8], stride=[1, 8] | 16 ร 1 ร 31 |
| 13 | drop | Dropout | p=0.25 | 16 ร 1 ร 31 |
| 14 | flatten | Flatten | 496 | |
| 15 | classifier | Linear | outFeatures=4 | 4 |
| 16 | logits | Output | 4 |
What the verifier says
The same 41 structural 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. First 46 lines; the app exports the whole file, plus the training loop, the data contract and a deploy bundle.
# 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 EEGNet(nn.Module):
def __init__(self):
super().__init__()
self.conv2d_1 = nn.Conv2d(1, 8, kernel_size=(1, 64), stride=1, padding=(0, 32))
self.batchNorm_1 = nn.BatchNorm2d(8)
self.depthwiseConv2d_1 = nn.Conv2d(8, 8*2, kernel_size=(22, 1), groups=8, bias=True)
self.batchNorm_2 = nn.BatchNorm2d(16)
self.elu_1 = nn.ELU(alpha=1)
self.avgpool2d_1 = nn.AvgPool2d(kernel_size=(1, 4), stride=(1, 4), padding=0)
self.dropout_1 = nn.Dropout(p=0.25)
self.separableConv2d_1 = nn.Sequential(
nn.Conv2d(16, 16, kernel_size=(1, 16), groups=16, bias=False),
nn.Conv2d(16, 16, kernel_size=1)
)
self.batchNorm_3 = nn.BatchNorm2d(16)
self.elu_2 = nn.ELU(alpha=1)
self.avgpool2d_2 = nn.AvgPool2d(kernel_size=(1, 8), stride=(1, 8), padding=0)
self.dropout_2 = nn.Dropout(p=0.25)
self.linear_1 = nn.Linear(496, 4)
def forward(self, x):
# eeg_window shape: [1,22,1000]
conv2d_mporal = self.conv2d_1(x)
batch_norm_bn_1 = self.batchNorm_1(conv2d_mporal)
depthwise_conv2d_patial = self.depthwiseConv2d_1(batch_norm_bn_1)
batch_norm_bn_2 = self.batchNorm_2(depthwise_conv2d_patial)
elu_elu_1 = F.elu(batch_norm_bn_2)
avgpool2d_pool_1 = self.avgpool2d_1(elu_elu_1)
dropout_drop_1 = self.dropout_1(avgpool2d_pool_1)
separable_conv2d_arable = self.separableConv2d_1(dropout_drop_1)
batch_norm_bn_3 = self.batchNorm_3(separable_conv2d_arable)
elu_elu_2 = F.elu(batch_norm_bn_3)
avgpool2d_pool_2 = self.avgpool2d_2(elu_elu_2)
dropout_drop_2 = self.dropout_2(avgpool2d_pool_2)
flatten_tten_1 = torch.flatten(dropout_drop_2, 1)
linear_near_1 = self.linear_1(flatten_tten_1)
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.