Electrocardiosignal anomaly detection method and device based on binary comparison network
Through the dual-comparison network, learning the characteristics of ECG signals in label-free data and optimizing the model structure, the efficiency and accuracy of ECG signals abnormal detection on medical terminal devices with limited computing resources is solved, and automated diagnosis and prediction are realized to adapt to the needs of medical tasks.
Patent Information
- Application Number
- CN202410445129.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-04-15
- Publication Date
- 2025-07-18
AI Technical Summary
The prior art is difficult to effectively use deep learning models for electrocardiogram abnormality detection on medical terminal devices with limited computing resources, and it relies on a large amount of labeled data and visual inspections of professional medical personnel, resulting in inefficiency and inconsistent results.
The electrocardiogram abnormality detection method based on the dual-comparison network is adopted to learn feature representations in labelless data through lightweight timing encoder and dual-comparison network, and the model structure is optimized in the fine-tuning stage to adapt to the needs of medical tasks and reduce the demand for computing resources.
It improves the accuracy and efficiency of ECG signal abnormality detection, can realize automated preliminary diagnosis and health prediction in a medical environment with limited computing resources, and enhances the model's understanding of dynamic changes and long-term dependence relationships of ECG signal.
Smart Images

Figure CN120323982A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical fields of artificial intelligence and time series data anomaly detection, and particularly relates to a method and device for electrocardiogram signal anomaly detection based on a dual contrast network. Background Art
[0002] In the era of rapid development of today's medical technology, the digital acquisition of physiological signal data has become the norm, especially for key vital sign data such as electrocardiogram (ECG). The core characteristic of these data lies in their time series nature, which records the dynamic changes of vital activities. Therefore, in the field of medical health, accurate anomaly detection of time series data is of inestimable value for early detection of electrocardiogram abnormalities, accurate disease diagnosis, and continuous monitoring of patients' health conditions. Especially in the aspect of electrocardiogram anomaly detection, the application of time series data anomaly detection can significantly improve the accuracy and efficiency of medical diagnosis, thus saving lives at critical moments. However, traditional anomaly detection methods usually rely on professional medical staff for visual inspection of signals. This process is not only time-consuming and inefficient, but may also lead to inconsistent results due to experience or subjectivity.
[0003] In recent years, deep learning technology has shown great potential in medical time series anomaly detection due to its powerful feature automatic extraction and pattern recognition capabilities. However, most deep learning models require a large amount of labeled data for training, and the sensitivity and privacy of electrocardiogram signal data make it very difficult to obtain a large amount of relevant labeled data, which poses a challenge to the application of deep learning models. In addition, since deep learning models often have complex structures and a large number of parameters, they require a large amount of storage space and computing resources, but medical terminal devices often have relatively limited computing resources. Therefore, it is urgently necessary to develop a method that can utilize the advantages of deep learning and adapt to the special needs of the medical field.
[0004] In view of the above problems, the present invention proposes a method for electrocardiogram signal anomaly detection based on a dual contrast network. This method specifically designs a model framework including two stages: pre-training and fine-tuning. In the pre-training stage, the model extracts features from different aspects of the original data in parallel through a lightweight time series encoder and two feature transformation algorithms, and optimizes the model parameters through dual contrast and gating mechanisms. Such a design aims to automatically learn the most useful feature representations from unlabeled electrocardiogram signal data. In the fine-tuning stage, in order to improve the applicability of the model in the actual medical environment, the complex structure in the pre-training stage is removed, only the lightweight time series encoder is retained, and a small amount of labeled data is used to finely adjust and optimize the model parameters to ensure its accuracy in specific medical tasks, which makes the model more efficient and easy to deploy. Summary of the Invention
[0005] The technical problem to be solved by the present invention is to provide a method and device for detecting abnormal electrocardiogram signals based on a dual contrast network, so as to learn richer and more accurate data representations based on unlabeled electrocardiogram signal data, thereby improving the accuracy of abnormal electrocardiogram signal detection and the applicability of the intelligent abnormal detection model on terminal devices with limited computing resources.
[0006] The present invention adopts the following technical means to achieve the invention purpose:
[0007] An abnormal electrocardiogram signal detection method based on a dual contrast network, characterized in that: the method includes the following steps:
[0008] S1. Obtain an abnormal electrocardiogram signal detection data set: Download the publicly available abnormal electrocardiogram signal detection data set on the network;
[0009] S2. Construct an abnormal electrocardiogram signal detection model: Construct an abnormal electrocardiogram signal detection model based on a dual contrast network;
[0010] S3. Train the abnormal electrocardiogram signal detection model: Train the abnormal electrocardiogram signal detection model constructed in step S2 on the abnormal electrocardiogram signal detection training data set obtained in step S1.
[0011] As a further limitation of this technical solution, step S2 is used to construct a pre-training input module, a lightweight time series encoder, a dual contrast network, a contrast fusion module, a fine-tuning input module, and a fine-tuning module, and then construct an abnormal electrocardiogram signal detection model.
[0012] As a further limitation of this technical solution, the pre-training input module extracts a piece of data from the abnormal electrocardiogram signal detection data set obtained in step S1. This data contains a signal metadata from the header file and an electrocardiogram signal data from the data file. Then, according to the information in the signal metadata, a reshape operation is performed on the electrocardiogram signal data to convert it into the input form required by the model, thereby obtaining an input data, denoted as T.
[0013] As a further limitation of this technical solution, the lightweight time series encoder uses a convolutional network as a component to encode the unlabeled electrocardiogram signal data, thereby obtaining the original time series features, denoted as The specific implementation is shown in the following formula:
[0014]
[0015] where T represents the unlabeled electrocardiogram signal data, and Encoder lite (·) represents the lightweight time series encoder.
[0016] As a further limitation of this technical solution, the dual-contrast network receives unlabeled electrocardiogram signal data and original temporal features, then performs two conversions on the unlabeled electrocardiogram signal data, and then calculates two sets of contrast losses in parallel based on the two conversion results and the original temporal features, so as to obtain a correlation contrast loss and a dependence contrast loss;
[0017] Specifically, the implementation process of this dual-contrast network is as follows:
[0018] (1) Perform the first conversion on the unlabeled electrocardiogram signal data: Use the time correlation conversion algorithm to convert it into time correlation features, denoted as Then use the correlation feature encoder to process it to obtain correlation features, denoted as The specific implementation is shown in the following formula:
[0019]
[0020]
[0021] Among them, T represents the unlabeled electrocardiogram signal data, Translate related (·) represents the time correlation conversion algorithm, Encoder related (·) represents the correlation feature encoder;
[0022] (2) Perform the second conversion on the unlabeled electrocardiogram signal data: Use the time dependence conversion algorithm to convert it into time dependence features, denoted as Then use the dependence feature encoder to process it to obtain dependence features, denoted as The specific implementation is shown in the following formula:
[0023]
[0024]
[0025] Among them, T represents the unlabeled electrocardiogram signal data, Translate depend (·) represents the time dependence conversion algorithm, Encoder depend (·) represents the dependence feature encoder;
[0026] (3) Calculate the first set of contrast losses based on the original temporal features and the correlation features, so as to obtain the correlation contrast loss, denoted as l r ; The specific implementation is shown in the following formula:
[0027]
[0028] Among them, represents the original temporal features, represents the correlation features, and contrastive_loss(·;·) represents the contrastive loss function;
[0029] (4) Calculate the second set of contrastive losses based on the original temporal features and the dependency features, so as to obtain the dependency contrastive loss, denoted as l d ; The specific implementation is shown in the following formula:
[0030]
[0031] where, represents the original temporal features, represents the correlation features, and contrastive_loss(·;·) represents the contrastive loss function.
[0032] As a further limitation to this technical solution, the constructed contrast fusion module uses a gating mechanism to adaptively fuse the two sets of contrastive losses, so as to obtain the pre-training contrastive loss, denoted as l; The specific implementation is shown in the following formula:
[0033] l = λ * l r +(1 - λ) * l d
[0034] where, l r represents the correlation contrastive loss, l d represents the dependency contrastive loss, and λ represents the trainable parameter.
[0035] As a further limitation to this technical solution, the constructed fine-tuning input module extracts a piece of data from the ECG signal anomaly detection dataset obtained in step S1. This data contains a piece of signal metadata from the header file, a piece of ECG signal data from the data file, and a piece of diagnostic information of the ECG signal from the annotation file. Then, according to the information in the signal metadata, a reshape operation is performed on the ECG signal data, so as to convert it into the input form required by the model, and the diagnostic information of the ECG signal is used as the label, so as to obtain a piece of input data, denoted as T f 。
[0036] As a further limitation to this technical solution, in the constructed fine-tuning module, complex structures in the pre-training stage, such as the dual-contrast network and the contrast fusion module, are deprecated, and only the lightweight temporal encoder is retained. Then, a Dense layer containing the sigmoid activation function is used as the output network layer. In the fine-tuning module, the lightweight temporal encoder receives a small amount of labeled ECG signal data and encodes it to obtain the original temporal features, denoted as Then it is passed to the output network layer; the output network layer maps it to a floating-point value in a specified interval, which is used as the anomaly probability of this electrocardiogram signal data, denoted as P; the specific implementation is shown in the following formula:
[0037]
[0038]
[0039] Among them, T f represents the labeled electrocardiogram signal data, and Encoder lite (·) represents a lightweight temporal encoder.
[0040] An electrocardiogram signal anomaly detection device based on a dual contrast network, characterized in that: the device includes:
[0041] An electrocardiogram signal anomaly detection dataset acquisition unit, used to download the publicly available electrocardiogram signal anomaly detection dataset on the network;
[0042] An electrocardiogram signal anomaly detection model construction unit, used to construct a pre-training input module, construct a lightweight temporal encoder, construct a dual contrast network, construct a contrast fusion module, construct a fine-tuning input module and construct a fine-tuning module, and then construct an electrocardiogram signal anomaly detection model;
[0043] An electrocardiogram signal anomaly detection model training unit, used to construct a loss function in the pre-training stage, construct an optimization function in the pre-training stage, construct a loss function in the fine-tuning stage and construct an optimization function in the fine-tuning stage, and then complete the pre-training, fine-tuning and prediction of the model.
[0044] An electronic device, including: a memory and at least one processor;
[0045] Among them, a computer program is stored on the memory;
[0046] The at least one processor executes the computer program stored in the memory, so that the at least one processor executes the electrocardiogram signal anomaly detection method based on the dual contrast network as described above.
[0047] A computer-readable storage medium, in which a computer program is stored, and the computer program can be executed by a processor to implement the electrocardiogram signal anomaly detection method based on the dual contrast network as described above.
[0048] Compared with the prior art, the beneficial effects of the present invention are as follows:
[0049] (1) Through the correlation comparison module in the dual-contrast network, the present invention can capture the temporal correlation features in the data, thereby enhancing the model's understanding of the dynamic changes in electrocardiogram signals and improving the model's in-depth semantic understanding of medical time series data;
[0050] (2) Through the dependence comparison module in the dual-contrast network, the present invention can capture the temporal dependence features in the data, thereby enhancing the model's ability to model the long-term dependence relationship of electrocardiogram signals and improving the model's understanding of the long-term dependence relationship of medical time series data;
[0051] (3) Through the fine-tuning module, the present invention can optimize the model structure for specific tasks and improve the generalization ability and applicability of the model;
[0052] (4) The method and device proposed by the present invention, combined with the dual-contrast network, can apply the intelligent model to the actual medical environment with limited computing resources, and achieve automated preliminary diagnosis or health prediction of electrocardiogram signals, improving the efficiency and accuracy of abnormal detection of electrocardiogram signal data. Brief Description of the Drawings
[0053] Figure 1 It is a flowchart of a method for detecting abnormal electrocardiogram signals based on a dual-contrast network
[0054] Figure 2 It is a flowchart for constructing an abnormal electrocardiogram signal detection model
[0055] Figure 3 It is a flowchart for training an abnormal electrocardiogram signal detection model
[0056] Figure 4 It is a flowchart of a device for detecting abnormal electrocardiogram signals based on a dual-contrast network
[0057] Figure 5 It is a schematic structural diagram of a dual-contrast network
[0058] Figure 6 It is a schematic framework diagram of an abnormal electrocardiogram signal detection model based on a dual-contrast network. Detailed Embodiments
[0059] Next, the technical solutions in the embodiments of the present invention will be clearly and completely described in conjunction with the accompanying drawings in the embodiments of the present invention. Obviously, the described embodiments are only a part of the embodiments of the present invention, rather than all the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those of ordinary skill in the art without creative efforts shall fall within the protection scope of the present invention.
[0060] Embodiment 1:
[0061] The overall model framework structure of the present invention is asFigure 6 As shown. From Figure 6 it can be seen that the main framework of the present invention includes two stages, namely the pre-training stage and the fine-tuning stage. The framework structure of the pre-training stage includes a lightweight temporal encoder, a dual contrast network, and a contrast fusion module. The framework structure of the fine-tuning stage includes a lightweight temporal encoder and a fine-tuning module. Among them, the lightweight temporal encoder is shared by the pre-training stage and the fine-tuning stage frameworks. In the pre-training stage, the lightweight temporal encoder receives unlabeled electrocardiogram signal data, encodes it, and thus obtains the original temporal representation, and then passes it to the dual contrast network. The dual contrast network receives unlabeled electrocardiogram signal data and the original temporal representation, performs dual contrast processing on them, and thus obtains the correlation contrast loss and the dependence ratio loss, and then passes them to the contrast fusion module. The contrast fusion module receives the correlation contrast loss and the dependence ratio loss, performs adaptive fusion processing on them, and thus obtains the pre-training contrast loss, which is used to optimize the model parameters. In the fine-tuning stage, the pre-trained lightweight temporal encoder receives labeled electrocardiogram signal data, encodes it, and thus obtains the original temporal representation, and then passes it to the fine-tuning module. The fine-tuning module receives the original temporal representation, maps it to a floating-point number on a specified interval, and uses it as the anomaly probability of this electrocardiogram signal data, which is used to optimize the model parameters or feedback to medical staff as the prediction result. Specifically as follows:
[0062] (1) The lightweight temporal encoder encodes the electrocardiogram signal data to obtain the original temporal features;
[0063] (2) The dual contrast network performs two transformations on the unlabeled electrocardiogram signal data, and then calculates two sets of contrast losses in parallel based on the two transformation results and the original temporal features, so as to obtain the correlation contrast loss and the dependence contrast loss;
[0064] (3) The contrast fusion module adaptively fuses the two sets of contrast losses using a gating mechanism to obtain the pre-training contrast loss;
[0065] (4) The fine-tuning module receives the original temporal representation, maps it to a floating-point number on a specified interval, and uses it as the anomaly probability of this electrocardiogram signal data, which is used to optimize the model parameters or feedback to medical staff as the prediction result.
[0066] Embodiment 2:
[0067] The dual contrast network is as Figure 5 shown. The dual contrast network receives unlabeled electrocardiogram signal data and the original temporal representation, then performs two transformations on the unlabeled electrocardiogram signal data, and then calculates two sets of contrast losses in parallel based on the two transformation results and the original temporal representation, so as to obtain the correlation contrast loss and the dependence contrast loss;
[0068] Specifically, the implementation process of the dual - contrast network is as follows:
[0069] (1) Perform the first transformation on the unlabeled electrocardiogram signal data: Use the time - correlation transformation algorithm to convert it into time - correlation features, denoted as Then use the correlation - feature encoder to process it, thereby obtaining correlation features, denoted as The specific implementation is shown in the following formula:
[0070]
[0071]
[0072] Among them, T represents the unlabeled electrocardiogram signal data, Translate depend (·) represents the time - dependence transformation algorithm, Encoder depend (·) represents the dependence - feature encoder;
[0073] (2) Perform the second transformation on the unlabeled electrocardiogram signal data: Use the time - dependence transformation algorithm to convert it into time - dependence features, denoted as Then use the dependence - feature encoder to process it, thereby obtaining dependence features, denoted as The specific implementation is shown in the following formula:
[0074]
[0075]
[0076] Among them, T represents the unlabeled electrocardiogram signal data, Translate depend (·) represents the time - dependence transformation algorithm, Encoder depend (·) represents the dependence - feature encoder;
[0077] (3) Calculate the first group of contrastive losses based on the original temporal features and correlation features, thereby obtaining the correlation contrastive loss, denoted as l r ; The specific implementation is shown in the following formula:
[0078]
[0079] Among them, represents the original temporal features, represents the correlation features, contrastive_loss(·;·) represents the contrastive loss function;
[0080] (4) Calculate the second group of contrastive losses based on the original temporal features and dependence features, thereby obtaining the dependence contrastive loss, denoted as ld ; The specific implementation is shown in the following formula:
[0081]
[0082] Among them, represents the original timing feature, represents the correlation feature, and contrastive_loss(·;·) represents the contrast loss function.
[0083] Example: The time correlation conversion algorithm Translate related (·) in the present invention selects to use the Gramian Angular Field algorithm, and the time dependence conversion algorithm Translate depend (·) selects to use the Markov Transition Field algorithm. Both the correlation feature encoder and the dependence feature encoder select to use the Transformer Encoder, and the contrast loss function contrastive_loss(·;·) selects to use NT-Xent (the normalized temperature-scaled cross entropy loss). In pytorch, the code implementation for the above description is as follows:
[0084]
[0085]
[0086] Among them, sample represents the original timing feature, Markov_feature represents the correlation feature, Gramian_feature represents the dependence feature, loss_related represents the correlation loss, and loss_depend represents the dependence loss.
[0087] Example 3:
[0088] As shown in the appendix Figure 1 A method for electrocardiogram signal anomaly detection based on a dual contrast network in the present invention includes the following steps:
[0089] S1. Obtain an electrocardiogram signal anomaly detection data set: Download the publicly available electrocardiogram signal anomaly detection data set on the network;
[0090] S2. Construct an electrocardiogram signal anomaly detection model: Construct an electrocardiogram signal anomaly detection model based on a dual contrast network;
[0091] S3. Train the electrocardiogram signal anomaly detection model: Train the electrocardiogram signal anomaly detection model constructed in step S2 on the electrocardiogram signal anomaly detection training data set obtained in step S1.
[0092] S1. Obtain an electrocardiogram (ECG) signal anomaly detection dataset
[0093] Download the publicly available ECG signal anomaly detection dataset from the network.
[0094] For example, there are many publicly available ECG signal anomaly detection datasets on the network, such as the MIT-BIH ECG database. Each data record in the MIT-BIH ECG database contains three files, namely ".hea", ".dat", and ".atr". Among them, the ".hea" is the header file, which records the file name, the number of leads, the sampling rate, and the number of data points. The format of the header file is as follows:
[0095] n a1 a2 … an
[0096] fs s1 s2 … sn
[0097] [gainl offset1][gain2 offset2]…[gainn offsetn]
[0098] n is the number of signal channels, a1 a2 … an are the names of the signal files for each channel (excluding the extension), fs is the sampling frequency of the signal (number of samples per second), s1 s2 … sn are the number of samples for each channel, and [gain1offset1][gain2 offset2]…[gainn offsetn] are the gain and offset for each channel, which are used to convert the digital signal back to the actual voltage value;
[0099] .dat is the data file, which is stored in binary format and contains the actual ECG signal data. Each sample is stored in 16-bit integer format, representing the voltage value of the ECG signal;
[0100] .atr is the annotation file, which records the diagnostic information of the ECG experts for the corresponding ECG signals. The format of the annotation file is as follows:
[0101] sample_number code annotation
[0102] sample_number is the ECG sampling point number corresponding to the annotation, code is a digital code representing a specific annotation type or event, and annotation is a character or string providing a text description of the event.
[0103] S2. Build an ECG signal anomaly detection model
[0104] The process of building an ECG signal anomaly detection model is as follows Figure 2As shown, the main operations are to construct a pre-training input module, a lightweight temporal encoder, a dual contrast network, a contrast fusion module, a fine-tuning input module, and a fine-tuning module.
[0105] S201. Construct a pre-training input module
[0106] Extract a piece of data from the ECG signal anomaly detection dataset obtained in step S1. This data contains a piece of signal metadata from the header file and an ECG signal data from the data file. Then, perform a reshape operation on the ECG signal data according to the information in the signal metadata, so as to convert it into the input form required by the model, thereby obtaining an input data, denoted as T.
[0107] S202. Construct a lightweight temporal encoder
[0108] The lightweight temporal encoder uses a convolutional network as a component to encode the unlabeled ECG signal data, thereby obtaining the original temporal features, denoted as The specific implementation is shown in the following formula:
[0109]
[0110] Among them, T represents the unlabeled ECG signal data, and Encoder lite (·) represents the lightweight temporal encoder;
[0111] For example, when implementing the present invention, the lightweight temporal encoder uses a three-layer convolutional network. In pytorch, the code implementation for the above description is as follows:
[0112]
[0113]
[0114] Among them, x_in represents the unlabeled ECG signal data, x_feature represents the original temporal features, and model_ts represents the lightweight temporal encoder.
[0115] S203. Construct a dual contrast network
[0116] The dual contrast network receives the unlabeled ECG signal data and the original temporal features, then performs two conversions on the unlabeled ECG signal data, and then calculates two sets of contrast losses in parallel based on the two conversion results and the original temporal features, thereby obtaining the correlation contrast loss and the dependence contrast loss; the specific implementation thereof can be seen in the dual contrast network described in Embodiment 2.
[0117] S204. Construct a contrast fusion module
[0118] The contrast fusion module uses a gating mechanism to adaptively fuse two sets of contrast losses to obtain the pre-training contrast loss, denoted as l. The specific implementation is shown in the following formula:
[0119] l = λ * l r + (1 - λ) * l d
[0120] Among them, l r represents the correlation contrast loss, l d represents the dependence contrast loss, and λ represents the trainable parameter.
[0121] Example: In PyTorch, the code implementation for the above description is as follows:
[0122]
[0123]
[0124] Among them, loss1 represents the correlation contrast loss, loss2 represents the dependence contrast loss, and fused_loss represents the pre-training contrast loss.
[0125] S205. Build a fine-tuning input module
[0126] Extract a piece of data from the ECG signal anomaly detection dataset obtained in step S1. This data contains a piece of signal metadata from the header file, a piece of ECG signal data from the data file, and a piece of diagnostic information of the ECG signal from the annotation file. Then, perform a reshape operation on the ECG signal data according to the information in the signal metadata, so as to convert it into the input form required by the model, and use the diagnostic information of the ECG signal as the label, thereby obtaining a piece of input data, denoted as T f .
[0127] S206. Build a fine-tuning module
[0128] In the fine-tuning module, complex structures in the pre-training stage, such as the dual contrast network and the contrast fusion module, are deprecated, and only the lightweight temporal encoder is retained. Then, a Dense layer containing a sigmoid activation function is used as the output network layer. In the fine-tuning module, the lightweight temporal encoder receives a small amount of labeled ECG signal data and encodes it to obtain the original temporal features, denoted as Then it is passed to the output network layer; the output network layer maps it to a floating-point value in a specified interval and serves as the anomaly probability of this piece of ECG signal data, denoted as P. The specific implementation is shown in the following formula:
[0129]
[0130]
[0131] Among them, T f represents the labeled electrocardiogram signal data, and Encoder lite (·) represents a lightweight temporal encoder.
[0132] For example, in PyTorch, the code implementation for the above description is as follows:
[0133]
[0134]
[0135] Among them, x_feature represents the labeled electrocardiogram signal data, TS_Encoder represents the lightweight temporal encoder, output_layer represents the output network layer, and output represents the anomaly probability.
[0136] S3. Train the electrocardiogram signal anomaly detection model
[0137] Train the electrocardiogram signal anomaly detection constructed in step S2 on the electrocardiogram signal anomaly detection dataset obtained in step S1. The process is as Figure 3 shown.
[0138] S301. Construct the contrastive loss function in the pre-training stage
[0139] The present invention adopts NT-Xent as the contrastive loss function in the pre-training stage, and the formula is as follows:
[0140]
[0141] Among them, z i represents the original temporal feature, z j represents the correlation feature or dependence feature, N represents the batch_size during training, sim(·, ·) represents the dot product similarity function, and τ represents the temperature parameter.
[0142] S302. Construct the optimization function in the pre-training stage
[0143] After the model tests various optimization functions, it finally selects the Adam optimization function as the optimization function in the pre-training stage. Except that its learning rate is set to 3e-4, other hyperparameters of Adam are selected according to the default values in PyTorch.
[0144] For example, in PyTorch, the code implementation for the above description is as follows:
[0145] optimizer = Adam(optimizer_grouped_parameters, lr = 3e-4)
[0146] Among them, optimizer_grouped_parameters are the parameters to be optimized, and by default, they are all the parameters in the electrocardiogram signal abnormality detection method.
[0147] S303. Construct the loss function in the fine-tuning stage
[0148] The present invention uses cross-entropy as the loss function in the fine-tuning stage, and the formula is as follows.
[0149]
[0150] Among them, y true is the true label, and y pred is the predicted result output by the model.
[0151] Example: In pytorch, the code implementation for the above description is as follows:
[0152] # Calculate the error between the predicted value and the label through the cross-entropy loss function
[0153] loss_fct = CrossEntropyLoss()
[0154] loss = loss_fct(logits.view(-1, self.num_labels), labels.view(-1))
[0155] Among them, labels is the true label, and logits is the predicted result output by the model.
[0156] S304. Construct the optimization function in the fine-tuning stage
[0157] After the model tests various optimization functions, it finally chooses to use the Adam optimization function as the optimization function in the fine-tuning stage. Except that its learning rate is set to 3e-5, other hyperparameters of Adam are selected with the default values in pytorch.
[0158] Example: In pytorch, the code implementation for the above description is as follows:
[0159] # Optimize the model parameters through the Adam optimizer
[0160] optimizer = Adam(optimizer_grouped_parameters, lr = 3e-5)
[0161] Among them, optimizer_grouped_parameters are the parameters to be optimized, and by default, they are all the parameters in the electrocardiogram signal abnormality detection method.
[0162] When the model has not been pre-trained, steps S301 and S302 need to be further executed for pre-training to optimize the model's parameters; when the model pre-training is completed, steps S303 and S304 can be executed for fine-tuning and prediction.
[0163] Embodiment 4
[0164] This device mainly includes 3 units, namely the electrocardiogram signal abnormality detection dataset acquisition unit, the electrocardiogram signal abnormality detection model construction unit, and the electrocardiogram signal abnormality detection model training unit. Its process is as Figure 4 shown, and the specific functions of each unit are described as follows:
[0165] The electrocardiogram signal abnormality detection dataset acquisition unit is used to download the publicly available electrocardiogram signal abnormality detection dataset on the network.
[0166] The electrocardiogram signal abnormality detection model construction unit is used to construct a pre-training input module, construct a lightweight time series encoder, construct a dual contrast network, construct a contrast fusion module, construct a fine-tuning input module, and construct a fine-tuning module, and then construct an electrocardiogram signal abnormality detection model.
[0167] The electrocardiogram signal abnormality detection model training unit is used to construct a loss function in the pre-training stage, construct an optimization function in the pre-training stage, construct a loss function in the fine-tuning stage, and construct an optimization function in the fine-tuning stage, and then complete the pre-training, fine-tuning, and prediction of the model.
[0168] Furthermore, the electrocardiogram signal abnormality detection model construction unit further includes:
[0169] The input module unit in the pre-training stage construction is responsible for constructing the unlabeled electrocardiogram signal data required in the pre-training stage, so as to obtain the input data in the pre-training stage;
[0170] The lightweight time series encoder construction unit is responsible for encoding the unlabeled electrocardiogram signal data to obtain the original time series features;
[0171] The dual contrast network construction unit is responsible for performing two conversions on the unlabeled electrocardiogram signal data, and then calculating two sets of contrast losses in parallel based on the two conversion results and the original time series features, so as to obtain the correlation contrast loss and the dependence contrast loss;
[0172] The contrast fusion module construction unit is responsible for adaptively fusing the two sets of contrast losses using a gating mechanism to obtain the pre-training contrast loss;
[0173] Construct an input module unit for the fine-tuning stage, which is responsible for constructing the labeled electrocardiogram signal data required in the fine-tuning stage, so as to obtain the input data for the fine-tuning stage;
[0174] Construct a fine-tuning module unit, which is responsible for receiving the original temporal representation, mapping it to a floating-point number on a specified interval, and using it as the anomaly probability of this electrocardiogram signal data to optimize the model parameters or feedback the prediction result to medical staff.
[0175] Furthermore, the electrocardiogram signal anomaly detection model training unit further includes:
[0176] Construct a contrast loss function unit for the pre-training stage, which is responsible for calculating the contrast loss error using the NT-Xent loss function;
[0177] Construct an optimization function unit for the pre-training stage, which is responsible for pre-training and adjusting the parameters in model training to reduce the contrast loss error;
[0178] Construct a loss function unit for the fine-tuning stage, which is responsible for calculating the error between the prediction result and the true label using the cross-entropy loss function;
[0179] Construct an optimization function unit for the fine-tuning stage, which is responsible for finely adjusting the parameters in the model to reduce the prediction error.
[0180] Embodiment 5:
[0181] The present disclosure provides an electronic device, including: a memory and at least one processor;
[0182] Wherein, a computer program is stored on the memory;
[0183] The at least one processor executes the computer program stored in the memory, so that the at least one processor executes the electrocardiogram signal anomaly detection method based on the dual contrast network as described above.
[0184] The processor may be a central processing unit (CPU), or may also be other general-purpose processors, digital signal processors (DSPs), application-specific integrated circuits (ASICs), off-the-shelf programmable gate arrays (FPGAs) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. The processor may be a microprocessor or the processor may also be any conventional processor, etc.
[0185] The memory can be used to store computer programs and / or modules. By running or executing the computer programs and / or modules stored in the memory, and calling the data stored in the memory, the processor realizes various functions of the electronic device. The memory mainly includes a program storage area and a data storage area. Among them, the program storage area can store the operating system, application programs required for at least one function, etc.; the data storage area can store data created according to the use of the terminal, etc. In addition, the memory can also include high-speed random access memory, and can also include non-volatile memory, such as hard disks, memory, plug-in hard disks, smart media cards (SMC), secure digital (SD) cards, flash memory cards, at least one magnetic disk storage period, flash memory devices, or other volatile solid-state storage devices.
[0186] Embodiment 6:
[0187] The present disclosure provides a computer-readable storage medium, in which a computer program is stored, and the computer program can be executed by a processor to implement the electrocardiogram signal abnormality detection method based on the dual contrast network as described above. Specifically, a system or device equipped with a storage medium can be provided, on which software program codes for implementing the functions of any one of the above embodiments are stored, and the computer (or CPU or MPU) of the system or device is made to read and execute the program codes stored in the storage medium.
[0188] In this case, the program code read from the storage medium itself can implement the functions of any one of the above embodiments, so the program code and the storage medium storing the program code constitute a part of the present invention.
[0189] Examples of storage media for providing program codes include floppy disks, hard disks, magneto-optical disks, optical disks (such as CD-ROM, CD-R, CD-RW, DVD-ROM, DVD-RAM, DVD-RW, DVD+RW), magnetic tapes, non-volatile memory cards, and ROMs. Optionally, the program code can be downloaded from a server computer via a communication network.
[0190] In addition, it should be clear that not only can the actual operations be completed in part or in whole by executing the program codes read by the computer, but also by the operating system etc. operating on the computer based on the instructions of the program codes, so as to implement the functions of any one of the above embodiments.
[0191] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit them; although the present invention has been described in detail with reference to the foregoing embodiments, those of ordinary skill in the art should understand that they can still modify the technical solutions described in the foregoing embodiments, or perform equivalent replacements on some or all of the technical features; and these modifications or replacements do not cause the essence of the corresponding technical solutions to deviate from the scope of the technical solutions of the embodiments of the present invention.
Claims
1. An electrocardiogram signal abnormality detection method based on a dual - contrast network, characterized in that: The method includes the following steps: S1. Obtain an electrocardiogram (ECG) signal anomaly detection dataset: Download the publicly available ECG signal anomaly detection dataset on the network; S2. Construct an ECG signal anomaly detection model: Construct an ECG signal anomaly detection model based on a dual-contrast network; S3. Train the ECG signal anomaly detection model: Train the ECG signal anomaly detection model constructed in step S2 on the ECG signal anomaly detection training dataset obtained in step S1.
2. The method for constructing an electrocardiogram signal abnormality detection method based on a dual - element contrast network according to claim 1, wherein: Step S2 is used to construct a pre-training input module, a lightweight temporal encoder, a dual-contrast network, a contrast fusion module, a fine-tuning input module, and a fine-tuning module, and then construct an ECG signal anomaly detection model; the aforementioned modules correspond to sub-steps respectively, denoted as S201, S202, S203, S204, S205, S206.
3. The method for constructing an ECG signal anomaly detection based on a dual-contrast network according to claim 1, wherein: The pre-training input module extracts a piece of data from the ECG signal anomaly detection dataset obtained in step S1. This data contains a piece of signal metadata from the header file and a piece of ECG signal data from the data file. Then, according to the information in the signal metadata, a reshape operation is performed on the ECG signal data to convert it into the input form required by the model, thereby obtaining a piece of input data, denoted as T; The constructed lightweight temporal encoder uses a convolutional network as a component to encode the unlabeled electrocardiogram signal data, thereby obtaining the original temporal features, denoted as The specific implementation is shown in the following formula: Among them, T represents the unlabeled electrocardiogram signal data, and Encoder lite (·) represents a lightweight temporal encoder.
4. The method for constructing an electrocardiogram signal abnormality detection method based on a dual - element contrast network according to claim 2, wherein: The dual-contrast network in the dual-contrast network receives unlabeled ECG signal data and original temporal features, then performs two conversions on the unlabeled ECG signal data, and then calculates two sets of contrast losses in parallel based on the two conversion results and the original temporal features, thereby obtaining a correlation contrast loss and a dependence contrast loss; Specifically, the implementation process of this dual-contrast network is as follows: S20301. Perform the first conversion on the unlabeled electrocardiogram signal data: use the time correlation conversion algorithm to convert it into time correlation features, denoted as Then use the correlation feature encoder to process it to obtain correlation features, denoted as The specific implementation is shown in the following formula: Among them, T represents the unlabeled electrocardiogram signal data, Translate related (·) represents the time correlation conversion algorithm, Encoder related (·) represents the correlation feature encoder; S20302. Perform the second conversion on the unlabeled electrocardiogram signal data: use the time-dependent conversion algorithm to convert it into time-dependent features, denoted as Then use the dependency feature encoder to process it to obtain the dependency features, denoted as The specific implementation is shown in the following formula: Among them, T represents the unlabeled electrocardiogram signal data, Translate depend (·) represents a time-dependent conversion algorithm, Encoder depend (·) represents a dependent feature encoder; S20303. Calculate the first set of contrastive losses based on the original temporal features and correlation features, so as to obtain the correlation contrastive loss, denoted as The specific implementation is shown in the following formula: Among them, represents the original timing feature, represents the correlation feature, and contrastive_loss(·;·) represents the contrastive loss function; S20304. Calculate the second set of contrastive losses based on the original temporal features and dependency features, so as to obtain the dependency contrastive loss, denoted as The specific implementation is shown in the following formula: Among them, represents the original timing feature, represents the correlation feature, and contrastive_loss(·;·) represents the contrastive loss function.
5. The method for constructing an electrocardiogram signal abnormality detection method based on a dual-contrast network according to claim 2, wherein: The constructed contrastive fusion module uses a gating mechanism to adaptively fuse two sets of contrastive losses to obtain a pre-trained contrastive loss, denoted as The specific implementation is shown in the following formula: Among them, represents the relevance contrast loss, represents the dependence contrast loss, and λ represents the trainable parameter.
6. The method for constructing an ECG signal anomaly detection based on a dual-contrast network according to claim 2, wherein: The constructed fine-tuning input module extracts a piece of data from the ECG signal anomaly detection dataset obtained in step S1. This data contains a piece of signal metadata from the header file, an ECG signal data from the data file, and a diagnostic information of the ECG signal from the annotation file. Then, according to the information in the signal metadata, a reshape operation is performed on the ECG signal data, so as to convert it into the input form required by the model, and the diagnostic information of the ECG signal is used as a label, thereby obtaining an input data, denoted as T f ; The constructed fine-tuning module deprecates complex structures in the pre-training stage, such as the dual contrast network and the contrast fusion module, and only retains the lightweight temporal encoder. Then, a Dense layer with a sigmoid activation function is used as the output network layer. In the fine-tuning module, the lightweight temporal encoder receives a small amount of labeled electrocardiogram signal data and encodes it to obtain the original temporal features, denoted as Then it is passed to the output network layer. The output network layer maps it to a floating-point value in a specified interval and serves as the anomaly probability of this electrocardiogram signal data, denoted as P. The specific implementation is shown in the following formula: Among them, T f represents labeled electrocardiogram signal data, and Encoder lite (·) represents a lightweight temporal encoder.
7. The method for constructing an electrocardiogram signal abnormality detection method based on a dual - contrast network according to claim 1, characterized in that: Step S3 is used to construct a loss function in the pre-training stage, an optimization function in the pre-training stage, a loss function in the fine-tuning stage, and an optimization function in the fine-tuning stage, and then train the ECG signal anomaly detection model; the aforementioned modules correspond to sub-steps respectively, denoted as S301, S302, S303, S304, and are described as follows in sequence: S301. Construct the contrast loss function in the pre-training stage Use NT-Xent as the contrast loss function in the pre-training stage. The formula is as follows: Among them, z i represents the original temporal feature, z j represents the correlation feature or the dependence feature, N represents the batch_size during training, sim(·, ·) represents the dot product similarity function, and τ represents the temperature parameter; S302. Construct the optimization function in the pre-training stage After the model tests various optimization functions, it finally selects the Adam optimization function as the optimization function in the pre-training stage. Except that its learning rate is set to 3e-4, other hyperparameters of Adam are selected according to the default values in pytorch; S303. Construct the loss function in the fine-tuning stage Use cross-entropy as the loss function in the fine-tuning stage. The formula is as follows: where y true is the true label, and y pred is the predicted result output by the model; S304. Construct the optimization function in the fine-tuning stage The model tested a variety of optimization functions and finally chose to use the Adam optimization function as the optimization function in the fine-tuning stage. Except that its learning rate was set to 3e-5, other hyperparameters of Adam were selected with the default settings in pytorch; When the model has not been pre-trained, steps S301 and S302 need to be further executed for pre-training to optimize the model's parameters; when the model pre-training is completed, steps S303 and S304 can be executed for fine-tuning and prediction.
8. An electrocardiogram signal abnormality detection device constructed based on a dual - element contrast network using claim 1, characterized in that: The device includes: An electrocardiogram signal abnormality detection dataset acquisition unit for downloading publicly available electrocardiogram signal abnormality detection datasets on the network; An electrocardiogram signal abnormality detection model construction unit for constructing a pre-training input module, constructing a lightweight time series encoder, constructing a dual-contrast network, constructing a contrast fusion module, constructing a fine-tuning input module, and constructing a fine-tuning module, and then constructing an electrocardiogram signal abnormality detection model; An electrocardiogram signal abnormality detection model training unit for constructing a loss function in the pre-training stage, constructing an optimization function in the pre-training stage, constructing a loss function in the fine-tuning stage, and constructing an optimization function in the fine-tuning stage, and then completing the pre-training, fine-tuning, and prediction of the model.
9. An electronic device, characterized in that, Including: A memory and at least one processor; Wherein, a computer program is stored on the memory; The at least one processor executes the computer program stored in the memory, so that the at least one processor executes the electrocardiogram signal abnormality detection method based on a dual-contrast network according to any one of claims 1 to 8.
10. A computer-readable storage medium, characterized in that, A computer program is stored in the computer-readable storage medium, and the computer program can be executed by a processor to implement the electrocardiogram signal abnormality detection method based on a dual-contrast network according to any one of claims 1 to 8.