JOVANA
Explore Library Glossary Getting Started Three Levels Fields How it works Mission
Join the mission
All guides

Compact Convolutions: EEGNet and the CNNs That Learn CSP

How ShallowConvNet, DeepConvNet and EEGNet encode decades of EEG signal-processing wisdom as convolutional layers — temporal filterbanks, learned spatial filters, and depthwise-separable economy.

From CSP to convolution

The insight behind EEGNet and ShallowConvNet is that the classical oscillatory pipeline — band-pass, then spatial filter, then log-variance — has a convolutional analogue at every step. A convolution along the time axis is a learnable FIR band-pass filterbank; a convolution along the channel axis is a learnable spatial filter, exactly what CSP computes in closed form.

\text{CSP:}\quad \max_{w}\ \frac{w^\top \Sigma_1 w}{w^\top \Sigma_2 w} \;\Longleftrightarrow\; \Sigma_1 w = \lambda\,\Sigma_2 w \qquad\qquad (x * h)[t] = \sum_{\tau} h[\tau]\,x[t-\tau]

Left: CSP as a generalised eigenproblem maximising a between-class variance ratio. Right: a temporal convolution — a learnable FIR filter. A CNN can learn both.

On the left, CSP finds a spatial filter w that makes one class's signal as strong as possible while the other's is weak — a ratio you maximise. On the right, a convolution just slides a small filter along a signal in time. A CNN can learn both kinds of filter from data instead of hand-designing them.

w
The spatial filter — a weighting of the electrode channels.
\Sigma_1,\ \Sigma_2
The covariance (signal-shape) matrices of class 1 and class 2.
\frac{w^\top \Sigma_1 w}{w^\top \Sigma_2 w}
Ratio of class-1 power to class-2 power under the filter.
(x * h)[t]
A convolution: filter h swept over signal x.

For left- versus right-hand imagery, CSP finds channels where left-hand power is high while right-hand power is low.

ShallowConvNet makes the correspondence almost literal: a temporal convolution, then a spatial convolution, then a squaring nonlinearity, mean-pooling and a log — that is a differentiable, trainable CSP-plus-log-variance. Once you see this, deep EEG stops looking like black-box magic and starts looking like classical signal processing with the filters set free.

Anatomy of EEGNet

EEGNet's three stages: a temporal-convolution filterbank, a depthwise spatial convolution (learned per-band CSP), and a cheap depthwise-separable convolution before the classifier.

EEGNet takes an input shaped (1, C, T) — one image plane, C channels, T time samples — and runs three stages. (1) F_1 temporal convolutions of kernel length about half the sampling rate act as a learned frequency filterbank. (2) A depthwise convolution over the channel dimension with depth multiplier D learns D spatial filters per temporal filter — a learned, per-band CSP. (3) A separable convolution mixes over time and then combines feature maps cheaply.

# EEGNet, schematically (PyTorch-ish); input x: (B, 1, C, T)
x = TemporalConv(F1, kernel=(1, fs//2))(x)     # learned band-pass filterbank
x = BatchNorm(x)
x = DepthwiseConv(depth=D, kernel=(C, 1))(x)   # D spatial filters per band (CSP-like)
x = AvgPool(ELU(BatchNorm(x)), (1, 4))         # square-free nonlinearity + downsample
x = SeparableConv(F2, kernel=(1, 16))(x)       # depthwise-then-pointwise temporal mix
x = AvgPool(ELU(BatchNorm(x)), (1, 8))
y = Softmax(Linear(Flatten(Dropout(x))))       # a few thousand params total
The deliberate smallness — only a few thousand parameters — is the point, not a limitation.

Why depthwise-separable

A standard convolution mixing C_{\text{in}} input maps to C_{\text{out}} output maps with kernel size K costs C_{\text{in}} C_{\text{out}} K parameters. A depthwise-separable convolution splits it into a per-channel depthwise filter and a 1{\times}1 pointwise mix, costing C_{\text{in}} K + C_{\text{in}} C_{\text{out}}.

\frac{C_{\text{in}} K + C_{\text{in}} C_{\text{out}}}{C_{\text{in}} C_{\text{out}} K} \;=\; \frac{1}{C_{\text{out}}} + \frac{1}{K}

The parameter ratio: an order-of-magnitude saving — exactly the implicit regularisation the small-data regime demands.

Splitting an ordinary convolution into a per-channel filter plus a mix-the-channels step cuts the parameter count to roughly \tfrac{1}{C_{\text{out}}} + \tfrac{1}{K} of the original — often about a tenfold saving. Fewer parameters is exactly the built-in restraint that small neural datasets need.

C_{\text{in}},\ C_{\text{out}}
Number of input and output channels.
K
The filter (kernel) length.
\frac{1}{C_{\text{out}}} + \frac{1}{K}
The fraction of the original parameters you keep.

With C_{\text{out}} = 40 and K = 25 you keep about \frac{1}{40} + \frac{1}{25} \approx 0.065 of the parameters — roughly a fifteenfold reduction. This is a depthwise-separable convolution.

Fewer parameters is not merely faster; it is stronger regularisation. In the small-data regime the model that generalises is usually the one that could not have memorised the training set in the first place. EEGNet's whole design philosophy is to stay as small as the physics allows.

Training recipe and augmentation

A workable recipe: band-pass roughly 0.5–40 Hz, per-channel normalisation fit on the training fold, crop into overlapping windows, dropout 0.25–0.5, batch normalisation, early stopping, a small learning rate. Data augmentation then multiplies your effective sample size: time-shifts, additive Gaussian noise, mixup between trials, channel dropout, Fourier-surrogate signals, and frequency masking.

Reading the learned filters

Because layer 1 is temporal filters and layer 2 is spatial filters, EEGNet is unusually interpretable: you can plot the learned frequency responses and the learned scalp topographies. But there is a subtle trap. A learned spatial filter may place large weight on a channel in order to cancel a noise source, not because the signal lives there.