Skip to content

Commit

Permalink
Simplify plot_braindecode.py
Browse files Browse the repository at this point in the history
  • Loading branch information
PierreGtch committed Jan 31, 2024
1 parent 6ef9a8a commit c546a49
Showing 1 changed file with 5 additions and 13 deletions.
18 changes: 5 additions & 13 deletions examples/plot_braindecode.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@
import torch
from braindecode import EEGClassifier
from braindecode.models import EEGNetv4
from sklearn.pipeline import Pipeline
from sklearn.pipeline import make_pipeline
from skorch.callbacks import EarlyStopping, EpochScoring
from skorch.dataset import ValidSplit

from moabb.datasets import BNCI2014_001
from moabb.evaluations import CrossSessionEvaluation
from moabb.paradigms import MotorImagery
from moabb.pipelines.utils_pytorch import BraindecodeDatasetLoader, InputShapeSetterEEG
from moabb.pipelines.utils_pytorch import BraindecodeDatasetLoader
from moabb.utils import setup_seed


Expand Down Expand Up @@ -94,16 +94,11 @@
# callbacks InputShapeSetterEEG, where we have to specify the correct name of the parameter.
# Here, we will use the EEGNet v4 model [1]_ .

model = EEGNetv4(in_chans=1, n_classes=1, input_window_samples=100)

# Send model to GPU
if cuda:
model.cuda()
model_cls = EEGNetv4

# Define a Skorch classifier
clf = EEGClassifier(
module=model,
criterion=torch.nn.CrossEntropyLoss,
module=model_cls,
optimizer=torch.optim.Adam,
optimizer__lr=LEARNING_RATE,
batch_size=BATCH_SIZE,
Expand All @@ -118,16 +113,13 @@
EpochScoring(
scoring="accuracy", on_train=False, name="valid_acc", lower_is_better=False
),
InputShapeSetterEEG(
params_list=["in_chans", "input_window_samples", "n_classes"],
),
],
verbose=1, # Not printing the results for each epoch
)

# Create the pipelines
pipes = {}
pipes["EEGNetV4"] = Pipeline([("Braindecode_dataset", create_dataset), ("Net", clf)])
pipes["EEGNetV4"] = make_pipeline(clf)

##############################################################################
# Evaluation
Expand Down

0 comments on commit c546a49

Please sign in to comment.