A wellbore ultrasonic leakage detection and early warning method and system based on segmented weakly supervised time sequence representation learning

CN122904048APending Publication Date: 2026-10-13UNIV OF SCI & TECH OF CHINA
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202611103519.1
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2026-07-23
Publication Date
2026-10-13

AI Technical Summary

Technical Problem

[0009]本发明旨在提供一种基于分段弱监督时序表征学习的井筒超声泄漏检测与预警方法与系统,以解决现有技术中现场泄漏标签稀缺、不同井段信号分布变化大、孤立点级分类稳定性不足以及预警结果难以区间化解释的问题

Benefits of technology

1、本发明将中心深度及其邻近深度窗口作为一个判断单元(包),通过最大池化与均值池化加权融合得到分段级预测值,符合现场工程人员按深度区间审查泄漏证据的实际工作流程。相比于传统的单窗口独立判断方式,分段多示例池化能够聚合多个相邻深度窗口的泄漏证据,有效抑制孤立噪声峰值引起的误报,同时增强对弱幅值但连续存在的泄漏响应的检测能力。

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122904048A_ABST
    Figure CN122904048A_ABST
Patent Text Reader

Abstract

The application discloses a kind of wellbore ultrasonic leakage detection early warning method and system based on segmented weak supervision timing representation learning.It includes: obtaining wellbore ultrasonic data and preprocessing;According to the amplitude ratio and amplitude difference of background and target signal, construct weak label, form segmented multiple-instance sample with central depth and adjacent window;Build network containing shared timing encoder, single-window auxiliary branch, background-target contrast branch and segmented multiple-instance pooling module;Define the joint loss function containing segmented classification, auxiliary, consistency and smoothing loss and train;Apply the model to the data to be measured, output suspected leakage depth interval, risk probability, leakage type and early warning level.The application uses segmented multiple-instance learning and background-target contrast to improve the accuracy and robustness of leakage detection under weak label conditions, reduce false positives, and can adapt to different well section signal changes.The application also provides a wellbore ultrasonic leakage detection and early warning system for implementing the above method.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the fields of wellbore integrity detection, ultrasonic nondestructive testing, time-series signal processing, and artificial intelligence early warning technology, and in particular to a wellbore ultrasonic leakage detection and early warning method and system based on piecewise weakly supervised time-series representation learning. Background Technology

[0002] The long-term safe operation of underground gas storage facilities, oil and gas production wells, and injection-production wells depends on the integrity of wellbore barriers such as tubing, casing, and cement sheaths. When natural gas or other fluids leak due to tubing rupture, casing corrosion, threaded seal failure, or cement sheath bonding failure, the risks of abnormal annular pressure, fluid cross-contamination, and reservoir contamination increase significantly. For underground gas storage facilities, wellhead or downhole barrier failure not only affects injection-production efficiency but may also threaten peak-shaving operation and energy supply security. Therefore, timely identification of wellbore leak locations, leakage pathways, and risk levels is a key technical issue in wellbore integrity assessment and safety early warning.

[0003] Currently, ultrasonic, electromagnetic, temperature, isotope, and multi-point wellbore methods are widely used both domestically and internationally for wellbore leakage detection. Among these, ultrasonic leakage detection has advantages such as being non-invasive, having a fast response, and being sensitive to high-frequency leakage acoustic signals. When leaking fluid passes through tiny cracks, thread gaps, or cementation defects, it induces a complex ultrasonic sound field. Sensors can collect acoustic signals along the well depth and identify abnormal well sections based on signal characteristics.

[0004] Existing engineering methods typically rely on human experience, amplitude thresholds, frequency domain energy, or a limited number of traditional machine learning models to make judgments. While these methods are effective in scenarios with clear rules and low noise, they still present the following problems in real-world wellbore environments: First, on-site data labeling is scarce. The actual location of a leak is often difficult to confirm directly; labels are mostly derived from pressure, flow rate, operational records, or subsequent engineering verification, making it difficult to obtain dense, precise window-level labels. While weakly supervised learning methods have been applied in fields such as medical ultrasound image processing, a complete technical solution for engineering applications has not yet been developed for wellbore ultrasonic leak detection.

[0005] Secondly, the acoustic background varies significantly across different well sections. Casing couplings, cemented seal sections, wellhead structures, well inclination variations, and different operating pressures can cause signal distribution drift, making single threshold or point-level classification models prone to failure. While the deep learning method proposed by Halliburton, which arranges measurement data into response images and then processes them via a convolutional neural network, has improved the intelligence level of detection to some extent, it still fails to effectively solve the generalization problem caused by signal distribution drift across different well sections.

[0006] Third, leak responses typically exhibit local continuity. Engineers generally make judgments based on continuous anomalies within a certain depth range, rather than on isolated sampling points. If the model only classifies a single window, it is easy to misclassify noise peaks as leaks, and it may also miss weak but continuous leak responses. Multi-instance learning methods have demonstrated the ability to process "packet-instance" structured data in fields such as video object detection, but a technical solution combining it with the local continuity characteristics in the depth direction of wellbore ultrasonic leak detection is still lacking.

[0007] Fourth, the interpretation of early warning results by interval is insufficient. Existing methods mostly output point-level detection results, making it difficult to provide suspected leak depth intervals and graded early warning information that have engineering guidance significance.

[0008] In recent years, methods such as Transformer, linear attention, selective state-space model, temporal basic model, multi-instance learning, and weakly supervised anomaly detection have shown strong capabilities in temporal modeling and anomaly detection. However, there is still a lack of complete technical solutions for engineering applications on how to combine them with background-target contrast, deep continuity modeling, weak label construction, and on-site early warning requirements in wellbore ultrasonic leak detection. Summary of the Invention

[0009] This invention aims to provide a wellbore ultrasonic leak detection and early warning method and system based on piecewise weakly supervised temporal representation learning, in order to solve the problems of scarce on-site leak tags, large variations in signal distribution in different well sections, insufficient stability of isolated point-level classification, and difficulty in interpreting early warning results in intervals in the existing technology.

[0010] To achieve the above objectives, the present invention adopts the following technical solution: A wellbore ultrasonic leak detection and early warning method based on piecewise weakly supervised temporal representation learning includes the following steps: S1. Acquire ultrasonic testing data of the wellbore and preprocess it to obtain the processed background signal, target signal and single-window signal; S2. Construct weak labels based on the amplitude ratio and amplitude difference between the background signal and the target signal, and form segmented multi-example samples with multiple windows at each center depth and its neighboring depths. S3. Construct a wellbore ultrasonic leak detection network, which includes a shared time encoder, a single-window auxiliary branch, a background-target comparison branch, and a segmented multi-instance pooling module; S4. Define a joint loss function and train the network. The joint loss function includes segmented classification loss, window peak auxiliary loss, single window auxiliary loss, consistency loss, and smoothing loss. S5. Apply the trained model to the wellbore data to be tested, and output the suspected leakage depth range, leakage risk probability, leakage type and warning level.

[0011] Further, in step S1, outlier removal, bandpass filtering, wavelet denoising or median filtering are performed on the original ultrasonic signal, and alignment is performed according to depth or time so that the background window and the target window correspond to the same depth or the same well structure position; each window is normalized and a first-order gradient channel is constructed, and each window includes at least a normalized amplitude channel and a first-order gradient channel. No. The first-order gradient channel of each sampling point is calculated using the following formula: ; in, Represents the normalized i-th Each amplitude sampling point, This represents the corresponding first-order gradient value. , This indicates the window length; preferably, the window length is 256 sampling points, and each window consists of a normalized amplitude channel. With first-order gradient channel Composed of two parts Furthermore, in step S2, for each pair of depth-matched background and target windows, the mean amplitude is calculated, and the amplitude ratio and amplitude difference are calculated accordingly. ; ; in, Indicates the amplitude ratio. Indicates the amplitude difference. This represents the average amplitude of the background window. This represents the mean amplitude of the target window. To prevent the stability constant from having a denominator of zero; When the amplitude ratio is not lower than the first threshold and the amplitude difference is not lower than the second threshold, the sample is marked as a weak positive sample; when the amplitude ratio is within the preset stable range and the absolute value of the amplitude difference does not exceed the third threshold, it is marked as a weak negative sample; samples between the two are removed, downweighted, or used as unlabeled samples for semi-supervised training; preferably, the first threshold is 1.12, the second threshold is 100, the stable range is 0.95 to 1.05, and the third threshold is 80.

[0012] Further, in step S2, at each center depth As the core, offset it upwards and downwards by a preset depth. Multiple windows at adjacent depths are selected to form a segmented multi-instance sample, denoted as: ; in, Indicates depth Segmented samples at the location, Indicates depth Window data at the location, This represents the depth offset, preferably. The value is 2 meters; each window is called an instance, the entire segmented sample is called a packet, and the packet label is determined by the center depth. Weak labels were identified at the location.

[0013] Furthermore, in step S3, the shared temporal encoder includes a one-dimensional convolutional patch embedding layer and a temporal coding layer; The calculation process for one-dimensional convolutional patch embedding is as follows: ; in, This indicates the input window. Indicates the kernel length. Indicates the step size. Representation layer normalization, Represents one-dimensional convolution. Indicates the sequence of patch tokens; The temporal coding layer employs one of the following: a lightweight Transformer encoder, a linear attention encoder, a selective state-space encoder, a convolutional-attention hybrid encoder, or a self-supervised pre-trained temporal encoder.

[0014] Furthermore, the background-target contrast branch inputs the background window and the target window into the shared temporal encoder respectively to obtain the background window embedding. Embedded with target window The cross-attention interaction module makes the target window features focus on the background window features, and the interaction results, the differences between the two, the element-wise product, and the deep embedding are concatenated to form the background-target contrast features: ; in, Indicates contrasting features. This indicates that the background window is embedded. The symbol ⊙ indicates target window embedding, and ⊙ indicates element-wise multiplication. Indicates deep embedding, Represents the cross-attention interaction function; The segmented multi-instance pooling module weights and fuses max pooling and mean pooling by a weight coefficient β to obtain segmented predicted values: ; in, Indicates the first The predicted value for each window, Indicates the number of windows within a segment. This represents the maximum pooling weight, preferably. The value is 0.65.

[0015] Further, in step S4, the joint loss function is expressed as: ; in, Indicates the piecewise predicted value. This represents the segmented classification loss. Indicates the peak auxiliary loss of the window. Indicates single-window auxiliary loss. Indicates consistency loss. Indicates smoothing loss. , , , Represents the weighting coefficients for each loss; The segmented classification loss and single-window auxiliary loss both employ focus loss. ; in, Represents the focus loss function. Indicates the predicted probability. Indicates a weak label. Indicates category weight, Indicates the adjustment factor for difficult samples; The consistency loss and smoothing loss are respectively defined as: ; ; in, Indicates consistency loss. Indicates smoothing loss. This represents the mean square error function. This represents the segmented predicted values. Indicates the first The predicted value for each window, Indicates the number of windows within a segment; Before or during training, a large number of unlabeled wellbore ultrasonic signals from the field can be used for self-supervised pre-training. The pre-training tasks can be flexibly selected according to the data situation, including one or more of the following: mask reconstruction, time-series segment sorting, contrastive learning, future segment prediction, or multi-scale frequency domain reconstruction.

[0016] Furthermore, in step S5, segments that continuously exceed the risk threshold are merged into suspected leakage depth ranges, and combined with pressure anomalies, temperature changes, wellbore structure, historical maintenance records and operating status, the leakage type and warning level are output. The final warning score is given by the following formula: ; in, Indicates depth The overall risk score of the location This indicates the probability of segmented leakage. Indicates the continuity score between adjacent depths. This indicates an abnormal stress score. Indicates the score for temperature anomalies. , , , Indicates the corresponding weight; The leakage types include one or more of the following: tubing leakage, casing leakage, cement sheath bonding failure leakage, annular abnormal flow, or multi-barrier composite failure.

[0017] A wellbore ultrasonic leak detection and early warning system based on piecewise weakly supervised temporal representation learning, used to implement the above-mentioned wellbore ultrasonic leak detection and early warning method based on piecewise weakly supervised temporal representation learning, includes: The data acquisition module is used to receive background ultrasonic signals, target ultrasonic signals, and information related to wellbore operations, such as pressure, temperature, time, well section structure, or operational status, collected along the well depth. The data preprocessing module is used to perform denoising, normalization, depth alignment, window splitting, and gradient channel construction. The weak label construction module is used to generate weak supervision labels based on the amplitude ratio, amplitude difference, energy difference, or frequency band energy difference between the background window and the target window. The segmented sample generation module is used to combine multiple neighboring windows into segmented multi-instance samples according to a preset depth offset, and to assign bag-level labels to the segmented multi-instance samples. The temporal representation learning module is used to extract temporal representations of background windows, target windows, and single-window samples through a shared temporal encoder. The segmented discrimination module is used to perform background-target interaction, relation feature construction, deep embedding and hybrid multi-instance pooling to obtain segmented leakage risk probabilities. The early warning output module is used to output the suspected leakage depth range, leakage type, risk probability and early warning level based on the segmented leakage risk probability, adjacent depth continuity, pressure anomaly, temperature anomaly and wellbore structure information.

[0018] Furthermore, the shared temporal encoder in the temporal representation learning module includes a one-dimensional convolutional patch embedding layer and a temporal coding layer. The one-dimensional convolutional patch embedding layer is configured with a convolutional kernel length... and step length The input window is divided into multiple local patch tokens, and the temporal coding layer employs one of the following: a lightweight Transformer encoder, a linear attention encoder, a selective state-space encoder, a convolutional-attention hybrid encoder, or a self-supervised pre-trained temporal encoder.

[0019] As can be seen from the above technical solutions, compared with the prior art, the beneficial effects of the present invention are: 1. This invention treats the center depth and its adjacent depth windows as a single judgment unit (packet), and obtains segmented predicted values ​​through weighted fusion of max pooling and mean pooling. This aligns with the actual workflow of on-site engineers reviewing leakage evidence by depth interval. Compared to the traditional single-window independent judgment method, segmented multi-instance pooling can aggregate leakage evidence from multiple adjacent depth windows, effectively suppressing false alarms caused by isolated noise peaks, while enhancing the detection capability for weak but continuous leakage responses.

[0020] 2. This invention designs a background-target comparison branch, which uses a cross-attention interaction module to make the target window features focus on the corresponding background window features, and concatenates the interaction results, differences, element-wise products, and depth embedding to form relational features. This mechanism explicitly models the difference between the normal state and the state to be measured at the same depth, making the features extracted by the model insensitive to changes in absolute amplitude, thereby alleviating the model failure problem caused by inconsistent signal distribution under different well sections and operating conditions, and improving the model's generalization ability under different well conditions.

[0021] 3. This invention employs a shared temporal encoder to simultaneously extract temporal features from background windows, target windows, and single-window samples. It also provides additional supervision signals through a single-window auxiliary branch, enabling the model to learn high-quality temporal representations even with limited labeled data. A one-dimensional convolutional patch embedding layer converts temporal signals into local patch tokens, which, combined with the temporal encoder, capture long-range dependencies, enhancing the representation capabilities for local acoustic anomalies and overall temporal structure.

[0022] 4. This invention employs a five-component joint loss function for training, comprising segmented classification loss, window peak auxiliary loss, single-window auxiliary loss, consistency loss, and smoothing loss. The focus loss effectively addresses the imbalance between positive and negative samples, enhancing the model's learning ability for a few weak positive samples; the consistency loss ensures that segmented predictions and window-level average predictions remain consistent, strengthening the robustness of the predictions; the smoothing loss constrains the continuous change of predicted values ​​between adjacent depth windows, avoiding drastic jumps in prediction results along the depth direction, making the detection results more consistent with the physical continuity characteristics of the leakage response.

[0023] 5. The shared temporal encoder of this invention can be flexibly replaced with a lightweight Transformer encoder, a linear attention encoder, a selective state-space encoder, a convolutional-attention hybrid encoder, or a self-supervised pre-trained temporal encoder to adapt to different sequence lengths and deployment end computing power constraints. It also supports self-supervised pre-training using a large amount of unlabeled wellbore ultrasonic signals from the field. The pre-training task can be flexibly selected from one or more of the following: mask reconstruction, temporal segment sorting, contrastive learning, future segment prediction, or multi-scale frequency domain reconstruction, facilitating subsequent model upgrades and cross-well transfer applications.

[0024] 6. The suspected leak depth range, leak risk probability, leak type, and warning level output by this invention directly correspond to the actual needs of the engineering site. By merging segments that continuously exceed the risk threshold into a suspected leak depth range, and combining multi-source information such as pressure anomalies, temperature changes, and wellbore structure to comprehensively determine the warning level, this invention provides an output format that can directly guide engineering decisions for wellbore integrity evaluation and safety warning. Attached Figure Description

[0025] Figure 1 This is a flowchart illustrating the overall process of the ultrasonic leak detection and early warning method for wellbore of the present invention. Figure 2 This is a schematic diagram illustrating the segmented multi-example sample construction of the present invention; Figure 3 This is a schematic diagram of the shared temporal encoder and background-target comparison branch of the present invention; Figure 4 This is a detailed schematic diagram of the network structure of the segmented weakly supervised temporal representation learning model of the present invention; Figure 5 This is a schematic diagram of the module structure of the wellbore ultrasonic leak detection and early warning system of the present invention; Figure 6 This is a schematic diagram of the internal network structure of the shared timing encoder of the present invention. Detailed Implementation

[0026] To make the objectives, technical solutions, and advantages of this invention clearer, the invention will be further described in detail below with reference to the accompanying drawings and embodiments. The illustrative embodiments and descriptions of this invention are for illustrative purposes only and are not intended to limit the invention.

[0027] Example 1: Ultrasonic Leak Detection and Early Warning Method for Wellbore like Figure 1 As shown, this embodiment provides a wellbore ultrasonic leakage detection and early warning method based on piecewise weakly supervised temporal representation learning, including the following steps S1 to S5.

[0028] Step S1: Data Acquisition and Preprocessing S11. Prepare background well section data, target well section data, and single-window inspection data.

[0029] The wellbore inspection data includes at least ultrasonic signals collected along the well depth, and may further include pressure, temperature, acquisition time, logging speed, casing structure, well section type, and operating condition information. Background signals refer to ultrasonic signals collected under normal operating conditions in well sections with no leakage risk; target signals refer to ultrasonic signals collected in the well section to be inspected; single-window signals refer to independent window samples used for single-window auxiliary classification. Background windows and target windows are paired according to the same depth or the same wellbore structure location.

[0030] Taking an injection-production well in an underground gas storage facility as an example, ultrasonic signals were collected at 0.05m intervals from the wellhead to the bottom of the well, covering a depth range of 0~3000m, resulting in approximately 60,000 ultrasonic signal data points. Signals from known leak-free well sections (such as the wellhead section from 0~200m and the bottom section from 2800~3000m) were selected as background signals, while the intermediate well sections were used as target signals.

[0031] S12. Preprocess the raw ultrasonic signal.

[0032] The original ultrasonic signal undergoes outlier removal, bandpass filtering, wavelet denoising, or median filtering, and is aligned by depth or time to ensure the background window and target window correspond to the same depth or the same wellbore structure location. Specifically: Outlier removal: using The criterion will exceed the mean. Sampling points that exceed one standard deviation are considered outliers and are removed, and replaced with linear interpolation of adjacent sampling points. Bandpass filtering: Based on the characteristic frequency band of the wellbore ultrasonic leakage signal, the passband range is set to 5kHz~50kHz to filter out low-frequency environmental noise and high-frequency circuit noise; Align by depth: Ensure that the depth coordinates of the background window and the target window are consistent, with a depth alignment accuracy of no less than 0.01m.

[0033] S13. Normalize each window and construct feature channels.

[0034] For each window, normalization is performed, and features such as first-order gradient, local energy, band energy, or envelope are constructed. In this embodiment, each window consists of a normalized amplitude channel. With first-order gradient channel It consists of two parts, denoted as .

[0035] Window length Take 256 sampling points, and normalize the amplitude channel using the following formula: ; in, Indicates the first The original amplitude of each sampling point Represents the normalized i-th Each amplitude sampling point, , Indicates the window length. This represents the original amplitude sequence within the current window. This represents the maximum amplitude among all sampled points within the current window. This represents the minimum amplitude among all sampling points within the current window.

[0036] No. The first-order gradient channel of each sampling point is calculated using the following formula: ; for ,by Fill in the blanks.

[0037] Step S2: Weak Label Construction and Segmented Multi-Instance Sample Generation S21. Calculate the statistical difference between the background window and the target window.

[0038] For each pair of depth-matched background and target windows, their mean amplitudes are calculated separately, serving as the basis for constructing weak labels. For the background window, its mean amplitude... Calculate using the following formula: ; in, Indicates the background window Normalized amplitude of each sampling point Indicates the window length.

[0039] Similarly, the mean amplitude of the target window Calculate using the following formula: .

[0040] The amplitude ratio between the background and the target window and amplitude difference They are defined as follows: ; ; in, This represents the average amplitude of the background window. This represents the mean amplitude of the target window. To prevent the stability constant from having a denominator of zero, this embodiment takes... .

[0041] S22. Construct weak labels based on amplitude ratio and amplitude difference.

[0042] This embodiment employs a dual-threshold weak label construction strategy: When the amplitude ratio is not lower than the first threshold And the amplitude difference is not lower than the second threshold. When this happens, the sample is labeled as a weak positive sample (label). This indicates a suspected leak at that depth. When the amplitude ratio is within the preset stable range... And the absolute value of the amplitude difference does not exceed the third threshold. When, it is labeled as a weak negative sample (label) A value indicating a normal depth position is considered normal. Samples falling between these two values ​​are either discarded, downweighted, or used as unlabeled samples in semi-supervised training.

[0043] In this embodiment, the first threshold value was optimized through experiments. Take 1.12, the second threshold. Take 100 as the lower limit of the stable interval. Take 0.95 as the upper limit of the stable interval. Take 1.05, the third threshold Take 80.

[0044] The specific logic for determining weak tag construction is as follows: .

[0045] S23. Construct segmented multiple instance samples.

[0046] like Figure 2 As shown, at each center depth As the core, offset it upwards and downwards by a preset depth. Multiple windows at adjacent depths are selected to form a segmented multi-instance sample. The center depth is used as the reference point. Based on this, segmented multiple instance samples are denoted as: ; in, Indicates depth Segmented samples at the location, Indicates depth Window data at the location, This represents the depth offset. In this embodiment, The value is 2 meters. Each window is called an instance, and the entire segment of samples is called a bag. The bag's label is determined by the center depth. Weak label identification at: ; in, Represents segmented samples Package-level tags, Indicates center depth Weak labels at the location.

[0047] Step S3: Construct a wellbore ultrasonic leak detection network The wellbore ultrasonic leak detection network constructed in this step includes a shared temporal encoder, a single-window auxiliary branch, a background-target contrast branch, and a segmented multi-instance pooling module. For example... Figure 3 and Figure 4 As shown, the specific structure is as follows: S31. Construct a shared timing encoder.

[0048] The shared temporal encoder is used to perform unified temporal feature extraction on all windows (including background windows, target windows, and single-window samples), including a one-dimensional convolutional patch embedding layer and a temporal coding layer.

[0049] The one-dimensional convolutional patch embedding layer uses a convolutional kernel and stride to divide the input window into multiple local patch tokens. The calculation process is as follows: ; in, This represents the input window, and its dimensions are... (Amplitude channel and gradient channel); Indicates the kernel length, in this embodiment ; In this embodiment, the step size is indicated. ; Layer normalization; This represents one-dimensional convolution; Represents a patch token sequence, with dimension . ,in For the number of patches, , As an embedded dimension, in this embodiment .

[0050] The temporal coding layer is used to capture long-range temporal dependencies between patch tokens. In this embodiment, the temporal coding layer uses a lightweight Transformer encoder, whose core computation is a multi-head self-attention mechanism. ; ; in, This represents a multi-head self-attention function. Indicates a feedforward network; It represents the hidden state (feature tensor) inside the temporal coding layer (Transformer block), which is gradually updated as the data passes through the multi-head attention sublayer and the feedforward network sublayer. Initially, it represents the intermediate representation that incorporates global attention, and eventually it represents the deep semantic features of the window after complete temporal coding. It is the patch token sequence (i.e., the original input features) output from the previous stage, which is connected via a residual connection to prevent gradient vanishing and accelerate convergence.

[0051] As an alternative, when the sequence to be processed is long or the computing power at the deployment end is limited, the temporal coding layer can be replaced by a linear attention encoder or a selective state-space encoder; when a large amount of unlabeled wellbore signals are available, the temporal coding layer can use a self-supervised pre-trained temporal encoder for transfer initialization. Encoder output window embedding. (here) This is a general term; the following... and (For specific examples), its dimensions are .

[0052] S32. Construct a single-window auxiliary branch.

[0053] The single-window auxiliary branch feeds the target window separately into the shared timing encoder to obtain the window embedding. Then, the single-window anomaly probability is output via the classification header: ; in, This represents the window embedding obtained by a single window through a shared timing encoder. Indicates a fully connected layer. This represents the Sigmoid activation function. This represents the probability of an anomaly in a single window.

[0054] The single-window auxiliary branch provides additional supervision signals to guide the shared temporal encoder in learning discriminative window-level representations.

[0055] S33. Construct a background-target comparison branch.

[0056] The background-target comparison branch is one of the core components of this invention. It is used to explicitly model the differences between the normal state and the state to be measured at the same depth, thereby adapting to the changes in signal distribution under different well sections and working conditions.

[0057] Background window With target window The data are fed into a shared timing encoder to obtain their respective window embeddings. and All of their dimensions are .

[0058] Subsequently, using the cross-attention interaction module, the target window features are made to focus on the corresponding background window features. The cross-attention calculation is as follows: ; ; in, , , These are the core triples for attention computation, representing Query, Key, and Value, respectively. , , It is a learnable projection matrix.

[0059] The background-target contrast features are constructed by combining the interaction results, the differences between the two, element-wise multiplication, and deep embedding: ; in, Indicates contrasting features. This indicates that the background window is embedded. ⊙ indicates target window embedding, and ⊙ indicates element-wise multiplication (Hadamard product). This represents deep embedding (encoding depth locations as vectors through learnable embedding layers). This represents the cross-attention interaction function.

[0060] Contrast features After passing through a fully connected layer and a sigmoid activation function, the output is an instance-level leak prediction value: ; in, Indicates the first The predicted value for each window, Indicates the first Background-target contrast features of a deep instance This represents the Sigmoid activation function.

[0061] S34. Construct a segmented multi-instance pooling module.

[0062] For multiple windows within the same segment sample (three windows in this example, each corresponding to a depth), , , The background-target comparison branch will provide its predicted value separately. The segmented multi-instance pooling module combines max pooling and mean pooling by weighting coefficients. Weighted fusion yields the overall predicted value for this segment: ; in, Indicates the piecewise predicted value. Indicates the first The predicted value for each window, Indicates the number of windows within a segment. This represents the max-pooling weight. In this embodiment, Take 3. Take 0.65.

[0063] This hybrid pooling strategy takes into account both the "leakage can be determined by a single strong anomalous instance in the packet" (max pooling) and the "comprehensive evidence of multiple instances in the packet" (mean pooling), which is consistent with the actual workflow of on-site engineers reviewing leakage evidence by depth interval.

[0064] like Figure 4 As shown, the model processes multiple depth instances in parallel within a segmented sample. Each depth instance includes a background window and a target window, which are composed of a normalized magnitude channel and a gradient channel, respectively, and share the same temporal encoder to obtain window embedding. The background-target contrast branch outputs instance-level leakage prediction, the single-window auxiliary branch outputs target window anomaly prediction, and multiple instance-level predictions are processed by segmented multi-instance pooling to obtain segmented leakage prediction.

[0065] Step S4: Define the joint loss function and train the network. S41. Define the joint loss function.

[0066] The total training loss is a weighted combination of segment classification loss, window peak auxiliary loss, single window auxiliary loss, consistency loss between segment prediction and window prediction, and smoothing loss of depth-adjacent windows.

[0067] Joint training objective for the model: ; in, Describes the joint training objective function. This represents the segmented classification loss. This represents the window peak auxiliary loss (used to supervise the maximum value in window prediction). Indicates single-window auxiliary loss. Indicates consistency loss. Indicates smoothing loss. , , , This represents the weighting coefficient for each loss; in this embodiment, we take... , , , .

[0068] S42. Define the specific form of each loss.

[0069] Segmented Classification of Losses With single-window auxiliary loss Focal loss is employed to improve the model's ability to learn from a few weak positive samples, thus mitigating the imbalance between positive and negative samples. ; in, Represents the focus loss function. Indicates the predicted probability. Indicates a weak label. This represents the class weights (used to balance positive and negative samples, in this embodiment) ), Indicates the hard sample adjustment factor (in this embodiment) ).

[0070] Segmented Classification of Losses segmented predicted values and package-level tags As input; single-window auxiliary loss single-window predicted values and center depth weak label As input.

[0071] Window peak auxiliary loss Defined as the binary cross-entropy loss between the maximum window prediction within a segment and the packet-level label: ; Consistency loss Constraints to maintain consistency between piecewise forecasts and window-level average forecasts are defined as the mean squared error between the two: ; in, This represents the mean square error function. This represents the segmented predicted values. Indicates the first The predicted value for each window, This indicates the number of windows within a segment.

[0072] Smoothing loss The constraint that the predicted values ​​of adjacent depth windows change continuously is defined as: ; This loss makes the detection results more consistent with the physical continuity of the leak response, avoiding drastic jumps in the prediction results in the depth direction.

[0073] S43, Network Training.

[0074] Before or during training, self-supervised pre-training can be performed using a large amount of unlabeled wellbore ultrasonic signals from the field. The pre-training task can be flexibly selected based on the data, including one or more of the following: Masked Reconstruction (randomly masking and reconstructing temporal segments), Temporal Shuffle Sorting (predicting the original order after shuffling segments), Contrastive Learning (comparing positive and negative sample pairs), Future Prediction (predicting future segments based on historical segments), or Multi-scale Frequency Reconstruction (reconstructing in the frequency domain). In this embodiment, Masked Reconstruction is used as the pre-training task.

[0075] The model was trained using the AdamW optimizer, with an initial learning rate set to... The batch size was set to 32, the number of training epochs was set to 100, and early stopping was used to prevent overfitting.

[0076] In this embodiment, ablation experiments were also conducted to verify the network parameters and hyperparameters during the training process, and the results are shown in Table 1: Table 1 Ablation Experimental Validation Results

[0077] The above ablation experiment results show that each component of the five-component joint loss function contributes positively to the final detection performance, and the complete model achieves optimal performance.

[0078] Step S5: Model Application and Early Warning Output S51. Preprocess the wellbore signal to be measured according to step S1 and input it into the trained model to obtain the window-level leakage probability. and segmented leakage probability .

[0079] For segments that continuously exceed the risk threshold (set to 0.5 in this embodiment, but adjustable according to on-site requirements), they are merged into a suspected leak depth range. Specifically, if the depth... Segment-level predicted values If a segment is identified as a suspected leak, then that segment is classified as such; consecutive depth segments classified as suspected leaks are merged into a single continuous suspected leak depth interval. .

[0080] S52. Output the leakage type and early warning level based on comprehensive multi-source information.

[0081] By combining abnormal pressure, temperature changes, wellbore structure, historical maintenance records, and operational status, the type of leakage is determined and an early warning level is given.

[0082] The warning levels are divided into three levels: low risk ( ), medium risk ( High risk ).

[0083] Leakage types can include pipeline leaks ( And located in the tubing section), casing leakage ( And located in the casing section), cement ring bonding failure and leakage ( The leakage type is determined by a comprehensive inference based on factors such as the location of the cement-sealed section, abnormal annular flow, and multiple barrier failures, with several of these factors potentially existing simultaneously on-site. These factors include segmental leakage probabilities, wellbore structural information, and historical maintenance records.

[0084] The final warning score is given by the following formula: ; in, Indicates depth The overall risk score of the location This indicates the probability of segmented leakage. This represents the continuity score between adjacent depths (obtained by calculating the consistency of predicted values ​​between adjacent depths). This represents the pressure anomaly score (a normalized score of 0 to 1 converted from annular pressure monitoring data). This represents the temperature anomaly score (a normalized score of 0 to 1 converted from temperature monitoring data). , , , This represents the corresponding weight; in this embodiment, we take... , , , .

[0085] Example 2: Wellbore Ultrasonic Leak Detection and Early Warning System like Figure 5 As shown, this invention also provides a wellbore ultrasonic leak detection and early warning system based on piecewise weakly supervised temporal representation learning, for implementing the above method. The system includes the following modules: Data acquisition module: This module receives background ultrasonic signals and target ultrasonic signals collected along the well depth, as well as pressure, temperature, time, well section structure, or operational status information related to wellbore operations. It supports importing various data formats, including field logging data, historical database data, and real-time monitoring data streams.

[0086] The data preprocessing module performs denoising, normalization, depth alignment, window segmentation, and gradient channel construction. Specifically, this module removes outliers, performs bandpass filtering and wavelet denoising on the raw ultrasound signal, aligns the background window with the target window according to the depth coordinates, segments each window into 256 sampling points, and constructs a normalized amplitude channel and a first-order gradient channel.

[0087] The weak label construction module generates weak supervision labels based on the amplitude ratio, amplitude difference, energy difference, or frequency band energy difference between the background window and the target window. This module employs a dual-threshold mechanism, labeling samples as weak positive samples, weak negative samples, or removing / downweighting them based on the comparison results of the amplitude ratio and amplitude difference with preset thresholds. Each threshold parameter supports manual setting and adaptive adjustment.

[0088] Segmented Sample Generation Module: Used to group multiple neighboring windows into segmented multi-example samples according to a preset depth offset, and to assign packet-level labels to the segmented multi-example samples. In this embodiment, each center depth is used as the basis for the generation module. With the core as the center, offset 2m above and below it, select 3 adjacent windows to form a segmented multi-example sample, and the packet-level label is determined by the weak label at the center depth.

[0089] Temporal representation learning module: Used to extract temporal representations of background window, target window, and single-window samples through a shared temporal encoder. For example... Figure 6 As shown, the shared temporal encoder includes a one-dimensional convolutional patch embedding layer and a temporal coding layer. The one-dimensional convolutional patch embedding layer uses the convolutional kernel length... and step length The input window is divided into multiple local patch tokens; the temporal coding layer uses a lightweight Transformer encoder, which includes a multi-head self-attention mechanism and a feedforward network, and the output window is embedded.

[0090] As an alternative, the temporal coding layer may employ one of the following: a linear attention encoder, a selective state space encoder (such as Mamba), a convolution-attention hybrid encoder, or a self-supervised pre-trained temporal encoder.

[0091] Segmentation discrimination module: Used to perform background-target interaction, relation feature construction, deep embedding, and hybrid multi-instance pooling to obtain segment-level leakage risk probabilities. Background-target contrast features Construct it according to the following formula: ; in, Indicates that the target window is embedded. The symbol ⊙ indicates an embedded background window, and ⊙ indicates an element-wise product (Hadamard product). This represents deep embedding (encoding depth locations as vectors through learnable embedding layers). This represents the cross-attention interaction function.

[0092] Segmented predicted values Calculate using the following formula: ; in, Indicates the first The predicted value for each window, Indicates the number of windows within a segment. This represents the max-pooling weight. In this embodiment, Take 3. Take 0.65.

[0093] Early warning output module: Based on segmented leakage risk probability, continuity of adjacent depths, pressure anomalies, temperature anomalies, and wellbore structural information, this module outputs the suspected leakage depth range, leakage type, risk probability, and early warning level. The output results can be provided to the wellbore integrity assessment system or field engineers in the form of tables, curves, depth range lists, or alarm messages.

[0094] Example 3: Electronic Equipment This embodiment also provides an electronic device, including a processor and a memory. The memory stores a computer program executable by the processor, which, when executed by the processor, implements the above-described wellbore ultrasonic leak detection and early warning method based on piecewise weakly supervised temporal representation learning.

[0095] Specifically, the electronic device may be an industrial computer, a server, an embedded industrial control computer, or a cloud computing device. The processor may employ one or more combinations of CPU, GPU, NPU, or FPGA.

[0096] Example 4: Computer-readable storage medium This embodiment also provides a computer-readable storage medium on which a computer program is stored. When the program is executed by a processor, it implements the steps of the above-described wellbore ultrasonic leakage detection and early warning method based on piecewise weakly supervised temporal representation learning.

[0097] The computer-readable storage medium may be a non-volatile storage medium such as ROM, RAM, disk, optical disk, USB flash drive, or SD card.

[0098] The above-described embodiments are merely preferred embodiments of the present invention and are not intended to limit the scope of the present invention. Various modifications and improvements made by those skilled in the art to the technical solutions of the present invention without departing from the spirit of the present invention should fall within the protection scope defined by the claims of the present invention.

Claims

1. A wellbore ultrasonic leakage detection and early warning method based on piecewise weakly supervised temporal representation learning, characterized in that, Includes the following steps: S1. Acquire ultrasonic testing data of the wellbore and preprocess it to obtain the processed background signal, target signal and single-window signal; S2. Construct weak labels based on the amplitude ratio and amplitude difference between the background signal and the target signal, and form segmented multi-example samples with multiple windows at each center depth and its neighboring depths. S3. Construct a wellbore ultrasonic leak detection network, which includes a shared time encoder, a single-window auxiliary branch, a background-target comparison branch, and a segmented multi-instance pooling module; S4. Define a joint loss function and train the network. The joint loss function includes segmented classification loss, window peak auxiliary loss, single window auxiliary loss, consistency loss, and smoothing loss. S5. Apply the trained model to the wellbore data to be tested, and output the suspected leakage depth range, leakage risk probability, leakage type and warning level.

2. The wellbore ultrasonic leakage detection and early warning method based on piecewise weakly supervised temporal representation learning according to claim 1, characterized in that, In step S1, outlier removal, bandpass filtering, wavelet denoising or median filtering are performed on the original ultrasonic signal, and alignment is performed according to depth or time so that the background window and the target window correspond to the same depth or the same well structure position. Normalize each window and construct a first-order gradient channel. Each window includes at least a normalized magnitude channel and a first-order gradient channel. No. The first-order gradient channel of each sampling point is calculated using the following formula: ; in, Represents the normalized i-th Each amplitude sampling point, This represents the corresponding first-order gradient value. , Indicates the window length.

3. The wellbore ultrasonic leakage detection and early warning method based on piecewise weakly supervised temporal representation learning according to claim 1, characterized in that, In step S2, for each pair of depth-matched background and target windows, the mean amplitude is calculated, and the amplitude ratio and amplitude difference are calculated accordingly. ; ; in, Indicates the amplitude ratio. Indicates the amplitude difference. This represents the average amplitude of the background window. This represents the mean amplitude of the target window. To prevent the stability constant from having a denominator of zero; When the amplitude ratio is not lower than the first threshold and the amplitude difference is not lower than the second threshold, the sample is marked as a weak positive sample; when the amplitude ratio is within the preset stable range and the absolute value of the amplitude difference does not exceed the third threshold, it is marked as a weak negative sample; samples between the two are removed, downweighted, or used as unlabeled samples for semi-supervised training.

4. The wellbore ultrasonic leakage detection and early warning method based on piecewise weakly supervised temporal representation learning according to claim 1, characterized in that, In step S2, at each center depth As the core, offset it upwards and downwards by a preset depth. Multiple windows at adjacent depths are selected to form a segmented multi-instance sample, denoted as: ; in, Indicates depth Segmented samples at the location, Indicates depth Window data at the location, This represents the depth offset; each window is called an instance, and the entire segment of samples is called a bag, with the bag's label determined by its center depth. Weak labels were identified at the location.

5. The wellbore ultrasonic leakage detection and early warning method based on piecewise weakly supervised temporal representation learning according to claim 1, characterized in that, In step S3, the shared temporal encoder includes a one-dimensional convolutional patch embedding layer and a temporal coding layer; The calculation process for one-dimensional convolutional patch embedding is as follows: ; in, This indicates the input window. Indicates the kernel length. Indicates the step size. Representation layer normalization, Represents one-dimensional convolution. Indicates the sequence of patch tokens; The temporal coding layer employs one of the following: a lightweight Transformer encoder, a linear attention encoder, a selective state-space encoder, a convolutional-attention hybrid encoder, or a self-supervised pre-trained temporal encoder.

6. The wellbore ultrasonic leakage detection and early warning method based on piecewise weakly supervised temporal representation learning according to claim 5, characterized in that, The background-target contrast branch inputs the background window and the target window into the shared temporal encoder respectively to obtain the background window embedding. Embedded with target window The cross-attention interaction module makes the target window features focus on the background window features, and the interaction results, the differences between the two, the element-wise product, and the deep embedding are concatenated to form the background-target contrast features: ; in, This indicates that the background window is embedded. The symbol ⊙ indicates target window embedding, and ⊙ indicates element-wise multiplication. Indicates deep embedding, Represents the cross-attention interaction function; The segmented multi-instance pooling module combines max pooling and mean pooling according to weight coefficients. Weighted fusion yields segmented predicted values: ; in, Indicates the piecewise predicted value. Indicates the first The predicted value for each window, Indicates the number of windows within a segment. This represents the maximum pooling weight.

7. The wellbore ultrasonic leakage detection and early warning method based on piecewise weakly supervised temporal representation learning according to claim 1, characterized in that, In step S4, the joint loss function is expressed as: ; in, Denotes the joint loss function. This represents the segmented classification loss. Indicates the peak auxiliary loss of the window. Indicates single-window auxiliary loss. Indicates consistency loss. Indicates smoothing loss. , , , Represents the weighting coefficients for each loss; The segmented classification loss and single-window auxiliary loss both employ focus loss. ; in, Represents the focus loss function. Indicates the predicted probability. Indicates a weak label. Indicates category weight, Indicates the adjustment factor for difficult samples; The consistency loss and smoothing loss are respectively defined as: ; ; in, Indicates consistency loss. Indicates smoothing loss. This represents the mean square error function. This represents the segmented predicted values. Indicates the first The predicted value for each window, This indicates the number of windows within a segment.

8. The wellbore ultrasonic leakage detection and early warning method based on piecewise weakly supervised temporal representation learning according to claim 1, characterized in that, In step S5, segments that continuously exceed the risk threshold are merged into suspected leakage depth ranges, and combined with pressure anomalies, temperature changes, wellbore structure, historical maintenance records and operating status, the leakage type and warning level are output. The final warning score is given by the following formula: ; in, Indicates depth The overall risk score of the location This indicates the probability of segmented leakage. Indicates the continuity score between adjacent depths. This indicates an abnormal stress score. Indicates the score for temperature anomalies. , , , Indicates the corresponding weight; The leakage types include one or more of the following: tubing leakage, casing leakage, cement sheath bonding failure leakage, annular abnormal flow, or multi-barrier composite failure.

9. A wellbore ultrasonic leak detection and early warning system based on piecewise weakly supervised temporal representation learning, used to implement the wellbore ultrasonic leak detection and early warning method based on piecewise weakly supervised temporal representation learning as described in any one of claims 1-8, characterized in that, include: The data acquisition module is used to receive background ultrasonic signals, target ultrasonic signals, and information related to wellbore operations, such as pressure, temperature, time, well section structure, or operational status, collected along the well depth. The data preprocessing module is used to perform denoising, normalization, depth alignment, window splitting, and gradient channel construction. The weak label construction module is used to generate weak supervision labels based on the amplitude ratio, amplitude difference, energy difference, or frequency band energy difference between the background window and the target window. The segmented sample generation module is used to combine multiple neighboring windows into segmented multi-instance samples according to a preset depth offset, and to assign bag-level labels to the segmented multi-instance samples. The temporal representation learning module is used to extract temporal representations of background windows, target windows, and single-window samples through a shared temporal encoder. The segmented discrimination module is used to perform background-target interaction, relation feature construction, deep embedding and hybrid multi-instance pooling to obtain segmented leakage risk probabilities. The early warning output module is used to output the suspected leakage depth range, leakage type, risk probability and early warning level based on the segmented leakage risk probability, adjacent depth continuity, pressure anomaly, temperature anomaly and wellbore structure information.

10. The wellbore ultrasonic leakage detection and early warning system based on piecewise weakly supervised temporal representation learning according to claim 9, characterized in that, The shared temporal encoder in the temporal representation learning module includes a one-dimensional convolutional patch embedding layer and a temporal coding layer. The one-dimensional convolutional patch embedding layer is configured with a convolutional kernel length of [missing information]. and step length The input window is divided into multiple local patch tokens, and the temporal coding layer employs one of the following: a lightweight Transformer encoder, a linear attention encoder, a selective state-space encoder, a convolutional-attention hybrid encoder, or a self-supervised pre-trained temporal encoder.