-
Notifications
You must be signed in to change notification settings - Fork 175
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
[MRG] USLEEP model #282
[MRG] USLEEP model #282
Conversation
…taset` to return sequences of windows - adding modified sleep staging examples that work on sequences of EEG windows - adding a method `embed` to `SleepStagetChambon2018` class to reuse it as a feature extractor in the sleep staging on sequences examples - adding tests
… test - updating sleep_staging_sequences example to use sampler instead of SequenceDataset
…ecode into sequence-dataset a
- adding seq_target_transform property to BaseConcatDataset to transform the targets when extracting sequences of SequenceWindowsDataset - adding functionality in BaseConcatDataset to index with a list of indices, such that a sequence a windows and targets can be returned - fixing SleepPhysionet bug where cropping would cause an error with some recordings - changing hyperparameters of sleep staging example to improve performance in a few epochs - adding more representative splitting functionality in sleep staging example - using class weights for imbalanced classes in sleep staging example
…ecode into sequence-dataset Fusioner usleep + sequence dataset
…ecode into sequence-dataset
…ecode into sequence-dataset new working branch
I just had a chat with @tgnassou and @l-omar-chehab. There are three things that still need to be done in this PR:
@tgnassou and @l-omar-chehab will reach out to the authors to ask them which version they ended up using.
|
Also, to answer your previous comment @robintibor : |
Maybe a clarification regarding examples as I see it @hubertjb
This way, we can make sure the code always runs, is fast enough on CI, and should prevent users from mistakenly adopting suboptimal pipelines. And it is acceptable if the example due to reduced data and reduced number of examples does not learn anything as is (e.g., our trialwise decoding example (https://braindecode.org/master/auto_examples/plot_bcic_iv_2a_moabb_trial.html) is barely above chance on train and exactly at chance on valid at the end of training). Otherwise, with examples that are "more realistic" but with suboptimal hyperparameters, we have seen users adopt suboptimal hyperparameters in their training and expect good results. |
This PR is ready to merge |
braindecode/models/usleep.py
Outdated
depth = 10 | ||
time_conv_size = 9 # 0.09s at sfreq = 100 Hz | ||
max_pool_size = 2 # 0.02s at sfreq = 100 Hz | ||
n_time_filters = 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.
if we expose this parameter in the init we'll need to add a test to make sure it works for different values no? No strong feeling here. @hubertjbanville thoughts?
@@ -209,6 +209,7 @@ | |||
with_skip_connection=True, | |||
n_classes=n_classes, | |||
input_size_s=input_size_samples / sfreq, | |||
apply_softmax=True |
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 need to use nn.CrossEntropyLoss here as you use class-weights? if so can you add a comment
so it's clear why you need to change a default parameter in a first example?
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.
what about these questions @tgnassou ? please do add some comment about the depth=12
line before the model creation, so it shows up clearly in the example doc why we reduce here. I am also confused about apply_softmax=True
and using nn.CrossEntropyLoss
as doc of cross entropy loss states:
https://pytorch.org/docs/stable/generated/torch.nn.CrossEntropyLoss.html
This criterion combines LogSoftmax and NLLLoss in one single class.
[...]
The input is expected to contain raw, unnormalized scores for each class.```
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.
Did you see this comment here @hubertjb ?
|
||
.. warning:: | ||
The example is written to have a very short excecution time. | ||
This number of epochs is here too small and very few recordings are used. |
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.
This number of epochs is here too small and very few recordings are used. | |
The number of epochs is here too small and very few recordings are used. |
.. warning:: | ||
The example is written to have a very short excecution time. | ||
This number of epochs is here too small and very few recordings are used. | ||
To obtain competitive results you need to use more data and more epochs. |
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.
Given what you observe can you be more specific? How many epochs will lead to
what accuracy (roughly). Something like : Taking for example at least 30 recordings
to training and doing 40 epochs should lead to a balanced accuracy close to 0.8.
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.
can you also put the same warning in plot_sleep_staging.py ?
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.
Yes and also add the changing of the depth parameter, in case that was for execution time @tgnassou
See comments by me and alex, and also @tgnassou I invited you to be maintainer, then you don't have to always wait for me to approve workflows. could you accept this invitation? |
So I think the loss comment from me above #282 (comment) definitely needs addressing. Is somebody still active on it or do we need to search somebody @hubertjb @tgnassou @agramfort |
I am in holidays, that's why i'm not very active these days. But I will continue the work in september! Is it ok for you @robintibor ? |
ok my plan was to have a release ~end of august, but maybe we can shift to midseptember anyways, then this one could be inside as well |
I'm still working on it and should have results soon @robintibor |
… number of filters of each layer, first conv layer in decoder blocks) - defining kernel size based on sfreq
…an even number - adding test for usleep number of parameters
@hubertjbanville nice ! can you just share a learning / convergence curve before we merge this? just to check that it's learning well and reaching good performance eg vs. Chambon et al. 🙏 |
Yes, I'll share that asap! So far I can say that the balanced sequence sampler does seem to speed up learning a bit. The USleep model, especially in its depth=12 version, is massively overparametrized though, especially given a smallish dataset like Sleep Physionet. Reducing the depth and adding some weight decay helps, but the SleepStagerChambon2018 learns much more quickly and so far reaches higher test performance. Also I did see a minor improvement in validation performance when combining softmax + CrossEntropyLoss, but so far not as much as what @tgnassou reported. More to come soon! |
Trying to conclude on this @robintibor @agramfort @tgnassou
Overall, I'm confident the model implementation is accurate. I went through the original keras implementation and made sure the dimensions and the number of parameters were exactly the same (there are now unit tests for these). The model does not learn as well on SleepPhysionet, but my guess is this is an issue with the scale of the data and the training budget rather than the model itself. |
Great summary. I suggest to merge. Thanks @hubertjb for finishing this and @tgnassou and @l-omar-chehab for the ground work |
Very nice ! Thank you @hubertjb ! |
@robintibor the green button is yours ! |
There were some conflicts now due to other PR merge, which I have resolved. |
Thanks @robintibor for fixing the conflicts and for pointing that out! I forgot to change that line - it should indeed be |
Great stuff, thanks @tgnassou @l-omar-chehab @hubertjb , merged now |
awesome team effort @tgnassou @l-omar-chehab @hubertjb 🚀 🚀 🚀 🚀 👏 👏 👏 👏 |
Add USleep model for sleep staging
Joint work with @l-omar-chehab