Using Wavenet for EEG seizure detection

Ward Van Laer
Jan 23, 2019 · 4 min read

Approximately 50 million people worldwide have epilepsy, making it one of the most common neurological diseases globally. In one of our recent projects for the Ghent University Hospital, we had to tackle the problem of detecting epileptic seizures in EEG signal recordings of rats and mice.

In almost all existing machine learning projects and papers on EEG seizure detection, the aim is solving the challenge of classifying short segments of EEG signals (e.g. this Kaggle competition). In our project, we go one step further: every sample of the EEG signal needs to be classified, resulting in the exact start and end times of seizures. These annotations provide valuable insights and can be used to measure the effectiveness of a medical treatment.

The WaveNet Architecture

Wavenet is a deep learning architecture developed by Google DeepMind in 2015. It is, until this moment, the go-to architecture for text-to-speech creation. By using such a deep learning model, the created speech sounds far more natural than speech created by a parametric TTS model. I recommend having a look at (and a listen to) the examples. Important to notice is that by using their proposed techniques, it is possible to learn from raw signal data in a fast manner.

The magic ingredient to make this possible is the use of dilated convolutions. By increasing the dilation factor of each convolutional layer, its receptive field can grow exponentially. Blocks consisting of various layers are then stacked and combined to form the output. This way, it is possible to construct speech signals one sample at a time.

Dilated convolutions in the WaveNet Architecture

Instead of using the WaveNet structure in a causal way, we use an adopted architecture to output one prediction sample for every input sample in one run. This output is scaled using the Softmax function between 0 and 1 (inter-seizure vs in-seizure samples). Our final model uses 3 or 4 EEG input channels and consists of 70 convolutional layers. This is the architecture we used:

The adapted WaveNet architecture

Postprocessing using an adopted Hidden Markov Model

The output of the Wavenet model can be interpreted as the probabillity of “the animal having a seizure at time t”. Converting this output to actual seizure start and end times, can be done in numerous ways, e.g. by fixing a simple threshold. However, such a simple approach will generate lots of small false-positive peaks which generate incorrect seizure-timings.

Our proposed solution uses an adaptation of the Hidden Markov Model as a probabilistic postprocessing engine. The model consists of only two states, namely the ictal and interictal phase (i.e. in-seizure and between-seizure). The emissions of the HMM are the output samples of the WaveNet model. All transition and emission probabilities can be estimated after training the model using a testset. Intuitively this means that for an animal with a high seizure ratio, the transition probability going from interictal to ictal will be high.

Given the emission samples of an HMM model, it is possible to calculate the most probable state sequence using the Viterbi algorithm. After calculating all transition and emission probabilities on test data, this algorithm makes it possible to compute the start and end times of seizures given the output of the trained WaveNet.

The need for consistent training data

Reviewing the output of the model, it became clear that defining what exactly defines an epileptic seizures needs to be standardized and agreed upon between the observers. This includes a definition of exact start and end times and minimum seizure length. By reducing this inter-observer variance, the model can learn from consistently annotated data. The use of the HMM as postprocessing step makes it possible to add extra parameters like minimum seizure length by conditioning the transition probabilities.

At IxorThink, the machine learning practice of Ixor, we are constantly trying to improve our methods to create state-of-the-art solutions. As a software-company we can provide stable products from proof-of-concept to deployment. Feel free to contact us for more information.

IxorThink

IxorThink is the AI and Machine Learning practice of Ixor…

Medium is an open platform where 170 million readers come to find insightful and dynamic thinking. Here, expert and undiscovered voices alike dive into the heart of any topic and bring new ideas to the surface. Learn more

Follow the writers, publications, and topics that matter to you, and you’ll see them on your homepage and in your inbox. Explore

If you have a story to tell, knowledge to share, or a perspective to offer — welcome home. It’s easy and free to post your thinking on any topic. Write on Medium

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store