YAML Metadata Warning:empty or missing yaml metadata in repo card
Check out the documentation for more information.
TOWARDS GENERALIZABLE LEARNING MODELS FOR EEG-BASED IDENTIFICATION OF PAIN PERCEPTION
This repository is a customized implementation inspired by MOABB (Mother of All BCI Benchmarks). It is designed to train and benchmark machine learning models on EEG datasets. The primary goal is to evaluate model performance and generalizability across participants of the sharded dataset.
Key Features
π§© Custom Dataset Integration Easily incorporate your own EEG datasets using a structured folder layout. Supports both raw and preprocessed data, enabling fast prototyping and flexible compatibility with BIDS-style or MOABB-style setups.
βοΈ Modular & Flexible Pipeline Clean and modular training pipeline supporting both classical machine learning and deep learning models. Includes preprocessing, training, evaluation, results saving with minimal boilerplate and checkpoints.
π Benchmarking & Reproducibility Compare multiple models using standardized evaluation protocols (within- and cross-participant), reproducible seeds, and consistent data splits. Designed for fair comparison across model families.
π§ Multi-Session & Cross-Site Support Seamlessly handles EEG data from different sessions and acquisition sites. Includes functionality to merge sessions and ensure consistent channel mapping across diverse setups.
ποΈ Result Logging & Visualization Automatically saves metrics, confusion matrices, and loss curves. Easily export figures and summaries for publications or reports.
EEG Signal Acquisition
The 10β20 International Positioning System is a widely used method for placing electrodes on the scalp for EEG signal recording. This system ensures standardized electrode placement, maintaining proportionality with the scalp's size and shape and preserving the relationship between each location and the underlying brain areas. High-quality EEG signals require the use of high-performance electrodes that provide consistent electrical contact with the skin, characterized by low impedance [1]. In our recordings, 64 active electrodes were used, following the 10β20 layout, with reference at FCz and ground at AFz. This configuration offers balanced sensitivity to both frontal and posterior brain regions, making it suitable for pain and sensory processing studies.
To ensure high signal quality, we used low-impedance, high-performance electrodes, and kept impedance below 10 kΞ© during acquisition. Such setup ensures stable contact with the scalp, minimizing noise and signal drift, crucial for capturing subtle patterns in brain activity. EEG signals were recorded at 1000 Hz and later downsampled to 250 Hz to reduce computational load while retaining relevant frequency content. To ensure clean signals, a bandpass filter between 1 and 100 Hz was applied to isolate relevant neural frequencies, and a notch filter at 60 Hz was used to remove powerline noise.
All EEG data are provided in BIDS-compliant format, ensuring compatibility with common EEG analysis toolkits such as MNE-Python and EEGLAB.
Repository Overview
data/: Contains EEG datasets.- Example structure:
./data/ βββ laval_5/ β βββ laval_5_session_0_epo.fif β βββ laval_5_session_1_epo.fif βββ mcgill_3 βββ mcgill_3_session_0_epo.fif β βββ mcgill_3_session_1_epo.fif
- Example structure:
Usage
Installation
- Clone the repository:
git clone https://anonymous.4open.science/r/eeg_pipeline_local-2108 cd eeg_pipeline_local - Install dependencies:
pip install -r requirements.txt
βΆοΈ Running the Pipeline
Model training and evaluation are executed via the main.py script, which supports both within-session and cross-subject evaluation schemes.
π§ Basic Usage
python main.py --evaluation EVAL_TYPE --model MODEL_NAME --subjects laval_5 + mcgill_3 +.. --data_path "./data" --results_path "./results" --verbose
βΉοΈ NB: To include all participants, simply omit the --subjects argument. The script will automatically load and evaluate on all available participants in the dataset folder.
π§ Examples
Run cross-subject evaluation with Deep4Net on all participants:
python main.py --evaluation cross_subject --model deep
Run within-session evaluation with TSLR on specific participants:
python main.py --evaluation within_session --model tslr --subjects laval_5 mcgill_3
βοΈ Arguments
| Argument | Description |
|---|---|
--evaluation |
Evaluation type: cross_subject or within_session |
--model |
Model name: csp, mdm, tslr, shallow, deep, eegnet, conformer, GGN |
--subjects |
(Optional) List of participants to include (e.g., laval_5 mcgill_3) |
--data_path |
Path to EEG dataset directory (default: ./data) |
--results_path |
Path to store output files (default: ./results) |
--verbose |
Add this flag to enable detailed logs during execution |
π€ Output Structure
After running an experiment, results are saved in the --results_path, structured by model and participant. Files typically include:
- JSON logs with accuracy and metrics per participant
- Confusion matrix images (PNG)
- Training curves (for deep models)
- Trained model (.pth/.joblib)
Example:
results/
βββ deep/
βββ laval_5/
β βββ laval_5_results.json
β βββ confusion_matrix_laval_5.png
β βββ training_curve_laval_5.png
βββ laval_5_model.pth
βββ mcgill_3/
β βββ ...
π Running on Compute Canada (SLURM)
If you're using a Compute Canada cluster (e.g., Cedar, BΓ©luga, or Narval), you can launch your experiment using a SLURM script.
Here is an example to run a cross-subject evaluation with a deep learning model:
#!/bin/bash
#SBATCH --account=def-yourpi # Replace with your allocation account
#SBATCH --job-name=eeg_run
#SBATCH --nodes=1
#SBATCH --gpus=1
#SBATCH --cpus-per-task=4
#SBATCH --mem=16G
#SBATCH --time=03:00:00
#SBATCH --output=logs/%x-%j.out
module load python/3.10
source ~/your-env/bin/activate # Activate your virtualenv or conda environment
# Run the evaluation
python main.py \
--evaluation cross_subject \
--model eegnet \
--data_path ./data \
--results_path ./results \
--verbose
Appendix
π For additional analyses and results, see the Appendix
π EEG Dataset: Pain Perception
This dataset is hosted on Hugging Face Datasets and contains EEG recordings in BIDS format (zipped file, ~13 GB).
π Browse the dataset on Hugging Face
π₯ Download the ZIP directly
References
- Apicella A, & al., "Machine Learning Strategies to Improve Generalization in EEG-based Emotion Assessment: a Systematic Review" 2024
- Schirrmeister R. T., et al., "Deep learning with convolutional neural networks for EEG decoding and visualization" 2017
- Roy Y., et al., "Deep learning-based electroencephalography analysis: a systematic review" 2020
- Chevallier S., et al., "The largest EEG-based BCI reproducibility study for open and reproducible science" 2024
- Downloads last month
- 58