Electrocardiosignal classification and target detection method based on multi-task model
Through the multi-task learning and one-dimensional YOLO object detection algorithm with independent expert mechanism, the problems of low efficiency and large calculation volume between tasks in ECG signal processing are solved, and high-precision and high-real-time ECG signal classification and object detection are achieved.
Patent Information
- Application Number
- CN202510344381.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-03-21
- Publication Date
- 2025-07-08
AI Technical Summary
The existing technology has low efficiency in multi-task learning in electrocardiogram signal processing, traditional object detection methods are unstable in noise and complex signals, and the calculation amount of object detection methods based on deep learning affects real-time performance.
A multi-task learning framework with independent expert mechanism is adopted, combined with one-dimensional YOLO object detection algorithm, through expert network, gated network and task branches, efficient information sharing and independence between tasks are achieved, computational volume is reduced, and real-time performance is improved.
It improves the accuracy and real-time nature of ECG signal classification and detection, solves the problems of task conflict and low computing efficiency in traditional methods, and achieves high accuracy and high real-time object detection.
Smart Images

Figure CN120267299A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to a method for electrocardiogram signal classification and target detection based on a multi-task model. Background Art
[0002] Electrocardiogram (ECG) signal processing plays a crucial role in the diagnosis of cardiovascular diseases. Automated ECG signal analysis can help doctors quickly identify abnormal conditions in a large amount of data, thus providing timely treatment suggestions. ECG signal processing includes multiple tasks such as abnormal heart rate classification and target detection. With the continuous in-depth research on multi-task learning methods, scholars have gradually realized that there is potential for mutual association and information sharing among multiple tasks. For example, the abnormal classification of ECG signals is closely related to target detection. The classification task can provide the task background for target detection, while the accuracy of target detection can in turn provide more accurate features for the classification task. The multi-task learning (MTL) method can not only improve the generalization ability of the model by optimizing multiple tasks simultaneously, but also make more effective use of the shared features between tasks. Especially in ECG signal processing, combining classification and target detection can enable the model to accurately locate key waveforms while performing abnormal detection of ECG signals, thus providing more comprehensive and accurate information for clinical diagnosis. Although multi-task learning has achieved remarkable results in many fields, its application in ECG signal processing still faces some challenges. Traditional multi-task learning methods often use hard sharing or soft sharing mechanisms, which makes the information exchange between different tasks not efficient and may lead to interference between tasks. How to effectively achieve knowledge sharing between tasks, avoid conflicts, and make full use of shared information while maintaining task independence is an important issue in current multi-task learning for ECG signal processing.
[0003] In addition to multitasking, the target detection task of electrocardiogram (ECG) signals itself is also of great research value. It is of great significance for the diagnosis of cardiovascular diseases and can help doctors with early warning and decision-making. Traditional target detection methods mainly rely on time-frequency transformation and threshold setting of signals. Although these methods can extract features from ECG signals to a certain extent, they also have many limitations. Traditional target detection methods include: 1. Differential threshold algorithm: This algorithm performs differential processing on ECG signals and then combines threshold setting to detect P waves, QRS complexes, and T waves. Although this method is simple to operate and can detect multiple waveforms simultaneously, it is sensitive to noise and prone to misjudgment when the signal is abnormal or the interference is large. 2. Wavelet transform: Wavelet transform is a time-frequency analysis method that can effectively extract the time-frequency features of ECG signals. Although it can enhance the waveform signal to a certain extent, since appropriate wavelet bases and scales need to be set, and in the case of large noise, the threshold setting relying on experience will affect its detection effect. 3. Hidden Markov chain: The Hidden Markov Chain (HMM) method realizes the recognition of each waveform by establishing a state transition model and regarding the ECG signal as a sequence generation process of multiple states. This method can better handle the temporal relationship between waveforms, but it requires a large number of samples for parameter estimation and is sensitive to the setting of model parameters in practical applications. Target detection methods based on deep learning include: Convolutional Neural Network (CNN): The Convolutional Neural Network can automatically extract useful features from ECG signals, reducing the complexity of manual feature extraction in traditional methods. However, the performance of traditional convolutional neural network models may be unstable when facing complex signals (such as signals in a high-noise environment). Bidirectional Long Short-Term Memory Network (BiLSTM): The Bidirectional Long Short-Term Memory Network can capture the long-term dependence relationship in the signal, thus effectively processing the time series characteristics in ECG signals. A hybrid model combining the Bidirectional Long Short-Term Memory Network and the Convolutional Neural Network can further improve the recognition accuracy. The latest research uses the method based on the U-shaped end-to-end network (U-Net), which can greatly improve the accuracy compared with previous models. However, all these traditional models have one problem: in principle, they classify ECG signals point by point, introducing too much unnecessary calculation. This affects the real-time performance of the model and thus hinders clinical applications.
[0004] The defects of the prior art are mainly manifested in the following aspects: 1. The sharing mechanism of multi-task learning is inefficient: Traditional multi-task learning methods usually use hard sharing or soft sharing mechanisms, resulting in inefficient information exchange between different tasks and possible interference between tasks. How to effectively share information while maintaining task independence is a major challenge in current multi-task learning for electrocardiogram signal processing. 2. Traditional object detection methods have limitations: Traditional object detection methods (such as differential threshold algorithms, wavelet transforms, hidden Markov chains, etc.) rely on manually set thresholds, and their performance is unstable in the case of large noise or complex signals, affecting recognition accuracy and robustness. 3. The real-time problem of deep learning-based object detection methods: Deep learning-based object detection methods (such as convolutional neural networks, bidirectional long short-term memory networks, U-shaped end-to-end networks, etc.) may achieve good results in the processing of complex signals, but these models bring excessive computational complexity, affecting the real-time performance of the models and thus restricting their application in clinics. Summary of the Invention
[0005] Object of the Invention: The technical problem to be solved by the present invention is to provide a method for electrocardiogram signal classification and object detection based on a multi-task model in view of the deficiencies of the prior art, including the following steps:
[0006] Step 1, preprocess the data set;
[0007] Step 2, establish the basic module of the model;
[0008] Step 3, establish a multi-task model;
[0009] Step 4, train the multi-task model.
[0010] In Step 2, the basic module of the model is the basic component of the multi-task model, including a convolutional module, a residual convolutional module, and a cross-stage partial convolutional module.
[0011] The convolutional module consists of three parts: a one-dimensional convolutional layer, a batch normalization layer (Batch Norm), and a SiLU activation function, and has 5 parameters: the number of input channels in_ch conv , the number of output channels out_ch conv , the kernel size k, the stride s, and the padding p.
[0012] In the convolutional module, the one-dimensional convolutional layer performs a convolutional operation on the input signal, and the output can be expressed as: Conv(x) = W conv *x + b conv . Among them, is the input tensor, B is the batch size, in_ch conv is the number of input channels, L is the length of the input, is the convolution kernel weight, k is the convolution kernel size, is the bias term, and * represents the convolution operation.
[0013] In the convolution module, the batch normalization layer normalizes each channel, and the output can be expressed as: where x is the output after the convolution operation, μ and σ are the mean and standard deviation of the input data respectively, and γ and are trainable scaling and offset parameters.
[0014] In the convolution module, the SiLU activation function performs the following operation: SiLU(x) = x · σ(x). Where σ(x) is the S-shaped (Sigmoid) function:
[0015] In step 2, the residual convolution module is composed of two convolution modules and a residual connection, and has only one parameter, the number of channels ch. The input and output channel numbers in_ch conv and out_ch conv of each convolution module are both equal to the number of channels ch of the module. Among them, the kernel size k of the two convolution modules is 3, the stride s is 1, and the boundary padding p is 1. After the signal is processed by the convolution module, it is added to the original unprocessed signal, which is the residual connection.
[0016] In step 2, the cross-stage partial convolution module consists of an input convolution module, n stacked residual convolution modules, and an output convolution module. This module has three parameters: the input channel number in_ch csp , the output channel number out_ch csp and the number of residual convolution modules n.
[0017] In the cross-stage partial convolution module, the input channel number of the input convolution module is equal to in_ch csp , the output channel number is equal to out_ch csp , the kernel size k is 1, the stride s is 1, and the boundary padding p is 0.
[0018] In the cross-stage partial convolution module, the number of channels of all residual convolution modules is 0.5 × out_ch csp . The output of the input convolution module is split into two parts, each with a size of (0.5 × out_ch, len), denoted as y2 and y3. Then y2 passes through all the residual convolution modules in turn, that is where ResBlock i (·) represents the i-th residual convolution module
[0019] In the cross-stage partial convolution module, the number of input channels of the output convolution module is equal to 0.5(n + 2)·in_ch csp , and the number of output channels is equal to out_ch csp , the kernel size k is 1, the stride s is 1, and the padding p is 0. Concatenate all the outputs, that is y4 is used as the input of the output convolution module.
[0020] In step 3, the multi-task model is a multi-task model with an independent expert mechanism, including an expert network, a gating network, a classification task branch, and a one-dimensional YOLO object detection task branch (hereinafter referred to as the "object detection task branch"); multiple expert networks are set in the model, and the number of experts is determined by the parameter num_experts. In the multi-task model with an independent expert mechanism, the two task branches must have independent experts and must contain shared experts. Each task branch has a gating network, and each gating network only controls the shared experts and the independent experts of the corresponding task. During forward propagation, the gating network will perform a weighted sum of the outputs of the expert network based on the input electrocardiogram signal to form a task-specific fused feature for input to the task branch.
[0021] The expert network consists of two convolution modules with a kernel size k of 3, a stride s of 2, and a padding p of 1. Let the number of leads of the electrocardiogram signal be lead and the signal length be len, then the number of input channels in_ch conv of the first convolution module is lead, and the number of output channels out_ch conv is 64. The number of input and output channels in_ch conv and out_ch conv of the second convolution module are 64 and 128 respectively.
[0022] The gating network consists of a Flatten Layer, a Fully-Connected Layer, and a Softmax. The gating network takes the electrocardiogram signal as the input. The electrocardiogram signal first passes through the Flatten Layer, which flattens the multi-dimensional input tensor into a one-dimensional vector, and then passes through the Fully-Connected Layer and the Softmax. The number of neurons in the Fully-Connected Layer is equal to the number of experts controlled by this gating network.
[0023] The specific calculation method of the Softmax is where z i (i = 1, 2, 3,..., m) represents the i-th element of the input vector z (with a length of m).
[0024] In Step 3, the classification task branch consists of 4 convolutional modules, 4 cross-stage partial convolutional modules, and 2 fully connected layers, arranged in the order of: convolution, cross-stage, convolution, cross-stage, convolution, cross-stage, convolution, cross-stage, fully connected, fully connected. The kernel size k of all convolutional modules is 3, the stride s is 2, and the padding p is 1. The number of input channels in_ch of the first convolutional module conv is 128, and the number of output channels out_ch conv is 256, while the number of input channels in_ch conv and the number of output channels out_ch conv of the remaining convolutional modules are both 256. The number of input channels in_ch csp and the number of output channels out_ch csp of all cross-stage partial convolutional modules are both 256, and the number of residual convolutional modules n is equal to 3. After the signal is processed by the convolutional module and the cross-stage partial convolutional module, the signal is first flattened, and the flattened result is denoted as x'. Subsequently, x' passes through the first fully connected layer. The number of neurons in this fully connected layer is 512, followed by a batch normalization layer, an Sigmoid activation function, and a Dropout layer. The Dropout layer randomly deactivates (sets to zero) some neurons in the fully connected layer with a probability p during each training to reduce the dependence on specific neurons, thereby improving the generalization ability of the model. In the inference stage, Dropout is no longer effective, and the model uses all neurons for calculation. Subsequently, the signal enters the second fully connected layer. The number of neurons in this fully connected layer is equal to the number of classes num_cls, followed by an Sigmoid activation function and a Dropout layer. Denote the output as y2, and y2 is the final output of the classification branch.
[0025] In Step 3, the object detection task branch can be divided into three parts: a backbone network, a neck network, and a head. The backbone network is responsible for extracting features at different scales, the neck network fuses features at each scale, and the head predicts the position and class information of the target on the feature maps at different scales. The structures of each part are as follows:
[0026] The backbone network is composed of three convolutional modules and three cross-stage partial convolutional modules stacked alternately in the order of: convolution, cross-stage, convolution, cross-stage, convolution, cross-stage. Among them, the input channel number of the first convolutional module is 128, the output channel number is 256, the convolution kernel size k is 3, the stride s is 2, and the boundary padding p is 1. The input channel number and the output channel number of the first cross-stage partial convolution are both 256, and the number of residual convolutional modules n is 6. Denote the output of the first cross-stage partial convolution as feature map R1 for subsequent network use. The input channel number of the second convolutional module is 256, the output channel number is 512, the convolution kernel size is 3, the stride is 2, and the padding is 1. The input channel number and the output channel number of the second cross-stage partial convolution are both 512, and the number of residual convolutional modules n is 6. Denote the output of the second cross-stage partial convolution as feature map R2. The third convolutional module has an input channel number of 512, an output channel number of 1024, a convolution kernel of 3, a stride of 2, and a padding of 1. The input and output channel numbers of the third cross-stage partial convolution are 1024, and the number of residual convolutional modules n is 3. Denote the output of the third cross-stage partial convolution as feature map R3.
[0027] The neck network mainly includes an upsampling layer (Upsample) and several convolutional / partial convolution across stages modules, in the following order: upsampling, partial convolution across stages, upsampling, partial convolution across stages, convolution, partial convolution across stages, convolution, partial convolution across stages. The upsampling layer uses bilinear interpolation to double the length of the feature map, and this operation does not change the number of channels. First, perform upsampling on R3, and then concatenate the upsampled R3 features with the R2 features in the channel dimension and input them into the first partial convolution across stages module. The input channel number of the first partial convolution across stages module is 1536, the output channel number is 512, and the number n of residual convolution modules is 3. Denote the output as the feature map Temp. Then, upsample the Temp feature map by 2 times, and then concatenate Temp with R1 to form a 768-channel feature map and input it into the second partial convolution across stages module. The input channel of the second partial convolution across stages module is 768, the output channel is 256, and the number n of residual convolution modules is 3. Denote the output as R1'. Subsequently, use the first convolutional module to downsample R1'. The input channel and output channel of the first convolutional module are both 256, the convolutional kernel is 3, the stride is 2, and the padding is 1. Concatenate the downsampled R1' features with the Temp feature map in the channel dimension to obtain a 768-channel feature map and input it into the third partial convolution across stages module. The input channel of the third partial convolution across stages module is 768, the output channel is 512, and the number n of residual convolution modules is 3. Denote the output as R2'. Subsequently, use the second convolutional module to downsample the R2' features. The input channel and output channel of the second convolutional module are both 512, the convolutional kernel is 3, the stride is 2, and the padding is 1. Then, concatenate the downsampled R2' with R3 in the channel dimension to obtain a 1536-channel feature map and input it into the fourth partial convolution across stages module. The input channel of the fourth partial convolution across stages module is 1536, the output channel is 1024, and the number n of residual convolution modules is 3. Denote the output as R3'.
[0028] The detection head consists of a bounding box regression branch (box) and a target class branch (cls). The bounding box regression branch contains three parallel sub-modules that process feature maps at different scales (R1′, R2′, and R3′) respectively. Each sub-module sequentially includes: a convolutional module (with an input channel of x and an output channel of 64), a convolutional module (with both input and output channels of 64), and a one-dimensional convolutional layer (with an input channel of 64 and an output channel of 2). The convolutional kernel size of the convolutional module is 3, the stride is 1, and the padding is 1. The last convolutional layer is used to output the prediction results, with a convolutional kernel size of 1, a stride of 1, and no padding. For the three sub-modules, x is 256, 512, and 1024 respectively. The structure of the target class branch is the same as that of the bounding box regression branch, but the output channel number of the last one-dimensional convolutional layer is 3, corresponding to the confidence levels of the P wave, QRS complex, and T wave waveforms. For each level of scale feature map, the output of its corresponding bounding box regression sub-module (2 channels) is concatenated with the output of the target class sub-module (3 channels) in the channel dimension to form the final prediction at that scale.
[0029] The method of the present invention avoids the task conflict of the traditional hard-sharing multi-task model by introducing multi-task learning with an independent expert mechanism, thereby significantly improving the classification and detection accuracy.
[0030] Meanwhile, the target detection task branch is based on the one-dimensional YOLO object detection algorithm. Compared with the traditional U-Net point-by-point classification method, it only performs regression on the waveform sections, greatly reducing redundant calculations, improving the real-time performance, achieving high accuracy and high real-time performance, and solving the problems faced by traditional models.
[0031] Advantages: (1) The method of the present invention introduces multi-task learning with an independent expert mechanism, enabling the task branches to maintain a certain degree of task independence while utilizing shared information, enhancing the generalization ability and processing efficiency of the model, and solving the task conflict problem of traditional multi-task networks.
[0032] (2) The present invention introduces a one-dimensional YOLO object detection task branch for object detection, greatly reducing the computational amount, enhancing the real-time performance compared with traditional models, and maintaining high accuracy at the same time. Description of the Drawings
[0033] The following further specifically describes the present invention in conjunction with the drawings and specific embodiments, and the above and / or other advantages of the present invention will become clearer.
[0034] Figure 1 It is a schematic diagram of the system architecture of an embodiment of the present application.
[0035] Figure 2 It is a structural diagram of the convolutional module.
[0036] Figure 3It is the structure diagram of the residual convolution module.
[0037] Figure 4 It is the structure diagram of the cross-stage partial convolution module.
[0038] Figure 5 It is the structure diagram of the gating network.
[0039] Figure 6 It is the structure diagram of the expert network.
[0040] Figure 7 It is the structure diagram of the classification branch.
[0041] Figure 8 It is the structure diagram of the target detection task branch.
[0042] Figure 9 It is the structure diagram of the detection head.
[0043] Figure 10 It is the structure diagram of the multi-task model.
[0044] Figure 11 It is the dataset overview.
[0045] Figure 12 It is the comparison of multi-task framework metrics.
[0046] Figure 13 It is the comparison of target detection task metrics.
[0047] Figure 14 It is the real-time comparison between the U-shaped end-to-end network and the one-dimensional YOLO target detection task branch. Detailed implementation
[0048] The present invention provides an electrocardiogram signal classification and target detection method based on a multi-task model, including:
[0049] Perform operations such as filtering, resampling, and cropping and splitting on the classification dataset and the target detection dataset, and then divide them into a training set and a test set. This step removes noise and redundant information in the signal through the preprocessing step, improves the signal quality and data processing efficiency, and provides a clear input for subsequent training.
[0050] Build the basic modules of the model, including the convolution module, the residual convolution module, and the cross-stage convolution module, which provides convenience for the subsequent model establishment.
[0051] Construct the multi-task learning framework, which includes an expert network, a gating network, a classification task branch, and a one-dimensional YOLO object detection task branch (hereinafter referred to as the "object detection task branch"). Through the independent expert mechanism, this framework ensures efficient information sharing between the two tasks, reduces interference between tasks, and solves the problem of information loss. Each task branch is equipped with an independent expert network and also utilizes the shared expert network for collaboration to improve the overall performance of the model.
[0052] The object detection task branch is based on the one-dimensional YOLO object detection algorithm, optimizes the computational efficiency and real-time performance of the object detection part, and realizes the efficient detection of key waveforms such as P waves, QRS complexes, and T waves in electrocardiogram signals, overcoming the problems of low computational efficiency and instability in traditional object detection methods, and improving the accuracy and robustness of the model.
[0053] As Figure 1 shown, the system architecture of the embodiment of this application includes a classification data set, an object detection data set, and a multi-task model. Among them, the classification data set can come from PTB diagnostic electrocardiogram data set, MIT-BIH arrhythmia data set, AHA arrhythmia electrocardiogram data set, etc., and the object detection data set can come from QT electrocardiogram data set, LUDB electrocardiogram data set, etc. The multi-task model includes an expert network, a classification task branch, and an object detection task branch. Their basic component modules include a convolutional module, a residual convolutional module, and a cross-stage partial convolutional module, etc. Taking the PTB data set as the classification data set and the QT data set as the object detection data set as an example, it specifically includes the following steps:
[0054] 1. Filter the two data sets. First, design a Butterworth band-pass filter with a low-pass frequency of 0.5 Hz, a high-pass frequency of 50 Hz, and an order of 5 according to the sampling frequency of the data set. Let the sampling frequency of the data set be f s (Specifically, the sampling frequency of the PTB data set is 500 Hz, and the sampling frequency of the QT data set is 250 Hz), then the Nyquist frequency Normalize the low-pass and high-pass frequencies With f L 、f H as the input, the coefficients of the designed 5th-order Butterworth band-pass filter can be obtained by using the Butterworth filter design function (such as the signal.butter function in the SciPy library of Python). Finally, use the designed filter to filter each signal in the data set.
[0055] 2. Resample the signals to the same frequency. Taking the PTB dataset and the QT dataset as examples, the former has a sampling rate of 500 Hz and the latter has a sampling rate of 250 Hz. Therefore, the data in the PTB dataset can be downsampled to 250 Hz or the QT dataset can be upsampled to 500 Hz. To simplify the computational complexity of the model, the scheme of downsampling the PTB dataset is adopted in this example. In addition, since the QT dataset is 2-lead and the PTB dataset is 12-lead, in order to align the data, only two leads (MLII lead and V5 lead) are taken from the PTB dataset.
[0056] 3. Perform cropping and segmentation processing on the signals. To ensure the accuracy of the model, each signal should contain at least 1 s of sampled values. In this example, the signals are segmented into segments of 512 sampled points, corresponding to a sampling time of 2.048 s. To ensure the integrity of the segmentation, first crop a segment of the signal at both the head and the tail of the original signal, so that the number of sampled points of the remaining signal is a multiple of the length of the segmentation segment (512 in this example). Let the lengths of these two segments of signals be len crop1 and len crop2 , the length of the signal be len sig , and the length of the segmentation segment be len seg . Then the calculation method of the lengths of these two segments of signals is as follows: when the length of the signal is even, when the length of the signal is odd, where mod represents taking the remainder and Round represents rounding down. Then set a window with a length of 512 points, place this window at the head of the cropped signal, and then repeat the following steps until the window reaches the end of the signal: take out the signal contained in the window, and then move the window half of the window distance (256 in this example). Each signal taken out of the window is used as a segmentation segment. For example, if the length of a certain segment of signal is 1124, then 50 sampled points should be cropped at both the head and the tail, so that the remaining length becomes 1024. For these 1024 points, the window is initially located at the first 512 points. After moving once (256 points), the window corresponds to the 257th to the 768th points. Move once again, and the window corresponds to the 513th to 1024th points. At this time, the window has reached the end of the signal. This segment of signal corresponds to three segments with a length of 512. When the length of the signal is odd
[0057] 4. For the classified dataset, save the processed segmented fragments by category. Taking the PTB dataset as an example, it contains 9 categories of signals: Bundle branch block, Cardiomyopathy, Dysrhythmia, Healthy control, Hypertrophy, Myocardial infarction, Myocarditis, Valvular heart disease, and Miscellaneous (Note: "Miscellaneous" refers to some categories that are not easily classified and is translated as "Miscellaneous" here).
[0058] 5. For the object detection dataset, further processing of the annotations is required. Taking the PTB dataset as an example, there are 5 types of annotations in this dataset, namely "p", "n", "t", "(", and ")", corresponding to the peak of the P wave, the peak of the QRS complex, the peak of the T wave, the starting point of the waveform, and the ending point of the waveform. The specific processing method is as follows:
[0059] a-1) For each segmented fragment, first find the waveform annotations contained in this fragment. Suppose the length of a certain signal is 1124. After the cropping and segmentation processing in step 3, there are three segmented fragments in total. Taking the first segmented fragment as an example, this fragment corresponds to the 51st point to the 562nd point of the original signal. Suppose there is a T-wave peak annotation at the 280th point, the nearest starting point annotation to the left of this T-wave peak annotation is at the 232nd point, and the nearest ending point annotation to the right of this T-wave peak annotation is at the 332nd point. Then from the 232nd point to the 332nd point is a complete T wave. Considering that the starting point of the first segmented fragment is at the 51st point, the starting point of this T wave is the 182nd point of this segmented fragment, which is 232 - 51 + 1, and the ending point of this T wave is the 282nd point of this segmented fragment, which is 332 - 51 + 1. It can be seen that this T wave is contained in this segmented fragment. If a certain segment of the waveform is incomplete in this segmented fragment, then this segment of the waveform is not counted in this fragment, and edge padding should be applied to this segment of the signal. Edge padding may introduce a certain deviation, but it helps to eliminate the impact of this incomplete fragment on the model. Still taking the signal with a length of 1124 as an example. The second segmented fragment corresponds to the 307th point to the 818th point of the original signal. If there is a T wave from the 232nd to the 332nd point, then the second segmented fragment only contains a part of this T wave (from the 307th point to the 332nd point, which corresponds to the 1st point to the 26th point in the second segmented fragment). At this time, edge padding should be applied to the head of the second segmented fragment, that is, make the values of the 1st point to the 26th point equal to the value of the 332nd point.
[0060] a-2) For the found annotations, perform coordinate transformation and normalization. Coordinate transformation means converting the form of the starting point and the ending point into the form of the center point and the width. The formula is Width = ending point - starting point. Normalization means dividing the center point and the width by the window length. Taking the starting point as 232 and the ending point as 332 as an example, the center point is The width is 332 - 232 = 100. After normalization (divided by 512), the center point is The width is
[0061] a-3) Finally, save the processed segmentation fragments and their corresponding labels. A waveform annotation includes the normalized center point, the normalized width, and the class number. The class number is one of the three integers 0, 1, and 2, corresponding to the P wave, QRS complex, and T wave respectively. Taking 0.55078125, 0.1953125, 2 as an example, this means that there is a T wave with a normalized width of 0.1953125 at the position with a normalized center of 0.55078125. A segmentation fragment should correspond to several such waveform annotations, and these waveform annotations should include all the waveforms present in the segmentation fragment.
[0062] 6. Build a convolutional module (ConvBlock), the structure is as Figure 2 shown. A basic convolutional module has 5 parameters: the number of input channels in_ch conv , the number of output channels out_ch conv , the kernel size k, the stride s, and the padding p. This module consists of three parts: a one-dimensional convolutional layer, a batch normalization layer (Batch Norm), and a SiLU activation function. The one-dimensional convolutional layer performs a convolutional operation on the input signal, and the output can be expressed as: Conv(x) = W conv *x + b conv . Among them, is the input tensor, B is the batch size, in_ch conv is the number of input channels, L is the length of the input, is the convolutional kernel weight, k is the convolutional kernel size, is the bias term, and * represents the convolutional operation. The length L out of the output tensor is given by the following formula: where L is the length of the input, p is the padding size, k is the convolutional kernel size, and s is the stride. The batch normalization layer normalizes each channel, and the output can be expressed as: where x is the output after the convolution operation, μ and σ are the mean and standard deviation of the input data respectively, and γ and β are trainable scaling and offset parameters. The output of the SiLU activation function is: SiLU(x) = x · σ(x). Where σ(x) is the sigmoid function: Therefore, the entire convolution module can be expressed as:
[0063] 7. Establish a residual convolution module (ResBlock), the structure is as Figure 3 shown. This module has only one parameter, the number of channels ch, which consists of two convolution modules and a residual connection. The input and output channel numbers in_ch conv and out_ch conv of each convolution module are both equal to the number of channels ch of this module. The output ResBlock(x) of the residual convolution module can be expressed as: ResBlock(x) = x + ConvBlock r2 (ConvBlock r1 (x)). Among them, the kernel size k of the two convolution modules is 3, the stride s is 1, and the padding p is 1. After the signal is processed by the convolution module, it is added to the original unprocessed signal, which is the residual connection.
[0064] 8. Establish a cross-stage partial convolution module (CSPBlock), the structure is as Figure 4 shown. This module has three parameters: the input channel number in_ch csp , the output channel number out_ch csp and the number of residual convolution modules n, which consists of an input convolution module, n stacked residual convolution modules, and an output convolution module. The input channel number of the input convolution module is equal to in_ch csp , the output channel number is equal to out_ch csp , the kernel size k is 1, the stride s is 1, and the padding p is 0. The input convolution module can be expressed as y1 = ConvBlock in (x). Among them, B is the batch size and len is the signal length. The number of channels of the n stacked residual convolution modules is all 0.5×out_ch csp . Before the tensor y1 is input into the residual convolution module, a splitting operation is first performed on it. y1 is split into two parts, and the size of each part is (0.5×out_ch, len), which can be expressed as: y2, y3 = Split(y1). Then y2 passes through n residual convolution modules, that is Then all the outputs are concatenated, expressed as y4 serves as the input to the output convolution module. The number of input channels of the output convolution module is equal to 0.5(n + 2)·in_ch csp , and the number of output channels is equal to out_ch csp , the kernel size k is 1, the stride s is 1, and the padding p is 0, which is expressed as: y5 = ConvBlock out (y4). y5 is the final output of this cross-stage partial convolution module.
[0065] 9. Construct the expert network (Expert), the structure is as Figure 5 shown. The expert network is composed of two convolution modules with kernel size k = 3, stride s = 2, and padding p = 1. Let the number of leads of the electrocardiogram signal be lead and the signal length be len, then the number of input channels in_ch conv of the first convolution module is lead, and the number of output channels out_ch conv is 64. The number of input and output channels in_ch conv and out_ch conv of the second convolution module are 64 and 128 respectively. The expert network can be expressed as: Expert(x) = ConvBlock e2 (ConvBlock e1 (x)), where
[0066] 10. Construct the gating network (Gate), the structure is as Figure 6 shown. The gating network consists of a flatten layer, a fully-connected layer, and a softmax function. The gating network takes the electrocardiogram signal as the input. The electrocardiogram signal first passes through the flatten layer, and the flatten layer flattens the multi-dimensional input tensor into a one-dimensional vector for input to the fully-connected layer. Let the batch size be B, the number of leads be lead, and the signal length be len, then the formula is x' = flatten(x), where is the input tensor, is the result after flattening. x' then passes through the fully-connected layer and the softmax function, and the formula is: y = soft t max(W gate x'), where is the weight matrix, is the output of the gating network, m is the number of neurons in the current layer, and also the number of experts controlled by the gating network. In this example, m = 3. In the formula, softmax is the softmax function, and the specific formula is where z i(i = 1, 2, 3, ..., m) represents the i-th element of the input vector z (with length m).
[0067] 11. Construct a classification task branch, with the structure as Figure 7 shown. The core components of the classification task branch include 4 convolutional modules, 4 cross-stage partial convolutional modules, and 2 fully connected layers, arranged in the order: convolutional, cross-stage, convolutional, cross-stage, convolutional, cross-stage, convolutional, cross-stage, fully connected, fully connected. The kernel size k of all convolutional modules is 3, the stride s is 2, and the padding p is 1. The number of input channels in_ch conv of the first convolutional module is 128, and the number of output channels out_ch conv is 256, while the number of input channels in_ch conv and the number of output channels out_ch conv of the remaining convolutional modules are both 256. The number of input channels in_ch csp and the number of output channels out_ch csp of all cross-stage partial convolutional modules are both 256, and the number of residual convolutional modules n is equal to 3. Let the length of the original electrocardiogram signal be len. After passing through the expert layer and the 4 convolutional modules in the classification branch, the signal length at this time is To input the signal into the fully connected layer, the signal first passes through a flattening layer, that is, x' = flatten(x), where is the input tensor, is the result after flattening. Subsequently, x' passes through the first fully connected layer. The number of neurons in this fully connected layer is 512, followed by a batch normalization layer, a SiLU activation function, and a Dropout layer, which can be expressed as: y1 = Dropout(SiLU(BatchNorm(W fc1 x' + b fc1 ))), where is the weight matrix, is the bias term, is the output. In the formula, Dropout represents the Dropout layer. The Dropout layer is a regularization technique used to prevent overfitting in neural networks. It randomly deactivates (sets to zero) some neurons in the fully connected layer with probability p during each training to reduce the dependence on specific neurons, thereby improving the generalization ability of the model. During the inference stage, Dropout is no longer effective, and the model uses all neurons for calculation. In this example, p = 0.5. y1 then enters the second fully connected layer. The number of neurons in this fully connected layer is equal to the number of classes num_cls, followed by a SiLU activation function and a Dropout layer (p = 0.5). For the PTB dataset, the number of classes num_cls = 9. It can be expressed as: y2 = Dropout(SiLU((Wfc2 y1 + b fc2 ))) , where is the weight matrix, is the bias term, and
[0068] 12. Construct the object detection task branch, the structure is as Figure 8 shown. The object detection task branch can be divided into three parts: the backbone network, the neck network, and the detection head. The backbone network is responsible for extracting features at different scales, the neck network fuses features at various scales, and the detection head predicts the location and class information of objects on feature maps at different scales. The structure of each part is as follows:
[0069] b - 1) The backbone network is composed of three convolutional modules (ConvBlock) and three cross-stage partial convolutional modules (CSPBlock) stacked alternately in the order: ConvBlock y1 → CSPBlock y1 → ConvBlock y2 → CSPBlock y2 → ConvBlock y3 → CSPBlock y3 . Among them, ConvBlock y1 is the first convolutional module, with an input channel number of 128, an output channel number of 256, a convolutional kernel size k of 3, a stride s of 2, and a padding p of 1. CSPBlock y1 is the first cross-stage partial convolutional module, with both the input channel number and the output channel number being 256, and the number of residual convolutional modules n being 6. Denote the output of CSPBlock y1 as feature map R1. ConvBlock y2 is the second convolutional module, with an input channel number of 256, an output channel number of 512, a convolutional kernel size of 3, a stride of 2, and a padding of 1. CSPBlock y2 is the second cross-stage partial convolutional module, with both the input channel number and the output channel number being 512, and the number of residual convolutional modules n being 6. Denote the output of CSPBlock y2 as feature map R2. ConvBlock y3 is the third convolutional module, with an input channel number of 512, an output channel number of 1024, a convolutional kernel of 3, a stride of 2, and a padding of 1. CSPBlock y3 is the third cross-stage partial convolutional module, with the input and output channel numbers being 1024, and the number of residual convolutional modules n being 3. Denote the output of CSPBlock y3The output is denoted as the feature map R3. After three downsampling convolutions in the backbone network, the model extracts three feature maps of different scales: R1 (256 channels, ), R2 (512 channels, ), and R3 (1024 channels, ). These three features correspond to high-resolution small-scale features, medium-resolution features, and low-resolution large-scale features respectively, covering the key information at different time scales.
[0070] b-2) The neck network adopts a top-down and bottom-up feature fusion structure, combining high-level semantics with low-level details to improve the accuracy of object detection. It mainly includes upsampling layers (Upsample) and several convolutional / cross-stage partial convolutional modules, in the order of: Upsample1 → CSPBlock y4 → Upsample2 → CSPBlock y5 → ConvBlock y4 → CSPBlock y6 → ConvBlock y5 → CSPBlock y7 . Upsample1 and Upsample2 are upsampling layers that use bilinear interpolation to double the length of the feature map (scale factor scale_factor = 2). This operation does not change the number of channels. The neck network takes R1 (256 channels, ), R2 (512 channels, ), and R3 (1024 channels, ) as inputs. First, R3 is upsampled (the length becomes ), and then the upsampled R3 feature is concatenated with the R2 ( ) feature in the channel dimension to form a 512 + 1024 = 1536-channel feature map ( ), which is input to CSPBlock y4 . CSPBlock y4 is a cross-stage partial convolutional module with an input channel number of 1536 (obtained by concatenating the upsampled R3 feature and the R2 feature in the channel dimension), an output channel number of 512, and the number of residual convolutional modules n being 3. The output feature map length of CSPBlock y4 is , which is the same as the lengths of R2 and the upsampled R3. Denote this output as the feature map Temp. Then the Temp feature map is upsampled 2 times (the length changes from to ), and then Temp is concatenated with R1 (256 channels, ) Concatenate to form a feature map with 256 + 512 = 768 channels (length ), and input it into CSPBlock y5 . CSPBlock y5 is a cross-stage partial convolution module. The input channels are 768 (obtained by concatenating the upsampled Temp and R1), the output channels are 256, and the number of residual convolution modules n is 3. The length of the feature map output by CSPBlock y5 is the same as the lengths of R1 and the upsampled Temp. This output is the updated high-resolution feature map (denoted as R1'). ConvBlock y4 is a convolution module. The input channels and output channels are both 256, the convolution kernel is 3, the stride is 2, and the padding is 1. ConvBlock y4 downsamples the R1' feature, reducing its length from to Concatenate the downsampled R1' feature (length ) with the non-upsampled Temp feature map (512 channels, ) in the channel dimension to obtain a feature map with 256 + 512 = 768 channels and length , and input it into CSPBlock y6 . CSPBlock y6 is a cross-stage partial convolution module. The input channels are 768, the output channels are 512, and the number of residual convolution modules n is 3. CSPBlock y6 outputs a 512-channel feature map with a length of the same as the lengths of the downsampled R1' and the non-upsampled Temp. This output is the updated medium-resolution feature map (denoted as R2'). ConvBlock y5 is a convolution module. The input channels and output channels are both 512, the convolution kernel is 3, the stride is 2, and the padding is 1. ConvBlock y5 downsamples the R2' feature, reducing its length from to Then concatenate the downsampled R2' with R3 (1024 channels, ) in the channel dimension to obtain a feature map with 512 + 1024 = 1536 channels and length , and input it into CSPBlock y7 . CSPBlock y7 has an input channel of 1536, an output channel of 1024, and the number of residual convolution modules n is 3. CSPBlock y7 fuses the middle-level features passed from bottom to top and the original high-level features, and outputs a 1024-channel feature map with a length of It is consistent with the lengths of R3 and the downsampled R2'. This output is the updated low-resolution feature map (denoted as R3'). After the neck network undergoes two-way fusion, it finally outputs three feature maps of the same scale as the backbone, but with multi-scale information fused: R1' (256 channels, ), R2' (512 channels, ), and R3' (1024 channels, ). Compared with the backbone output, the output feature maps of the neck contain fused features from high and low levels, which helps the model detect targets of different durations or amplitudes at different scales.
[0071] b-3) The detection head consists of a bounding box regression branch (box) and a target class branch (cls), and performs target prediction for the three-scale features output by the neck. The structure is as Figure 9 shown. The bounding box regression branch contains three parallel sub-modules that process feature maps of different scales (R1', R2', and R3') respectively. Each sub-module sequentially includes: a convolutional module (with an input channel of x and an output channel of 64), a convolutional module (with both input and output channels of 64), and a one-dimensional convolutional layer (with an input channel of 64 and an output channel of 2). Among them, the convolutional kernel size of the convolutional module is 3, the stride is 1, and the padding is 1, while the last convolutional layer is used to output the prediction result, with a convolutional kernel size of 1, a stride of 1, and no padding. For the three sub-modules, x is 256, 512, and 1024 respectively, corresponding to the number of channels of feature maps of different scales. The final 2-channel output represents two parameters of the target bounding box (center point offset and width offset, see c-1 for details). The structure of the target class branch is the same as that of the bounding box regression branch, but the output channel number of the last one-dimensional convolutional layer is 3, corresponding to the confidence levels of each waveform of the P wave, QRS complex, and T wave. For each level of scale feature map, the output of its corresponding bounding box regression sub-module (2 channels) and the output of the target class sub-module (3 channels) are concatenated in the channel dimension to form the final prediction at that scale. For example, for the high-resolution feature map (256 channels, ), the output size of the bounding box regression branch The output size of the target class branch After concatenation, we get prediction tensor (where 5 = 2 + 3).
[0072] 13. Build a multi-task model. The model is as Figure 10As shown in the figure. The multi-task model adopts an architecture that combines expert fusion and task-specific branches. The overall model consists of an expert network (Experts), a gating network (Gate), and task branches (TaskTowers). Among them, the task branches include a classification task branch and an object detection task branch. Multiple expert networks are set in the model, and the number of experts is determined by the parameter num_experts (in this example, num_experts = 4). The expert network is responsible for feature extraction of the original input signal, and its output will be used as the information source for subsequent task branches. Each task has a gating network. During forward propagation, the gating network performs weighted summation on the expert outputs according to the input electrocardiogram signal to form task-specific fused features, and its calculation formula is: y = ∑ j,j∈E softmax(W gate x) j ·F (j) (x). Among them, F (j) (x) is the output of the j-th expert network, and E represents the expert controlled by the current task. Generally speaking, the number of experts num_experts ≥ 3. Two tasks must have independent experts, and there must be shared experts in the framework. In this example, there are a total of 4 experts. The first expert is the independent expert of the object detection task branch, the fourth expert is the independent expert of the classification task branch, and the second and third experts are the shared experts of the two tasks. Therefore, for the object detection task branch, E = {1, 2, 3}, and for the classification task branch, E = {2, 3, 4}.
[0073] 14. Read the processed classification dataset and object detection dataset in steps 1 - 5, and randomly divide them into a training set and a test set according to a ratio of 4:1. The statistics of the dataset samples in this example are as Figure 11 shown. The labels of the object detection dataset need to be converted into a tensor format consistent with the three scales output by the object detection task branch, that is, B × 5 × scale. Among them, B is the batch size, is the output scale of the three detection heads of the object detection task branch (len is the length of the electrocardiogram signal). For each scale, a label tensor with a shape of B × 5 × scale needs to be constructed, where the 5 channels correspond in sequence: normalized center point offset (offset), logarithmic width offset (log_width_offset), confidence of class 0 (P wave), confidence of class 1 (QRS wave), and confidence of class 2 (T wave). For each grid scale, encode according to the following steps:
[0074] c-1) Initialize a zero tensor with a size of B × 5 × scale.
[0075] c-2) According to the current scale scale, calculate the normalized length cell_size of each grid cell, and the formula is:
[0076] c-3) Extract the normalized center point (center_norm), normalized width (width_norm), and class number (cls) from each original label.
[0077] c-4) Determine the grid cell where the target is located by calculating Determine the grid cell where the target is located.
[0078] c-5) After determining the grid where the target is located, calculate the normalized offset of the target center within the grid; At the same time, calculate the logarithmic offset of the width, using the formula: where a very small value 10 -16 is added to prevent numerical instability during logarithmic calculation.
[0079] c-6) Fill the calculated offset and log_width_offset into the corresponding positions of the pre-initialized zero tensor; at the same time, according to the target category, assign the corresponding category channel (starting from the third channel, the (2 + cls)-th) to 1, indicating that the target of this category exists in this grid cell.
[0080] 15. Set the loss function for the classification task. The classification task branch uses the Focal Loss to address the problem of dataset imbalance. The specific calculation method of the Focal Loss is as follows:
[0081] d-1) Calculate the traditional cross-entropy loss where p t represents the predicted probability of the model for the true category.
[0082] d-2) Introduce the focusing factor (1 - p t ) γ (where γ is usually set to 2). At the same time, weight different category samples through the category weight (α), and the formula is where α can be dynamically calculated according to the number of category samples in the training set, so that when the sample distribution is unbalanced, the minority categories obtain higher weights, and finally the overall loss of the classification task is obtained. In this example, the calculation method is as follows: where class_samples represents the number of samples of this category, and max_samples represents the number of samples of the category with the most samples.
[0083] 16. Set the loss function for the object detection task. The loss function of the object detection task branch includes the following parts:
[0084] e-1) Class Loss: To measure the classification prediction error of each grid cell, the binary cross-entropy loss function (BCEWithLogitsLoss) is adopted. The last 3 channels output by the object detection task branch correspond to the prediction scores of 3 object classes respectively, and are directly compared with the object labels during calculation. The loss function formula is where pred cls is the class score tensor predicted by the model, and target cls is the one-hot encoded vector obtained after label encoding.
[0085] e-2) Bounding Box Loss: For the regression of the position and width of the object in the signal, first, the predicted value of the center point is restricted to [0, 1] using the sigmoid activation function, and then the error is calculated with the true label. The predicted width value is then exponentiated (exp) to restore the logarithmic offset to the actual offset. The one-dimensional distance intersection over union loss function (DIoU) is used to measure the difference between the predicted bounding box and the true bounding box. The formula is where σ(·) represents the sigmoid activation function, and DIoU is the distance intersection over union function. The formula for the distance intersection over union loss function is: where IoU is the intersection over union function, and the calculation method is (inter is the intersection of the two object boxes, union is the union of the two boxes, ε is a very small value to prevent division by zero), ρ is the distance between the center points of the two object boxes, and c is the length of the smallest closed interval containing the two objects. Additionally, to avoid the influence of grids without objects on the bounding box loss, only the grid cells where objects exist (determined by any class channel in the object label being 1) participate in the calculation of the coordinate loss.
[0086] e-3) The final object detection loss is the weighted sum of each part of the loss, where the bounding box coordinate loss and the class loss are multiplied by the preset weight factors λ box and λ class (both are set to 1 in this example). The calculation formula is This design not only ensures a reasonable balance between the bounding box regression and the classification prediction error but also facilitates adjusting the importance of each loss term according to requirements during actual training.
[0087] 17. Set the hyperparameters for training. The hyperparameters include: batch size B, initial learning rate lr, number of training epochs epoch, weight decay weight_decay, learning rate decay factor α, minimum number of epochs for learning rate decay patience, L1 regularization weight w L1 and L2 regularization weight w L2. In this example, B = 100, lr = 10 -3 , epoch = 500, weight_decay = 10 -5 , α = 0.5, patience = 25, w L1 = 10 -5 , w L2 = 10 -5 .
[0088] 18. Set the optimizer and learning rate scheduler. The optimizer uses the Adaptive Moment Estimation (Adam) optimizer, and its initial learning rate is set to lr (already set in step 17, which is 10 in this example -3 ), and the weight decay parameter is weight_decay (already set in step 17, which is 10 in this example -5 ). The learning rate scheduler uses the metric-based learning rate decay (ReduceLROnPlateau), and monitors according to the total loss of the validation set (the sum of the losses of the classification task and the object detection task). When the validation loss does not improve within consecutive patience (already set in step 17, which is 25 in this example) epochs, the learning rate decays by a factor of α to ensure the adaptive adjustment of the learning rate during the training process.
[0089] 19. Set the data augmentation method. Data augmentation aims to improve the robustness and generalization ability of the electrocardiogram signal model. By applying operations such as adding noise, amplitude scaling, and time translation to the original signal, it simulates various interference factors in signal acquisition. The specific implementation is as follows:
[0090] f-1) Add Gaussian noise: Add Gaussian noise with a mean of 0 and a standard deviation of σ to the original signal (σ = 0.05 in this example).
[0091] f-2) Random amplitude scaling: Randomly sample a scaling factor from the preset scaling range [scale min , scale max (scale min = 0.8, scale max = 1.2 in this example). Scale the original signal by this factor to simulate the changes of signals with different amplitudes and enhance the model's robustness to amplitude changes.
[0092] f-3) Random time translation: Randomly sample a translation factor from the preset translation range [shift min , shift max (shift min = -0.1, shift max= 0.1), and perform edge padding. Finally, crop the translated signal to restore it to the original length (512) to ensure consistent data dimensions.
[0093] 20. Start training. In one training epoch, first read the classification data in batches, perform data augmentation, and then send it into the model. After obtaining the model output, only take the output of the classification task branch, calculate the focal loss, and add the L1 and L2 regularization terms to form the total loss. After backpropagation, update the model parameters. Then read the object detection data in batches, perform data augmentation, and send it into the model. After obtaining the model output, only take the output of the object detection task branch. The model outputs predictions at multiple scales, calculate the corresponding losses respectively, and sum the losses of the three scales; similarly, add the regularization loss and then perform backpropagation to update the model parameters. After each training epoch, evaluate the model performance on the validation set and calculate the average losses of the classification task and the object detection task; according to the validation loss, update the learning rate scheduler, and save the current model weights when the model achieves the best validation loss. The trained model can be applied to the actual scenario.
[0094] Through the introduction of a multi-task learning framework with an independent expert mechanism in the embodiments of this application, the classification task and the object detection task can efficiently share information, avoiding interference between tasks in traditional hard-sharing or soft-sharing mechanisms. This mechanism not only enhances the collaboration between tasks but also improves the utilization efficiency of information, thus greatly improving the overall efficiency of electrocardiogram signal processing. Figure 12 The comparison results show that the multi-task model with an independent expert mechanism adopted in the embodiments of this application outperforms the traditional multi-task model in both the classification task and the object detection task. In terms of the classification task, the precision of the model in this application reaches 0.9996, the accuracy is 0.9980, the recall rate is 0.9980, and the F1 score is 0.9980. Compared with traditional single-expert models (F1 score of 0.9498) and mixed-expert models (F1 score of 0.9891), etc., the model in this application has a significant improvement in classification accuracy. In the object detection task, the model in this application also demonstrates excellent performance. Its F1 score reaches 0.9943, far exceeding that of the single-expert model (F1 score of 0.9283) and the mixed-expert model (F1 score of 0.9771). Generally speaking, the multi-task model with an independent expert mechanism adopted in the embodiments of this application not only achieves higher accuracy and stability in the classification task but also reaches better detection performance in the object detection task. This shows that while improving the information sharing efficiency, this mechanism can effectively avoid interference between tasks, enabling the model to achieve better performance in the multi-task learning framework.
[0095] By introducing a one-dimensional YOLO object detection task branch, the embodiments of the present application can overcome the deficiencies of traditional methods in terms of real-time performance and computational efficiency, and achieve efficient detection of key waveforms such as P waves, QRS complexes, and T waves in electrocardiogram signals. Figure 13 The comparison results show that the one-dimensional YOLO object detection task branch adopted in the present application is superior to traditional methods in terms of the F1 scores of P waves, QRS complexes, and T waves. Among them, the F1 score of P waves reaches 0.9909, the F1 score of QRS complexes is 0.9955, the F1 score of T waves is 0.9966, and the overall average F1 score is as high as 0.9943, significantly superior to other methods. For example, the average F1 score of the U-shaped end-to-end network is 0.9849, while the average F1 score of the cascade of convolutional neural network and 2-bi-directional long short-term memory network is 0.9690, both lower than the method of the present application. In addition, compared with the method of only using convolutional neural network (average F1 score 0.9460) and some traditional algorithms (average F1 score of differential threshold algorithm 0.8693, average F1 score of wavelet transform algorithm 0.7539, average F1 score of hidden Markov chain 0.9572), the embodiments of the present application have greatly improved the detection accuracy.
[0096] In terms of real-time performance, Figure 14 the results show that the one-dimensional YOLO object detection task branch of the embodiments of the present application is significantly superior to the U-shaped end-to-end network in terms of inference speed. Under the same experimental environment (12 th th Gen Intel(R) Core(TM) i7-12700H central processing unit, Nvidia Geforce RTX 3060 Laptop graphics card, 16G memory), the number of parameters of the expert network and the one-dimensional YOLO object detection task branch is 23,754,319, the parameter file size is 90.9MB, and the average inference time is only 931.849ms. In contrast, the number of parameters of the U-shaped end-to-end network is 33,938,722, the parameter file size reaches 130.0MB, and the average inference time is as high as 1832.644ms, almost twice that of the method of the present application. This shows that the embodiments of the present application greatly improve the computational efficiency while ensuring high accuracy, making it more advantageous in electrocardiogram signal processing scenarios with high real-time requirements.
Claims
1. A multi-task model based on independent experts, an electrocardiogram signal classification and target detection method containing a one-dimensional YOLO target detection task branch (hereinafter referred to as "target detection task branch"), characterized in that It includes the following steps: Step 1, preprocess the dataset; Step 2, establish the basic modules of the model; Step 3, establish a multi-task model; Step 4, train the multi-task model.
2. The method according to claim 1, characterized in that, In Step 2, the basic modules of the model are the basic components of the multi-task model, including a convolutional module, a residual convolutional module, and a cross-stage partial convolutional module. The convolutional module consists of three parts: a one-dimensional convolutional layer, a batch normalization layer (Batch Norm), and a SiLU activation function. In the convolutional module, the SiLU activation function of the sigmoid unit performs the following operation: SiLU(x) = x · σ(x). Where σ(x) is the sigmoid function: The residual convolutional module is composed of two convolutional modules and a residual connection. The cross-stage partial convolutional module consists of an input convolutional module, several stacked residual convolutional modules, and an output convolutional module. In the cross-stage partial convolution module, the signal is first processed by the input convolution module and then split into two parts, denoted as y2 and y3. Then y2 passes through all the residual convolution modules in sequence, namely where ResBlock i (·) represents the z-th residual convolution module ( there are n residual convolution modules in total). Finally, all the outputs are concatenated, that is After y4 is processed by the output convolution module, it is used as the output of the cross-stage partial convolution module.
3. The method according to claim 2, characterized in that, In Step 3, the multi-task model is a multi-task model with an independent expert mechanism, including an expert network, a gating network, a classification task branch, and an object detection task branch. The basic component modules include a convolutional module, a residual convolutional module, and a cross-stage partial convolutional module. There are multiple expert networks in the model. Each of the two task branches has an independent expert, and there are shared experts in the model. Each task branch has a gating network, and each gating network only controls the shared experts and the independent experts corresponding to the task. During forward propagation, the gating network will perform a weighted sum of the outputs of the expert networks based on the input electrocardiogram signal to form a task-specific fused feature for input into the task branch.
4. The method according to claim 3, wherein In Step 3, the expert network is composed of two convolutional modules.
5. The method according to claim 4, wherein In Step 3, the gating network is composed of a FlattenLayer, a Fully-Connected Layer, and a Softmax. The gating network takes the electrocardiogram signal as input. The electrocardiogram signal first passes through the FlattenLayer, which flattens the multi-dimensional input tensor into a one-dimensional vector, and then passes through the Fully-Connected Layer and the Softmax. The number of neurons in the Fully-Connected Layer is equal to the number of experts controlled by this gating network. The specific calculation method of the normalization exponential function is where z i (i = 1, 2, 3,..., m) represents the i-th element of the input vector z (with a length of m).
6. The method according to claim 5, characterized in that, In Step 3, the classification task branch consists of 4 convolutional modules, 4 cross-stage partial convolutional modules, and 2 fully-connected layers, arranged in the order of: convolution, cross-stage, convolution, cross-stage, convolution, cross-stage, convolution, cross-stage, fully-connected, fully-connected. After the signal is processed by the convolutional module and the cross-stage partial convolutional module, the signal is first flattened. The flattened result then passes through the first fully-connected layer, followed by a batch normalization layer, a SiLU activation function, and a Dropout layer. Subsequently, the signal enters the second fully-connected layer. The number of neurons in this fully-connected layer is equal to the number of classes, followed by a SiLU activation function and a Dropout layer. The Dropout layer randomly deactivates (sets to zero) some neurons in the fully-connected layer with a probability p during each training. During the inference phase, Dropout no longer takes effect, and the model uses all neurons for calculation.
7. The method according to claim 6, wherein In Step 3, the object detection task branch can be divided into three parts: a Backbone, a Neck, and a Head.
8. The method according to claim 7, wherein In step 3, the backbone network consists of three convolutional modules and three cross-stage partial convolutional modules stacked alternately in the order of: convolution, cross-stage, convolution, cross-stage, convolution, cross-stage. Denote the output of the first cross-stage partial convolution as feature map R1, the output of the second cross-stage partial convolution as feature map R2, and the output of the third cross-stage partial convolution as feature map R3.
9. The method according to claim 8, wherein In step 3, the neck network mainly includes an upsampling layer (Upsample) and several convolutional / cross-stage partial convolutional modules in the order of: upsampling, cross-stage partial convolution, upsampling, cross-stage partial convolution, convolution, cross-stage partial convolution, convolution, cross-stage partial convolution. The upsampling layer uses bilinear interpolation to double the length of the feature map without changing the number of channels. First, R3 is upsampled, and then the upsampled R3 feature is concatenated with the R2 feature in the channel dimension and input into the first cross-stage partial convolutional module. Denote the output as feature map Temp. Then, the Temp feature map is upsampled by a factor of 2, and then Temp is concatenated with R1 and input into the second cross-stage partial convolutional module, and the output is denoted as R1'. Subsequently, the first convolutional module is used to downsample R1'. The downsampled R1' feature is concatenated with the Temp feature map in the channel dimension and input into the third cross-stage partial convolutional module, and the output is denoted as R2'. Subsequently, the second convolutional module is used to downsample the R2' feature. Then, the downsampled R2' is concatenated with R3 in the channel dimension and input into the fourth cross-stage partial convolutional module, and the output is denoted as R3'.
10. The method according to claim 9, characterized in that, In step 3, the detection head consists of a bounding box regression branch (box) and a target category branch (cls). The bounding box regression branch contains three parallel sub-modules that process the feature maps R1', R2', and R3' of different scales respectively. Each sub-module sequentially includes: a convolutional module, a convolutional module, and a one-dimensional convolutional layer. The structure of the target category branch is the same as that of the bounding box regression branch. For each level of scale feature map, the output of its corresponding bounding box regression sub-module is concatenated with the output of the target category sub-module in the channel dimension to form the final prediction at that scale.
Citation Information
Cited By
Electrocardiosignal atrial fibrillation detection system and method and electronic equipment
CN121040922A