Inspiration

We are a group of 5 undergraduate students participating in LA Hacks 2022 who are enthusiastic about neuroscience, machine learning, psychiatry, and their related applications. This project was our collaborative effort on a ML-based prediction and self-diagnosis of epilepsy according to user-input data. Our inspiration came from the fact that epilepsy is one of the most common neurological disease in the world, and diagnosis has been rather complicated and inconvenient for many patients including those elderly people.

Background

Epilepsy, a brain disorder that happens when certain nerve cells in your brain misfire, is the most common cause of seizures. They can affect your behavior or the way you see things around you for a short time. But epilepsy isn’t the only cause of seizures. You can also have a seizure from:

  • High fever, often from an infection like meningitis
  • Not getting enough sleep
  • Low blood sodium (hyponatremia), which you can get from taking diuretics (water pills)
  • Taking certain medications such as certain pain relievers, antidepressants, or medications to help you stop smoking
  • Bleeding in the brain from a head injury
  • Stroke
  • Brain tumor
  • Amphetamines or cocaine
  • Alcohol abuse, during times of withdrawal or extreme intoxication
  • COVID-19 infection

There are about a dozen types of epilepsy, and the type you have plays a role in which kind of seizure you may have. It is a common neurological disorder that people suffer from. That's why we want to focus this topic on our World Wide Wellness Track.

What it does

EEG-derived brain graphs are reliable measures for exploring exercise-induced changes in brain networks (Buchel, 2021 Oct Nature). We use users' recent data and their past medical history with the power of machine learning to collectively generate an individualized EEG streaming chart versus time and a real-time diagnosis report including our treatment suggestions.

How we built it

Our project is mainly divided into two parts: backend and frontend. Stacks including: MATLAB (Data Visualization), Python (TensorFlow, Flask), JavaScript (Node.JS, React.JS, Chart.JS, JSX, etc.), HTML/CSS.

Backend

Model

The backend consists of a pre-trained machine learning model built with TensorFlow. Our model consists of the following layers:

  1. Input layer of dimension (16, 4097, 1), representing a 16-batch of 4097 datapoints recordings of electrical potential data collected from EEG sensor.

  2. Long Short-Term Memory Layer (form of RNN) with 64 neurons

  3. Dropout Layer, which randomly sets inputs to 0 35% of the time, used to prevent overfitting.

  4. Dense Layer, which is a layer of neurons in a neural network that receive inputs from all neurons from the previous layer. In this case, this is our output layer.

  5. Activation Layer, which simply provides an activation function (sigmoid).

The output layer will produce an output between 0 to 1, representing the how confident the model believes a potential epileptic seizure situation. Finally we compile the model with binary entropy loss and ADAM as optimizer.

Training

We use credible EEG dataset from Brown University Epilepsy Database collected from epilepsy seizure patients. We use two sets of data: one set of non-epileptic, eyes-open, one set of epileptic, in-seizure. Each set of EEG dataset consists of 200 recordings, in which each consists one channel of electric voltage data for 4097 datapoints.

We preprocess the data from the text files downloaded from the data source using TQDM library. Then we use SciKit-Learn to shuffle the data and partition it to Train data and Test data.

Finally we train the model with 16 batch size in 20 epochs. The trained model's weights are saved to a HDI5 file so that we can quickly use the model to predict the patient's new EEG data.

API

We use Flask to provide API for the frontend to access.

We provide several route functions for the frontend to access to. The central route function collects the user's information and search for that user's most recent EEG data. The EEG data is put into the model to evaluate the result. The resulting 0-1 floating point number is converted to percentage and displayed on the Dashboard page.

Frontend

We use React.JS as our framework to develop our front end webpage.

We built the registration form and the dashboard to show results after diagnosis using using HTML/CSS/JS. Here, in the dashboard we have integrated chartjs-plugin to visualize the reports.

Challenges we ran into

We tried to use ChartJS-Streaming-Plugin to show the actual brainwave pattern. But the plugin seems to be outdated and we wasn't able to make it work.

Accomplishments that we're proud of

It is our first time using TensorFlow to create a backend machine learning model and make it useful to frontend user. Using the theory of machine learning and applying it to help real patients who need help is rewarding. It is a full-stack development experience that we value.

What we learned

We learned the usage of TensorFlow, React.JS framework, Flask, and server-client communication knowledge. We also did a direct comparison of the credible EEG statistics from research literature by employing MATLAB plot and analysis functions, which provided a even more straightforward visualization of the difference in EEG trends among epilepsy patients and normal people.

What's next for AI Brainwave Seizure Detection

  1. Since we don't have the actual hardware of EEG electrodes and boards and real patients to access, we are not able to connect our software to real patients. However, we can proceed by connecting the actual BCI boards like OpenBCI Cyton to real patients.

  2. We can setup cloud service for the patients to upload their EEG data themselves. We can monitor their EEG data performance and warn them if a potential seizure is likely. Many lives would be saved if their seizure are discovered earlier.

  3. Chatbot feature is not fully implemented. We want to make it an AI helper based on NLP models that help with the patient exploring information and medical advices on epilepsy.

References

https://www.webmd.com/epilepsy/types-of-seizures-their-symptoms#:~:text=There%20are%20six%20kinds%20of,shakes%2C%20and%20you%20lose%20consciousness

NeurotechX Deep Learning Workshops

Built With

Share this project:

Updates