A sequence to sequence learning model for sleep stage and fragmentation analysis with ready to use server API.
- Python 2.7
- tensorflow/tensorflow-gpu
- numpy
- scipy
- scikit-learn
- matplotlib
- imbalanced-learn(0.4.3)
- pandas
- mne
We use the Physionet Sleep-EDF datasets for training our model.
- Use the below script to download SC subjects from the Sleep_EDF (2013) dataset
cd data_2013
chmod +x download_physionet.sh
./download_physionet.sh
- Use the below script to preprocess the signals from specified folder, channel
python prepare_upload_signal.py --data_dir data_2013 --output_dir data_2013/eeg_fpz_cz --select_ch 'EEG Fpz-Cz'
You can modify args settings in seq2seq_sleep_sleep-EDF.py at your discretion.
- Use the below script to train a model with the 20-fold cross-validation using Fpz-Cz channel of the Sleep_EDF (2013) dataset:
python seq2seq_sleep_sleep_EDF.py --data_dir data_2013/eeg_fpz_cz --output_dir output_2013 --n_folds 20
Use the below script to first preprocess a signal and then classify different stages for it with the selected model saved in folder /seq2seq-model.
python prepare_upload_signal.py --data_dir eeg_data --output_dir eeg_data/eeg_fpz_cz --select_ch 'EEG Fpz-Cz'
python predict_upload_signal.py --filename ST7022J0.npz
Helper functions for scoring, sleep fragmentation analysis locate in script eeg_frag_info_combine.py. These functions will be used in our API in deploy.py
Use the below script to start a local Flask server
python deploy.py
POST /api/analysis- Body:
file=[sleep signal file] - Header:
ContentType=multipart/form-data - Response:
- message: HTTP status message
- sleep_score, sleep_msg: sleep quality score and the message to display on clicking the button of score
- wtr, wtr_msg: weighted transition rate and the message to display on clicking the button of wtr
- total_sleep_time: total actual sleep time to be displayed on FE
- first_section_info: the information about the first section
- total_section_num: total number of sections
{ "message": ..., "sleep_score": ..., "sleep_msg": ..., "wtr": ..., "wtr_msg": ..., "total_sleep_time": ..., "total_section_num": ..., "first_section_info": { "section_id": ..., "stage_name": ..., "description": ..., "signal": { "x": ..., "y": ..., } } }
- Body:
GET /api/section- Param:
sec_id=[int from 0 to total_section_num-1] - Response:
{ "section": { "section_id": ..., "stage_name": ..., "description": ..., "signal": { "x": ..., "y": ..., } } }
- Param:
-
dataloader.py dhedfreader.pyare helper libraries for reading edf signal files -
Procfile requirements.txt runtime.txtare config files for hosting the server on Heroku