GithubHelp home page GithubHelp logo

skjerns / autosleepscorer Goto Github PK

View Code? Open in Web Editor NEW
104.0 104.0 22.0 47.1 MB

An open-source sleep stage classification Python package

License: GNU Affero General Public License v3.0

Python 100.00%
automated-eeg-sleep-staging deep-learning hypnogram lstm sleep-analysis sleep-research sleep-scorer sleep-stage-classification sleep-stage-scoring sleep-staging tensorflow

autosleepscorer's Introduction

autosleepscorer's People

Contributors

skjerns avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

autosleepscorer's Issues

How to run the model with only eeg data in edf file?

Hi,

It's really a good project(not flattering, it's really fantastic).
In your thesis, you compared the accuracy of different input channel selection such as eeg, eeg+emg, eeg+eog, and all.
But the coed itself requires all channels?
I wonder how can I run the AutoSleepScorer with only eeg channel?

Sincerely
Liu

The running result was not found

Hi Simon
There is no error in the code running, how can the running result not be found, it is in the folder ./weights in the file?

Confusion Matrix

screenshot

Can you please explain the parameters passed to this function for obtaining the confusion matrix for this model?

Float edf

Hi Simon

I am just getting a error

TypeError: 'float' object does not support item assignment

when I am taking the dataset of ST7022JM-Hypnogram.edf or any other hypnogram.edf from physionet in sleep telemetry while converting into csv file format

How do I resolve it !!

ValueError: The number of FixedLocator locations (6), usually from a call to set_ticks, does not match the number of ticklabels (5).

From README:

# create a SleepData object 
from sleepscorer import Scorer, SleepData
file = SleepData('sample-psg.edf', start = 2880000, stop = 5400000, 
							  channels={'EEG':'EEG Fpz-Cz', 'EMG':'EMG submental', 
                              			'EOG':'EOG horizontal'}, preload=False)
# Create and run Scorer
scorer = Scorer([file], hypnograms=True, demo=True)
scorer.run()
# this will only work if you have matplotlib set-up
tools.show_sample_hypnogram('sample-psg.groundtruth.csv', start=960, stop=1800)
Predicting...
100%|█████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 4/4 [00:11<00:00,  2.91s/it]
Still rolling, I should fix that.
Predictions saved to sample-psg.edf.csv
assuming 0=W, 1=S1, 2=S2, 3=SWS, 4=REM
Traceback (most recent call last):
  File "start.py", line 8, in <module>
    scorer.run()
  File "C:\Users\Igoncharov\Anaconda3\envs\env36\lib\site-packages\sleepscorer\sleepscorer.py", line 103, in run
    tools.plot_hypnogram(preds, title ='Predictions for {}'.format( os.path.basename(filename)))
  File "C:\Users\Igoncharov\Anaconda3\envs\env36\lib\site-packages\sleepscorer\tools.py", line 302, in plot_hypnogram
    plt.yticks([0,-1,-2,-3,-4,-5], ['W','REM', 'S1', 'S2', 'SWS' ])
  File "C:\Users\Igoncharov\Anaconda3\envs\env36\lib\site-packages\matplotlib\pyplot.py", line 1719, in yticks
    labels = ax.set_yticklabels(labels, **kwargs)
  File "C:\Users\Igoncharov\Anaconda3\envs\env36\lib\site-packages\matplotlib\axes\_base.py", line 63, in wrapper
    return get_method(self)(*args, **kwargs)
  File "C:\Users\Igoncharov\Anaconda3\envs\env36\lib\site-packages\matplotlib\cbook\deprecation.py", line 451, in wrapper
    return func(*args, **kwargs)
  File "C:\Users\Igoncharov\Anaconda3\envs\env36\lib\site-packages\matplotlib\axis.py", line 1796, in _set_ticklabels
    return self.set_ticklabels(labels, minor=minor, **kwargs)
  File "C:\Users\Igoncharov\Anaconda3\envs\env36\lib\site-packages\matplotlib\axis.py", line 1718, in set_ticklabels
    "The number of FixedLocator locations"
ValueError: The number of FixedLocator locations (6), usually from a call to set_ticks, does not match the number of ticklabels (5).

Confusion Matrix

Hi Simon
Like how can we create a confusion matrix from our dataset ?

Precision

I have found both your code and your masters thesis to be incredibly helpful in doing so. Very recently I was testing your scorer and datasets with a precision marker, and received 55% precision rather than 80%. It is very possible that I made a mistake, so if you have a module/function that computes the accuracy, that will be great. Thank you so much.

Regarding result

Hi Simon

I have doubt that how you have calculated the values of accuracy and confusion matrix using certain channel like eeg , eeg+eog and eeg+emg as your model predict all the three channel collectively.

Runtime error

hello,I run the run_sample.py, but it occurs a error like thess:

File "C:\Users\bc\Desktop\AutoSleepScorerDev-master\keras_utils.py", line 689, in cv
train_data = [data[j] for j in train_idx]

File "C:\Users\bc\Desktop\AutoSleepScorerDev-master\keras_utils.py", line 689, in
train_data = [data[j] for j in train_idx]

IndexError: index 46139 is out of bounds for axis 0 with size 45242

the error occured when the model build the cv dataset, the train index is out of bound.

Path Error

Hi Simon, I'm getting this error.

main.py", line 50, in

if os.path.isdir(path):

TypeError: _isdir: path should be string, bytes or os.PathLike, not NoneType

Could you please help in identifying the reason why the path is inaccessible?

Training on another sleep database

Hi Simon,
I am starting to train the CNN/RNN on other sleep databases, and the 1st one is the SHHS database, but I have a doubt about the way to set the channels that are used (channels) and I did this:

sleep.available_channels
['SaO2', 'H.R.', 'EEG(sec)', 'ECG', 'EMG', 'EOG(L)', 'EOG(R)', 'EEG', 'THOR RES', 'ABDO RES', 'POSITION', 'LIGHT', 'NEW AIR', 'OX stat']
channels = {'EEG':['EEG(sec)','EEG'], 'EMG':'EMG', 'EOG':['EOG(L)','EOG(R)']} # set channels that are used: EEG(sec) = C3/A2 & EEG = C4/A1

Is it the correct way to retain the two available EEG channels 'EEG(sec)' and 'EEG' ? I ask because the script/training is running, so it has recognized/infered the EEG channel(s), but it missed the EOG channels.
Jeff

ValueError

Hi Simon
I am just getting an error
Value Error:-Found unexpected instance while processing input tensors for keras functional model. Expecting KerasTensor which is from tf.keras.Input() or output from keras layer call(). Got: 0

How to resolve it !!

Consumer devices for recording requisite EDF file

Hi there, great project, I'm personally looking into whether any consumer electronics can create the EDF files that you would use in the algorithm, I have a Muse headband device and they seem to have all the requisite sensors but I'm not sure if access to raw data is available for anything but EEG. Any ideas on this front, thanks!

Cannot open 'cnn.hdf5' 'rnn.hdf5'

I am trying to run the example code you posted in README.md. But, when loading the model hdf5 file, it shows an error.

File "h5py/h5f.pyx", line 78, in h5py.h5f.open
OSError: Unable to open file (file signature not found)

It seems like the model files are corrupted when I try to run "h5debug cnn.hdf5".

HDF5-DIAG: Error detected in HDF5 (1.8.16) thread 139994803136256:
#000: ../../../src/H5F.c line 604 in H5Fopen(): unable to open file
major: File accessibilty
minor: Unable to open file
#1: ../../../src/H5Fint.c line 1087 in H5F_open(): unable to read superblock
major: File accessibilty
minor: Read failed
#2: ../../../src/H5Fsuper.c line 277 in H5F_super_read(): file signature not found
major: File accessibilty
minor: Not an HDF5 file
cannot open file

Could you check the model files again?

FYI, I am running your code in Ubuntu 16.04 with python3

ERROR: No matching distribution found for tensorflow==1.3.0

pip install git+https://github.com/skjerns/AutoSleepScorer

Collecting git+https://github.com/skjerns/AutoSleepScorer
  Cloning https://github.com/skjerns/AutoSleepScorer to c:\users\igoncharov\appdata\local\temp\pip-req-build-_opres_k
  Running command git clone -q https://github.com/skjerns/AutoSleepScorer 'C:\Users\Igoncharov\AppData\Local\Temp\pip-req-build-_opres_k'
  Resolved https://github.com/skjerns/AutoSleepScorer to commit 5fa890a81c3ccbc0cab4ebcf87f4acf67311608a
Collecting keras==2.0.6
  Using cached Keras-2.0.6.tar.gz (228 kB)
ERROR: Could not find a version that satisfies the requirement tensorflow==1.3.0 (from sleepscorer) (from versions: 2.5.0rc0, 2.5.0rc1, 2.5.0rc2, 2.5.0rc3, 2.5.0, 2.5.1, 2.6.0rc0, 2.6.0rc1, 2.6.0rc2, 2.6.0)
ERROR: No matching distribution found for tensorflow==1.3.0

ModuleNotFoundError: No module named'Scorer'

Hi Simon
I have a question for you,I always have such problems when I run code:ModuleNotFoundError: No module named'Scorer',If you have the time, can you answer this question?I would appreciate it if you write back soon.

Keras not multi-processing safe ?

Hi there,
I have successfully run the sleep scorer training part (AutoSleepScorerDev) and generated new cnn & rnn weights:

  • they are slightly larger than the weights proposed for direct download (386 662 ko for the cnn weights I have generated, 386 652 ko for the one proposed & named cnn.hdf5, 18 368 ko for the rnn weights I have generated vs 14 212 ko for the rnn.hdf5).
  • for AutoSleepScorer only (not the training part), the keras prediction mode induces multiple runtime errors seemingly due to multiprocessing (I tried to disable it within the code in SleepLoader.py, tools.py, etc...) & not redibitory (it runs till the end & output a predicted hypnogram but not along with the groundtruth one ) like this:

RuntimeError:
An attempt has been made to start a new process before the
current process has finished its bootstrapping phase.

    This probably means that you are not using fork to start your
    child processes and you have forgotten to use the proper idiom
    in the main module:

        if __name__ == '__main__':
            freeze_support()
            ...

    The "freeze_support()" line can be omitted if the program
    is not going to be frozen to produce an executable.

I use Python 3.6.6, tensorflow 1.10.0, tensorflow-gpu 1.10.0, Keras 2.2.2: did you experiment such runtime errors ?
Take care,
Jean-François Baure
PS) Thanks so much skjerns, your code is very interesting.

What is the purpose of the line np.stack([eeg])

Hi Simon, may I know what is the function of these lines? I had dissect to understand its purpose, but turn out no where. Appreciate if you can shed some light

Especially, the need of the pool.apply and RawArray here. I had read the documentation, but still unable to relate why you used it here.

            xx=np.stack([eeg]) # I am able to run even w/o stack
            vv=mne.create_info(1, self.sfreq, 'eeg')
            res_eeg = pool.apply_async(
                mne.io.RawArray(xx, vv, first_samp=0, verbose=0).resample,args=(100.,)) 

About Hypnograms

Hi Simon
I'm Jim, a student of China. I'm learning your code. Can you share the hypnograms files of your thesis because of edfx database has been updated, so I can't run the edfx_database.py correctly. My e-mail address is [email protected]. Thanks a lot!

comparision

Hi Simon

Just want to ask can I get the hypnogram image which contain both human and cnn+lstm as you have paste image in your introduction part just because as I am getting only edf file image

Confusion Matrix

Hi Simon

For Plotting a confusion matrix we require a square matrix but like how can we make a square matrix from the dataset as the data are in the csv format and they are very long entries data so do you apply any code for making matrix or you have just done mannualy or you have done in excel ?

Error

ok !! But I have installed the new version than where I should run the code with the old version of keras , tensorflow and h5py!! How could I install the older version !!
One more that the dropbox link that you have shared if I just click on that link it shows the files are deleted !! Does it affect the code !!
Secondly how will I get the hypnogram so either it will be downloaded or show directly after the successfull execution of code!!

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.