Deep learning-based sleep spindle automatic detection method and system, and medium
Patent Information
- Application Number
- CN202610550803.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-04-24
- Publication Date
- 2026-08-28
AI Technical Summary
一旦增强模块过拟合或噪声放大,容易导致输出波动,难以在复杂输入条件下保持输出稳定,导致系统可控性与稳定性不足
[0024] Compared with existing methods for automatic detection of sleep spindle waves, especially detection networks based on a one-dimensional U-shaped encoder-decoder structure, such as the SUMO model proposed by Kaulen et al., this invention improves feature extraction, cross-layer fusion, and bottleneck modeling methods while maintaining its end-to-end, fully convolutional, pointwise probability output, and event segment generation through smoothing and thresholding engineering framework. This results in the following beneficial effects:
Smart Images

Figure CN122642831A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the fields of biomedical signal processing and deep learning technology, and in particular to a method and system for automatic detection of sleep spindle waves based on deep learning. Background Technology
[0002] Sleep spindles are characteristic electroencephalogram (EEG) waveforms during non-rapid eye movement (NREM) sleep, typically appearing as fusiform oscillations with a frequency of 11-16 Hz and a duration of 0.5-2.0 seconds. As a key marker of sleep stages and an important indicator of memory consolidation and neural plasticity, the density, duration, and morphological characteristics of spindles are widely used in the auxiliary diagnosis and treatment evaluation of neuropsychiatric disorders such as insomnia, schizophrenia, and Alzheimer's disease.
[0003] Currently, the clinical gold standard still relies on manual visual interpretation by professional physicians according to the American Academy of Sleep Medicine (AASM) manual. However, manual interpretation has significant limitations, including high subjectivity, low consistency (large fluctuations in Kappa coefficients among different physicians), low efficiency, and susceptibility to fatigue, making it difficult to meet the needs of large-scale clinical screening and precise quantitative analysis. Therefore, developing high-precision and robust automated detection algorithms has become a research hotspot in this field.
[0004] To overcome the poor generalization ability of traditional signal processing methods (such as bandpass filtering combined with fixed thresholds), semantic segmentation models based on deep learning have gradually become mainstream. Among them, detection techniques based on the simplified U-Net architecture, represented by SUMO (Slim U-Net trained on MODA), are highly representative. However, this model uses standard convolutional kernels for feature extraction, and its feature extraction process is a "passive learning" process. Due to the lack of explicit edge guidance mechanisms, the model struggles to capture the amplitude and frequency abrupt changes (i.e., edge jumps) that occur at the beginning and end of sleep spindle bursts. This results in insufficient adaptability to situations where "start and end boundaries are unclear and the envelope contour is easily submerged by noise," and the definition of the start and end boundaries of spindles is not sharp enough, causing boundary localization errors. When processing EEG data from elderly subjects, because their spindle amplitudes are lower and durations are shorter, the model, without morphological prior guidance, is highly prone to confusing weak spindle signals with background EEG noise (such as slow waves).
[0005] Existing techniques such as SUMO employ simple feature concatenation as a skip connection method in cross-layer feature fusion. Shallow raw features acquired at the encoder front end, containing significant environmental electrical noise and artifacts, are directly passed to the decoder, easily causing "noise pollution" in the prediction results and increasing the risk of false alarms. While SUMO explicitly uses "matching-level concatenation skip connections" for fusion, it lacks a dynamic mechanism for judging the reliability of features at different scales, making it difficult to utilize global context to filter and calibrate cross-scale information.
[0006] The SUMO model structure consists of multiple levels of "convolution-activation-normalization" and relies on pooling / upsampling to expand the receptive field. However, it lacks an adaptive selection mechanism for multi-scale dilated branches at its bottleneck. This leads to existing bottleneck layers primarily relying on local convolutions, underutilizing multi-scale contextual information and struggling to adapt to spindle wave events of varying durations and intensities. SUMO generates event segments at the output through smoothing with moving averages and thresholding; this post-processing helps reduce transient jitter, but its main effect is on the output probability level. Furthermore, the lack of a control mechanism for the proportion of enhanced features injected during the feature fusion stage within the network makes it prone to output fluctuations and difficulty maintaining output stability under complex input conditions, resulting in insufficient system controllability and stability.
[0007] Because it cannot accurately pinpoint the edge at the signal level, the model still exhibits some linearity bias when estimating downstream clinical indicators. In particular, its performance degrades rapidly in detection scenarios that require high overlap, thus limiting the accuracy of the model's duration estimation. Summary of the Invention
[0008] The main objective of this patent is to provide a method, system, and medium for automatic detection of sleep spindle waves based on deep learning. The system adopts a U-shaped network structure of encoder-bottleneck-decoder, and achieves multi-scale feature fusion through skip connections. The system includes an input preprocessing unit, a feature encoding unit, a bottleneck enhancement unit, a feature decoding unit, and a category output unit. The system takes continuous time series as input and performs multi-level compression and recovery within the network to output the category probability at each time point and the start and end segments of the spindle wave event generated from the probability sequence.
[0009] To achieve the above objectives, this application provides the following solution:
[0010] In a first aspect, the present invention discloses an automatic detection method for sleep spindle waves based on deep learning, characterized by comprising the following steps:
[0011] Raw EEG signal data is acquired and preprocessed to obtain a standardized time-series signal tensor.
[0012] The time-series signal tensor is input into the feature encoder unit for multi-level feature extraction and downsampling to obtain multi-scale encoded features. A multi-stage edge-guided attention module is embedded in the encoding process. This module adaptively switches the morphological prior extraction strategy according to the network layer depth: in the shallow layer, boundary abrupt information is extracted based on gradient operators, and in the deep layer, envelope contour information is extracted based on smoothing operators. The extracted morphological prior features are then fused into the backbone features.
[0013] The multi-scale encoded features are input into the bottleneck enhancement unit, which includes parallel basic convolutional main paths and multi-scale dilated convolutional enhancement paths. The credibility of the enhancement path features is evaluated through a quality gating mechanism, and the contribution of the enhancement paths is fused in a restricted manner based on the credibility to obtain the bottleneck features.
[0014] The fused features output from the bottleneck layer are input into the feature decoding unit for progressive upsampling and recovery. At the jump connection of the decoder, the jump features from the encoder are recursively downsampled using a recursive generalization self-attention module to construct a global context. Local details are calibrated through a cross-attention mechanism. After quality evaluation and constrained incremental fusion, enhanced jump features are obtained and fused with the upsampled features.
[0015] Point-by-point category probabilities are generated based on the feature sequences output by the decoder, and the time period information of the sleep spindle wave event is obtained through post-processing.
[0016] Secondly, this invention discloses a system for performing a recursive edge-guided attention network method for sleep spindle detection, comprising:
[0017] The input preprocessing unit preprocesses the raw EEG signal data and outputs a standardized time-series signal tensor.
[0018] The feature encoding unit performs multi-level feature extraction and downsampling on the temporal signal tensor to obtain multi-scale encoded features. The feature encoding unit includes a basic convolution module, a downsampling module, and a multi-stage edge-guided attention enhancement module embedded in the basic convolution module. The multi-stage edge-guided attention enhancement module uses gradient operators to extract boundary information in the shallow layer and smoothing operators to extract envelope and contour information in the deep layer, and adaptively fuses the extracted morphological prior features into the main feature flow.
[0019] The bottleneck enhancement unit processes deep coding features. The bottleneck enhancement unit adopts a dual-path structure, including a main path for extracting local patterns and an enhancement path for expanding the receptive field. The enhancement features output by the enhancement path are fused with the features of the main path after being restricted by a quality gating mechanism.
[0020] The feature decoding unit recovers the temporal resolution step by step through multiple decoding layers, and embeds a recursive generalized self-attention module in each decoding layer. The recursive generalized self-attention module recursively downsamples the jump features from the corresponding layer from the encoder side to construct global contextual features, and uses a cross-attention mechanism to calibrate local details. A quality factor is generated through a quality evaluation network, and the enhanced jump features are injected into the current decoding layer through a hard threshold gating and restricted incremental fusion strategy, and fused with the upsampled features.
[0021] The category output unit includes an output discrimination unit and a post-processing unit; the output discrimination unit generates point-by-point category probabilities based on the feature sequence output by the decoder; the post-processing unit is used to generate time period information of sleep spindle wave events based on the point-by-point category probabilities.
[0022] Thirdly, the present invention discloses a computer-readable storage medium having a computer program stored thereon, characterized in that the program implements the above-described method when executed by a processor.
[0023] Compared with the prior art, the beneficial effects of the present invention are:
[0024] Compared with existing methods for automatic detection of sleep spindle waves, especially detection networks based on a one-dimensional U-shaped encoder-decoder structure, such as the SUMO model proposed by Kaulen et al., this invention improves feature extraction, cross-layer fusion, and bottleneck modeling methods while maintaining its end-to-end, fully convolutional, pointwise probability output, and event segment generation through smoothing and thresholding engineering framework. This results in the following beneficial effects:
[0025] To address the issues of "lack of morphological feature perception" and "unclear boundary definition," this invention introduces a multi-stage edge-guided attention mechanism during the encoding / decoding feature extraction process. This allows the network to explicitly utilize the morphological prior information of the spindle wave, thereby improving the shortcomings of existing technologies that rely primarily on convolutional self-learning and are insufficiently adaptable to situations where "start and end boundaries are unclear and the envelope contour is easily submerged by noise." Specifically, this invention uses gradient-type boundary guidance in shallow layers to emphasize abrupt changes in signal start and end points, and smooth contour guidance in deep layers to highlight the overall envelope structure. Furthermore, through a channel-adaptive weighting mechanism, the network can stably focus on key morphological regions under different noise levels, individual amplitude differences, and variations in spindle wave morphology. This reduces false detections and false negatives caused by boundary positioning offsets and morphological confusion, improving the consistency and interpretability of the detection output over time.
[0026] To address the issues of "noise pollution caused by the semantic gap" and "lack of screening in cross-layer feature fusion," this invention introduces a recursive generalized self-attention mechanism at skip connections, along with feature quality assessment and gating control. This improves upon existing technologies like SUMO, which typically rely solely on "direct concatenation" for information transfer during cross-layer feature fusion, making it difficult to utilize global context for screening and calibration of cross-scale information. SUMO's structural description explicitly employs "matching-level concatenation skip connections" for fusion, lacking a dynamic mechanism for judging the reliability of features at different scales. This invention constructs a global context representation covering a longer time span through recursive downsampling and uses cross-attention to calibrate the original resolution skip features in context. This provides more coherent global information guidance and more effective local detail compensation during the decoding stage. Simultaneously, by using a quality scoring threshold and contribution limit constraints, enhancement contributions are only activated when the enhanced features are reliable, and their impact is suppressed when they are unreliable. This introduces long-range dependency modeling capabilities while avoiding unstable perturbations of the main branch by the enhanced branches, improving robustness and stability across subjects and noise conditions.
[0027] To address the issue of insufficient utilization of multi-scale context in the bottleneck layer, this invention employs a dual-path adaptive dilated convolutional enhancement structure at the network bottleneck layer. This allows the network to expand its receptive field on demand while maintaining stable representation of the lightweight main path, thus improving upon the problem of insufficient utilization of multi-scale contextual information caused by the bottleneck layer's reliance on local convolution. The SUMO model structure consists of multiple levels of "convolution-activation-normalization" and relies on pooling / upsampling to expand the receptive field. However, it lacks an adaptive selection mechanism for multi-scale dilated branches at the bottleneck. This invention acquires context at different time scales by parallelizing dilated convolutional branches with varying dilation rates. Combined with an independent quality assessment network and an incremental fusion strategy based on limited contribution, the enhancement branches participate when reliable and are suppressed when unreliable. This expands the temporal observation field while suppressing background noise interference that may be introduced by dilated convolution, achieving "on-demand activation and limited injection" of multi-scale features. This improves adaptability to spindle wave events of varying durations and intensities.
[0028] To address the issue of insufficient system controllability and stability, the quality gating and constrained fusion strategy of this invention enables the system to possess better controllability and stability during training and inference. Existing technologies (such as SUMO) smooth and threshold event segments at the output end through moving averages, which helps reduce transient jitter, but its main effect is on the output probability level. This invention, however, introduces quality assessment and gating constraints at the feature fusion stage within the network, applying threshold control and upper limit restrictions to the injection ratio of augmented features. This keeps the impact of "global augmentation / multi-scale augmentation" on backbone features within a controllable range, thus making it more effective at maintaining output stability under complex input conditions and reducing output fluctuations caused by overfitting of augmentation modules or noise amplification.
[0029] Overall, this invention, while inheriting the existing technology's end-to-end output probability and engineering process of forming the start, end, and duration of spindle waves through smoothing and event merging, further strengthens morphological prior modeling, global context calibration, and enhanced branch stability control. Therefore, it is more suitable for the long-term stable operation requirements under the conditions of "cross-population differences, noise interference, and event morphology diversity" in actual sleep EEG automatic analysis scenarios, and is conducive to obtaining more consistent event-level output results, which facilitates subsequent statistical analysis of downstream indicators such as spindle wave density and duration. Attached Figure Description
[0030] Figure 1 Flowchart of a deep learning-based automatic sleep spindle wave detection method;
[0031] Figure 2 A schematic diagram of the overall architecture of a deep learning network.
[0032] Marker description
[0033] The following is about Figure 2 The middle arrow is marked; the marking explanation is below:
[0034] 1. (5, 2)-Conv + ReLU + BN: A one-dimensional convolution with a kernel size of 5 and an inflation rate of 2, followed by ReLU activation and BatchNorm normalization.
[0035] 2. (5, 1)-Conv + ReLU + BN: A one-dimensional convolution with a kernel size of 5 and an inflation rate of 1, followed by ReLU and BatchNorm.
[0036] 3. RG-SA Module (...) : Recursive generalized self-attention module for skip connection feature enhancement (recursive downsampling + cross attention + gating + residual).
[0037] 4. Max-Pool 4: 4 times the maximum pooling downsampling (length reduced to 1 / 4).
[0038] 5. Up Conv Layer: Upsampling convolutional layer (recovers time length and adjusts channels).
[0039] 6. (1, 1)-Conv: 1×1 one-dimensional convolution, mainly used for channel mapping.
[0040] 7. Crop: Trim, remove excess boundary length to align with the target output length.
[0041] 8. EGA (...): Edge-guided attention module (edge / local enhancement + channel attention + MLP + residual).
[0042] 9. DualPathBottleneck (...) Dual-path bottleneck module (basic convolutional branch + dilated convolutional branch, which are merged after gating).
[0043] 10. Padding: Padding adds points at both ends of the sequence to align with the convolution / pooling computation dimensions. Detailed Implementation
[0044] The present invention will be further described in detail below with reference to the embodiments and accompanying drawings, but the embodiments of the present invention are not limited thereto.
[0045] Example 1:
[0046] like Figure 1 , Figure 2 As shown, a method for automatic detection of sleep spindle waves based on deep learning is described, with the following specific steps:
[0047] 1. Preprocessing unit:
[0048] The raw EEG data is acquired and the EEG signals are preprocessed to obtain the required time-series signal tensor.
[0049] The raw EEG data originates from either a single-channel EEG one-dimensional time-series signal sequence x or a target channel selected from a multi-channel EEG and projected onto a single-channel EEG one-dimensional time-series signal sequence x. The original signal length is L. The input signal is resampled to 100Hz. To avoid frequency aliasing during resampling, a low-pass filtering followed by downsampling can be used.
[0050] Bandpass filtering, such as a Butterworth filter or other phase-preserving filters, is used to cover the frequency band (0.3–30 Hz) and its neighborhood of the spindle wave to preserve the waveform's morphological characteristics. Standardization is then applied to each input sequence after filtering to reduce the impact of outlier amplitudes on model convergence. Ideally, each input sequence should be standardized with zero mean and unit variance using z-score standardization. Alternatively, robust statistics (median and interquartile range) can be used for scaling to further reduce the influence of outlier amplitudes on the model.
[0051] The preprocessed one-dimensional signal is organized into a three-dimensional tensor for the adaptation network computation. Preferably, the input is organized as a three-dimensional tensor of shape (B, 1, L), where B is the batch size, 1 is the number of input channels, and L is the sequence length. Since the U-shaped network involves multiple levels of pooling and upsampling operations, to ensure size matching of the feature maps at skip connections, the input sequence length needs to be aligned: the system preferably aligns the input sequence length to a length L′ that is divisible by the product of each pooling scale. The pooling scale can be a fixed value for each level or different values for different levels; preferably, each pooling scale is 2 or 4. When L is less than L′, symmetrical padding or reflection padding is performed in the time dimension, with a padding length of Δ=L′−L. After the inference output is completed, the output sequence is trimmed to its original length L to ensure a one-to-one correspondence between the output and input time axes.
[0052] The raw EEG data is preprocessed in a standardized manner to eliminate the influence of individual differences among subjects, equipment noise and signal non-stationarity, construct a time-series signal tensor adapted to the input of deep neural networks, and ensure that the data processing flow of the training end and the inference end is strictly consistent.
[0053] 2. Encoder Unit: Encoder module and multi-stage edge-guided attention (EGA) module
[0054] The encoder unit constructs a multi-level coding network to perform deep feature extraction and downsampling on the preprocessed temporal signal tensor, gradually expanding the receptive field to capture long-range contextual information. It also innovatively introduces a multi-stage edge-guided attention (EGA) module, explicitly injecting the morphological priors of the sleep spindle wave (i.e., the abrupt changes in the start and end boundaries and the envelope continuity of the overall waveform) into the feature stream, significantly improving the model's sensitivity to weak spindle waves and the accuracy of boundary localization.
[0055] 2.1.1 Encoder Basic Architecture and Convolutional Block Design
[0056] Hierarchical structure configuration: The encoder consists of N coding layers connected in series, where N is an integer, preferably ranging from 2 to 6. The specific number of layers can be dynamically configured according to the computing power resources of the deployed equipment and the accuracy requirements of the task.
[0057] 2.1.2 Feature Extraction Submodule
[0058] Each coding layer contains a convolutional feature extraction submodule for extracting local temporal feature patterns. The convolutional feature extraction submodule preferably employs a double convolutional structure, i.e., two consecutive one-dimensional convolutions, followed by nonlinear activation and normalization. The kernel size can be 3, 5, or other odd numbers to maintain central symmetry. The convolution stride is typically 1; the padding method is preferably "same" or equivalent symmetrical padding to ensure that the temporal dimension length remains unchanged before and after convolution. To expand the receptive field without increasing the number of parameters, a dilation rate d can be introduced into the convolution. In shallow encoders, the dilation rate can be kept at 1 in the basic convolutional block, while in deep encoders, d can be increased layer by layer (d=2,4).
[0059] 2.1.3 Downsampling Submodule
[0060] Located after convolutional feature extraction, the downsampling submodule is used to compress temporal resolution. It can be implemented using max pooling, average pooling, or strided convolution; max pooling is preferred to enhance the response to local salient features (such as spindle wave peaks) while suppressing background noise. The downsampling ratio is preferably 2 or 4, or different downsampling ratios can be set for different levels. The output feature of the encoder at level i is denoted as the jump feature Fi, and its tensor shape is (B, Ci, Li), where Ci is the number of channels and Li is the time length of that level. Ci can increase exponentially with increasing level depth, for example, by a factor of 2, to enhance the semantic expressiveness of higher levels.
[0061] 2.2 Structure and Operation of the Multi-Stage Edge-Guided Attention Module (EGA)
[0062] This invention embeds a multi-stage edge-guided attention module into the basic convolutional blocks of the encoder and / or decoder. This module adaptively switches the morphological prior extraction strategy according to the depth of the network layers: shallow layers focus on boundary abrupt changes, and deep layers focus on envelope contours. This is used to explicitly inject the spindle wave morphological prior (boundary abrupt changes and envelope contours) into the feature representation. The module takes the features of the current layer as input, outputs enhanced features of the same shape, and back-injects the backbone feature flow in a residual manner.
[0063] 2.2.1 EGA Module Insertion Location and Residual Connection
[0064] EGA can be flexibly inserted between two convolutions in a dual convolutional structure, i.e., the output of the first convolution enters the EGA and then is input into the second convolution; or it can be inserted at the output of the dual convolutional structure. Insertion between two convolutions is preferred, so that the second convolution can further integrate shape-guided information. The EGA input feature is denoted as F, and the output enhancement feature is denoted as F′. Both have the same shape, (B, C, L). The final output is fused with the input through residual superposition, using the formula: F...out =F+λ*F′, where λ is the learning weight coefficient, ensuring the identity mapping of the main features and the stable propagation of gradients.
[0065] 2.2.2 Shallow Boundary Guiding Unit: Boundary Guiding Mechanism Based on Gradient Operator
[0066] (1) In the shallow stage (e.g., the number of channels is less than or equal to the preset threshold T1, or it is located in the first k coding layers), EGA focuses on capturing the instantaneous changes at the start and end of the spindle wave. EGA uses a one-dimensional gradient operator to extract boundary information. The gradient operator uses a one-dimensional differential convolution kernel with fixed weights to simulate gradient calculation. The calculation process performs this convolution operation on the input feature F to obtain the gradient response map; the convolution kernel is, for example, [-1,0,1] or equivalent form, or a one-dimensional differential kernel constructed using the Scharr idea. (2) The absolute value of the gradient response is taken to represent the boundary strength, and then processed by activation function (such as ReLU, GELU or other nonlinear functions) and normalization (BatchNorm1d, LayerNorm or equivalent structure) to generate a boundary attention mask. (3) Feature fusion: The boundary attention mask is multiplied (weighted) or concatenated with the original features element-wise and then fused by 1×1 convolution to highlight the feature responses of the start and end edges.
[0067] 2.2.3 Deep Guiding Unit: Envelope Guiding Mechanism Based on Smooth Operator
[0068] For deeper encoder layers (e.g., those with more than T1 channels or located in subsequent coding layers), EGA focuses on extracting the overall smooth envelope and duration of the spindle wave. EGA uses a one-dimensional smoothing operator to extract envelope and contour information. The smoothing operator can be implemented using a Gaussian kernel, with kernel lengths of odd numbers such as 3, 5, and 7, and standard deviation σ ranging from 0.5 to 2.0 to match the typical duration scale of the spindle wave. Weighting strategy: To enhance portability, Gaussian kernel weights can be fixed and not trained (to ensure the physical interpretability of the smoothing properties), or they can be set as trainable parameters but subject to regularization constraints to maintain the smoothing properties.
[0069] 2.2.4 Channel Adaptive Weighting Unit: Morphological Enhancement Output
[0070] To further refine feature representation, the EGA module integrates an adaptive channel weighting mechanism at its end, achieving joint enhancement through "morphological guidance + channel selection".
[0071] (1) The EGA further includes a channel adaptive weighting unit, which is used to generate channel weights based on feature statistics. The channel weights are generated by first performing global average pooling on the features to obtain a channel description of (B, C, 1), and then generating weight coefficients of (B, C, 1) through lightweight convolution or fully connected mapping, and restricting them to between 0 and 1 by Sigmoid. (2) The channel weights are used to scale the fused features channel by channel, and then the residuals are superimposed with the input features to obtain the final EGA output, thereby realizing the joint mechanism of "morphological prior guidance + adaptive emphasis".
[0072] 3. Bottleneck Enhancement Unit: Dual-Path Adaptive Dilated Convolutional Enhancement Structure in the Bottleneck Layer
[0073] This invention introduces a dual-path enhancement structure at the bottleneck position between the deepest layers of the encoder and decoder. By setting up a "basic convolutional main path" and a "multi-scale dilated convolutional enhancement path" in parallel, it balances the stability of local continuous features with the ability to capture long-term temporal context. This solves the problem of poor scale adaptability caused by the fixed receptive field of deep features. It is used to balance local continuous features and long-term temporal context features, and achieves on-demand activation and contribution upper limit constraints through quality gating, realizing "on-demand activation" and "constrained fusion" of the enhancement paths, ensuring that the system can still output stably when the signal-to-noise ratio is low or the feature quality is poor.
[0074] 3.1 Main Path: Basic Convolutional Stable Representation Module
[0075] The main path serves as the baseline path of the system, responsible for extracting robust local time-series patterns and ensuring the basic availability of the model under any operating conditions.
[0076] The main path consists of basic convolutional blocks composed of standard one-dimensional convolutions, normalization layers, and nonlinear activation functions. These blocks extract local patterns from the bottleneck input features to generate basic features. This serves as the foundation for the bottleneck output. Training strategy: The main path parameters participate in the entire normal training process and contribute to the output construction under all circumstances, ensuring that the system can still work stably when the enhancement path fails.
[0077] 3.2 Enhanced Path: Parallel Multi-Scale Dilated Convolution Branch
[0078] The enhancement path, as an adaptive extension pathway of the system, is specifically designed to capture long-range dependencies at different time scales to address the variability in the duration of spindle waves.
[0079] Multi-scale dilated convolution design: The enhancement path includes at least two parallel dilated convolution branches, each employing a different dilation rate to cover different time scales. Preferably, it includes a first dilated branch with a dilation rate of 2 to capture temporal correlations of medium span, and a second dilated branch with a dilation rate of 4 to capture contextual information of longer span. The kernel size is preferably 3, and padding is set according to the dilation rate to ensure that the temporal length of the output features of each branch is consistent with the input. The outputs of the two dilated branches are normalized and activated respectively, then concatenated along the channel dimension, and finally fused and compressed using a 1×1 convolution to obtain the enhanced feature Di.
[0080] A progressive learning strategy is adopted, which sets an independent learnable fusion weight parameter γ for the enhancement path. A cold start mechanism is used to initialize γ to a minimum value (e.g., 0.001). This makes the contribution of the enhancement path approximately zero in the early stage of training, and the network mainly relies on the main path to converge. As training progresses, γ is gradually increased, which enables the enhancement path to learn "under what feature quality conditions it is effective to contribute", avoiding gradient conflicts in the early stage of training.
[0081] 3.3 Enhance path quality assessment, gating, and contribution cap
[0082] To prevent low-quality features from introducing noise through enhancement paths, this invention designs a rigorous quality assessment and restricted fusion mechanism.
[0083] (1) The gated augmented feature Di enters the Quality Assessment Network and outputs the quality factor qd. This assessment network can have the same or equivalent structure as the quality assessment module in the skip connection (e.g., it includes global pooling and fully connected mapping) and is used to determine the credibility of the augmented feature at the current time in real time.
[0084] (2) The "threshold-based" strategy is used to dynamically control the activation state of the enhancement path: when qd is below the threshold, the enhancement path is suppressed; when qd exceeds the threshold, the enhancement path participates in fusion according to the gating strength. The threshold can be 0.5, and the amplification factor can be 2.0 or other values.
[0085] (3) The weights of the enhanced path that ultimately participate in the output are restricted weights w=clip(γ×gate(qd), 0, βd), where βd is the upper limit, preferably not exceeding 0.3, to avoid the enhanced path causing excessive perturbation to the main path. (4) The bottleneck output is obtained by superimposing the main path output and the enhanced features of the restricted weights, and can form a residual connection with the bottleneck input. The residual ratio can be set in the range of 0.05 to 0.3 to enhance gradient propagation and noise resistance.
[0086] S4 Decoding Unit: Decoder Module and Recursive Generalized Self-Attention Module (RG-SA)
[0087] This invention embeds a Recursive Generalized Self-Attention (RG-SA) module at the skip connection between the encoder and decoder. It constructs a long-range global context through recursive downsampling and calibrates local details using a cross-attention mechanism. Simultaneously, it introduces a quality assessment network and a constrained incremental fusion strategy to achieve "on-demand injection" and "amplitude constraint" of enhanced features, effectively preventing low-quality features from interfering with the main signal and improving the model's robustness in complex noisy environments.
[0088] 4.1 Recursive Generalized Self-Attention Module (RG-SA) Architecture
[0089] The RG-SA function originates from the jump feature Fi on the encoder side. The input tensor is (B, C, Li), and the output is the enhanced jump feature Gi, which also has the shape (B, C, Li), used to supplement long-range dependency information.
[0090] The enhanced hop feature Gi does not directly replace Fi, but performs restricted incremental fusion with Fi to obtain the final hop feature Fi*, which is then fused with the decoder upsampled features.
[0091] 4.1.1 Recursive Downsampling and Global Context Construction
[0092] To reduce the computational complexity of self-attention and capture long temporal context, RG-SA first constructs low-resolution contextual features through recursive downsampling units. The input jump features Fi are downsampled at multiple levels along the temporal dimension to obtain low-resolution contextual features Ri. Downsampling can be implemented using depthwise separable convolutions or grouped convolutions, with a stride preferably of 4 or 2.
[0093] The number of recursions K is adaptively determined based on the input length Li. When Li is large, the number of recursions increases to ensure the final contextual features cover a sufficiently long time range; when Li is small, the number of recursions is at least 1 to ensure at least one contextual abstraction. This results in low-resolution contextual features Ri. After local patterns are extracted from the contextual features Ri through depthwise convolution, they are then compressed using a 1×1 convolution to obtain compact feature representations, the key vector Ki and value vector Vi, used for attention calculation, thereby reducing the computational complexity of the attention matrix.
[0094] 4.1.2 Cross-attention calibration and conditional location coding
[0095] RG-SA employs a cross-attention approach, generating a query vector Qi from the original high-resolution skip features Fi through a linear mapping, and mapping the downsampled and compressed contextual features into a key vector Ki and a value vector Vi. An attention matrix is obtained by calculating the similarity between Qi and the compressed Ki, and Vi is then weighted and converged to generate an initial enhanced feature Gi. This process achieves "calibrating local details (Query) with global context (Key / Value)".
[0096] To avoid the rigidity of explicit position vectors (such as sinusoidal embedding), RG-SA introduces a depthwise convolutional position enhancement unit in the value vector Vi branch. This unit performs temporal convolution on Vi using depthwise convolution to obtain the position enhancement amount, which is then added to Vi and input into attention convergence. This approach dynamically enhances the encoding capability of spindle wave duration and start / end boundary positions without introducing additional position parameter vectors.
[0097] 4.2 Integration Strategy of Quality Assessment and Constrained Incremental Analysis
[0098] To prevent the enhanced features Gi generated by RG-SA from introducing noise under low signal-to-noise ratio conditions, this invention designs a strict quality gating and fusion constraint mechanism.
[0099] (1) The quality assessment network adopts a lightweight network structure, which consists of "adaptive average pooling - dimensionality reduction convolution - activation - dimensionality increase convolution - sigmoid". The enhanced jump feature Gi output by RG-SA enters the quality assessment network to generate a scalar quality factor qi, which ranges from 0 to 1 and represents the credibility of the enhanced feature at the current time.
[0100] (2) The hard threshold gating mechanism adopts a hard threshold activation + linear amplification strategy to control the opening of the enhancement path. When qi does not exceed the preset threshold θ, the gating value approaches 0, so that Gi does not participate or weakly participates in the fusion; when qi is greater than θ, the gating value increases with the increase of qi. The threshold θ is preferably 0.5, and the linear amplification coefficient s can be set, preferably s is 2.0, so that qi in the interval [0.5, 1.0] is mapped to the gating strength of [0, 1.0].
[0101] (3) The constrained incremental fusion adopts learnable weight initialization, sets the learnable fusion parameter α, and initializes it to a minimum value (e.g., 0.001) so that the enhancement branch has little impact on the system in the initial stage, and then gradually learns the optimal fusion ratio; at the same time, the maximum upper limit β of the final fusion weight of α and the gating value is set, and β is preferably no more than 0.3, so as to limit the maximum contribution ratio of the enhancement branch to the final feature. Thus, a conservative fusion mechanism of "original jump features as the main feature and enhancement branches as the auxiliary feature" is formed.
[0102] (4) The residual superposition output, the final jump feature Fi* can be constructed as follows: Fi is the base term, and then the incremental term with restricted weights (the difference between Gi and Fi or Gi itself) is superimposed to avoid distribution drift caused by the augmentation branch and improve the stability of training and inference.
[0103] 4.3 Exception Handling and Adaptive Degradation Protection Mechanism
[0104] To further enhance the robustness and availability of the system under edge computing devices or extreme data conditions, this invention incorporates anomaly detection and adaptive degradation strategies in the RG-SA module and skip connection paths. When a computational anomaly is detected or the input conditions are not met, the system can automatically degrade to the standard convolutional pass mode, ensuring that the detection process is not interrupted.
[0105] (1) Degradation protection for computational anomalies: During RG-SA execution, if anomalies such as dimension mismatch, insufficient length due to downsampling, or memory overflow are detected in the attention matrix calculation, the system immediately triggers a bypass mechanism (Bypass Mode) to skip the current RG-SA enhancement calculation and quality gating fusion step. It can degrade to not using RG-SA enhancement and directly pass the original skip feature Fi from the encoder side as the final skip feature Fi* to the decoder. This ensures that even in the extreme case of attention module failure, the backbone of the U-shaped network remains unobstructed, and the system can still output detection results based on the basic convolutional features, avoiding program crashes or invalid outputs and ensuring system availability and robustness.
[0106] (2) Adaptive adjustment of short sequence input: When the length of the input sequence Li is short, the number of recursive downsamplings inside RG-SA can be dynamically adjusted or the recursive downsampling can be skipped directly. This avoids the contextual features from degenerating into nothingness or losing key temporal information due to excessive downsampling, and ensures that the model can work stably under different length input segments (such as short-term micro-sleep events).
[0107] 4.4 Decoder Module and Feature Reconstruction
[0108] The decoder module is used to recover the temporal resolution step by step and output the point-by-point discrimination result by combining the enhanced jump features.
[0109] (1) Upsampling method and channel mapping
[0110] The upsampling strategy involves upsampling deep features at each decoding unit level, prioritizing nearest-neighbor upsampling to reduce the number of parameters and maintain stability. Linear interpolation upsampling or transposed convolution can also be used. After upsampling, a one-dimensional convolution maps the number of channels to the target number of channels, so that they can be concatenated with the skip features in the channel dimension before entering the convolutional block for processing.
[0111] (2) Jump fusion and convolutional reconstruction
[0112] Feature concatenation: The final skip features Fi*, enhanced by RG-SA and gated filtering, are concatenated with the decoder upsampled features along the channel dimension. The concatenated features are then fed into the convolutional reconstruction block, which can employ a double convolution structure and may further embed the aforementioned edge-guided attention (EGA) module to achieve the reconstruction and calibration of semantic information and detailed textures.
[0113] (3) Size alignment and output cropping
[0114] When there is a difference in time length between the skip features and the upsampled features (caused by pooling / upsampling factor), the system prioritizes symmetrical padding of the shorter features to achieve alignment and avoid information loss. At the end of the network, the output probability sequence is finally pruned according to the original input signal length L, removing all padding parts to ensure that the output point-by-point detection results strictly correspond one-to-one with the time axis of the input EEG signal.
[0115] 5. Category Output Unit: Output discrimination unit and post-processing unit
[0116] It consists of two sub-modules: an output discrimination unit and a post-processing unit. The output discrimination unit realizes the point-by-point mapping from the feature space to the probability space. Through temporal smoothing, threshold determination and physiological rule constraints, the output discrimination unit transforms the discrete probability sequence into continuous, clinically significant spindle wave event segments.
[0117] 5.1 Output Discriminant Unit: Pointwise Probability Mapping
[0118] The high-resolution features recovered by the decoder are then classified and discriminated to generate point-by-point class confidence scores.
[0119] (1) The channel mapping and Logits generation structure uses a 1×1 convolutional layer as the classification head, mapping the feature tensor Z output by the decoder to C class channels (total number of classes) to obtain a pointwise normalized logits tensor Z. The Softmax function (for multi-class classification) or the Sigmoid function (for binary classification) is applied to the logits tensor Z along the class dimension to transform it into a normalized probability distribution. A pointwise probability sequence P is generated. For binary classification tasks, the probability sequence P of the "spindle wave" class is the focus.
[0120] (2) When it is a binary classification, the output can be "spindle wave probability sequence" and "non-spindle wave probability sequence"; when it is a multi-class classification, it can output the probability sequence of different subtypes of spindle waves or other sleep microstructure events.
[0121] 5.2 Post-processing unit
[0122] Since point-by-point prediction by neural networks may be subject to high-frequency jitter or instantaneous false alarms, the post-processing unit introduces signal processing and rule engine to transform the probability sequence into a stable list of events.
[0123] (1) The post-processing unit performs time-domain smoothing on the point-by-point probability sequence to suppress high-frequency noise in point-by-point prediction and enhance the continuity of event boundaries. A moving average filter is applied to the spindle wave probability sequence, with a filter window size of W. W can be calculated based on the signal sampling rate, and the corresponding time span is 0.1 seconds to 2.0 seconds. For example, if the sampling rate ranges from 10 to 200 sampling points. The smoothed probability sequence can more accurately reflect the continuous oscillation characteristics of the spindle wave and eliminate isolated spike false alarms.
[0124] (2) Event segment merging and physiological constraint filtering
[0125] After smoothing, a point-by-point label sequence can be generated using threshold discrimination or by taking the maximum class of each point, and consecutive positive class time points can be merged into an event segment output. The event segment can be further constrained by a minimum duration (not less than 0.5 seconds in this embodiment) to filter out short noise segments; the structured event output results can include fields such as the event start point, end point, duration, and maximum confidence level, which facilitates subsequent statistical analysis of indicators such as spindle wave density and duration.
[0126] [Experimental Results Verification]
[0127] To verify the effectiveness and advancement of the proposed sleep spindle wave automatic detection method (REGA-Net), we conducted performance tests on the publicly available standard dataset MASS.
[0128] 1. Experimental setup and evaluation indicators
[0129] In this experiment, the overlap threshold was set to 20%, meaning that when the intersection-union ratio (IoU) between the model-predicted detection box and the ground truth annotation box is greater than or equal to 20%, the detection is considered correct.
[0130] Evaluation indicators include:
[0131] Precision: Reflects the accuracy of the model's predictions;
[0132] Recall: Reflects the model's ability to detect true targets and avoids missed detections;
[0133] F1 score: The harmonic mean of precision and recall, used to comprehensively evaluate model performance.
[0134] In addition, to verify the model's generalization ability across different age groups, we divided the test data into a Younger group and an Older group for separate statistical analysis.
[0135] 2. Comparison Methods
[0136] This experiment compares the proposed method (REGA-Net) with the following existing technologies: Mean Expert, A7, and SUMO.
[0137] 3. Experimental Results and Analysis
[0138] The specific testing performance comparison data is shown in the table below:
[0139] Accuracy Recall rate F1 score F1 score F1 score Mean Expert 0.78 0.72 0.72 0.76 0.65 A7 0.7 0.76 0.73 0.74 0.71 SUMO 0.85 0.79 0.82 0.84 0.79 REGA-Net (this application) 0.831 0.859 0.845 0.878 0.787
[0140] 4. Results Explanation
[0141] The data in the table above shows that:
[0142] Optimal overall performance: The REGA-Net method proposed in this application achieves an overall F1 score of 0.845, which is better than the comparative methods SUMO (0.820), A7 (0.730) and expert mean (0.720), indicating that the method has the best overall performance in balancing precision and recall.
[0143] High recall advantage: REGA-Net achieved an overall recall of 0.859, significantly higher than all other comparative methods. This means that this method can effectively reduce the missed detection of sleep spindle waves, which is of great significance for avoiding the omission of key pathological features in clinical auxiliary diagnosis.
[0144] Strong age generalization ability:
[0145] In the young group data, REGA-Net achieved an F1 score of 0.878, significantly outperforming the second-best method SUMO (0.840), demonstrating its strong ability to capture the EEG characteristics of young subjects.
[0146] In the elderly group data, although the performance of all methods declined to some extent (due to the increased complexity of EEG signals in the elderly), REGA-Net still maintained an F1 score of 0.787, which was basically on par with the best comparison method SUMO (0.790) and much higher than the expert mean (0.650) and the A7 method (0.710), demonstrating that the method has good robustness and applicability in different age groups.
[0147] In summary, the REGA-Net method proposed in this application outperforms existing technologies and the average level of manual methods in terms of detection accuracy, false negative control, and cross-age adaptability, demonstrating significant progress.
[0148] Example 2
[0149] This embodiment discloses a system for performing a recursive edge-guided attention network method for sleep spindle detection, comprising: an input preprocessing unit for preprocessing the input raw EEG signal data and outputting a standardized temporal signal tensor.
[0150] Feature encoding unit: Based on the temporal signal tensor, multi-level feature extraction and downsampling are performed to obtain multi-scale encoded features; the feature encoding unit includes a basic convolution module, a downsampling module, and a multi-stage edge-guided attention enhancement module embedded in the basic convolution module; the multi-stage edge-guided attention enhancement module uses gradient operators to extract boundary information in the shallow layer, and uses smoothing operators to extract envelope and contour information in the deep layer, and adaptively fuses the extracted morphological prior features into the main feature flow.
[0151] The bottleneck enhancement unit processes deep encoded features. The bottleneck enhancement unit adopts a dual-path structure, including a main path for extracting local patterns and an enhancement path for expanding the receptive field. The main path consists of a basic convolutional block composed of a standard one-dimensional convolution, a normalized layer, and a nonlinear activation function, which extracts local patterns from the bottleneck input features. The enhancement path contains at least two parallel dilated convolutional branches, each branch using a different dilation rate to cover different time scales.
[0152] The enhanced features output by the enhanced path are fused with the features of the main path after being restricted by a quality gating mechanism;
[0153] The feature decoding unit recovers the temporal resolution step by step through multiple decoding layers, and embeds a recursive generalized self-attention module in each decoding layer. The recursive generalized self-attention module recursively downsamples the jump features from the corresponding layer from the encoder side to construct global contextual features, and uses a cross-attention mechanism to calibrate local details. A quality factor is generated through a quality evaluation network, and the enhanced jump features are injected into the current decoding layer through a hard threshold gating and restricted incremental fusion strategy, and fused with the upsampled features.
[0154] The category output unit includes an output discrimination unit and a post-processing unit. The output discrimination unit and the post-processing unit generate point-by-point category probabilities based on the feature sequence output by the decoder. The post-processing unit is used to generate time period information of sleep spindle wave events.
[0155] Example 3
[0156] This embodiment also discloses a computer-readable storage medium storing a computer program that, when executed by a processor, implements the steps in the above-described method embodiments.
[0157] The above description is merely a preferred embodiment of the present invention and is not intended to limit the invention. Various modifications and variations can be made to the present invention by those skilled in the art. Any modifications, equivalent substitutions, improvements, etc., 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 sleep spindle waves based on deep learning, characterized in that, Includes the following steps: Raw EEG signal data is acquired and preprocessed to obtain a standardized time-series signal tensor. The time-series signal tensor is input into the feature encoder unit for multi-level feature extraction and downsampling to obtain multi-scale encoded features; A multi-stage edge-guided attention module is embedded in the encoding process. This module adaptively switches the morphological prior extraction strategy according to the network layer depth: it extracts boundary mutation information based on gradient operators in shallow layers and extracts envelope contour information based on smoothing operators in deep layers, and then integrates the extracted morphological prior features into the backbone features. The multi-scale encoded features are input into the bottleneck enhancement unit, which includes parallel basic convolutional main paths and multi-scale dilated convolutional enhancement paths. The credibility of the enhancement path features is evaluated through a quality gating mechanism, and the contribution of the enhancement paths is fused in a restricted manner based on the credibility to obtain the bottleneck features. The fused features output from the bottleneck layer are input into the feature decoding unit for progressive upsampling and recovery. At the jump connection of the decoder, the jump features from the encoder are recursively downsampled using a recursive generalization self-attention module to construct a global context. Local details are calibrated through a cross-attention mechanism. After quality evaluation and constrained incremental fusion, enhanced jump features are obtained and fused with the upsampled features. Point-by-point category probabilities are generated based on the feature sequences output by the decoder, and the time period information of the sleep spindle wave event is obtained through post-processing.
2. The method according to claim 1, characterized in that, The multi-stage edge-guided attention module includes a boundary gradient guidance unit, a contour envelope guidance unit, and a channel adaptive weighting unit. The boundary gradient guidance unit uses a one-dimensional gradient operator to perform convolution operations on shallow features in the shallow edge stage to extract boundary guidance features. The boundary guidance features are added to and fused with the original features to obtain boundary enhancement features. The contour envelope guidance unit uses a one-dimensional smoothing operator to perform convolution operations on deep features in the deep stage, extracts envelope and contour information, and obtains smooth features. The channel adaptive weighting unit generates channel weights based on feature statistics, scales the fused morphological prior features channel by channel, and superimposes them back into the backbone features in a residual manner.
3. The method according to claim 1, characterized in that, The recursive generalization self-attention module recursively downsamples the input jump features to obtain low-resolution context features, and constructs global context features based on the low-resolution context features. By using a cross-attention mechanism, the original jump features are used as the query vector, and the key vector and value vector derived from the global context features are converged for attention to obtain the enhanced jump features. A quality factor is generated for the enhanced jump feature through a quality assessment network. When the quality factor exceeds a preset threshold, the gating strength is calculated based on the amplification factor, and the enhanced jump feature is fused to the original jump feature in a restricted incremental fusion manner with restricted weights.
4. The method according to claim 1, characterized in that, The multi-scale dilated convolution enhancement path contains at least two parallel convolutional branches with different dilation rates. The enhanced features of the enhanced path output are used to generate quality factors through an independent quality evaluation network, and after being fused with hard threshold gating and restricted increment, they are superimposed on the main path output in the form of residuals. The quality gating mechanism outputs a quality factor through a quality assessment network. When the quality factor is lower than a preset threshold, the enhancement path is suppressed. When the quality factor is higher than the preset threshold, the gating strength is calculated according to a linear amplification strategy.
5. The method according to claim 4, characterized in that, The quality assessment network is sequentially connected to an adaptive average pooling layer, a dimension-reducing convolutional layer, an activation function layer, a dimension-upgrading convolutional layer, and a Sigmoid activation layer. The quality factor ranges from 0 to 1. The threshold is set to θ. When the quality factor is less than or equal to the preset threshold θ, the gate value approaches zero. When the quality factor is greater than or equal to θ, the gate value increases linearly or non-linearly with the quality factor. The adaptive average pooling layer is used to perform global spatial compression on the input enhanced jump features, and the dimensionality reduction convolutional layer and the dimensionality increase convolutional layer form a bottleneck structure to extract the quality dependencies between channels.
6. The method according to claim 3, characterized in that, The recursive generalization self-attention module also includes an anomaly degradation protection mechanism: The number of recursive downsampling iterations is adaptively determined based on the time length of the input jump feature. When the length is short, the number of recursion iterations is reduced or recursive downsampling is skipped. During execution, if a dimension mismatch, memory overflow, or computational anomaly is detected, a bypass mechanism is immediately triggered, skipping the current self-attention enhancement computation and quality gating fusion step, and directly passing the original jump features from the encoder side as the final jump features to the decoder.
7. The method according to claim 1, characterized in that, The post-processing in step S5 includes: performing temporal smoothing filtering on the point-by-point category probability sequence, generating a binary label sequence by threshold discrimination, merging consecutive positive class labels into event segments, and filtering out event segments with a duration lower than a preset minimum threshold.
8. A recursive edge-guided attention network system for sleep spindle wave detection, characterized in that, To implement the method of any one of claims 1-7, comprising: The input preprocessing unit preprocesses the raw EEG signal data and outputs a standardized time-series signal tensor. The feature encoding unit performs multi-level feature extraction and downsampling on the temporal signal tensor to obtain multi-scale encoded features. The feature encoding unit includes a basic convolution module, a downsampling module, and a multi-stage edge-guided attention enhancement module embedded in the basic convolution module. The multi-stage edge-guided attention enhancement module uses gradient operators to extract boundary information in the shallow layer and smoothing operators to extract envelope and contour information in the deep layer, and adaptively fuses the extracted morphological prior features into the main feature flow. The bottleneck enhancement unit processes deep coding features. The bottleneck enhancement unit adopts a dual-path structure, including a main path for extracting local patterns and an enhancement path for expanding the receptive field. The enhancement features output by the enhancement path are fused with the features of the main path after being restricted by a quality gating mechanism. The feature decoding unit recovers the temporal resolution step by step through multiple decoding layers, and embeds a recursive generalized self-attention module in each decoding layer. The recursive generalized self-attention module recursively downsamples the jump features from the corresponding layer from the encoder side to construct global contextual features, and uses a cross-attention mechanism to calibrate local details. A quality factor is generated through a quality evaluation network, and the enhanced jump features are injected into the current decoding layer through a hard threshold gating and restricted incremental fusion strategy, and fused with the upsampled features. The category output unit includes an output discrimination unit and a post-processing unit; the output discrimination unit generates point-by-point category probabilities based on the feature sequence output by the decoder; the post-processing unit is used to generate time period information of sleep spindle wave events based on the point-by-point category probabilities.
9. The system according to claim 8, characterized in that, The main path consists of a basic convolutional block composed of a standard one-dimensional convolution, a normalized layer, and a nonlinear activation function, which performs local pattern extraction on the bottleneck input features; the enhancement path contains at least two parallel dilated convolutional branches, each branch using a different dilation rate to cover different time scales.
10. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the program is executed by the processor, it implements the method of any one of claims 1 to 7.