This project use the MASS-SS3 dataset.
The raw EEG data is in edf file format and consisted of an Annotated dataset and a PSG dataset. We converted the PSG.edf into multiple 30s segments with a 256Hz sampling as the input x, the data in the corresponding Annotation.edf as label y. After encoding and removing any dirty data(including data with label of ?), the processed data were saved in npz file format and were then stored in Software/data/{cetain_channel}/
directory.
The model was built and trained using a concatenation of CNNs and BiLSTM.
- Pretrain the CNN model by running
pretrain.py --data_dir data/{cetain_channel}/ --k_folds {k_folds} --epochs {epochs} --batch_size {batch_size} --model_mode {model_mode}
Results from pretraining were saved in Software/output/{best_CNN}/
directory.
- Concatenate the outputs with the BiLSTM model for the fine-tuning process by running
fineTune.py --data_dir Software/output/{best_CNN}/ --k_folds {k_folds} --epochs {epochs} --batch_size {batch_size}
Results from fineTune were saved in Software/output/{bestModel}/
directory, which will be converted to Tensorflow Lite model for hardware deployment.
- Tensorflow Lite’s converter is used to convert the Tensorflow model into a Tensorflow Lite model.
- The Tensorflow Lite model is converted into a C source file to be compatible for deployment. This is done with the unix xxd command, which makes a hex dump of the Tensorflow Lite model file.
Sample code can be found in Hardware_ESP32/Convert_New_Model.ipynb
- Firmware code is written to control the operations of the MCU utilizing methods from the Tensorflow Lite library.
- The model is deployed to the ESP32-S2-DEVKITC-1 MCU which is connected to the computer through a USB-to-UART cable. PlatformIO IDE is used to facilitate the deployment process.
Project source code can be found in Hardware_ESP32/
Code References