forked from NeuroTechX/moabb
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathload_model.py
63 lines (48 loc) · 1.8 KB
/
load_model.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
60
61
62
63
"""
==============================================
Load Model (Scikit, Keras) with MOABB
==============================================
This example shows how to use load the pretrained pipeline in MOABB.
"""
# Authors: Igor Carrara <[email protected]>
#
# License: BSD (3-clause)
from pickle import load
import keras
from scikeras.wrappers import KerasClassifier
from sklearn.pipeline import Pipeline
from moabb import set_log_level
from moabb.pipelines.features import StandardScaler_Epoch
from moabb.utils import setup_seed
set_log_level("info")
###############################################################################
# In this example, we will use the results computed by the following examples
#
# - plot_benchmark_
# - plot_benchmark_braindecode_
# - plot_benchmark_DL_
# ---------------------
# Set up reproducibility of Tensorflow and PyTorch
setup_seed(42)
###############################################################################
# Loading the Scikit-learn pipelines
with open(
"./results/Models_WithinSession/Zhou2016/1/0/CSP + SVM/fitted_model_best.pkl",
"rb",
) as pickle_file:
CSP_SVM_Trained = load(pickle_file)
###############################################################################
# Loading the Keras model
# We load the single Keras model, if we want we can set in the exact same pipeline.
model_Keras = keras.models.load_model(
"./results/Models_WithinSession/BNCI2014-001/1/1E/Keras_DeepConvNet/kerasdeepconvnet_fitted_model_best.h5"
)
# Now we need to instantiate a new SciKeras object since we only saved the Keras model
Keras_DeepConvNet_Trained = KerasClassifier(model_Keras)
# Create the pipelines
pipes_keras = Pipeline(
[
("StandardScaler_Epoch", StandardScaler_Epoch),
("Keras_DeepConvNet_Trained", Keras_DeepConvNet_Trained),
]
)