Skip to content

CRCHUM-Epilepsy-Group/dl_epilepsy_reeg

Repository files navigation

DeepEpilepsy: Improving diagnostic accuracy of routine EEG for epilepsy using deep learning

Link to article: Improving diagnostic accuracy of routine EEG for epilepsy using deep learning.

By Émile Lemoine,1,2,3 Denahin Toffa,1,3 An Qi Xu,3 Jean-Daniel Tessier,1,3 Mezen Jemel,1,3 Frédéric Lesage,2,4 Dang Khoa Nguyen,1,3 and Elie Bou Assi.1,3

1Department of Neurosciences, Université de Montréal, Montréal, Qc, Canada. 2Institute of Biomedical Engineering, École Polytechnique de Montréal, Montréal, Qc, Canada. 3 Centre de Recherche du CHUM (CRCHUM), Montréal, Qc, Canada. 4 Centre de Recherche de l’institut de Cardiologie de Montréal, Montréal, Qc, Canada.

EEG processing

Abstract

The yield of routine EEG to diagnose epilepsy is limited by low sensitivity and the potential for misinterpretation of interictal epileptiform discharges. Our objective is to develop, train, and validate a deep learning model that can identify epilepsy from routine EEG recordings, complementing traditional interpretation based on identifying interictal discharges. This is a retrospective cohort study of diagnostic accuracy. All consecutive patients undergoing routine EEG at our tertiary care center between January 2018 and September 2019 were included. EEGs recorded between July 2019 and September 2019 constituted a temporally shifted testing cohort. The diagnosis of epilepsy was established by the treating neurologist at the end of the available follow-up period, based on clinical file review. Original EEG reports were reviewed for IEDs. We developed seven novel deep learning models based on Vision Transformers and Convolutional Neural Networks, training them to classify raw EEG recordings. We compared their performance to interictal discharge-based interpretation and two previously proposed machine learning methods. The study included 948 EEGs from 846 patients (820 EEGs/728 patients in training/validation, 128 EEGs/118 patients in testing). Median follow-up was 2.2 years and 1.7 years in each cohort, respectively. Our flagship Vision Transformer model, DeepEpilepsy, achieved an area under the receiver operating characteristic curve of 0.76 (95% confidence interval: 0.69–0.83), outperforming interictal discharge-based interpretation (0.69; 0.64–0.73) and previous methods. Combining DeepEpilepsy with interictal discharges increased the performance to 0.83 (0.77–0.89). DeepEpilepsy can identify epilepsy on routine EEG independently of interictal discharges, suggesting that deep learning can detect novel EEG patterns relevant to epilepsy diagnosis. Further research is needed to understand the exact nature of these patterns and evaluate the clinical impact of this increased diagnostic yield in specific settings.

Information

This repository is for reference purpose only. The code is not actively maintained. We are working on a Python library for the analysis and classification of interictal routine EEG data (not available at the moment).

The dependencies are based on Python 3.10.6

Trained Models

The trained DeepEpilepsy models are available on HuggingFace: emilelemoine/DeepEpilepsy_v1

Usage

import torch
from epileptology.ml.models.transformers import ViT1d
from epileptology.utils.parsers import parse_config

#Load configuration
config = parse_config("proj_config.yaml")
training_config = parse_config(config["data"]["sweep_config"])

# Initialize model (example: DeepEpilepsy-Large-30s)

model_name = "ViT1d_Conv1d_large_50"
SFREQ = 200
SEGMENT_DURATION = 30
model_config = training_config[model_name]["model"]
model_config.update({
    "n_class": 2,
    "n_timepoints": int(SFREQ * SEGMENT_DURATION)
})

model = ViT1d(**model_config)
model.load_state_dict(torch.load("path/to/model.pt"))
model.eval()

# Preprocess EEG (shape: n_channels, n_timepoints)
def standard_scale(eeg, eps=1e-20):
    means = eeg.mean(dim=-1, keepdim=True)
    stds = eeg.std(dim=-1, keepdim=True) + eps
    return (eeg - means) / stds

# Crop to segment duration and normalize
eeg_segment = eeg_segment[..., :int(SFREQ * SEGMENT_duration)]
eeg_segment = standard_scale(eeg_segment).unsqueeze(0)  # Add batch dimension

# Inference
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
model.to(device)
with torch.no_grad():
    predictions = model(eeg_segment.to(device))
    probabilities = torch.softmax(predictions, dim=1)

Available models: DeepEpilepsy (ViT with convolutional tokenizer) with 50 ("Large") or 200 (Small) point patches. Variants for 10- or 30s segments are included. See proj_config.yaml and training scripts for model configurations.

Note: EEG data must be preprocessed to BIDS format and segmented according to configuration parameters (see scripts for examples on how to define dataloaders).

Contact

For any questions, please contact the corresponding author or submit an issue.

References

@article{10.1093/braincomms/fcaf319,
    author = {Lemoine, Émile and Toffa, Denahin and Xu, An Qi and Tessier, Jean-Daniel and Jemel, Mezen and Lesage, Frédéric and Nguyen, Dang K and Bou Assi, Elie},
    title = {Improving diagnostic accuracy of routine EEG for epilepsy using deep learning},
    journal = {Brain Communications},
    pages = {fcaf319},
    year = {2025},
    month = {08},
    issn = {2632-1297},
    doi = {10.1093/braincomms/fcaf319},
    url = {https://doi.org/10.1093/braincomms/fcaf319},
    eprint = {https://academic.oup.com/braincomms/advance-article-pdf/doi/10.1093/braincomms/fcaf319/64127494/fcaf319.pdf},
}

Émile Lemoine, Denahin Toffa, An Qi Xu, Jean-Daniel Tessier, Mezen Jemel, Frédéric Lesage, Dang K Nguyen, Elie Bou Assi, Improving diagnostic accuracy of routine EEG for epilepsy using deep learning, Brain Communications, 2025;, fcaf319, https://doi.org/10.1093/braincomms/fcaf319

About

DeepEpilepsy: a deep learning model to detect epilepsy on routine EEG

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages