An electroencephalogram bad segment automatic detection method and system based on contrast self-supervised learning
By comparing self-supervised learning methods and utilizing multi-level morphological representation and temporal evolution modeling, the problem of bad segment identification in automatic EEG signal detection is solved, achieving efficient and robust bad segment detection. The generated simulation dataset has strong controllability and outperforms existing technologies.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- HUAZHONG NORMAL UNIV
- Filing Date
- 2025-11-25
- Publication Date
- 2026-07-14
AI Technical Summary
Existing technologies struggle to effectively and automatically detect bad segments in EEG signal analysis, and their reliance on manually labeled data leads to poor model generalization ability, especially when labels are missing or the dataset changes, resulting in performance degradation.
A contrastive self-supervised learning method is adopted. Through a multi-level morphological representation module and a temporal evolution modeling module, the feature encoding module is trained in an unsupervised manner to capture the domain invariant properties of EEG segments. A symmetric loss function is generated for model optimization, and supervised training is combined to improve detection performance.
It achieves efficient and automatic removal of EEG bad segments without the need for manual experience parameter setting, outperforming existing methods. It can efficiently complete bad segment detection even with limited labeled data, and the generated simulation dataset is highly controllable.
Smart Images

Figure CN121705988B_ABST
Abstract
Description
Technical Field
[0001] This invention belongs to the field of electroencephalography (EEG) imaging technology, and more specifically, relates to a method and system for automatic detection of bad segments in EEG signals using contrastive self-supervised learning. Background Technology
[0002] Electroencephalography (EEG) imaging technology has advantages such as being non-invasive, simple, low-cost, requiring little constraint on the subject, having high temporal resolution, and being able to objectively reflect the state of brain activity. Therefore, it is widely used in neuroscience and engineering research such as brain cognition and brain disease assessment. However, regardless of the specific application scenario or equipment model, signal quality is always the key to conducting further application analysis. During the recording process, EEG is inevitably subject to artifacts and noise interference, the sources of which include: (1) electrophysiological activities from other sources in the body, such as electrooculography, electrocardiography, and electromyography interference caused by physiological activities such as sweating, accelerated heartbeat, blinking, or turning the head; (2) non-physiological artifact signals caused by the acquisition equipment or environment, such as abnormal factors such as excessive impedance, drying of EEG paste, and electrode detachment. Such contamination is difficult to completely avoid. Especially in long-term EEG monitoring that can last for several hours, some segments of the original data recording will inevitably be tampered with by artifacts and noise contamination, thereby masking or "distorting" the signals reflecting the true state of the brain in the EEG recording, causing deviations in the acquired potential characteristics of EEG, and further causing errors in subsequent analysis. In the development of most EEG analysis workflows, it is required to input clean EEG signals with as little interference as possible. However, the current mainstream method is basically for experts to visually examine EEG recordings, manually delete bad segments, and retain only the clean (normal) EEG data for further processing and analysis. However, the analysis methods built on this data will experience performance degradation when processing new EEG data, and this requires extremely high human resources. Therefore, automated processing solutions are imperative.
[0003] Deep learning-based methods integrate feature engineering and classifiers, employing an end-to-end strategy for bad segment detection. Leveraging the powerful feature extraction capabilities of deep neural networks, they replace manual feature design, automatically learning and capturing deep features of EEG segments. The representations obtained through end-to-end training feedback can more prominently characterize the differences between bad and normal EEG segments. However, building high-performance deep learning models typically requires a large amount of labeled data. Despite the vast scale of EEG data, truly effective labeled samples are very limited because labeling is highly dependent on expert knowledge, time-consuming, laborious, and subjective; continuous labeling can also easily lead to quality degradation. Furthermore, in different EEG analysis scenarios, there are significant differences in amplitude and frequency between groups and individuals, and even between channels in different scalp locations of the same individual at the same time; and new test datasets often lack sufficient labels. Therefore, whether the threshold is optimized based on a specific dataset or the model is trained under supervised supervision, its bad segment detection performance is difficult to guarantee once transferred to other datasets. Constrained by the determination of key parameters and the lack of labels, this inherent specificity further amplifies the challenge of EEG bad segment detection. Summary of the Invention
[0004] To address the aforementioned deficiencies or improvement needs of existing technologies, this invention provides a comparative self-supervised learning-based automatic detection method and system for bad segments in EEG signals. This method trains the feature encoding module in an unsupervised manner to fully learn the domain-invariant properties of EEG segments, thereby alleviating the dependence on labels.
[0005] To achieve the above objectives, according to one aspect of the present invention, an automatic detection method for bad segments in electroencephalogram (EEG) signals based on contrastive self-supervised learning is provided, comprising the steps of:
[0006] Collect EEG data sequences, denoise the EEG data sequences and segment them into multiple EEG data segments. Use the EEG data segments as the smallest unit for automatic bad segment detection, label the EEG data segments, and form an EEG dataset.
[0007] The EEG dataset is input into a deep learning-based automatic detection model for training and optimization. This automatic detection model includes a multi-level morphological representation module, a temporal evolution modeling module, a first prediction module, and a second prediction module. The multi-level morphological representation module performs multi-resolution sampling and multi-level feature extraction and fusion on EEG data segments, captures temporal dependencies within the EEG data segments, and outputs deep features of the temporal information within the hidden segments. The temporal evolution modeling module captures the temporal dependencies between different EEG data segments within the same EEG data sequence and outputs deep features of the temporal information between the hidden segments. The first prediction module outputs a first prediction result for the EEG data segments based on the deep features of the temporal information within the hidden segments. The second prediction module outputs a second prediction result for the EEG data segments based on the deep features of the temporal information between the hidden segments.
[0008] The training and optimization of the automatic detection model includes the following steps: flipping the EEG data segments forward and backward and up and down to generate positive sample pairs of EEG data segments; using the symmetry loss of the positive sample pairs to perform comparative self-supervised training on the whole consisting of the multi-level morphological representation module and the first prediction module; after the comparative self-supervised training is completed, using labeled EEG data segments to perform supervised training on the whole consisting of the multi-level morphological representation module, the temporal evolution modeling module and the second prediction module.
[0009] Preferably, the EEG dataset includes a semi-simulated EEG artifact dataset, a childhood autism EEG dataset, and an adult resting-state EEG dataset. The acquisition of the semi-simulated EEG artifact dataset includes the following steps:
[0010] Obtain clean EEG data sequences, and randomly assign the type of artifact data to be added to each clean EEG data sequence;
[0011] For each clean EEG data sequence, a bad segment length is randomly assigned, and a specified type of artifact data and noise data are added within the specified bad segment length.
[0012] Preferably, the multi-level morphological representation module includes:
[0013] The multi-resolution EEG mapping module is used to convert input EEG data segments into input signals of different resolutions using successive convolutional layers;
[0014] A multi-level feature mining module is used to extract features from the input signal at each resolution and fuse the features of input signals at different resolutions.
[0015] The bidirectional recurrent neural network module is used to capture the temporal dependencies within EEG data segments and output deep features that hide the temporal information within the segments.
[0016] Preferably, the capture of temporal dependencies within the EEG data segment includes the following steps:
[0017] The deep features obtained after fusing multi-resolution sampling and multi-level feature extraction are denoted as . Using deep feature dimensions, it captures temporal dependencies within EEG data segments to obtain forward hidden state vectors. and backward hidden state vector The calculation formula is:
[0018] ;
[0019] in, It means The hidden state vector of the previous layer, It means The hidden state vector of the next layer, The hidden state function is implemented using a gated loop unit;
[0020] Fusion of forward hidden state vectors and backward hidden state vector This yields a deep feature vector that integrates the temporal correlations between the forward and backward directions. The calculation formula is as follows:
[0021] ;
[0022] Among the symbols Indicates vector aggregation, This represents the first weight matrix. This represents the first deviation variable.
[0023] Preferably, the step of capturing the temporal dependencies between different EEG data segments in the same EEG data sequence and outputting deep features that hide the temporal information between segments includes the following steps:
[0024] The EEG data sequence is denoted as , A deep feature vector derived from the fusion of forward and backward temporal correlations of multiple EEG data segments within a sequence. composition, L represents the number of segments in the sequence. This method captures the temporal dependencies between different EEG data segments and obtains the forward hidden state vector of the sequence. and the sequence backward hidden state vector ;
[0025] Hidden state vectors of the fusion sequence forward and the sequence backward hidden state vector Output deep features that reveal temporal information between hidden segments. The calculation formula is:
[0026] ;
[0027] in, This represents the second weight matrix. This represents the second deviation variable.
[0028] Preferably, the first prediction module includes:
[0029] A projection head, consisting of two fully connected layers, is used to map the deep features of temporal information within the hidden segments of positive sample pairs into a low-dimensional space, generating corresponding projection vectors, denoted as . ;
[0030] A prediction head, consisting of two fully connected layers with dimensions opposite to those of the projection head, is used to project the vector... Map back to the original feature space to generate prediction vectors .
[0031] Preferably, the contrastive self-supervised training includes the following steps:
[0032] Calculate the symmetric loss function for positive sample pairs. The calculation formula is:
[0033] ;
[0034] in It is an L2 norm;
[0035] The overall system consisting of the multi-level morphological representation module and the first prediction module is trained and optimized based on the symmetric loss function.
[0036] Preferably, the second prediction module is a Sigmoid layer, and the supervised training includes the following steps:
[0037] The input EEG data sequence is denoted as... L represents the number of segments in the EEG data sequence, and the corresponding label sequence is... The predicted output of the sigmoid layer is Calculate the discrimination loss of a single EEG data segment , The calculation formula is:
[0038] ;
[0039] Calculate the overall discriminant loss of the entire EEG data sequence. The calculation formula is:
[0040] .
[0041] Preferably, each subset of the dataset is divided into 10 parts. Each training session uses 9 parts as the training set and the remaining part as the test set, ensuring that each data set is tested once. The entire process is repeated 10 times, and the average of the 10 results is taken as the test performance.
[0042] According to another aspect of the present invention, an automatic detection system for bad segments of EEG signals based on contrastive self-supervised learning is provided, comprising:
[0043] The dataset construction module is used to collect EEG data sequences, denoise the EEG data sequences and segment them into multiple EEG data segments, use the EEG data segments as the smallest unit for automatic bad segment detection, label the EEG data segments, and form an EEG dataset.
[0044] An automatic detection model is provided, comprising a multi-level morphological representation module, a temporal evolution modeling module, a first prediction module, and a second prediction module. The multi-level morphological representation module performs multi-resolution sampling and multi-level feature extraction and fusion on EEG data segments, captures temporal dependencies within the EEG data segments, and outputs deep features of temporal information within hidden segments. The temporal evolution modeling module captures temporal dependencies between different EEG data segments within the same EEG data sequence and outputs deep features of temporal information between hidden segments. The first prediction module outputs a first prediction result for the EEG data segments based on the deep features of temporal information within hidden segments. The second prediction module outputs a second prediction result for the EEG data segments based on the deep features of temporal information between hidden segments.
[0045] The training and optimization of the automatic detection model includes the following steps: flipping the EEG data segments forward and backward and up and down to generate positive sample pairs of EEG data segments; using the symmetry loss of the positive sample pairs to perform comparative self-supervised training on the whole consisting of the multi-level morphological representation module and the first prediction module; after the comparative self-supervised training is completed, using labeled EEG data segments to perform supervised training on the whole consisting of the multi-level morphological representation module, the temporal evolution modeling module and the second prediction module.
[0046] In summary, this invention proposes an automatic detection method and system for bad segments in EEG signals based on contrastive self-supervised learning. By capturing multi-level features in a deep learning model and dynamically evolving to highlight the differences between bad segments and normal EEG fragments, the feature encoding module is trained in an unsupervised manner to fully learn the domain-invariant properties of EEG fragments, thus alleviating dependence on labels. Specifically, this is manifested in:
[0047] (1) The model can efficiently remove bad segments of the original EEG without the need for manual experience parameter setting, and it outperforms existing mainstream methods in many performance indicators.
[0048] (2) Based on self-supervised contrastive learning, it can make full use of unlabeled data to learn the deep representation of EEG, and can still efficiently complete the bad segment detection task even when labeled data is limited.
[0049] (3) A method for synthesizing simulated EEG artifact datasets: By adding multiple types of artifacts and noise to real EEG signals, controllable construction of EEG segments with different levels of contamination can be achieved. This method generates simulated datasets that are both realistic and scalable, providing a feasible approach and technical path for subsequent similar studies in situations where data is insufficient or annotation is difficult. Attached Figure Description
[0050] Figure 1 A flowchart illustrating the automatic detection method for bad segments in electroencephalogram (EEG) signals provided in this embodiment of the invention;
[0051] Figure 2 This is a structural diagram of a multi-level morphological characterization module provided in an embodiment of the present invention;
[0052] Figure 3 This is a network architecture diagram of the automatic detection model provided in an embodiment of the present invention;
[0053] Figure 4 A flowchart illustrating the construction process of a semi-simulated raw EEG dataset provided in an embodiment of the present invention. Detailed Implementation
[0054] 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 accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative and not intended to limit the invention. Furthermore, the technical features involved in the various embodiments of this invention described below can be combined with each other as long as they do not conflict with each other.
[0055] In the description of the embodiments of this application, the term "multiple" means two or more, and the terms "comprising" and "having," and any variations thereof, are intended to cover non-exclusive inclusion. For example, a process, method, apparatus, product, or device that includes a series of steps or modules is not necessarily limited to those steps or modules that are explicitly listed, but may include other steps or modules that are not explicitly listed or that are inherent to such processes, methods, products, or devices.
[0056] The naming or numbering of steps in the embodiments of the present invention does not mean that the steps in the method flow must be executed in the time / logical order indicated by the naming or numbering. The execution order of the named or numbered process steps can be changed according to the technical purpose to be achieved, as long as the same or similar technical effect can be achieved.
[0057] In this document, the term "embodiment" means that a particular feature, structure, or characteristic described in connection with an embodiment may be included in at least one embodiment of the invention. The appearance of this phrase in various places throughout the specification does not necessarily refer to the same embodiment, nor is it a separate or alternative embodiment mutually exclusive with other embodiments. It will be explicitly and implicitly understood by those skilled in the art that the embodiments described herein can be combined with other embodiments.
[0058] This invention provides a method and system for automatic detection of bad segments in EEG signals based on comparative self-supervised learning, which will be described below.
[0059] An embodiment of the present invention provides an automatic detection method for bad segments of EEG signals using comparative self-supervised learning, comprising steps 1 to 2.
[0060] Step 1: Collect EEG data sequences, denoise the EEG data sequences and segment them into multiple EEG data segments. Use the EEG data segments as the smallest unit for automatic bad segment detection, label the EEG data segments, and form an EEG dataset.
[0061] (1) Data collection
[0062] In one embodiment, three different datasets are used as the data source for training the model: a 23-channel 500Hz semi-simulated EEG artifact dataset (hereinafter referred to as Dataset 1), an 8-channel 1000Hz childhood autism EEG dataset (hereinafter referred to as Dataset 2), and an 8-channel 1000Hz adult resting-state EEG dataset (hereinafter referred to as Dataset 3).
[0063] Data collection specifically includes the following steps:
[0064] 1.1 EEG signal acquisition is typically performed in a specialized EEG acquisition room. Sensors are attached to the scalp of the brain to record data from the person at rest or during a task, and the data is transmitted in real time to a computer for storage. Dataset 1 also incorporates real physiological signals such as electromyography (EMG), electrooculography (EOG), and electrocardiography (ECG) for subsequent synthesis of simulated EEG artifact data.
[0065] 1.2 Subjects were required to remove their glasses, earrings, and other items, and wear a headgear made of a special material.
[0066] 1.3 In dataset 1, electrodes corresponding to 23 channels were passed through the headgear, along with a reference electrode and a ground wire, and in datasets 2 and 3, electrodes corresponding to 8 channels, a reference electrode, and a ground wire were passed through the headgear and tightly fitted to the subject's scalp. A special conductive paste was applied to the contact points to reduce the resistivity.
[0067] 1.4 Dataset 1 uses 60-second preprocessed resting-state EEG data from subjects in a "calm and stable" state as the EEG data to be cleaned. Dataset 2 uses resting-state EEG data with an average recording duration of approximately 8 minutes and 20 seconds. Dataset 3 uses resting-state EEG data collected from three normally developing adult males without obvious brain dysfunction.
[0068] (2) Data preprocessing
[0069] The EEG acquisition device acquired 60 seconds of pure raw EEG signal for dataset 1, and raw signals for datasets 2 and 3 with an average recording duration of approximately 8 minutes and 20 seconds. The processing required for this step is divided into the following parts: (1) downsampling, bandpass filtering and notch filtering are used for each dataset to improve signal quality and remove irrelevant noise; (2) the raw signal for each dataset is divided into multiple time segments using a fixed time window as the smallest unit for automatic detection of bad segments; (3) the segments of dataset 1 are simulated to simulate the contamination process, and then bad segments are labeled for each dataset; (4) all segments of each dataset are divided into 10 parts, and the performance is evaluated using the ten-fold cross-validation method.
[0070] Data preprocessing specifically includes the following steps:
[0071] 2.1 First, the acquired EEG data was downsampled to 256Hz to improve its noise resistance; then, a bandpass filtering algorithm was used to retain only the 0.5-80Hz portion; finally, a notch filter was used to filter out the 50Hz portion.
[0072] 2.2 The complete EEG recording of each subject was segmented into segments with no overlap, using a 10-second sliding window. Each 2-second segment of one-dimensional data was a test sample segment, and 5 consecutive segments were a sequence.
[0073] 2.3 Pure EEG data from Dataset 1 were synthesized with various artifacts and noise signals in a two-step process. First, during the raw EEG simulation stage, each pure EEG segment was randomly paired with a type of artifact. Artifacts refer to non-EEG signal "noise" contained in the raw EEG. These types include: physiological artifacts (e.g., electrooculography or eye movements, electromyography or muscle movements, electrocardiography and heartbeat activity), and non-physiological artifacts (e.g., electrode movement and baseline drift). Subsequently, during the corrupted segment EEG synthesis stage, the length of the corrupted segment was randomly determined, and artifacts and additional noise signals such as Gaussian white noise, square waves, and sawtooth waves were added within a specified range to further contaminate the segment.
[0074] 2.4 Divide each dataset into 10 parts and use 10-fold cross-validation to evaluate model performance. In each training iteration, use 9 parts as the training set and the remaining part as the test set, ensuring that each data point is tested once. Repeat this process 10 times, and the average of the 10 results is taken as the test performance.
[0075] Step 2: Input the EEG dataset into a deep learning-based automatic detection model for training and optimization. The automatic detection model includes a multi-level morphological representation module, a temporal evolution modeling module, a first prediction module, and a second prediction module. The multi-level morphological representation module performs multi-resolution sampling and multi-level feature extraction and fusion on EEG data segments, captures temporal dependencies within EEG data segments, and outputs deep features of temporal information within hidden segments. The temporal evolution modeling module captures temporal dependencies between different EEG data segments within the same EEG data sequence and outputs deep features of temporal information between hidden segments. The first prediction module is used to predict the temporal dependencies between hidden segments based on the temporal information within the hidden segments. The deep features of temporal information output the first prediction result of the EEG data segment; the second prediction module is used to output the second prediction result of the EEG data segment based on the deep features of the temporal information between hidden segments; the training optimization of the automatic detection model includes the following steps: flipping the EEG data segment forward and backward and up and down to generate positive sample pairs of EEG data segments, and using the symmetry loss of the positive sample pairs to perform comparative self-supervised training on the whole composed of the multi-level morphological representation module and the first prediction module; after the comparative self-supervised training is completed, the labeled EEG data segments are used to perform supervised training on the whole composed of the multi-level morphological representation module, the temporal evolution modeling module and the second prediction module.
[0076] The key to this invention lies in achieving multi-level morphological representation, temporal evolution modeling, and self-supervised comparative learning through an automatic detection model.
[0077] Multilevel morphological representation (MMR) comprehensively characterizes the deep features of raw EEG segments through multi-resolution EEG mapping and multi-level feature mining. First, the input raw signal is downsampled using triple convolution to generate a set of multi-resolution signals. Then, deep features are extracted from these signals at different resolutions (including the original resolution) to obtain multiple feature vectors that fuse multi-level information. Finally, feature aggregation merges these feature vectors from different scales into a unified deep representation. Multilevel morphological representation (MMR) can also capture temporal dependencies within segments.
[0078] The core function of temporal evolution modeling is to enhance the ability to identify abnormal segments in EEG. By accurately capturing the temporal dependencies between segments, it makes the differences in evolutionary patterns between normal and abnormal segments more significant, thereby achieving effective characterization of these differences.
[0079] Self-supervised contrastive learning, based on a symmetric loss-based Siamese architecture, makes full use of unlabeled data, thereby effectively improving the representation of raw EEG features and thus helping to obtain robust representations of EEG data.
[0080] The following section explains each module and the principles of model training.
[0081] (1) Multilevel morphological characterization module (MMR)
[0082] The multi-resolution EEG mapping module includes: a multi-resolution EEG mapping module, which uses continuous convolutional layers to convert input EEG data segments into input signals of different resolutions; a multi-level feature mining module, which extracts features of input signals at each resolution and fuses the features of input signals at different resolutions; and a bidirectional recurrent neural network module (BiRNN), which captures temporal dependencies within EEG data segments and outputs deep features that hide temporal information within the segments.
[0083] Multi-resolution EEG mapping module: To this end, successive convolutional layers are used to convert the input signal into representations at different resolutions for feature learning. Each layer uses a one-dimensional convolution with a kernel of (1,4) and a stride of 4 to downsample the input signal to one-quarter the resolution of the previous layer. The input signal length is (T,1), and a 2-second EEG segment with a sampling rate of 256 Hz is used by default. After the k-th layer, the output length is... The outputs from each layer are sequentially fed into subsequent multi-level feature mining modules. Multi-scale observation helps to obtain more comprehensive EEG features.
[0084] Multi-level Feature Mining Module: Bad segments exhibit greater diversity in shape, duration, and rhythm, making it difficult to fully reflect their characteristics using only deep features. Therefore, it is necessary to fuse shallow and deep features for joint representation. A symmetric U-shaped feature extraction network with skip connections was designed to fuse local details and global information from EEG signals to obtain richer multi-level morphological features and achieve effective bad segment detection. This network consists of an encoder, decoder, and intermediate layers. The encoder contains three sets of convolutional blocks (kernel size 3, number of kernels 16, 32, and 64), extracting high-level features and reducing feature length through convolution and pooling. The intermediate layer contains two convolutional layers (128 kernels) connecting the encoder and decoder. The decoder fuses shallow and deep features through upsampling and skip connections. The fused features are transformed into deep feature vectors through global average pooling and fully connected layers. Different input resolutions correspond to different receptive fields. When the convolution kernel size is set to (1, 3), the receptive field lengths of each feature extractor from top to bottom are 0.0117, 0.0468, 0.1875, and 0.75 seconds, respectively. Finally, the outputs of the four feature extractors are aggregated to form a complete multi-level morphological feature representation.
[0085] A bidirectional recurrent neural network (BiRNN) module is used to enhance intra-segment temporal dependencies. Sudden bursts of bad segments are often accompanied by artifact bursts, causing interruptions in normal EEG signals; this temporal characteristic is an important supplement to signal representation. Therefore, a BiRNN is added after each feature learning module to model intra-segment temporal dependencies. The depth feature vectors A at different resolutions are used as inputs to the BiRNN, and the hidden state vectors are calculated through forward and backward recurrent layers. , This enables temporal feature association learning.
[0086] ;
[0087] in, It means The hidden state vector of the previous layer, It means The hidden state vector of the next layer.
[0088] In formulas (1) and (2), the hidden state function It is implemented using gated cyclic units (GRUs) to model temporal dependencies. The specific implementation process is as follows:
[0089] ;
[0090] Among them, variables , , , , , Represents the weight matrix. Is the input layer at time step The input signal, , , Indicates the deviation variable. These represent resetting the gate vector, updating the gate vector, and creating a new hidden candidate vector, respectively. and The implementation process is similar.
[0091] Deep feature vectors that fuse forward and backward temporal correlations The calculation formula is as follows:
[0092] ;
[0093] Among the symbols Indicates vector aggregation, This represents the first weight matrix. The first bias variable is represented by the aggregated vector, which is then passed through a global average pooling layer to merge the forward and backward correlations to obtain the final deep feature vector.
[0094] (2) Temporal Evolution Modeling Module
[0095] A sequence-to-sequence strategy with multiple inputs and multiple outputs is employed, combining the target segment with context segments. This allows for the simultaneous utilization of internal features and temporal information in the discrimination process, thereby improving detection accuracy. In this stage, the input sequence... The deep feature vectors of multiple segments within the sequence composition: L is the number of segments in the sequence. Bidirectional temporal dependency modeling is performed to encode long-term sequence relationships between segments, with the forward and backward hidden state vectors as follows: and The hidden state is computed using BiGRU, and the output vector is... The formula is as follows:
[0096] ;
[0097] in, This represents the second weight matrix. This represents the second deviation variable.
[0098] (3) First prediction module
[0099] The first prediction module is connected after the multi-level morphological representation module (MMR) and includes a projection head consisting of a two-layer fully connected network and a prediction head consisting of two fully connected layers with dimensions opposite to those of the projection head.
[0100] (4) Second prediction module
[0101] The second prediction module is connected after the temporal evolution modeling module. The second prediction module uses a Sigmoid layer for classification prediction.
[0102] (5) Training and optimization of the automatic detection model
[0103] The training and optimization of the automatic detection model includes two stages:
[0104] The first stage involves flipping the EEG data segments forward and backward and up and down to generate positive sample pairs of EEG data segments. The symmetric loss of the positive sample pairs is used to perform comparative self-supervised training on the whole consisting of the multi-level morphological representation module and the first prediction module to learn the general multi-level morphological features of EEG segments.
[0105] In the second stage, after the self-supervised training is completed, labeled EEG data fragments are used to fine-tune the overall supervised training consisting of the multi-level morphological representation module, the temporal evolution modeling module, and the second prediction module, thereby optimizing the model's performance in the bad segment detection task.
[0106] The two stages employ different prediction modules for prediction output. The first stage uses a first prediction module to output the first prediction result of the EEG data segment based on the depth features of temporal information within the hidden segments. The second stage uses a second prediction module to output the prediction result based on the depth features of temporal information between hidden segments (…). The second prediction result of the output EEG data segment.
[0107] After training and optimization, the EEG sequence to be detected can be denoised and segmented into multiple EEG data segments, which are then input into the automatic detection model. The model uses a multi-level morphological representation module, a temporal evolution modeling module, and a second prediction module to automatically detect bad segments of the EEG signal. The second prediction module outputs the bad segment detection results.
[0108] The working principle of the first phase of contrastive self-supervised training is as follows.
[0109] 5.1 In each training batch, for data segments Data augmentation is performed to improve the robustness and generalization ability of the feature encoder. This is achieved by flipping the segments forwards and backwards, and vertically, to generate corresponding positive sample pairs. .
[0110] 5.2 The designed MMR encoder takes the enhanced data fragments as input and generates a corresponding feature vector for each enhanced sample. The calculation method and formula (7) for these two eigenvectors The calculation method is the same.
[0111] 5.3 The projection head consists of two fully connected network layers, which maps the two input feature vectors to a low-dimensional space to generate the corresponding projection vectors. .
[0112] 5.4 The prediction head consists of two fully connected layers with dimensions opposite to those of the projection head. Its function is to map the projection vector back to the original feature space and generate the prediction vector. .
[0113] 5.5 The training objective is to minimize the distance between the predicted vector and another projected vector (e.g., ...). and or and The loss function is symmetric, allowing for the same calculation method to be used on both sets of augmented samples. The similarity metric uses negative cosine similarity; the optimization objective is achieved by minimizing this value.
[0114] ;
[0115] in It is an L2 norm.
[0116] For any EEG segment sample The corresponding symmetric loss function is defined as follows:
[0117] ;
[0118] The principle of supervised training fine-tuning in the second stage is as follows.
[0119] Each segment is processed by feature encoding to obtain each output vector. All are classified by a sigmoid layer to output... .
[0120] Under the sequence-to-sequence strategy, to enable the model to penalize the classification error of each segment, the input EEG sequence is assumed to be... The corresponding label sequence is The predicted output is The definitions of single-segment loss and overall sequence discrimination loss are given in formulas (9) and (10), respectively:
[0121] ;
[0122] An automatic detection system for bad segments in EEG signals based on contrastive self-supervised learning, according to an embodiment of the present invention, includes:
[0123] The dataset construction module is used to collect EEG data sequences, denoise the EEG data sequences and segment them into multiple EEG data segments. The EEG data segments serve as the smallest unit for automatic bad segment detection. The EEG data segments are labeled to form an EEG dataset.
[0124] An automatic detection model is provided, comprising a multi-level morphological representation module, a temporal evolution modeling module, a first prediction module, and a second prediction module. The multi-level morphological representation module performs multi-resolution sampling and multi-level feature extraction and fusion on EEG data segments, captures temporal dependencies within the EEG data segments, and outputs deep features of temporal information within hidden segments. The temporal evolution modeling module captures temporal dependencies between different EEG data segments within the same EEG data sequence and outputs deep features of temporal information between hidden segments. The first prediction module outputs EEG data based on the deep features of temporal information within hidden segments. The first prediction result of the data segment; the second prediction module is used to output the second prediction result of the EEG data segment based on the deep features of the temporal information between hidden segments; the training optimization of the automatic detection model includes the following steps: flipping the EEG data segment forward and backward and up and down to generate positive sample pairs of EEG data segments, and using the symmetry loss of the positive sample pairs to perform comparative self-supervised training on the whole composed of the multi-level morphological representation module and the first prediction module; after the comparative self-supervised training is completed, the whole composed of the multi-level morphological representation module, the temporal evolution modeling module and the second prediction module is trained in a supervised manner using labeled EEG data segments.
[0125] The working principle and technical effect of the automatic detection system for bad segments of EEG signals are the same as those of the automatic detection method for bad segments of EEG signals mentioned above, and will not be repeated here.
[0126] Those skilled in the art will readily understand that the above description is merely a preferred embodiment of the present invention and is not intended to limit the present invention. Any modifications, equivalent substitutions, and improvements made within the spirit and principles of the present invention should be included within the scope of protection of the present invention.
Claims
1. A method for automatic detection of bad segments in EEG signals using contrastive self-supervised learning, characterized in that, Including the following steps: Collect EEG data sequences, denoise the EEG data sequences and segment them into multiple EEG data segments. Use the EEG data segments as the smallest unit for automatic bad segment detection, label the EEG data segments, and form an EEG dataset. The EEG dataset is input into a deep learning-based automatic detection model for training and optimization. This automatic detection model includes a multi-level morphological representation module, a temporal evolution modeling module, a first prediction module, and a second prediction module. The multi-level morphological representation module performs multi-resolution sampling and multi-level feature extraction and fusion on EEG data segments, captures temporal dependencies within the EEG data segments, and outputs deep features of the temporal information within the hidden segments. The temporal evolution modeling module captures the temporal dependencies between different EEG data segments within the same EEG data sequence and outputs deep features of the temporal information between the hidden segments. The first prediction module outputs a first prediction result for the EEG data segments based on the deep features of the temporal information within the hidden segments. The second prediction module outputs a second prediction result for the EEG data segments based on the deep features of the temporal information between the hidden segments. The training and optimization of the automatic detection model includes the following steps: flipping the EEG data segments forward and backward and up and down to generate positive sample pairs of EEG data segments; using the symmetry loss of the positive sample pairs to perform comparative self-supervised training on the whole consisting of the multi-level morphological representation module and the first prediction module; after the comparative self-supervised training is completed, using labeled EEG data segments to perform supervised training on the whole consisting of the multi-level morphological representation module, the temporal evolution modeling module and the second prediction module.
2. The automatic detection method for bad segments of EEG signals using contrastive self-supervised learning as described in claim 1, characterized in that, The EEG dataset includes a semi-simulated EEG artifact dataset, a childhood autism EEG dataset, and an adult resting-state EEG dataset. The acquisition of the semi-simulated EEG artifact dataset includes the following steps: Obtain clean EEG data sequences, and randomly assign the type of artifact data to be added to each clean EEG data sequence; For each clean EEG data sequence, a bad segment length is randomly assigned, and a specified type of artifact data and noise data are added within the specified bad segment length.
3. The automatic detection method for bad segments of EEG signals using contrastive self-supervised learning as described in claim 1, characterized in that, The multi-level morphological representation module includes: The multi-resolution EEG mapping module is used to convert input EEG data segments into input signals of different resolutions using successive convolutional layers; A multi-level feature mining module is used to extract features from the input signal at each resolution and fuse the features of input signals at different resolutions. The bidirectional recurrent neural network module is used to capture the temporal dependencies within EEG data segments and output deep features that hide the temporal information within the segments.
4. The automatic detection method for bad segments of EEG signals using contrastive self-supervised learning as described in claim 1, characterized in that, The capture of temporal dependencies within EEG data segments includes the following steps: The deep features obtained after fusing multi-resolution sampling and multi-level feature extraction are denoted as . Using deep feature dimensions, it captures temporal dependencies within EEG data segments to obtain forward hidden state vectors. and backward hidden state vector The calculation formula is: ; in, It means The hidden state vector of the previous layer, It means The hidden state vector of the next layer, The hidden state function is implemented using a gated loop unit; Fusion of forward hidden state vectors and backward hidden state vector This yields a deep feature vector that integrates the temporal correlations between the forward and backward directions. The calculation formula is as follows: ; Among the symbols Indicates vector aggregation, This represents the first weight matrix. This represents the first deviation variable.
5. The automatic detection method for bad segments of EEG signals using contrastive self-supervised learning as described in claim 1, characterized in that, The steps involved in capturing the temporal dependencies between different EEG data segments within the same EEG data sequence and outputting deep features that hide the temporal information between segments are as follows: The EEG data sequence is denoted as , A deep feature vector derived from the fusion of forward and backward temporal correlations of multiple EEG data segments within a sequence. composition, L represents the number of segments in the sequence. This method captures the temporal dependencies between different EEG data segments and obtains the forward hidden state vector of the sequence. and the sequence backward hidden state vector ; Hidden state vectors of the fusion sequence forward and the sequence backward hidden state vector Output deep features that reveal temporal information between hidden segments. The calculation formula is: ; in, This represents the second weight matrix. This represents the second deviation variable.
6. The automatic detection method for bad segments of EEG signals using contrastive self-supervised learning as described in claim 1, characterized in that, The first prediction module includes: A projection head, consisting of two fully connected layers, is used to map the deep features of temporal information within the hidden segments of positive sample pairs into a low-dimensional space, generating corresponding projection vectors, denoted as . ; A prediction head, consisting of two fully connected layers with dimensions opposite to those of the projection head, is used to project the vector... Map back to the original feature space to generate prediction vectors .
7. The automatic detection method for bad segments of EEG signals using contrastive self-supervised learning as described in claim 6, characterized in that, The contrastive self-supervised training includes the following steps: Calculate the symmetric loss function for positive sample pairs. The calculation formula is: ; in It is an L2 norm; The overall system consisting of the multi-level morphological representation module and the first prediction module is trained and optimized based on the symmetric loss function.
8. The automatic detection method for bad segments of EEG signals using contrastive self-supervised learning as described in claim 1, characterized in that, The second prediction module is a Sigmoid layer, and the supervised training includes the following steps: The input EEG data sequence is denoted as... L represents the number of segments in the EEG data sequence, and the corresponding label sequence is... The predicted output of the sigmoid layer is Calculate the discrimination loss of a single EEG data segment , The calculation formula is: ; Calculate the overall discriminant loss of the entire EEG data sequence. The calculation formula is: 。 9. The automatic detection method for bad segments of EEG signals using contrastive self-supervised learning as described in claim 2, characterized in that, Each subset of the dataset is divided into 10 parts. In each training session, 9 parts are used as the training set and the remaining part is used as the test set to ensure that each data point is tested once. The entire process is repeated 10 times, and the average of the 10 results is taken as the test performance.
10. An automatic detection system for bad segments in electroencephalogram (EEG) signals based on contrastive self-supervised learning, characterized in that, include: The dataset construction module is used to collect EEG data sequences, denoise the EEG data sequences and segment them into multiple EEG data segments, use the EEG data segments as the smallest unit for automatic bad segment detection, label the EEG data segments, and form an EEG dataset. An automatic detection model is provided, comprising a multi-level morphological representation module, a temporal evolution modeling module, a first prediction module, and a second prediction module. The multi-level morphological representation module performs multi-resolution sampling and multi-level feature extraction and fusion on EEG data segments, captures temporal dependencies within the EEG data segments, and outputs deep features of temporal information within hidden segments. The temporal evolution modeling module captures temporal dependencies between different EEG data segments within the same EEG data sequence and outputs deep features of temporal information between hidden segments. The first prediction module outputs a first prediction result for the EEG data segments based on the deep features of temporal information within hidden segments. The second prediction module outputs a second prediction result for the EEG data segments based on the deep features of temporal information between hidden segments. The training and optimization of the automatic detection model includes the following steps: flipping the EEG data segments forward and backward and up and down to generate positive sample pairs of EEG data segments; using the symmetry loss of the positive sample pairs to perform comparative self-supervised training on the whole consisting of the multi-level morphological representation module and the first prediction module; after the comparative self-supervised training is completed, using labeled EEG data segments to perform supervised training on the whole consisting of the multi-level morphological representation module, the temporal evolution modeling module and the second prediction module.