Research on epileptic EEG recognition based on improved residual networks of 1-D CNN and indRNN

Background Epilepsy is one of the diseases of the nervous system, which has a large population in the world. Traditional diagnosis methods mostly depended on the professional neurologists’ reading of the electroencephalogram (EEG), which was time-consuming, inefficient, and subjective. In recent years, automatic epilepsy diagnosis of EEG by deep learning had attracted more and more attention. But the potential of deep neural networks in seizure detection had not been fully developed. Methods In this article, we used a one-dimensional convolutional neural network (1-D CNN) to replace the residual network architecture’s traditional convolutional neural network (CNN). Moreover, we combined the Independent recurrent neural network (indRNN) and CNN to form a new residual network architecture-independent convolutional recurrent neural network (RCNN). Our model can achieve an automatic diagnosis of epilepsy EEG. Firstly, the important features of EEG were learned by using the residual network architecture of 1-D CNN. Then the relationship between the sequences were learned by using the recurrent neural network. Finally, the model outputted the classification results. Results On the small sample data sets of Bonn University, our method was superior to the baseline methods and achieved 100% classification accuracy, 100% classification specificity. For the noisy real-world data, our method also exhibited powerful performance. Conclusion The model we proposed can quickly and accurately identify the different periods of EEG in an ideal condition and the real-world condition. The model can provide automatic detection capabilities for clinical epilepsy EEG detection. We hoped to provide a positive significance for the prediction of epileptic seizures EEG.

the health of patients but also brought great mental pressures [2,3]. The development of EEG provided a non-invasive, low-cost, and effective technology that can be used in clinical trials to detect cerebral cortex brain activity and related diseases [4][5][6]. A large number of studies have shown that epilepsy EEG was significantly different from normal EEG. The brain activities of patients with epilepsy usually included the interictal and the ictal period [7]. When brain activities change from one state to another, the EEG signal will change obviously. Therefore, EEG is an important basis for the clinical diagnosis of epilepsy.
The professional neurologists'reading of EEG is the main method to determine epilepsy [8]. However, it is complex and time-consuming to observe and detect long-range EEG signals by people. The heavy workload can easily cause fatigue of medical personnel and lead to inaccurate manual detection. Moreover, we often make a judgment only through professional experience. So, an automatic detection and classification model of EEG become more and more urgent and important.
In recent years, some significant progress has been made in the diagnosis of epileptic diseases and the detection of seizures based on Electroencephalogram (EEG). Nonlinear dynamics, machine learning, deep learning and other technologies have also been applied to the research of epileptic diseases, and good results have been achieved. The recurrent neural network(RNN) [9] and the CNN [10] are the research hotpots in recent years. The former focuses on the context of time series, and the latter focuses more on EEG feature extraction. Unlike traditional small-dose calculation research, deep neural networks are focused more on big data research. However, there are still some problems that cannot be solved at this stage.
The main contributions of our work are as follows: a new neural network architecture, which was the recurrent convolution neural network(RCNN), was proposed by combining the advantages of the recurrent neural networks and the convolutional neural networks. This new architecture used the one-dimensional convolutional neural network to extract the features of the original EEG, then used the independent recurrent neural network to learn the relationship between time series, and finally realized the automatic diagnosis of epileptic EEG by classification function. We used the Bonn University data sets and our private data sets for training and testing. In order to avoid the individual specificity in the epilepsy diagnosis algorithm, we ensured that the data sets used in the experiment were from different individuals, and compared with the relevant frontier research. Our method had generally achieved good results. In the binary classification task, even 100% of results are obtained in accuracy and specificity. These results indicated that the new architecture we proposed can effectively realize the automatic detection of epilepsy EEG.

Models of convolutional neural network
Convolutional neural network (CNN) is a type of feedforward neural network that includes convolution operations and has a deep structure. The characteristics of it are local perception and parameter sharing, which is one of the hottest research points in the field of image processing [11]. A complete CNN contains a convolution layer, a down-sampling layer, and a fully connected layer [12], as shown in Fig. 1. The convolution layer can enhance certain features of the original EEG signal through convolution operations and reduce the impact of noise; The downsampled layer, which is often referred to as the pooling operation, can reduce the amount of data processing while retaining useful Information; the fully connected layer gets the image features extracted by the neural network. And the full connection layer outputs the final result through the function "softmax" in Fig. 1. Figure 2 shows a common frame diagram of epilepsy prediction system based on convolutional neural network. The key of the system lies in the reconstruction of the original EEG data, that is, the reconstruction of the input image. In the existing methods, one-dimensional, two-dimensional and three-dimensional EEG are reconstructed according to the dimension of convolution operation [13][14][15][16][17]. The latest seizure prediction studies which use CNN in recent years, use convolution features of different dimensions to build models. Convolutional neural network often uses reconstructed image processing in the prediction of seizures. With the changes of EEG data dimension, important information may be lost. The existence of the pooling layer will also lead to the loss of many very valuable information. And it will also ignore the relationship between the whole and the part.
Therefore, the research based on convolution model need to be improved.

Models of recurrent neural network
Recurrent neural networks (RNN) have achieved great success and are widely used in the field of time series analysis [18], for example, the natural language processing. The recurrent neural network includes an input layer, a hidden layer and an output layer. Figure 3 shows a complete recurrent neural network structure. Among them, x is the input data; s is the memory of the sample at time t, that is, the hidden layer; o is the output sample, and U and V are the weight of the input and output samples. Different from the traditional feedforward feedback neural network, RNN introduces a directional loop, as shown in the right part of Fig. 3. The output of time t is related to the previous time as well as the current time. RNN can deal with the problem of correlation between inputs, especially the EEG time series analysis.
Different from the EEG analysis of convolutional neural network, the original EEG data does not need to  be reconstructed, and RNN can directly process EEG sequence, which ensures the maximum information retention of EEG. CNN has obvious advantages, but there are still shortcomings, and the situation of RNN is similar. Because the parameters of each recurrent layer network are shared, as the depth of the layer increases, the RNN will have the problem of gradient explosion or gradient disappearance. In order to solve these problems, some variant RNNs, such as GRU [19], LSTM [20], bi-LSTM [21] and many more are used in the study of seizure prediction [22][23][24].

Models of recurrent convolution neural network
We listed the researches of CNN and RNN in epileptic seizure. CNN has better spatial information capturing ability, while RNN is better at analyzing the relationship between time series. We know that EEG collected from the clinic is not only the cumulative of time, but also the interaction between different leads. And the spatial relationships between brain network nodes are equally important. Considering the different advantages of CNN and RNN, a new architecture idea is applied to EEG analysis. Figure 4 shows a CNN and RNN recurrent convolutional neural network seizure detection system. The basic idea is that under the movement of a fixed time sliding window, the CNN network learns the spatial features between the sequences and extracts them. And the network inputs them into the recurrent neural network according to the time sequence. Finally, the classification results are given through the time relationship between RNN learning sequences.
The research based on this new architecture has not been carried out sufficiently. Ahmedt David et al. [25] proposed a simple end-to-end architecture based on convolution and recurrent neural networks, which extracted spatiotemporal representations from 119 epileptic seizure databases of 28 patients. Subsequently, the cosine similarity distance between the test representation and the library of five abnormal seizures separated from the test data set was used to identify seizure tests with abnormal patterns that did not conform to known behaviors. The motion features extracted based on clinical image data were used for seizure detection to provide more possibilities for the diagnosis of epilepsy diseases. Although this framework did not use EEG data, it was possible for multimodal research to predict seizures based on EEG and Surveillance Video.
Meysam et al. [26] proposed a seizure detection model of convolution and long-short-term memory recurrent neural network based on clinical detection of EEG. This model can input the convolution features of the multichannel EEG data of the reconstructed two-dimensional pictures into the relationships between the learning sequences in the LSTM, and finally output the classification results. XY Wei et al. [27] proposed a similar study, but the difference was the image reconstruction. In this paper, the team converted the EEG time series into twodimensional EEG, and then fused multi-channel into three-dimensional structure. A feasible method, longterm recursive convolutional network (LRCN), was proposed to implement an end-to-end automatic prediction model for seizures.
Convolutional network blocks are used to automatically extract depth features from data. The LRCN combined the LSTM neural network block to distinguish different image sequences and identified the front segment from the streaming data. The model was tested with independent data and provided a higher sensitivity of seizure prediction and a low false prediction rate of 0.04 FP/h than the method manually designed in previous studies and a single deep neural network. This reconstruction of the external structure was an important point of our researches, but some teams considered the combination of two networks within the neural network. The team of Li Feifei [28] proposed an E3D-LSTM network with strong memory. 3D convolution was used instead of 2D convolution as the basic calculation operation of LSTM network, and a self-attention mechanism was added to enable the network to take into account both long-term and short-term information dependence and local spatiotemporal feature extraction. This provided new ideas for video prediction, motion classification and other related issues, and was a very enlightening work.

Public dataset
The public data set used in this experiment is from the EEG data set of the University of Berne [29]. This data set has been preprocessed into EEG under ideal conditions and is widely used. The database contains five groups, each group of 100 time series, each time series length is 23.6 s. Groups A and B are from the resting state of healthy volunteers, Groups C, D, and E all come from patients' EEG. The difference is that the time of epileptic seizure is recorded in Group E, while there is no seizure in the other two groups during the whole recording period.

Private dataset
The private data set for this experiment came from the Department of Neurology at the First Affiliated Hospital of Xinjiang Medical University and the First Affiliated Hospital of Sun Yat-Sen University from 2013 to 2016. There were 15 patients with epilepsy (5 males and 10 females, aged 6-51 years). Scalp electrodes are placed according to the international 10-20 system. The sampling frequency is 500 Hz. The total duration of available EEG recordings is approximately 540 h. The onset and offset time intervals are manually annotated by clinical experts after visual inspection, for a total of 168 episodes. According to the requirements of experimental design and the definition of stages, EEG is classified into interictal period, preictal period, and ictal period. The information about the EEG data set is shown in Table 1.

Definitions of different periods
The seizure process is divided into four states, including interictal, preictal, ictal, postictal [30][31][32], as shown in Fig. 5. Clinical experts have marked the starting and ending points of seizures in the data. In order to predict future seizures, the key of the epileptic seizure prediction system is to separate preictal from the interictal period. Preictal is defined as the data segment before the ictal (or seizure) cycle, which can be clearly identified from the EEG signal. However, different studies have different definitions of the length of preictal, ranging from 10 to 60 min [33]. In addition, each patient data contains at least two seizures in this study, but the interval between the two seizures can be long or short. Through the work of different studies, the best pre-onset period is now defined as 30 min before the onset. For seizures less than 30 min from the previous seizure, we think they are only one seizure.
Interictal is defined as the part of the signal that is neither ictal nor preictal. In our experiment, the data of at least 1 h after seizure and at least 40 min after seizure were defined as the interictal period through literature review. In this paper, the data of 30 min in the 35 min before each attack is used as the pre-onset data to maintain the balance of the positive and negative samples in the data sample set.

System framework of RCNN
In this study, the residual network architecture was combined with the recurrent neural network, and 1-D CNN was used to replace the two-dimensional convolution (2-D CNN) operation in the residual structure. The purpose of this was to establish a spatiotemporal deep learning model for epileptic seizure detection. 1-DCNN was used to automatically extract signal features from the original EEG, and the indRNN neural network was used to distinguish different categories based on the extracted features. The construction process of the epilepsy EEG automatic detection model in this paper is shown in Fig. 6. The model ran on a high-performance computer with Python 3.
In this study, the indRNN network was combined with the previously proposed convolutional neural network to create a spatiotemporal deep learning model for seizure detection. The traditional convolutional neural network processed the input data by convolution and pooling operations, and then inputted into the fully connected layer to output the results.
The input layer of our model was connected with a complete residual convolution neural network. The unreconstructed EEG signal was inputted into the convolutional neural network to output a transformed fixed-length feature vector. Multiple consecutive outputs formed a feature sequence, which is then input to indRNN. indRNN mapped the input to the hidden layer, updated the hidden layer, and finally outputted the predicted distribution result at time step t, and used softmax to determine the category. In this process, indRNN learned the changes of abstract features of EEG, and the output results determined the current EEG segment through the classification function, and then made a judgment.

Independent residual network architecture
Independent residual network architecture shown in the Table 2.
Residual network CNN can extract the features of low/mid/high-level. The more layers of the network, the richer the features of different levels can be extracted  [34]. Moreover, the deeper the network is, the more abstract the features are and the more semantic information they have. If the layers behind the deep network are identity maps, then the model degenerates into a shallow network. After years of development, residual network has great advantages for deep-seated network learning. The residual architecture [35] used in this experiment is a convolutional network of three residual blocks, as shown in the Fig. 7 is the structure diagram of the first residual block, the stitching of the second residual block is the same as the first, the third as shown on the right, it is slightly different.
Independent recurrent neural network The recurrent neural network has been widely used in sequence learning problems such as action recognition, scene annotation, language processing, and has achieved remarkable results. Compared with feed-forward networks such as CNN, RNN has a cyclic connection, in which the last hidden state is the input to the next state. The training of RNN is faced with the problems of gradient vanishing and gradient explosion due to the multiplication of cyclic weight matrices. Therefore, it is actually difficult to construct and train deep LSTM or GRU based on RNN. Each neuron in IndRNN independently processes a type of spatiotemporal model [22]. Traditionally, RNN is regarded as a multi-layer perceptron with shared parameters in time. Different from the traditional RNN, the IndRNN neural network was used in this paper provides a new perspective for the recurrent neural network, that is, the spatial patterns are aggregated independently over time. The correlation between different neurons can be used by stacking two or more layers. In this case, each neuron in the next layer processes the output of all neurons in the previous layer which can solve the problems of gradient disappearance and gradient explosion.
Network configuration Our identification network was trained to global optimization by using "SGD" as the optimization function and "categorical_crossentropy" as  the loss function. Stochastic Gradient Descent (SGD) was used to train various machine learning and deep learning models because of its fast learning speed and online updating. 2-D CNN in the residual network was used to replace by 1-D CNN, which can directly process the original EEG data without preprocessing the EEG dimension. The parameters of the convolution unit were selected as: the length of convolution kernel was (8,5,3) and the number of convolution kernels was (64, 128, 128), the activation function was "LeakyReLU". The convolution part was mainly to capture the short-term time correlation of EEG data; the part of circulating unit network was mainly used to distinguish EEG categories. With the increase of network depth, the gradient disappearance and gradient explosion problems of the recurrent network became more and more serious. In this experiment, the independent recurrent neural network was selected, and the number of neurons was set to 128. Finally, we used "Dense" to output the classification results, and selected the function "softmax" as the activation function. The batch size was set to 64, and the number of iterations was set to 512. We compared the public data set with the private data set, and various noise levels in the experiment are fully considered.

Results and discussion
In this section, we mainly tested the epilepsy detection performance on public data sets with ideal conditions and real data sets with clinical trials. The sensitivity (Sens), specificity (Spec) and classification accuracy (Acc) of evaluation indicators were evaluated. The details will be described in the following paragraph.

Experimental design
The difference between public data sets under ideal conditions and clinical experimental data sets was artifacts and noise, which will affect the detection results. We first tested on public data sets, and then tested on real data sets for comparison.

Model training and testing
Epilepsy EEG classification research is the correct identification of EEG signal fragments, and the recognition of the epilepsy different periods which have already been defined. Figure 8 showed the training and testing of our experimental model. In this experiment, the open dataset contained three different kinds of EEG, which are the healthy people group, the epilepsy patients without seizure group and the epilepsy patients with seizure group. Therefore, according to the contrast principle, we designed two classification and three classification tasks to detect the performance of the algorithm. The experimental design of the two-class task was the EEG recognition of the healthy people group and the epilepsy patient group; the experimental design of the three-class task was the healthy people group and the non-seizure group and the seizure group.
In addition to the public dataset, our experiments took into account noise and interference in the real world, and selected specific types of epilepsy patients with interictal, preictal and ictal EEG for testing. Real data has the characteristics of streaming data. So in our experiments, we formalized it as windowed streaming data. Each 10s EEG segment was identified and the EEG category was output. Because this experiment does not involve the task of prediction, our EEG classification recognition only takes the time window, and discards the event classification task.
Ten folds cross-validation was used in this study. First, EEG signals were randomly divided into 10 equal parts. Nine out of ten EEG signals were used to train the neural network in this paper, and the remaining one-tenth were used to test the performance of the system. By moving the test and training data sets, the strategy was repeated ten times. The accuracy, sensitivity and specificity values reported in this paper are the average values obtained from ten evaluations.

Evaluation indicators
There are three most important and commonly used parameters to evaluate the performance of epileptic detection methods: sensitivity (Sen), specificity (Spe) and classification accuracy (Acc). Sen indicates the sensitivity of the recognition system, that is to say, it measures the ability of the classifier to capture EEG data. Spec indicates that the recognition system can correctly recognize the different periods EEG data, that is to say, it measures the classifier's recognition ability for the different periods seizure. Acc indicates the recognition capability of the recognition system. In this article, sensitivity and specificity are equally important for the evaluation of our model. Sensitivity can reflect the missed diagnosis rate of our model, and specificity can reflect the misdiagnosis rate of our model. In our experiments, we did not pursue high specificity at the cost of sensitivity. On the contrary, we hope that we can find a balance between sensitivity and specificity. The specific formula is as follows:

Detection of epilepsy under ideal conditions
We first checked the proposed deep learning method by using the EEG signal without artifacts and noise. After EEG preprocessing (data segmentation and shaping), EEG would be fed into our deep neural network model, and its ultimate goal was to effectively learn EEG features and classify correctly.

Two-class detection task results
In the task of classification of epileptic EEG, the first category was to distinguish the normal EEG of healthy people and the epileptic EEG of epileptic patients. In our public dataset, it belonged to the classification between datasets (A, B) and datasets (C, D, E). However, some scholars believe that the non-epileptic interictal EEG should also be regarded as normal EEG in clinical practice. In our experiment, we mainly identified non-epileptic active EEG (datasets A, B and C, D) and epileptic seizure active EEG (dataset E).
Considering that each dataset has 100 signals, there is a class imbalance problem in our classification task. Based on these considerations, on the one hand, we considered data expansion, on the other hand, we selected non-epileptic EEG randomly in our experiment. In addition, in our evaluation indicators, we no longer simply relied on specificity, the sensitivity and accuracy were also our concerns. The data in the Table 3 showed that the epilepsy EEG recognition model based on 1-DCNN and indRNN can effectively identify the disease. Regarding the identification experiment results of the two-class task, both Acc and Spec achieved 100%, which was the best performance in the baseline algorithms.

Three-class detection task results
Non-epileptic EEG can be divided into normal EEG and interictal EEG, so we have made a three-class classification task. The three-class classification task was mainly to distinguish different brain electrical activities: normal, interictal and ictal. In addition to the automatic diagnosis of patients, the three-class model can also detect the symptoms of epilepsy patients. Such a model was more meaningful. Table 4 showed the results under our evaluation indicators. As shown in the Table 4, our algorithm achieves the best results in terms of specificity, sensitivity and accuracy in the baseline algorithm.

Detection epilepsy under real conditions
There are noise and interference in the real world data, such as muscle activity, eye movement interference and environmental noise. The model's performance in the real world can bring a real significance to clinical practice. Considering these, our experiment collected EEG data of 15 patients in a clinical environment, which were divided into interictal period, preictal period and ictal period according to the existing definition of epilepsy stage.

Two-class detection task results
For patients in the real world, it is more meaningful to predict the onset of seizures. The premise of accurately predicting seizures is the accurate recognition of EEG in the pre-seizure period. Different from the dichotomous experiment under the ideal condition, we no longer pay attention to non-epileptic activity EEG and seizure activity EEG. We are more concerned about the difference between preictal EEG and ictal EEG. We used 15 patients with pre-onset and onset EEG for the experiment and the results were shown in Table 5. Epilepsy was the manifestation of the disease, the real-world data have interference, the corresponding results have been reduced, but still in the baseline method is the best.

Three-class detection task results
The definition of the epilepsy periods has been introduced above, which are interictal, preictal and ictal. On the basis of the two-class classification model, the task of interictal EEG recognition was added. Recognition of preictal can provide a reference for seizure prediction model, and recognition of the interictal period has a positive effect on reducing the false alarm rate of epileptic seizure prediction. Table 6 showed the results of three classification experiments. Our method is still the best among the baseline methods.

Comparison of research results of the same category
In addition to the comparison with the baseline method mentioned above, we also compared the results of similar studies in recent years, as shown in Table 7. For the private data used in this experiment, the dataset in the same category study is already a variable, so it is not considered in this comparison. We have collected result from those studies based on the University of Bourne data set over the past five years, including two classifications and three classifications. From the evaluation index of the model, our research had achieved outstanding specificity, sensitivity and accuracy. Only in the three classification problems, the sensitivity of our algorithm was lower than that of Behara et al. [36]

Conclusions
The professional neurologists' reading of EEG is the main method to determine epilepsy. However, it is complex and time-consuming to observe and detect long-range EEG signals by people. Most of the current researches on EEG diagnosis of epilepsy use single-lead data, and the researches on multi-lead and full-lead data need to be further improved. In this paper, we propose the RCNN model to achieve the automatic diagnosis task of epilepsy EEG, and achieve the automatic labeling of different stages of epilepsy EEG.Our research describes a new method of automatic detection of epilepsy that can directly process the original EEG. In the framework of the traditional residual network, we used the one-dimensional convolutional neural network to replace it, and combined independent convolution recurrent neural network to form a new recurrent residual network to realize the automatic diagnosis of epileptic EEG. Firstly, we used the residual network architecture of the one-dimensional convolutional neural network to learn important features of EEG, and then the recurrent neural network was used to learn the relationship between sequences. Finally, the classification results were output. Our research demonstrated the potential of deep learning in epilepsy detection and seizure prediction, and the possibility of combining convolutional neural networks with recurrent neural networks. It is hoped that this study can promote the further development of epileptic seizure prediction system.