-
Notifications
You must be signed in to change notification settings - Fork 165
/
braindecode_EEGInception.py
59 lines (52 loc) · 1.48 KB
/
braindecode_EEGInception.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import torch
from braindecode import EEGClassifier
from braindecode.models import EEGInception
from sklearn.pipeline import Pipeline
from skorch.callbacks import EarlyStopping, EpochScoring
from skorch.dataset import ValidSplit
from moabb.pipelines.features import Resampler_Epoch
# Set up GPU if it is there
cuda = torch.cuda.is_available()
device = "cuda" if cuda else "cpu"
# Hyperparameter
LEARNING_RATE = 0.0001
WEIGHT_DECAY = 0
BATCH_SIZE = 64
SEED = 42
VERBOSE = 1
EPOCH = 10
PATIENCE = 3
# Define a Skorch classifier
clf = EEGClassifier(
module=EEGInception,
optimizer=torch.optim.Adam,
optimizer__lr=LEARNING_RATE,
batch_size=BATCH_SIZE,
max_epochs=EPOCH,
train_split=ValidSplit(0.2, random_state=SEED),
device=device,
callbacks=[
EarlyStopping(monitor="valid_loss", patience=PATIENCE),
EpochScoring(
scoring="accuracy", on_train=True, name="train_acc", lower_is_better=False
),
EpochScoring(
scoring="accuracy", on_train=False, name="valid_acc", lower_is_better=False
),
],
verbose=VERBOSE, # Not printing the results for each epoch
)
# Create the pipelines
pipes = Pipeline(
[
("resample", Resampler_Epoch(128)),
("EEGInception", clf),
]
)
# this is what will be loaded
PIPELINE = {
"name": "braindecode_EEGInception",
"paradigms": ["LeftRightImagery", "MotorImagery"],
"pipeline": pipes,
"citations": "https://doi.org/10.1109/TNSRE.2020.3048106",
}