PROJECT 03

Self-Supervised Pretraining for Cross-Subject Motor Imagery BCI

Can representation learning reduce calibration?

Built to answer one specific question: can contrastive pretraining across many subjects' EEG reduce the labeled-calibration burden a new user faces before a motor-imagery BCI becomes usable? With an honest account of which interventions actually moved the needle and which didn't.

  • Self-Supervised Learning
  • EEG
  • EEGNet
  • NT-Xent
  • Riemannian Geometry
  • Cross-Subject
  • ONNX
// system_architecture5 STAGES
BNCI2014_001 + PhysionetMI (MOABB)
Channel Alignment + Augmentation
EEGNet Encoder + NT-Xent
Frozen Encoder
Few-Shot Evaluation (Linear Probe / Fine-Tune / Fusion)

Question

Can self-supervised representation learning, combined with Riemannian methods, reduce the dependence on labeled EEG data and improve cross-subject decoding?

Why It Matters

Labeled EEG data is scarce and expensive. Cross-subject generalization is one of the hardest open problems in BCI. Self-supervised pretraining is a promising direction for learning transferable representations — but the question is whether it actually helps in practice, or whether the gain comes from somewhere else entirely.

System

A multi-dataset self-supervised (NT-Xent contrastive) pretrained EEGNet-style encoder, trained across BNCI2014_001 and PhysionetMI with strict subject-level train/holdout separation. A rigorous classical baseline (Riemannian tangent-space geometry + Logistic Regression). A few-shot evaluation protocol (linear probing, full fine-tuning, SSL+Riemannian fusion). Two Streamlit applications: a Device Setup Wizard and a Benchmarking Lab. A verified ONNX export with numerical parity confirmed.

Data

BNCI2014_001 (BCI Competition IV-2a, Brunner et al., 2008) and PhysionetMI (Schalk et al., 2004), accessed via MOABB. Strict subject-level train/holdout separation with committed subject-split manifests as a leakage audit trail.

Method

Preprocessing

Channel alignment across datasets and per-trial normalization. EEG-specific augmentations: channel dropout, jitter, frequency masking, and noise.

Feature Extraction

Learned representations from a self-supervised NT-Xent contrastive pretext task, plus Riemannian covariance-based tangent-space features. The fusion method combines both feature types.

Model

EEGNet-style encoder with a projection head for contrastive learning. Linear probe head and full fine-tuning head for downstream evaluation. Riemannian tangent-space + Logistic Regression as the classical baseline.

Training

Two-stage: self-supervised pretraining on unlabeled EEG across both datasets (7–15 min on Apple Silicon MPS), followed by supervised few-shot evaluation on held-out subjects. Pretrained checkpoints published on GitHub Releases.

Evaluation

Few-shot evaluation at k=20 (80 labeled trials) on genuinely held-out subjects. Methods compared: random encoder + linear probe, pretrained + linear probe, pretrained + full fine-tune, pretrained + Riemannian fusion, and Riemannian baseline with full data. Cross-dataset transfer tested in both directions.

Experiment

Three interventions were tried to improve vanilla contrastive pretraining: (1) combining datasets, (2) LR schedule tuning (flat vs. cosine), and (3) more pretraining subjects. All three failed — accuracy plateaued at 45–47% regardless. The intervention that actually worked was feature fusion: combining the frozen SSL embedding with Riemannian tangent-space features. This reached 80.4% of full-calibration accuracy using 86% less calibration time. The gain came from combining SSL with a classical feature type, not from better SSL.

Results

Methodk=20 Accuracy% of Full-CalCalibration Time
Random encoder + linear probe39.1%54.1%10.7 min
Pretrained + linear probe46.9%64.8%10.7 min
Pretrained + full fine-tune40.4%55.9%10.7 min
Pretrained + Riemannian fusion58.2%80.4%10.7 min
Riemannian baseline (full data)72.3%100%76.8 min

BNCI2014_001, held-out subjects. Fusing SSL with Riemannian features reaches 80.4% of full-calibration accuracy using 86% less calibration time.

Vanilla contrastive pretraining alone plateaued at 45–47% regardless of data scale, schedule, or augmentation tuning. The gain that mattered came from combining the frozen SSL embedding with Riemannian tangent-space features — reaching 58.2% accuracy (80.4% of full-calibration ceiling) with only 80 labeled trials (~10.7 min) instead of 576 trials (~76.8 min). Cross-dataset transfer was also tested: an encoder pretrained on only one dataset, evaluated few-shot on the other dataset's holdout subjects, landed within ~1pt of the within-dataset reference at every k — a genuine transfer result.

What Changed

Three negative results (dataset combination, LR schedule tuning, more pretraining subjects) did not improve accuracy. The one intervention that worked was feature fusion — combining SSL embeddings with Riemannian tangent-space features. This was not the first thing tried; see docs/BENCHMARKS.md for the full negative-result sequence. Additionally, embeddings were found to carry exploitable subject-identity information (69.3% accuracy on subject identity from frozen embeddings, 10% chance floor), which has not yet been decomposed from the motor-imagery-relevant structure.

Limitations

  • No real headset tested — only replay outlet streaming recorded research data, never live electrodes.
  • Vanilla contrastive pretraining has a real ceiling at 45–47% — three independent interventions all converged to the same band.
  • Fusion requires Riemannian feature computation at inference time, not just the frozen encoder.
  • Fixed 22-channel montage — a device with a different channel layout is not compatible without retraining.
  • Small holdout set (2 subjects/dataset) — reported numbers are means over 2 held-out subjects, not a population-level claim.

Next Experiment

Try a metric-learning objective beyond vanilla NT-Xent (supervised-contrastive or prototypical-network, using pretrain-subject labels which are available but currently unused). Then broaden the holdout evaluation across several different random splits, not just one fixed 2-subject split per dataset.