Open dawin2015 opened 6 months ago
Thanks for raising this issue. Could you share a minimal code to reproduce this issue?
Thansk for @sylvchev's soon reply. Certainly. Just a little change according to the moabb example.
import os
import matplotlib.pyplot as plt
import torch
from absl.logging import ERROR, set_verbosity
from moabb import benchmark, set_log_level
from moabb.analysis.plotting import score_plot
from moabb.datasets import Shin2017A
from moabb.paradigms import LeftRightImagery
from moabb.utils import setup_seed
from braindecode import EEGClassifier
from braindecode.models import EEGNetv4
from sklearn.pipeline import make_pipeline
from skorch.callbacks import EarlyStopping, EpochScoring
from skorch.dataset import ValidSplit
from moabb.evaluations import CrossSessionEvaluation
set_log_level("info")
# Avoid output Warning
set_verbosity(ERROR)
os.environ["TF_CPP_MIN_LOG_LEVEL"] = "3"
# Print Information PyTorch
print(f"Torch Version: {torch.__version__}")
# Set up GPU if it is there
cuda = torch.cuda.is_available()
device = "cuda" if cuda else "cpu"
# Set random seed to be able to reproduce results
seed = 42
setup_seed(seed)
# Restrict this example only to the first two subjects of BNCI2014_001
dataset = Shin2017A(accept=True)
dataset.subject_list = dataset.subject_list[:2]
datasets = [dataset]
# Hyperparameter
LEARNING_RATE = 0.0625 * 0.01 # parameter taken from Braindecode
WEIGHT_DECAY = 0 # parameter taken from Braindecode
BATCH_SIZE = 64 # parameter taken from BrainDecode
EPOCH = 10
PATIENCE = 3
fmin = 4
fmax = 100
tmin = 0
tmax = None
clf = EEGClassifier(
module=EEGNetv4,
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=1, # Not printing the results for each epoch
)
# Create the pipelines
pipes = {}
pipes["EEGNetV4"] = make_pipeline(clf)
dataset.subject_list = dataset.subject_list[:2]
evaluation = CrossSessionEvaluation(
paradigm=LeftRightImagery(),
datasets=dataset,
suffix="braindecode_example",
overwrite=True,
return_epochs=True,
n_jobs=1,
)
results = evaluation.process(pipes)
Expected Result
Using Shin2017A dataset to do a CrossSession LeftRightImagery classification.
Current Result
Environment
Moabb Version: 1.0.0 Braindecode: 0.8.1