Skip to content

Commit aac69af

Browse files
author
Xiaohui Zhang
committed
Merge remote-tracking branch 'refs/remotes/origin/main'
2 parents d664e64 + d1e0e61 commit aac69af

10 files changed

+70
-727
lines changed

LICENSE.md

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2022 Xiaohui Zhang
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

+49
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,52 @@ Part of the WFCI data used in this paper is available on PhysioNet. To note, If
3232
year={2021}
3333
}
3434
```
35+
## Code structure
36+
```
37+
└── Scripts
38+
├── AtlasandIsbrain.mat
39+
├── AttentionLayer.py
40+
├── create_tfrecords_over_10s.py
41+
├── create_tfrecords.py
42+
├── dataloader_sleep.py
43+
├── gradcam.py
44+
├── main.py
45+
├── model_attention_bilstm.py
46+
├── mouse_split.json
47+
├── train_tfrecords.sh
48+
├── utils.py
49+
└── visualize_lstm_attention_weights.py
50+
├── Results
51+
  ├── fragmented_sleep.m
52+
   ├── overlay_heatmap_gradcam.m
53+
   ├── plot_gradcam.m
54+
   ├── plot_hypnogram.m
55+
   ├── plot_scoring_length.m
56+
   ├── tight_subplot.m
57+
   └── visualize_attention_weights.m
58+
```
59+
#### In the `Scripts` folder, these are mainly the scripts for training and testing of the bidirectional LSTM model.
60+
- `main.py`: the main python script to launch the network training, validation, testing, computing the Grad-CAM and extracting the temporal attention weights by defining the parameter `mode` in the config file `train_tfrecords.sh`.
61+
- `create_tfrecords*.py`: data preprocessing code to create tfrecords from continuous WFCI recordings. When the requested epoch lenghth is large than 10 second, the code takes additional frames in the adjacent epochs to compose the final epoch, eg., take adjacent 5-second in the epoch N-1 and epoch N+1 to compose a 20-second length for epoch N.
62+
- `dataloader_sleep.py`: the dataloader to create tf.dataset object for network input, need to be modified accordingly.
63+
- `model_attention_bilstm.py`: code for building the hybrid attention-based bi-lstm model.
64+
- `AttentionLayer.py`: TensorFlow wrapper functions for building various type of attention module, including the LSTM attention, the spatial [SimAM](http://proceedings.mlr.press/v139/yang21o.html) and [CBAM](https://doi.org/10.48550/arXiv.1807.06521) module.
65+
- `gradcam.py`: code to compute the [Grad-CAM](https://doi.org/10.48550/arXiv.1610.02391) heatmaps.
66+
- `visualize_lstm_attention_weights.py`: code to visualize learned attention scores of each time steps in a given 10-s input.
67+
- `mouse_split.json`: config file to define the train/validation/test split.
68+
#### In the `Results` folder, these are mainly the MATLAB codes to analyze the sleep scoring results.
69+
- `plot_hypnogram.m`: cpde to ploy color-coded hypnogram.
70+
- `plot_gradcam.m`: overlay Grad-CAM heatmap on a selected frame with the help of function `overlay_heatmap_gradcam.m`.
71+
- `fragmented_sleep.m`: code to calculate the number of sleep transitions and the average length in each of the sleep states.
72+
- `visualize_attention_weights.m`: visualize the color-coded attention weights.
73+
## Running the Code
74+
- The main setup for running the code is running:
75+
```
76+
./train_tfrecords.sh
77+
```
78+
by setting the `mode` as `train` for training the network, `gradcam` for generating the Grad-CAM heatmap for given inputs and `attention_weights` for extacting the temporal attention scores.
79+
## Citations
80+
If you use our codes to investigating the functional brain network in WFCI, and/or the example data in your research, the authors of this software would like you to cite our paper and/or conference proceedings in your related publications.
81+
```
82+
TBD
83+
```

Scripts/.AttentionLayer.py.swo

-16 KB
Binary file not shown.

Scripts/PolyLoss.py

-27
This file was deleted.

Scripts/mask.mat

-540 Bytes
Binary file not shown.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)