Xiang Zhang, Lina Yao, Manqing Dong, Zhe Liu, Yu Zhang, Yong Li
IEEE Journal of Biomedical and Health Informatics, 2020
Epileptic seizure detection from EEG signals is challenged by substantial inter-patient variability, which limits models trained on one patient from generalizing to another. This work proposes a deep learning framework that learns patient-independent seizure representations by separating seizure-specific features from patient-specific noise through adversarial training. A channel-wise attention mechanism is incorporated to identify the relative contribution of each EEG channel, providing interpretable outputs alongside the detection decision. The framework operates on the Temple University Hospital (TUH) EEG corpus in a leave-one-subject-out evaluation across 14 subjects.
Raw EEG Signal
|
v
+---------------------+
| Convolutional AE | -- shared encoder
| (task branch h_t) | -- seizure-specific features
| (person branch h_p)| -- patient-specific features
+---------------------+
| |
v v
+----------+ +----------+
| Task CNN | |Person CNN| -- adversarial objectives
| (seizure)| |(identity)|
+----------+ +----------+
|
v
+------------------+
| Attention Layer | -- channel importance weights
+------------------+
|
v
Seizure / Normal
- Shared convolutional autoencoder: encodes the input EEG window into two disentangled latent branches, one for seizure-relevant features and one for patient identity.
- Task classifier (class_t): a 4-layer CNN trained to predict seizure vs. normal using the task branch, weighted by 10x in the loss to emphasize seizure discrimination.
- Person classifier (class_p): an adversarial branch trained on the patient branch to encode and then suppress patient-identifying information from the task branch.
- Attention mechanism: a dense layer applied to the raw input that gates the task representation, highlighting the most informative EEG channels.
- Joint training: all components are optimized simultaneously with a combined loss (reconstruction + task cross-entropy + adversarial person cross-entropy + L2 regularization).
Install dependencies with:
pip install -r requirements.txt| Package | Tested Version | Notes |
|---|---|---|
| tensorflow | 1.x | Uses tf.contrib and tf.Session (TF 1 API) |
| numpy | >= 1.16 | |
| scipy | >= 1.2 | |
| scikit-learn | >= 0.20 | Used for MinMaxScaler |
Note: The code uses the TensorFlow 1.x API (
tf.contrib,tf.Session,tf.layers). TensorFlow 2.x is not compatible without modification. A GPU with CUDA support is recommended for training.
See data/README.md for download instructions and directory layout.
Step 1. Download the TUH EEG Seizure Corpus and preprocess it into the expected pickle format (see data/README.md).
Step 2. Update the data path in main.py:
# Line 17 of main.py — replace with your local path
all_data = pickle.load(open("/path/to/all_14sub.p", "rb"))Step 3. Run training with leave-one-subject-out cross-validation:
python main.pyTraining iterates over all 14 subjects, holding each out as the test subject in turn. Accuracy on the task (seizure detection) and person (identity) classifiers is printed every 10 steps.
adversarial_seizure_detection/
├── main.py # Training entry point (leave-one-subject-out loop)
├── src/
│ ├── __init__.py
│ └── utils.py # one_hot encoding, sliding-window extraction, accuracy helpers
├── data/
│ └── README.md # Dataset download and setup instructions
├── requirements.txt
├── CITATION.cff
├── LICENSE
└── README.md
If you find this work useful, please cite:
@article{zhang2020adversarial,
title = {Adversarial representation learning for robust patient-independent epileptic seizure detection},
author = {Zhang, Xiang and Yao, Lina and Dong, Manqing and Liu, Zhe and Zhang, Yu and Li, Yong},
journal = {IEEE Journal of Biomedical and Health Informatics},
volume = {24},
number = {10},
pages = {2852--2859},
year = {2020},
publisher = {IEEE},
doi = {10.1109/JBHI.2020.2971610}
}For questions about the code or algorithm, contact xiang.alan.zhang@gmail.com.
This repository is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.