MCPcopy Index your code
hub / github.com/akaraspt/deepsleepnet

github.com/akaraspt/deepsleepnet @v1.0

Chat with this repo
repository ↗ · DeepWiki ↗ · release v1.0 ↗ · + Follow
413 symbols 929 edges 31 files 252 documented · 61%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

DeepSleepNet

A deep learning model for automatic sleep stage scoring based on raw, single-channel EEG.

Code for the model in the paper DeepSleepNet: a Model for Automatic Sleep Stage Scoring based on Raw Single-Channel EEG by Akara Supratak, Hao Dong, Chao Wu, Yike Guo from Data Science Institute, Imperial College London.

This work has been accepted for publication in IEEE Transactions on Neural Systems and Rehabilitation Engineering.

You can also find our accepted version before the publication in arXiv.

Environment

Prepare dataset

We evaluated our DeepSleepNet with MASS and Sleep-EDF dataset.

For the MASS dataset, you have to request for a permission to access their dataset. For the Sleep-EDF dataset, you can run the following scripts to download SC subjects.

cd data
chmod +x download_physionet.sh
./download_physionet.sh

Then run the following script to extract specified EEG channels and their corresponding sleep stages.

python prepare_physionet.py --data_dir data --output_dir data/eeg_fpz_cz --select_ch 'EEG Fpz-Cz'
python prepare_physionet.py --data_dir data --output_dir data/eeg_pz_oz --select_ch 'EEG Pz-Oz'

Training a model

Run this script to train a DeepSleepNet model for the first fold of the 20-fold cross-validation.

python train.py --data_dir data/eeg_fpz_cz --output_dir output --n_folds 20 --fold_idx 0 --pretrain_epochs 100 --finetune_epochs 200 --resume False

You need to train a DeepSleep model for every fold (i.e., fold_idx=0...19) before you can evaluate the performance. You can use the following script to run batch training

chmod +x batch_train.sh
./batch_train.sh data/eeg_fpz_cz/ output 20 0 19 0

Scoring sleep stages

Run this script to determine the sleep stages for the withheld subject for each cross-validation fold.

python predict.py --data_dir data/eeg_fpz_cz --model_dir output --output_dir output

The output will be stored in numpy files.

Get a summary

Run this script to show a summary of the performance of our DeepSleepNet compared with the state-of-the-art hand-engineering approaches. The performance metrics are overall accuracy, per-class F1-score, and macro F1-score.

python summary.py --data_dir output

Submit the job to the eAE cluster equipped with TensorLayer

  1. Setup an eAE cluster (follows the instruction in this link)
  2. Setup a MongoDB
  3. Change location of MongoDB in deepsleep/trainer.py
  4. Modify submit_eAE.py
  5. Run python submit_eAE.py

ToDo

  • Release a version that does not depend on MongoDB and Tensorlayer (easier to install, but could take longer time for training).

Citation

If you find this useful, please cite our work as follows:

@article{Supratak2017,
    title = {{DeepSleepNet: a Model for Automatic Sleep Stage Scoring based on Raw Single-Channel EEG}},
    author = {Supratak, Akara and Dong, Hao and Wu, Chao and Guo, Yike},
    journal = {IEEE Transactions on Neural Systems and Rehabilitation Engineering},
    year = {2017},
    doi={10.1109/TNSRE.2017.2721116}, 
    ISSN={1534-4320}, 
}

Licence

  • For academic and non-commercial use only.
  • Apache License 2.0

Core symbols most depended-on inside this repo

print_performance
called by 9
summary.py
maybe_download_and_extract
called by 9
tensorlayer/files.py
_conv1d_layer
called by 8
deepsleep/model.py
list_remove_repeat
called by 8
tensorlayer/layers.py
apply_transform
called by 8
tensorlayer/prepro.py
dict_to_one
called by 7
tensorlayer/utils.py
transform_matrix_offset_center
called by 6
tensorlayer/prepro.py
print_n_samples_each_class
called by 5
deepsleep/sleep_stage.py

Shape

Function 215
Method 137
Class 61

Languages

Python100%

Modules by API surface

tensorlayer/layers.py127 symbols
tensorlayer/prepro.py41 symbols
tensorlayer/db.py34 symbols
tensorlayer/nlp.py26 symbols
tensorlayer/files.py26 symbols
tensorlayer/cost.py20 symbols
deepsleep/data_loader.py17 symbols
dhedfreader.py13 symbols
deepsleep/trainer.py13 symbols
predict.py11 symbols
deepsleep/nn.py11 symbols
deepsleep/model.py11 symbols

For agents

$ claude mcp add deepsleepnet \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact