A cross-device EEG modeling method for motor imagery based on graph neural network

Through the cross-device EEG modeling method based on graph neural network, the problem of insufficient decoding ability in cross-device model migration is solved, and the effective migration of high-quality multi-channel data sets to low-quality few-channel data sets is achieved, which improves the EEG performance. The decoding accuracy of the data and the generalization ability of the model are suitable for practical application scenarios.

CN118466752BActive Publication Date: 2024-10-11SHANGHAI SHAONAO SENSING TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202410548281.8
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-05-06
Publication Date
2024-10-11
Estimated Expiration
2044-05-06

AI Technical Summary

Technical Problem

It is difficult to improve the EEG data decoding capabilities through cross-device model migration with existing technology, especially in the migration from high-quality multi-channel data sets to low-quality few-channel data sets, resulting in limited model generalization capabilities and decoding accuracy.

Method used

A cross-device motor imagery EEG modeling method based on graph neural networks is used to divide the EEG data into source domains and target domains, use high-quality multi-channel data sets to train the model, fuse channel information and reduce the number of channels, and then migrate Fine-tuning enables the model to adapt to low-quality few-channel data sets and improve the model's generalization and decoding capabilities.

Benefits of technology

It achieves high classification accuracy on low-quality few-channel data sets, improves the model's cross-device decoding ability and patient movement intention recognition accuracy, simplifies the model migration process between devices, and is suitable for practical application scenarios.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118466752B_ABST
    Figure CN118466752B_ABST
Patent Text Reader

Abstract

The present invention discloses a cross-device motor imagery EEG modeling method based on graph neural network, including the following steps: EEG data preprocessing, source domain multi-channel model training, source domain few-channel model training, and transfer fine-tuning. The present invention extracts and fuses channel information of multi-channel, high-quality EEG signals on a training set through convolutional neural networks and graph neural networks, and trains a source domain multi-channel model; a small number of channels are used as signal input on the training set, and the student model is guided to learn multi-channel fusion information under limited channel input by comparing the difference in eigenvalues ​​of the source domain multi-channel model and the source domain few-channel model; the source domain few-channel model is used as a pre-training model, and transfer learning is used on the source domain EEG data set to fine-tune the model parameters to adapt to the data feature distribution of the test set; the constructed model can successfully realize the classification of motor imagery EEG signal tasks across devices, and solve the problems of migration difficulties caused by inconsistent channels across devices.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of electroencephalogram (EEG) modeling methods, and in particular to a cross-device motor imagery EEG modeling method based on a graph neural network. Background Art

[0002] Motor Imagery-Brain Computer Interface (MI-BCI) is a technology that enables direct communication and interaction between the human brain and the outside world by decoding the electroencephalogram (EEG) generated when the patient imagines a motor task. It has great development potential in the field of rehabilitation. Traditional EEG devices use wet electrodes to obtain multi-channel, high-quality, low-noise EEG data, and then the equipment experimental preparation time is too long, which is difficult to meet the plug-and-play needs of patients in actual application scenarios. Portable dry electrode EEG devices can obtain EEG data without experimental preparation time, but due to the small number of channels and high impedance of the device, the EEG signal is noisy and of low quality. At the same time, since portable EEG devices are mostly used by patients, the amount of collected data is small, making it difficult for algorithms such as deep learning (DL) to effectively decode. Although multi-channel wet electrode EEG devices collect a large amount of historical data, it is difficult to improve model performance by directly migrating data due to the different EEG channels and data quality of different devices.

[0003] In summary, how to improve cross-device model migration and decoding capabilities, learn motor imagery information from high-quality multi-channel EEG datasets, build high-precision decoding models and migrate to low-quality, low-channel EEG datasets are issues that technical personnel in this field urgently need to solve. Summary of the invention

[0004] The main purpose of an embodiment of the present invention is to propose a cross-device motor imagery EEG modeling method based on graph neural network, aiming to build a model using high-quality, multi-channel EEG datasets, use graph neural networks to fuse channel information and reduce the number of channels, and then adapt the model to low-quality, low-channel datasets through migration and fine-tuning, thereby improving the model's generalization and cross-device decoding capabilities.

[0005] The technical solution of the present invention to solve the above technical problems is to provide a cross-device motor imagery EEG modeling method based on graph neural network, comprising the following steps:

[0006] (1) EEG data preprocessing:

[0007] Divide the EEG data into a training set (source domain) and a test set (target domain);

[0008] Among them, the training set has M EEG channels, the test set has N EEG channels, and M>N;

[0009] (2) Source domain multi-channel model training:

[0010] The training set data is sent to the source domain multi-channel model for training. The predicted classification results are obtained through training. The training loss value of the predicted classification results and the true classification results is calculated using the cross entropy function. Then, the parameters of the source domain multi-channel model are reversely updated. The model learning feature point is F Source M_channels ;

[0011] (3) Source domain few-channel model training:

[0012] Select channels in the training set data so that the number and position of EEG channels are consistent with those in the test set;

[0013] Input the training set data of N EEG channels into the source domain few-channel model for training; obtain the predicted classification results through training, and use the cross entropy function to calculate the classification loss value between the predicted classification results and the actual classification results. cls ;

[0014] The feature points F learned from the source domain multi-channel model Source M_channels And the in-domain classification feature F learned by the source domain few-channel model Source N_channels , calculate the distillation loss value loss through the Coral function align ;

[0015] The classification loss value loss cls And distillation loss loss align Add together to get the final model loss loss all , through the final model loss loss all Reverse gradient updates the source domain few-channel model to obtain a pre-trained source domain few-channel model;

[0016] (4) Migration fine-tuning:

[0017] The test set data set of N EEG channels is divided into two parts: training and testing. The training part is sent to the pre-trained source domain few-channel model for retraining to obtain a transfer fine-tuning model. The predicted classification results are obtained through training, and the training loss value of the predicted classification results and the actual classification results is calculated using the cross entropy function, and then the parameters of the model are updated in reverse.

[0018] When the migration and fine-tuning model parameters are updated, some pre-trained weight parameters are frozen and the remaining weight parameters are iteratively updated; the final model is verified in the test part of the test set.

[0019] Furthermore, the step of preprocessing the EEG data includes:

[0020] Perform baseline removal on EEG data;

[0021] Frequency domain filtering is performed using a 5th order Butterworth filter;

[0022] Normalization is performed using the Z-Score algorithm; the Z-Score algorithm is:

[0023]

[0024] Among them, x is the input data, z is all the data points of each channel in each EEG sample, μ is the mean of this set of data points, and σ is the standard deviation of this set of data points.

[0025] Furthermore, the step of training the source domain multi-channel model includes:

[0026] The training set multi-channel data is sent to the source domain multi-channel model in batches for training, with 16 samples in each batch;

[0027] Set the number of iterations i to 0, the number of early stopping iterations j to 0, and the learning rate to 0.001;

[0028] Update source domain multi-channel model parameters;

[0029] Calculate and save the validation set loss. If i is 0, save the first training set loss result as the minimum training loss value, and stop the number of early iterations j+1;

[0030] Compare the loss of the i-th training set with the minimum training loss value saved in history. If the loss of the i-th training set is smaller, save the current training loss value as the minimum training loss value, and reset the number of early stopping iterations j to 0; if the loss of the i-th training set is larger, then the current training loss value is not saved as the minimum training loss value, and the number of early stopping iterations is j+1;

[0031] When the number of early stopping iterations j reaches 100, the source domain multi-channel model with the minimum training loss value is saved;

[0032] The number of iterations is updated to i+1;

[0033] When the number of iterations is less than 800, continue the loop iteration;

[0034] When the number of iterations reaches or exceeds 800, even if the number of early stopping iterations is less than 100, the source domain multi-channel model that obtains the minimum training loss value is still saved.

[0035] Furthermore, the step of sending the training set multi-channel data in batches into the source domain multi-channel model for training includes:

[0036] The data is passed through a two-dimensional convolutional layer to obtain temporal features;

[0037] Further extract the temporal features through the fully connected network;

[0038] The channel space features are extracted through the graph neural convolution layer, and the channel information is fused, so that the number of channels changes from M to N;

[0039] The predicted classification results are obtained through the fully connected layer and softmax function.

[0040] Furthermore, in the step of sending the training set multi-channel data in batches into the source domain multi-channel model for training:

[0041] Assume that the data X fed into the training set multi-channel model is Source_M The format is (B, D, M, T), where B represents the number of samples input to the model each time, D represents the feature dimension of each sample input data, M represents the number of channels of each sample input data, and T represents the amount of data of each sample input data;

[0042] When the selected network layer is a two-dimensional convolutional layer, three two-dimensional convolutional layers with different filter sizes are selected, namely (1, T1), (1, T2) and (1, T3), with a dimension of F1, which means that features of T1, T2 and T3 data points will be extracted in each filter, and the extracted dimensions are all F1 with a step size of 1; the padding parameter of the two-dimensional convolutional layer is set to 0, that is, the data is padded with 0; the formula is as follows:

[0043]

[0044] in, is the output of CNN, w is the weight of the neuron, b is the bias, and f is the activation function;

[0045] When the selected network layer is a fully connected network, the fully connected network is composed of 4 convolutional layers with filter size (C, 1) and dimension F2, and two average pooling layers with size (Cavg, 1); Cavg represents the pooling range, and the average value of Cavg data is calculated each time, with a step size of 5; when the feature with dimension F1 is input into the convolutional layer in the fully connected network, each newly acquired F2 dimension will be added to the original F1 dimension feature as a new feature and sent to the next convolutional layer. Therefore, the feature dimension of the final fully connected network output is F3 = F2*4 + F1;

[0046] When the selected network layer is the graph neural network convolution layer, the adjacency matrix of the graph neural network is AInitial The Pearson index P is initialized by calculating the features output by the fully connected network. The specific formula is as follows:

[0047]

[0048]

[0049] Where X i X j Represents the i-th and j-th input features, cov() calculates the covariance matrix, and var() calculates the variance; in the matrix A Initial Add a matrix A consisting of learnable weights W to trainable , the eigenvalue is output through the relu function. The specific formula is as follows:

[0050]

[0051]

[0052] Normalize the matrix A. The specific formula is as follows:

[0053]

[0054]

[0055] where D is the degree matrix, is the normalized adjacency matrix; Flatten layer is used to flatten and expand to obtain F sourceM_channels ;

[0056] When the selected layer network obtains the predicted classification result through the fully connected layer and the softmax function, the cross entropy function is used to calculate the classification loss value of the predicted classification result and the actual classification result. The calculation formula of the cross entropy function is:

[0057]

[0058] Among them, m represents the number of classification labels, y p Represents the model prediction label, y t Represents the true label.

[0059] Furthermore, the step of training the source domain few-channel model includes:

[0060] The training set few-channel data is sent to the source domain few-channel model in batches for training, with the number of samples in each batch being 16;

[0061] Set the number of iterations i to 0, the number of early stopping iterations j to 0, and the learning rate to 0.001;

[0062] Update the source domain few-channel model parameters;

[0063] Calculate and save the validation set loss. If i is 0, save the first training set loss result as the minimum training loss value, and stop the number of early iterations j+1;

[0064] Compare the loss of the i-th training set with the minimum training loss value saved in history. If the loss of the i-th training set is smaller, save the current training loss value as the minimum training loss value, and reset the number of early stopping iterations j to 0; if the loss of the i-th training set is larger, do not save the current training loss value as the minimum training loss value, and reset the number of early stopping iterations j+1;

[0065] When the number of early stopping iterations j reaches 50, the source domain few-channel model with the minimum training loss value is saved;

[0066] The number of iterations is updated to i+1;

[0067] When the number of iterations is less than 500, continue the loop iteration;

[0068] When the number of iterations reaches or exceeds 500, even if the number of early stopping iterations is less than 50, the source domain few-channel model with the minimum training loss value is still saved.

[0069] Furthermore, the step of sending the training set few-channel data in batches into the source domain multi-channel model for training includes:

[0070] The number of channels in the training set of few-channel data is N. The graph neural network is used to extract channel space features and fuse channel information.

[0071] When the selected network layer is a graph neural convolution layer, the feature obtained by flattening the Flatten layer is called F Source N_channels ; By reducing the feature distribution distance, the multi-channel model information of the training set can be passed to the few-channel model of the training set, and the loss value loss calculated by the Coral function align ,as follows:

[0072]

[0073] in Represents the covariance matrix of the feature matrix in C, each time F is calculated Source M_channels and F Source N_channels The distance of the covariance matrix between is input into the final loss function:

[0074] loss all (y p ,y t )=losscls +loss align

[0075] Among them, m represents the number of classification labels, y p Represents the model prediction label, y t Represents the true label.

[0076] Furthermore, the migration fine-tuning step includes:

[0077] Using the pre-trained training set few-channel model as the benchmark model, the migration model relearns the parameters on the benchmark model;

[0078] The few-channel data of the test set are sent to the migration model in batches for training, with 16 samples in each batch;

[0079] Set the number of iterations i to 0, the number of early stopping iterations j to 0, and the learning rate to 0.001;

[0080] Update migration model parameters;

[0081] Calculate and save the validation set loss. If i is 0, save the first training set loss result as the minimum training loss value, and stop the number of early iterations j+1;

[0082] Compare the loss of the i-th training set with the minimum training loss value saved in history. If the loss of the i-th training set is smaller, the training loss value is saved as the minimum training loss value, and the number of early stopping iterations j is reset to 0; if the loss of the i-th training set is larger, the training loss value is not saved as the minimum training loss value, and the number of early stopping iterations is j+1;

[0083] When the number of early stopping iterations j reaches 50, the migration model with the minimum training loss value is saved;

[0084] The number of iterations is updated to i+1;

[0085] When the number of iterations is less than 500, continue the loop iteration;

[0086] When the number of iterations reaches or exceeds 500, the migration model with the minimum training loss value is saved even if the number of early stopping iterations is less than 50.

[0087] The technical solution of the present invention has obvious outstanding substantial features and significant advantages:

[0088] 1. The present invention classifies and identifies motor imagery EEG across devices based on graph neural networks. The EEG data sets of different devices are divided into a source domain and a target domain. The source domain data has many channels, high quality and low noise, while the target domain data has few channels, poor quality and high noise; however, the EEG acquisition equipment used in the target domain has a short preparation time and can achieve plug-and-play functions, which is convenient for patients to use directly in hospitals or in life. The model constructed by the present invention can be modeled using a high-quality data set and then migrated to a low-quality data set, so that the model can also achieve a high classification accuracy in the target domain and effectively identify the patient's motor intention.

[0089] 2. The present invention divides the model training into two steps. The first is source domain model training, which enables the model to learn to fuse information from multiple channels, and then use the signal input of a few channels to fit the feature distribution of multi-channel input, reducing the number of channels used and redundancy. The second is target domain model training. Through migration and fine-tuning, the parameters of the source domain training model can be retrained to adapt to the data distribution of the target domain, thereby improving the model classification performance.

[0090] 3. The present invention uses a large amount of historical data in the source domain data for modeling, and improves the generalization ability of the model by learning the common invariant features and classification features between subdomains. When performing cross-subject MI task recognition on new patients or subjects, it is no longer necessary to spend a lot of time on separate modeling to obtain higher classification recognition accuracy. BRIEF DESCRIPTION OF THE DRAWINGS

[0091] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on the structures shown in these drawings without paying creative work.

[0092] Figure 1 This is a flowchart of the steps of the cross-device motor imagery EEG modeling method based on graph neural network according to the present invention;

[0093] Figure 2 is a flow chart of the EEG data preprocessing of the present invention;

[0094] Figure 3 is a flow chart of the source domain multi-channel model training of the present invention;

[0095] Figure 4 is a structural diagram of the source domain multi-channel model of the present invention;

[0096] Figure 5 is a structural diagram of the fully connected network of the present invention;

[0097] Figure 6 is a flowchart of the source domain few-channel model training of the present invention;

[0098] Figure 7 is a structural diagram of the source domain few-channel model of the present invention;

[0099] Figure 8 It is a flowchart of the migration fine-tuning model training of the present invention. DETAILED DESCRIPTION

[0100] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.

[0101] It should be noted that all directional indications in the embodiments of the present invention (such as up, down, left, right, front, back, etc.) are only used to explain the relative position relationship, movement status, etc. between the components under a certain specific posture (as shown in the accompanying drawings). If the specific posture changes, the directional indication will also change accordingly.

[0102] In addition, in the present invention, descriptions such as "first", "second", etc. are only used for descriptive purposes and cannot be understood as indicating or implying their relative importance or implicitly indicating the number of the indicated technical features. Therefore, the features defined as "first" or "second" may explicitly or implicitly include at least one of the features. In the description of the present invention, the meaning of "several" or "multiple" is at least two, such as two, three, etc., unless otherwise clearly and specifically defined.

[0103] In the present invention, unless otherwise clearly specified and limited, the terms "connection", "fixation", etc. should be understood in a broad sense. For example, "fixation" can be a fixed connection, a detachable connection, or an integral connection; it can be a mechanical connection or an electrical connection; it can be a direct connection or an indirect connection through an intermediate medium, it can be the internal connection of two elements or the interaction relationship between two elements, unless otherwise clearly defined. For ordinary technicians in this field, the specific meanings of the above terms in the present invention can be understood according to specific circumstances.

[0104] In addition, the technical solutions between the various embodiments of the present invention can be combined with each other, but it must be based on the fact that ordinary technicians in the field can implement it. When the combination of technical solutions is contradictory or cannot be implemented, it should be deemed that such combination of technical solutions does not exist and is not within the scope of protection required by the present invention.

[0105] The main purpose of an embodiment of the present invention is to propose a cross-device motor imagery EEG modeling method based on graph neural network, aiming to build a model using high-quality, multi-channel EEG datasets, use graph neural networks to fuse channel information and reduce the number of channels, and then adapt the model to low-quality, low-channel datasets through migration and fine-tuning, thereby improving the model's generalization and cross-device decoding capabilities.

[0106] The specific contents of the cross-subject motor imagery EEG modeling method based on domain generalization proposed by the present invention will be described below in a specific embodiment:

[0107] Example 1

[0108] A cross-device motor imagery EEG modeling method based on graph neural network, Figure 1 As shown, the following steps are included:

[0109] (1) EEG data preprocessing:

[0110] Divide the EEG data into a training set (source domain) and a test set (target domain);

[0111] Among them, the training set has M EEG channels, the test set has N EEG channels, and M>N;

[0112] (2) Source domain multi-channel model training:

[0113] The training set data is sent to the source domain multi-channel model for training. The predicted classification results are obtained through training. The training loss value of the predicted classification results and the true classification results is calculated using the cross entropy function. Then, the parameters of the source domain multi-channel model are reversely updated. The model learning feature point is F Source M_channels ;

[0114] (3) Source domain few-channel model training:

[0115] Select channels in the training set data so that the number and position of EEG channels are consistent with those in the test set;

[0116] Input the training set data of N EEG channels into the source domain few-channel model for training; obtain the predicted classification results through training, and use the cross entropy function to calculate the classification loss value between the predicted classification results and the actual classification results. cls ;

[0117] The feature points F learned from the source domain multi-channel model Source M_channels And the in-domain classification feature F learned by the source domain few-channel model Source N_channels , calculate the distillation loss value loss through the Coral functionalign ;

[0118] The classification loss value loss cls And distillation loss loss align Add together to get the final model loss loss all , through the final model loss loss all Reverse gradient updates the source domain few-channel model to obtain a pre-trained source domain few-channel model;

[0119] (4) Migration fine-tuning:

[0120] The test set data set of N EEG channels is divided into two parts: training and testing. The training part is sent to the pre-trained source domain few-channel model for retraining to obtain a transfer fine-tuning model. The predicted classification results are obtained through training, and the training loss value of the predicted classification results and the actual classification results is calculated using the cross entropy function, and then the parameters of the model are updated in reverse.

[0121] When the migration and fine-tuning model parameters are updated, some pre-trained weight parameters are frozen and the remaining weight parameters are iteratively updated; the final model is verified in the test part of the test set.

[0122] Furthermore, the step of preprocessing the EEG data includes:

[0123] Perform baseline removal on EEG data;

[0124] Frequency domain filtering is performed using a 5th order Butterworth filter;

[0125] Normalization is performed using the Z-Score algorithm; the Z-Score algorithm is:

[0126]

[0127] Among them, x is the input data, z is all the data points of each channel in each EEG sample, μ is the mean of this set of data points, and σ is the standard deviation of this set of data points.

[0128] Furthermore, the step of training the source domain multi-channel model includes:

[0129] The training set multi-channel data is sent to the source domain multi-channel model in batches for training, with 16 samples in each batch;

[0130] Set the number of iterations i to 0, the number of early stopping iterations j to 0, and the learning rate to 0.001;

[0131] Update source domain multi-channel model parameters;

[0132] Calculate and save the validation set loss. If i is 0, save the first training set loss result as the minimum training loss value, and stop the number of early iterations j+1;

[0133] Compare the loss of the i-th training set with the minimum training loss value saved in history. If the loss of the i-th training set is smaller, save the current training loss value as the minimum training loss value, and reset the number of early stopping iterations j to 0; if the loss of the i-th training set is larger, then the current training loss value is not saved as the minimum training loss value, and the number of early stopping iterations is j+1;

[0134] When the number of early stopping iterations j reaches 100, the source domain multi-channel model with the minimum training loss value is saved;

[0135] The number of iterations is updated to i+1;

[0136] When the number of iterations is less than 800, continue the loop iteration;

[0137] When the number of iterations reaches or exceeds 800, even if the number of early stopping iterations is less than 100, the source domain multi-channel model that obtains the minimum training loss value is still saved.

[0138] Furthermore, the step of sending the training set multi-channel data in batches into the source domain multi-channel model for training includes:

[0139] The data is passed through a two-dimensional convolutional layer to obtain temporal features;

[0140] Further extract the temporal features through the fully connected network;

[0141] The channel space features are extracted through the graph neural convolution layer, and the channel information is fused, so that the number of channels changes from M to N;

[0142] The predicted classification results are obtained through the fully connected layer and softmax function.

[0143] Furthermore, in the step of sending the training set multi-channel data in batches into the source domain multi-channel model for training:

[0144] Assume that the data X fed into the training set multi-channel model is Source_M The format is (B, D, M, T), where B represents the number of samples input to the model each time, D represents the feature dimension of each sample input data, M represents the number of channels of each sample input data, and T represents the amount of data of each sample input data;

[0145] When the selected network layer is a two-dimensional convolutional layer, three two-dimensional convolutional layers with different filter sizes are selected, namely (1, T1), (1, T2) and (1, T3), with a dimension of F1, which means that features of T1, T2 and T3 data points will be extracted in each filter, and the extracted dimensions are all F1 with a step size of 1; the padding parameter of the two-dimensional convolutional layer is set to 0, that is, the data is padded with 0; the formula is as follows:

[0146]

[0147] in, is the output of CNN, w is the weight of the neuron, b is the bias, and f is the activation function;

[0148] When the selected network layer is a fully connected network, the fully connected network is composed of 4 convolutional layers with filter size (C, 1) and dimension F2, and two average pooling layers with size (CaVg, 1); Cavg represents the pooling range, and the average value of CaVg data is calculated each time, with a step size of 5; when the feature with dimension F1 is input into the convolutional layer in the fully connected network, each newly acquired F2 dimension will be added to the original F1 dimension feature as a new feature and sent to the next convolutional layer. Therefore, the feature dimension of the final fully connected network output is F3 = F2*4 + F1;

[0149] When the selected network layer is the graph neural network convolution layer, the adjacency matrix of the graph neural network is A Initial The Pearson index P is initialized by calculating the features output by the fully connected network. The specific formula is as follows:

[0150]

[0151]

[0152] Where X i , X j represents the i-th and j-th input features, cov() calculates the covariance matrix, and var() calculates the variance; in order to make the parameters of the adjacency matrix learnable, in the matrix A Initial Add a matrix A consisting of learnable weights W to trainable , the eigenvalue is output through the relu function. The specific formula is as follows:

[0153]

[0154]

[0155] In order to integrate the information of each channel according to the weight of the adjacency matrix A, the matrix A needs to be normalized. The specific formula is as follows:

[0156]

[0157]

[0158] where D is the degree matrix, is the normalized adjacency matrix; Flatten layer is used to flatten and expand to obtain F SourceM_channels ;

[0159] When the selected layer network obtains the predicted classification result through the fully connected layer and the softmax function, the cross entropy function is used to calculate the classification loss value of the predicted classification result and the actual classification result. The calculation formula of the cross entropy function is:

[0160]

[0161] Among them, m represents the number of classification labels, y p Represents the model prediction label, y t Represents the true label.

[0162] Furthermore, the step of training the source domain few-channel model includes:

[0163] The training set few-channel data is sent to the source domain few-channel model in batches for training, with the number of samples in each batch being 16;

[0164] Set the number of iterations i to 0, the number of early stopping iterations j to 0, and the learning rate to 0.001;

[0165] Update the source domain few-channel model parameters;

[0166] Calculate and save the validation set loss. If i is 0, save the first training set loss result as the minimum training loss value, and stop the number of early iterations j+1;

[0167] Compare the loss of the i-th training set with the minimum training loss value saved in history. If the loss of the i-th training set is smaller, save the current training loss value as the minimum training loss value, and reset the number of early stopping iterations j to 0; if the loss of the i-th training set is larger, do not save the current training loss value as the minimum training loss value, and reset the number of early stopping iterations j+1;

[0168] When the number of early stopping iterations j reaches 50, the source domain few-channel model with the minimum training loss value is saved;

[0169] The number of iterations is updated to i+1;

[0170] When the number of iterations is less than 500, continue the loop iteration;

[0171] When the number of iterations reaches or exceeds 500, even if the number of early stopping iterations is less than 50, the source domain few-channel model with the minimum training loss value is still saved.

[0172] Furthermore, the step of sending the training set few-channel data in batches into the source domain multi-channel model for training includes:

[0173] The number of channels in the training set of few-channel data is N. The graph neural network is used to extract channel space features and fuse channel information.

[0174] When the selected network layer is a graph neural convolution layer, the feature obtained by flattening the Flatten layer is called F Source N_channels ; By reducing the feature distribution distance, the multi-channel model information of the training set can be passed to the few-channel model of the training set, and the loss value loss calculated by the Coral function align ,as follows:

[0175]

[0176] in Represents the covariance matrix of the feature matrix in C, each time F is calculated SourceM_channels and F Souree N_channels The distance of the covariance matrix between is input into the final loss function:

[0177] loss all (y p ,y t )=loss cls +loss align

[0178] Among them, m represents the number of classification labels, y p Represents the model prediction label, y t Represents the true label.

[0179] Furthermore, the migration fine-tuning step includes:

[0180] Using the pre-trained training set few-channel model as the benchmark model, the migration model relearns the parameters on the benchmark model;

[0181] The few-channel data of the test set are sent to the migration model in batches for training, with 16 samples in each batch;

[0182] Set the number of iterations i to 0, the number of early stopping iterations j to 0, and the learning rate to 0.001;

[0183] Update migration model parameters;

[0184] Calculate and save the validation set loss. If i is 0, save the first training set loss result as the minimum training loss value, and stop the number of early iterations j+1;

[0185] Compare the loss of the i-th training set with the minimum training loss value saved in history. If the loss of the i-th training set is smaller, the training loss value is saved as the minimum training loss value, and the number of early stopping iterations j is reset to 0; if the loss of the i-th training set is larger, the training loss value is not saved as the minimum training loss value, and the number of early stopping iterations is j+1;

[0186] When the number of early stopping iterations j reaches 50, the migration model with the minimum training loss value is saved;

[0187] The number of iterations is updated to i+1;

[0188] When the number of iterations is less than 500, continue the loop iteration;

[0189] When the number of iterations reaches or exceeds 500, the migration model with the minimum training loss value is saved even if the number of early stopping iterations is less than 50.

[0190] Example 2

[0191] A cross-device motor imagery EEG modeling method based on graph neural network, such as Figure 1 As shown, the following steps are included:

[0192] (1) EEG data preprocessing:

[0193] Preprocess the EEG data;

[0194] The high-quality EEG data set obtained by EEG acquisition equipment with multiple channels, low impedance and strong anti-interference is used as the training set (source domain), and the low-quality EEG data set obtained by EEG acquisition equipment with few channels, high impedance and poor anti-interference is used as the test set (target domain);

[0195] Among them, the source domain dataset has a total of M EEG channels, the number of target domain EEG channels is N, and M>N;

[0196] (2) Source domain multi-channel model training:

[0197] The source domain data with M EEG channels is fed into the source domain multi-channel model for one training;

[0198] The predicted classification results of the training are used to calculate the training loss value of the predicted classification results and the actual classification results using the cross entropy function, and then the parameters of the source domain multi-channel model are reversely updated;

[0199] During the training process, the model learns the feature points F SourceM_channels ;

[0200] (3) Source domain few-channel model training:

[0201] Filter channels in the source domain data of M EEG channels so that the number and position of EEG channels are consistent with those of N EEG channels in the target domain;

[0202] The number of EEG channels of the source domain data after screening is N. The source domain data of N EEG channels are input into the source domain few-channel model for training once;

[0203] The predicted classification results of the training are calculated using the cross entropy function to calculate the classification loss value of the predicted classification results and the actual classification results. cls ;

[0204] The feature points F learned from the source domain multi-channel model SourceM_channels And the in-domain classification feature F learned by the source domain few-channel model Source N_channels , calculate the distillation loss value loss through the Coral function align ;

[0205] The classification loss value loss as And distillation loss loss align Add together to get the final model loss loss all , through the final model loss loss all The reverse gradient updates the source domain few-channel model to obtain the pre-trained source domain few-channel model.

[0206] (4) Migration fine-tuning:

[0207] The target domain dataset of N EEG channels is divided into two parts: training and testing. The training part is sent to the pre-trained source domain few-channel model for retraining to obtain a transfer fine-tuning model.

[0208] The predicted classification results of the training are calculated using the cross entropy function to calculate the training loss value of the predicted classification results and the actual classification results, and then the parameters of the model are updated in reverse;

[0209] When the migration and fine-tuning model parameters are updated, some pre-trained weight parameters are frozen and the remaining weight parameters are iteratively updated; the final model is verified in the target domain test part.

[0210] Understandably, the present application constructs a cross-device model based on a graph neural network to classify and identify motor imagery EEG tasks. The high-quality EEG data set obtained by the multi-channel, low-impedance, and strong anti-interference EEG acquisition device is used as the training set (source domain), and the low-quality EEG data set obtained by the EEG acquisition device with few channels, high impedance, and poor anti-interference is used as the test set (target domain). First, a multi-channel source domain data set is used, and the multi-channel information is fused and reduced to a few channels through the graph neural network, so that the model first learns the feature distribution based on the fusion of multiple channels. Then the source domain few-channel data is input, and the prior knowledge of the source domain multi-channel model is learned through the Coral function to form a pre-trained source domain few-channel model. Afterwards, the source domain few-channel model is used as the baseline model, and the migration fine-tuning technology is used to input a small part of the target domain data to retrain the model, and finally the remaining target domain data is tested. Although the data collected by the multi-channel wet electrode EEG acquisition device is of high quality, it is difficult to meet the actual needs of patients in hospitals or daily life scenarios due to the long experimental preparation time. Therefore, a portable few-channel, no-preparation portable EEG acquisition device is needed. However, the data collected by this type of device is of low quality, which brings difficulties to the task classification of the EEG decoding algorithm. If the model or data is directly migrated from a high-quality EEG dataset, the accuracy of the migrated model will be low due to the mismatch in the number of EEG channels of the two devices and the inconsistent data distribution. This model is based on a graph neural network. First, the high-quality multi-channel dataset is channel-fused and the classification space is represented by the EEG features of a few channels. Then, the space learned by the high-quality dataset is migrated to a low-quality, few-channel model to achieve the purpose of model device migration, so that the migrated model is suitable for the dataset of the new device, and at the same time, certain prior knowledge is learned from a large amount of high-quality historical data to improve the classification performance of the model.

[0211] Furthermore, if Figure 2 As shown, the step of preprocessing the EEG data includes:

[0212] Baseline removal: Remove the baseline of EEG data;

[0213] Frequency domain filtering: The processed EEG data is filtered in the frequency domain using a 5th-order Butterworth filter;

[0214] Z-Score normalization processing: Normalization processing is performed through the Z-Score algorithm; the Z-Score algorithm is:

[0215]

[0216] Among them, x is the input data, z is all the data points of each channel in each EEG sample, μ is the mean of this set of data points, and σ is the standard deviation of this set of data points.

[0217] Furthermore, if Figure 3 As shown, the step of sending the preprocessed source domain data into the source domain multi-channel model for one training includes:

[0218] The preprocessed source domain multi-channel data is sent to the source domain multi-channel model in batches for training, with the number of samples in each batch being 16;

[0219] Set the number of iterations i to 0, the number of early stopping iterations j to 0, and the learning rate to 0.001;

[0220] Update source domain multi-channel model parameters;

[0221] Calculate and save the validation set loss. If i is 0, save the first training set loss result as the minimum training loss value, and stop the number of early iterations j+1;

[0222] Compare the loss of the i-th training set with the minimum training loss value saved in history. If the loss of the i-th training set is smaller, the training loss value is saved as the minimum training loss value, and the number of early stopping iterations j is reset to 0; if the loss of the i-th training set is larger, the training loss value is not saved as the minimum training loss value, and the number of early stopping iterations is j+1;

[0223] When the number of early stopping iterations j reaches 100, the source domain multi-channel model with the minimum training loss value is saved;

[0224] The number of iterations is updated to i+1;

[0225] When the number of iterations is less than 800, continue the loop iteration;

[0226] When the number of iterations reaches or exceeds 800, even if the number of early stopping iterations is less than 100, the source domain multi-channel model with the minimum training loss value is still saved;

[0227] Understandably, after each training, the softmax function obtains the predicted classification result as y p , the actual classification result during training is y t , use the cross entropy function to calculate the difference between the two, that is, the training loss value. The formula is as follows:

[0228]

[0229] In order to reduce the training loss value, the source domain multi-channel model will update the parameter weights through back-propagation loop iterations. The learning rate for each propagation is δ, which is initially set to 0.001, and the total number of loop iterations is 800. At the same time, in order to reduce the training time and save the best parameter model in time, the training loss value is also monitored in the loop iteration and the maximum number of early stopping times is set to 100. When the training loss value of the model no longer decreases within 100 iterations, the model with the minimum loss value is considered to be the best parameter model. Even if the total number of loop iterations does not reach 800, the model training will stop. If the total number of loop iterations has reached 800 during the accumulation of 100 early stopping iterations, in order to prevent the model parameters from failing to converge, the loop will also end, and the model with the lowest current loss will be saved as the best model.

[0230] Furthermore, if Figure 4 As shown, the preprocessed source domain multi-channel data is sent to the source domain multi-channel model in batches for training, and the steps include:

[0231] The data is passed through a two-dimensional convolutional layer to obtain temporal features;

[0232] Further extract the temporal features through the fully connected network;

[0233] The channel space features are extracted through the graph neural convolution layer, and the channel information is fused, so that the number of channels changes from M to N;

[0234] The predicted classification results are obtained through the fully connected layer and softmax function.

[0235] Assume that the data X fed into the source domain multi-channel model Source_M The format is (B, D, M, T), where B represents the number of samples input to the model each time, D represents the feature dimension of each sample input data, M represents the number of channels of each sample input data, and T represents the amount of data of each sample input data;

[0236] Furthermore, when the selected network layer is a two-dimensional convolutional layer, three two-dimensional convolutional layers with different filter sizes are selected, namely (1, T1), (1, T2) and (1, T3), with a dimension of F1, which means that in each filter, features of T1, T2 and T3 data points will be extracted respectively, and the extracted dimensions are all F1 with a step size of 1; the padding parameter of the two-dimensional convolutional layer is set to 0, that is, the data is padded with 0; the formula is as follows:

[0237]

[0238] in, is the output of CNN, w is the weight of the neuron, b is the bias, and f is the activation function;

[0239] When the selected network layer is a fully connected network, such as Figure 5 As shown in the figure, the fully connected network consists of 4 convolutional layers with filter size (C, 1) and dimension F2, and two average pooling layers with size (Cavg, 1). Cavg represents the pooling range, and the average value of Cavg data is calculated each time with a step size of 5. When the feature with dimension F1 is input into the convolutional layer in the fully connected network, the newly acquired F2 dimension will be added to the original F1 dimension feature as a new feature and sent to the next convolutional layer. Therefore, the feature dimension of the final fully connected network output is F3 = F2*4 + F1.

[0240] When the selected network layer is the graph neural network convolution layer, the adjacency matrix of the graph neural network is A Initial The Pearson index P is initialized by calculating the features output by the fully connected network. The specific formula is as follows:

[0241]

[0242]

[0243] Where X i X j represents the i-th and j-th input features, cov() calculates the covariance matrix, and var() calculates the variance. In order to make the parameters of the adjacency matrix learnable, in the matrix A Initial Add an additional matrix A consisting of learnable weights W trainable , and finally output the eigenvalue through the relu function. The specific formula is as follows:

[0244]

[0245]

[0246] In order to integrate the information of each channel according to the weight of the adjacency matrix A, the matrix A needs to be normalized. The specific formula is as follows:

[0247]

[0248]

[0249] where D is the degree matrix, is the normalized adjacency matrix. Then use the Flatten layer to flatten and expand to get F SourceM_channels At this time, the feature has a total of M input channels. In order to match the number of channels in the target domain, the M channels need to be filtered to N channels, and then sent to the softmax classification layer to calculate the loss value through the loss function and output the classification result.

[0250] Furthermore, if Figure 6 As shown, the step of sending the preprocessed source domain data into the source domain few-channel model for one training includes:

[0251] The preprocessed source domain few-channel data is sent to the source domain few-channel model in batches for training, with the number of samples in each batch being 16;

[0252] Set the number of iterations i to 0, the number of early stopping iterations j to 0, and the learning rate to 0.001;

[0253] Update the source domain few-channel model parameters;

[0254] Calculate and save the validation set loss. If i is 0, save the first training set loss result as the minimum training loss value, and stop the number of early iterations j+1;

[0255] Compare the loss of the i-th training set with the minimum training loss value saved in history. If the loss of the i-th training set is smaller, the training loss value is saved as the minimum training loss value, and the number of early stopping iterations j is reset to 0; if the loss of the i-th training set is larger, the training loss value is not saved as the minimum training loss value, and the number of early stopping iterations is j+1;

[0256] When the number of early stopping iterations j reaches 50, the source domain few-channel model with the minimum training loss value is saved;

[0257] The number of iterations is updated to i+1;

[0258] When the number of iterations is less than 500, continue the loop iteration;

[0259] When the number of iterations reaches or exceeds 500, even if the number of early stopping iterations is less than 50, the source domain few-channel model with the minimum training loss value is still saved.

[0260] Furthermore, if Figure 7 As shown in Figure 1, the input of the source domain few-channel model training method is the preprocessed source domain few-channel data. The model structure is similar to the source domain multi-channel model, except that:

[0261] The number of channels of the source domain few-channel data is already N, so there is no need to change the number of channels after using the graph neural network to extract channel space features and fuse the channel information.

[0262] When the selected network layer is a graph neural convolution layer, the feature obtained by flattening the Flatten layer is called F Source N_channels By reducing the feature distribution distance, the source domain multi-channel model information can be transferred to the source domain few-channel model. The loss value loss calculated by the Coral function align as follows:

[0263]

[0264] in Represents the covariance matrix of the feature matrix in C, each time F is calculated SourceM _ channels and F Source N_channels The distance of the covariance matrix between them is input into the final loss function:

[0265] loss all (y p ,y t )=loss cls +loss align

[0266] Among them, m represents the number of classification labels, y p Represents the model prediction label, y t Represents the true label.

[0267] Furthermore, if Figure 8 As shown, the migration fine-tuning method comprises the following steps:

[0268] Use the pre-trained source domain few-channel model as the baseline model, and the migration model will relearn the parameters on this baseline model;

[0269] The preprocessed target domain few-channel data is sent to the migration model in batches for training, with 16 samples in each batch;

[0270] Set the number of iterations i to 0, the number of early stopping iterations j to 0, and the learning rate to 0.001;

[0271] Update migration model parameters;

[0272] Calculate and save the validation set loss. If i is 0, save the first training set loss result as the minimum training loss value, and stop the number of early iterations j+1;

[0273] Compare the loss of the i-th training set with the minimum training loss value saved in history. If the loss of the i-th training set is smaller, the training loss value is saved as the minimum training loss value, and the number of early stopping iterations j is reset to 0; if the loss of the i-th training set is larger, the training loss value is not saved as the minimum training loss value, and the number of early stopping iterations is j+1;

[0274] When the number of early stopping iterations j reaches 50, the migration model with the minimum training loss value is saved;

[0275] The number of iterations is updated to i+1;

[0276] When the number of iterations is less than 500, continue the loop iteration;

[0277] When the number of iterations reaches or exceeds 500, the migration model with the minimum training loss value is saved even if the number of early stopping iterations is less than 50;

[0278] The above is only a preferred specific embodiment of the present invention, but the protection scope of the present invention is not limited thereto. Any changes or substitutions that can be easily thought of by a person skilled in the art within the technical scope disclosed by the present invention should be included in the protection scope of the present invention. Therefore, the protection scope of the present invention should be based on the protection scope of the claims.

Claims

1. A cross-device motor imagery EEG modeling method based on graph neural network, characterized in that: The following steps are involved: (1) EEG data preprocessing: Divide the EEG data into training set and test set; Among them, the training set has M EEG channels, the test set has N EEG channels, and M>N; (2) Source domain multi-channel model training: The training set data is sent to the source domain multi-channel model for training. The predicted classification results are obtained through training. The training loss value of the predicted classification results and the true classification results is calculated using the cross entropy function. Then, the parameters of the source domain multi-channel model are reversely updated. The model learning feature points are ; (3) Source domain few-channel model training: Select channels in the training set data so that the number and position of EEG channels are consistent with those in the test set; The training set data of the screened N EEG channels is input into the source domain few-channel model for training; the predicted classification results are obtained through training, and the classification loss value of the predicted classification results and the actual classification results is calculated using the cross entropy function ; Feature points learned from the source domain multi-channel model In-domain classification features learned from the source domain few-channel model , calculate the distillation loss value through the Coral function ; The classification loss value and distillation loss Add together to get the final model loss , through the final model loss Reverse gradient updates the source domain few-channel model to obtain a pre-trained source domain few-channel model; (4) Migration fine-tuning: The test set data set of N EEG channels is divided into two parts: training and testing. The training part is sent to the pre-trained source domain few-channel model for retraining to obtain a transfer fine-tuning model. The predicted classification results are obtained through training, and the training loss value of the predicted classification results and the actual classification results is calculated using the cross entropy function, and then the parameters of the model are updated in reverse. When the migration and fine-tuning model parameters are updated, some pre-trained weight parameters are frozen and the remaining weight parameters are iteratively updated; the final model is verified in the test part of the test set.

2. The cross-device motor imagery EEG modeling method based on graph neural network according to claim 1 is characterized in that: The steps of preprocessing the EEG data include: Perform baseline removal on EEG data; Frequency domain filtering is performed using a 5th order Butterworth filter; Normalization is performed using the Z-Score algorithm; the Z-Score algorithm is: ; in, is the input data, z is all the data points of each channel in each EEG sample, is the mean of this set of data points, is the standard deviation of this set of data points.

3. The cross-device motor imagery EEG modeling method based on graph neural network according to claim 1 is characterized in that: The steps of training the source domain multi-channel model include: The training set multi-channel data is sent to the source domain multi-channel model in batches for training, with 16 samples in each batch; Set the number of iterations i to 0, the number of early stopping iterations j to 0, and the learning rate to 0.001; Update source domain multi-channel model parameters; Calculate and save the validation set loss. If i is 0, save the first training set loss result as the minimum training loss value, and stop the number of early iterations j+1; Compare the loss of the i-th training set with the minimum training loss value saved in history. If the loss of the i-th training set is smaller, save the current training loss value as the minimum training loss value, and reset the number of early stopping iterations j to 0; if the loss of the i-th training set is larger, then the current training loss value is not saved as the minimum training loss value, and the number of early stopping iterations is j+1; When the number of early stopping iterations j reaches 100, the source domain multi-channel model with the minimum training loss value is saved; The number of iterations is updated to i+1; When the number of iterations is less than 800, continue the loop iteration; When the number of iterations reaches or exceeds 800, the source domain multi-channel model with the minimum training loss value is saved.

4. The cross-device motor imagery EEG modeling method based on graph neural network according to claim 3 is characterized in that: The step of sending the training set multi-channel data in batches into the source domain multi-channel model for training includes: The data is passed through a two-dimensional convolutional layer to obtain temporal features; Further extract the temporal features through the fully connected network; The channel space features are extracted through the graph neural convolution layer, and the channel information is fused to change the number of channels from M to N; The predicted classification results are obtained through the fully connected layer and softmax function.

5. The cross-device motor imagery EEG modeling method based on graph neural network according to claim 1 is characterized in that: The steps of training the source domain few-channel model include: The training set few-channel data is sent to the source domain few-channel model in batches for training, with 16 samples in each batch; Set the number of iterations i to 0, the number of early stopping iterations j to 0, and the learning rate to 0.001; Update the source domain few-channel model parameters; Calculate and save the validation set loss. If i is 0, save the first training set loss result as the minimum training loss value, and stop the number of early iterations j+1; Compare the i-th training set loss with the historically saved minimum training loss value. If the i-th training set loss is smaller, save the training loss value as the minimum training loss value, and reset the number of early stopping iterations j to 0; if the i-th training set loss is larger, do not save the training loss value as the minimum training loss value, and reset the number of early stopping iterations j+1; When the number of early stopping iterations j reaches 50, the source domain few-channel model with the minimum training loss value is saved; The number of iterations is updated to i+1; When the number of iterations is less than 500, continue the loop iteration; When the number of iterations reaches or exceeds 500, the source domain few-channel model with the minimum training loss value is saved.

6. The cross-device motor imagery EEG modeling method based on graph neural network according to claim 1 is characterized in that: The migration fine-tuning steps include: Using the pre-trained training set few-channel model as the benchmark model, the migration model relearns the parameters on the benchmark model; The few-channel data of the test set are sent to the migration model in batches for training, with 16 samples in each batch; Set the number of iterations i to 0, the number of early stopping iterations j to 0, and the learning rate to 0.001; Update migration model parameters; Calculate and save the validation set loss. If i is 0, save the first training set loss result as the minimum training loss value, and stop the number of early iterations j+1; Compare the loss of the i-th training set with the minimum training loss value saved in history. If the loss of the i-th training set is smaller, save the current training loss value as the minimum training loss value, and reset the number of early stopping iterations j to 0; if the loss of the i-th training set is larger, do not save the current training loss value as the minimum training loss value, and reset the number of early stopping iterations j+1; When the number of early stopping iterations j reaches 50, the migration model with the minimum training loss value is saved; The number of iterations is updated to i+1; When the number of iterations is less than 500, continue the loop iteration; When the number of iterations reaches or exceeds 500, the migration model with the minimum training loss value is saved.