/U-Time

U-Time: A Fully Convolutional Network for Time Series Segmentation

Primary LanguagePythonMIT LicenseMIT

U-Time

Implementation of the U-Time model for time-series segmentation as described in:

Mathias Perslev, Michael Hejselbak Jensen, Sune Darkner, Poul Jørgen Jennum, and Christian Igel. U-Time: A Fully Convolutional Network for Time Series Segmentation Applied to Sleep Staging. Advances in Neural Information Processing Systems (NeurIPS 2019)

Pre-print version: https://arxiv.org/abs/1910.11162

TLDR: An end-to-end example

# Clone repo and install
git clone https://github.com/perslev/U-Time
pip3 install -e U-Time

# Obtain a public sleep staging dataset
ut fetch --dataset sleep-EDF-153 --out_dir datasets/sleep-EDF-153

# Prepare a fixed-split experiment
ut cv_split --data_dir 'datasets/sleep-EDF-153' \
            --subject_dir_pattern 'SC*' \
            --CV 1 \
            --validation_fraction 0.20 \
            --test_fraction 0.20 \
            --common_prefix_length 5 \
            --file_list

# Initialize a U-Time project
ut init --name my_utime_project \
        --model utime \
        --data_dir datasets/sleep-EDF-153/views/fixed_split

# Start training
cd my_utime_project
ut train --num_GPUs=1 --channels 'EEG Fpz-Cz'

# Predict and evaluate
ut evaluate --out_dir eval --one_shot

# Print a confusion matrix
ut cm --true 'eval/test_data/dataset_1/files/*/true.npz' \
      --pred 'eval/test_data/dataset_1/files/*/pred.npz'
      
# Print per-subject summary statistics
ut summary --csv_pattern 'eval/test_data/*/evaluation_dice.csv' \
           --print_all

# Output sleep stages for every 3 seconds of 100 Hz signal 
# Here, the 'folder_regex' matches 2 files in the dataset 
ut predict --folder_regex '../datasets/sleep-EDF-153/SC400[1-2]E0' \
           --out_dir high_res_pred \
           --data_per_prediction 300 \
           --one_shot