FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
moabb/examples/example_codecarbon.py at develop · goodcpp/moabb · GitHub
goodcpp
moabb
Repository navigation
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
moabb
/
examples
/
example_codecarbon.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
122 lines (106 loc) · 4.5 KB
Breadcrumbs
moabb
/
examples
/
example_codecarbon.py
Copy path
File metadata and controls
122 lines (106 loc) · 4.5 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
"""
=================================================
Benchmarking with MOABB showing the CO2 footprint
=================================================
This example shows how to use MOABB to track the CO2 footprint
using `CodeCarbon library <https://codecarbon.io/>`__.
For this example, we will use only one
dataset to keep the computation time low, but this benchmark is designed
to easily scale to many datasets. Due to limitation of online documentation
generation, the results is computed on a local cluster but could be easily
replicated on your infrastructure.
"""
# Authors: Igor Carrara <igor.carrara@inria.fr>
# Bruno Aristimunha <b.aristimunha@gmail.com>
#
# License: BSD (3-clause)
###############################################################################
from
moabb
import
benchmark
,
set_log_level
from
moabb
.
analysis
.
plotting
import
codecarbon_plot
from
moabb
.
datasets
import
BNCI2014_001
,
Zhou2016
from
moabb
.
paradigms
import
LeftRightImagery
set_log_level
(
"info"
)
###############################################################################
# Loading the pipelines
# ---------------------
#
# To run this example we use several pipelines, ML and DL (Keras) and also
# pipelines that need an optimization of the hyperparameter.
# All this different pipelines are stored in ``pipelines_codecarbon``
###############################################################################
# Selecting the datasets (optional)
# ---------------------------------
#
# If you want to limit your benchmark on a subset of datasets, you can use the
# ``include_datasets`` and ``exclude_datasets`` arguments. You will need either
# to provide the dataset's object, or a dataset's code. To get the list of
# available dataset's code for a given paradigm, you can use the following
# command:
paradigm
=
LeftRightImagery
()
for
d
in
paradigm
.
datasets
:
print
(
d
.
code
)
###############################################################################
# In this example, we will use only the last dataset, 'Zhou 2016', considering
# only the first subject.
#
# Running the benchmark
# ---------------------
#
# The benchmark is run using the ``benchmark`` function. You need to specify the
# folder containing the pipelines to use, the kind of evaluation and the paradigm
# to use. By default, the benchmark will use all available datasets for all
# paradigms listed in the pipelines. You could restrict to specific evaluation
# and paradigm using the ``evaluations`` and ``paradigms`` arguments.
#
# To save computation time, the results are cached. If you want to re-run the
# benchmark, you can set the ``overwrite`` argument to ``True``.
#
# It is possible to indicate the folder to cache the results and the one to
# save the analysis & figures. By default, the results are saved in the
# ``results`` folder, and the analysis & figures are saved in the ``benchmark``
# folder.
dataset
=
Zhou2016
()
dataset2
=
BNCI2014_001
()
dataset
.
subject_list
=
dataset
.
subject_list
[:
1
]
dataset2
.
subject_list
=
dataset2
.
subject_list
[:
1
]
datasets
=
[
dataset
,
dataset2
]
results
=
benchmark
(
pipelines
=
"./pipelines_codecarbon/"
,
evaluations
=
[
"WithinSession"
],
paradigms
=
[
"LeftRightImagery"
],
include_datasets
=
datasets
,
results
=
"./results/"
,
overwrite
=
False
,
plot
=
False
,
output
=
"./benchmark/"
,
)
###############################################################################
# Benchmark prints a summary of the results. Detailed results are saved in a
# pandas dataframe, and can be used to generate figures. The analysis & figures
# are saved in the ``benchmark`` folder.
results
.
head
()
order_list
=
[
"CSP + SVM"
,
"Tangent Space LR"
,
"EN Grid"
,
"CSP + LDA Grid"
,
"Keras_EEGNet_8_2"
,
]
###############################################################################
# Plotting the results
# --------------------
# We can plot the results using the ``codecarbon_plot`` function, generated
# below. This function takes the dataframe returned by the ``benchmark``
# function as input, and returns a pyplot figure.
# The ``order_list`` argument is used to specify the order of the pipelines in
# the plot.
codecarbon_plot
(
results
,
order_list
,
country
=
"(France)"
)
###############################################################################
# The result expected will be the following image, but varying depending on the
# machine and the country used to run the example.
#
# .. image:: ../images/example_codecarbon.png
# :align: center
# :alt: carbon_example
#
###############################################################################
Back
|
FazBrowse Home
|
New Git URL