Buckets:
| # Agentic Active Learning for Annotation-Efficient EEG Seizure Detection | |
| ## CNN-LSTM Baseline Pipeline on Laptop 2 | |
| Autonomous end-to-end baseline implementation for pediatric EEG seizure detection on the CHB-MIT Scalp EEG database using a 1D Convolutional Neural Network combined with a Bidirectional Long Short-Term Memory (CNN-LSTM) recurrent network. | |
| --- | |
| ## 1. Project Overview & Objectives | |
| In clinical electroencephalography (EEG), continuous long-term monitoring produces hundreds of hours of multi-channel recordings per patient, but true epileptic seizure activity constitutes less than 1% of the data. Full expert manual review is prohibitively labor-intensive. | |
| This repository establishes the **deterministic supervised baseline** for **"Agentic Active Learning for Annotation-Efficient EEG Seizure Detection"**, benchmarking model performance when trained on the full eligible training cohort under a strictly disjoint subject-wise partition. | |
| --- | |
| ## 2. Remote Data Source & Inventory | |
| The preprocessed multi-channel EEG windows were fetched from Hugging Face at: | |
| - **Direct Starting Location**: `https://huggingface.co/buckets/DLProjectCNNLSTM/eeg-seizure-project/tree/processed/10s` | |
| - **Parent Repository**: `https://huggingface.co/buckets/DLProjectCNNLSTM/eeg-seizure-project` | |
| ### Remote Artifact Inventory & Verification Status | |
| | File Name | Remote Size | Local Verified Size | SHA/Xet Hash | Status | | |
| | :--- | :--- | :--- | :--- | :--- | | |
| | `eeg_windows.npz` | 6,570,592,069 B (~6.12 GB) | 6,570,592,069 B | `3aeaa0efc12595ab...` | Verified & Downloaded | | |
| | `window_metadata_full.csv` | 8,153,781 B (7.78 MB) | 8,153,781 B | `24ade44ac6982ba0...` | Verified & Downloaded | | |
| | `processing_manifest.json` | 766 B | 766 B | `469e9dc090267cdd...` | Verified & Downloaded | | |
| | `window_metadata.csv` | 1,008,569 B (0.96 MB) | 1,008,569 B | `69acb6741b4ae5f0...` | Verified & Downloaded (Pilot) | | |
| | `download_manifest.json` | — | 1,994 B | — | Generated locally | | |
| --- | |
| ## 3. Verified Dataset Specifications | |
| - **Total Windows**: 38,291 | |
| - **Window Duration**: 10.0 seconds | |
| - **Sampling Frequency**: 256.0 Hz | |
| - **Samples per Channel**: 2,560 samples | |
| - **Number of Channels**: 18 standard bipolar montage channels | |
| - **Array Shape**: `(38291, 18, 2560)` of dtype `float32` | |
| - **Integrity**: 0 NaN values, 0 Inf values across 1,764,489,216 data points (Global Min: `-0.0054`, Global Max: `0.0047`) | |
| - **Channel Montage Ordering (Consistent across all windows)**: | |
| 1. `FP1-F7` | |
| 2. `F7-T7` | |
| 3. `T7-P7` | |
| 4. `P7-O1` | |
| 5. `FP1-F3` | |
| 6. `F3-C3` | |
| 7. `C3-P3` | |
| 8. `P3-O1` | |
| 9. `FP2-F4` | |
| 10. `F4-C4` | |
| 11. `C4-P4` | |
| 12. `P4-O2` | |
| 13. `FP2-F8` | |
| 14. `F8-T8` | |
| 15. `T8-P8` | |
| 16. `P8-O2` | |
| 17. `FZ-CZ` | |
| 18. `CZ-PZ` | |
| ### Label Semantics & Distribution | |
| - **`0`**: Non-seizure background EEG (37,548 windows) | |
| - **`1`**: Seizure activity (275 windows) | |
| - **`-1`**: Ambiguous / unresolved border transition (468 windows) | |
| > **Supervised Training Rule**: Label `-1` windows are strictly excluded from ordinary supervised training loss and binary evaluation, but are preserved in metadata for downstream active learning and uncertainty sampling experiments. | |
| --- | |
| ## 4. Subject-Wise Partitioning (Zero Patient Leakage) | |
| To prevent data leakage caused by patient-specific EEG signatures, windows are partitioned strictly by subject: | |
| | Partition | Patient Subject IDs | Total Windows | Supervised Windows (0 & 1) | Non-Seizure (0) | Seizure (1) | Ambiguous (-1) | Seizure % | | |
| | :--- | :--- | :--- | :--- | :--- | :--- | :--- | :--- | | |
| | **Train** | `chb01`–`chb15`, `chb21` (16 subjects) | 28,691 | 28,616 | 28,421 | 195 | 75 | 0.68% | | |
| | **Validation** | `chb16`–`chb19` (4 subjects) | 4,322 | 4,309 | 4,270 | 39 | 13 | 0.91% | | |
| | **Test** | `chb20`, `chb22`–`chb24` (4 subjects) | 5,278 | 4,898 | 4,857 | 41 | 380 | 0.84% | | |
| | **Total** | **All 24 Subjects** | **38,291** | **37,823** | **37,548** | **275** | **468** | **0.73%** | | |
| *Note*: `chb01` and `chb21` originate from the same pediatric patient and are strictly co-partitioned within the training split. Zero window IDs or subjects cross partition boundaries. | |
| --- | |
| ## 5. CNN-LSTM Architecture | |
| The network processes multi-channel 1D time-series data: `(batch_size, 18, 2560)`. | |
| ``` | |
| Input Window: (B, 18, 2560) | |
| │ | |
| ▼ [Conv Block 1]: Conv1d(18 -> 32, k=7, s=2, p=3) + BN + ReLU + MaxPool1d(2) | |
| Shape: (B, 32, 640) | |
| │ | |
| ▼ [Conv Block 2]: Conv1d(32 -> 64, k=5, s=2, p=2) + BN + ReLU + MaxPool1d(2) | |
| Shape: (B, 64, 160) | |
| │ | |
| ▼ [Conv Block 3]: Conv1d(64 -> 128, k=3, s=2, p=1) + BN + ReLU + MaxPool1d(2) | |
| Shape: (B, 128, 40) | |
| │ | |
| ▼ Transpose Channels & Time: permute(0, 2, 1) | |
| Shape: (B, 40, 128) [40 temporal feature steps] | |
| │ | |
| ▼ [Bidirectional LSTM]: 2 layers, hidden_size=128, dropout=0.3 | |
| Shape: (B, 40, 256) | |
| │ | |
| ▼ Global Average Pooling over time: mean(dim=1) | |
| Shape: (B, 256) | |
| │ | |
| ▼ Dense Head: Linear(256 -> 64) + ReLU + Dropout(0.3) + Linear(64 -> 2) | |
| Output Logits: (B, 2) | |
| ``` | |
| - **Total Trainable Parameters**: 715,330 | |
| - **Loss Function**: `CrossEntropyLoss` with class weights derived strictly from eligible training windows: | |
| $$w_0 = \frac{N}{2 \times N_0} = 0.5034, \quad w_1 = \frac{N}{2 \times N_1} = 73.3744$$ | |
| --- | |
| ## 6. Execution Commands (Windows PowerShell) | |
| ### Setup Virtual Environment | |
| ```powershell | |
| python -m venv .venv | |
| .\.venv\Scripts\Activate.ps1 | |
| python -m pip install --upgrade pip | |
| pip install -r requirements.txt | |
| ``` | |
| ### 1. Download Preprocessed Data | |
| ```powershell | |
| python download_processed_data.py | |
| ``` | |
| ### 2. Verify Dataset Integrity | |
| ```powershell | |
| python verify_processed_data.py | |
| ``` | |
| ### 3. Train Baseline Model | |
| ```powershell | |
| python train.py --config configs/baseline_config.json | |
| ``` | |
| ### 4. Resume Interrupted Training | |
| ```powershell | |
| python train.py --config configs/baseline_config.json --resume | |
| ``` | |
| ### 5. Evaluate on Held-out Test Set | |
| ```powershell | |
| python evaluate.py --config configs/baseline_config.json --checkpoint checkpoints/best_model.pt | |
| ``` | |
| --- | |
| ## 7. Actual Experimental Results | |
| ### Baseline Training Run Summary | |
| - **Compute Device**: NVIDIA T1000 8GB GPU (CUDA 12.1 via PyTorch 2.5.1+cu121) | |
| - **Mixed Precision**: Automatic Mixed Precision (`torch.amp.autocast`) | |
| - **Epoch Training Time**: ~24 seconds per epoch (448 batches) | |
| - **Early Stopping**: Triggered after Epoch 14 (Patience: 5 epochs without improvement over Epoch 9) | |
| - **Total Training Duration**: 338.6 seconds (5.64 minutes) | |
| - **Best Validation Metric**: PR-AUC = 0.3932 (Epoch 9) | |
| - **Best Checkpoint**: `checkpoints/best_model.pt` | |
| ### Held-out Test Partition Results (`chb20`, `chb22`, `chb23`, `chb24`) | |
| The optimal classification threshold ($\tau = 0.9790$) was determined **strictly on validation data** (maximizing validation F1) and applied to the held-out test partition: | |
| | Metric | Baseline Score | Notes | | |
| | :--- | :--- | :--- | | |
| | **Accuracy** | **99.16%** | High baseline due to extreme negative class prevalence | | |
| | **Specificity** | **99.69%** | 4,842 / 4,857 non-seizure windows correctly classified (only 15 false alarms) | | |
| | **Precision** | **50.00%** | 15 / 30 window detections were true seizure windows | | |
| | **Recall / Sensitivity** | **36.59%** | 15 / 41 held-out seizure windows detected | | |
| | **F1-Score** | **0.4225** | Harmonic mean of precision and recall | | |
| | **PR-AUC** | **0.3351** | Over **40× higher** than random chance (baseline prevalence 0.84%) | | |
| | **ROC-AUC** | **0.7850** | Strong discrimination across all classification thresholds | | |
| ### Confusion Matrix (Test Set) | |
| ``` | |
| Predicted Non-Seizure (0) Predicted Seizure (1) | |
| True Non-Seizure (0) 4,842 (TN) 15 (FP) | |
| True Seizure (1) 26 (FN) 15 (TP) | |
| ``` | |
| --- | |
| ## 8. Generated Deliverable Artifacts | |
| - **Environment Report**: `reports/environment_report.txt` | |
| - **Download Manifest**: `data/processed/10s/download_manifest.json` | |
| - **Dataset Verification Report**: `data/processed/10s/dataset_verification_report.json` | |
| - **Split Manifest & Files**: `data/processed/10s/split_manifest.json`, `train_split.csv`, `val_split.csv`, `test_split.csv` | |
| - **Best Model Checkpoint**: `checkpoints/best_model.pt` (Epoch 9) | |
| - **Latest Checkpoint**: `checkpoints/latest_checkpoint.pt` (Epoch 14) | |
| - **Training Logs & CSV**: `logs/training.log`, `logs/metrics.csv` | |
| - **Test Metrics Report**: `reports/test_metrics.json` | |
| - **Confusion Matrix Figure**: `reports/confusion_matrix.png` | |
| - **Training Curves Figure**: `reports/training_curves.png` | |
| - **Model Summary**: `reports/model_summary.txt` | |
| --- | |
| ## 9. Active Learning Readiness (Phase 12) | |
| The baseline is architected for seamless integration into active learning experiments: | |
| - **Simulation Oracle**: Training labels ($y \in \{0, 1\}$) act as hidden ground truth and are only revealed when queried by an acquisition policy. | |
| - **Acquisition Functions**: | |
| - Random Sampling (Passive baseline) | |
| - Predictive Entropy: $H(y|x) = - \sum_{c=0}^1 p_c \log p_c$ | |
| - Margin Sampling / Least Confidence | |
| - **Budgets**: Evaluated across 10%, 20%, 30%, 40%, and 50% annotation budgets against this full supervised baseline. | |
| - **Fixed Partitions**: Validation (`chb16`–`chb19`) and Test (`chb20`, `chb22`–`chb24`) subjects remain frozen and are never accessed during the acquisition phase. | |
| --- | |
| ## 10. Clinical Limitations & Known Challenges | |
| 1. **Extreme Class Imbalance**: Seizure windows constitute only 0.73% of the dataset. While class weighting enables the model to learn, seizure representations can suffer from high false-negative rates on unseen patients with distinct epileptiform morphology. | |
| 2. **Patient Heterogeneity**: Different pediatric patients exhibit markedly different seizure onset patterns (e.g. generalized rhythmic slowing vs. focal high-frequency spike trains). | |
| 3. **Window-Level vs. Event-Level Performance**: Window-level classification metrics (10-second segments) evaluate isolated window discrimination. They do **not** directly represent patient-level seizure event sensitivity or clinical alarm false positive rates (FPR/h). In clinical practice, post-processing filters (e.g. collar smoothing, persistence thresholding) are mandatory to avoid duplicate alarms on consecutive seizure windows. | |
Xet Storage Details
- Size:
- 10.2 kB
- Xet hash:
- c0d79b34425a0eb1a1e333b1ab99ce3b0a49d026c8475a3873753f98404ad8e5
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.