# EEGNet

> Compact CNN for EEG/BCI — depthwise + separable convs make it 10× lighter than standard CNNs (Lawhern 2018)

Pick when channel count is low (4–8) and labelled trials are scarce (<400). Strong default for motor imagery / P300 BCI on consumer headsets.

- Category: Biosignal
- Layers: 16
- Parameters: 2.7K
- Input shape (batchless): 1 × 22 × 1000
- Output shape: 4
- Verifier verdict: pass
- Graph JSON: https://neurarch.com/templates/eegnet/model.json
- Open on the canvas: https://neurarch.com/?template=eegnet

## Structure

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

## Verifier findings

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

## Exported PyTorch (first 46 lines)

```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 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)
```

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