Electrocardio compression method and system based on learnable semantic distillation and layered residual quantization
By using an autoencoder-based compression and reconstruction framework and a three-stage training method, the problem of decoupling diagnostic semantics from waveform details in electrocardiogram signals is solved. This enables the extraction of high-level semantics and hierarchical high-fidelity reconstruction, supporting hierarchical scalable transmission and near-diagnostic lossless compression.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- SOUTH CHINA UNIV OF TECH
- Filing Date
- 2026-01-28
- Publication Date
- 2026-05-12
AI Technical Summary
Existing ECG signal compression technologies struggle to effectively decouple diagnostic semantics from waveform details, resulting in the loss of clinically significant waveform details at high compression ratios, and they cannot support layered scalable transmission and high-fidelity reconstruction.
We employ an autoencoder-based compression and reconstruction framework, employing a three-stage training process: semantic distillation and alignment, joint optimization of detail reconstruction and quantization, and end-to-end joint global fine-tuning. By utilizing learnable query vectors and hierarchical vector quantizers, we achieve deep decoupling and orthogonal representation of semantics and details.
It enables direct extraction of high-level semantics within the compressed domain for diagnostic purposes, while achieving hierarchical high-fidelity reconstruction through residual compensation, supporting layered scalable transmission and near-diagnostic lossless compression.
Smart Images

Figure CN122004881A_ABST
Abstract
Description
Technical Field
[0001] This invention belongs to the field of electrocardiogram (ECG) signal compression technology, and relates to an ECG compression method and system based on learnable semantic distillation and hierarchical residual quantization. Background Technology
[0002] Existing ECG signal compression technologies have evolved from traditional transform domain methods to modern deep learning methods, mainly including transform domain and compressed sensing-based methods, deep convolutional autoencoder-based methods, and Transformer and generative model-based methods.
[0003] Transform-domain and compressed sensing methods primarily utilize the sparsity of ECG signals in specific transform domains (such as the frequency domain and wavelet domain). A typical transform coding process usually includes three steps: transform, quantization, and encoding. For example, discrete wavelet transform (DWT) or discrete cosine transform (DCT) is used to convert the time-domain signal into frequency-domain coefficients, thresholding is used to remove low-energy coefficients, and finally entropy coding is used to output a compressed bitstream. Another related compressed sensing (CS) technique uses a random observation matrix to undersample the signal and reconstructs the signal at the receiver using a nonlinear optimization algorithm. However, these methods are mainly based on the statistical properties of the signal (such as minimizing the mean square error) and lack the ability to perceive pathological semantics. At high compression ratios, they are prone to losing minute but clinically significant waveform details such as the P wave and ST segment, resulting in the Gibbs effect, and cannot effectively distinguish between the "diagnostic critical area" and background noise in the signal.
[0004] With the development of deep learning, compression based on end-to-end neural networks has gradually become mainstream. Methods based on deep convolutional autoencoders (CAEs) typically employ an encoder-decoder architecture. The encoder extracts the spatial morphological features of ECG signals through a convolutional neural network and maps them into low-dimensional continuous latent variables. The decoder then uses deconvolution operations to inversely map the latent variables back to the original signal. Although this improves the compression ratio compared to traditional methods, existing autoencoder technologies still have significant drawbacks: they encode pathological semantics (such as arrhythmia categories) and waveform details (such as high-frequency textures) in the same "black box" latent space, resulting in severe coupling between semantics and details. This coupling prevents the model from achieving "semantic-first" transmission and also does not support hierarchical scalable transmission, meaning it cannot dynamically select whether to transmit only diagnostic information or reconstruct high-fidelity waveforms based on channel conditions.
[0005] In recent years, utilizing self-attention mechanisms and generative adversarial networks (GANs) to process electrocardiogram (ECG) signals has become a new trend. For example, masked autoencoders are used to learn robust representations of signals through a "fill-in-the-blank" approach, or GANs are used to generate multi-lead signals from single-lead signals. While Transformers excel at capturing long-range dependencies, their high computational complexity makes them difficult to deploy on low-power edge devices. More importantly, current generative compression methods focus primarily on signal fidelity and have not yet established a physical correspondence between discrete codebooks and explicit clinical diagnostic semantics, making it difficult to directly use compressed features for downstream analysis tasks.
[0006] In summary, while existing technologies have made some progress in compression ratio and reconstruction accuracy, they generally fail to achieve effective decoupling between "diagnostic semantics" and "waveform details." Clinically, there is an urgent need for a novel compression architecture that can directly extract high-level semantics within the compression domain for diagnostic purposes, while simultaneously achieving hierarchical high-fidelity reconstruction through residual compensation. Summary of the Invention
[0007] The purpose of this invention is to address the aforementioned problems in existing technologies by proposing an ECG compression method and system based on learnable semantic distillation and hierarchical residual quantization.
[0008] To achieve the above objectives, the basic solution of this invention is: an electrocardiogram compression method based on learnable semantic distillation and hierarchical residual quantization, comprising the following steps:
[0009] A compression and reconstruction framework based on an autoencoder is set up. The raw ECG signal is collected and input into the compression and reconstruction framework, and the compressed ECG data is output by the compression and reconstruction framework.
[0010] The compression and reconstruction framework undergoes three-stage training:
[0011] Phase 1: Constructing a supervised architecture based on the "teacher-student" paradigm, using external knowledge from the pre-trained teacher network to guide the student network. Specifically, this involves: initializing learnable query vectors, extracting semantic flow features from the original ECG signal using the student network's dual-stream temporal encoder, constructing a joint optimization objective function that includes semantic knowledge distillation and task supervision, and updating the query vectors and parameters of the dual-stream temporal encoder through backpropagation, thereby enabling the student network to acquire initial semantic feature learning capabilities.
[0012] Phase 2: Freeze the trained query vectors, focus on optimizing the preset hierarchical vector quantizer and timing decoder, input the continuous semantic latent variables and continuous detail latent variables output by the dual-stream timing encoder, establish the mapping relationship between discrete quantization detail variables, quantization semantic variables and continuous features by minimizing waveform reconstruction loss and codebook commitment loss, and use the semantic guidance mechanism to realize the temporal morphology reconstruction of ECG waveforms.
[0013] The three-stage process involves unfreezing the dual-stream timing encoder, hierarchical vector quantizer, timing decoder, and parameters. This process weights and fuses multiple optimization objectives, including semantic distillation, waveform reconstruction, and vector quantization. Through end-to-end collaborative training, the compression and reconstruction framework achieves a globally optimal balance between compression efficiency, signal reconstruction quality, and clinical diagnostic accuracy.
[0014] The working principle and beneficial effects of this basic scheme are as follows: This technical scheme sets up a compression and reconstruction framework based on an autoencoder, which can directly extract high-level semantics for diagnosis within the compression domain, and achieve hierarchical high-fidelity reconstruction through residual compensation. A progressive three-stage training scheme is designed to effectively separate semantic and detail features and perform high-fidelity reconstruction, realizing deep decoupling and orthogonal representation of "pathological semantic information" and "morphological detail information" in ECG signals, thereby supporting hierarchical scalable transmission and near-diagnostic lossless compression.
[0015] Furthermore, a learnable query vector is initialized, and semantic stream features of the original ECG signal are extracted using the student network's dual-stream temporal encoder. A joint optimization objective function incorporating semantic knowledge distillation and task supervision is constructed. The query vector and the parameters of the dual-stream temporal encoder are updated through backpropagation, enabling the student network to acquire initial semantic feature learning capabilities. The specific steps are as follows:
[0016] Initialize a set of learnable query vectors and input them into a two-stream temporal encoder to extract semantic latent variables. and details of hidden variables The optimization process revolves around semantic latent variables. Expanding on this, it specifically includes two parallel supervision paths:
[0017] One is the knowledge distillation path, semantic latent variables. After undergoing dimensionality projection and spatial transformation using a feature adapter, its feature distribution is aligned with the high-dimensional features extracted by the teacher network. Specifically:
[0018] Each dimension of the input vector is fully connected to all neurons in the output layer of the feature adapter via a weight matrix. The data is projected from one feature space to another through a linear transformation (weighted summation), and a bias term is introduced to adjust the flexibility of the fit.
[0019] ,
[0020] in, It is an input vector with shape . ; It is a learnable weight matrix with shape [formula missing]. ; It is a bias vector with shape . ; It is the output vector, with shape [missing information]. ;
[0021] Then, together with the teacher network features, a statistical aggregation operation based on global average pooling and max pooling is performed, and the distillation loss between the global statistical feature vectors of the two is calculated. The statistical aggregation is as follows:
[0022] ,
[0023] ,
[0024] in, This is the output of the student network after processing by the adapter. For the output of the teacher network, The sequence length difference was eliminated, and the global semantic center and the intensity of the most significant pathological response were respectively represented, namely the mean of the output features of the student network in the time dimension, the mean of the output features of the teacher network in the time dimension, the maximum value of the output features of the student network in the time dimension, and the maximum value of the output features of the teacher network in the time dimension. This represents the number of learnable query vectors, where i and j are the indices of the learnable query vectors; T is the received length of the sequence concatenation layer.
[0025] The final distillation loss is a weighted average of orientation alignment loss and intensity alignment loss, and the loss function is... for:
[0026] ,
[0027] in, These are the balance weighting coefficients for directional loss and intensity loss, respectively.
[0028] The first term, orientation alignment loss, is calculated using cosine similarity, by constraining the global mean vector. and The angle between the two networks forces the student network to learn the activation direction of the teacher network in the feature space, that is, to learn the "distribution pattern of the main pathological features".
[0029] The second strength alignment loss uses L1 distance, which is achieved by constraining the global maximum vector. and The absolute difference, forcing students to learn online and the teacher's network to respond to specific pathological waveforms;
[0030] Secondly, there is the task supervision path and semantic latent variables. The results are directly input into the classification head to generate pathological predictions, and the cross-entropy loss is calculated by comparing them with the actual clinical diagnostic labels. ,for:
[0031] ,
[0032] Where M is the total number of pathological classification categories, For the one-hot encoding of the true label, if the sample belongs to class c, then Otherwise, it is 0; The probability value of class c in the predicted probability distribution output by the classification head;
[0033] The weighted sum of distillation loss and cross-entropy loss is used as the overall optimization objective. The query vector and classification head of the two-stream temporal encoder are updated via backpropagation, enabling the two-stream temporal encoder to acquire initial semantic learning capabilities.
[0034] ,
[0035] in, These are the weighting coefficients used to balance the two losses.
[0036] A teacher-student supervised architecture is constructed, utilizing a pre-trained teacher network to introduce external knowledge. By computing the distillation loss of the feature space and the cross-entropy loss of the classification task, the semantic flow branch of the two-stream encoder is forced to focus on capturing global pathological features, thereby constructing a semantic latent variable space with high diagnostic value.
[0037] Furthermore, the pre-trained semantic flow parameters are frozen, and the pre-defined hierarchical vector quantizer and temporal decoder are optimized. By minimizing the waveform reconstruction loss and codebook commitment loss, a mapping relationship between discrete codebooks and continuous features is established. A semantic guidance mechanism is used to restore the temporal morphology of the ECG waveform, and the objective functions for waveform reconstruction and vector quantization optimization are obtained. The specific steps are as follows:
[0038] The overall optimization objective is set to consist of reconstruction loss, codebook loss, and commitment loss, where reconstruction loss is used to measure the reconstruction signal. With the original signal The fidelity between the two streams is determined by the codebook loss term, which updates the vector e in the discrete codebook by shifting it toward the output of the two-stream temporal encoder (i.e., cluster center update); the commitment loss is used to constrain the two-stream temporal encoder so that its output latent variables... Instead of drifting arbitrarily, it tries to get as close as possible to the currently selected codebook vector e;
[0039] In this stage, the queries trained in the first stage in the dual-stream temporal encoder are frozen to preserve their diagnostic semantics, while the computing power is concentrated on updating the temporal decoder parameters and codebook vector. The loss function is:
[0040] ,
[0041] ,
[0042] ,
[0043] ,
[0044] in, To reconstruct the signal, The original input signal, These are implicit variables output by the encoder. Here are the codewords in the codebook, and sg[·] is the stop gradient operation. is a weighting coefficient used to balance the reconstruction loss and the codebook loss.
[0045] By minimizing waveform reconstruction loss and codebook commitment loss, the training system establishes a mapping relationship between discrete codebooks and continuous features, and uses a semantic guidance mechanism to achieve accurate recovery of the temporal morphology of ECG waveforms, realizing joint optimization of detailed reconstruction and quantization.
[0046] Furthermore, the codebook of the hierarchical vector quantizer consists of two parts: a semantic codebook and a detail codebook, which are respectively designed for the semantic latent variables output by the dual-stream temporal encoder. With details and hidden variables Implement differentiated discrete processing strategies;
[0047] The semantic codebook employs a standard vector quantization mechanism, while the detail codebook uses a multi-level residual vector quantization mechanism, consisting of several cascaded sub-codebooks. The quantization formula is defined as follows:
[0048] Semantic codebook quantization: Let the continuous semantic latent variables output by the encoder be... Semantic codebook is defined as , where K is the codebook capacity (i.e., the total number of prototype vectors contained therein). This is the k-th prototype vector;
[0049] The quantization process aims to find the prototype vector in the codebook that has the closest Euclidean distance to the input vector, and the resulting semantic features. for:
[0050] ,
[0051] ,
[0052] Among them, index As a semantically discrete code being transmitted, and It is then fed into the temporal decoder as a global context guide, and can also be used in the classification head for subsequent classification;
[0053] Detail codebook quantization: Let the continuous detail latent variables output by the encoder be... The detail quantizer contains M cascaded subcodebooks. Each level of codebook Each contains N prototype vectors, and the quantization process is a recursive calculation of the residuals:
[0054] Define the initial input residual as For the m-th level quantization ( Perform the following steps:
[0055] Sub-level mapping: in the current level codebook Find the residual with the previous level closest vector :
[0056] ,
[0057] in, The significance of this vector quantization process lies in finding the corresponding expression in the codebook m. The closest typing, The codeword in codebook m;
[0058] Residual update: Calculate the new residual This serves as the input for the next level of quantization:
[0059] ,
[0060] Final reconstruction: After M-level quantization, the quantized detailed features The sum of all child quantized vectors:
[0061] ,
[0062] Through this residual quantization mechanism, as the quantization level M increases, the quantization error decreases. By gradually decreasing the size, high-fidelity restoration of the original waveform characteristics can be achieved.
[0063] By mapping the nearest neighbor search to discrete quantized detail variables and quantized semantic variables respectively, global pathological features with high diagnostic discriminative power can be captured at a low bit rate.
[0064] Furthermore, the parameters of the dual-stream temporal encoder, hierarchical vector quantizer, and temporal decoder are unfrozen. Multiple optimization objectives, including semantic distillation, waveform reconstruction, and vector quantization, are weighted and fused. Through end-to-end collaborative training, the steps to achieve a globally optimal balance between compression efficiency, signal reconstruction quality, and clinical diagnostic accuracy in the compression reconstruction framework are as follows:
[0065] The parameters of all core modules (dual-stream timing encoder, hierarchical vector quantizer, and timing decoder, etc.) are unfrozen. After encoding and quantization, the raw ECG signal is split into two parallel supervision paths:
[0066] In the signal reconstruction path, the time-series decoder uses the fused discrete features to generate the reconstructed signal and calculates the reconstruction loss to ensure waveform fidelity, specifically:
[0067] The timing decoder uses the received discrete index sequence and a corresponding preset codebook to perform reverse mapping, thereby recovering the semantic latent variables. With time-series latent variables ;
[0068] Initial feature mapping: mapping the time-series latent variables The input to the first one-dimensional convolutional layer is transformed by the channel dimension to obtain the initial temporal features;
[0069] Primary semantic interaction: Initial temporal features are input into the first query-enhanced attention module, while the semantic latent variables are introduced. Attention is calculated between the query vector and the temporal features that serve as keys / values, and the output is a feature stream that fuses preliminary semantic information.
[0070] Residual feature extraction: The fused feature stream is passed through two cascaded residual blocks in sequence to extract deep contextual information while maintaining effective gradient propagation;
[0071] Secondary semantic enhancement: The processed features are fed into the second query enhancement attention module, which utilizes the semantic latent variables again. Secondary semantic alignment and enhancement are performed on the feature stream to strengthen the pathological category features in the reconstructed signal;
[0072] Signal reconstruction output: After the feature stream is smoothed by the subsequent residual blocks, the high-dimensional features are projected back to the original signal space using the terminal convolutional layer, and finally a reconstructed electrocardiogram is generated.
[0073] In the semantic diagnostic path, semantic latent variables Continued supervision from the faculty network (distillation) and real-label classification is provided to maintain a high level of pathological identification capability. This involves two parallel processing branches:
[0074] Firstly, the distillation branch: Mapping is performed using a feature adapter to align the feature dimensions to the output dimension of the teacher network, and the distillation loss is calculated. To achieve knowledge transfer;
[0075] Secondly, classification branches: The probability distribution of each category is predicted using a classification head, and the cross-entropy loss is calculated by combining the true category labels. To achieve categorized supervision;
[0076] Total loss function It is the weighted sum of all loss terms, that is, it includes reconstruction loss, codebook loss, commitment loss, semantic distillation loss, and classification cross-entropy loss, and is:
[0077] ,
[0078] in, , , , , These are all weight hyperparameters used to adjust the proportion of different losses during training.
[0079] Through end-to-end collaborative training, the model achieves a globally optimal balance between compression efficiency, signal reconstruction quality, and clinical diagnostic accuracy, enabling end-to-end joint global fine-tuning.
[0080] The present invention also provides an electrocardiogram compression system based on the method described in the present invention, comprising a data acquisition unit and a processing unit, wherein the data acquisition unit is used to acquire raw electrocardiogram signals and transmit them to the processing unit;
[0081] The processing unit is equipped with an autoencoder-based compression and reconstruction framework, which includes a dual-stream timing encoder, a hierarchical vector quantizer, and a timing decoder.
[0082] The dual-stream temporal encoder is used to extract the semantic flow branch of the original electrocardiogram signal, perform knowledge distillation and task supervision, construct a semantic distillation optimization objective function, and perform backpropagation to update the query vector and classification head of the dual-stream temporal encoder, so that the student network has the initial semantic feature learning ability.
[0083] The continuous semantic latent variables and continuous detail latent variables input into the layered vector quantizer and the timing decoder are the output of the dual-stream timing encoder. By minimizing the waveform reconstruction loss and codebook commitment loss, a mapping relationship is established between discrete quantization detail variables, quantization semantic variables and continuous features. The semantic guidance mechanism is used to realize the temporal morphology reconstruction of the ECG waveform.
[0084] Then, all core module parameters are unfrozen, and multiple optimization objectives such as semantic distillation, waveform reconstruction, and vector quantization are weighted and fused. Through end-to-end collaborative training, the framework achieves a globally optimal balance between compression efficiency, signal reconstruction quality, and clinical diagnostic accuracy.
[0085] This system adopts an autoencoder-based compression and reconstruction framework, which mainly consists of a hierarchical vector quantizer, a dual-stream temporal encoder, and a temporal decoder. It achieves deep decoupling and orthogonal representation of "pathological semantic information" and "morphological detail information" in electrocardiogram signals, thereby supporting hierarchical scalable transmission and near-diagnostic lossless compression.
[0086] Furthermore, the dual-stream temporal encoder consists of two convolutional layers at the beginning and end, four residual feature extraction blocks, and two query enhancement attention modules (QAA).
[0087] After the input signal enters the dual-stream timing encoder, it passes through the first convolutional layer with a kernel size of 7 and an output channel number of 32.
[0088] Entering the hierarchical coding process: The signal first passes through the first two residual feature extraction blocks (both with a step size of 4), and the number of channels doubles layer by layer; at this time, the feature vector and the learnable query are input together into the first query enhancement attention module to extract the preliminary semantic query;
[0089] The feature vector continues to pass through the next two residual feature extraction blocks (with step lengths of 4 and 2 respectively), and the number of channels continues to double, thereby achieving downsampling of the input signal;
[0090] The deep features are output in two paths: one path is input together with the initial semantic query, and the second query enhances the attention module to generate semantic latent variables. The other path goes through the last convolutional layer with a kernel size of 3, outputting the detailed latent variables. .
[0091] It acquires variables, fully preserves the time sequence length and high-frequency waveform details corresponding to the original signal, has a dimension much smaller than the time sequence features, and highly condenses global diagnostic information, which is dedicated to subsequent signal reconstruction and pathological classification tasks.
[0092] Furthermore, the hierarchical vector quantizer adopts a dual-stream parallel processing architecture, including a semantic codebook module, a detail codebook module, and a splicing unit;
[0093] The first processing branch is the semantic quantization branch: the semantic codebook module is configured to receive input semantic latent variables. This module contains a semantic codebook, which is used to perform nearest neighbor search and matching on semantic features and output the first index representing high-level semantic information.
[0094] The second processing branch is the detail quantization branch: the detail codebook module is configured to receive input latent detail variables. The module contains a set of cascaded or parallel detail codebooks, configured to perform fine quantization on the texture features and output a second index group representing the signal detail information;
[0095] Output stage: The splicing unit is connected to the output of the semantic codebook module and the detail codebook module respectively. The splicing unit is configured to serially splice the first index and the second index group to generate the final index sequence as the output, thereby realizing the complete discretization representation of the semantic information and texture details of the original signal.
[0096] Through residual quantization, as the quantization level M increases, the quantization error decreases. By gradually reducing the size, high-fidelity restoration of the original waveform characteristics is achieved.
[0097] Furthermore, the temporal decoder consists of a temporal feature reconstruction backbone network and a query enhancement attention module (QAA) embedded therein;
[0098] The temporal feature reconstruction backbone network consists of several cascaded one-dimensional convolutional layers (Conv1d) and residual feature reconstruction modules (Res-Block). The input and output convolutional layers are responsible for the inverse projection of the feature dimension and the generation of the final waveform, respectively. The middle region contains multiple sets of cascaded residual modules, which are used to recover the temporal length and morphological details of the electrocardiogram signal step by step.
[0099] The Query Enhanced Attention (QAA) module, serving as the interface for semantic guidance information injection, is embedded before or between the residual module group and is configured with dual input interfaces to receive detailed features from the backbone network and semantic latent variables from the quantizer, respectively.
[0100] The temporal decoder internally forms two parallel and interactive data processing paths, which perform detail reconstruction and semantic guidance respectively:
[0101] In the detailed feature reconstruction path, the quantized detailed latent variables (Z) d' First, the input convolutional layer performs preliminary feature mapping, and then the input enters the first QAA module;
[0102] The detailed features utilize the attention mechanism to receive the injection and calibration of global semantic information, completing the first feature enhancement. The enhanced features are then upsampled or refined into deep features through the first set of residual modules, and then re-enter the subsequent QAA module to receive semantic guidance.
[0103] The feature sequences, after multiple levels of reconstruction and correction, are finally mapped back to the original signal space through the output convolutional layer to generate a high-fidelity reconstructed electrocardiogram signal.
[0104] The decoder internally forms two parallel and interactive data processing paths, which respectively perform detailed reconstruction and semantic guidance to generate the required signals.
[0105] Furthermore, the query enhancement attention module consists of a query vector storage unit, a sequence concatenation layer, a multi-head self-attention layer, a feedforward neural network layer, and a feature splitting layer;
[0106] The sequence splicing layer receives ECG feature input of length T and combines it with a preset number of query vector storage units. The learnable query vectors are merged along the time dimension to form a vector of length T+. Enhanced feature sequences;
[0107] The enhanced sequence enters the multi-head self-attention layer. The query vector at the end of the sequence acts as a "probe" to actively aggregate global pathological semantic information, while the ECG features at the beginning of the sequence are also updated by fusing global contextual information using the attention mechanism.
[0108] The entire enhancement sequence enters the feedforward neural network layer, where high-dimensional features are extracted and the nonlinear expressive power of the model is enhanced through linear transformation and activation function.
[0109] The feature splitting layer performs a separation operation on the sequence after processing by the feedforward network, restoring it to two parts: the latter... Each vector is used as a semantic latent variable ( The output is sent to the semantic flow branch for subsequent semantic quantization and classification, while the first T vectors are embedded as ECG features enhanced by the attention mechanism and output to the detail flow branch or the next level convolutional layer.
[0110] The feedforward neural network layer (FFN layer) is a two-layer fully connected layer, and the activation function of the first layer is ReLU.
[0111] By aggregating global pathological semantic information and integrating global contextual information, the nonlinear expressive capability of the architecture is enhanced, enabling simultaneous semantic extraction and waveform feature updating.
[0112] Furthermore, the Res-Block consists of three residual units and one one-dimensional convolutional layer. Each residual unit comprises two one-dimensional convolutional layers, an activation function, and residual connections. The number of channels in each residual unit is the same as the number of input feature channels. The kernel size of the last convolutional layer is 3, and the stride and number of channels are consistent with the input features. A pre-activated residual structure is used, consisting of two parallel paths: a main convolutional branch and a skip connection branch.
[0113] The main convolutional branch adopts a "bottleneck" design, consisting of multiple sets of cascaded Snake activation layers and one-dimensional dilated convolutional layers. The number of feature channels is distributed in a way that is first compressed and then restored, and the convolutional layers are configured with a non-zero dilation rate to expand the receptive field.
[0114] Skip connection branches are used to transmit identity mapping features, or to include a 1x1 convolutional layer for dimension alignment when the input and output dimensions are inconsistent.
[0115] After the input feature tensor enters the module, it is divided into two paths: one path enters the main convolution branch, undergoes channel compression, and then sequentially passes through the Snake activation function for periodic nonlinear transformation and one-dimensional dilated convolution for temporal feature extraction, and finally restores to the original channel dimension;
[0116] The other path transmits directly via a jump connection to the branch;
[0117] The output of the main convolution branch is added element-wise to the output of the skip connection branch to obtain the final output of the module.
[0118] It has a simple structure and is easy to use.
[0119] Furthermore, a feature adapter is configured between the semantic output of the dual-stream temporal encoder and the teacher network. The feature adapter is a learnable feature alignment unit, and its physical structure is a fully connected layer.
[0120] The feature adapter converts the semantic latent variables generated by the dual-stream temporal encoder. The original latent space projection is mapped to the feature space of the teacher network, and the feature dimensions are adjusted to match the output dimension of the teacher network, so that the two can calculate the distillation loss in a unified metric space, thus realizing the effective imitation of the high-dimensional feature distribution of the teacher network by the student network.
[0121] Furthermore, a classification head is configured after the output of the dual-stream timing encoder or semantic quantizer. The classification head acts as an auxiliary supervisory component, mapping semantic latent variables to a predefined ECG pathology label space.
[0122] The classification head contains a feature aggregation unit for processing the input sequence of semantic query vectors. Perform global average pooling (GAP) or attention-weighted aggregation in the time dimension to compress it into a single global semantic feature vector that does not change with the sequence length;
[0123] A single global semantic feature vector is input into a multilayer perceptron (MLP). The MLP consists of several cascaded fully connected layers, normalization layers, and nonlinear activation layers, and outputs the predicted probability distribution corresponding to various arrhythmia categories through a linear projection layer at the end.
[0124] The classification head module is configured after the encoder or semantic quantizer output as an auxiliary supervisory component, designed to map semantic latent variables to a predefined ECG pathology label space. Attached Figure Description
[0125] Figure 1 This is a flowchart illustrating the ECG compression method based on learnable semantic distillation and hierarchical residual quantization of the present invention.
[0126] Figure 2 This is a flowchart illustrating the dual-stream timing encoder of the ECG compression system of the present invention;
[0127] Figure 3 This is a flowchart illustrating the timing decoder of the ECG compression system of the present invention;
[0128] Figure 4 This is a flowchart illustrating the query-enhanced attention module of the ECG compression system of the present invention;
[0129] Figure 5 This is a schematic diagram of the hybrid asymmetric masking mechanism of the ECG compression system of the present invention;
[0130] Figure 6 This is a schematic diagram of the first stage of the ECG compression method based on learnable semantic distillation and hierarchical residual quantization of the present invention.
[0131] Figure 7 This is a schematic diagram of the two-stage process of the ECG compression method based on learnable semantic distillation and hierarchical residual quantization of the present invention.
[0132] Figure 8 This is a schematic diagram of the three-stage ECG compression method based on learnable semantic distillation and hierarchical residual quantization of the present invention.
[0133] Figure 9 This is a schematic diagram of the detailed codebook module of the layered vector quantizer in the ECG compression system of the present invention;
[0134] Figure 10 This is a schematic diagram of the structure of the layered vector quantizer of the electrocardiogram compression system of the present invention. Detailed Implementation
[0135] Embodiments of the present invention are described in detail below. Examples of these embodiments are shown in the accompanying drawings, wherein the same or similar reference numerals denote the same or similar elements or elements having the same or similar functions throughout. The embodiments described below with reference to the accompanying drawings are exemplary and are only used to explain the present invention, and should not be construed as limiting the present invention.
[0136] In the description of this invention, it should be understood that the terms "longitudinal", "lateral", "up", "down", "front", "rear", "left", "right", "vertical", "horizontal", "top", "bottom", "inner", "outer", etc., indicate the orientation or positional relationship based on the orientation or positional relationship shown in the accompanying drawings. They are only for the convenience of describing this invention and simplifying the description, and do not indicate or imply that the device or element referred to must have a specific orientation, or be constructed and operated in a specific orientation. Therefore, they should not be construed as limitations on this invention.
[0137] In the description of this invention, unless otherwise specified and limited, it should be noted that the terms "installation", "connection" and "linking" should be interpreted broadly. For example, they can refer to mechanical or electrical connections, or internal connections between two components. They can be direct connections or indirect connections through an intermediate medium. Those skilled in the art can understand the specific meaning of the above terms according to the specific circumstances.
[0138] This invention discloses an electrocardiogram (ECG) compression method based on learnable semantic distillation and hierarchical residual quantization, achieving deep decoupling and orthogonal representation of "pathological semantic information" and "morphological detail information" in ECG signals, thereby supporting hierarchical scalable transmission and near-diagnostic lossless compression. Figure 1 As shown, the ECG compression method based on learnable semantic distillation and hierarchical residual quantization includes the following steps:
[0139] To ensure that the above architecture can effectively separate semantic and detailed features and achieve high-fidelity reconstruction, an autoencoder-based compression reconstruction framework is set up. The original ECG signal is collected and input into the compression reconstruction framework, and the compression reconstruction framework outputs compressed ECG data.
[0140] The compression and reconstruction framework undergoes three-stage training (progressive three-stage training):
[0141] Phase 1 (Semantic Distillation and Alignment Phase): Constructing a supervised architecture based on a "teacher-student" paradigm, the teacher network is pre-trained with external knowledge (meaning the student model (i.e., the proposed encoder) to learn the teacher model's knowledge; specifically, for the same input signal, the goal is to make the student model's output close to the teacher model's output. Both the teacher and student models are neural networks). This guides the student network by: initializing a learnable query vector; extracting semantic flow features from the original ECG signal using the student network's dual-stream temporal encoder; constructing a joint optimization objective function that includes semantic knowledge distillation and task supervision; updating the query vector and the parameters of the dual-stream temporal encoder through backpropagation, enabling the student network to acquire initial semantic feature learning capabilities; and forcing the semantic flow branch of the dual-stream encoder to focus on capturing global pathological features by calculating the distillation loss of the feature space and the cross-entropy loss of the classification task, thereby constructing a semantic latent variable space with high diagnostic value.
[0142] Phase Two (Joint Optimization Phase of Detail Reconstruction and Quantization): Freeze (meaning set the vectors to an untrainable state, and the values of these vectors will not be updated in subsequent training) the trained query vectors, focus on optimizing the preset hierarchical vector quantizer and timing decoder, input the continuous semantic latent variables and continuous detail latent variables output by the dual-stream timing encoder, establish the mapping relationship between discrete quantized detail variables, quantized semantic variables and continuous features by minimizing waveform reconstruction loss and codebook commitment loss, and realize the temporal morphology reconstruction of ECG waveform using semantic guidance mechanism; by minimizing waveform reconstruction loss and codebook commitment loss, train the system to establish the mapping relationship between discrete codebook and continuous features, and realize the accurate recovery of ECG waveform temporal morphology using semantic guidance mechanism.
[0143] The three-stage (end-to-end joint global fine-tuning stage) involves unfreezing (unfreezing is the reverse operation of freezing, making the parameters updatable) all core module parameters (dual-stream timing encoder, hierarchical vector quantizer and timing decoder, learnable query, classification head and all codebooks), and weighted fusion of multiple optimization objectives such as semantic distillation, waveform reconstruction and vector quantization. Through end-to-end collaborative training, the compression reconstruction framework achieves a globally optimal balance between compression efficiency, signal reconstruction quality and clinical diagnostic accuracy.
[0144] The learnable query vector is typically an N*D vector, where N is the number of queries / length and D is the dimension of each learnable query. Preferably, its initial value is determined by orthogonal initialization. Specifically, a vector filled with random noise is first generated by sampling from a standard normal distribution. Matrix A; then, A is decomposed into QR decomposition as follows: Q is an orthogonal matrix containing N mutually perpendicular (orthogonal) vectors with uniform magnitude, while R is an upper triangular matrix containing redundant correlation and scaling information. Finally, R is discarded, and Q is retained as the initial value of the final learnable Query, thereby ensuring that the N Queries are uncorrelated in the D-dimensional feature space and match different feature patterns in the ECG signal.
[0145] In general, random initialization can also be used to determine the initial value of the learnable query vector, that is, to sample random values from a uniform distribution or a normal distribution.
[0146] In a preferred embodiment of the present invention, such as Figure 6 As shown, a learnable query vector is initialized, and semantic stream features of the original ECG signal are extracted using the student network's two-stream temporal encoder. A joint optimization objective function incorporating semantic knowledge distillation and task supervision is constructed. The query vector and the parameters of the two-stream temporal encoder are updated through backpropagation, enabling the student network to acquire initial semantic feature learning capabilities. The specific steps are as follows:
[0147] The first phase of training aims to force the semantic flow branch in the two-stream encoder to learn discrete representations with high diagnostic value by introducing external knowledge supervision. This phase constructs a "teacher-student" distillation architecture, in which the input ECG signal is simultaneously fed into the two-stream temporal encoder to be trained and a pre-trained teacher network with frozen parameters.
[0148] Initialize a set of learnable query vectors and input them into a two-stream temporal encoder to extract semantic latent variables. and details of hidden variables Since this stage focuses on constructing the semantic space, the optimization process revolves around semantic latent variables. Expanding on this, it specifically includes two parallel supervision paths:
[0149] One is the knowledge distillation path, semantic latent variables. After undergoing dimensionality projection and spatial transformation using a feature adapter, its feature distribution is aligned with the high-dimensional features extracted by the teacher network. Specifically:
[0150] Each dimension of the input vector is fully connected to all neurons in the output layer of the feature adapter via a weight matrix. The data is projected from one feature space to another through a linear transformation (weighted summation), and a bias term is introduced to adjust the flexibility of the fit.
[0151] ,
[0152] in, It is an input vector with shape . ; It is a learnable weight matrix with shape [formula missing]. ; It is a bias vector with shape . ; It is the output vector, with shape [missing information]. For example, if the semantic latent variables output by the encoder are N*D vectors, and the output vector of the teacher network has a dimension of N*L, and D≠L, then after passing through the feature adapter, D can be forced to equal L.
[0153] Then, together with the teacher network features, a statistical aggregation operation based on global average pooling and max pooling is performed, and the distillation loss between the global statistical feature vectors of the two is calculated. The statistical aggregation is as follows:
[0154] ,
[0155] ,
[0156] in, This is the output of the student network after processing by the adapter. For the output of the teacher network, The sequence length difference was eliminated, and the global semantic center and the intensity of the most significant pathological response were respectively represented, namely the mean of the output features of the student network in the time dimension, the mean of the output features of the teacher network in the time dimension, the maximum value of the output features of the student network in the time dimension, and the maximum value of the output features of the teacher network in the time dimension. This represents the number of learnable query vectors, where i and j are the indices of the learnable query vectors; T is the received length of the sequence concatenation layer.
[0157] The final distillation loss is a weighted average of orientation alignment loss and intensity alignment loss, and the loss function is... for:
[0158] ,
[0159] in, These are the balance weighting coefficients for directional loss and intensity loss, respectively, and can both be set to 0.5;
[0160] The first term, orientation alignment loss, is calculated using cosine similarity (Cosine Loss), by constraining the global mean vector. and The angle between the two networks forces the student network to learn the activation direction of the teacher network in the feature space, that is, to learn the "distribution pattern of the main pathological features".
[0161] The second strength alignment loss uses L1 distance, which is achieved by constraining the global maximum vector. and The absolute difference, forcing students to learn online and the teacher's network to respond to specific pathological waveforms;
[0162] Secondly, there is the task supervision path and semantic latent variables. The data is directly input into the classification head to generate pathological predictions, and the cross-entropy loss is calculated by comparing it with the actual clinical diagnostic labels. ,for:
[0163] ,
[0164] Where M is the total number of pathological classification categories, For the one-hot encoding of the ground truth label, if the sample belongs to class c, then Otherwise, it is 0; The probability value of class c in the predicted probability distribution output by the classification head;
[0165] The weighted sum of distillation loss and cross-entropy loss is used as the overall optimization objective. The query vector and classification head of the two-stream temporal encoder are updated via backpropagation, enabling the two-stream temporal encoder to acquire initial semantic learning capabilities.
[0166] ,
[0167] in, The weighting factor used to balance the two losses can be set to 0.2.
[0168] In a preferred embodiment of the present invention, the teacher network (Teacher Model) is a pre-trained and parameter-frozen deep neural network that serves as a knowledge source for semantic distillation;
[0169] The teacher network employs a high-performance classification model architecture (such as ResNet1d or Transformer) trained on a large-scale ECG dataset, which is capable of extracting high-level pathological semantic features.
[0170] Throughout the training process, the teacher network remains in inference mode with its parameters frozen. It does not participate in backpropagation and gradient updates, but is only responsible for mapping the input ECG signal into a high-dimensional target semantic feature vector, providing stable supervision signals for the semantic branches of the encoder.
[0171] In a preferred embodiment of the present invention, such as Figure 7 As shown, the pre-trained semantic flow parameters are frozen, and the preset hierarchical vector quantizer and temporal decoder are optimized. By minimizing the waveform reconstruction loss and codebook commitment loss, a mapping relationship between discrete codebooks and continuous features is established. Then, a semantic guidance mechanism is used to restore the temporal morphology of the ECG waveform, and the objective function for waveform reconstruction and vector quantization optimization is obtained. The specific steps are as follows:
[0172] The overall optimization objective is set by the reconstruction loss. The codebook loss and commitment loss are combined, with the reconstruction loss used to measure the reconstructed signal. With the original signal The fidelity between the two streams is determined by the codebook loss term, which updates the vector e in the discrete codebook by shifting it toward the output of the two-stream temporal encoder (i.e., cluster center update); the commitment loss is used to constrain the two-stream temporal encoder so that its output latent variables... Instead of drifting arbitrarily, it tries to get as close as possible to the currently selected codebook vector e;
[0173] In this stage, the queries trained in the first stage in the dual-stream temporal encoder are frozen to preserve their diagnostic semantics, while the computing power is concentrated on updating the temporal decoder parameters and codebook vector. The loss function is:
[0174] ,
[0175] ,
[0176] ,
[0177] Training Phase Two: ,
[0178] in, To reconstruct the signal, The original input signal, These are implicit variables output by the encoder. Here are the codewords in the codebook, and sg[·] is the stop gradient operation. These are weighting coefficients used to balance the reconstruction loss and the codebook loss, such as... .
[0179] The mapping between the codebook and semantics is learned through the design and optimization of the loss function. Specifically, firstly, the semantic flow parameters and query vectors trained in the first stage of the encoder are frozen to preserve their high-dimensional representation ability of ECG signal diagnostic semantics; then, the hierarchical vector quantizer and temporal decoder are optimized. In this process, a stable mapping relationship between discrete codebooks and continuous features is established by minimizing the overall optimization objective function, which includes waveform reconstruction loss, codebook loss, and commitment loss, and a semantic guidance mechanism is used to assist in the temporal morphological recovery of ECG waveforms.
[0180] The second phase of training aims to build high-fidelity waveform reconstruction capabilities and simultaneously optimize the distribution characteristics of the discrete codebook. The focus of training shifts to the parameter updates of the hierarchical vector quantizer and the temporal decoder.
[0181] During the forward propagation of data, the raw ECG signal is input to a dual-stream timing encoder, generating continuous latent variables of detail (Zd) and semantic latent variables (Zs). These two latent variables then enter the quantizer module, where they are mapped to discrete quantized detail variables (Zd') and quantized semantic variables (Zs') through nearest neighbor search. To achieve waveform reconstruction, the timing decoder simultaneously receives these two quantized variables as input, using the global semantic context provided by Zs' to guide the recovery of waveform details in Zd', ultimately generating the reconstructed ECG signal.
[0182] In a preferred embodiment of the present invention, the codebook of the hierarchical vector quantizer consists of two parts: a semantic codebook and a detail codebook, which are respectively designed for the semantic latent variables output by the dual-stream temporal encoder. With details and hidden variables Implement differentiated discrete processing strategies;
[0183] The semantic codebook employs a standard vector quantization mechanism, while the detail codebook uses a multi-level residual vector quantization mechanism, consisting of several cascaded sub-codebooks. The quantization formula is defined as follows:
[0184] Semantic codebook quantization (Standard VQ): Let the continuous semantic latent variables output by the encoder be... Semantic codebook is defined as , where K is the codebook capacity (i.e., the total number of prototype vectors contained therein). This is the k-th prototype vector;
[0185] The quantization process aims to find the prototype vector in the codebook that has the closest Euclidean distance to the input vector, and the resulting semantic features. for:
[0186] ,
[0187] ,
[0188] Among them, index As a semantically discrete code being transmitted, and It is then fed into the temporal decoder as a global context guide, and can also be used in the classification head for subsequent classification;
[0189] Detail codebook quantization: Let the continuous detail latent variables output by the encoder be... The detail quantizer contains M cascaded subcodebooks. Each level of codebook Each contains N prototype vectors, and the quantization process is a recursive calculation of the residuals:
[0190] Define the initial input residual as For the m-th level quantization ( Perform the following steps:
[0191] Sub-level mapping: in the current level codebook Find the residual with the previous level closest vector :
[0192] ,
[0193] in, The significance of this vector quantization process lies in finding the corresponding expression in the codebook m. The closest typing, The codeword in codebook m;
[0194] Residual update: Calculate the new residual This serves as the input for the next level of quantization:
[0195] ,
[0196] Final reconstruction: After M-level quantization, the quantized detailed features The sum of all child quantized vectors:
[0197] ,
[0198] Through this residual quantization mechanism, as the quantization level M increases, the quantization error decreases. By gradually decreasing the size, high-fidelity restoration of the original waveform characteristics can be achieved.
[0199] In a preferred embodiment of the present invention, such as Figure 8As shown, the steps to unfreeze all core module parameters (including dual-stream timing encoder, hierarchical vector quantizer, and timing decoder), perform weighted fusion of multiple optimization objectives such as semantic distillation, waveform reconstruction, and vector quantization, and achieve a globally optimal balance between compression efficiency, signal reconstruction quality, and clinical diagnostic accuracy through end-to-end collaborative training are as follows:
[0200] The third stage of training aims to overcome the limitations of independent optimization in the first two stages. Through end-to-end global joint training, the dual-stream encoder, hierarchical quantizer, temporal decoder, and classification head work together under a unified optimization objective.
[0201] After unfreezing the parameters of all core modules (dual-stream timing encoder, hierarchical vector quantizer, and timing decoder, etc.), the raw ECG signal, after encoding and quantization, is split into two parallel supervision paths:
[0202] In the signal reconstruction path, the time-series decoder uses the fused discrete features to generate the reconstructed signal and calculates the reconstruction loss to ensure waveform fidelity, specifically:
[0203] The timing decoder uses the received discrete index sequence and a corresponding preset codebook to perform reverse mapping, thereby recovering the semantic latent variables. With time-series latent variables ;
[0204] Initial feature mapping: mapping the time-series latent variables The input to the first one-dimensional convolutional layer is transformed by the channel dimension to obtain the initial temporal features;
[0205] Primary semantic interaction: Initial temporal features are input into the first query-enhanced attention module, while the semantic latent variables are introduced. Attention is calculated between the query vector and the temporal features that serve as keys / values, and the output is a feature stream that fuses preliminary semantic information.
[0206] Residual feature extraction: The fused feature stream is passed through two cascaded residual blocks in sequence to extract deep contextual information while maintaining effective gradient propagation;
[0207] Secondary semantic enhancement: The processed features are fed into the second query enhancement attention module, which utilizes the semantic latent variables again. Secondary semantic alignment and enhancement are performed on the feature stream to strengthen the pathological category features in the reconstructed signal;
[0208] Signal reconstruction output: After the feature stream is smoothed by the subsequent residual blocks, the high-dimensional features are projected back to the original signal space using the terminal convolutional layer, and finally a reconstructed electrocardiogram is generated.
[0209] Ideally, the entire calculation process of the attention mechanism can be summarized as follows: the query and key are matched to calculate a weight, and then the weight is applied to the value. The specific mathematical formula is as follows:
[0210] ;
[0211] In the semantic diagnostic path, semantic latent variables Continued supervision from the faculty network (distillation) and real-label classification is provided to maintain a high level of pathological identification capability. This involves two parallel processing branches:
[0212] Firstly, the distillation branch: Mapping is performed using a feature adapter to align the feature dimensions to the output dimension of the teacher network, and the distillation loss is calculated. To achieve knowledge transfer;
[0213] Secondly, classification branches: The probability distribution of each category is predicted using a classification head, and the cross-entropy loss is calculated by combining the true category labels. To achieve categorized supervision;
[0214] Total loss function It is the weighted sum of all loss terms, that is, it includes reconstruction loss, codebook loss, commitment loss, semantic distillation loss, and classification cross-entropy loss, and is:
[0215] Training Phase Three: ,
[0216] in, , , , , These are all weight hyperparameters used to adjust the proportion of different losses during training, and can be set to 0.5, 0.1, 1.0, 0.25, and 0.25 respectively.
[0217] The present invention also provides an electrocardiogram (ECG) compression system based on the method described herein, comprising a data acquisition unit and a processing unit. The data acquisition unit is used to acquire raw ECG signals and transmit them to the processing unit. The processing unit includes an autoencoder-based compression and reconstruction framework, which comprises a dual-stream timing encoder, a hierarchical vector quantizer, and a timing decoder.
[0218] A dual-stream temporal encoder is used to extract the semantic flow branch of the original electrocardiogram signal, perform knowledge distillation and task supervision, construct a semantic distillation optimization objective function, and perform backpropagation to update the query vector and classification head of the dual-stream temporal encoder, so that the student network has the initial semantic feature learning ability.
[0219] The continuous semantic latent variables and continuous detail latent variables input to the dual-stream timing encoder in the hierarchical vector quantizer and timing decoder are used to establish the mapping relationship between discrete quantization detail variables, quantization semantic variables and continuous features by minimizing waveform reconstruction loss and codebook commitment loss. The timing morphology reconstruction of ECG waveform is realized by using a semantic guidance mechanism.
[0220] Then, all core module parameters are unfrozen, and multiple optimization objectives such as semantic distillation, waveform reconstruction, and vector quantization are weighted and fused. Through end-to-end collaborative training, the framework achieves a globally optimal balance between compression efficiency, signal reconstruction quality, and clinical diagnostic accuracy.
[0221] In a preferred embodiment of the present invention, such as Figure 2 As shown, the dual-stream temporal encoder consists of two convolutional layers at the beginning and end, four residual feature extraction blocks, and two query enhancement attention modules;
[0222] After the input signal enters the dual-stream timing encoder, it passes through the first convolutional layer with a kernel size of 7 and an output channel number of 32.
[0223] Entering the hierarchical coding process: The signal first passes through the first two residual feature extraction blocks (both with a step size of 4), and the number of channels doubles layer by layer; at this time, the feature vector and the learnable query are input together into the first query enhancement attention module to extract the preliminary semantic query;
[0224] The feature vector continues to pass through the next two residual feature extraction blocks (with step lengths of 4 and 2 respectively), and the number of channels continues to double, thereby achieving downsampling of the input signal;
[0225] The deep features are output in two paths: one path is input together with the initial semantic query, and the second query enhances the attention module to generate semantic latent variables. The other path goes through the last convolutional layer with a kernel size of 3, outputting the detailed latent variables. .
[0226] In the semantic stream processing path, a set of preset, learnable query vectors independent of the input signal are initialized and input into the first QAA module, which acts as a "probe" to perform multi-head attention interaction with shallow ECG features, actively aggregating global pathological semantic information to generate intermediate query vectors.
[0227] The intermediate query vector skips the intermediate residual feature extraction module and is directly passed as input to the next QAA module. It interacts with the deep ECG features to correct and refine the semantic representation. The query vector after multi-level aggregation is finally used as a semantic latent variable. Output. This variable has a much smaller dimensionality than temporal features and highly condenses global diagnostic information, making it specifically designed for subsequent pathological classification tasks.
[0228] In a preferred embodiment of the present invention, such as Figure 9 and Figure 10 As shown, the hierarchical vector quantizer adopts a dual-stream parallel processing architecture, including a semantic codebook module, a detail codebook module, and a concatenation unit.
[0229] The first processing branch is the semantic quantization branch: the semantic codebook module is configured to receive input semantic latent variables. This module contains a semantic codebook, which is used to perform nearest neighbor search and matching on semantic features and output the first index representing high-level semantic information.
[0230] The second processing branch is the detail quantization branch: the detail codebook module is configured to receive input latent detail variables. The module contains a set of cascaded or parallel detail codebooks, configured to perform fine quantization on the texture features and output a second index group representing the signal detail information;
[0231] Output stage: The splicing unit is connected to the output of the semantic codebook module and the detail codebook module respectively. The splicing unit is configured to serially splice the first index and the second index group to generate the final index sequence as the output, thereby realizing the complete discretization representation of the semantic information and texture details of the original signal.
[0232] In a preferred embodiment of the present invention, such as Figure 3 As shown, the temporal decoder consists of a temporal feature reconstruction backbone network and a query enhancement attention module (QAA) embedded therein;
[0233] The temporal feature reconstruction backbone network consists of several cascaded one-dimensional convolutional layers (Conv1d) and residual feature reconstruction modules (Res-Block). The input and output convolutional layers are responsible for the inverse projection of the feature dimension and the generation of the final waveform, respectively. The middle region contains multiple sets of cascaded residual modules, which are used to recover the temporal length and morphological details of the electrocardiogram signal step by step.
[0234] The Query Enhanced Attention (QAA) module, serving as the interface for semantic guidance information injection, is embedded before or between the residual module group and is configured with dual input interfaces to receive detailed features from the backbone network and semantic latent variables from the quantizer, respectively.
[0235] The temporal decoder internally forms two parallel and interactive data processing paths, which perform detail reconstruction and semantic guidance respectively:
[0236] In the detailed feature reconstruction path, the quantized detailed latent variables (Z) d' First, the input convolutional layer performs preliminary feature mapping, and then the input enters the first QAA module;
[0237] The detailed features utilize the attention mechanism to receive the injection and calibration of global semantic information, completing the first feature enhancement. The enhanced features are then upsampled or refined into deep features through the first set of residual modules, and then re-enter the subsequent QAA module to receive semantic guidance.
[0238] The feature sequences, after multiple levels of reconstruction and correction, are finally mapped back to the original signal space through the output convolutional layer to generate a high-fidelity reconstructed ECG signal.
[0239] The decoder structure is a mirror image of the encoder, and the input is the latent variables of detail. First, a one-dimensional convolutional layer is input, with a kernel size of 7, and the number of channels matches the dimension of the final latent variables, which is 1024 by default. Then, the hierarchical decoding process begins: first, the semantic latent variables... The waveform features are input along with the feature vector into the first query-enhanced attention module to initially reconstruct them from the semantic latent variables. This is followed by the first two residual feature extraction blocks (corresponding to step lengths of 2 and 4, respectively). Afterward, the features are again processed by the semantic latent variables. The signals are input together into the second query enhancement attention module for semantic enhancement, and then pass through two residual feature extraction blocks (with stride lengths of 4 and 4 respectively). Throughout the process, the number of channels is halved for each residual feature extraction block. Finally, the features are passed through a one-dimensional convolutional layer with a kernel size of 7 and a channel count of 1 to recover the original signal.
[0240] Preferably, the temporal decoder adopts a cascaded structure, sequentially comprising an input convolutional layer, a first semantic injection stage, an intermediate feature extraction stage, a second semantic injection stage, a deep feature extraction stage, and an output convolutional layer. The specific connections are as follows: the input convolutional layer (Conv1d) receives detail latent variables at its input, and its output is connected to a first query-augmented attention module (Query-Aug-Attn). The output of the first query-augmented attention module is connected to an intermediate feature extraction stage composed of two concatenated residual blocks (Res-Blocks). The output of this intermediate feature extraction stage is connected to the second query-augmented attention module. Subsequently, the data stream passes through the deep feature extraction stage composed of two concatenated residual blocks and is finally connected to the output convolutional layer. Specifically, both the first and second query-augmented attention modules are configured with semantic query interfaces to receive input semantic latent variables (…). This allows for the weighting and guidance of semantic information on temporal features at different levels.
[0241] In a preferred embodiment of the present invention, such as Figure 4 As shown, the query enhancement attention module consists of a query vector storage unit, a sequence concatenation layer, a multi-head self-attention layer, a feedforward neural network layer, and a feature splitting layer.
[0242] The sequence splicing layer receives ECG feature input of length T and combines it with a preset number of query vector storage units. The learnable query vectors are merged along the time dimension to form a vector of length T+. Enhanced feature sequences;
[0243] The enhanced sequence enters the multi-head self-attention layer. The query vector at the end of the sequence acts as a "probe" to actively aggregate global pathological semantic information, while the ECG features at the beginning of the sequence are also updated by fusing global contextual information using the attention mechanism.
[0244] The entire enhancement sequence enters the feedforward network layer, where high-dimensional features are extracted and the non-linear expressive power of the model is enhanced through linear transformation and activation functions.
[0245] The feature splitting layer performs a separation operation on the sequence after processing by the feedforward network, restoring it to two parts: the latter... Each vector is used as a semantic latent variable ( The output is sent to the semantic flow branch for subsequent semantic quantization and classification, while the first T vectors are output to the detail flow branch or the next level convolutional layer as ECG feature embeddings enhanced by the attention mechanism, thereby realizing the synchronous operation of semantic extraction and waveform feature update.
[0246] The feedforward neural network layer (FFN layer) is a two-layer fully connected layer, and the activation function of the first layer is ReLU.
[0247] QAA's Attention Mask employs a hybrid asymmetric masking mechanism (such as...). Figure 5 As shown in the diagram, a differentiated view design balances the needs of streaming processing and global interaction. On the encoder side, the mask matrix is configured to impose strict causal constraints on the feature stream, meaning that the feature vectors can only aggregate information from the current and historical moments, while masking future moments and query vectors, to ensure the real-time performance and causality of signal processing.
[0248] For semantic query streams, a global view is opened, allowing query vectors to scan the complete feature sequence to capture long-distance pathological dependencies. On the decoder side, the masking strategy is adjusted to a semantically guided mode. Although detailed features are still limited by causal masking and cannot predict future waveforms, they are allowed to focus on the entire sequence of quantized semantic latent variables. This enables the decoder to accurately infer and recover local waveform details under the real-time guidance of global pathological information.
[0249] In a preferred embodiment of the present invention, the Res-Block consists of three residual units and one one-dimensional convolutional layer. Each residual unit comprises two one-dimensional convolutional layers, an activation function (such as the Snake activation function), and residual connections. The number of channels in each residual unit is the same as the number of input feature channels. The kernel size of the last convolutional layer is 3, and the stride and number of channels are consistent with the input features. A pre-activated residual structure is used, consisting of two parallel paths: a main convolutional branch and a skip connection branch.
[0250] The main convolutional branch adopts a "bottleneck" design, consisting of multiple sets of cascaded Snake activation layers and one-dimensional dilated convolutional layers. The number of feature channels is distributed in a way that is first compressed and then restored, and the convolutional layers are configured with a non-zero dilation rate to expand the receptive field.
[0251] Skip connection branches are used to transmit identity mapping features, or to include a 1x1 convolutional layer for dimension alignment when the input and output dimensions are inconsistent.
[0252] In terms of data flow, the input feature tensor is divided into two paths after entering the module: one path enters the main convolution branch, undergoes channel compression, and then sequentially passes through the Snake activation function for periodic nonlinear transformation and one-dimensional dilated convolution for temporal feature extraction, and finally restores to the original channel dimension.
[0253] The other path transmits directly via a jump connection to the branch;
[0254] The output of the main convolution branch is added element-wise to the output of the skip connection branch to obtain the final output of the module.
[0255] In a preferred embodiment of the present invention, a feature adapter is configured between the semantic output end of the dual-stream temporal encoder and the teacher network. The feature adapter is a learnable feature alignment unit, and its physical structure is a fully connected layer.
[0256] The feature adapter converts the semantic latent variables generated by the dual-stream temporal encoder. The original latent space projection is mapped to the feature space of the teacher network, and the feature dimensions are adjusted to match the output dimension of the teacher network, so that the two can calculate the distillation loss in a unified metric space, thus realizing the effective imitation of the high-dimensional feature distribution of the teacher network by the student network.
[0257] In a preferred embodiment of the present invention, a classification head is configured after the output of the dual-stream timing encoder or semantic quantizer. The classification head serves as an auxiliary supervisory component, mapping semantic latent variables to a predefined electrocardiogram pathology label space.
[0258] The classification head contains a feature aggregation unit for processing the input sequence of semantic query vectors. Perform global average pooling (GAP) or attention-weighted aggregation in the time dimension to compress it into a single global semantic feature vector that does not change with the sequence length;
[0259] A single global semantic feature vector is input into a multilayer perceptron (MLP). The MLP consists of several cascaded fully connected layers (Linear Layer), normalization layers (such as LayerNorm), and nonlinear activation layers (such as ReLU or GELU). At the end, a linear projection layer outputs the predicted probability distribution corresponding to various arrhythmia categories (such as normal, atrial fibrillation, premature ventricular contractions, etc.).
[0260] This invention, by introducing knowledge distillation and a learnable query mechanism from a teacher network, endows discrete representations with explicit physical meaning, forcibly constraining the first-layer codebook to a "pathological semantic space" and subsequent codebooks to a "morphological residual space," thereby overcoming the uninterpretability of traditional VQ "black box" clustering. This design, which decouples semantics from details, enables near-diagnostic lossless hierarchical scalable transmission: at extremely low bandwidths, transmitting only the semantic codebook index can preserve state-of-the-art diagnostic accuracy and recover the basic waveform; at normal bandwidths, combining subsequent codebook indexes enables high-fidelity reconstruction.
[0261] In addition, the progressive three-stage training strategy of "semantic distillation-detail reconstruction-joint fine-tuning" effectively avoids gradient conflicts between the two heterogeneous loss functions of "waveform reconstruction" and "pathological classification" in the early stage of training, ensuring that the model can converge to the global optimum in terms of compression efficiency, signal fidelity and diagnostic accuracy.
[0262] The specific embodiments described herein are merely illustrative examples of the present invention. Those skilled in the art can make various modifications or additions to the described embodiments or use similar methods to substitute them, without departing from the technology of the present invention or exceeding the scope defined by the appended claims.
Claims
1. An ECG compression method based on learnable semantic distillation and hierarchical residual quantization, characterized in that, Includes the following steps: A compression and reconstruction framework based on an autoencoder is set up. The raw ECG signal is collected and input into the compression and reconstruction framework, and the compressed ECG data is output by the compression and reconstruction framework. The compression and reconstruction framework undergoes three-stage training: Phase 1: Constructing a "teacher-student" paradigm of supervised architecture, pre-training the external knowledge of the teacher network to guide the student network. Specifically, this involves: initializing learnable query vectors, extracting semantic flow features of the original ECG signal using the student network's dual-stream temporal encoder, constructing a joint optimization objective function that includes semantic knowledge distillation and task supervision, and updating the query vectors and parameters of the dual-stream temporal encoder through backpropagation, so that the student network has the initial semantic feature learning ability. Phase 2: Freeze the trained query vectors, focus on optimizing the preset hierarchical vector quantizer and timing decoder, input the continuous semantic latent variables and continuous detail latent variables output by the dual-stream timing encoder, establish the mapping relationship between discrete quantization detail variables, quantization semantic variables and continuous features by minimizing waveform reconstruction loss and codebook commitment loss, and use the semantic guidance mechanism to realize the temporal morphology reconstruction of ECG waveforms. The three-stage process involves unfreezing the dual-stream timing encoder, hierarchical vector quantizer, timing decoder, and parameters. This process weights and fuses multiple optimization objectives, including semantic distillation, waveform reconstruction, and vector quantization. Through end-to-end collaborative training, the compression and reconstruction framework achieves a globally optimal balance between compression efficiency, signal reconstruction quality, and clinical diagnostic accuracy.
2. The ECG compression method based on learnable semantic distillation and hierarchical residual quantization according to claim 1, characterized in that, Initialize a learnable query vector, extract semantic stream features from the original ECG signal using the student network's dual-stream temporal encoder, construct a joint optimization objective function incorporating semantic knowledge distillation and task supervision, and update the query vector and the parameters of the dual-stream temporal encoder through backpropagation, enabling the student network to acquire initial semantic feature learning capabilities. The specific steps are as follows: Initialize a set of learnable query vectors and input them into a two-stream temporal encoder to extract semantic latent variables. and details of hidden variables The optimization process revolves around semantic latent variables. Expanding on this, it specifically includes two parallel supervision paths: One is the knowledge distillation path, semantic latent variables. After undergoing dimensionality projection and spatial transformation using a feature adapter, its feature distribution is aligned with the high-dimensional features extracted by the teacher network. Specifically: Each dimension of the input vector is fully connected to all neurons in the output layer of the feature adapter via a weight matrix. The data is projected from one feature space to another through a linear transformation (weighted summation), and a bias term is introduced to adjust the flexibility of the fit. , in, It is an input vector with shape . ; It is a learnable weight matrix with shape [formula missing]. ; It is a bias vector with shape [missing information]. ; It is the output vector, with shape [missing information]. ; Then, together with the teacher network features, a statistical aggregation operation based on global average pooling and max pooling is performed, and the distillation loss between the global statistical feature vectors of the two is calculated. The statistical aggregation is as follows: , , in, This is the output of the student network after processing by the adapter. For the output of the teacher network, The sequence length difference was eliminated, and the global semantic center and the intensity of the most significant pathological response were respectively represented, namely the mean of the output features of the student network in the time dimension, the mean of the output features of the teacher network in the time dimension, the maximum value of the output features of the student network in the time dimension, and the maximum value of the output features of the teacher network in the time dimension. This represents the number of learnable query vectors, where i and j are the indices of the learnable query vectors; T is the received length of the sequence concatenation layer. The final distillation loss is a weighted average of orientation alignment loss and intensity alignment loss, and the loss function is... for: , in, These are the balance weighting coefficients for directional loss and intensity loss, respectively. The first term, orientation alignment loss, is calculated using cosine similarity, by constraining the global mean vector. and The angle between the two networks forces the student network to learn the activation direction of the teacher network in the feature space, that is, to learn the "distribution pattern of the main pathological features"; The second strength alignment loss uses L1 distance, which is achieved by constraining the global maximum vector. and The absolute difference, forcing students to learn online and the teacher's network to respond to specific pathological waveforms; Secondly, there is the task supervision path and semantic latent variables. The data is input into the classification head to generate pathological prediction results, and the cross-entropy loss is calculated by comparing them with the actual clinical diagnostic labels. ,for: , Where M is the total number of pathological classification categories, For the one-hot encoding of the true label, if the sample belongs to class c, then Otherwise, it is 0; The probability value of class c in the predicted probability distribution output by the classification head; The weighted sum of distillation loss and cross-entropy loss is used as the overall optimization objective. Backpropagation is performed on the dual-stream temporal encoder, query vector, and classification head to update them, enabling the dual-stream temporal encoder to acquire initial semantic learning capabilities. , in, These are the weighting coefficients used to balance the two losses.
3. The ECG compression method based on learnable semantic distillation and hierarchical residual quantization according to claim 1, characterized in that, The pre-trained semantic stream parameters are frozen, and the preset hierarchical vector quantizer and temporal decoder are optimized. By minimizing the waveform reconstruction loss and codebook commitment loss, a mapping relationship between discrete codebooks and continuous features is established. A semantic guidance mechanism is used to restore the temporal morphology of the ECG waveform, and the objective function for waveform reconstruction and vector quantization optimization is obtained. The specific steps are as follows: The overall optimization objective is set to consist of reconstruction loss, codebook loss, and commitment loss, where reconstruction loss is used to measure the reconstruction signal. With the original signal The fidelity between the two streams is determined by the codebook loss term, which updates the vector e in the discrete codebook by shifting it toward the output of the two-stream temporal encoder (i.e., cluster center update); the commitment loss is used to constrain the two-stream temporal encoder so that its output latent variables... Instead of drifting arbitrarily, it tries to get as close as possible to the currently selected codebook vector e; In this stage, the queries trained in the first stage in the dual-stream temporal encoder are frozen to preserve their diagnostic semantics, while the computing power is concentrated on updating the temporal decoder parameters and codebook vector. The loss function is: , , , , in, To reconstruct the signal, The original input signal, These are implicit variables output by the encoder. Here are the codewords in the codebook, and sg[·] is the stop gradient operation. is a weighting coefficient used to balance the reconstruction loss and the codebook loss.
4. The ECG compression method based on learnable semantic distillation and hierarchical residual quantization according to claim 3, characterized in that, The codebook of the hierarchical vector quantizer consists of two parts: a semantic codebook and a detail codebook, which are respectively designed for the semantic latent variables output by the dual-stream temporal encoder. With details and hidden variables Implement differentiated discrete processing strategies; The semantic codebook employs a standard vector quantization mechanism, while the detail codebook uses a multi-level residual vector quantization mechanism, consisting of several cascaded sub-codebooks. The quantization formula is defined as follows: Semantic codebook quantization: Let the continuous semantic latent variables output by the encoder be... Semantic codebook is defined as , where K is the codebook capacity (i.e., the total number of prototype vectors contained therein). This is the k-th prototype vector; The quantization process aims to find the prototype vector in the codebook that has the closest Euclidean distance to the input vector, and the resulting semantic features. for: , , Among them, index As a semantically discrete code being transmitted, and It is then fed into the temporal decoder as a global context guide, and can also be used in the classification head for subsequent classification; Detail codebook quantization: Let the continuous detail latent variables output by the encoder be... The detail quantizer contains M cascaded subcodebooks. Each level of codebook Each contains N prototype vectors, and the quantization process is a recursive calculation of the residuals: Define the initial input residual as For the m-th level quantization ( Perform the following steps: Sub-level mapping: in the current level codebook Find the residual with the previous level closest vector : , in, The significance of this vector quantization process lies in finding the corresponding expression in the codebook m. The closest typing, The codeword in codebook m; Residual update: Calculate the new residual This serves as the input for the next level of quantization: , Final reconstruction: After M-level quantization, the quantized detailed features The sum of all child quantized vectors: , Through this residual quantization mechanism, as the quantization level M increases, the quantization error decreases. By gradually decreasing the size, high-fidelity restoration of the original waveform characteristics can be achieved.
5. The ECG compression method based on learnable semantic distillation and hierarchical residual quantization according to claim 3, characterized in that, The steps involved in unfreezing the parameters of the dual-stream temporal encoder, hierarchical vector quantizer, and temporal decoder, weighted fusion of multiple optimization objectives including semantic distillation, waveform reconstruction, and vector quantization, and end-to-end collaborative training to achieve a globally optimal balance between compression efficiency, signal reconstruction quality, and clinical diagnostic accuracy in the compression reconstruction framework are as follows: The parameters of the dual-stream sequential encoder, hierarchical vector quantizer, and sequential decoder are unfrozen. After encoding and quantization, the raw ECG signal is split into two parallel supervisory paths: In the signal reconstruction path, the time-series decoder uses the fused discrete features to generate the reconstructed signal and calculates the reconstruction loss to ensure waveform fidelity, specifically: The timing decoder uses the received discrete index sequence and a corresponding preset codebook to perform reverse mapping, thereby recovering the semantic latent variables. With time-series latent variables ; The time-series latent variables The input is fed into the first-dimensional convolutional layer, and a channel-dimensional projection transformation is performed to obtain the initial temporal features; The initial temporal features are input into the first query-enhanced attention module, while the semantic latent variables are introduced. Attention is calculated between the query vector and the temporal features that serve as keys / values, and the output is a feature stream that fuses preliminary semantic information. The fused feature stream is passed sequentially through two cascaded residual blocks to extract deep contextual information while maintaining effective gradient propagation. The processed features are fed into the second query enhancement attention module, which utilizes the semantic latent variables again. Secondary semantic alignment and enhancement are performed on the feature stream to strengthen the pathological category features in the reconstructed signal; After the feature stream is smoothed by the subsequent residual blocks, the high-dimensional features are projected back to the original signal space using the terminal convolutional layer, and finally a reconstructed electrocardiogram is generated. In the semantic diagnostic path, semantic latent variables Continued supervision from the faculty network (distillation) and real-label classification is provided to maintain a high level of pathological identification capability. This involves two parallel processing branches: Firstly, the distillation branch: The feature dimensions are mapped using a feature adapter to align with the output dimension of the teacher network, and the distillation loss is calculated. To achieve knowledge transfer; Secondly, classification branches: The probability distribution of each category is predicted using a classification head, and the cross-entropy loss is calculated by combining the true category labels. To achieve categorized supervision; Total loss function It is the weighted sum of all loss terms, that is, it includes reconstruction loss, codebook loss, commitment loss, semantic distillation loss, and classification cross-entropy loss, and is: , in, , , , , These are all weight hyperparameters used to adjust the proportion of different losses during training.
6. An electrocardiogram compression system based on the method of any one of claims 1-5, characterized in that, It includes a data acquisition unit and a processing unit. The data acquisition unit is used to acquire raw electrocardiogram signals and transmit them to the processing unit. The processing unit is equipped with an autoencoder-based compression and reconstruction framework, which includes a dual-stream timing encoder, a hierarchical vector quantizer, and a timing decoder. The dual-stream temporal encoder is used to extract the semantic flow branch of the original electrocardiogram signal, perform knowledge distillation and task supervision, construct a semantic distillation optimization objective function, and perform backpropagation to update the query vector and classification head of the dual-stream temporal encoder, so that the student network has the initial semantic feature learning ability. The continuous semantic latent variables and continuous detail latent variables input into the layered vector quantizer and the timing decoder are the output of the dual-stream timing encoder. By minimizing the waveform reconstruction loss and codebook commitment loss, a mapping relationship is established between discrete quantization detail variables, quantization semantic variables and continuous features. The semantic guidance mechanism is used to realize the temporal morphology reconstruction of the ECG waveform. Then, all core module parameters are unfrozen, and multiple optimization objectives such as semantic distillation, waveform reconstruction, and vector quantization are weighted and fused. Through end-to-end collaborative training, the framework achieves a globally optimal balance between compression efficiency, signal reconstruction quality, and clinical diagnostic accuracy.
7. The ECG compression system according to claim 6, characterized in that, The dual-stream temporal encoder consists of two convolutional layers at the beginning and end, four residual feature extraction blocks, and two query enhancement attention modules (QAA). After the input signal enters the dual-stream timing encoder, it passes through the first convolutional layer with a kernel size of 7 and an output channel number of 32. Entering the hierarchical coding process: The signal first passes through the first two residual feature extraction blocks (both with a step size of 4), and the number of channels doubles layer by layer; at this time, the feature vector and the learnable query are input together into the first query enhancement attention module to extract the preliminary semantic query; The feature vector continues to pass through the next two residual feature extraction blocks (with step lengths of 4 and 2 respectively), and the number of channels continues to double, thereby achieving downsampling of the input signal; The deep features are output in two paths: one path is input together with the initial semantic query, and the second query enhances the attention module to generate semantic latent variables. The other path goes through the last convolutional layer with a kernel size of 3, outputting the detailed latent variables. .
8. The electrocardiogram compression system according to claim 6, characterized in that, The hierarchical vector quantizer adopts a dual-stream parallel processing architecture, including a semantic codebook module, a detail codebook module, and a splicing unit; The first processing branch is the semantic quantization branch: the semantic codebook module is configured to receive input semantic latent variables. This module contains a semantic codebook, which is used to perform nearest neighbor search and matching on semantic features and output the first index representing high-level semantic information. The second processing branch is the detail quantization branch: the detail codebook module is configured to receive input latent detail variables. The module contains a set of cascaded or parallel detail codebooks, configured to perform fine quantization on the texture features and output a second index group representing the signal detail information; The splicing unit is connected to the output of the semantic codebook module and the detail codebook module respectively. The splicing unit is configured to serially splice the first index and the second index group to generate the final index sequence as the output, thereby realizing the complete discretization representation of the semantic information and texture details of the original signal.
9. The electrocardiogram compression system according to claim 6, characterized in that, The temporal decoder consists of a temporal feature reconstruction backbone network and a query enhancement attention module (QAA) embedded therein; The temporal feature reconstruction backbone network consists of several cascaded one-dimensional convolutional layers (Conv1d) and residual feature reconstruction modules (Res-Block). The input and output convolutional layers are responsible for the inverse projection of the feature dimension and the generation of the final waveform, respectively. The middle region contains multiple sets of cascaded residual modules, which are used to recover the temporal length and morphological details of the electrocardiogram signal step by step. The Query Enhanced Attention (QAA) module, serving as the interface for semantic guidance information injection, is embedded before or between the residual module group and is configured with dual input interfaces to receive detailed features from the backbone network and semantic latent variables from the quantizer, respectively. The temporal decoder internally forms two parallel and interactive data processing paths, which perform detail reconstruction and semantic guidance respectively: In the detailed feature reconstruction path, the quantized detailed latent variables (Z) d' First, the input convolutional layer performs preliminary feature mapping, and then the input enters the first QAA module; The detailed features utilize the attention mechanism to receive the injection and calibration of global semantic information, completing the first feature enhancement. The enhanced features are then upsampled or refined into deep features through the first set of residual modules, and then re-enter the subsequent QAA module to receive semantic guidance. The feature sequence, after multiple levels of reconstruction and correction, is finally mapped back to the original signal space through the output convolutional layer to generate a high-fidelity reconstructed electrocardiogram signal.
10. The electrocardiogram compression system according to claim 7 or 9, characterized in that, The query-enhanced attention module consists of a query vector storage unit, a sequence concatenation layer, a multi-head self-attention layer, a feedforward neural network layer, and a feature splitting layer. The sequence splicing layer receives ECG feature input of length T and combines it with a preset number of query vector storage units. The learnable query vectors are merged along the time dimension to form a vector of length T+. Enhanced feature sequences; The enhanced sequence enters the multi-head self-attention layer. The query vector at the end of the sequence acts as a "probe" to actively aggregate global pathological semantic information, while the ECG features at the beginning of the sequence are also updated by fusing global contextual information using the attention mechanism. The entire enhancement sequence enters the feedforward neural network layer, where high-dimensional features are extracted and the nonlinear expressive power of the model is enhanced through linear transformation and activation function. The feature splitting layer performs a separation operation on the sequence after processing by the feedforward network, restoring it to two parts: the latter... A vector is used as a semantic latent variable ( The output is fed to the semantic flow branch for subsequent semantic quantization and classification, while the first T vectors are embedded as ECG features enhanced by the attention mechanism and output to the detail flow branch or the next level convolutional layer. The feedforward neural network layer (FFN layer) is a two-layer fully connected layer, and the activation function of the first layer is ReLU.
11. The electrocardiogram compression system according to claim 9, characterized in that, Res-Block consists of three residual units and one one-dimensional convolutional layer. Each residual unit comprises two one-dimensional convolutional layers, an activation function, and residual connections. The number of channels in each residual unit is the same as the number of input feature channels. The last convolutional layer has a kernel size of 3, and its stride and number of channels are consistent with the input features. It uses a pre-activated residual structure, consisting of two parallel paths: a main convolutional branch and a skip connection branch. The main convolution branch adopts a "bottleneck" design, consisting of multiple sets of cascaded Snake activation layers and one-dimensional dilated convolutional layers. Its feature channel number is distributed in the form of compression followed by recovery, and the convolutional layers are configured with a non-zero dilation rate to expand the receptive field. Skip connection branches are used to transmit identity mapping features, or to include a 1x1 convolutional layer for dimension alignment when the input and output dimensions are inconsistent. After the input feature tensor enters the module, it is divided into two paths: one path enters the main convolution branch, undergoes channel compression, and then sequentially passes through the Snake activation function for periodic nonlinear transformation and one-dimensional dilated convolution for temporal feature extraction, and finally restores to the original channel dimension; The other path transmits directly via a jump connection to the branch; The output of the main convolution branch is added element-wise to the output of the skip connection branch to obtain the final output of the module.
12. The ECG compression system according to claim 7, characterized in that, A feature adapter is configured between the semantic output of the dual-stream temporal encoder and the teacher network. The feature adapter is a learnable feature alignment unit, and its physical structure is a fully connected layer. The feature adapter converts the semantic latent variables generated by the dual-stream temporal encoder. The original latent space projection is mapped to the feature space of the teacher network, and the feature dimensions are adjusted to match the output dimension of the teacher network, so that the two can calculate the distillation loss in a unified metric space, thus realizing the effective imitation of the high-dimensional feature distribution of the teacher network by the student network.
13. The ECG compression system according to claim 7, characterized in that, A classification head is configured after the output of the dual-stream timing encoder or semantic quantizer. The classification head acts as an auxiliary supervisory component, mapping semantic latent variables to a predefined ECG pathology label space. The classification head contains a feature aggregation unit for processing the input sequence of semantic query vectors. Perform global average pooling (GAP) or attention-weighted aggregation in the time dimension to compress it into a single global semantic feature vector that does not change with the sequence length; A single global semantic feature vector is input into a multilayer perceptron (MLP). The MLP consists of several cascaded fully connected layers, normalization layers, and nonlinear activation layers, and outputs the predicted probability distribution corresponding to various arrhythmia categories through a linear projection layer at the end.