Electrocardiogram arrhythmia classification method and system based on residual shrinkage network
By employing a residual shrinking network approach, combined with wavelet denoising, data balancing, and multi-attention mechanisms, the problems of noise interference, data imbalance, and feature extraction in ECG arrhythmia classification are solved, achieving efficient and accurate arrhythmia classification suitable for resource-constrained terminals.
Patent Information
- Application Number
- CN202511200903.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-08-26
- Publication Date
- 2025-11-28
AI Technical Summary
Existing electrocardiogram arrhythmia classification technologies suffer from problems such as insufficient noise interference handling, significant impact of data imbalance, limited feature extraction capabilities, poor generalization ability, and low computational efficiency, making them difficult to deploy on resource-constrained terminals.
A residual shrinking network-based approach was adopted, which constructs an arrhythmia classification model by wavelet denoising, undersampling-oversampling hybrid strategy, CNN network, GRU network and multi-attention mechanism, performs data balancing and feature extraction, and combines temporal self-attention and translead attention to optimize the training strategy to improve classification accuracy and generalization ability.
It significantly improves the accuracy and generalization ability of arrhythmia classification, enhances the recognition effect of abnormal heartbeats, adapts to diverse clinical scenarios, and is suitable for resource-constrained terminals.
Smart Images

Figure CN121015205A_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the technical field of arrhythmia classification, and particularly relates to an electrocardiogram arrhythmia classification method and system based on a residual contraction network. BACKGROUND
[0002] An electrocardiogram (ECG) is an important medical means for recording the electrical activity of the heart and is indispensable in the diagnosis of cardiac diseases such as arrhythmia. Traditional ECG analysis relies on manual interpretation by physicians, which has the problems of low efficiency, strong subjectivity, and great influence by experience, and therefore automatic classification methods have become a research hotspot.
[0003] Early algorithms combine hand-designed features with classic classifiers, and although they perform stably on small-scale datasets (such as 85%-90% classification accuracy on the MIT-BIH database of 5 classes), they are dependent on professional knowledge and sensitive to feature design, and have limited generalization ability across datasets. With the improvement of computing power, deep learning has become the mainstream: CNN models are good at extracting local shape features, RNN / LSTM models are good at capturing temporal dependencies, and Transformer models model long-range relationships through self-attention, and fusion models (such as CNN+LSTM) have improved the classification accuracy of the MIT-BIH database to 92%-95%.
[0004] However, the prior art still has the following significant defects: first, noise interference is not handled well, and power frequency, electromyographic noise, etc. are difficult to completely remove, and existing models lack a special suppression mechanism, resulting in features containing noise information; second, data imbalance has a great impact, and simple oversampling easily introduces noise and undersampling loses information, so that the recall rate of the minority class heartbeat is often less than 70%; third, the feature extraction capability is limited, and a single model (CNN model is not good at modeling long sequences, and LSTM model is sensitive to local features) is difficult to fully capture deep and temporal features, and has weak discrimination ability for similar heartbeats; fourth, the generalization ability is poor, and is often optimized on a single dataset, and has insufficient cross-scene adaptability; fifth, the computing efficiency is low, and the complex model has large parameters and slow reasoning, which is difficult to deploy on resource-constrained terminals. These problems restrict the practical application of ECG automatic classification. SUMMARY
[0005] The purpose of the present application is to provide an electrocardiogram arrhythmia classification method and system based on a residual contraction network to improve the above technical problems.
[0006] In order to achieve the above application purpose, the embodiments of the present application provide the following technical solutions:
[0007] An electrocardiogram arrhythmia classification method based on a residual contraction network comprises:
[0008] An original ECG signal (electrocardiogram signal) is obtained and preprocessed to obtain an ECG signal.
[0009] The ECG balanced signal is obtained by performing data balancing processing on the ECG signal through an under-sampling-over-sampling hybrid strategy.
[0010] An arrhythmia classification model is constructed based on a CNN network and a GRU network and in combination with time sequence self-attention and cross-lead attention.
[0011] The ECG balanced signal is input into the arrhythmia classification model for classification to obtain an arrhythmia classification result.
[0012] An electrocardiogram arrhythmia classification system based on a residual shrinkage network comprises:
[0013] An ECG signal acquisition module is configured to acquire an original ECG signal (electrocardiogram signal) and perform preprocessing to obtain an ECG signal.
[0014] An ECG balancing module is configured to perform data balancing processing on the ECG signal through an under-sampling-over-sampling hybrid strategy to obtain an ECG balanced signal.
[0015] An arrhythmia classification model construction module is configured to construct an arrhythmia classification model based on a CNN network and a GRU network and in combination with time sequence self-attention and cross-lead attention.
[0016] An arrhythmia classification model training module is configured to train the arrhythmia classification model.
[0017] An arrhythmia classification module is configured to input the ECG balanced signal into the arrhythmia classification model for classification to obtain an arrhythmia classification result.
[0018] The present application has the following advantages:
[0019] The present application realizes efficient electrocardiogram arrhythmia classification through multi-link cooperation, and the core is a model design of fine preprocessing, data balancing strategy and multi-attention mechanism: the preprocessing provides high-quality input through wavelet denoising and accurate R-wave detection; the under-sampling-over-sampling hybrid strategy solves the class imbalance and improves the minority class recognition; the ResTCL-Net fuses the CNN, GRU, RCA, TSA and CLA modules to mine signal features in multiple dimensions; the optimized training strategy considers efficiency and stability, and comprehensive evaluation guarantees performance. The scheme significantly improves the classification accuracy and generalization ability, and enhances the abnormal heartbeat recognition. BRIEF DESCRIPTION OF DRAWINGS
[0020] In order to more clearly illustrate the technical solutions of the embodiments of the present application, the following will briefly introduce the drawings needed to be used in the embodiments. It should be understood that the following drawings only show some of the embodiments of the present application, and therefore should not be regarded as a limitation on the scope. For those skilled in the art, other related drawings can also be obtained without creative labor.
[0021] Figure 1 The method flowchart in the embodiments of the present application is shown in the figure.
[0022] Figure 2 The arrhythmia classification model structure diagram in the embodiments of the present application is shown in the figure.
[0023] Figure 3 The system structure diagram in the embodiments of the present application is shown in the figure. DETAILED DESCRIPTION
[0024] The technical solutions of the embodiments of the present application will be described clearly and completely in the following with reference to the drawings of the embodiments of the present application. Obviously, the described embodiments are only some of the embodiments of the present application, but not all. The components of the embodiments of the present application described and shown in the drawings can be arranged and designed in various different configurations. Therefore, the following detailed description of the embodiments of the present application provided in the drawings is not intended to limit the scope of the claimed present application, but only represents selected embodiments of the present application. Based on the embodiments of the present application, all other embodiments obtained by those skilled in the art without creative labor are within the scope of the present application.
[0025] Please refer to Figure 1 The present embodiment provides a method for classifying arrhythmia of electrocardiogram based on residual shrinkage network. Figure 1 The execution subject of the method shown can be a software and / or hardware device. The execution subject of the present application can include but is not limited to at least one of the following: user equipment, network equipment, etc. Among them, the user equipment can include but is not limited to computer, smart phone, personal digital assistant (Personal Digital Assistant, PDA) and the above-mentioned electronic equipment, etc. The network equipment can include but is not limited to a single network server, a server group composed of multiple network servers or a cloud composed of a large number of computers or network servers based on cloud computing. Cloud computing is a kind of distributed computing, which is a super virtual computer composed of a group of loosely coupled computers. The present embodiment does not make any limitation.
[0026] A method for classifying arrhythmia of electrocardiogram based on residual shrinkage network, comprising:
[0027] S1, obtaining an original ECG signal and preprocessing to obtain an ECG signal;
[0028] The preprocessing includes wavelet denoising, R-wave detection, heartbeat segmentation and standardization, so that the S1 includes:
[0029] S1-1, using db4 wavelet algorithm to perform wavelet denoising on the original ECG signal to obtain an ECG denoising signal;
[0030] Specifically, using db4 wavelet to perform 5-layer multi-resolution decomposition on the original ECG signal to obtain one group of approximation coefficients (cA5) and five groups of detail coefficients (cD1-cD5); according to the formula:
[0031]
[0032] The adaptive threshold T of each detail coefficient is calculated respectively i ; wherein, log(·) represents the logarithmic function with natural constant as the base, σi represents the standard deviation sum corresponding to the i-th detail coefficient, and l i represents the signal length of the original ECG signal corresponding to the i-th detail coefficient.
[0033] Based on the respective adaptive threshold, soft threshold processing is performed on each detail coefficient to remove the detail coefficients less than the adaptive threshold, to obtain the screened detail coefficients, which can avoid the "pseudo Gibbs phenomenon" (oscillation distortion) at the signal mutation, make the denoised ECG waveform smoother, and at the same time retain the steep characteristics of R wave;
[0034] Wavelet reconstruction is performed on each screened detail coefficient and approximation coefficient to obtain an ECG denoising signal.
[0035] S1-2, performing R-wave detection on the ECG denoising signal through a Butterworth band-pass filter to obtain an ECG detection signal and R-wave position information thereof;
[0036] Specifically, using a 4th-order Butterworth band-pass filter of 5-15 Hz to process the ECG denoising signal, to enhance the QRS wave characteristics of the ECG denoising signal, and obtain an ECG filtered signal.
[0037] The first derivative of the ECG filtered signal is calculated and used as the steep slope of the R wave; the ECG filtered signal is squared to obtain an ECG amplification signal, which amplifies the peak value difference of the ECG filtered signal, so that the peak value corresponding to the R wave is more prominent in the subsequent processing, facilitating the subsequent peak detection.
[0038] The ECG amplified signal is smoothed by moving average with a 150 ms window to obtain an integrated feature sequence. The candidate peak values (minimum height is set to 0.5 times the maximum value of the sequence) of the feature sequence are detected by using the scipy.signal.find_peaks function, and the real R wave positions (R wave real information) in the range of ±25 sampling points (about 70 ms) before and after the candidate peak values in the original ECG signal are searched to obtain an ECG detection signal, ensuring that the positioning error is less than 50 ms.
[0039] S1-3, taking the R wave position information as the center of the window, setting the intercepting window; the ECG detection signal is segmented by the intercepting window to obtain the corresponding heartbeat segment;
[0040] The purpose of heartbeat segmentation is to extract the signal segment corresponding to each heartbeat (heartbeat) from the continuous electrocardiogram signal, and to unify the segment length to facilitate subsequent model analysis. Therefore, the S1-3 includes:
[0041] Since each R wave corresponds to a key node of a heartbeat, the R wave position information is taken as the center of the intercepting window to ensure that the core features of the heartbeat are included when intercepting. Taking the R wave position information as a “peak point (peak)”, the signal segment from peak-179 to peak+180 is intercepted, covering the key features of QRS complex and P wave and determining the corresponding lead signal to obtain the heartbeat segment. If the intercepting window exceeds the ECG detection signal range (such as the beginning or end of the signal), the window is automatically adjusted to the beginning or end of the signal to ensure that the length of each heartbeat segment is strictly 360 points, and the input format is unified.
[0042] S1-4, standardizing the heartbeat segment corresponding to the ECG detection signal to obtain an ECG signal.
[0043] Specifically, the two lead signals of each heartbeat segment in the ECG detection signal are standardized respectively, and the difference between each heartbeat segment and its mean value is divided by the standard deviation. If the standard deviation of the lead signal is 0 (no fluctuation), the lead signal is directly set to 0 to eliminate the influence of direct current component and amplitude difference on model training, so that the model pays more attention to the waveform shape of the ECG signal rather than the amplitude size.
[0044] S2, balancing the data of the ECG signal by an under-sampling-over-sampling hybrid strategy to obtain an ECG balanced signal;
[0045] Due to the fact that normal heartbeats in the ECG signal account for a much higher proportion than abnormal heartbeats (such as ventricular premature beats and atrial premature beats), there is a problem of unbalanced data set categories. Therefore, data balancing processing is introduced to solve the problem of unbalanced data set categories and improve the classification performance of the minority class in the ECG signal. However, existing methods for handling data imbalance, such as oversampling, can easily lead to deviation of the distribution of synthetic samples and real samples, introducing noise. Under-sampling can lose effective information of the majority class, causing the model to tend to the majority class, and the recall rate of the minority class is generally lower than 70%, reducing the recognition ability of the classification model for heartbeats corresponding to the minority class. Further, the embodiment proposes a hybrid strategy composed of under-sampling and oversampling to solve the problem of class imbalance.
[0046] The hybrid strategy composed of under-sampling and oversampling includes:
[0047] The number of samples of each heartbeat type in the ECG signal is counted to determine the degree of imbalance and determine the majority class, the intermediate class and the minority class. The ECG signal is sampled by the hybrid strategy composed of under-sampling and oversampling to obtain the ECS sampling signal; a subset of samples of the majority class is randomly selected by under-sampling, and the number of samples of the majority class is reduced to within ten times the number of samples of the minority class; the samples in the minority class are copied by using a random sampling method with replacement, that is, the number of samples of the minority class is supplemented to the number of samples of the majority class after under-sampling by oversampling, to avoid loss of information of the ECG signal; the intermediate class is completely retained. The samples in the ECS sampling signal are randomly rearranged to eliminate the potential influence of data order on model training, and an ECG balanced signal is obtained.
[0048] Among them, the minority class is the heartbeat type with the least number of samples, the majority class is the heartbeat type with the number of samples more than ten times the number of samples of the minority class, and the intermediate class is the heartbeat type with the number of samples between one times and ten times the number of samples of the minority class.
[0049] S3, based on the CNN network and the GRU network and combined with the time sequence self-attention and the cross-lead attention, a heart rhythm disorder classification model, i.e. ResTCL-Net model, is constructed;
[0050] Due to the network structure design of part of the existing classification model, it is difficult to fully capture the deep features and time sequence information in the ECG signal. For example, although the convolutional neural network (CNN) can extract local waveform features, it is insufficient to model long-term time sequence dependence. Although the long short-term memory network (LSTM) can process time sequence data, it has low sensitivity to local key features. This leads to insufficient ability to distinguish some similar heart beat types, and the classification accuracy needs to be improved. In addition, the classification model has insufficient generalization ability, is usually trained and optimized in a single data set, and has poor generalization performance in new data sets or different clinical scenarios, which is difficult to adapt to the diversified needs in actual application. Therefore, in order to solve the problems of being unable to fully capture deep features and time sequence information and insufficient generalization ability of the classification model, the RCA (residual channel attention) module, the TSA (time sequence sub-attention) module and the CLA (cross-lead attention) module are selected.
[0051] As shown in Figure 2 The arrhythmia classification model includes an initial feature extraction layer, residual layers 1 to 4, an RCA module, a TSA module, a CLA module and a classification layer connected in series. The outputs of the residual layers 1 to 4 are all connected to an RCA module, and the outputs of each RCA module are input to the TSA module after being merged.
[0052] The initial feature extraction layer includes a Conv layer, a BN layer (batch normalization layer), a ReLU layer and a Maxpool layer (maximum pooling layer) connected in series. The convolution kernel of the Conv layer is 7x1, and the input channel number and the output channel number are 2 and 32 respectively. The padding is 3, which further ensures that the feature length remains unchanged, and is used to extract the local waveform features of each lead signal in the ECG balanced signal. The ReLU layer introduces a nonlinear change to increase the expression ability of the features. The Maxpool layer compresses the features output by the ReLU from 360 to 180, which not only reduces the model calculation amount, but also retains the key features.
[0053] The residual layers 1 to 4 each include two residual blocks (RB1 and RB2). In each residual layer, multi-scale feature extraction is achieved by gradually increasing the channel number and compressing the feature length. The input / output channel number and the step length of the residual layer 1 are 32 and 1 respectively, and the feature length remains 180. The input channel number of the residual layer 2 is increased from 32 to the output channel number 64, the step length is 2, and the feature length is reduced from 180 to 90. The input channel number of the residual layer 3 is increased from 64 to the output channel number 128, the step length is 2, and the feature length is reduced from 90 to 45. The input channel number of the residual layer 4 is increased from 128 to the output channel number 256, the step length is 2, and the feature length is reduced from 45 to 22.
[0054] Each RCA module includes an A-AvgPool layer, a Conv layer, a ReLU layer, a Conv layer, and a sigmoid layer in series. The outputs of each RCA module are fused and input into the TSA module. However, the feature dimensions of the attention modules do not match, and the dimensions of different attention modules are different, which may cause information redundancy and conflict, and lead to the possibility of capturing similar features. Therefore, an adaptive average pooling layer is introduced into the RCA module to unify the time series length of data to 24 and transpose it to (B, 24, 256) to adapt to the input dimension of the TSA module.
[0055] The TSA module includes two bidirectional GRU networks, a Multi-Attention layer, and an LN layer in series. The Multi-Attention layer adopts 4-head self-attention and only focuses on the feature association between lead signals, which is beneficial to balance the time series modeling capability and the amount of calculation. The LN layer is used to split the data and reduce the dimension of the output data of the TSA module (B, 24, 2, 128) to meet the input format requirements of the CLA module.
[0056] The CLA module includes a double self-attention layer and a feature fusion layer. The double self-attention layer includes two parallel Self-Attention layers. The double-head self-attention of the CLA module only focuses on the feature association between lead signals. The classification layer includes a global average pooling layer, a fully connected-regularization layer, and an output layer in series.
[0057] S4, inputting the ECG balance signal into the arrhythmia classification model for classification to obtain an arrhythmia classification result.
[0058] The training process of the arrhythmia classification model is as follows:
[0059] S4-1, obtaining a training ECG balance signal;
[0060] It should be noted that the MIT-BIH arrhythmia database is read to avoid repeated preprocessing operations, and a caching mechanism is designed. By judging whether the preset cache file exists, if it exists, the ECG number and its label are loaded through the pickle module; if it does not exist, first traverse the 48 records in the MIT-BIH arrhythmia database, read the ECG signal (select 2-lead data) of each record using the wfdb.rdrecord function, and read the annotation information (including R wave position sample and heartbeat type symbol) through the wfdb.rdann function. The MIT-BIH arrhythmia database is screened to obtain 8 target heartbeat types: normal heartbeat ('N'), left bundle branch block ('L'), right bundle branch block ('R'), ventricular premature beat ('V'), paced beat (''), atrial premature beat ('A'), paced fusion beat ('f'), and ventricular fusion beat ('F'). Through a dictionary, the 8 target heartbeat types are mapped to numbers (0-7), and finally the training ECG signal and its label are obtained.
[0061] The training ECG signal is processed in the same way as S1 to S2 to obtain a training ECG balanced signal.
[0062] S4-2, inputting the training ECG balanced signal into an initial feature extraction layer to obtain a training local waveform feature;
[0063] Specifically, the local waveform feature of the training ECG balanced signal is extracted through the Conv layer of the initial feature extraction layer, covering the key frequency band of the QRS complex. Then, the BN layer is used for processing to standardize the 32-channel features, stabilize the training process, and obtain the training standard waveform feature. The training standard waveform feature is processed by the ReLU layer to introduce non-linear changes and enhance the feature expression ability, and the training enhanced waveform feature is obtained. The Maxpool layer is used to process the training enhanced waveform feature, compressing its feature length from 360 to 180, reducing the amount of calculation while retaining key features.
[0064] S4-3, sequentially inputting the training local waveform feature into residual layer 1 to residual layer 4 according to the data flow direction in Figure 2 to obtain a first training compressed waveform feature, a second training compressed waveform feature, a third training compressed waveform feature, and a fourth training compressed waveform feature, respectively;
[0065] Specifically, the training local waveform feature is input into the residual layer 1 to obtain a first training compressed waveform feature; the first training compressed waveform feature is input into the residual layer 2 to obtain a second training compressed waveform feature; the second training compressed waveform feature is input into the residual layer 3 to obtain a third training compressed waveform feature; and the third training compressed waveform feature is input into the residual layer 4 to obtain a fourth training compressed waveform feature. Through the four stacked residual layers, multi-scale feature extraction is realized by gradually increasing the number of channels and compressing the feature length.
[0066] S4-4, inputting the first training compressed waveform feature, the second training compressed waveform feature, the third training compressed waveform feature and the fourth training compressed waveform feature into corresponding RCA modules and fusing them to obtain a training waveform key fusion feature;
[0067] In the embodiment, the processing process of each RCA module is the same, and the processing of the first training compressed waveform feature by the RCA module is taken as an example for explanation. The RCA module realizes adaptive adjustment of feature channel weight by means of compression-excitation-reconstruction mechanism, thereby enhancing the channel feature corresponding to the key waveform (such as QRS wave) and suppressing the interference of noise channels. The specific process is as follows:
[0068] Firstly, in the compression stage, the time sequence feature of each channel is compressed into one value by an adaptive average pooling (AdaptiveAvgPool 1d layer) operation, so as to extract the global information of the channel and obtain a first training global waveform feature. Subsequently, the excitation stage is entered, which includes multiple key steps. Firstly, a 1x1 convolution layer (Conv layer) is used to compress the channel number to 1 / 16 of the original channel number (for example, from 256 channels to 16 channels), so as to obtain a second training global waveform feature and effectively reduce the calculation amount; secondly, a ReLU activation function is used to introduce nonlinearity and process the second training global waveform feature, so as to improve the expression ability of the model and obtain a training nonlinear waveform feature; thirdly, a 1x1 convolution layer is used to restore the channel number of the training nonlinear waveform feature to the original channel number (for example, from 16 channels to 256 channels), so as to obtain a third training global waveform feature; and finally, a Sigmoid activation function is used to output a channel weight between 0 and 1. Finally, in the reconstruction stage, the obtained channel weight is multiplied with the main path feature channel by channel to obtain the output data of the RCA module, so as to realize the effect of "enhancing important channels and suppressing secondary channels".
[0069] S4-5, inputting the training waveform key fusion feature into the TSA module to obtain a training waveform key time sequence feature;
[0070] In the TSA module, the key fusion features of the training waveform are preprocessed, the adaptive average pooling is used to unify the time sequence length to 24 and transpose to (B, 24, 256), and the time sequence modeling is adapted. Then, the 2-layer bidirectional GRU (hidden layer dimension 128, bidirectional total dimension 256) is used to encode the time sequence features, and the (B, 24, 256) result is output to capture the local time sequence dependence. Then, the attention weight is calculated by 4 heads of self-attention mechanism on the GRU output, the correlation of different time points is modeled, and the weighted feature is output. Finally, the multi-head self-attention output and the GRU output are connected in residual, and the LayerNorm normalization is used to enhance the stability. The “bidirectional GRU + multi-head self-attention” is used to consider the local and long-range correlation modeling, and the convolution layer is used to compress the weighted lead features, so as to retain the time sequence information extracted by the TSA module and integrate the lead complementarity, and the semantic complementarity is realized.
[0071] S4-6, inputting the key time sequence features of the training waveform into the CLA module and the classification layer to obtain the training arrhythmia classification result;
[0072] In the CLA module, after inputting the key time sequence features of the training waveform into the CLA module, first, the feature is split, the (B, 24, 256) feature output by the TSA module is split according to the lead dimension to (B, 2, 24, 256), so as to clearly distinguish the features of the two leads. Then, the lead correlation modeling link of the double self-attention layer is entered, the 2×2 lead correlation matrix is calculated by using 2 heads of self-attention mechanism, the feature contribution of different leads is dynamically adjusted, such as enhancing the weight of the lead containing clear QRS wave, so as to learn the complementary information between the leads and fit the spatial correlation characteristics of the two lead signals. Then, the weighted lead features are fused by the feature fusion layer to (B, 24, 256) through the 1×1 convolution layer (input / output channel 256), the key correlation information between the leads is retained, and the optimized global waveform features are provided for the subsequent classification layer.
[0073] In the classification layer, the training global waveform features output by the CLA module are input into the classification layer, the training global waveform features (B, 24, 256) are time sequence dimension pooled by the global average pooling layer, and are compressed into a feature vector (B, 256). The feature is further refined by the 512-dimensional full connection layer in the full connection-regularization layer, and after the ReLU activation, the 50% Dropout is introduced to suppress the overfitting. The output features of the full connection-regularization layer are input into the output layer, the 8-dimensional full connection layer (corresponding to 8 types of heartbeats) is used to output the prediction probability (B, 8), the Softmax function is used for normalization, and finally the probability distribution of each category is obtained, that is, the training arrhythmia classification result.
[0074] S4-7, based on the training arrhythmia classification result and the label, the cross-entropy loss function is calculated;
[0075] S4-8, based on the cross-entropy loss function, the network parameters of the arrhythmia classification model are iteratively adjusted and evaluated by the Adam optimizer and the back propagation algorithm until the evaluation results meet the iteration end condition, and the corresponding process is:
[0076] The training configuration is set: the loss function is CrossEntropyLoss (cross-entropy loss), which can adapt to multi-classification tasks; the Adam optimizer uses an initial learning rate of 0.001 and a weight decay of 1e-4, which can adaptively adjust the parameter update step; the learning rate scheduling uses the CosineAnnealingLR scheduler to make the learning rate decay to the minimum value according to the cosine curve with the training round; at the same time, the mixed precision training is realized through torch.cuda.amp.autocast and GradScaler, the forward propagation is calculated with FP16 (half precision) to reduce memory occupation and speed up operation, and the backward propagation is through gradient scaling to avoid gradient overflow under FP16 precision, balancing speed and stability.
[0077] When entering the training loop, first set the model to training mode (model.train) to enable batch normalization and Dropout. Then traverse the training set, input the signal to the ResTCL-Net to output the prediction probability, calculate the difference between the prediction probability and the true label through the cross-entropy loss function, then empty the historical gradient, calculate the gradient and scale to avoid overflow, then update the model parameters through optimizer.step, and adjust the scaling factor. Print the current loss every 10 batches to monitor the training dynamics, and verify the model performance on the test set after each round of training, and save the model weight with the highest test accuracy.
[0078] Finally, enter the evaluation loop, set the model to evaluation mode (model.eval), and turn off batch normalization and Dropout to reduce computation. Traverse the test set, collect the true label, predicted label and prediction probability (all_scores), generate a classification report, and calculate the precision, recall and F1 score of each class to comprehensively evaluate the performance.
[0079] The above process of iteratively adjusting the network parameters and evaluating based on the cross-entropy loss function through the Adam optimizer and the back propagation algorithm is repeated until the evaluation results meet the iteration end condition. The iteration end condition is set according to actual needs, for example, if the precision and recall both reach the set threshold, it is considered to pass the evaluation and end the iteration.
[0080] In summary, the present application realizes efficient and accurate electrocardiogram arrhythmia classification through multi-link cooperative optimization, the core of which is the combination of fine preprocessing, balanced data strategy and model design of multi-attention mechanism: in the preprocessing stage, db4 wavelet denoising is used to retain R wave features, accurate R wave detection and uniform length heartbeat segmentation and standardization are used to provide high-quality input for the model; the mixed strategy of under-sampling and over-sampling effectively solves the class imbalance problem, avoids information loss and noise introduction, and improves the recognition ability of the minority class; the ResTCL-Net model fuses the local feature extraction of CNN, the time series modeling capability of GRU, and the enhancement of key channel features by the RCA module, the capture of local and long-range temporal dependencies by the TSA module, and the learning of complementary information by the CLA module, and multi-dimensionally mines the deep features of ECG signals; during the training process, mixed precision training, optimized Adam optimizer and cosine annealing learning rate scheduling are used to balance efficiency and stability, and comprehensive evaluation indicators are used to ensure the performance of the model. The overall scheme significantly improves the accuracy and generalization ability of arrhythmia classification, especially enhances the recognition effect of abnormal heartbeats, and provides reliable support for clinical arrhythmia diagnosis.
[0081] As shown in Figure 3 A residual contraction network-based electrocardiogram arrhythmia classification system, comprising:
[0082] An ECG signal acquisition module for acquiring and preprocessing original ECG signals (electrocardiogram signals) to obtain ECG signals;
[0083] An ECG balancing module for balancing the data of the ECG signals through a mixed strategy of under-sampling and over-sampling to obtain an ECG balanced signal;
[0084] An arrhythmia classification model construction module for constructing an arrhythmia classification model based on CNN and GRU networks and combining time series self-attention and cross-lead attention;
[0085] An arrhythmia classification model training module for training the arrhythmia classification model;
[0086] An arrhythmia classification module for inputting the ECG balanced signal into the arrhythmia classification model for classification to obtain an arrhythmia classification result.
[0087] The ECG signal acquisition module comprises an ECG signal acquisition module and a preprocessing submodule; the preprocessing submodule comprises a wavelet denoising unit, an R wave detection unit, a heartbeat segmentation unit and a standardization unit; wherein:
[0088] The ECG signal acquisition module is used to acquire ECG signals;
[0089] A wavelet denoising unit is configured to perform wavelet denoising on the original ECG signal by using a db4 wavelet algorithm, to determine approximation coefficients and detail coefficients, and to obtain an ECG denoised signal by combining wavelet reconstruction;
[0090] An R wave detection unit is configured to perform R wave detection on the ECG denoised signal by using a Butterworth band-pass filter, to obtain an ECG detection signal and R wave position information thereof;
[0091] A heart beat segmentation unit is configured to set a clipping window with the R wave position information as a window center, and to perform heart beat segmentation on the ECG detection signal by using the clipping window, to obtain a corresponding heart beat segment;
[0092] A standardization unit is configured to perform standardization on the heart beat segment corresponding to the ECG detection signal, to obtain an ECG signal.
[0093] The arrhythmia classification model training module comprises:
[0094] A training data acquisition submodule is configured to acquire training data and labels thereof;
[0095] An arrhythmia classification model training running submodule is configured to process the training data, to obtain a training arrhythmia classification result;
[0096] A loss function calculation submodule is configured to calculate a cross-entropy loss function based on the training arrhythmia classification result and the labels;
[0097] A parameter adjustment submodule is configured to adjust network parameters of the arrhythmia classification model by using an Adam optimizer and a back propagation algorithm based on the cross-entropy loss function;
[0098] A parameter evaluation submodule is configured to evaluate the adjusted network parameters until an evaluation result meets an iteration end condition.
[0099] It should be noted that, as for the system in the above-described embodiments, the specific manner in which each module performs an operation has been described in detail in the embodiments related to the method, and will not be described in detail here.
[0100] The above only describes preferred embodiments of the present application and is not intended to limit the present application. The present application can be variously changed and modified by those skilled in the art. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present application shall be included in the protection scope of the present application.
[0101] The above merely illustrates the specific embodiments of the present application, but the protection scope of the present application is not limited thereto, any person skilled in the art can easily think of the changes or replacements within the technical range disclosed by the present application, which should be covered in the protection scope of the present application. Therefore, the protection scope of the present application should be subject to the protection scope of the claims.
Claims
1. A method for classifying electrocardiographic arrhythmias based on residual contraction networks, characterized in that, include: The raw ECG signal is acquired and preprocessed to obtain the ECG signal; The ECG signal is balanced by a hybrid undersampling-oversampling strategy. A cardiac arrhythmia classification model is constructed based on CNN and GRU networks, combined with temporal self-attention and translead attention. The ECG balance signal is input into the arrhythmia classification model for classification, and the arrhythmia classification result is obtained.
2. The electrocardiogram arrhythmia classification method based on residual contraction networks according to claim 1, characterized in that, The preprocessing includes: The original ECG signal was denoised using the db4 wavelet algorithm to determine the approximation coefficients and detail coefficients. Combined with wavelet reconstruction, the denoised ECG signal was obtained. R-wave detection is performed on the denoised ECG signal using a Butterworth bandpass filter to obtain the ECG detection signal and its R-wave position information. A truncated window is set with the R-wave position information as the center; the ECG detection signal is segmented into heartbeat segments through the truncated window to obtain the corresponding heartbeat fragments; The ECG signal is obtained by standardizing the heartbeat segments corresponding to the ECG detection signal.
3. The electrocardiogram arrhythmia classification method based on residual contraction networks according to claim 1, characterized in that, The arrhythmia classification model includes a series of initial feature extraction layers, residual layers 1 to 4, an RCA module, a TSA module, a CLA module, and a classification layer. The outputs of residual layers 1 to 4 are all connected to an RCA module, and the outputs of each RCA module are merged and then input into the TSA module. The initial feature extraction layer includes a cascaded Conv layer, BN layer, ReLU layer, and Maxpool layer; residual layers 1 to 4 each include two residual blocks; each RCA module includes a cascaded A-AvgPool layer, Conv layer, ReLU layer, Conv layer, and sigmoid layer; the TSA module includes two cascaded bidirectional GRU layers, a Multi-Attention layer, and an LN layer; the CLA module includes a dual self-attention layer and a feature fusion layer; the dual self-attention layer includes two parallel Self-Attention layers; the classification layer includes a cascaded global average pooling layer, a fully connected-regularized layer, and an output layer.
4. The electrocardiogram arrhythmia classification method based on residual contraction networks according to claim 3, characterized in that, The training process of the arrhythmia classification model is as follows: Acquire the training ECG balanced signal; input the training ECG balanced signal into the initial feature extraction layer to obtain the training local waveform features; The training local waveform features are sequentially input into residual layers 1 to 4 to obtain the first training compressed waveform features, the second training compressed waveform features, the third training compressed waveform features and the fourth training compressed waveform features, respectively. The first, second, third, and fourth training compressed waveform features are input into the corresponding RCA modules and fused to obtain the key fused features of the training waveform. The key fusion features of the training waveform are input into the TSA module to obtain the key time-series features of the training waveform; The key temporal features of the training waveform are input into the CLA module and the classification layer to obtain the training arrhythmia classification results. Based on the training arrhythmia classification results and labels, the cross-entropy loss function is calculated. Based on the cross-entropy loss function, the network parameters of the arrhythmia classification model are iteratively adjusted and evaluated using the Adam optimizer and backpropagation algorithm until the evaluation results meet the iteration termination condition.
5. The electrocardiogram arrhythmia classification method based on residual contraction networks according to claim 4, characterized in that, Each RCA module employs a compression-excitation-reconstruction mechanism to adaptively adjust the weights of its feature channels; The first training compressed waveform features are processed using the RCA module. The corresponding process is as follows: The first training compressed waveform features are compressed by the A-AvgPool layer, that is, the first training compressed waveform features of each channel are compressed into 1 value to obtain the first training global waveform features. The first training global waveform feature is activated by the first Conv layer in the RCA module to obtain the second training global waveform feature; The second training global waveform features are nonlinearly processed by a ReLU layer to obtain the training nonlinear waveform features; The training nonlinear waveform features are channel-expanded by the second Conv layer in the RCA module to obtain the third training global waveform features. The channel weights of the third training global waveform feature are adjusted and reconstructed by using the Sigmoid activation function, thus completing the RCA module's processing of the first training compressed waveform feature.
6. A cardiac arrhythmia classification system based on residual contraction networks, used to implement the cardiac arrhythmia classification method based on residual contraction networks as described in any one of claims 1 to 5, characterized in that, include: The ECG signal acquisition module is used to acquire the raw ECG signal and preprocess it to obtain the ECG signal. The ECG balancing module is used to perform data balancing on the ECG signal using an undersampling-oversampling hybrid strategy to obtain a balanced ECG signal. The arrhythmia classification model construction module is used to build arrhythmia classification model based on CNN network and GRU network, combined with temporal self-attention and translead attention; The arrhythmia classification model training module is used to train the arrhythmia classification model. The arrhythmia classification module is used to input the ECG balanced signal into the arrhythmia classification model for classification and to obtain the arrhythmia classification result.
7. The electrocardiogram arrhythmia classification system based on residual contraction networks according to claim 6, characterized in that, The ECG signal acquisition module includes an ECG signal acquisition module and a preprocessing submodule; the preprocessing submodule includes a wavelet denoising unit, an R-wave detection unit, a heartbeat segmentation unit, and a normalization unit; wherein: ECG signal acquisition module, used to acquire ECG signals; The wavelet denoising unit is used to perform wavelet denoising on the original ECG signal using the db4 wavelet algorithm, determine the approximation coefficients and detail coefficients, and combine them with wavelet reconstruction to obtain the ECG denoised signal. The R-wave detection unit is used to perform R-wave detection on the ECG denoised signal through a Butterworth bandpass filter to obtain the ECG detection signal and its R-wave position information. The heartbeat segmentation unit is used to set a truncated window with the R-wave position information as the window center; the ECG detection signal is segmented into heartbeat segments through the truncated window to obtain the corresponding heartbeat segments; The normalization unit is used to normalize the heartbeat segments corresponding to the ECG detection signal to obtain the ECG signal.
8. The electrocardiogram arrhythmia classification system based on residual contraction networks according to claim 6, characterized in that, The arrhythmia classification model training module includes: The training data acquisition submodule is used to acquire training data and its labels; The arrhythmia classification model training and operation submodule is used to process training data and obtain the training arrhythmia classification results; The loss function calculation submodule is used to calculate the cross-entropy loss function based on the training arrhythmia classification results and labels; The parameter tuning submodule is used to iteratively adjust the network parameters of the arrhythmia classification model based on the cross-entropy loss function, using the Adam optimizer and backpropagation algorithm. The parameter evaluation submodule is used to evaluate the adjusted network parameters until the evaluation results meet the iteration termination condition.
Citation Information
Cited By
Electrocardio gating scanning control method and system based on multi-model fusion algorithm
CN121667735A
Electrocardiogram-gated scanning control method and system based on multi-model fusion algorithm
CN121667735B
Electrocardiosignal classification method based on lead feature fusion and particle swarm optimization
CN121705847A