plahteenlahti / psg-age-estimation

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool


Age Estimation from Sleep using Deep Learning Predicts Life Expectancy

Deep learning framework for age estimation in nocturnal polysomnography recordings.
Explore the docs »

View Demo · Report Bug · Request Feature

Table of Contents

  1. About The Project
  2. Getting Started
  3. Usage
  4. License
  5. Academic Citation

About The Project

This project is an analysis tool for polysomnography (PSG) studies that estimates age based on electrophysiological waveforms. The age estimation error (estimated age - chronological age) is a health measure, which was found to be associated with higher risk for mortality. The software inputs PSG data in the European Data Format (.edf).

Getting Started

To get a local copy up and running follow these simple steps.

Prerequisites

Here is a list of steps to get prerequisites for the repository.

  • Get python v. 3.7.
  • Get python packages from requirement.txt file. These can be installed with pip:
    pip install -r requirements.txt

Installation

  1. Clone the repo
    git clone https://github.com/abrinkk/psg-age-estimation.git

Usage

Age Estimation (Inference) in New PSGs

To estimate age in .edf files, a single script perform all steps: 1) preprocessing, 2) estimation with all four age estimation models, and 3) collects all results in a single .csv file:

python age_estimation_all.py --input_folder FOLDER_WITH_EDF_FILES --output_folder FOLDER_WITH_PREPROCESSED_FILES

Training Age Estimation Models from Scratch

The project includes further scripts in matlab and R for outcome analysis etc. Therefore, additional prerequisites are necessary:

  • Matlab v. 2019b
  • R v. 4.0.4

These are the steps required to follow the method outlined in our paper:

  1. Split data in a training, validation, and test set with uniform age distributions for the training and validation set.
    matlab data_age.m
  2. Preprocess all data. This step select and references the correct channels, filters, and resamples the signals. This step is carried out for each cohort separately.
    python psg2h5.py --input_folder FOLDER_WITH_EDF_FILES --output_folder FOLDER_WITH_PREPROCESSED_FILES --cohort COHORT_NAME
  3. Run the training script, which trains a model with a given configuration.
    python age_main.py --pre_hyperparam LR L2 DROPOUT_RATE DROPOUT_CHANNELS LOSS_FUNCTION BATCH_SIZE SEQUENCE_LENGTH SLEEP_DATA ONLY_EEG --bo 
    Here the pre_hyperparam flags indicate hyperparameters for phase (1) of the model. LR: learning rate, L2: L2 weight decay, DROPOUT_RATE: dropout rate for the last layer, DROPOUT_CHANNELS: dropout rate for each signal, LOSS_FUNCTION: choice of loss function, BATCH_SIZE: batch_size, SEQUENCE_LENGTH: length of epochs (set to 5 minutes), SLEEP_DATA: to ignore all data in wakefulness, ONLY_EEG: flag to choose channel configurations. The --bo flag indicates whether to use Bayesian optimization for the hyperparameters in phase (2) of the model.
  4. (Optional) - Interpret model decisions.
    python model_interpretation.py --m_run MODEL_NAME --atr_method RELEVANCE_ATTRIBUTION_METHOD
  5. (Optional) - Evaluate mortality risk based on age estimation errors.
    matlab sleep_age_statistics.m

NOTE: Matlab script need to be changed such that paths are correctly set.

License

Distributed under the MIT License. See LICENSE for more information.

Academic Citation

Please use the following citation when referencing this software:

About

License:MIT License


Languages

Language:MATLAB 64.3%Language:Python 34.4%Language:HTML 1.1%Language:Java 0.2%Language:R 0.1%