Code Monkey home page Code Monkey logo

slptransformer_vim's Introduction

SleepTransformer and OOD Detection (ViM)

This repository contains the implementation of data processing and OOD detection for sleep stage classification using the SleepTransformer model.

The research poster for the entire project is shown below: SleepTransformer with ViM

Steps to Reproduce

1. Dataset Preparation

  1. Download part of the SHHS dataset, not for training, just to generate features for OOD detection.


These are the source code and experimental setup for SHHS.

  1. Download the sc and st data from the SleepEDF dataset and organize them into a 'meta' folder.


These are the source code and experimental setup for SleepEDF.

2. Running SleepTransformer

  1. Download the SleepTransformer model code and pretrained weights and biases obtained from the SHHS dataset.

The model weights trained on SHHS are available at https://zenodo.org/record/7927282 for reproducing the results in the paper.

  1. Preprocess the original data (.edf) into files with 21 time steps per sample (.mat) using MATLAB. Generate 'test' and 'train' lists. Note that the 'train' list is used only for model benchmarking and not actual training.
  2. Modify the dataset address in the SleepTransformer code, run it, and generate prediction results in .mat format. Additionally, include code to output features extracted from fc2 and save them in .pkl format.
  3. Process the output predictions using the tools in the 'evaluation' folder to consolidate the 21 time step predictions into a single aggregated result.

3. Running OOD Detection (ViM)

  1. Read the 'benchmark' file to understand the idea behind ViM. Design code for OOD detection based on this idea. During this process, preprocess the data by taking logarithms and apply different thresholds for varying levels of OOD detection.
  2. Output a list of detected OOD data, and use this list to remove OOD samples. Pay attention to time step correspondences; each data group has a last sample of 21 time steps that hasn't been through detection. Therefore, be cautious while matching indices for removal.
  3. Compare the performance using different lists obtained from different thresholds.

Disclaimer

This repository serves as a guide for the described steps and their implementation. Please refer to the respective codes and tools for detailed usage instructions.

Tips

This README provides an overview and may omit some details.

Reference

  1. Huy Phan, Kaare Mikkelsen, Oliver Y. Chén, Philipp Koch, Alfred Mertins, and Maarten De Vos. "SleepTransformer: Automatic Sleep Staging With Interpretability and Uncertainty Quantification." IEEE Transactions on Biomedical Engineering (TBME), vol. 69, no. 8, pp. 2456-2467, 2022. [PDF] [Preprint]

  2. Haoqi Wang, Zhizhong Li, Litong Feng, Wayne Zhang. "ViM: Out-Of-Distribution with Virtual-logit Matching." Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition, 2022.

slptransformer_vim's People

Contributors

oooorca avatar

Stargazers

Konata avatar Yuhan Chen avatar

Watchers

Yuhan Chen avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.