Electroencephalogram signal classification method based on time sequence convolution and prototype learning
By using lightweight temporal convolutional layers, bidirectional temporal convolutional networks, and prototype learning classification modules, the problem of insufficient long-range and multi-scale temporal dependency capture and non-stationarity adaptation in existing EEG signal classification methods is solved, achieving higher classification accuracy and generalization ability.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- GUANGZHOU UNIVERSITY
- Filing Date
- 2026-01-05
- Publication Date
- 2026-04-21
AI Technical Summary
Existing EEG signal classification methods are unable to fully capture the long-range and multi-scale time dependencies in EEG signals, and common classifiers based on fully connected layers lack the ability to adapt to signal non-stationarity, which limits the discriminative power and robustness of the models.
Lightweight temporal convolutional layers and pointwise convolutional layers are used for spatiotemporal feature extraction. Combined with bidirectional temporal convolutional networks and gated channel attention mechanisms, statistical features are extracted through variance pooling. A prototype learning classification module is constructed and trained using a joint loss function to optimize the category prototype vectors.
It improves the temporal feature representation ability and robustness of EEG signal classification, enhances the discriminative power of features and the generalization ability across subjects, and improves classification accuracy.
Smart Images

Figure CN121901792A_ABST
Abstract
Description
Technical Field
[0001] This invention belongs to the field of EEG signal processing technology, and particularly relates to an EEG signal classification method based on temporal convolution and prototype learning. Background Technology
[0002] Electroencephalography (EEG), due to its high temporal resolution and non-invasive nature, is a key technology in the field of brain-computer interfaces (BCI) for acquiring brain intention signals. EEG signals based on motor imagery (MI), which can be generated autonomously by the user without external stimulation, have become an important type of BCI control signal. Traditional MI-EEG signal classification methods rely on handcrafted features and shallow machine learning models, and their performance is limited by feature representation and generalization capabilities.
[0003] In recent years, deep learning methods, represented by convolutional neural networks (CNNs) and temporal convolutional networks (TCNs), have improved decoding performance through automatic feature learning. However, existing methods still face two challenges: first, ordinary temporal modeling is insufficient to fully capture the complex long-range and multi-scale temporal dependencies in EEG signals; second, common classifiers based on fully connected layers lack adaptability to signal non-stationarity and fail to explicitly model and optimize the essential feature representations of each category, thus limiting the model's discriminative power and robustness. Summary of the Invention
[0004] In view of the above-mentioned deficiencies of the prior art, this invention proposes a brainwave signal classification method based on temporal convolution and prototype learning. The technical solution designed in this invention includes the following steps: S1: Perform preliminary spatiotemporal feature extraction on the input EEG signal; S2: Perform bidirectional temporal series modeling on the initially extracted spatiotemporal features to obtain comprehensive temporal series features; S3: Extract variance statistical features from the initially extracted spatiotemporal features, and concatenate the variance statistical features with the comprehensive temporal features to obtain multi-scale fusion features; S4: Input the multi-scale fused features into the prototype learning classification module, and obtain the classification result by calculating the distance between the feature and the learnable category prototype vector; Preferably, S1 includes: S11: A lightweight temporal convolutional layer is used to extract temporal features from the input EEG signal. The lightweight temporal convolutional layer uses a one-dimensional convolution with shared weights for each channel, and all input channels reuse the same set of convolutional kernel parameters. S12: Spatial features are extracted from the output of S11 using pointwise convolutional layers to obtain spatiotemporal features.
[0005] Preferably, S2 includes: S21: Perform mean pooling and Dropout processing on the spatiotemporal features; S22: Input the processed spatiotemporal features into the forward temporal convolutional network and the backward temporal convolutional network respectively; S23: The outputs of the forward temporal convolutional network and the backward temporal convolutional network are weighted and averaged and fused. The fused spatiotemporal features are then concatenated with the outputs of the two networks to obtain comprehensive temporal features.
[0006] Preferably, both the forward temporal convolutional network and the backward temporal convolutional network are composed of at least one causal convolutional residual block, and each residual block includes a causal convolutional layer, a batch normalization layer, an activation function layer, a Dropout layer, and a gated channel attention module.
[0007] Preferably, S4 includes: Construct a prototype learning classification module, maintain a learnable prototype vector for each category, and the dimension of the prototype vector is the same as the dimension of the multi-scale fusion feature. Calculate the Euclidean distance between the multi-scale fusion feature of the sample to be classified and the prototype vectors of all categories, calculate the classification score based on the Euclidean distance, and output the classification result.
[0008] Preferably, the classification method is trained using a joint loss function that includes main classification loss and prototype distance loss.
[0009] Preferably, the joint loss function is formulated as follows:
[0010]
[0011] In the formula, For the joint loss function, Primary classification loss, For prototype distance loss, These are the preset weighting coefficients. Let be the average Euclidean distance from all training samples to their corresponding class prototype vectors. This is another pre-set weighting coefficient. The comparative loss is based on the boundary violation.
[0012] Beneficial effects: 1. This application constructs an improved bidirectional temporal convolutional network and combines it with a gated channel attention mechanism, which can more fully capture forward and backward long-term temporal dependencies in EEG signals and improve the representation ability of temporal features. 2. This application extracts the statistical fluctuation characteristics of the signal by designing a variance pooling branch and integrates them with deep time series characteristics to form a multi-scale feature representation that combines detailed time series patterns with macroscopic statistical regularities, thereby enhancing the feature robustness. 3. This application replaces the traditional classifier with prototype learning. By explicitly learning and optimizing the prototype vector of each category and imposing constraints on intra-class aggregation and inter-class separation, the model can learn a more discriminative and stable feature space, thereby improving classification accuracy and cross-subject generalization ability. Attached Figure Description
[0013] Figure 1 This is a flowchart illustrating a preferred embodiment of the present invention; Figure 2 This is a schematic diagram of the model structure of a preferred embodiment of the forward GCTCN of the present invention; Figure 3 This is a schematic diagram of the GCA structure according to a preferred embodiment of the present invention; Figure 4 This is a prototype learning diagram of a preferred embodiment of the present invention; Figure 5 This is a schematic diagram of the original data feature distribution of subject A01 in the BCI2a dataset according to a preferred embodiment of the present invention; Figure 6 This is a schematic diagram of the feature distribution of subject A01 in the BCI2a dataset after being extracted by the method of this invention, according to a preferred embodiment of the present invention. Detailed Implementation
[0014] The embodiments of the present invention will be described in detail below. The following embodiments are implemented based on the technical solution of the present invention, and detailed implementation methods and specific operation processes are given. However, the protection scope of the present invention is not limited to the following embodiments.
[0015] This invention designs a method for classifying electroencephalogram (EEG) signals based on temporal convolution and prototype learning, such as... Figure 1-6 As shown, the technical solution includes the following steps, specifically: S1: Perform preliminary spatiotemporal feature extraction on the input EEG signal; S2: Perform bidirectional temporal series modeling on the initially extracted spatiotemporal features to obtain comprehensive temporal series features; S3: Extract variance statistical features from the initially extracted spatiotemporal features, and concatenate the variance statistical features with the comprehensive temporal features to obtain multi-scale fusion features; S4: Input the multi-scale fused features into the prototype learning classification module, and obtain the classification result by calculating the distance between the feature and the learnable category prototype vector; Preferably, S1 includes: S11: Lightweight temporal convolutional layers are used to extract temporal features from the input EEG signals. The lightweight temporal convolutional layers use one-dimensional convolution with shared weights for each channel, and all input channels reuse the same set of convolutional kernel parameters. S12: Spatial features are extracted from the output of S11 using pointwise convolutional layers to obtain spatiotemporal features.
[0016] Specifically, in step S11, 16 convolutional kernels of length 75 are designed to extract temporal dimension features, and the output feature dimension is (C×16, ), where C is the number of input channels for the original EEG signal, This represents the number of time points after temporal convolution.
[0017] In addition, in step S12, the C×16 channels are linearly mixed into 32 channels at once through 1×1 convolution, and nonlinear transformation is performed by batch normalization and ELU activation function to complete the extraction of spatial features.
[0018] Preferably, S2 includes: S21: Perform mean pooling and Dropout processing on the spatiotemporal features; S22: Input the processed spatiotemporal features into the forward temporal convolutional network and the backward temporal convolutional network respectively; S23: The outputs of the forward temporal convolutional network and the backward temporal convolutional network are weighted and averaged and fused. The fused spatiotemporal features are then concatenated with the outputs of the two networks to obtain comprehensive temporal features.
[0019] Specifically, in step S21, mean pooling is performed on the pointwise convolution output using an average pooling kernel with a kernel size of 32, and Dropout processing is combined to extract the main trend features of the signal as the input of the bidirectional temporal convolutional network.
[0020] In addition, in step S22, the forward temporal convolutional network consists of two causal convolutional residual blocks, each containing causal convolution, batch normalization, ELU activation function, Dropout, and gated channel attention. The dropout rate of the Dropout layer is set to 0.2. The backward temporal convolutional network has the same structure as the forward network, and its input is a time-reversed EEG signal.
[0021] In addition, in step S23, the outputs of the forward temporal convolutional network and the backward temporal convolutional network are weighted and averaged, with the specific fusion weights fixed at 0.5:0.5, to obtain a bidirectional fused feature. Finally, the forward output, the backward output, and this bidirectional fused feature are concatenated to form a comprehensive temporal feature.
[0022] Preferably, both the forward temporal convolutional network and the backward temporal convolutional network consist of at least one causal convolutional residual block, and each residual block includes a causal convolutional layer, a batch normalization layer, an activation function layer, a Dropout layer, and a gated channel attention module.
[0023] Specifically, each residual block includes two dilated causal convolutional layers and a gated channel attention module (GCA). The dilation factor in the dilated causal convolution increases with the number of residual blocks, allowing the model to expand its receptive field and capture information from longer time series without increasing the number of convolutional layers. Using deep dilated causal convolutions maintains model performance while reducing the number of parameters. All convolutional kernel sizes are set to... .
[0024] In addition, the operation of the gated channel attention module is divided into three parts: statistical information embedding, channel weight generation, and gating adaptation. Statistical information embedding involves calculating the variance to obtain the time information for each channel. The formula is as follows: ; Channel weights are generated using L2 regularization for channel normalization. The specific calculation formula is as follows:
[0025] Where C represents the total number of channels, and s is the vector obtained by embedding statistical information. It is a very small constant (e.g., 1e-5) to avoid numerical problems when differentiating at zero; Gated adaptive modulation modulates the normalized weights using learnable parameters and activation functions, and then fuses them with the original feature map. The specific operation is defined as follows:
[0026] Here, γ and β are learnable scaling and bias parameters. When the gating weights of a channel are actively activated by the tanh function (output is positive), GCA promotes the features of that channel to compete with other channels. When the gating weights are passively activated (output is negative), GCA encourages the features of that channel to cooperate with other channels, thus realizing a dynamic gating channel attention mechanism.
[0027] Furthermore, for the variance statistical feature extraction of S3, this includes constructing a variance pooling branch to extract the signal's fluctuation characteristics and non-stationary features through variance pooling. Statistical time-series information in the spatiotemporal features is extracted using variance pooling, through the formula... The local variance of the input sequence is calculated. Specifically, a sliding window with a kernel size of 100 and a stride of 50 is used to calculate the local variance of the input sequence, and the output features are flattened to form the final temporal statistical features. Finally, the comprehensive temporal features extracted by the bidirectional temporal convolutional network are concatenated with this variance statistical feature to form the final multi-scale fusion feature representing the samples for classification.
[0028] Preferably, S4 includes: Construct a prototype learning classification module, maintain a learnable prototype vector for each category, and the dimension of the prototype vector is the same as the dimension of the multi-scale fusion feature. Calculate the Euclidean distance between the multi-scale fusion feature of the sample to be classified and the prototype vectors of all categories, calculate the classification score based on the Euclidean distance, and output the classification result.
[0029] Specifically, during network optimization, the prototype learning classification module learns a prototype vector for each category, representing the typical feature patterns of that category. For example, when performing a 4-class classification task, prototype vectors for 4 different categories are constructed.
[0030] In addition, L2 norm constraints are applied to the prototype vectors. By renormalizing, the L2 norm of each prototype vector is limited to a fixed range (e.g., 0.25). This constraint ensures numerical stability, prevents some prototype vectors from having excessively large norms that dominate gradient updates during training, and promotes stable convergence during training, avoiding prototype vectors from diverging to infinity.
[0031] Preferably, the classification method is trained using a joint loss function that includes the main classification loss and the prototype distance loss.
[0032] Preferably, the joint loss function is as follows:
[0033]
[0034] In the formula, For the joint loss function, Primary classification loss, For prototype distance loss, These are the preset weighting coefficients. Let be the average Euclidean distance from all training samples to their corresponding class prototype vectors. This is another pre-set weighting coefficient. The comparative loss is based on the boundary violation.
[0035] Specifically, primary classification loss A cross-entropy loss function based on distance metrics is employed. This loss function calculates the negative Euclidean distance between sample features and prototype vectors of all classes as similarity, and applies a Softmax function to transform it into a class probability distribution before calculating the cross-entropy loss. This approach aims to drive features of similar samples to cluster towards their class prototypes through gradient optimization, while simultaneously distancing features of dissimilar samples from each other, thereby directly optimizing the model's feature extractor and prototype vectors.
[0036] Additionally, prototype distance loss This is used to further optimize the feature space structure, achieving intra-class aggregation and inter-class separation, based on intra-class loss. Inter-class comparison loss It is composed of weighted combinations, among which Calculate the Euclidean distance (i.e., intra-class distance) of all samples to their own true class prototype. The average value of )
[0037] Where N is the total number of samples involved in the loss calculation, minimizing This directly causes the features of similar samples to converge toward their corresponding prototype vectors, achieving compact aggregation of features within a class.
[0038] The construction is based on a strict boundary constraint. For each sample i, the Euclidean distance to its nearest non-self class prototype is calculated, i.e., the minimum inter-class distance. Boundary constraints require that the intra-class distance of a sample, after increasing by a preset safety boundary value m, remains less than its minimum inter-class distance.
[0039] Define a boundary violation quantity for each sample:
[0040] The inter-class contrast loss is defined as the average of the positive values among all violations:
[0041] This loss is ensured only if the above boundary constraints are violated (i.e., A penalty signal is generated only when the distance between classes is greater than 0, thereby driving the model to meet the constraints by optimizing to increase the minimum inter-class distance or decrease the intra-class distance, and finally forming an inter-class separation with a clear safety boundary in the feature space.
[0042] Specifically, in a preferred embodiment, the weighting coefficient α and the safety boundary value m are both set to 1. In this case, the optimization objectives of intra-class aggregation and inter-class separation are given equal importance, and a decision boundary of suitable width can be constructed. Experiments show that the model achieves the best discriminative performance under this configuration. The weighting coefficient β in the total loss function is set to 0.0001. This setting effectively leverages the normalization effect of the prototype distance loss while ensuring that the main classification loss dominates during training.
[0043] Furthermore, the classification method employs a two-stage training strategy. It can be adapted for use on different EEG signal datasets; the implementation on the BCI Competition IV 2a dataset is shown below. The dataset is split according to the official partitioning: session 1 is used for training, and session 2 is used for testing. The training data is further divided into a training set and a validation set, with a ratio of 8:2.
[0044] In the first phase, the model is trained using only the training set, and the validation set accuracy is monitored. Training is stopped if the validation set accuracy does not increase for 300 consecutive epochs. After the stopping criterion is met, the network parameters with the best validation set accuracy are restored.
[0045] Starting with this saved model, the training procedure continues in the second phase, where the model is trained using the complete training data (i.e., the combined training and validation sets). The second phase of training stops when the validation set loss falls below the training set loss from the first phase.
[0046] To avoid infinite training without convergence, the maximum number of training epochs for training phase 1 and phase 2 is limited to 1000 and 500 epochs, respectively.
[0047] The experimental results on the BCI2a dataset for 9 subjects (A01-A09) are shown in Tables 1 and 2: Table 1: Accuracy (%) Comparison (with baseline and state-of-the-art models)
[0048] Table 2: Accuracy Rate (%) Comparison (Validation of Prototype Learning Effectiveness)
[0049] As shown in Table 1, the average classification accuracy of the proposed BiGCVar-PL method is not as high as that of EEGNet, EEGTCNet, ATCNet, and CTMIFNet. Table 2 shows that the improved prototype learning method has higher accuracy and better generalization ability across different subjects than ordinary linear classifiers. The average classification accuracy is also higher.
[0050] The preferred embodiments of the present invention have been described in detail above. It should be understood that those skilled in the art can make numerous modifications and variations based on the concept of the present invention without creative effort. Therefore, all technical solutions that can be obtained by those skilled in the art based on the concept of the present invention through logical analysis, reasoning, or limited experimentation on the basis of existing technology should be within the scope of protection defined by the claims.
Claims
1. A method for classifying electroencephalogram (EEG) signals based on temporal convolution and prototype learning, characterized in that, include: S1: Perform preliminary spatiotemporal feature extraction on the input EEG signal; S2: Perform bidirectional temporal series modeling on the initially extracted spatiotemporal features to obtain comprehensive temporal series features; S3: Extract variance statistical features from the initially extracted spatiotemporal features, and concatenate the variance statistical features with the comprehensive temporal features to obtain multi-scale fusion features; S4: Input the multi-scale fused features into the prototype learning classification module, and obtain the classification result by calculating the distance between the feature and the learnable class prototype vector.
2. The EEG signal classification method based on temporal convolution and prototype learning according to claim 1, characterized in that, S1 includes: S11: A lightweight temporal convolutional layer is used to extract temporal features from the input EEG signal. The lightweight temporal convolutional layer uses a one-dimensional convolution with shared weights for each channel, and all input channels reuse the same set of convolutional kernel parameters. S12: Spatial features are extracted from the output of S11 using pointwise convolutional layers to obtain spatiotemporal features.
3. The EEG signal classification method based on temporal convolution and prototype learning according to claim 1, characterized in that, S2 includes: S21: Perform mean pooling and Dropout processing on the spatiotemporal features; S22: Input the processed spatiotemporal features into the forward temporal convolutional network and the backward temporal convolutional network respectively; S23: The outputs of the forward temporal convolutional network and the backward temporal convolutional network are weighted and averaged and fused. The fused spatiotemporal features are then concatenated with the outputs of the two networks to obtain comprehensive temporal features.
4. The EEG signal classification method based on temporal convolution and prototype learning according to claim 3, characterized in that, Both the forward temporal convolutional network and the backward temporal convolutional network consist of at least one causal convolutional residual block. Each residual block contains a causal convolutional layer, a batch normalization layer, an activation function layer, a Dropout layer, and a gated channel attention module.
5. The EEG signal classification method based on temporal convolution and prototype learning according to claim 1, characterized in that, S4 includes: Construct a prototype learning classification module, maintain a learnable prototype vector for each category, and the dimension of the prototype vector is the same as the dimension of the multi-scale fusion feature. Calculate the Euclidean distance between the multi-scale fusion feature of the sample to be classified and the prototype vectors of all categories, calculate the classification score based on the Euclidean distance, and output the classification result.
6. The EEG signal classification method based on temporal convolution and prototype learning according to claim 1, characterized in that, The classification method is trained using a joint loss function that includes main classification loss and prototype distance loss.
7. The EEG signal classification method based on temporal convolution and prototype learning according to claim 6, characterized in that, The joint loss function is given by the following formula: In the formula, For the joint loss function, Primary classification loss, For prototype distance loss, These are the preset weighting coefficients. Let be the average Euclidean distance from all training samples to their corresponding class prototype vectors. This is another pre-set weighting coefficient. The comparative loss is based on the boundary violation.