Skip to content
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 Braindecode pipeline #328

Merged
merged 54 commits into from
Apr 4, 2023
Merged

Conversation

bruAristimunha
Copy link
Collaborator

Hi @sylvchev!

This is a work in progress to add the braindecode object to moabb. I need your assistance with this task.

In the file moabb/pipelines/braindecode.py, I create two custom classes for working with the braindecode library and scikit-learn classifiers.

The CreateBraindecodeDataset class serves as a transformer that converts a BaseEpochs object from the mne library into a WindowsDataset object from the braindecode library. We can evolve this first class/transformation to handle the raw data, and window sliding becomes a parameter.

The BraindecodeClassifierModel class is a classifier that wraps any classifier from EEGClassifier, providing a consistent interface for fitting the classifier to a WindowsDataset, making predictions, and computing predicted probabilities. In theory, this wrapper is not necessary, as long as we make this code sequence with the object returned by the EEGClassifier. It's a design decision.

from functools import partial
clf.fit = partial(clf.fit, epochs=10)

My points of concern for this part are mainly contained in the second file, pipelines/braindecode.py. To generate the EEGClassifier object, we need to have the n_classes, n_chans and the input_window_samples. And I understand this is handled more dynamically with moabb.

@bruAristimunha
Copy link
Collaborator Author

Hi @agramfort!

You are more than welcome to review the code if you have some space in your schedule.

I understand that the benefit of this wrapper is tremendous for braindecode—an extremely simplified way to benchmark multiple moabb datasets with any braindecode model.

@agramfort
Copy link

I don't have enough background on moabb but I am super excited to see this happening !

thx @bruAristimunha 🙏

@bruAristimunha
Copy link
Collaborator Author

bruAristimunha commented Feb 9, 2023

Hi @agramfort!

I really appreciate your message, and I understand that it may be different.

Insisting just a bit, I wanted to share a positive aspect of your revision - the library seems similar to scikit-learn and pyriemann, with classes like the transformations and pipelines in sklearn.

Would you mind looking at a tutorial on how braindecode fits in? I can put together something similar to what I showed earlier: braindecode/braindecode#46 (comment)

I think it will be something very close to your revisions in braindecode and pyriemann.

I greatly respect your time and expertise, and I'd really appreciate your help with this, but I totally understand if that's not possible.

@bruAristimunha
Copy link
Collaborator Author

I think, we need to change the poetry command to install everything using the new optional libraries.

@carraraig carraraig self-assigned this Mar 6, 2023
@sylvchev
Copy link
Member

sylvchev commented Mar 6, 2023

Ok, I wanted to propose a version that relies on braindecode.datasets.create_from_mne_raw or braindecode.preprocessing.create_windows_from_events but the crop approach seems broken for now (see braindecode/braindecode#422 (comment)) so the braindecode.datasets.create_from_X_y seems the best option right now.

moabb/pipelines/__init__.py Outdated Show resolved Hide resolved
moabb/pipelines/braindecode.py Outdated Show resolved Hide resolved
pipelines/braindecode.py Outdated Show resolved Hide resolved
pipelines/braindecode.py Outdated Show resolved Hide resolved
pyproject.toml Outdated Show resolved Hide resolved
pyproject.toml Show resolved Hide resolved
Copy link
Member

@sylvchev sylvchev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should identify the origin of the predict_proba error

moabb/benchmark.py Outdated Show resolved Hide resolved
bruAristimunha and others added 2 commits April 4, 2023 15:41
Co-authored-by: Sylvain Chevallier <sylvain.chevallier@universite-paris-saclay.fr>
@sylvchev sylvchev merged commit 241c8c2 into NeuroTechX:develop Apr 4, 2023
@sylvchev
Copy link
Member

sylvchev commented Apr 4, 2023

Thanks @bruAristimunha and @carraraig ! 🙏

@bruAristimunha bruAristimunha deleted the braindecode branch June 8, 2024 20:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants