This project implements deep learning models for automated seizure detection using EEG (Electroencephalogram) data from the CHB-MIT Scalp EEG Database. The project explores various neural network architectures including LSTM, CNN-LSTM hybrids, and EEGNet for temporal seizure pattern recognition.
The system processes EEG recordings to automatically detect seizure events by analyzing temporal patterns in brain activity. Multiple model architectures are implemented and compared, with a focus on LSTM-based approaches that can capture the sequential nature of EEG signals.
The project uses the CHB-MIT Scalp EEG Database which contains:
- EEG recordings from pediatric patients
- 23-channel EEG data sampled at 256 Hz
- Annotated seizure start and end times
- Data stored in EDF (European Data Format) files
All EEG files with seizure from patient chb01 are extracted to the data_org folder for quick testing.
chb-mit-scalp-eeg-database-1.0.0/
├── chb01/
├── chb02/
├── ...
└── chb24/
├── README.md
├── seizure_times.pkl # Preprocessed seizure timing data
├── seizure_detection_lstm_2_seconds_model.keras # Trained model
├──
├── Core Scripts:
├── LSTM_all_data.py # Train on all patients combined
├── LSTM_one_per_patient_1_minute.py # Per-patient model (1-minute windows)
├── LSTM_one_per_patient_2_seconds.py # Per-patient model (2-second windows)
├── LSTM_chb01.py # Single patient (chb01) analysis
├──
├── Utility Scripts:
├── read_edf_dataset.py # EDF file exploration
├── read_seisure_time.py # Seizure timing analysis
└── predict_seizure_start_time.py # Predicting seizure start time
- EDF File Loading: Uses MNE library to read EEG data
- Temporal Windowing: Configurable sliding window approach
- Data Validation: Filters files with exactly 23 channels
- Seizure Labeling: Automatic labeling based on temporal overlap
- Sequential LSTM layers for temporal pattern recognition
- Dropout regularization to prevent overfitting
- CNN Feature Extraction: TimeDistributed CNN layers for spatial feature extraction
- Bidirectional LSTM: Captures forward and backward temporal dependencies
- Batch Normalization: Stabilizes training
- Advanced Regularization: Multiple dropout layers
- 3D CNN for spatial-temporal pattern capture
- LSTM for sequence modeling
- Global pooling for dimensionality reduction
- Specialized CNN architecture for EEG analysis
- Depthwise convolutions for channel-specific feature extraction
- Single model trained on all patients
- Better generalization across different seizure types
- Individual models for different intervals (eg. 2 seconds, 1 minute)
- Accounts for patient-specific seizure patterns
- (Outliers) Excludes patients under 4 years old (chb06, chb10, chb12, chb13)
# Install required packages
pip install mne numpy tensorflow scikit-learn pickle
# For EDF file handling
pip install pyedflib# Explore seizure timing data
python read_seisure_time.py
# Explore EDF dataset
python read_edf_dataset.pypython LSTM_one_per_patient_2_seconds.pypython LSTM_one_per_patient_1_minute.pypython LSTM_all_data.pypython LSTM_chb01.pyModels are automatically evaluated with:
- Confusion Matrix: True/False positives and negatives
- Classification Report: Precision, recall, F1-score
- Early Stopping: Prevents overfitting during training
delta: Non-seizure data length before/after seizure (default: 100 seconds)offset: Minimum overlap for seizure classification (default: 2-10 seconds)seq_len: Sliding window length (2 seconds or 60 seconds)
batch_size: 16epochs: 30-50 with early stoppingvalidation_split: 0.2test_size: 0.2
load_seizure_time(): Load preprocessed seizure timingsload_edf(): Load EEG data from EDF filesslice_data(): Create temporal windows with labels
create_lstm_model(): Basic LSTM architecturecreate_improved_lstm_model(): Advanced LSTM with CNN featurescreate_cnn_lstm_hybrid(): 3D CNN + LSTM combinationcreate_eegnet(): EEGNet implementation
generate_dataset(): Process multiple patients into training data
- Both 2-second windows and 1-minute windows can achieve an accuracy around 85%.
- 2-seconds windows are used for predicting seizure start time and achieve an accuracy around 50%.
- Model outputs are saved as
.kerasfiles for future inference.
- Real-time Processing: Optimize for online seizure detection
- Feature Engineering: Incorporate frequency domain features
- Attention Mechanisms: Improve temporal focus
- Multi-modal Data: Integrate additional physiological signals
- Interpretability: Add model explanation capabilities
- CHB-MIT Scalp EEG Database: PhysioNet
- MNE Python library for EEG processing
- TensorFlow/Keras for deep learning implementation
This project is for research and educational purposes. Please cite the CHB-MIT database when using this code.
