Spaces:
Sleeping
Sleeping
Commit
·
29201f7
1
Parent(s):
e0bb4b6
update
Browse files
app.py
CHANGED
@@ -11,41 +11,51 @@ from mne.channels import read_custom_montage
|
|
11 |
quickstart = """
|
12 |
# Quickstart
|
13 |
|
|
|
|
|
14 |
### Raw data
|
15 |
1. The data need to be a two-dimensional array (channel, timepoint).
|
16 |
2. Make sure you have **resampled** your data to **256 Hz**.
|
17 |
3. Upload your EEG data in `.csv` format.
|
18 |
|
19 |
### Channel locations
|
20 |
-
Upload your data's channel locations in `.loc` format, which can be obtained using **EEGLAB**.
|
21 |
-
|
22 |
-
### Model
|
23 |
-
Choose the model you want to use.
|
24 |
-
The detailed description of the models can be found in other pages.
|
25 |
|
26 |
### Imputation
|
27 |
The models was trained using the EEG signals of 30 channels, including: `Fp1, Fp2, F7, F3, Fz, F4, F8, FT7, FC3, FCz, FC4, FT8, T7, C3, Cz, C4, T8, TP7, CP3, CPz, CP4, TP8, P7, P3, Pz, P4, P8, O1, Oz, O2`.
|
28 |
We expect your input data to include these channels as well.
|
29 |
-
If your data doesn't contain all of the mentioned channels,
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
|
|
|
|
|
|
|
|
35 |
>Note: The imputed channels **need to be removed** after the data being reconstructed.
|
36 |
|
37 |
### Mapping result
|
38 |
-
|
39 |
|
40 |
### Missing channels
|
41 |
-
The channels displayed here are those for which the template didn't find suitable channels to use, and utilized
|
42 |
Therefore, you need to
|
43 |
-
<
|
44 |
after you download the denoised data.
|
45 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
46 |
"""
|
47 |
-
# ### Denoised data: Once the reconstructing process finished, the denoised data will be downloadable here.
|
48 |
-
# ### New channel locations: The template channel locations is downloadable here.
|
49 |
|
50 |
icunet = """
|
51 |
# IC-U-Net
|
@@ -53,6 +63,7 @@ icunet = """
|
|
53 |
Electroencephalography (EEG) signals are often contaminated with artifacts. It is imperative to develop a practical and reliable artifact removal method to prevent the misinterpretation of neural signals and the underperformance of brain–computer interfaces. Based on the U-Net architecture, we developed a new artifact removal model, IC-U-Net, for removing pervasive EEG artifacts and reconstructing brain signals. IC-U-Net was trained using mixtures of brain and non-brain components decomposed by independent component analysis. It uses an ensemble of loss functions to model complex signal fluctuations in EEG recordings. The effectiveness of the proposed method in recovering brain activities and removing various artifacts (e.g., eye blinks/movements, muscle activities, and line/channel noise) was demonstrated in a simulation study and four real-world EEG experiments. IC-U-Net can reconstruct a multi-channel EEG signal and is applicable to most artifact types, offering a promising end-to-end solution for automatically removing artifacts from EEG recordings. It also meets the increasing need to image natural brain dynamics in a mobile setting.
|
54 |
"""
|
55 |
|
|
|
56 |
with gr.Blocks() as demo:
|
57 |
|
58 |
state_json = gr.JSON(elem_id="state", visible=False)
|
@@ -76,7 +87,7 @@ with gr.Blocks() as demo:
|
|
76 |
in_raw_loc = gr.File(label="Channel locations (.loc, .locs)", file_types=[".loc", "locs"])
|
77 |
with gr.Row():
|
78 |
in_fill_mode = gr.Dropdown(choices=["zero",
|
79 |
-
("adjacent
|
80 |
("mean (manually select channels)", "mean")],
|
81 |
value="zero",
|
82 |
label="Imputation",
|
@@ -145,7 +156,7 @@ with gr.Blocks() as demo:
|
|
145 |
except OSError as e:
|
146 |
utils.dataDelete(filepath+"/temp_data/")
|
147 |
os.mkdir(filepath+"/temp_data/")
|
148 |
-
print(e)
|
149 |
|
150 |
return {state_json : {"filepath" : filepath+"/temp_data/"},
|
151 |
accordion : gr.Accordion(visible=False),
|
|
|
11 |
quickstart = """
|
12 |
# Quickstart
|
13 |
|
14 |
+
## 1. Channel mapping
|
15 |
+
|
16 |
### Raw data
|
17 |
1. The data need to be a two-dimensional array (channel, timepoint).
|
18 |
2. Make sure you have **resampled** your data to **256 Hz**.
|
19 |
3. Upload your EEG data in `.csv` format.
|
20 |
|
21 |
### Channel locations
|
22 |
+
Upload your data's channel locations in `.loc` format, which can be obtained using **EEGLAB**.
|
23 |
+
>If you cannot obtain it, we recommend you to download the standard montage <a href="">here</a>. If the channels in those files doesn't match yours, you can use **EEGLAB** to modify them to your needed montage.
|
|
|
|
|
|
|
24 |
|
25 |
### Imputation
|
26 |
The models was trained using the EEG signals of 30 channels, including: `Fp1, Fp2, F7, F3, Fz, F4, F8, FT7, FC3, FCz, FC4, FT8, T7, C3, Cz, C4, T8, TP7, CP3, CPz, CP4, TP8, P7, P3, Pz, P4, P8, O1, Oz, O2`.
|
27 |
We expect your input data to include these channels as well.
|
28 |
+
If your data doesn't contain all of the mentioned channels, there are 3 imputation ways you can choose from:
|
29 |
+
|
30 |
+
<u>Manually</u>:
|
31 |
+
- **mean**: select the channels you wish to use for imputing the required one, and we will average their values. If you select nothing, zeros will be imputed. For example, you didn't have **FCZ** and you choose **FC1, FC2, FZ, CZ** to impute it(depending on the channels you have), we will compute the mean of these 4 channels and assign this new value to **FCZ**.
|
32 |
+
|
33 |
+
<u>Automatically</u>:
|
34 |
+
Firstly, we will attempt to find neighboring channel to use as alternative. For instance, if the required channel is **FC3** but you only have **FC1**, we will use it as a replacement for **FC3**.
|
35 |
+
Then, depending on the **Imputation** way you chose, we will:
|
36 |
+
- **zero**: fill the missing channels with zeros.
|
37 |
+
- **adjacent**: fill the missing channels using neighboring channels which are located closer to the center. For example, if the required channel is **F3** but you only have **F7, FZ**, then we will choose **FZ** as the imputing value for **F3**.
|
38 |
>Note: The imputed channels **need to be removed** after the data being reconstructed.
|
39 |
|
40 |
### Mapping result
|
41 |
+
Once the mapping process is finished, the **template montage** and the **input montage**(with the channels choosen by the mapping function displaying their names) will be shown.
|
42 |
|
43 |
### Missing channels
|
44 |
+
The channels displayed here are those for which the template didn't find suitable channels to use, and utilized **Imputation** to fill the missing values.
|
45 |
Therefore, you need to
|
46 |
+
<span style="color:red">**remove these channels**</span>
|
47 |
after you download the denoised data.
|
48 |
|
49 |
+
### Template location file
|
50 |
+
You need to use this as the **new location file** for the denoised data.
|
51 |
+
|
52 |
+
## 2. Decode data
|
53 |
+
|
54 |
+
### Model
|
55 |
+
Select the model you want to use.
|
56 |
+
The detailed description of the models can be found in other pages.
|
57 |
+
|
58 |
"""
|
|
|
|
|
59 |
|
60 |
icunet = """
|
61 |
# IC-U-Net
|
|
|
63 |
Electroencephalography (EEG) signals are often contaminated with artifacts. It is imperative to develop a practical and reliable artifact removal method to prevent the misinterpretation of neural signals and the underperformance of brain–computer interfaces. Based on the U-Net architecture, we developed a new artifact removal model, IC-U-Net, for removing pervasive EEG artifacts and reconstructing brain signals. IC-U-Net was trained using mixtures of brain and non-brain components decomposed by independent component analysis. It uses an ensemble of loss functions to model complex signal fluctuations in EEG recordings. The effectiveness of the proposed method in recovering brain activities and removing various artifacts (e.g., eye blinks/movements, muscle activities, and line/channel noise) was demonstrated in a simulation study and four real-world EEG experiments. IC-U-Net can reconstruct a multi-channel EEG signal and is applicable to most artifact types, offering a promising end-to-end solution for automatically removing artifacts from EEG recordings. It also meets the increasing need to image natural brain dynamics in a mobile setting.
|
64 |
"""
|
65 |
|
66 |
+
|
67 |
with gr.Blocks() as demo:
|
68 |
|
69 |
state_json = gr.JSON(elem_id="state", visible=False)
|
|
|
87 |
in_raw_loc = gr.File(label="Channel locations (.loc, .locs)", file_types=[".loc", "locs"])
|
88 |
with gr.Row():
|
89 |
in_fill_mode = gr.Dropdown(choices=["zero",
|
90 |
+
("adjacent channel", "adjacent"),
|
91 |
("mean (manually select channels)", "mean")],
|
92 |
value="zero",
|
93 |
label="Imputation",
|
|
|
156 |
except OSError as e:
|
157 |
utils.dataDelete(filepath+"/temp_data/")
|
158 |
os.mkdir(filepath+"/temp_data/")
|
159 |
+
#print(e)
|
160 |
|
161 |
return {state_json : {"filepath" : filepath+"/temp_data/"},
|
162 |
accordion : gr.Accordion(visible=False),
|