Cross-subject electroencephalogram emotion recognition model training method, emotion recognition method and device

By employing dynamic feature modulation and adversarial domain invariant learning, the cross-subject generalization ability of the EEG emotion recognition model was improved, addressing the issues of individual differences and environmental interference. This resulted in highly robust and real-time emotion recognition, making it suitable for scenarios such as online education.

CN121723239APending Publication Date: 2026-03-24BEIJING UNIV OF POSTS & TELECOMM +1
View PDF 0 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-10-28
Publication Date
2026-03-24

AI Technical Summary

Technical Problem

Traditional EEG emotion recognition models have low recognition accuracy in cross-subject scenarios, cannot effectively adapt to the physiological differences and neural response heterogeneity of different individuals, and lack real-time performance and stability, which limits their application in diverse application scenarios.

Method used

By employing a dynamic feature modulation module, a shared encoder, a conditional diffusion reconstruction module, an adversarial domain invariant learning module, and a lightweight classifier, the model's cross-subject generalization ability and real-time performance are improved through feature modulation, noise injection, and adversarial learning.

Benefits of technology

It achieves high robustness and real-time performance of cross-subject EEG emotion recognition model, which is suitable for application scenarios with high real-time requirements such as online education, and provides a high robust emotion computing solution with zero-sample cold start.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121723239A_ABST
    Figure CN121723239A_ABST
Patent Text Reader

Abstract

The invention provides a cross-subject brain electrical emotion recognition model training method and an emotion recognition method and device.The method comprises the steps that emotion related features are enhanced through a parallel channel-frequency band attention mechanism of a dynamic feature modulation module, controlled noise is introduced through a conditional diffusion reconstruction module, and noise is reversely denoised and reconstructed; constructing a loss guide sharing encoder to update and realize tested noise decoupling, combining a gradient inversion layer of a resistance domain invariant learning module, obtaining domain invariant features based on training, introducing a data source classification task to perform adversarial learning, introducing an inversion coefficient to the gradient of a domain discriminator during back propagation, and returning the inversion coefficient to the sharing encoder; and forcing the shared encoder to ignore features related to individual characteristics, and finally predicting emotion classification through a lightweight classifier. According to the method, performance degradation caused by individual physiological differences can be avoided, the accuracy of cross-subject emotion recognition is improved, and a zero-sample cold start and high-robustness emotion recognition scheme is provided for scenes with high real-time requirements.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the fields of artificial intelligence, brain-computer interfaces and emotion computing, and in particular to a method for training a cross-subject EEG emotion recognition model, an emotion recognition method and device. Background Technology

[0002] In the fields of artificial intelligence and brain-computer interface technology, emotion recognition methods based on electroencephalography (EEG) have shown great application potential. EEG technology can capture brain activity in real time, providing a non-invasive solution for monitoring and analyzing emotional states. However, in existing technologies, the application of these methods in cross-subject scenarios faces a series of key challenges.

[0003] Traditional EEG emotion recognition models can achieve a recognition accuracy of 90% in single-subject scenarios, but when the model needs to adapt to new subjects, its recognition accuracy drops significantly to only 60-70%. This stems from two core issues: individual physiological differences, such as signal amplitude drift caused by skull thickness and electrode impedance (inter-individual variance reaching ±30μV); and heterogeneity of neural responses, for example, under the same emotional stimulus, the correlation between prefrontal activation patterns is only 0.41 among different individuals.

[0004] To address these challenges, existing mainstream solutions include domain adaptation methods, multimodal fusion methods, and manual noise injection methods. Domain adaptation methods require unlabeled EEG data from the target subjects for fine-tuning, which cannot meet the needs of some applications with high real-time requirements. For example, in online education, each new student needs at least 10 minutes of resting-state EEG data for calibration when using the system for the first time.

[0005] Traditional unimodal models, such as RGNN, employ fixed topological coding mechanisms and rely on pre-defined spatial relationships of electrode positions. Once a channel is disrupted, spatiotemporal feature extraction completely collapses. For example, when 25% of the electrodes detach due to head rotation, the model's accuracy drops from a baseline of 71.65% to 53.1%. Multimodal fusion methods, by integrating EEG, eye movements, or facial expressions, can improve recognition rates, but at the cost of high computational load. Furthermore, these methods are susceptible to interference from environmental factors such as facial occlusion. For instance, the AttGraph model integrates EEG signals and eye movement data to improve emotion recognition, but with 12.7M parameters and an inference latency exceeding 1200ms on a Jetson Nano edge device, it is unsuitable for applications requiring real-time interaction, such as online education where the model's real-time interaction threshold must be less than 500ms.

[0006] Manual noise injection methods, such as DMMR, enhance generalization through hybrid reconstruction modules. However, because the noise patterns used in DMMR are artificially preset, they are difficult to accurately simulate real-individual variations. For example, in real-world applications, the electrode contact impedance abruptly caused by subject head movement exceeds 10kΩ, leading to channel signal drift; actions such as swallowing or blinking introduce non-stationary electromyographic interference, the amplitude of which ( Far exceeding emotion-related Band signal amplitude ( Models employing manual noise injection methods often inject linear noise, which fails to capture the two types of nonlinear time-varying features mentioned above. This results in a cross-subject recognition standard deviation as high as 8.01% on the SEED-IV dataset, with a difference of 16.1 percentage points between the maximum and minimum values, making them unsuitable for some application scenarios with high stability requirements.

[0007] Therefore, despite significant progress in single-subject emotion recognition technology, major challenges remain in cross-subject generalization. The limitations of existing technologies in handling individual differences and complex environmental interference restrict their application in diverse scenarios, such as online education and telemedicine, where real-time performance is crucial. Summary of the Invention

[0008] In view of this, embodiments of the present invention provide a method for training a cross-subject EEG emotion recognition model, an emotion recognition method, and an apparatus to eliminate or improve one or more defects existing in the prior art. This addresses the problems of insufficient cross-subject generalization ability, poor real-time performance, and low stability in existing EEG emotion recognition technologies.

[0009] One aspect of the present invention provides a method for training a cross-subject EEG emotion recognition model, the method comprising the following steps: A training sample set containing multiple samples is obtained. Each sample comes from multiple subjects. Each sample contains the EEG signal of one subject and adds a subject identifier as the first label and an emotion classification as the second label. The EEG signal is a three-dimensional EEG tensor based on channels, frequency bands and time steps. The system comprises a dynamic feature modulation module, a shared encoder, a conditional diffusion reconstruction module, a shared decoder, an adversarial domain-invariant learning module, and a lightweight classifier. The EEG signal is input into the dynamic feature modulation module, where it undergoes parallel processing via channel attention and frequency band attention branches before feature modulation and reshaping to obtain weighted features. These weighted features are then processed by the shared encoder to output a latent representation. The conditional diffusion reconstruction module uses this latent representation as input, injecting controlled noise step-by-step through cosine scheduling during forward diffusion, and performing step-by-step denoising based on a Transformer encoder during backward conditional denoising, outputting predicted noise through the shared decoder. The adversarial domain-invariant learning module averages the latent representation output by the shared encoder along the time dimension to obtain sample-level features, which are then output by a domain discriminator to predict the subject's origin. The domain discriminator introduces a gradient inversion layer that identically transmits sample set features during forward propagation and introduces inversion coefficients to the gradient of the domain discriminator during backward propagation, feeding them back to the shared encoder. The latent representation output by the shared encoder is input into the lightweight classifier to output a predicted emotion classification. A first loss is constructed based on the deviation between the controlled noise and the predicted noise; a second loss is constructed based on the deviation between the predicted subject source and the first label; a third loss is constructed based on the predicted emotion classification and the second label; the dynamic feature modulation module, the shared encoder, the conditional diffusion reconstruction module, the shared decoder, the adversarial domain invariant learning module, and the lightweight classifier are trained using the training sample set, wherein the shared encoder and the domain discriminator are alternately optimized, the second loss is minimized to update the domain discriminator, the second loss is maximized to update the shared encoder, and the first loss and the third loss are minimized to update global parameters; The dynamic feature modulation module, the shared encoder, and the lightweight classifier obtained after parameter updates are combined into a cross-subject EEG emotion recognition model.

[0010] In some embodiments of the present invention, the channel attention branch includes a continuously configured average pooling layer, a multilayer perceptron, and a first activation function layer, used to output the channel attention weights of the EEG data, expressed as: in, This represents the channel attention weight; This represents the electroencephalogram (EEG) signal; This indicates that the EEG signal is averaged and pooled. This refers to the multilayer perceptron; Represents the Sigmoid function; The frequency band attention branch includes consecutively configured 1D convolutional layers, max pooling layers, and a second activation function layer, used to output the frequency band attention weights, expressed as follows: in, This represents the frequency band attention weight; This indicates that a one-dimensional convolution operation is performed on the aforementioned EEG signal; This represents the global max pooling operation; The formula for calculating the weighted feature is: in, This represents the weighted feature; This represents an element-wise multiplication operation; This represents the transpose of the frequency band attention weights.

[0011] In some embodiments of the present invention, controlled noise is injected stepwise during forward diffusion using cosine scheduling, as calculated by: ; ; ; Where t is the current diffusion step number, and its value ranges from 1 to 10. , This represents the total number of diffusion steps; Indicates Gaussian noise; Indicates the first Noise samples after step diffusion; Indicates the first Noise samples of the first step, initial This is the latent characterization; In the inverse conditional denoising process, denoising is performed step-by-step based on the Transformer encoder and the predicted noise is output through the shared decoder, including: The time-step embedding is calculated using the following formula: Where t is the current diffusion step number, and its value ranges from 1 to 10. , This represents the total number of diffusion steps; This represents the generated time-step embedding vector, used to label the current diffusion step. Location; This represents the total dimension of the embedding vector; This represents a dimension index variable used for iterating through dimensions. Half of; The latent representation is used as an emotional semantic conditional vector, and the calculation formula is: Where c represents the emotional semantic condition vector; This represents the weighted feature; This refers to the shared encoder; This represents a linear transform layer; C represents the number of channels, B represents the number of bandwidths, and T represents the time step. The noise sample corresponding to each time step, the time step embedding, and the sentiment semantic conditional vector are input into the Transformer encoder to output the predicted noise.

[0012] In some embodiments of the present invention, the first loss is the expectation of the mean square error of the controlled noise and the predicted noise, calculated as follows: in, The controlled noise is described as Gaussian noise. This represents the first loss.

[0013] In some embodiments of the present invention, the domain discriminator introduces a gradient inversion layer that identically transmits sample set features during forward propagation and, during backpropagation, introduces inversion coefficients for the gradient of the domain discriminator back to the shared encoder. These inversion coefficients are dynamically adjusted according to the training phase using a cosine annealing strategy. The gradient calculation formula for the gradient inversion layer during backpropagation is: in, This indicates the second loss; This represents the gradient of the domain discriminator; This indicates the gradient inversion layer's processing of the gradient; This represents the sample-level features; Indicates the inversion coefficient; The inversion coefficient is calculated using the first cosine annealing function during the pre-training phase, and the formula is as follows: Where e represents the current training batch; E represents the total number of training batches; This indicates the maximum value set manually. This indicates the minimum value set manually. The inversion coefficient is calculated using the second cosine annealing function during the fine-tuning stage, and the formula is as follows: The formula for calculating the second loss is: in, This represents the probability distribution of the predicted subject's origin; This indicates the one-hot encoding of the second tag; This represents the cross-entropy loss function.

[0014] In some embodiments of the present invention, the lightweight classifier consists of two fully connected network layers, each followed by an activation function layer, expressed as: in, This represents the sample-level features. This represents the weight matrix of the first fully connected layer of the network; This represents the weight matrix of the second fully connected layer; Indicates a modified linear unit. This represents the probability of the predicted emotion category.

[0015] In some embodiments of the present invention, the method further includes using INT8 quantization to compress the cross-subject EEG emotion recognition model.

[0016] In some embodiments of the present invention, the method further includes: During the pre-training phase, the dynamic feature modulation module, the shared encoder, the conditional diffusion reconstruction module, the shared decoder, the adversarial domain invariant learning module, and the lightweight classifier are jointly optimized via a cloud server to obtain a preliminary cross-subject EEG emotion recognition model. During the fine-tuning phase, the weights of the cross-subject EEG emotion recognition model, excluding the lightweight classifier, are frozen using an edge device, and the parameters of the lightweight classifier are fine-tuned. The formula for calculating the third loss is: in, This refers to the third loss; This indicates the category of emotions. This represents the probability of the predicted emotion category.

[0017] On the other hand, the present invention also provides a method for cross-subject EEG emotion recognition, the method comprising the following steps: The EEG data of the target subject is acquired, wherein the EEG signal is a three-dimensional EEG tensor based on channel, frequency band and time step; The EEG data is input into the cross-subject EEG emotion recognition model obtained by the training method of the cross-subject EEG emotion recognition model, and the emotion recognition result of the target subject is output.

[0018] On the other hand, the present invention also provides a cross-subject EEG emotion recognition device, including a processor, a memory, and a computer program / instructions stored in the memory, wherein the processor is used to execute the computer program / instructions, and when the computer program / instructions are executed, the device implements the steps of the above method.

[0019] This invention discloses a cross-subject EEG emotion recognition model training method, emotion recognition method, and apparatus. The method involves using a dynamic feature modulation module to modulate and reshape EEG signals across channels and frequency bands, followed by latent representation extraction via a shared encoder. A conditional diffusion reconstruction module introduces controlled noise into the latent representation and performs reverse denoising, constructing a loss based on the noise to force the shared encoder to decouple from subject-specific noise. An adversarial domain-invariant learning module is used to introduce a data source classification task for adversarial learning. During backpropagation, the gradient of the domain discriminator is inverted and fed back to the shared encoder, forcing the shared encoder to ignore features related to individual characteristics and focus more on emotion-related features, thereby improving generalization ability.

[0020] Furthermore, in the conditional diffusion reconstruction module, by constructing time-step embeddings and sentiment semantic conditional vectors and performing inverse conditional denoising on noisy samples under their guidance, the noise is reconstructed to establish a loss for parameter tuning of the shared encoder, enabling the shared encoder to more efficiently decouple subject-specific noise.

[0021] Furthermore, a two-stage training protocol and lightweight design are introduced during training. In the pre-training stage, the dynamic feature modulation module, shared encoder, conditional diffusion reconstruction module, shared decoder, adversarial domain invariant learning module, and lightweight classifier are jointly trained on a cloud server using a training sample set to learn general representations across subjects. In the fine-tuning stage, the parameters of the dynamic feature modulation module, shared encoder, conditional diffusion reconstruction module, shared decoder, and adversarial domain invariant learning module are frozen at the end of pre-training, and only the two fully connected layers of the classifier are updated. This enables rapid deployment of the pre-trained model in practical applications, rapid adaptation to data characteristics in specific scenarios, and saves computing resources on edge nodes.

[0022] This invention effectively solves the performance degradation problem of traditional EEG emotion recognition models caused by individual physiological differences in cross-subject scenarios, and provides a zero-sample cold start and highly robust emotion computing solution for application scenarios with high real-time requirements such as online education.

[0023] Additional advantages, objects, and features of the invention will be set forth in part in the description which follows, and will also become apparent in part to those skilled in the art upon studying the description, or may be learned by practice of the invention. The objects and other advantages of the invention can be realized and obtained by means of the structures specifically pointed out in the description and drawings.

[0024] Those skilled in the art will understand that the objectives and advantages achievable with the present invention are not limited to those specifically described above, and that the above and other objectives achievable with the present invention will become clearer from the following detailed description. Attached Figure Description

[0025] The accompanying drawings, which are included to provide a further understanding of the invention and form part of this application, are not intended to limit the scope of the invention. The components in the drawings are not drawn to scale but are merely illustrative of the principles of the invention. For ease of illustration and description of certain parts of the invention, corresponding portions in the drawings may be enlarged, i.e., may appear larger relative to other components in an exemplary device actually manufactured according to the invention. In the drawings: Figure 1 This is a flowchart of a cross-subject EEG emotion recognition model training method in one embodiment of the present invention.

[0026] Figure 2 This is a flowchart of dynamic feature modulation in another embodiment of the present invention.

[0027] Figure 3 This is a flowchart of the forward diffusion process in another embodiment of the present invention.

[0028] Figure 4 This is a diagram illustrating the collaborative framework of generative feature reconstruction and adversarial domain generalization in another embodiment of the present invention.

[0029] Figure 5 This is a flowchart of the reverse conditional denoising process in another embodiment of the present invention. Detailed Implementation

[0030] To make the objectives, technical solutions, and advantages of this invention clearer, the invention will be further described in detail below with reference to the embodiments and accompanying drawings. Here, the illustrative embodiments and descriptions of this invention are used to explain the invention, but are not intended to limit the invention.

[0031] It should also be noted that, in order to avoid obscuring the invention with unnecessary details, only the structures and / or processing steps closely related to the solution according to the invention are shown in the accompanying drawings, while other details that are not closely related to the invention are omitted.

[0032] It should be emphasized that the term "including / comprises" as used herein refers to the presence of a feature, element, step, or component, but does not exclude the presence or addition of one or more other features, elements, steps, or components.

[0033] It should also be noted that, unless otherwise specified, the term "connection" in this article can refer not only to a direct connection, but also to an indirect connection involving an intermediary.

[0034] In the following description, embodiments of the invention will be illustrated with reference to the accompanying drawings. In the drawings, the same reference numerals represent the same or similar parts, or the same or similar steps.

[0035] While current EEG emotion recognition technology has made significant progress in single-subject scenarios, it still faces major challenges in cross-subject generalization. Existing technologies are insufficient in handling individual differences and complex environmental interference, and their poor real-time performance and low stability also limit their application in diverse scenarios.

[0036] To address the problems existing in the prior art, this invention provides a method for training a cross-subject EEG emotion recognition model, the flowchart of which is shown below. Figure 1 As shown, the method includes the following steps S101~S104: S101: Obtain a training sample set containing multiple samples, each sample being derived from multiple subjects. Each sample contains the EEG signal of one subject, and adds a subject identifier as the first label and an emotion classification as the second label. The EEG signal is a three-dimensional EEG tensor based on channels, frequency bands, and time steps.

[0037] S102: Acquires a dynamic feature modulation module, a shared encoder, a conditional diffusion reconstruction module, a shared decoder, an adversarial domain-invariant learning module, and a lightweight classifier. The EEG signal is input into the dynamic feature modulation module, where it is processed in parallel by channel attention branches and frequency band attention branches before feature modulation and reshaping to obtain weighted features. These weighted features are processed by the shared encoder to output latent representations. The conditional diffusion reconstruction module takes these latent representations as input, injects controlled noise step-by-step through cosine scheduling during forward diffusion, and performs step-by-step denoising based on the Transformer encoder during backward conditional denoising, outputting predicted noise through the shared decoder. The adversarial domain-invariant learning module averages the latent representations output by the shared encoder along the time dimension to obtain sample-level features, which are then output by the domain discriminator to predict the subject's origin. The domain discriminator introduces a gradient inversion layer that identically transmits sample set features during forward propagation and introduces inversion coefficients to the gradient of the domain discriminator during backward propagation, feeding them back to the shared encoder. The latent representations output by the shared encoder are input into the lightweight classifier to output a predicted emotion classification.

[0038] S103: Construct a first loss based on the deviation between controlled noise and predicted noise; construct a second loss based on the deviation between the predicted subject source and the first label; construct a third loss based on the predicted emotion classification and the second label; train the dynamic feature modulation module, shared encoder, conditional diffusion reconstruction module, shared decoder, adversarial domain invariant learning module, and lightweight classifier using the training sample set, wherein the shared encoder and domain discriminator are alternately optimized, the second loss is minimized to update the domain discriminator, the second loss is maximized to update the shared encoder, and the first and third losses are minimized to update the global parameters.

[0039] S104: The dynamic feature modulation module, shared encoder, and lightweight classifier obtained after parameter update are combined into a cross-subject EEG emotion recognition model.

[0040] In step S101, the training sample set contains EEG signal data from multiple subjects. Each sample corresponds to the EEG recording of a subject in a specific emotional state. A first label is used to distinguish different individuals, and a second label is used to label the emotional category of the sample, classifying the emotions. The raw EEG signals are preprocessed based on channels, frequency bands, and time steps, and converted into a three-dimensional EEG tensor.

[0041] In some embodiments, the preprocessing process includes the following steps: The time-domain signal acquired by the wearable EEG signal device was segmented by a sliding time window, with a window length of 15 seconds and a step size of 0.5 seconds.

[0042] For each time window, the differential entropy and relative spectral density of the signal are calculated, and five characteristic frequency bands are extracted, namely... Wave, Wave, Wave, wave and Wave, in which: The wave correspondence The frequency band primarily reflects deep relaxation and unconscious states.

[0043] The wave correspondence Frequency bands are closely related to working memory load and cognitive effort.

[0044] The wave correspondence Frequency bands characterize the processes of relaxation, alertness, and emotion regulation.

[0045] The wave correspondence Frequency bands indicate focused states and active cognitive processing.

[0046] The wave correspondence Frequency bands are associated with higher-order cognitive integration and emotional arousal.

[0047] A three-dimensional EEG tensor is constructed, wherein the three-dimensional EEG tensor has 62 channels, 5 frequency bands, and 30 time steps, and is represented as follows: ; Where C represents the number of channels, B represents the number of frequency bands, and T represents the time step; The training sample set data is divided into target domain data and source domain data. The single subject data reserved is the target domain data, and the remaining subject data is the source domain data.

[0048] In step S102, the flowchart of dynamic feature modulation is as follows: Figure 2 As shown, the dynamic feature modulation module takes the preprocessed EEG signal as input, performs feature enhancement processing on the input EEG signal through parallel channel attention branch and frequency band attention branch, and performs weighted fusion on the outputs of the channel attention branch and frequency band attention branch. The EEG signal is then weighted and reshaped by combining the input EEG signal with the weighted fusion result, and weighted features are output.

[0049] The dynamic feature modulation module is the core innovative module of this invention, playing a key role in enhancing biometric features. Its core objective is to focus on key brain regions related to emotion (such as the prefrontal cortex) and specific frequency bands (such as high arousal). (Band), significantly improving the recognizability of emotional signals against the background of electromyographic interference.

[0050] In some embodiments, the channel attention branch includes a sequentially configured average pooling layer, a multilayer perceptron, and a first activation function layer, used to output the channel attention weights of the EEG data, expressed as: in, This represents the channel attention weight; This represents the electroencephalogram (EEG) signal; This indicates that the EEG signal is averaged and pooled. This refers to the multilayer perceptron; This represents the Sigmoid function.

[0051] Channel attention branches utilize multilayer perceptron and average pooling operations to process input EEG signals, and then activate them through the Sigmoid function to generate channel attention weights. This operation strengthens signals in brain regions related to emotion regulation, especially the prefrontal cortex, which is the core brain region for emotion regulation.

[0052] In some embodiments, the frequency band attention branch includes a sequentially configured 1D convolutional layer, a max-pooling layer, and a second activation function layer, used to output the frequency band attention weights, expressed as follows: in, This represents the frequency band attention weight; This indicates that a one-dimensional convolution operation is performed on the EEG signal, with the kernel size set to 3. This indicates a global max pooling operation.

[0053] The frequency band attention branch uses one-dimensional convolution to analyze the coupling relationship between frequency bands and increase the weights of frequency bands related to emotional arousal, especially... For each band, the convolution output is processed using global max pooling and the Sigmoid function to generate band attention weights.

[0054] In some embodiments, the weight fusion process combines the outputs of the channel attention branch and the frequency band attention branch to form a comprehensive weight vector. This vector reflects the importance of different channels and frequency bands in emotion expression, and its calculation formula is as follows: in, This represents the transpose of the frequency band attention weights; This indicates the fusion weight.

[0055] In some embodiments, the feature modulation process utilizes the aforementioned fusion weights to reshape the input EEG signal using weighted weighting. The contribution of each channel and frequency band of the input EEG signal is adjusted through element-wise multiplication to obtain weighted features. The formula for calculating the weighted features is as follows: in, This represents the weighted feature; This indicates an element-wise multiplication operation.

[0056] The prefrontal region of the EEG signal processed by the dynamic feature modulation module Band activity was significantly enhanced, emotion-independent interference noise was suppressed, and the signal-to-noise ratio of emotion-related signals was improved by 3.2 dB.

[0057] The shared encoder is responsible for processing the weighted features output by the dynamic feature modulation module, encoding the weighted features, and extracting latent representations that can represent key information of the input data.

[0058] After the source domain data and target domain data in the training sample set are modulated by the dynamic feature modulation module, they are input into the shared encoder. The shared encoder performs exactly the same operation on the input source domain data or target domain data, but the uses of its output results are different. Specifically: The source domain data is processed by a dynamic feature modulator to output weighted features, which are then processed by a shared encoder to output latent representations, which are used for forward diffusion and noise prediction training.

[0059] In some embodiments, the above latent representation can be expressed as: ; The data in the target domain is processed by a dynamic feature modulator to output weighted features, which are then processed by a shared encoder to output latent representations used as sentiment semantic conditional vectors.

[0060] In some embodiments, the above-mentioned sentiment semantic condition vector can be represented as: ; The formula for calculating the above sentiment semantic condition vector is: Where c represents the sentiment semantic condition vector; This represents the weighted feature; This refers to the shared encoder; This represents the linear transform layer; C represents the number of channels, which is 256 here; B represents the number of frequency bands; and T represents the time step.

[0061] The conditional diffusion reconstruction module is the innovative core of this invention. It solves the problem of individual variation through generative modeling. Using the aforementioned latent representations as input, it achieves cross-subject noise decoupling and emotional feature enhancement through two-stage processing of forward diffusion and reverse conditional denoising.

[0062] The forward diffusion process is as follows: Figure 3 As shown, in the forward diffusion stage, controlled noise is injected sequentially according to a preset cosine scheduling function to recursively generate noise samples.

[0063] In some embodiments, the formula for recursively generating noise samples is: ; ; ; Where t is the current diffusion step number, and its value ranges from [value range missing]. , This represents the total number of diffusion steps; Indicates Gaussian noise; Indicates the first Noise samples after step diffusion; Indicates the first Noise samples of the first step, initial This is the latent representation.

[0064] Forward diffusion evolves continuously from the true data distribution to a state of pure noise.

[0065] The reverse conditional denoising process flow is as follows: Figure 5 As shown, the process is guided by the emotional semantic conditional vector. Through the Transformer encoder, features are fused from the noise sample, the time step embedding, and the emotional semantic conditional vector. Through the multi-head self-attention mechanism, the subject-specific noise is decoupled from the noise sample based on the emotional semantic information of the conditional vector, and the denoised features are output. The multi-head self-attention layer of the Transformer encoder mentioned above has an embedded electrode distance prior matrix to enhance the model's robustness to spatial topology.

[0066] In some embodiments, the formula for calculating the electrode distance prior matrix is: ; in, Indicates electrode and Three-dimensional Euclidean distance (unit: millimeters) in the international 10-20 system standard head model; This represents a learnable scale parameter used to control the intensity of spatial distance attenuation, with a value of 0.15. This represents the numerical stability constant, with a value of 0.01. Represents the natural exponential function; This represents the prior matrix of electrode distance.

[0067] When calculating attention weights, As a bias term, the model prioritizes information from physically adjacent electrodes. For example, when the distance between FP1-FP2-Fz in the prefrontal cortex is less than 40 mm, the corresponding weight is greater than 0.9. Even if 25% of the channels fail due to head movement (e.g., FP1 detachment), the model can still utilize the high-weight information from adjacent electrodes (FPz, AF3) to reconstruct physiologically reasonable spatiotemporal features and maintain reasoning continuity through a multi-head self-attention mechanism. The calculation formula for the multi-head self-attention is: ; in, Represents the query matrix; Represents the key matrix; Represents a value matrix; Represents the query-key similarity matrix; Indicates matrix transpose; This represents the prior matrix for electrode distance; Indicates the scaling factor; This represents the feature matrix to be weighted and aggregated. This represents the normalization function.

[0068] In some embodiments, the formula for calculating the predicted noise is: in, This represents the predicted noise.

[0069] The above time step embedding maps discrete diffusion steps to a 128-dimensional continuous vector through sinusoidal position encoding, ultimately obtaining a time step embedding that matches the shape of the noise sample.

[0070] In some embodiments, the time step embedding is calculated as follows: in, This represents the current diffusion step number, with a value range of... , This represents the total number of diffusion steps; This represents the generated time-step embedding vector, used to label the current diffusion step. Location; This represents the total dimension of the embedding vector; This represents a dimension index variable used for iterating through dimensions. Half of it.

[0071] In some embodiments, 1D-CNN is used instead of Transformer encoder. Although this can reduce computation by about 40%, its limited receptive field makes it difficult to capture long-range dependencies across brain regions, resulting in a 3.2% decrease in cross-subject accuracy on the SEED-IV dataset (from 71.3% to 74.5%).

[0072] In some embodiments, the conditional diffusion reconstruction module in this invention can be replaced by a variational autoencoder, which constrains the latent space distribution through KL divergence. However, the variational autoencoder is difficult to model complex individual variations, and the physiological rationality of the reconstructed samples is significantly reduced (band power error increases by 47%), resulting in a loss of 5.7 percentage points in cross-subject generalization.

[0073] In some embodiments, the conditional diffusion reconstruction module in this invention can be replaced by unsupervised contrastive learning, which constructs sample pairs through the SimCLR framework to avoid the complex computation of generative modeling. However, it requires 10 times the amount of data to achieve the same accuracy and is extremely sensitive to data augmentation strategies. A simple channel shift can cause the accuracy to fluctuate by ±9.1%.

[0074] In some embodiments, the conditional diffusion reconstruction module of the present invention can employ knowledge distillation to compress the amount of data in the model, distilling the 6-layer Transformer encoder into a 2-layer LSTM network. Although this can reduce the number of model parameters by 52%, the noise reconstruction error increases by 12% due to the weakened temporal modeling capability, and the cross-subject stability deteriorates significantly (standard deviation increases to 9.7%). The shared decoder reconstructs the denoised features output by the Transformer encoder and outputs predicted noise, which is represented as: ; in, This is represented as prediction noise.

[0075] The adversarial domain-invariant learning module is the core component of this invention for achieving cross-subject generalization. Its processing flow includes: The latent representations are averaged along the time dimension by using a temporal aggregation unit to obtain sample-level features.

[0076] In some embodiments, the above sample-level features are represented as: ; in, This represents sample-level features.

[0077] The domain discriminator predicts the subject's origin based on the aforementioned sample-level features.

[0078] In some embodiments, the domain discriminator employs a three-layer MLP network architecture to classify the subject origin from the SEED-IV data based on sample-level features.

[0079] By introducing a gradient inversion layer through adversarial game units to learn domain-invariant features, sample-level features are passed identically during forward propagation, and inversion coefficients are introduced into the gradient of the domain discriminator during backpropagation and fed back to the shared encoder. In this way, the shared encoder is trained to generate features that are difficult for the domain discriminator to recognize, thereby improving the generalization ability of the model.

[0080] In some embodiments, the gradient calculation formula for the gradient inversion layer during backpropagation is: in, Indicates the second loss; The gradient of the domain discriminant; This indicates how the gradient inversion layer processes the gradient; Represents sample-level features; This represents the inversion coefficient.

[0081] In some embodiments, the inversion coefficient is dynamically adjusted according to the training phase using a cosine annealing strategy. The first cosine annealing function is used during the pre-training phase, and its calculation formula is: Where e represents the current training batch; E represents the total number of training batches; This indicates the maximum value set manually. This indicates the minimum value set manually. During the fine-tuning stage, the second cosine annealing function is used, and the calculation formula is: Where e represents the current training batch; E represents the total number of training batches; This indicates the maximum value set manually. This indicates the minimum value set manually.

[0082] In some embodiments, the adversarial domain-invariant learning module in this invention can be replaced by a maximum mean difference constraint. By minimizing the feature distribution distance between source domains, the instability of adversarial training can be avoided. However, the kernel function (such as Gaussian kernel bandwidth) needs to be manually designed. Furthermore, the generalization of educational scenarios fluctuated by ±4.3% (compared to ±2.1% for adversarial domain invariant learning modules).

[0083] In some embodiments, the adversarial domain invariant learning module in this invention can be replaced by mutual information minimization, but the computational overhead increases by 47%, making it unsuitable for lightweight deployment scenarios.

[0084] The core of this invention lies in constructing a collaborative framework for generative feature reconstruction and adversarial domain generalization. For example... Figure 4 As shown, the model enhances emotion-related frequency bands through dynamic feature modulation, decouples subject-specific noise through the conditional diffusion reconstruction module, and introduces a gradient reversal layer through the adversarial domain invariant learning module. This forces the model to ignore features related to individual characteristics and focus more on emotion-related features, thereby improving generalization ability and ultimately achieving end-to-end robust mapping of EEG signals from raw input to emotional decision-making.

[0085] In step S103, a first loss is constructed based on the deviation between the controlled noise and the predicted noise. The first loss is the core training objective of the conditional diffusion reconstruction module.

[0086] In some embodiments, the first loss is calculated as follows: in, This represents controlled noise, which is Gaussian noise; Indicates predicted noise; This indicates the first loss.

[0087] A second loss is constructed based on the deviation between the predicted subject source and the first label. This second loss is the core training objective of the adversarial domain invariant learning module.

[0088] In some embodiments, the second loss calculation formula is: in, This represents the probability distribution of the predicted subject's origin; This indicates the one-hot encoding of the second tag; This represents the cross-entropy loss function.

[0089] A third loss is constructed based on the predicted sentiment classification and the second label, and the third loss is the training objective of the lightweight classifier.

[0090] In some embodiments, the lightweight classifier consists of two fully connected network layers, each followed by an activation function layer, expressed as follows: in, Represents sample-level features. This represents the weight matrix of the first fully connected layer of the network; This represents the weight matrix of the second fully connected layer; Indicates a modified linear unit. This represents the probability of the predicted emotion category.

[0091] This invention divides the training process of the cross-subject EEG emotion recognition model into a pre-training stage and a fine-tuning stage.

[0092] In the pre-training phase, the dynamic feature modulation module, shared encoder, conditional diffusion reconstruction module, shared decoder, adversarial domain invariant learning module, and lightweight classifier are jointly trained on a cloud server using a training sample set. The training objective is to simultaneously optimize the six modules on the training sample set to ensure that the final cross-subject EEG emotion recognition model has cross-subject generalization ability. The training process adopts an innovative alternating optimization strategy and verifies the model's performance through the leave-one-out-of-one-out method.

[0093] During the fine-tuning phase, the parameters of the dynamic feature modulation module, shared encoder, conditional diffusion reconstruction module, shared decoder, and adversarial domain invariant learning module at the end of pre-training are frozen, and only the parameters of the lightweight classifier are adjusted to minimize the third loss as the training objective.

[0094] In some embodiments, the alternating optimization process includes: Data from individual subjects in the training sample set are selected sequentially as target domain data and used as the target domain validation set. The remaining subject data in the training sample set are used as source domain data and are used as the source domain training set. Repeat the above partitioning process to ensure that the data of each subject is validated once as a target domain.

[0095] Optimize the domain discriminator by fixing the parameters of the shared encoder and updating only the parameters of the domain discriminator to minimize the second loss. Train the domain discriminator to improve its ability to identify the subject's source from sample-level features. The shared encoder is optimized by fixing the parameters of the domain discriminator and updating the parameters of the shared encoder by introducing a gradient inversion layer. This enables the shared encoder to generate features that cannot distinguish between subjects, thereby gradually eliminating subject information in the sample-level features. Each cycle of adversarial training of the shared encoder parameters and domain discriminator parameters continues to minimize the first and third losses, and the parameters of the dynamic feature modulation module, conditional diffusion reconstruction module, shared decoder, and lightweight classifier are updated synchronously until the accuracy of cross-subject EEG emotion recognition and the discrimination rate of the domain discriminator reach a convergence state.

[0096] In some embodiments, the cross-subject EEG emotion recognition model, after pre-training and fine-tuning phases, can be quantized using INT8, and the model size can be compressed to 35KB or less, making it suitable for some lightweight deployment scenarios and achieving an end-to-end inference latency of 460ms on a Cortex-M7 processor (80MHz).

[0097] The target domain data is used only to verify the model's generalization ability and does not participate in any parameter updates.

[0098] In some embodiments, to further adapt to lightweight deployment scenarios, the dynamic feature modulation module can be statically processed and used with predefined frequency band weights ( , , , This alternative attention mechanism, while reducing computational load by 30%, is unsuitable for special education groups (such as patients with ADHD whose gamma band response is weakened), resulting in an 8.1% decrease in accuracy for this group.

[0099] In step S104, after the model training is completed, the trained dynamic feature modulation module, shared encoder and lightweight classifier are integrated to form the final cross-subject EEG emotion recognition model.

[0100] The dynamic feature modulation module enhances the input EEG signals, highlighting key frequency bands and channel information related to emotion, and outputs weighted features. The shared encoder maps the modulated weighted features to a unified low-dimensional latent space, eliminating the influence of individual differences and outputting latent representations. The lightweight classifier classifies emotional states based on the input latent representations. These three modules work together, enabling the model to directly process EEG data from new subjects without requiring retraining or calibration for individuals, thus achieving cross-subject emotion recognition capabilities.

[0101] On the other hand, the present invention also provides a method for cross-subject EEG emotion recognition, the method comprising the following steps: The EEG data of the target subject is acquired, wherein the EEG signal is a three-dimensional EEG tensor based on channel, frequency band and time step; The EEG data is input into the cross-subject EEG emotion recognition model obtained by the training method of the cross-subject EEG emotion recognition model, and the emotion recognition result of the target subject is output.

[0102] On the other hand, the present invention also provides a cross-subject EEG emotion recognition device, including a processor, a memory, and a computer program / instructions stored in the memory, wherein the processor is used to execute the computer program / instructions, and when the computer program / instructions are executed, the device implements the steps of the above method.

[0103] The present invention will now be described with reference to a specific embodiment: This embodiment verifies the effectiveness of the invention based on the SEED and SEED-IV datasets. The datasets are a mixture of EEG signals from 15 subjects in different emotional states from the SEED and SEED-IV datasets. The emotional states are categorized as: focused, confused, bored, and neutral.

[0104] In the EEG data preprocessing stage, the time-domain signals collected by the subjects through the wearable EEG signal device were segmented by a sliding time window with a window length of 15 seconds and a step size of 0.5 seconds. For each time window, the differential entropy and relative spectral density of the signal are calculated, and five feature frequency bands are extracted. These frequency bands are respectively... wave (corresponding) frequency band) wave (corresponding) frequency band) wave (corresponding) frequency band) wave (corresponding) (frequency band) and wave (corresponding) (frequency band) A three-dimensional EEG tensor is constructed, wherein the three-dimensional EEG tensor has 62 channels, 5 frequency bands, and 30 time steps, and is represented as follows: ; During the model pre-training stage, the dynamic feature modulation module, shared encoder, conditional diffusion reconstruction module, shared decoder, adversarial domain invariant learning module, and lightweight classifier are jointly optimized.

[0105] The dynamic feature modulation module takes the preprocessed EEG signal as input, performs feature enhancement processing on the input EEG signal through parallel channel attention branch and frequency band attention branch, and performs weighted fusion on the output of the channel attention branch and frequency band attention branch. The EEG signal is then weighted and reshaped by combining the input EEG signal with the weighted fusion result, and weighted features are output.

[0106] The channel attention branch includes consecutively configured average pooling layers, multilayer perceptrons, and a first activation function layer, used to output the channel attention weights of the EEG data, expressed as: in, This represents the channel attention weight; This represents the electroencephalogram (EEG) signal; This indicates that the EEG signal is averaged and pooled. This refers to the multilayer perceptron; Represents the Sigmoid function; The frequency band attention branch consists of consecutively configured 1D convolutional layers, max pooling layers, and a second activation function layer, used to output the frequency band attention weights, expressed as: in, This represents the frequency band attention weight; This indicates that a one-dimensional convolution operation is performed on the EEG signal, with the kernel size set to 3. This represents the global max pooling operation; The weight fusion process combines the outputs of the channel attention branch and the frequency band attention branch to form a comprehensive weight vector. This vector reflects the importance of different channels and frequency bands in emotion expression, and its calculation formula is as follows: in, This represents the transpose of the frequency band attention weights; Indicates the fusion weights; The feature modulation process utilizes the aforementioned fusion weights to reshape the input EEG signal using weighted averages. The contribution of each channel and frequency band of the input EEG signal is adjusted through element-wise multiplication to obtain weighted features. The formula for calculating these weighted features is as follows: in, This represents the weighted feature; This represents an element-wise multiplication operation; The prefrontal region of the EEG signal processed by the dynamic feature modulation module Band activity was significantly enhanced, emotion-independent interference noise was suppressed, and the signal-to-noise ratio of emotion-related signals was improved by 3.2 dB.

[0107] The training sample set data is divided into target domain data and source domain data. The single subject data reserved is the target domain data, and the remaining subject data is the source domain data.

[0108] After the source domain data and target domain data in the training sample set are modulated by the dynamic feature modulation module, they are input into the shared encoder. The shared encoder performs the exact same operation on the input source domain data or target domain data, and outputs latent representations, but the uses of their output results are different. Specifically: The source domain data is processed by a dynamic feature modulator to output weighted features, which are then processed by a shared encoder to output latent representations. These latent representations are used for forward diffusion and noise prediction training. The latent representations can be expressed as: ; The data in the target domain is processed by a dynamic feature modulator to output weighted features, which are then processed by a shared encoder to output latent representations, which are used as conditional vectors for sentiment semantics.

[0109] The above sentiment semantic condition vector can be represented as: ; The formula for calculating the above sentiment semantic condition vector is: in, Represents the emotional semantic conditional vector; This represents the weighted feature; This refers to the shared encoder; Indicates a linear transformation layer; This indicates the number of channels, which is 256 here. Indicates the number of frequency bands. Indicates a time step; The conditional diffusion reconstruction module introduces a generative feature reconstruction paradigm. Using the aforementioned latent representations as input, it achieves cross-subject noise decoupling and emotional feature enhancement through two-stage processing of forward diffusion and reverse conditional denoising.

[0110] During the forward diffusion phase, controlled noise is injected sequentially according to a preset cosine scheduling function to recursively generate noise samples, and the forward diffusion continues to evolve from the real data distribution to a pure noise state. The formula for recursively generating noise samples is: ; ; ; in, This represents the current diffusion step number, with a value range of... , This represents the total number of diffusion steps; Indicates Gaussian noise; Indicates the first Noise samples after step diffusion; Indicates the first Noise samples of the first step, initial This is the latent representation.

[0111] The inverse conditional denoising process is guided by the sentiment semantic conditional vector. A Transformer encoder fuses features from noisy samples, temporal embeddings, and the sentiment semantic conditional vector. A multi-head self-attention mechanism decouples participant-specific noise from the noisy samples based on the sentiment semantic information of the conditional vector, outputting denoised features. The cosine similarity of the denoised features across participants of the same emotion category is 0.78, a significant improvement compared to the 0.52 achieved with the baseline manual noise injection scheme.

[0112] The above time-step embedding maps the discrete diffusion steps to a 128-dimensional continuous vector through sinusoidal position encoding, ultimately obtaining a time-step embedding with the same shape as the noise sample. The calculation formula is as follows: in, This represents the current diffusion step number, with a value range of... , This represents the total number of diffusion steps; This represents the generated time-step embedding vector, used to label the current diffusion step. Location; This represents the total dimension of the embedding vector; This represents a dimension index variable used for iterating through dimensions. Half of it.

[0113] The shared decoder reconstructs the denoised features from the Transformer encoder output and outputs predicted noise, represented as: ; in, This is represented as prediction noise.

[0114] The adversarial domain-invariant learning module includes a temporal aggregation unit, a domain discriminator, and an adversarial game unit.

[0115] The latent representations are averaged along the time dimension using a temporal aggregation unit to obtain sample-level features, represented as follows: ; The domain discriminator predicts the subject's origin based on the above sample-level features. The domain discriminator adopts a three-layer MLP network architecture and classifies the subject's origin from the SEED-IV data according to the sample-level features.

[0116] By introducing a gradient inversion layer through adversarial game units to learn domain-invariant features, sample-level features are passed identically during forward propagation, and inversion coefficients are introduced into the gradient of the domain discriminator during backpropagation and fed back to the shared encoder. In this way, the shared encoder is trained to generate features that are difficult for the domain discriminator to recognize, thereby improving the generalization ability of the model.

[0117] The gradient calculation formula for the gradient reversal layer during backpropagation is: in, Indicates the second loss; The gradient of the domain discriminant; This indicates how the gradient inversion layer processes the gradient; Represents sample-level features; This represents the inversion coefficient.

[0118] The aforementioned inversion coefficients are dynamically adjusted according to the training phase using a cosine annealing strategy. During the pre-training phase, the first cosine annealing function is used, and its calculation formula is: Where e represents the current training batch; E represents the total number of training batches; This indicates the maximum value set manually. This indicates the minimum value set manually. The inversion coefficient is calculated using the second cosine annealing function during the fine-tuning stage, and the formula is as follows: Where e represents the current training batch; E represents the total number of training batches; This indicates the maximum value set manually. This indicates the minimum value set manually.

[0119] The first loss is constructed based on the deviation between the controlled noise and the predicted noise, and is calculated as follows: in, This represents controlled noise, which is Gaussian noise; Indicates predicted noise; This indicates the first loss.

[0120] The second loss is constructed based on the deviation between the predicted subject's origin and the first label, and is calculated as follows: in, This represents the probability distribution of the predicted subject's origin; This indicates the one-hot encoding of the second tag; This represents the cross-entropy loss function.

[0121] A third loss is constructed based on the predicted sentiment classification and the second label. The formula for calculating the third loss is: in, This refers to the third loss; This indicates the category of emotions. This represents the probability of the predicted emotion category.

[0122] During pre-training, the model's performance is rigorously evaluated using leave-one-out cross-validation, specifically including: Data from one subject in each training sample set was selected sequentially as the target domain data and used as the target domain validation set. The data from the remaining 14 subjects in the training sample set were used as source domain data and served as the source domain training set. Repeat the above partitioning process to ensure that the data of each subject is validated once as a target domain.

[0123] Optimize the domain discriminator by fixing the parameters of the shared encoder and updating only the parameters of the domain discriminator to minimize the second loss. Train the domain discriminator to improve its ability to identify the subject's source from sample-level features. The shared encoder is optimized by fixing the parameters of the domain discriminator and updating the parameters of the shared encoder by introducing a gradient inversion layer. This enables the shared encoder to generate features that cannot distinguish between subjects, thereby gradually eliminating subject information in the sample-level features. Each cycle of adversarial training involving the shared encoder and domain discriminator parameters continues, minimizing the first and third losses while simultaneously updating the parameters of the dynamic feature modulation module, conditional diffusion reconstruction module, shared decoder, and lightweight classifier. After 150 rounds of adversarial training, the discriminant's resolution stabilizes at a level close to random guessing. The accuracy rate, that is, the discrimination accuracy rate among 15 possible subject categories, is approximately 6.7%, with a fluctuation range (standard deviation) of ±0.8%.

[0124] During the fine-tuning phase, the parameters of the dynamic feature modulation module, shared encoder, conditional diffusion reconstruction module, shared decoder, and adversarial domain invariant learning module are frozen at the end of pre-training. Only the parameters of the lightweight classifier are adjusted, with minimizing the third loss as the training objective. The lightweight classifier employs a two-layer fully connected network. The weight matrix of the first fully connected network... The weight matrix of the second fully connected network The number of parameters is 8448.

[0125] In the actual deployment phase, the trained cross-subject EEG emotion recognition model can be quantized using INT8, and the model size can be compressed to 35KB or less. On a Cortex-M7 processor (80MHz), an end-to-end inference latency of 460ms can be achieved.

[0126] In practical applications, the aforementioned deployed cross-subject EEG emotion recognition model, when used in real-world scenarios, enables new subjects to use the model without calibration, and allows for initial login within 30 seconds, with a short cold start time. Seconds (including device self-test only); On the SEED-IV dataset, it achieved a cross-subject accuracy of 74.5% (a 1.8% improvement compared to the manual noise injection method), with the standard deviation compressed to ≤7.1% (the standard deviation of the accuracy of the manual noise injection method was as high as 8.01%); on the SEED dataset, it achieved a cross-subject accuracy of 87.63%. In terms of anti-interference capability, the cross-subject EEG emotion recognition model still maintained an accuracy of 73.1% when simulating 25% channel failure. In contrast, the accuracy of the traditional RGNN model plummeted from a baseline of 71.65% to 53.1% under the same experimental conditions.

[0127] In specific application scenarios, such as online education, this invention simulates an extreme test with 25% channel failure to address real-world interference such as student head movement and poor device contact. The test results show that the accuracy of the cross-subject EEG emotion recognition model decreased by only 2.8%, while the manual noise injection method decreased by 7.3%. This noise resistance stems from a dual biophysical mechanism: firstly, the Transformer's multi-head self-attention is achieved through the electrode distance matrix... The coding space topology prior allows for the reconstruction of complete brain region activation patterns even with partial channel loss. Secondly, the emotional semantic conditional vector provided by the dynamic feature modulation module serves as a neural oscillation anchor, guiding the conditional diffusion reconstruction module to repair damaged signals—for example, when the FP1 electrode fails, the system relies on the relationship between FP2 and Fz... Band correlation generates physiologically plausible surrogate values. This capability enables the invention to maintain performance fluctuations of ±3% in noisy classroom environments, providing educators with stable and reliable emotional monitoring. Students' emotional states are fed back to educators in real time, driving dynamic adjustments to teaching strategies (e.g., confusion triggers a restructuring of knowledge point explanations).

[0128] The present invention will now be described with reference to another specific embodiment: In this embodiment, we will demonstrate how to use the two-stage training protocol of the present invention to train a cross-subject EEG emotion recognition model, which is designed to identify and classify different emotional states such as focus, confusion, boredom and neutrality.

[0129] The training sample set was a hybrid dataset of SEED and SEED-IV, containing EEG signals from 15 subjects in various emotional states.

[0130] The training sample set is partitioned using leave-one-out cross-validation, as follows: Data from one subject in each training sample set was selected sequentially as the target domain data and used as the target domain validation set. The data from the remaining 14 subjects in the training sample set were used as source domain data and served as the source domain training set. Repeat the above partitioning process to ensure that the data from each of the 15 subjects are validated once as a separate target domain.

[0131] The pre-training phase was performed in the cloud, using an NVIDIA A100 GPU, with a training duration of 24 hours, a batch size of 64, and the Adam optimizer with a learning rate of 3e-4. The target loss function for training consists of a first loss and a second loss, where the weight of the second loss is 0.5, and its calculation formula is: in, Represent the target loss function; During training, the model's parameters are updated by the Adam optimizer to minimize the target loss function. After training, the parameters of the dynamic feature modulation module, shared encoder, conditional diffusion reconstruction module, shared decoder, and adversarial domain invariant learning module are frozen.

[0132] The fine-tuning phase is performed on the edge devices that need to be deployed, including but not limited to RTX 3060 laptops or ARM architecture processors; During the fine-tuning phase, only the lightweight classifier is adjusted. Parameters and The parameters are trained and updated with the goal of minimizing the third loss, which is calculated as follows: in, This refers to the third loss; This indicates the category of emotions. This represents the probability of the predicted emotion category.

[0133] The training results show that on an RTX 3060 laptop, the fine-tuning process can be completed within 10 minutes, while on ARM devices, due to the further reduction in computational requirements, fine-tuning can be completed with only one forward propagation.

[0134] In some application scenarios requiring lightweight deployment, such as in resource-scarce areas, this invention can compress the size of the cross-subject EEG emotion recognition model to 35KB or less through quantization methods such as INT8, achieving an end-to-end latency of 460ms on an ARM Cortex-M7 processor (80MHz clock speed), meeting the real-time threshold (<500ms) for educational interaction. This achievement is attributed to the three-order optimization strategy: operator fusion combines the MLP and convolution calculation of the dynamic feature modulation module into a single instruction; memory pool reuse avoids the repeated allocation of intermediate features in the conditional diffusion reconstruction module; and the classifier weight pruning rate is 70% without any loss of accuracy.

[0135] Educators can deploy cross-subject EEG emotion recognition models in resource-scarce areas at low cost, promoting educational equity.

[0136] Meanwhile, the localized deployment model ensures that the raw EEG data does not leave the device, complying with GDPR / FERPA education privacy regulations.

[0137] Corresponding to the above method, the present invention also provides a cross-subject EEG emotion recognition device, including a processor, a memory, and a computer program / instructions stored in the memory, wherein the processor is used to execute the computer program / instructions, and when the computer program / instructions are executed, the device implements the steps of the above method.

[0138] In summary, the present invention provides a cross-subject EEG emotion recognition model training method, emotion recognition method, and apparatus. After dynamic feature modulation module modulates and reshapes EEG signals across channels and frequency bands, latent representations are extracted by a shared encoder. A conditional diffusion reconstruction module introduces controlled noise into the latent representations and performs reverse denoising, constructing a loss based on the noise, forcing the shared encoder to decouple from subject-specific noise. An adversarial domain-invariant learning module introduces a data source classification task for adversarial learning. During backpropagation, inversion coefficients are introduced into the gradient of the domain discriminator and fed back to the shared encoder, forcing the shared encoder to ignore features related to individual characteristics and focus more on emotion-related features, thereby improving generalization ability.

[0139] Furthermore, in the conditional diffusion reconstruction module, by constructing time-step embeddings and sentiment semantic conditional vectors and performing inverse conditional denoising on noisy samples under their guidance, the noise is reconstructed to establish a loss for parameter tuning of the shared encoder, enabling the shared encoder to more efficiently decouple subject-specific noise.

[0140] Furthermore, a two-stage training protocol and lightweight design are introduced during training. In the pre-training stage, the dynamic feature modulation module, shared encoder, conditional diffusion reconstruction module, shared decoder, adversarial domain invariant learning module, and lightweight classifier are jointly trained on a cloud server using a training sample set to learn general representations across subjects. In the fine-tuning stage, the parameters of the dynamic feature modulation module, shared encoder, conditional diffusion reconstruction module, shared decoder, and adversarial domain invariant learning module are frozen at the end of pre-training, and only the two fully connected layers of the classifier are updated. This enables rapid deployment of the pre-trained model in practical applications, rapid adaptation to data characteristics in specific scenarios, and saves computing resources on edge nodes.

[0141] Those skilled in the art will understand that the exemplary components, systems, and methods described in conjunction with the embodiments disclosed herein can be implemented in hardware, software, or a combination of both. Whether implemented in hardware or software depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application, but such implementation should not be considered beyond the scope of this invention. When implemented in hardware, it can be, for example, electronic circuits, application-specific integrated circuits (ASICs), appropriate firmware, plug-ins, function cards, etc. When implemented in software, the elements of this invention are programs or code segments used to perform the desired tasks. The programs or code segments can be stored in a machine-readable medium or transmitted over a transmission medium or communication link via data signals carried in a carrier wave.

[0142] It should be clarified that the present invention is not limited to the specific configurations and processes described above and shown in the figures. For the sake of brevity, detailed descriptions of known methods are omitted here. In the above embodiments, several specific steps are described and shown as examples. However, the method process of the present invention is not limited to the specific steps described and shown. Those skilled in the art can make various changes, modifications, and additions, or change the order of steps, after understanding the spirit of the present invention.

[0143] In this invention, features described and / or illustrated for one embodiment may be used in the same or similar manner in one or more other embodiments, and / or combined with or in place of features of other embodiments.

[0144] The above description is merely a preferred embodiment of the present invention and is not intended to limit the present invention. For those skilled in the art, various modifications and variations of the embodiments of the present invention are possible. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of the present invention should be included within the protection scope of the present invention.

Claims

1. A training method for a cross-subject EEG emotion recognition model, characterized in that, The method includes the following steps: A training sample set containing multiple samples is obtained. Each sample comes from multiple subjects. Each sample contains the EEG signal of one subject and adds a subject identifier as the first label and an emotion classification as the second label. The EEG signal is a three-dimensional EEG tensor based on channels, frequency bands and time steps. The system comprises a dynamic feature modulation module, a shared encoder, a conditional diffusion reconstruction module, a shared decoder, an adversarial domain-invariant learning module, and a lightweight classifier. The EEG signal is input into the dynamic feature modulation module, where it undergoes parallel processing via channel attention and frequency band attention branches before feature modulation and reshaping to obtain weighted features. These weighted features are then processed by the shared encoder to output a latent representation. The conditional diffusion reconstruction module uses this latent representation as input, injecting controlled noise step-by-step through cosine scheduling during forward diffusion, and performing step-by-step denoising based on a Transformer encoder during backward conditional denoising, outputting predicted noise through the shared decoder. The adversarial domain-invariant learning module averages the latent representation output by the shared encoder along the time dimension to obtain sample-level features, which are then output by a domain discriminator to predict the subject's origin. The domain discriminator introduces a gradient inversion layer that identically transmits sample set features during forward propagation and introduces inversion coefficients to the gradient of the domain discriminator during backward propagation, feeding them back to the shared encoder. The latent representation output by the shared encoder is input into the lightweight classifier to output a predicted emotion classification. A first loss is constructed based on the deviation between the controlled noise and the predicted noise; a second loss is constructed based on the deviation between the predicted subject source and the first label; a third loss is constructed based on the predicted emotion classification and the second label; the dynamic feature modulation module, the shared encoder, the conditional diffusion reconstruction module, the shared decoder, the adversarial domain invariant learning module, and the lightweight classifier are trained using the training sample set, wherein the shared encoder and the domain discriminator are alternately optimized, the second loss is minimized to update the domain discriminator, the second loss is maximized to update the shared encoder, and the first loss and the third loss are minimized to update global parameters; The dynamic feature modulation module, the shared encoder, and the lightweight classifier obtained after parameter updates are combined into a cross-subject EEG emotion recognition model.

2. The training method for the cross-subject EEG emotion recognition model according to claim 1, characterized in that, The channel attention branch includes a continuously configured average pooling layer, a multilayer perceptron, and a first activation function layer, used to output the channel attention weights of the EEG data, expressed as: in, This represents the channel attention weight; This represents the electroencephalogram (EEG) signal; This indicates that the EEG signal is averaged and pooled. This refers to the multilayer perceptron; Represents the Sigmoid function; The frequency band attention branch includes consecutively configured 1D convolutional layers, max pooling layers, and a second activation function layer, used to output the frequency band attention weights, expressed as follows: in, This represents the frequency band attention weight; This indicates that a one-dimensional convolution operation is performed on the aforementioned EEG signal; This represents the global max pooling operation; The formula for calculating the weighted feature is: in, This represents the weighted feature; This represents an element-wise multiplication operation; This represents the transpose of the frequency band attention weights.

3. The training method for the cross-subject EEG emotion recognition model according to claim 1, characterized in that, In the forward diffusion process, controlled noise is injected stage by stage using cosine modulation, and the calculation formula is: ; ; ; Where t is the current diffusion step number, and its value ranges from 1 to 10. , This represents the total number of diffusion steps; Indicates Gaussian noise; Indicates the first Noise samples after step diffusion; Indicates the first Noise samples of the first step, initial This is the latent characterization; In the inverse conditional denoising process, denoising is performed step-by-step based on the Transformer encoder and the predicted noise is output through the shared decoder, including: The time-step embedding is calculated using the following formula: Where t is the current diffusion step number, and its value ranges from 1 to 10. , This represents the total number of diffusion steps; This represents the generated time-step embedding vector, used to label the current diffusion step. Location; This represents the total dimension of the embedding vector; This represents a dimension index variable used for iterating through dimensions. Half of; The latent representation is used as an emotional semantic conditional vector, and the calculation formula is: Where c represents the emotional semantic condition vector; This represents the weighted feature; This refers to the shared encoder; This represents a linear transform layer; C represents the number of channels, B represents the number of bandwidths, and T represents the time step. The noise sample corresponding to each time step, the time step embedding, and the sentiment semantic conditional vector are input into the Transformer encoder to output the predicted noise.

4. The training method for the cross-subject EEG emotion recognition model according to claim 3, characterized in that, The first loss is the expected value of the mean square error of the controlled noise and the predicted noise, and is calculated as follows: in, The controlled noise is described as Gaussian noise. This represents the predicted noise; This represents the first loss.

5. The training method for the cross-subject EEG emotion recognition model according to claim 1, characterized in that, The domain discriminator introduces a gradient inversion layer that identically transmits sample set features during forward propagation and, during backpropagation, introduces inversion coefficients for the gradient of the domain discriminator, which are then fed back to the shared encoder. These inversion coefficients are dynamically adjusted using a cosine annealing strategy based on the training phase. The gradient calculation formula for the gradient inversion layer during backpropagation is: in, This indicates the second loss; This represents the gradient of the domain discriminator; This indicates the gradient inversion layer's processing of the gradient; This represents the sample-level features; Indicates the inversion coefficient; The inversion coefficient is calculated using the first cosine annealing function during the pre-training phase, and the formula is as follows: Where e represents the current training batch; E represents the total number of training batches; This indicates the maximum value set manually. This indicates the minimum value set manually. The inversion coefficient is calculated using the second cosine annealing function during the fine-tuning stage, and the formula is as follows: The formula for calculating the second loss is: in, This represents the probability distribution of the predicted subject's origin; This indicates the one-hot encoding of the second tag; This represents the cross-entropy loss function.

6. The training method for the cross-subject EEG emotion recognition model according to claim 5, characterized in that, The lightweight classifier consists of two fully connected network layers, with an activation function layer following each fully connected network layer, expressed as follows: in, This represents the sample-level features. This represents the weight matrix of the first fully connected layer of the network; This represents the weight matrix of the second fully connected layer; Indicates a modified linear unit. This represents the probability of the predicted emotion category.

7. The training method for the cross-subject EEG emotion recognition model according to claim 6, characterized in that, The method also includes using INT8 quantization to compress the cross-subject EEG emotion recognition model.

8. The training method for the cross-subject EEG emotion recognition model according to claim 1, characterized in that, The method further includes: During the pre-training phase, the dynamic feature modulation module, the shared encoder, the conditional diffusion reconstruction module, the shared decoder, the adversarial domain invariant learning module, and the lightweight classifier are jointly optimized via a cloud server to obtain a preliminary cross-subject EEG emotion recognition model. During the fine-tuning phase, the weights of the cross-subject EEG emotion recognition model, excluding the lightweight classifier, are frozen using an edge device, and the parameters of the lightweight classifier are fine-tuned. The formula for calculating the third loss is: in, This refers to the third loss; This indicates the category of emotions. This represents the probability of the predicted emotion category.

9. A method for cross-subject EEG emotion recognition, characterized in that, The method includes the following steps: The EEG data of the target subject is acquired, wherein the EEG signal is a three-dimensional EEG tensor based on channel, frequency band and time step; The EEG data is input into the cross-subject EEG emotion recognition model obtained by the training method of the cross-subject EEG emotion recognition model according to any one of claims 1 to 8, and the model outputs the emotion recognition result of the target subject.

10. A cross-subject EEG emotion recognition device, comprising a processor, a memory, and a computer program / instructions stored in the memory, characterized in that, The processor is used to execute the computer program / instructions, and when the computer program / instructions are executed, the device / equipment / system implements the steps of the method as described in any one of claims 1 to 9.