A motor imagery EEG signal classification method based on parallel CNN-Transformer neural network
Through the parallel CNN-Transformer neural network, combined with continuous wavelet transform and multi-feature fusion, the problem of motor imagination EEG signal feature extraction and classification is solved, achieving higher classification accuracy and Kappa value, and overcoming the timing problems in the existing technology. The problem of insufficient information utilization.
Patent Information
- Application Number
- CN202111260895.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-10-28
- Publication Date
- 2024-09-24
- Estimated Expiration
- 2041-10-28
AI Technical Summary
It is difficult for existing technology to effectively extract and classify the rich features of motor imagery EEG signals, especially the temporal information, and it is difficult for deep learning models to have efficient parallel computing capabilities when processing temporal signals.
A method based on parallel CNN-Transformer neural network is used to generate time-frequency feature maps through continuous wavelet transform. CNN extracts frequency and position information, and Transformer extracts time features, and fuses them with multiple features to improve classification accuracy.
It improves the classification accuracy and average Kappa value of motor imagery EEG signals, avoids overfitting, and makes full use of the timing information of EEG signals.
Smart Images

Figure CN113887513B
Abstract
Description
Technical Field
[0001] The invention belongs to the field of signal processing and pattern recognition, and in particular to a motor imagery electroencephalogram signal classification method based on a parallel CNN-Transformer neural network. Background Art
[0002] Brain-computer interface (BCI) controls external devices through the conscious activities of the human brain to achieve communication between the brain and the device. EEG signals are widely used in BCI due to their high temporal resolution, low cost and non-invasiveness. Motor imagery electroencephalogram (MI EEG) is a type of EEG signal that can be generated spontaneously without external stimulation. The nonlinearity, non-stationarity and low signal-to-noise ratio of MI EEG pose great challenges to decoding. The key issues in brain information decoding are feature extraction and classification recognition.
[0003] Time domain and frequency domain analysis methods are common feature extraction methods. It is difficult to fully extract rich EEG features using time domain analysis or frequency domain analysis alone. Researchers have proposed using time-frequency domain analysis methods such as Short Time Fourier Transform (STFT) and Continuous Wavelet Transform (CWT) to describe the characteristics of MI EEG from two dimensions: time and frequency. For time-varying and non-stationary EEG signals, STFT cannot simultaneously obtain high time resolution and frequency resolution. Compared with STFT, CWT has a variable window shape and higher time-frequency resolution. At the same time, CWT can achieve multi-scale expression of different frequency bands of the signal through translation and scaling of wavelet basis functions. The adaptive multi-resolution feature of CWT makes it more suitable for analyzing EEG signals whose frequency changes over time.
[0004] In previous classification and recognition research, deep learning methods have been widely used for EEG signal decoding. Convolutional Neural Networks (CNN) are widely used because of their powerful local feature learning capabilities. However, since EEG signals are essentially time series signals with strong time dependence, CNN cannot fully utilize the temporal information in EEG signals. Researchers introduced recurrent neural networks (RNNs) to process the temporal correlation of EEG signals. The sequential input method used by RNNs makes it difficult for the model to have efficient parallel computing capabilities, and it is difficult for RNNs to establish global dependencies. Recently, Transformers, which have the characteristics of capturing dependencies between long temporal input sequences and parallel computing, have received more and more attention, which provides new ideas for processing the temporal information of MI EEG. Summary of the invention
[0005] In view of the problems existing in the prior art, the present invention proposes a motor imagery EEG signal classification method based on a parallel CNN-Transformer neural network. In the method of the present invention, CWT is first used to obtain a two-dimensional feature map of MI EEG combined with time, frequency and position information. Then CNN extracts the frequency features and position information in the two-dimensional feature map; Transformer extracts the time features in the two-dimensional feature map. Finally, the accuracy of the motor imagery EEG signal classification task is improved by multi-feature fusion.
[0006] In view of this, the technical solution adopted by the present invention is: a motor imagery EEG signal classification method based on a parallel CNN-Transformer neural network, comprising the following steps:
[0007] S1, preprocessing of motor imagery EEG signals;
[0008] S2, adding noise to the preprocessed motor imagery EEG signals to augment the data;
[0009] S3, performing time-frequency analysis on the motor imagery EEG signal processed in step S1 and step S2 to generate a two-dimensional feature map including time features, frequency features and position information;
[0010] S4, building a CNN model, setting network parameters, and extracting frequency features and location information in the two-dimensional feature map;
[0011] S5, build the Transformer model, set the network parameters, and extract the time features in the two-dimensional feature map;
[0012] S6, concatenating the features extracted in step S4 and step S5, and inputting them into the classifier to obtain the motor imagery classification result.
[0013] Specifically, the preprocessing in step S1 is to select an 8-30 Hz bandpass filter to filter the motor imagery EEG signal. The bandpass filter is a Butterworth filter.
[0014] Specifically, the adding of noise in step S2 is adding Gaussian noise for data expansion.
[0015] Specifically, the time-frequency analysis in step S3 selects the continuous wavelet transform whose mother wavelet is the complex Morlet wavelet to perform time-frequency analysis, and respectively analyzes C3, C4, and C5 in the motor imagery EEG signals processed in step S1 and step S2. z The data of the three channels C4 are transformed by continuous wavelet transform to generate a two-dimensional time-frequency diagram, and the two-dimensional time-frequency diagrams of the three channels in each step are combined into a two-dimensional feature diagram containing time, frequency and position information. Specifically, it includes:
[0016] S3-1, C3, C z CWT analysis is performed on the data of the three channels C, C4 with a duration of 4s to generate a two-dimensional time-frequency diagram containing time and frequency. The continuous wavelet transform uses the following formula:
[0017]
[0018] Where CWT(s,τ) represents the continuous wavelet transform output, s represents the scale and s≠0, τ represents the translation factor, yes The complex conjugate function of pass By translation and scaling, <·> represents the inner product, x(t) represents the input sequence, Represents the translation and scaling of the mother wavelet.
[0019] S3-2, intercept the two-dimensional time-frequency diagram of the 8-30 Hz frequency band closely related to the motor imagery EEG signals in the three EEG signal channels respectively, and arrange the intercepted images up and down according to the electrode sequence to form a two-dimensional feature map containing time, frequency and position information.
[0020] Specifically, the CNN model in step S4 includes 3 convolutional layers and 3 maximum pooling layers. The size of each convolution kernel in the convolutional layer is 3×3, the stride is 1 pixel, and the convolutional layer input is padded with 1 pixel. The number of filters in the three convolutional layers is 16, 32, and 64, respectively. A maximum pooling layer is added after each convolutional layer, the size of the first two pooling layers is 2×2, and the size of the last pooling layer is 8×8, and the size and stride of each pooling window are the same.
[0021] Specifically, the Transformer model described in step S5 cuts the two-dimensional feature map obtained in step S3 into non-overlapping input feature sequences according to unit time along the time dimension, and then uses the feature sequence after input encoding and position encoding as the input of the Transformer model; the Transformer includes 3 identical encoder layers stacked together, each layer consists of two sub-layers of a 4-head self-attention layer and a feedforward neural network layer, and the outputs of the two sub-layers are residually connected and layer normalized.
[0022] Specifically, in step S6, the frequency features and position information extracted by CNN in step 4 and the time features extracted by Transformer in step 5 are connected in series as new inputs and input into the fully connected layer for classification.
[0023] The advantages and beneficial effects of the present invention are as follows:
[0024] The present invention provides a parallel CNN-Transformer network model for motor imagery classification. First, the data set is increased by adding noise to avoid overfitting. Secondly, a two-dimensional feature map of MI EEG combined with time, frequency and position information is obtained through CWT, which enriches the characteristics of the network and enhances the feature extraction ability of the network. Then, the CNN model focuses on learning the frequency features and position information extracted by CWT; the Transformer focuses on learning the time features extracted by CWT. The features learned by the two are connected in series as the input of the classifier, which effectively integrates the feature image information and enhances the recognition ability of MI EEG. Finally, compared with the motor imagery classification method with good performance in recent years, the present invention has higher average accuracy and average Kappa value. BRIEF DESCRIPTION OF THE DRAWINGS
[0025] Figure 1 It is a flow chart of the motor imagery EEG signal classification method based on the parallel CNN-Transformer neural network;
[0026] Figure 2 It is a parallel CNN-Transformer neural network framework diagram. DETAILED DESCRIPTION
[0027] The following will describe the technical solutions in the embodiments of the present invention in detail in conjunction with the accompanying drawings in the embodiments of the present invention. The described embodiments are only part of the embodiments of the present invention.
[0028] See also Figure 1 and Figure 2 , the embodiment of the present invention includes the following steps:
[0029] S1, this embodiment uses the EEG signal dataset of the left and right hand motor imagery of the 4th International Brain-Computer Interface Competition in 2008 BCI competition IV dataset 2b. z The EEG signals of the three channels C4, C5, and C6 containing the motor imagery task in the 3-7s time period were filtered with a 8-30Hz bandpass filter using a Butterworth filter.
[0030] S2, add Gaussian noise with a mean of zero and a standard deviation of 0.1 to the original data, expanding the data volume to three times the original data. Increase the data set to avoid overfitting.
[0031] S3, perform time-frequency analysis on the EEG data obtained in step S1 and step S2 to generate a two-dimensional feature map; select the continuous wavelet transform whose mother wavelet is the complex Morlet wavelet (cmor4-4) for time-frequency analysis. The advantage of the complex Morlet wavelet is that it has non-orthogonality and symmetry, and has a good balance and concentration between local transformations in the time domain and the frequency domain. The advantage of CWT is that it can express the characteristic information of EEG signals in the time domain and the frequency domain. The CWT window shape is variable and has higher time-frequency resolution. At the same time, CWT can achieve multi-scale expression of different frequency bands of the signal through translation and scaling of the wavelet basis function. The adaptive multi-resolution feature of CWT makes it more suitable for analyzing EEG signals whose frequency changes over time. The specific steps are as follows:
[0032] S3-1, C3, C z CWT analysis is performed on the data of the three channels C, C4 with a duration of 4s to generate a two-dimensional time-frequency diagram containing time and frequency. The continuous wavelet transform uses the following formula:
[0033]
[0034] Where CWT(s,τ) represents the continuous wavelet transform output, s represents the scale and s≠0, and τ represents the translation factor. yes The complex conjugate function of . Mother wavelet Can be Shift and scale to get. <·> represents the inner product. x(t) represents the input sequence, Represents the translation and scaling of the mother wavelet.
[0035] S3-2, respectively intercept the 8-30Hz frequency band of the three EEG signal channels that are closely related to the motor imagery EEG signal, and arrange the intercepted images up and down according to the electrode sequence to form a 64×64 two-dimensional feature map containing time, frequency and position information. The advantage is that it not only uses the time and frequency features, but also the position information of the EEG signal.
[0036] S4, build a convolutional neural network module, and use the convolutional neural network to extract frequency features and position information from the two-dimensional feature map. The convolutional neural network structure mainly includes 3 convolutional layers and 3 maximum pooling layers. The continuous wavelet transform obtains a two-dimensional feature map of size 64×64 as the network input. The convolution kernel size of each convolutional layer is 3×3, and the stride is 1 pixel. The zero padding method is used for the convolution operation to prevent the loss of boundary information in the feature map. The number of filters in the three convolutional layers is 16, 32, and 64, respectively. A maximum pooling layer is added after each convolutional layer. The kernel size of the first two pooling layers is 2×2, and the kernel size of the last pooling layer is 8×8. The size and stride of each pooling window are the same. Batch Normalization (BN) and ReLU nonlinearity are applied between each convolutional layer and each maximum pooling layer. Before ReLU, BN is used to process the output data of each layer. In order to avoid overfitting, 50% Dropout is added. Finally, the feature map output by the maximum pooling layer is flattened into a one-dimensional feature vector of length 256.
[0037] S5, build the Transformer module, and use the Transformer to extract temporal features from the two-dimensional feature map. The Transformer consists of three identical encoder layers stacked together, each of which consists of two sublayers: a 4-head self-attention layer and a feedforward neural network layer. The outputs of the two sublayers are both residually connected and layer normalized. Figure 2 In the parallel CNN-Transformer neural network framework diagram, Multi-Head Attention, Feed Forward, Add&Norm are self-attention layer, feedforward neural network layer, residual connection and layer normalization respectively.
[0038] First, the two-dimensional feature map is cut into x=[x1,x2,…,x T ] is a non-overlapping input feature sequence, where x T Represents the feature sequence at time T. Then the input sequence is projected to a new sequence of dimension 64 by a learnable linear transformation through the embedding layer. Then the encoded input sequence is positionally encoded, and the dimension of the positional encoding is the same as the input encoding. The positional encoding is given by the following formula. Finally, the feature sequence after the input encoding and the positional encoding are added as the input of the Transformer model.
[0039]
[0040]
[0041] PE(pos,2i) means adding a sin variable to the even position of each vector, and PE(pos,2i+1) means adding a cos variable to the odd position of each vector. pos represents the position index of each sequence data, d model It represents the feature embedding dimension, i represents a dimension of the feature, and the wavelength of sin / cos in different dimensions ranges from 2π to 10000*2π.
[0042] In the self-attention layer, the Transformer's self-attention mechanism calculates the weights of the EEG features of different time slices to find the dependencies between time steps. Specifically, first, the query vector Q, key vector K, and value vector V are obtained through linear transformation at each position of the input sequence. Secondly, Q is dot-multiplied with the key vector K of each time step feature. Then, the calculation result is normalized using the softmax function. Finally, each value vector V is multiplied by the normalized score, and then the weighted sum is calculated, which is the output of the self-attention layer. The outputs of the 4 subspaces corresponding to the 4 self-attention heads are merged together. The multi-head self-attention mechanism is calculated by the following formula.
[0043]
[0044] MultiHead(Q,K,V)=Concat(head1,...,head h )W O
[0045] in
[0046] Among them, Q, K, and V are the abbreviations of query, key, and value respectively. is the scaling factor, W O is a learnable matrix.
[0047] There is a feed-forward network after the multi-head self-attention sublayer, which consists of two linear transformations and a ReLU activation function in the middle. In addition, each sublayer is followed by a residual connection and layer normalization. Finally, the model output is averaged in the time dimension to obtain a one-dimensional feature vector of length 64.
[0048] S6, the features extracted by the CNN model and the Transformer model are concatenated into a new one-dimensional array and input into the softmax classifier to obtain the classification results of the left and right hand movement imagery task.
Claims
1. A motor imagery EEG signal classification method based on a parallel CNN-Transformer neural network, characterized in that: The following steps are involved: S1, preprocessing of motor imagery EEG signals; S2, adding noise to the preprocessed motor imagery EEG signals to augment the data; S3, performing time-frequency analysis on the motor imagery EEG signals processed in step S1 and step S2 to generate a two-dimensional feature map containing time features, frequency features and position information; the time-frequency analysis selects a continuous wavelet transform whose mother wavelet is a complex Morlet wavelet to perform time-frequency analysis, and respectively performs time-frequency analysis on C3, C4 and C5 in the motor imagery EEG signals processed in step S1 and step S2. z The data of the three channels C4 are transformed by continuous wavelet transform to generate a two-dimensional time-frequency diagram, and the two-dimensional time-frequency diagrams of the three channels in each step are combined into a two-dimensional feature diagram containing time, frequency and position information, specifically including: S3-1, C3, C4 in the motor imagery EEG signal processed in step S1 and step S2 z CWT analysis is performed on the data of the three channels C, C4 with a duration of 4s to generate a two-dimensional time-frequency diagram containing time and frequency. The continuous wavelet transform uses the following formula: Where CWT(s,τ) represents the continuous wavelet transform output, s represents the scale and s≠0, τ represents the translation factor, yes The complex conjugate function of pass By translation and scaling, <·> represents the inner product, x(t) represents the input sequence, represents the translation and scaling of the mother wavelet; S3-2, intercept the two-dimensional time-frequency graphs of the 8-30 Hz frequency band that is closely related to the motor imagery EEG signals in the three EEG signal channels respectively, and arrange the intercepted images up and down according to the electrode sequence to form a two-dimensional feature graph containing time, frequency and position information; S4, constructing a CNN model, setting network parameters, and extracting frequency features and position information in a two-dimensional feature map; the CNN model includes three convolutional layers and three maximum pooling layers, the size of each convolution kernel in the convolutional layer is 3×3, the stride is 1 pixel, the convolutional layer input is padded with 1 pixel, the number of filters in the three convolutional layers is 16, 32, and 64, respectively, and a maximum pooling layer is added after each convolutional layer. The size of the first two pooling layers is 2×2, and the size of the last pooling layer is 8×8, and the size and stride of each pooling window are the same; S5, constructing a Transformer model, setting network parameters, and extracting time features from the two-dimensional feature map; the Transformer model cuts the two-dimensional feature map obtained in step S3 into non-overlapping input feature sequences according to unit time along the time dimension, and then uses the feature sequence after input encoding and position encoding as the input of the Transformer model; the Transformer includes three identical encoder layers stacked together, each layer consisting of two sublayers of a 4-head self-attention layer and a feedforward neural network layer, and the outputs of the two sublayers are both residually connected and layer normalized; S6, concatenate the features extracted in step S4 and step S5, and input them into the classifier to obtain the motor imagery classification result; concatenate the frequency features and position information extracted by CNN in step S4 and the time features extracted by Transformer in step 5 as new inputs, and input them into the fully connected layer for classification.
2. According to claim 1, a motor imagery EEG signal classification method based on a parallel CNN-Transformer neural network is characterized in that: The preprocessing in step S1 is to select an 8-30 Hz bandpass filter to filter the motor imagery EEG signal.
3. According to claim 2, a motor imagery EEG signal classification method based on a parallel CNN-Transformer neural network is characterized in that: The bandpass filter is a Butterworth filter.
4. According to claim 1, a motor imagery EEG signal classification method based on a parallel CNN-Transformer neural network is characterized in that: The adding of noise in step S2 is adding Gaussian noise for data expansion.
