Epileptic Seizure Detection on an Ultra-Low-Power Embedded RISC-V Processor Using a Convolutional Neural Network

The treatment of refractory epilepsy via closed-loop implantable devices that act on seizures either by drug release or electrostimulation is a highly attractive option. For such implantable medical devices, efficient and low energy consumption, small size, and efficient processing architectures are essential. To meet these requirements, epileptic seizure detection by analysis and classification of brain signals with a convolutional neural network (CNN) is an attractive approach. This work presents a CNN for epileptic seizure detection capable of running on an ultra-low-power microprocessor. The CNN is implemented and optimized in MATLAB. In addition, the CNN is also implemented on a GAP8 microprocessor with RISC-V architecture. The training, optimization, and evaluation of the proposed CNN are based on the CHB-MIT dataset. The CNN reaches a median sensitivity of 90% and a very high specificity over 99% corresponding to a median false positive rate of 6.8 s per hour. After implementation of the CNN on the microcontroller, a sensitivity of 85% is reached. The classification of 1 s of EEG data takes t=35 ms and consumes an average power of P≈140 μW. The proposed detector outperforms related approaches in terms of power consumption by a factor of 6. The universal applicability of the proposed CNN based detector is verified with recording of epileptic rats. This results enable the design of future medical devices for epilepsy treatment.


Introduction
With about 1% of the population affected, epilepsy is one of the most common neurological diseases globally [1].Epilepsy requires ongoing medical attention and is associated with a decrease in the patients' quality of life and higher mortality rates [2,3].Every year in the USA alone, the direct medical expenses including lost or reduced earnings associated with epilepsy are estimated to be $15.5 billion [4].Despite ongoing research and development of new AEDs [5,6], the most common treatment in form of systemic administration of anti-epileptic drugs (AEDs) does not achieve sufficient long-term seizure suppression in ~30% of the patients.Therefore, alternative treatment methods to refractory epilepsy such as intracranial drug delivery [7] or neurostimulation [8] have been suggested.The pinnacle of development would be an implantable closed-loop system for on-demand intervention during ictal periods, which have to be identified sufficiently fast through an automated seizure classification system.
Since the beginning of research on automated classification of epileptic seizures in the 1970s, several algorithms to detect seizures have been developed [9,10].The challenge in classical approaches of seizure detection is developing a model that is capable of dealing with the changing characteristics of seizures within the same subject.The different approaches rely on feature extraction coupled with a classification strategy.These features are for example wavelet-based filters, frequency band and spectral analysis, the slope, height, and duration characteristics of a seizure or cross-channel correlations [10].Recently, with a view at hardware efficiency in order to enable implantable systems, convolutional neural networks have been analyzed for seizure detection algorithms.Lawhern et al. [11] showed with EEGNet that state-of-the-art seizure classification and interpretation is possible with a compact convolutional neural network.A CNN optimized for ultra-low power requirements was introduced in [12].The detector, called SeizureNet, reaches a median sensitivity of 0.96 long-term for invasive intracranial EEG recordings.The efficiency of epileptic seizure prediction based on deep learning is analyzed and compared in [13,14].
Biomedical implantable and wearable devices are usually limited by size and energy restrictions.To meet the devices' high energy efficiency requirements and form factor budget, many functions are incorporated into the device by application-specific integrated circuits (ASICs) [15,16].Applying this concept, several applications have been developed successfully, going far beyond standard applications like pacemakers and hearing aids.A very small and lightweight bioelectric recording system for flying insects has been shown in [17].An implantable cortical microstimulator for Brain-Computer Interfaces was realized in [18].Benabi et al. [19] demonstrated that a tetraplegic patient can control an exoskeleton by an implanted epidural wireless brain-machine interface.In [15,16], it has been shown that an electronic system can be miniaturized to such an extent that even neural recording from neonatal mice to monitor growing processes of the brain can be feasible.The integration of digital logic into systems with low-power microcontrollers based on RISC-V architecture is promising to further advance this field of research.The RISC-V architecture is based on the reduced instruction set computer principles introduced by the University of Berkeley, California.It is available under an open source license and thus, unlike most other microcontrollers, free to use.
In this paper, an epileptic seizure detector suitable for ultra-low-power RISC-V embedded processors and based on a CNN is presented.The implementation, training, and verification of the CNN is performed in MATLAB using the open source CHB-MIT dataset.The main requirement for the detection algorithm is the feasibility for an ultra-low-power hardware implementation.At the same time the detection algorithm has to achieve stateof-the-art detection performance.Low-power and low-complexity architectures call for dimensionality reduction and small memory usage.A multi-channel EEG is a high dimensional dataset and memory usage is thus a challenge.In this work, a CNN fulfilling the low-power and low-complexity requirements is presented.It consists of only a few layers and a manageable number of weights, thus fulfilling low memory requirements.
The paper is structured as follows.Section 2 presents the dataset and Section 3 the microcontroller hardware.In Section 4, the CNN architecture and its training and implementation in Matlab are presented.The implementation of the classifier on a RISC-V-based embedded microcontroller is presented in Section 4.4.The transferability of the proposed detector and its functionality is cross-validated and proven with EEG data from a rodent absence epilepsy model (Genetic Absence Epilepsy Rats from Strasbourg (GAERS)) in Section 4.5.In Section 4.6, the capability of the developed classifier to predict epileptic seizures is demonstrated.Section 5 presents the measurements and results of the performane of the detector for each of the presented chapters.The performance of the classifier is compared with similar state-of-the-art approaches in Section 6.

Dataset
In this work the open source CHB-MIT dataset, collected at the Children's Hospital Boston, is used [20,21].It contains continuous scalp EEG recordings from 24 children with intractable seizures, which have been labeled by medical professionals.The type of epilepsy is not specified in [20,21].However, this does not limit the performance of classification, as our network is independent of specific epilepsy types, but instead is trained patient specifically.The EEG sampling frequency for all patients was 256 Hz.
Most recordings contain 23 channels with EEG signals.For electrode positioning the international 10-20 system of EEG electrode positions and nomenclature is used.Overall, this dataset contains approximately 865 h of EEG signals with 198 seizures that usually last several seconds.
In addition, the presented algorithm and epilepsy detection method is verified with data from EEG recordings in a rodent model.We have used the Genetic Absence Epilepsy Rat from Strasbourg (GAERS), which represent one of the best established rodent models for generalized epilepsy.The rats show seizures with characteristic "spike and wave discharge" EEG patterns.For this study, male rats between 6 and 9 months were implanted with epidural electrodes.In total recordings with a length of more than 150 h are available.The data set has been made available via open access on the portal IEEE Dataport [22].Experiments were performed in accordance with the German law on animal protection and were approved by the Animal Care and Ethics Committee of the University of Kiel.

Hardware Description
State-of-the-art ultra-low-power microcontrollers allow the execution of complex CNNs complying with real-time, power and size requirements of implantable systems.The microcontroller board chosen for implementing the CNN on hardware is the GAPuino Board developed by GreenWaves Technology [23].The main processing unit is a GAP8, which is a multi-core RISC-V processor derived from the PULP platform.It is optimized through different approaches to run IoT applications on an ultra-low power base, especially CNNs.These approaches include a powerful programmable parallel processing unit, a hardware convolutional engine and an on-chip power management to reduce the component count while maximizing battery power down-conversion efficiency.The board is an Arduino Uno form factor board including several peripheral interfaces necessary for prototyping [24].The open source RISC-V-based processor is chosen to enable complete customization and free use of the processor for implantable systems.In future, it is planed to adapt and optimize the RISC-V hardware, especially the hardware convolutional engine, to the specific needs of biosignal processing.In addition, the RISC-V processor architecture is forecasted to be an important processor architecture in industry and research within the next 5 years with over 60 billion processor cores fabricated [25].

Dataset Preparation
Seizure detection can be modeled as a time-series classification problem that classifies the input data into ictal and inter-ictal parts.The CHB-MIT dataset is used as the input for a convolutional neural network.The EEG files of the dataset are preprocessed as described in detail in the Appendix A. The dataset contains a labeling of epileptic activity into ictal and inter-ictal.This labeled EEG data is used for further analysis.The CNN is trained for each patient individually.The datasets of each patients are processed separately and data from individual patients is not shared between the patients, neither in training or test nor in validation phase.
The holdout-method is used to split the dataset into training, validation, and test set.The ratio between these three parts is 60-20-20.The training set is used to train the neural network.On the basis of the validation set, the model optimizes its weights.The final model will be the model which maximizes the classification performance for the validation set.Consequently, the performance on the validation set is not a good estimation for the performance of unseen data.This problem is solved by using the third split: the data set.The data set is only used the test of the final model.It is therefore a good database to evaluate the performance of the model on unseen, new data.The 60-20-20 split is done in the same manner for the ictal data as well as for the inter-ictal data.
For most patients the files contain recordings of 23 channels.However, for almost every patient adjustments have to be conducted to provide a homogeneous input.Empty channel recordings or strongly alternating amplitudes for single channels have been excluded from the analysis.

Data Structuring
The CNN of the epileptic seizure detector processes time signals with a dedicated and fixed length.The dataset is split into parts with a length of 1 s.These blocks of data are the input for the neural network.The length of 1 s is selected to keep the time period of the runtime of a forward pass low while not losing valuable time-dependent information, which is necessary for real-time sensor and actuator systems [12].The forward pass is the calculation process of traversing through all neurons from first to last layer.The procedure to get these short signal windows is to slide a window with the dimension W = E × (T • f s ) over the data, where E are the number of channels, T is the time length of the window and f s is the sampling frequency.A sampling frequency of f s = 256 Hz and E = 23 channels leads to an input matrix of the size 23 × 256 for T = 1 s.
For the inter-ictal data, the window is sliding with no overlap.As already stated, there is an imbalanced number of ictal and inter-ictal data, which is generally challenging for classifiers [26].Truong et al. [27] propose an approach to solve this problem by generating additional ictal data for training.Similar to the windowing process for the inter-ictal data a window of the dimension 23 × 256 is shifted over the ictal recordings.The difference here is that the window is only shifted by one sample per iteration, compared to 256 samples for non-ictal data.This corresponds to an overlapping of 99.6 %, illustrated in Figure 1.
To exemplify this, a epileptic seizure with a length of 10 s is considered.Without the overlapping techniques, this seizure would be cut into chunks of 1 s length generating 10 seizure events.Using the overlapping technique, 2304 seizures events with a respective length of 1 s (256 samples) are generated.This massive overlapping technique is only used for seizure data in the validation and training set.The test set is cut into samples without overlapping.An EEG signal recorded at the head of a patient is easily corrupted by physiological and non-physiological artifacts such as action potentials from scalp muscle or motion of EEG cables, respectively [20,21].The CHB-MIT dataset is partially corrupted by such artifacts.The recordings, e.g., contain 60 Hz noise, caused by the power supply.This 60 Hz noise differs between channels as well as between patients.To reduce the data processing and thus the hardware requirements, a signal preprocessing is not implemented in this work.It is not known to the authors, and not stated in the description of the dataset, if the dataset contains preprocessed data or if the recording equipment of the dataset performs data preprocessing of any kind.For future implantable systems it is assumed that the amount of distortions is reduced due to internal intracranial recordings compared to external recordings.

CNN Architecture
The architecture of the CNN used in this work is illustrated in Figure 2 and based on the SeizureNet CNN [12].In [12], various architecture elements and functions are analyzed in order to evaluate the runtime and memory requirements for an energy-efficient seizure detecting classifier.This includes layer types like convolutions, dense layers (fully connected layer), pooling layers, and different activation functions.While the network in [12] was evaluated using the "Epilepsiae" dataset, especially the intracranial EEG dataset recorded at the University of Freiburg, our work is based on the CHB-MIT [21] dataset.The CNN in our work is optimized for ultra-low-power and energy consumption for future implantable systems.Training, verification and optimization of the CNN developed and presented in our work is performed in MATLAB using the MATLAB deep learning toolbox.The source code has been made available online under open access license [28] to enable rapid adoption in future research projects.
The implemented model architecture for this work is illustrated in Figure 2. The input is a 23 × 256 matrix.The first layer is a convolutional layer using a kernel with the dimensions 23 × 17.In the first layer, a convolution over all electrodes is chosen.The data from a multi-channel EEG recording are not spatially uncorrelated and with the selected size the kernel size can be reduced effectively.This approach is similar to spatial pattern recognition approaches and was also recommended in [11].By adding a filtering over time, the first layer can efficiently learn spatial-time features.For the first layer, the number of kernels is given by 20 × to provide a sufficient quantity of learnable patterns while keeping the amount of weights to be trained on a low level.By implementing a kernel over all electrodes, the output of the first layer is significantly smaller than the input.This is important when taking the needed memory into account.For all convolutional layers the kernel is sliding over the input with a stride of S = 1.The next three convolutional layers extract key features and reduce the dimensionality of the network.The kernel size for the second layer is 10 × 1 × 5 × 20.For the third and fourth layer it is 10 × 1 × 5 × 10.A rectified linear activation function (ReLu) is used for each layer.The output layer is a 10 × 2 fully connected layer using a sigmoid activation function for each of the ten hidden neurons.As the classification task is to decide between ictal and inter-ictal recordings, each output neuron stands for a class.With a softmax function right at the end of the neural network the probability for the two output classes is calculated.
To reduce the output size for layer 1-2 even further, each convolutional layer is followed by a 1 × 4 max pooling layer with a stride of S = 4.The third convolutional layer is followed by a 1 × 2 max pooling layer with a stride of S = 2.To avoid overfitting, each layer except the output layer also contains a dropout layer with a dropout rate of 20%.The dropout layers are only used during the training phase.

CNN Hardware Implementation
The trained network is implemented on a RISC-V based GAP8 ultra-low-power microprocessor.To make use of its efficiency-increasing hardware convolutional engine and to implement the MATLAB trained CNN on the GAP8, processor optimizations and adjustments have to be made.This includes an adaptation of the network architecture, a transmission of the network architecture from MATLAB to C-Code and a quantization of all parameters including the input matrix.This is necessary, as GAP8 comes, for energy efficiency purposes, without a floating point unit.The quantization performed is an 16-bit Q1.14 fixed point quantization.The quantized parameters on the GAPuino Board are stored in integer form.
In total the CNN has a number of 10.162 trainable parameters and a memory requirement of 62.7 kB for 32-bit floats.The detailed structure, the number of trainable parameters and the required memory size per layer are presented in the Appendix A, Table A2.
To implement the CNN trained in MATLAB on the GAPuino Board the TensorFlow SDK used.The Greenwaves GAP8 SDK only supports quadratic convolutions.As the architecture developed in Matlab includes only non-quadratic kernels (23 × 17, 1 × 5 etc.) the number of layers and the filter dimensions have to be changed.The new architecture is given in Table A2.The network only contains two convolutional layers with a kernel size of 5 × 5 with a stride S = 1 and a fully connected layer of the size 2440 × 2. The Max Pooling layers are reduced to a 2 × 2 pooling with a stride S = 2.

Transferability of the CNN Based Classifier
The transferability of the presented algorithm and epilepsy detection method to classification tasks of the same structure is verified with data from EEG recordings in a rodent model.From the data set, random sample data sets are selected for further analysis.To meet the requirements of rat recordings, the CNN was adopted in such a way that only single channel recordings were used for training.The kernel matrix was adjusted to 1600 instead of 256 to meet the sampling frequency requirement of f s = 1.6 kHz of the rats model recording.This ensures that a time frame with a length of 1 s is analyzed and equivalence to the CHB-MIT dataset is maintained.Measurements and results are presented in Section 5.5.

Seizure Prediction Based on Pre-Ictal Data
From a patient's perspective it would be highly desirable to detect an epileptic seizure before it occurs, instead of a detection during its occurrence.This would allow to issue warnings and take precautionary measures [29].The ability to predict seizures with the developed CNN-based classification model is analyzed.While no clear unified definition of the length of the pre-ictal phase exists, various works define a period of up to 1 h before a seizure onset as pre-ictal [30][31][32].In this section, only EEG data from non-seizure files are used for training, validation, and testing, and the models are trained in MATLAB.The seizure recordings are analyzed for different time periods defined as pre-ictal phases for 19 out of the 20 patients.It is assumed that the prediction quality depends on the length of the pre-ictal phase.If information about the upcoming seizure is available in the pre-ictal phase it can be expected that the prediction quality increases when longer time periods of the pre-ictal phase are taken into consideration by the classifier.The length of the pre-ictal phases are selected as 5, 10, 20, and 30 min.The performance of the prediction and the influence of the length of the pre-ictal phase is analyzed.

Evaluation Metrics
The performance of the CNN is evaluated with three metrics quantifying the quality of the binary classification task:

•
Sensitivity, also called true positive rate (TPR): A measure for the proportion of ictal sequences (positives) that are correctly classified by the model as a seizure.
with TP: true positives, i.e., ictal sequences correctly classified as a seizure; P: positives, i.e., the total number of ictal sequences (positive cases) in the dataset.
• Specificity, also called true negative rate (TNR): Ratio of inter-ictal sequences correctly classified by the model as a non-seizure.
with TN: true negatives, i.e., inter-ictal sequences correctly classified as a non-seizure; N: negatives, i.e., the total number of inter-ictal sequences (negative cases) in the dataset.
As the specificity of the classifier is very high with values of of 0.998 and higher, the specificity is measured in units of false positive rate for better comparability with other works.
• False positive rate (FPR) per hour (fp/h): Number of inter-ictal sequences (with a length of 1 s) wrongly classified by the model as a seizure per hour.The relation between these measures is given by: • AUC-score: Area under receiver operating characteristic (ROC) Curve-Measure of the model's ability to distinguish between the seizure and non-seizure classes.
These metrics ensure a comparability between different patients and results from related work.

MATLAB Classification Results
For each patient, an individual CNN is trained based on a personal dataset.The training phase of the neural network is limited to a length of 25 epochs.This makes the results comparable and provides equal conditions for all patients.All together the training is performed for 20 patients.All evaluation metrics are calculated for each patient separately.
Figures 3 and 4 illustrate the results of the classification in the time domain.The figures show the amplitude of a single channel EEG data in gray and the classification result as a probability in blue.A classified seizure event with a length of 101 s (marked in red) with a high detection probability throughout the event and low probability outside of the event is depicted in Figure 3. Figure 4 shows a classified seizure event with a length of 264 s (marked in red) and a highly fluctuating detection probability (blue).A possible reason for the poor detection probability in the event of Figure 4 could be the high background and low SNR in the signal (grey).
The detection sensitivity of all analyzed patients is shown in Figure 5 for a classification threshold of 0.5.The median sensitivity is 90% with a minimum outlier of 62.5% and a maximum of 100%.In this and the subsequent analysis, the median value instead of the average value is calculated in order to take into account possible outliers due to bad signal quality or corrupted (non-physiological) data in single patient's data sets.The AUC-score is illustrated in Figure 5 showing a high median of 98% with the high quartile reaching 90% and the low quartile 95%.Overall, the sensitivity is the most important metric to evaluate the detection algorithm.Its importance is related to the fact that not detecting a seizure is worse than having a false positive alarm.The AUC is mainly an additional score to compare different neural network architectures since it is independent of the classifier threshold.
The distribution of the false positives per hour, which is according to Equation (3) a measure for the specificity, is shown in Figure 6.The median fp/h rate is 6.8 fp/h.Seventy-five percent of the results show less than 20 false positives per hour.For three patients, the fp/h rate is significantly higher (101, 95, and 65) than it is for the other patients.It is hypothesized and verified with a random sample test that this is due to a lower signal quality and higher noise level for these three patients.The best 5 patients stand out with a maximum of 1.7 fp/h.The minimum is 0.5 fp/h for patient 2.
The detection sensitivity of all analysed patients is shown in Figure 5 for a classifi-298 cation threshold of 0.5.The median sensitivity is 90 % with a minimum outlier of 62.5 % 299 and a maximum of 100 %.In this and the subsequent analysis the median value instead 300 of the average value is calculated in order to take into account possible outliers due to 301 bad signal quality or corrupted (non-physiological) data in single patient's data sets.The AUC-score is illustrated in Figure 5 showing a high median of 98 % with the 303 high quartile reaching 99 % and the low quartile 95 %.Overall, the sensitivity is the most 304 important metric to evaluate the detection algorithm.Its importance is related to the 305 fact that not detecting a seizure is worse than having a false positive alarm.The AUC is   The AUC-score is illustrated in Figure 5 showing a high median of 98 % with the 303 high quartile reaching 99 % and the low quartile 95 %.Overall, the sensitivity is the most 304 important metric to evaluate the detection algorithm.Its importance is related to the 305 fact that not detecting a seizure is worse than having a false positive alarm.The AUC is The distribution of the false positives per hour, which is according to Eq. 3 a 309 measure for the specificity, is shown in Figure 6.The median fp/h rate is 6.8 fp/h.75 % 310 of the results show less than 20 false positives per hour.For three patients the fp/h rate 311 is significantly higher (101, 95 and 65) than it is for the other patients.It is hypothesised 312 and verified with a random sample test that this is due to a lower signal quality and 313 Figure 6.Illustration of the specificity of the classification showing a boxplot (median value (red), lower and upper quartile (blue), min.and max.value (black), outlier (red cross)) of the fp/h for 20 patients.The median fp/h is 6.8, 75 percentile: 19.8, 25 percentile: 1.75.The analysis is done on time signals with a length of 1 s.A false positive rate of 6.8 fp/h corresponds to a specificity of 0.998, this means that 99.8% of inter-ictal time frames of 1 s are classified correctly.

Classification Results for Hardware-Optimized CNN
The sensitivity and specificity for 10 EEG recordings classified in Python using the hardware optimized CNN structure are presented in Figure 7.The median sensitivity is 88.8%, the median specificity is 97.7%.For comparison Figure 8 shows the boxplot of the sensitivity and specificity of the EEG recordings classified in MATLAB.For the 21 analyzed recordings the median values are 83.3% and 99.8% respectively.

Power Consumption
The power consumption of the classification task is measured using a shunt resistor (R = 1 Ω) connected in series with the power supply of the processor of the GAPuino Board.While the processor performs the classification task, the voltage drop at the shunt resistor is measured.Based on the voltage and the value of the resistor, the power consumption is calculated.The measurement setup is depicted in Figure A1.
In order to have a trigger for the energy measurement, a digital I/O port is set to high before the GAP8 kernels are launched and set to low after the classification task is done.The voltage curve while classifying 1 s of EEG data is shown in Figure 9.The time period between on-and offset of the 8 processor kernels is marked by the trigger.The classification task of 1 s of EEG data takes a length of 33.5 ms.The maximum voltage reached is 15.44 mV.The trigger is scaled by a factor of 100 to simplify the representation.The maximum power consumption is 238.4 µW.The average consumption over the classification period is 140 µW.The energy required for one classification task is E = 4.9 µJ.The declared energy consumption is for classifying 1 s of EEG data and only for the GAP8 processor itself.The consumption of the whole board is not measured.

Verification with EEG Recordings in a Rodent Model
The presented algorithm and epilepsy detection method are verified with data from EEG recordings in a rodent model.This exemplified result illustrates, that the developed CNN based seizure detection model is generally applicable and transferable to similarly structured classifications task.The performance of the adoption of the CNN is not evaluated in this work.

Seizure Prediction
For 19 out of the 20 patients, the seizure recordings are analyzed for different time periods defined as pre-ictal phases prior to seizure onset.Figure 11 shows the result of the analysis in the boxplot of fp/h for pre-ictal time periods.For this work the analysis is conducted for the time periods of 30, 20, 10, and 5 min.The classification results show a median false positive rate of 2.15 fp/h for a pre-ictal time period of 30 min, of 1.8 fp/h for 20 min, 3.0 fp/h for 10 min, and 3.9 fp/h for 5 min.While the shortest phase of 5 min shows the worst prediction, a clear trend for an increase in prediction quality for longer periods of pre-ictal phases can be seen.This strengthens the assumption that information about the upcoming seizure is available in the pre-ictal phase and that the prediction quality increases when more information is available or longer time periods are taken into consideration, respectively.ordings from a GAERS rat (grey) with a duration of 470 seconds showing a seizure event (red), nd the output probability of the classification (blue).
phase and that the prediction quality increases when more information is available longer time periods are taken into consideration, respectively.The classification results show a median false positive rate of 2.15 fp/h for a pre-ictal time peri of 30 minutes, of 1.8 fp/h for 20 minutes, 3.0 fp/h for 10 minutes and 3.9 fp/h for 5 minutes.

Comparison with state-of-the-art
A comparison of the overall classification performance of the developed approa with recently published work is shown in Table 1.This comparison contains recent wor that focus on future implantable systems.Thus, the appoaches focus on low hardwa complexity and low power requirement.Although it has to be admitted that it is difficu to compare the performance of classifiers based on classification results from differe databases, it can be stated that all three classifiers show compatible performance.
SeizureNet [12] IntegerNet [26] This work Figure 11.Seizure prediction based on pre-ictal Boxplot (median value (red), lower and upper quartile (blue), min.and max.value (black), outlier (red cross)) of the classification results in fp/h for 19 patients.The time period defined as "pre-ictal" varies from 30, 20, 10 to 5 min.The classification results show a median false positive rate of 2.15 fp/h for a pre-ictal time period of 30 min, of 1.8 fp/h for 20 min, 3.0 fp/h for 10 min and 3.9 fp/h for 5 min.

Comparison with State-of-the-Art
A comparison of the overall classification performance of the developed approach with recently published work is shown in Table 1.This comparison contains recent works that focus on future implantable systems.Thus, the approaches focus on low hardware complexity and low power requirement.Although it has to be admitted that it is difficult to compare the performance of classifiers based on classification results from different databases, it can be stated that all three classifiers show compatible performance.A comparison of the power consumption with measurement results from state-of-theart solutions is shown in Table 2.The average power consumption for a classification is more than 80% smaller than in [12].With respect to energy consumption the presented work achieves a reduction by a factor of 6.9 and higher compared to that in [27], which consumes 34-90 µJ for each classification.The performance of different algorithms to detect epileptic seizures is compared in Table 3, based on the work in [33].In this comparison, hardware requirements are not considered.The analysis are based on different data sets, thus the performance parameters cannot be compared directly.Nevertheless, it can be stated that it is possible to achieve comparable sensitivity and specificity with a variety of algorithms.
Table 3.Comparison of the performance of different algorithms for seizure detection independent of the hardware requirements, based on those in [33].

Conclusions
In this work, an epileptic seizure detection algorithm using a convolutional neural network has been presented, analyzed in MATLAB and implemented on an ultra-lowpower RISC-V processor.In an implementation of the CNN on a RISC-V-based GAPuino microcontroller, a sensitivity of 85% is reached.The classification of 1 s of EEG data requires E = 4.9 µJ, which is suitable for low-power implantable systems.The specificity is higher than 99%.The classification of 1 s of input data takes 35 ms.Thus the low latency required for real-time applications is achieved.The proposed detector reduces the power consumption by the factor of 6 compared to related approaches.This is reached by the adoption of the CNN and by exploiting the hardware convolution engine of the of GAP8 microprocessor, which allows an energy efficient computation of the convolution operator.The CNN presented here is trained individually for each patient.Accordingly, this approach is not limited to a specific type of epilepsy.Instead it is generally applicable for epilepsy with recurring and comparable seizure events.This was confirmed with recordings from a rat model.
The classifiers, codes, and the data from recordings in the rodent model are made available to the public under open access license.This enables easy reuse and rapid adoption of the presented approach for future developments and applications.

Figure 1 .
Figure 1.Sliding window technique [27]: A window with a length of 256 samples/1 s is sliding over seizure data with a step size of S = 1 sample to generate extra seizures for a balanced training set.

Figure 2 .
Figure 2. Schematic depiction of the CNN architecture showing the convolutional layers with their respective input matrix (blue rectangles) and kernels (red rectangles).Input is a 23 × 256 matrix.Between each convolutional layer, a dropout layer and max pooling layer is placed.Output are the two classes ictal and inter-ictal.

Figure 3 .
Figure 3. Single channel EEG data (gray) from a seizure record file of patient 1 showing 101 s of diagnosed seizure (red) with the output probability of the classification (blue).

Figure 4 .
Figure 4. Single channel EEG data (gray) from a seizure record file of patient 8 showing 264 s of diagnosed seizure (red) and the output probability of the classification (blue).

306
mainly an additional score to compare different neural network architectures since it is 307 independent of the classifier threshold.

Figure 6 .Figure 5 .
Figure 6.Illustration of the specificity of the classification showing a boxplot (median value (red), lower and upper quartile (blue), min.and max.value (black), outlier (red cross)) of the fp/h for 20 patients.The median fp/h is 6.8, 75 percentile: 19.8, 25 percentile: 1.75.The analysis is done on time signals with a length of 1 second.A false positive rate of 6.8 fp/h corresponds to a specificity of 0.998, this means that 99.8 % of inter-ictal time frames of 1 second are classified correctly.The distribution of the false positives per hour, which is according to Eq. 3 a

Figure 6 .
Figure 6.Illustration of the specificity of the classification showing a boxplot (median value (red), lower and upper quartile (blue), min.and max.value (black), outlier (red cross)) of the fp/h for 20 patients.The median fp/h is 6.8, 75 percentile: 19.8, 25 percentile: 1.75.The analysis is done on time signals with a length of 1 second.A false positive rate of 6.8 fp/h corresponds to a specificity of 0.998, this means that 99.8 % of inter-ictal time frames of 1 second are classified correctly.

Figure 7 .
Figure 7. Sensitivity and Specificity boxplot (median value (red), lower and upper quartile (blue), min.and max.value (black), outlier (red cross)) for 10 EEG recordings classified in Python with a median sensitivity and specificity of 88.8% and 97.7%, respectively.

Figure 9 .
Figure 9. Measured voltage between TP5 and TP6 to measure the power consumption of GAP8 while classifying 1 s of EEG data (blue), trigger signal indicating the start and the end of the processing of 1 s of EEG data.
Figure 10 shows one channel of the time signal of a recording of an epileptic rat with seizures and the classification result of the algorithm.The gray signal shows the recorded EEG signal in µV.The dashed red line shows the classification target indicating a seizure event with target value one and a non-seizure event with target value low, classified by neurological experts.The blue solid line shows the output probability of the classifier.As shown in the example in Figure 10, the four seizure events are detected by the classifier and the classification results of the CNN match very well with the classification of experts.

Figure 10 .
Figure 10.Single-channel recordings from a GAERS rat (gray) with a duration of 470 s showing a seizure event (red), as diagnosed by an expert, and the output probability of the classification (blue).

Figure 11 .
Figure 11.Seizure prediction based on pre-ictal data.Boxplot (median value (red), lower an upper quartile (blue), min.and max.value (black), outlier (red cross)) of the classification resu in fp/h for 19 patients.The time period defined as 'pre-ictal' varies from 30, 20, 10 to 5 minut The classification results show a median false positive rate of 2.15 fp/h for a pre-ictal time peri of 30 minutes, of 1.8 fp/h for 20 minutes, 3.0 fp/h for 10 minutes and 3.9 fp/h for 5 minutes.

Table 1 .
Comparison of the overall classification performance of the developed approach with published work.

Table 2 .
Comparison of the energy consumption of a classification task for different chips and classifiers while running a seizure classification.