-
Notifications
You must be signed in to change notification settings - Fork 193
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adding Sleep Models #341
Adding Sleep Models #341
Conversation
Also primarily the code of the model is from this repo. I've put the paper reference, should I add the reference to this too somewhere? |
Codecov Report
@@ Coverage Diff @@
## master #341 +/- ##
==========================================
+ Coverage 81.90% 82.74% +0.83%
==========================================
Files 51 53 +2
Lines 3515 3714 +199
==========================================
+ Hits 2879 3073 +194
- Misses 636 641 +5 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Div12345 you'll need to add test and update the documentation
ask if you need help
Yeah you could just write a simple test checking that the model forward works and has expected shapes, see https://github.com/braindecode/braindecode/blob/7f524e5f81f4caff42a1e205ae8d92281d30eeb8/test/unit_tests/models/test_models.py for inspiration, you could add a test there |
Regarding the docs, what all should be updated? From the USleep PR I see api.rst and whats_new.rst updated. Should these just be updated manually? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
search for SleepStagerChambon2018 in the code base to see where the new models should be mentionned. Just add the new model names below
braindecode/models/attn_sleep.py
Outdated
|
||
|
||
class AttnSleep(nn.Module): | ||
"""Sleep Staging Architecture from Eldele et al 2021. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you add 2 publics models here no?
to be consistent this could be:
SleepStagerEldele2021
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the same convention to be followed for all the sleep staging models (USleep also)? Or only because here I'm adding these together?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you add apparently 2 new public models so to me this deserves for each a doc entry, tests etc.
feel free to start with one if you prefer / find it easier.
I just added the tests. There is one thing with the Eldele2021, it is written very specifically for 100Hz and 30s (the convolutional layers and fully connected layers after are restricting that). There can either be a resampling at the beginning to make the overall number of samples to 3000 or I can try replacing the pooling layers with AdaptiveMax/AvgPool which provides a constant output size. |
Maybe we can use similar solution to the one used in braindecode/braindecode/models/sleep_stager_chambon_2018.py Lines 60 to 63 in 3102ad5
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do you have some learning curves eg on physionet to see how well it learns?
you can start from the example of Chambon's model.
# Authors: Divyesh Narayanan <divyesh.narayanan@gmail.com> | ||
# # | ||
# # License: BSD (3-clause) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
# Authors: Divyesh Narayanan <divyesh.narayanan@gmail.com> | |
# # | |
# # License: BSD (3-clause) | |
# Authors: Divyesh Narayanan <divyesh.narayanan@gmail.com> | |
# | |
# License: BSD (3-clause) |
""" | ||
Forward pass. | ||
Parameters |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
""" | |
Forward pass. | |
Parameters | |
"""Forward pass. | |
Parameters |
import torch | ||
from torch import nn | ||
import torch.nn.functional as F | ||
import numpy as np | ||
import math | ||
import copy | ||
from copy import deepcopy |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
import torch | |
from torch import nn | |
import torch.nn.functional as F | |
import numpy as np | |
import math | |
import copy | |
from copy import deepcopy | |
import math | |
import copy | |
from copy import deepcopy | |
import numpy as np | |
import torch | |
from torch import nn | |
import torch.nn.functional as F |
first standard lib, then order by core component in the ecosystem (from global to local)
docs/whats_new.rst
Outdated
@@ -73,6 +73,7 @@ Enhancements | |||
- Only load data if needed during preprocessing (e.g., allow timecrop without loading) (:gh:`164` by `Robin Tibor Schirrmeister`_) | |||
- Adding option to sort filtered channels by frequency band for the filterbank in :func:`braindecode.datautil.filterbank` (:gh:`185` by `Lukas Gemein`_) | |||
- Adding the USleep model :class:`braindecode.models.USleep` (:gh:`282` by `Theo Gnassounou`_ and `Omar Chehab`_) | |||
- Adding SleepStagerEldele2021 and SleepStagerBlanco2020 models :class:`braindecode.models.SleepStagerEldele2021` and :class:`braindecode.models.SleepStagerBlanco2020` (:gh:`341` by `Divyesh Narayanan`_) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Adding SleepStagerEldele2021 and SleepStagerBlanco2020 models :class:`braindecode.models.SleepStagerEldele2021` and :class:`braindecode.models.SleepStagerBlanco2020` (:gh:`341` by `Divyesh Narayanan`_) | |
- Adding :class:`braindecode.models.SleepStagerEldele2021` and :class:`braindecode.models.SleepStagerBlanco2020` models for sleep staging (:gh:`341` by `Divyesh Narayanan`_) |
@agramfort The learning curve is available here The Eldele2021 learns fairly well whereas the Blanco2020 is pretty poor for this case. @sliwy I'll check that out. |
If there is no bug in Blanco2020 then I would not add a "so so" model to
braindecode and it's not free in terms of maintenance
and testing time
… |
In my use case here it shows decent learning. But I understand, let me know if you want me to make any further specific tests to see if it's worth it or otherwise I can remove it. |
what is changing compared to the graph you showed above? less epochs?
different data?
…On Mon, Oct 25, 2021 at 1:58 PM Divyesh Narayanan ***@***.***> wrote:
In my use case here
<https://github.com/Div12345/SleepStaging-TransferLearning/blob/main/Blanco2020_Model_Sleep_TL.ipynb>
it shows decent learning. But I understand, let me know if you want me to
make any further specific tests to see if it's worth it or otherwise I can
remove it.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#341 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AABHKHBN7PW2G5IQVRA6YWDUIVA4TANCNFSM5GI6AZRQ>
.
Triage notifications on the go with GitHub Mobile for iOS
<https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675>
or Android
<https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub>.
|
Same Physionet, 6 class (without reduction to AASM guidelines), more data, SGD optim (vs Adam in example), data sampler to give balanced epochs. |
Same Physionet, 6 class (without reduction to AASM guidelines), more data,
SGD optim (vs Adam in example), data sampler to give balanced epochs.
that makes many changes each of them could also benefit to the already
available models.
ideally we should have a benchmark file/notebook with soemthign like:
for model in benchmarked_models:
# train, and plot perf
so we can compare the different models in a fair manner
|
I agree. I've been working on exactly that for MOABB NeuroTechX/moabb#190, there's also the corresponding issue in Braindecode #46, but I think the datasets are bigger here? So to download, save the datasets and run the DL runs, I personally don't have the resources required to do that. |
@Div12345 you mean the time or the computational ressources? |
I mean computational resources. |
this I can help at Inria. If you share a script we can run it and share the
results with you
… |
Okay, we can continue this discussion on the Braindecode benchmarking issue, I guess then? In terms of discussing what all are to be tested out and on what datasets? |
works for me
… |
@sliwy I looked into the method used in SleepStagerChambon, so the conv/pool sizes are adjusted according to the sfreq. As I understand it, though this specifically helps in the "resolution" sort of, of the CNN there, it doesn't necessarily make the final output of the same length (for example when the length of the input signal changes with sfreq same)? I think that is taken care of by the allocation of the size of the last layer using len_last_layer? Here, there are sort of 2 main submodules and the size is varying at the end of the first submodule itself. I don't know the particular usefulness of the sfreq dependent CNN sizes, but if you say it'll be useful, I can add it anyways. |
I would suggest you resample the data to the sfreq you want for the
architecture you have.
It's much easier than updating the architecture
… |
|
||
# exception case for shhs to make modification in mrcnn as per implementation in the paper | ||
shhs = False | ||
if input_size_s == 30 and sfreq == 125 and d_model == 100: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
all the sleep scoring models I know work with 30s windows. I think could even enforce this. Then it's just a matter of sfreq. If sfreq==100 do this and if 125 do that. If different crash. No need to mention shhs in the code. Just put the doctsring that if sfreq==125Hz then we will use the reference architecture from XXX et al. which was validated on SHHS dataset. This is just doc, no variable name etc.
makes sense?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
but from what I understood,f or the "shhs case" we still have to perform the adaptation necessary for that case so that the model doesn't just crash (change kernel length). so we have to somehow do that right?
what do you mean do the "adaptation"? it's more than the "if else" I
suggested?
… |
I am still not 100% sure I understood correct, but i guess we have to supply |
yes this copy paste should be fixed
I am still not 100% sure I understood correct, but i guess we have to
supply _MRCNN with the information that kernel_length=6 for that case?
could also supply kernel_length=6 directly? or how do you mean?
yes for example.
|
So @Div12345 is a bit busy atm and would take a bit time before he can continue. Should we merge this in its current form or make a braindecode release without this? Otherwise from my side release could be done. What do you think @agramfort @gemeinl @hubertjb ? |
… more standardized for sleep examples
@Div12345 you need fix conflicts here |
@agramfort I changed the name of the plot_sleep_staging example to plot_sleep_staging_chambon2018 to be more standardized like the other sleep staging examples. I think that is what is causing the conflict? |
you need to merge the main branch into your branch. There has been changes
in this example
in parallel and this creates a conflict.
… |
@Div12345 you need to |
Gives |
I pushed a fix
please share the urls of the rendered examples in the doc build so we
can see how it looks
|
I would strongly be in favour of drastically reducing nr of epochs and/or possibly dataset size to speed up example on CI. now we know it would have good performance with reasonable epochs, so we can just cut to just 1 epoch from my point of view.. right now it has 11 min running time on CI just for this example... As before, let's just be clear to the reader that this is a modified example for faster runtime and be superclear how to run it for reasonable performance... |
@robintibor done. |
so let's merge this and have a release! how do you think @agramfort ? |
Co-authored-by: Alexandre Gramfort <alexandre.gramfort@m4x.org>
Since there were no further comments, have commited the last suggestions inside and now it's merged! Thanks so much @Div12345 !! :) |
Closes #334
Added the AttnSleep Model and have the example tried once here. AttnSleep requires Single-Channel EEG Data. So I used a new windows_dataset with a picked channel. I wasn't sure whether to update the existing example because then it probably won't look good with 2 different datasets creations?