Terahertz defect identification and symbolization deployment method based on physical constraint kan
Patent Information
- Application Number
- CN202611059630.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-07-16
- Publication Date
- 2026-08-18
AI Technical Summary
[0003]现有技术中,对于太赫兹缺陷识别与符号化部署方法,普遍存在数据采集与预处理训练环节脱节、需依赖第三方软件完成数据中转,未将太赫兹探测器的条纹噪声、增益漂移、相干干涉等物理退化机制显式融入数据增强与模型约束,主流深度学习检测模型多为黑盒结构、参数量庞大且缺乏可解释的符号化转换路径,同时分类判定多依赖固定阈值、多部署引擎下的推理数值一致性缺乏统一管控的缺陷,影响了太赫兹缺陷识别模型的真实工况泛化精度、边缘端部署的轻量化水平与适配性,也难以满足工业无损检测场景对模型可解释性、跨平台结果一致性的应用要求
Smart Images

Figure CN122597400A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of image analysis technology, specifically to a method for terahertz defect identification and symbolic deployment based on physically constrained KAN. Background Technology
[0002] The terahertz defect identification and symbolic deployment method transforms the complex physical signals obtained from terahertz detection into a quantifiable and transferable standardized defect characterization system, significantly improving the objectivity, consistency, and automation level of defect identification. At the same time, it facilitates rapid migration and reuse across different devices, platforms, and scenarios, providing efficient, reliable, and interpretable intelligent detection support for fields such as industrial quality inspection and material evaluation.
[0003] In existing technologies, terahertz defect identification and symbolic deployment methods generally suffer from several drawbacks. These include a disconnect between data acquisition and preprocessing training, reliance on third-party software for data transfer, and a failure to explicitly incorporate physical degradation mechanisms of terahertz detectors, such as stripe noise, gain drift, and coherent interference, into data augmentation and model constraints. Mainstream deep learning detection models are often black-box structures with a large number of parameters and lack interpretable symbolic conversion paths. Furthermore, classification decisions often rely on fixed thresholds, and there is a lack of unified control over the consistency of inference values across multiple deployment engines. These shortcomings affect the real-world generalization accuracy of terahertz defect identification models, the lightweight nature and adaptability of edge deployment, and the difficulty in meeting the application requirements of industrial non-destructive testing scenarios for model interpretability and cross-platform result consistency.
[0004] Based on this, the present invention provides a method for terahertz defect identification and symbolic deployment based on physical constraint KAN. Summary of the Invention
[0005] The main objective of this invention is to provide a terahertz defect identification and symbolic deployment method based on physically constrained KANs, in order to solve the problems mentioned in the background above.
[0006] To achieve the above objectives, the present invention provides the following technical solution:
[0007] A terahertz defect identification and symbolic deployment method based on physically constrained KANs includes the following steps:
[0008] S1. Terahertz Image Acquisition, Preprocessing, and Dataset Construction: Directly connect to the terahertz array detector, call the native application programming interface to read the raw floating-point image frames, and sequentially perform differential correction, spatial filtering, and grayscale transformation processing to generate standardized images and store them according to labels to construct the training dataset.
[0009] S2. Terahertz Image Physically Constrained Data Augmentation: For the nine types of physical degradation mechanisms of terahertz detectors, a probabilistic configurable augmentation strategy is constructed. Augmentation is applied randomly to the training set samples in a fixed order, while no augmentation is applied to the validation set and test set.
[0010] S3, KAN Defect Classification Model Training and Optimal Threshold Calibration: Construct a KAN based on the B-spline activation function, input the enhanced training set into the network for supervised training, iteratively update the network parameters using K-fold hierarchical cross-validation, and search for the optimal classification threshold based on the validation set with the maximization of the Youden exponent as the criterion and save it with the model.
[0011] KAN stands for Kolmogorov-Arnold Network, a neural network structure built on the Kolmogorov-Arnold representation theorem, using B-spline functions as learnable edge activation functions.
[0012] S4. KAN Model Multi-Template Symbolization and Threshold Recalibration: Traverse the B-spline activation function of each edge of the trained KAN, use multiple physical and mathematical templates for least squares fitting, filter qualified edges and prune unqualified edges through adaptive mean square error threshold, and generate a structured symbolic configuration file.
[0013] After symbolization is completed, K-fold threshold calibration is re-executed, and the recalibrated optimal classification threshold is written to the configuration file;
[0014] S5, Multi-engine Consistent Inference Deployment Architecture Construction: Construct four types of inference engines: deep learning engine, numerical computation engine, standard mathematical library engine, and embedded simulation engine. The four types of engines follow unified input preprocessing rules, numerical truncation rules, and floating-point precision standards.
[0015] Preferably, step S1 specifically includes:
[0016] Connect directly to the Terasense series 64×64 pixel terahertz array detector via USB cable and call the native application programming interface to read raw floating-point image frames.
[0017] Three types of parameters are configured through the device control module: exposure index, cumulative frame count, and bad pixel threshold.
[0018] Differential correction supports three differential modes: off, on, and calibration file. In on mode, the first defect-free image after acquisition starts is used as the reference frame to perform pixel-by-pixel differential operation. In calibration file mode, a pre-recorded background calibration file is loaded to perform background compensation.
[0019] Spatial filtering is performed in a fixed order through three levels of processing: 3×3 kernel median filtering, Gaussian blurring with adjustable standard deviation, and bilateral filtering with adjustable spatial domain parameters.
[0020] The grayscale transformation is performed in a fixed order with three levels of processing: linear transformation of contrast and brightness, non-linear correction of Gamma, and sharpening with adjustable intensity.
[0021] The dataset uses a four-folder structured storage structure, with the four folders corresponding to normal samples in the training set, defective samples in the training set, normal samples in the test set, and defective samples in the test set, respectively.
[0022] Preferably, in step S2, the enhancement operators corresponding to the nine types of physical degradation mechanisms are applied sequentially according to the terahertz imaging degradation chain, in the following order: geometric transformation, non-uniformity residual, thermal drift, fringe noise, coherent interference, gain drift, readout noise, electronic noise, and bad pixel injection; after all enhancements are applied, the image pixel values are cropped to the [0,1] interval.
[0023] The probability of occurrence of each type of enhancement operator can be adjusted independently, with an adjustment range of 0% to 100%.
[0024] Preferably, in step S2, the parameter range for each type of enhancement operator is as follows:
[0025] The frequency range of the stripe noise is 0.5 to 2.5, the amplitude range is 0.005 to 0.03, and the direction supports four modes: X direction, Y direction, XY bidirectional, and random.
[0026] The gain coefficient for gain drift ranges from 0.98 to 1.02;
[0027] The electronic noise is additive Gaussian noise with a sigma range of 0.003 to 0.012.
[0028] The rotation angle range of geometric transformations is -5° to +5°, and it supports horizontal and vertical flipping.
[0029] The percentage of bad pixels injected ranges from 0.1% to 1%, and the mode supports three modes: zeroing, saturation, and random.
[0030] The standard deviation of gain for non-uniform residuals is 0.02, and the standard deviation of offset is 0.01.
[0031] The baseline amplitude of thermal drift is 0.02;
[0032] The frequency range of the coherent interference is 0.1 to 0.5, and the amplitude range is 0.005 to 0.02.
[0033] The readout noise is a Poisson-Gaussian mixture, with a 1:1 ratio of amplitude weighting between the Poisson and Gaussian noise components.
[0034] Preferably, in step S3, the input to KAN is a flattened 64×64 pixel terahertz image vector, and the input vector is input to the hidden layer after PCA dimensionality reduction.
[0035] The PCA dimensionality reduction dimension can be adjusted from 16 to 256, and the number of hidden layer nodes can be adjusted from 8 to 256.
[0036] Each connection edge of the network is equipped with a learnable B-spline activation function, and the hidden layer nodes perform a linear summation on the activation results of all input edges;
[0037] The grid number of B-splines is adjustable from 2 to 20, and the order is adjustable from 2 to 5.
[0038] The network parameters are initialized using a physical heuristic method, and a Gaussian perturbation with a mean of 0 and a standard deviation of 0.01 is applied to the coefficients of all B-spline basis functions.
[0039] Preferably, in step S3, the number of folds in the K-fold stratified cross-validation can be adjusted from 2 to 10.
[0040] K-fold random partitioning is performed independently on normal samples and defective samples respectively. Then, the normal samples and defective samples in the corresponding fold are merged to form the training subset and validation subset of the fold, ensuring that the ratio of the two classes of samples in each fold is consistent with the sample ratio of the entire dataset.
[0041] The training process uses the Adam optimizer, which supports switching between two loss functions: binary cross-entropy loss and mean squared error loss.
[0042] The learning rate scheduling employs a decay strategy based on validation set loss, with a decay factor of 0.5, a patience value of 10 rounds, and a minimum learning rate of 1×10. -6 ;
[0043] L2 norm gradient clipping was used with a clipping threshold of 10.0.
[0044] Preferably, in step S3, the search process for the optimal classification threshold is as follows:
[0045] Within the model output probability range of the validation set, exhaustively search all candidate thresholds in the range of 0.01 to 0.99 with a step size of 0.01.
[0046] For each candidate threshold, calculate the corresponding true positive rate and true negative rate, and calculate the Youden index using the formula J=TPR+TNR-1;
[0047] The threshold corresponding to the maximum value of the Youden index is selected as the optimal classification threshold for the model, and saved together with the network weight parameters to the model file.
[0048] Preferably, in step S4, the various physical mathematical templates are exponential function template, sine function template, cubic polynomial template, Gaussian function template, and damped oscillation function template.
[0049] The fitting process uniformly samples 200 to 500 sample points within the input interval [-1,1]. The Levenberg-Marquardt nonlinear least squares method is used to fit the parameters of the five types of templates respectively. The template with the smallest fitting residual is selected as the final symbolic expression of the edge.
[0050] Preferably, in step S4, the adaptive mean square error threshold is obtained by multiplying the threshold coefficient by the larger of the signal variance output by the side activation function and 0.01;
[0051] Edges with fitting residuals below a threshold are considered qualified edges, and their corresponding mathematical expressions and template parameters are retained.
[0052] Edges with fitting residuals higher than a threshold are considered unqualified edges, and pruning is performed with a pruning log recorded.
[0053] For output standard deviation less than 1×10 -8 The constant edges are directly recorded as constant functions;
[0054] The symbolic configuration file is in JSON structured format, containing two parts: statistical metadata and node formula parameter array. The statistical metadata includes classification threshold, input standardized mean vector, input standard deviation vector, PCA transformation matrix, input dimension, and number of hidden layer nodes.
[0055] Preferably, in step S5, the reasoning logic of the four types of reasoning engines are as follows:
[0056] The deep learning engine loads the original KAN model weight file, performs forward inference based on the deep learning framework, and outputs the classification probability through the Sigmoid function.
[0057] The numerical computation engine loads the symbolic configuration file, calls the general numerical computation library to perform formula calculations according to the network level, and outputs the classification probability.
[0058] The standard math library engine relies on the standard math library that comes with the programming language to perform formula calculations and performs input limiting on exponential and sine operations;
[0059] The embedded simulation engine performs 32-bit single-precision floating-point truncation and layer-by-layer numerical overflow protection in the host computer environment, reproducing the operation logic after the embedded C language is ported.
[0060] All inference engines uniformly implement the following numerical protection rules: hard truncation of input features is performed in the range of [-1,1], the input log probability of the Sigmoid function is limited to the range of [-50,50], and all floating-point operations adopt the 32-bit single-precision floating-point standard.
[0061] The present invention has the following beneficial effects:
[0062] 1. This invention constructs a complete technical solution that sequentially connects terahertz image acquisition and preprocessing with dataset construction, physically constrained data augmentation, KAN defect classification model training and optimal threshold calibration, KAN model multi-template symbolization and threshold recalibration, and multi-engine consistent inference deployment. This achieves an end-to-end defect identification closed loop from direct hardware connection to terahertz array detectors to edge-end white-box deployment. Compared with existing technologies, this invention improves the coherence of data acquisition and model training processes, the adaptability of models to the physical characteristics of terahertz imaging, and the compatibility of deployment schemes with different operating environments. Therefore, it can solve the problems in existing technologies such as the disconnect between image acquisition and preprocessing, the lack of integration of deep learning models with the physical degradation mechanism of terahertz imaging, and the difficulty of black-box models meeting the interpretability requirements of edge-end deployment.
[0063] 2. This invention constructs a probabilistically configurable enhancement strategy targeting nine types of physical degradation mechanisms of terahertz detectors. It applies enhancement processing to training set samples according to the imaging degradation link sequence. At the same time, it combines K-fold hierarchical cross-validation and the optimal threshold calibration method that maximizes the Youden exponent to achieve accurate matching between the training data distribution and the degradation characteristics of real working conditions. Compared with the prior art, it can improve the model's generalization ability in real detection scenarios and the comprehensive discrimination performance of defect classification. Therefore, it can solve the problem of domain shift caused by the lack of physical basis for data augmentation in the prior art and the problem that fixed threshold classification cannot take into account both defect detection rate and normal sample specificity.
[0064] 3. This invention utilizes a KAN model symbolization method based on least squares fitting of multiple physical and mathematical templates and adaptive mean square error threshold pruning to generate structured symbolic configuration files and complete classification threshold recalibration. Simultaneously, it constructs a four-class inference engine architecture that follows unified input preprocessing, numerical truncation, and floating-point precision rules, achieving white-box mathematical expression of the model and numerical consistency across deployment environments. Compared with existing technologies, this reduces hardware dependence on edge deployments and model storage volume, and improves the consistency and interpretability of output results in different inference environments. Therefore, it can solve the problems in existing technologies such as the difficulty in lightweight deployment of deep learning models relying on dedicated frameworks, insufficient interpretability due to the lack of model symbolization mechanisms, and uncontrollable biases in inference results across multiple deployment environments. Attached Figure Description
[0065] Figure 1 This is a schematic diagram of the method flow of the present invention;
[0066] Figure 2 This is a schematic diagram of the terahertz image acquisition preprocessing and dataset construction process of the present invention;
[0067] Figure 3 This is a schematic diagram of the training and optimal threshold calibration process of the KAN defect classification model of the present invention. Detailed Implementation
[0068] To enable those skilled in the art to better understand the present invention, the technical solutions of the present invention will be clearly and completely described below with reference to the accompanying drawings of the embodiments of the present invention. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.
[0069] In this document, the term "embodiment" means that a particular feature, structure, or characteristic described in connection with an embodiment may be included in at least one embodiment of the invention. The appearance of this phrase in various places throughout the specification does not necessarily refer to the same embodiment, nor is it a mutually exclusive, independent, or alternative embodiment. It will be explicitly and implicitly understood by those skilled in the art that the embodiments described herein can be combined with other embodiments.
[0070] Example 1, please refer to Figure 1 and Figure 2 As shown, this embodiment provides a terahertz defect identification and symbolic deployment method based on physically constrained KANs, including the following steps:
[0071] S1. Terahertz Image Acquisition, Preprocessing, and Dataset Construction: Directly connect to the terahertz array detector, call the native application programming interface to read the raw floating-point image frames, and sequentially perform differential correction, spatial filtering, and grayscale transformation processing to generate standardized images and store them according to labels to construct the training dataset.
[0072] Step S1 specifically includes:
[0073] Connect directly to the Terasense series 64×64 pixel terahertz array detector via USB cable and call the native application programming interface to read raw floating-point image frames.
[0074] Three types of parameters are configured through the device control module: exposure index, cumulative frame count, and bad pixel threshold.
[0075] Differential correction supports three differential modes: off, on, and calibration file. In on mode, the first defect-free image after acquisition starts is used as the reference frame to perform pixel-by-pixel differential operation. In calibration file mode, a pre-recorded background calibration file is loaded to perform background compensation.
[0076] Spatial filtering is performed in a fixed order through three levels of processing: 3×3 kernel median filtering, Gaussian blurring with adjustable standard deviation, and bilateral filtering with adjustable spatial domain parameters.
[0077] The grayscale transformation is performed in a fixed order with three levels of processing: linear transformation of contrast and brightness, non-linear correction of Gamma, and sharpening with adjustable intensity.
[0078] The dataset uses a four-folder structured storage structure, with the four folders corresponding to normal samples in the training set, defective samples in the training set, normal samples in the test set, and defective samples in the test set, respectively.
[0079] Furthermore, the device control module implements parameter configuration and frame data reading through the application programming interface of the detector's native driver, eliminating the need for third-party acquisition software. The entire process of a single frame image is completed within a 33-millisecond cycle, meeting the requirements for real-time acquisition and processing. The entire process of a single frame image includes differential processing, filtering, grayscale transformation, and pseudo-color mapping.
[0080] The exposure index is adjustable from 0 to 10, corresponding to a detector output frame rate of approximately 6 to 90 fps; the cumulative frame count is adjustable from 1 to 100, used to stack multiple frames to improve image quality in low signal-to-noise ratio scenarios; the bad pixel threshold is adjustable from 0.0 to 100.0, used to automatically mark and filter detector-failed pixels. When saving images, both the original floating-point array file and the preview image file are output simultaneously. The preview image is generated using pseudo-color mapping for quick visual verification of sample quality. The dataset file name includes a collection timestamp and label identifier, allowing direct differentiation of sample categories and collection times via filename.
[0081] Example 2, please refer to Figure 1 As shown, this embodiment provides a terahertz defect identification and symbolic deployment method based on physically constrained KANs, including the following steps:
[0082] S2. Terahertz Image Physically Constrained Data Augmentation: For the nine types of physical degradation mechanisms of terahertz detectors, a probabilistic configurable augmentation strategy is constructed. Augmentation is applied randomly to the training set samples in a fixed order, while no augmentation is applied to the validation set and test set.
[0083] In step S2, the enhancement operators corresponding to the nine types of physical degradation mechanisms are applied sequentially according to the terahertz imaging degradation chain, in the following order: geometric transformation, non-uniformity residual, thermal drift, fringe noise, coherent interference, gain drift, readout noise, electronic noise, and bad pixel injection; after all enhancements are applied, the image pixel values are cropped to the [0,1] interval.
[0084] The probability of occurrence of each type of enhancement operator can be adjusted independently, with an adjustment range of 0% to 100%.
[0085] The parameter ranges for each type of enhancement operator are as follows:
[0086] The frequency range of the stripe noise is 0.5 to 2.5, the amplitude range is 0.005 to 0.03, and the direction supports four modes: X direction, Y direction, XY bidirectional, and random.
[0087] The gain coefficient for gain drift ranges from 0.98 to 1.02;
[0088] The electronic noise is additive Gaussian noise with a sigma range of 0.003 to 0.012.
[0089] The rotation angle range of geometric transformations is -5° to +5°, and it supports horizontal and vertical flipping.
[0090] The percentage of bad pixels injected ranges from 0.1% to 1%, and the mode supports three modes: zeroing, saturation, and random.
[0091] The standard deviation of gain for non-uniform residuals is 0.02, and the standard deviation of offset is 0.01.
[0092] The baseline amplitude of thermal drift is 0.02;
[0093] The frequency range of the coherent interference is 0.1 to 0.5, and the amplitude range is 0.005 to 0.02.
[0094] The readout noise is a Poisson-Gaussian mixture, with a 1:1 ratio of amplitude weighting between the Poisson and Gaussian noise components.
[0095] Furthermore, each type of enhancement operator corresponds to a physical degradation mechanism in the terahertz imaging link: stripe noise simulates fixed pattern noise caused by non-uniformity of detector pixel response; gain drift simulates overall brightness change caused by power fluctuation of terahertz source; electronic noise simulates thermal noise and shot noise of detector; geometric transformation simulates sample placement angle deviation; bad pixel injection simulates detector pixel damage and failure; non-uniformity residue simulates pixel-level gain and offset differences remaining after non-uniformity correction; thermal drift simulates image baseline drift caused by changes in ambient temperature; coherent interference simulates parasitic interference artifacts generated by terahertz coherent source; and readout noise simulates Poisson-Gaussian mixed noise generated by detector readout circuit.
[0096] All enhancement operators are applied only to training set samples, while no enhancement processing is applied to validation and test set samples, ensuring that the model evaluation results can reflect the generalization performance under real-world conditions. The occurrence probability and parameter range of each type of enhancement operator can be configured independently, and the configuration parameters can be adjusted through the controls on the training interface to adapt to detector application scenarios with different degrees of degradation.
[0097] Example 3, please refer to Figure 1 and Figure 3 As shown, this embodiment provides a terahertz defect identification and symbolic deployment method based on physically constrained KANs, including the following steps:
[0098] S3, KAN Defect Classification Model Training and Optimal Threshold Calibration: Construct a KAN based on the B-spline activation function, input the enhanced training set into the network for supervised training, iteratively update the network parameters using K-fold hierarchical cross-validation, and search for the optimal classification threshold based on the validation set with the maximization of the Youden exponent as the criterion and save it with the model.
[0099] In step S3, the input to KAN is a flattened 64×64 pixel terahertz image vector, and the input vector is input to the hidden layer after PCA dimensionality reduction.
[0100] The PCA dimensionality reduction dimension can be adjusted from 16 to 256, and the number of hidden layer nodes can be adjusted from 8 to 256.
[0101] Each connection edge of the network is equipped with a learnable B-spline activation function, and the hidden layer nodes perform a linear summation on the activation results of all input edges;
[0102] The grid number of B-splines is adjustable from 2 to 20, and the order is adjustable from 2 to 5.
[0103] The network parameters are initialized using a physical heuristic method, and a Gaussian perturbation with a mean of 0 and a standard deviation of 0.01 is applied to the coefficients of all B-spline basis functions.
[0104] The number of folds in K-fold hierarchical cross-validation can be adjusted from 2 to 10.
[0105] K-fold random partitioning is performed independently on normal samples and defective samples respectively. Then, the normal samples and defective samples in the corresponding fold are merged to form the training subset and validation subset of the fold, ensuring that the ratio of the two classes of samples in each fold is consistent with the sample ratio of the entire dataset.
[0106] The training process uses the Adam optimizer, which supports switching between two loss functions: binary cross-entropy loss and mean squared error loss.
[0107] The learning rate scheduling employs a decay strategy based on validation set loss, with a decay factor of 0.5, a patience value of 10 rounds, and a minimum learning rate of 1×10. -6 ;
[0108] L2 norm gradient clipping was used with a clipping threshold of 10.0.
[0109] The search process for the optimal classification threshold is as follows:
[0110] Within the model output probability range of the validation set, exhaustively search all candidate thresholds in the range of 0.01 to 0.99 with a step size of 0.01.
[0111] For each candidate threshold, calculate the corresponding true positive rate and true negative rate, and calculate the Youden index using the formula J=TPR+TNR-1;
[0112] The threshold corresponding to the maximum value of the Youden index is selected as the optimal classification threshold for the model, and saved together with the network weight parameters to the model file.
[0113] Furthermore, physical heuristic initialization, by applying tiny Gaussian perturbations to the coefficients of the B-spline basis functions, simulates the small-signal response characteristics of terahertz signals, which can accelerate the network convergence speed.
[0114] The training process supports batch training queue management, allowing multiple sets of KAN model tasks with different architecture parameters to be added in advance. The system automatically executes the training sequentially according to the queue order, without the need for manual intervention or switching.
[0115] The training interface displays the K-fold cross-validation loss curve in real time, where the solid line represents the validation set loss and the dashed line represents the training set loss. Curves with different numbers of folds are distinguished by different colors, making it easy to intuitively observe the training convergence status.
[0116] The interface synchronously displays a dynamic schematic diagram of the KAN network structure, drawing nodes and connection edges according to the true dimensions of the input layer, hidden layer, and output layer. The node colors are dynamically refreshed according to the activation values, intuitively presenting the feature learning process of the network.
[0117] The training interface features a real-time dual-image display area, showing images of normal and defective samples from the current batch side-by-side. If a certain type of sample is missing from the current batch, a sample is randomly selected from the corresponding dataset to supplement the display, used for real-time verification of data augmentation and preprocessing effects. The threshold strategy supports switching between "automatic threshold (Youden optimal)" and "fixed threshold" modes via interface controls to meet the needs of different experimental comparison scenarios.
[0118] The training process employs an L2 norm gradient pruning mechanism to prevent gradient explosion during training and improve training stability.
[0119] Example 4, please refer to Figure 1 As shown, this embodiment provides a terahertz defect identification and symbolic deployment method based on physically constrained KANs, including the following steps:
[0120] S4. KAN Model Multi-Template Symbolization and Threshold Recalibration: Traverse the B-spline activation function of each edge of the trained KAN, use multiple physical and mathematical templates for least squares fitting, filter qualified edges and prune unqualified edges through adaptive mean square error threshold, and generate a structured symbolic configuration file.
[0121] After symbolization is completed, K-fold threshold calibration is re-executed, and the recalibrated optimal classification threshold is written to the configuration file;
[0122] In step S4, the various physical mathematical templates are exponential function template, sine function template, cubic polynomial template, Gaussian function template, and damped oscillation function template.
[0123] The fitting process uniformly samples 200 to 500 sample points within the input interval [-1,1]. The Levenberg-Marquardt nonlinear least squares method is used to fit the parameters of the five types of templates respectively. The template with the smallest fitting residual is selected as the final symbolic expression of the edge.
[0124] The adaptive mean square error threshold is obtained by multiplying the threshold coefficient by the larger of the signal variance output by the side activation function and 0.01;
[0125] Edges with fitting residuals below a threshold are considered qualified edges, and their corresponding mathematical expressions and template parameters are retained.
[0126] Edges with fitting residuals higher than a threshold are considered unqualified edges, and pruning is performed with a pruning log recorded.
[0127] For output standard deviation less than 1×10 -8 The constant edges are directly recorded as constant functions;
[0128] The symbolic configuration file is in JSON structured format, containing two parts: statistical metadata and node formula parameter array. The statistical metadata includes classification threshold, input standardized mean vector, input standard deviation vector, PCA transformation matrix, input dimension, and number of hidden layer nodes.
[0129] Furthermore, the exponential function (p0·exp(p1·t)+p2), the sine function (p0·sin(p1·t+p2)+p3), and the cubic polynomial (p0·t) 3 +p1·t 2 +p2·t+p3), Gaussian function (p0·exp(-(t-p1)) 2 / (2*p2 2))+p3), damped oscillation (p0·exp(-p1·t)·sin(p2·t+p3)+p4).
[0130] The symbolization process offers eight quick template preset groups: all templates, material absorption templates, interference fringe templates, nonlinear templates, defect diffusion templates, resonance attenuation templates, classical physical templates, and polynomial combination templates. Each preset group corresponds to different combinations of physical and mathematical templates, allowing for one-click selection to suit the corresponding imaging scene. Threshold recalibration is performed through an independent background thread, using a K=5 fold hierarchical partitioning method to process terahertz sample data. After inference using the symbolic formula model on each fold validation set, the corresponding Youden optimal threshold is calculated. Finally, the average of the K fold thresholds is written to the metadata field of the symbolization configuration file.
[0131] For output standard deviation less than 1×10 -8 The constant edges are directly recorded as constant functions and the corresponding network topology is preserved, eliminating the need for curve fitting and reducing the amount of symbolic computation.
[0132] The symbolization configuration file uses a JSON structured format, divided into two parts: statistical metadata and node formula parameter arrays. This enables the model to be self-contained, eliminating the need for additional dependencies on the original training environment during deployment. The symbolization result file is named "original model name + symbolization + timestamp" to easily distinguish between different versions of the symbolized model.
[0133] The symbolic model supports an asynchronous loading mechanism. The loading process reads data in batches by node, loading one model every 300 milliseconds to avoid blocking the graphical interface when loading large models.
[0134] Example 5, please refer to Figure 1 As shown, this embodiment provides a terahertz defect identification and symbolic deployment method based on physically constrained KANs, including the following steps:
[0135] S5, Multi-engine Consistent Inference Deployment Architecture Construction: Construct four types of inference engines: deep learning engine, numerical computation engine, standard mathematical library engine, and embedded simulation engine. The four types of engines follow unified input preprocessing rules, numerical truncation rules, and floating-point precision standards.
[0136] In step S5, the reasoning logic of the four types of reasoning engines are as follows:
[0137] The deep learning engine loads the original KAN model weight file, performs forward inference based on the deep learning framework, and outputs the classification probability through the Sigmoid function.
[0138] The numerical computation engine loads the symbolic configuration file, calls the general numerical computation library to perform formula calculations according to the network level, and outputs the classification probability.
[0139] The standard math library engine relies on the standard math library that comes with the programming language to perform formula calculations and performs input limiting on exponential and sine operations;
[0140] The embedded simulation engine performs 32-bit single-precision floating-point truncation and layer-by-layer numerical overflow protection in the host computer environment, reproducing the operation logic after the embedded C language is ported.
[0141] All inference engines uniformly implement the following numerical protection rules: hard truncation of input features is performed in the range of [-1,1], the input log probability of the Sigmoid function is limited to the range of [-50,50], and all floating-point operations adopt the 32-bit single-precision floating-point standard.
[0142] Furthermore, the deep learning engine supports a model warm-up mechanism, which performs a zero-input forward inference once after loading the model to ensure that the model is fully loaded and runs without crashes before formally receiving inference tasks.
[0143] The numerical computation engine performs formula calculations based on a general numerical computation library, making it suitable for edge computing nodes that have a numerical computation environment but lack the conditions for deploying deep learning frameworks.
[0144] The standard math library engine relies solely on the basic math library that comes with the programming language, with no third-party dependencies, making it suitable for minimalist operating environments such as bare-metal microcontrollers.
[0145] The embedded simulation engine replicates the operational behavior of the embedded C language after porting by simulating the 32-bit floating-point precision limit and layer-by-layer overflow protection logic in the host computer environment. It can verify the numerical consistency of the embedded deployment in advance without actually burning the hardware.
[0146] The unsymbolized original KAN model only supports inference via deep learning engines; the symbolized model supports three types of inference engines: numerical computation engines, standard mathematical library engines, and embedded simulation engines. All four engines uniformly adhere to numerical protection rules: input features are hard-truncated in the range [-1,1] to prevent B-spline extrapolation explosion; the logarithmic probability of the Sigmoid function input is limited to the range [-50,50] to eliminate numerical saturation; and all floating-point operations uniformly adopt the 32-bit single-precision standard to ensure controllable deviations in cross-engine inference results.
[0147] Example 6, please refer to Figure 1 As shown, this embodiment provides a terahertz defect identification and symbolic deployment system based on physical constraint KAN. The system is built with a graphical interface framework and integrates the entire process of data acquisition, model training, deployment verification, and model comparison.
[0148] The system interface has four function tabs. The parameters of each tab are automatically remembered and restored through the operating system registry, and the system supports one-click restoration of default parameters.
[0149] The first tab is the data acquisition page. The left side is divided into the device control group, image processing parameter group, and dataset storage group. The middle area is the real-time image display window, which supports interpolation and zoom display. The right side is the operation log window, which records operation information such as acquisition, storage, and parameter modification in real time.
[0150] The second tab is the training mode page. The left side is divided into the data import group, the physical enhancement parameter group, the model architecture configuration group, and the training queue management group. The middle area is divided into the real-time sample display area, the training curve display area, and the training control button area. The right side is divided into the network structure diagram area and the system log area.
[0151] The third tab is the deployment verification page. The left side is divided into model selection group, symbolic template group, threshold setting group, and input image drag and drop area. The right side is divided into engine selection group, inference result display group, mathematical expression display group, and multi-engine comparison table group.
[0152] Mathematical expressions are displayed in groups according to network hierarchy, with a maximum of 50 expressions displayed at a time. Scrolling is supported for viewing any expressions that exceed this limit.
[0153] The fourth tab is the model comparison page. The left side displays a model registry table showing nine items of information for all historically trained models: name, architecture type, best AUC, accuracy, number of parameters, training duration, thresholding strategy, optimal threshold, and deployment size. The right side features three sets of comparison tables: the first is a comparison table of model size and inference speed, including model type, storage size, single-frame inference time, and dependent environment, used to quantify the lightweight effect before and after symbolization; the second is a comparison table of multi-engine inference consistency, including engine type, percentage deviation of normal sample probability, percentage deviation of defective sample probability, and maximum absolute deviation from the benchmark engine, used to verify cross-engine numerical stability; the third is a comparison table of Youden threshold optimization effects, including thresholding strategy, AUC, Youden index, and F1 score, used to compare the statistical performance of four strategies: fixed threshold, optimal training set, optimal K-fold validation, and recalibration after symbolization.
[0154] Furthermore, the model selection area supports right-click operations, allowing users to perform actions such as unloading models and viewing model information, and supports loading multiple models simultaneously for comparison.
[0155] The model comparison page supports automatically populating the comparison table data after selecting a model from the model registry, and supports exporting the comparison data as a structured file for easy subsequent analysis.
[0156] The system supports one-click deployment, which can package and output the symbolic configuration file and standard mathematical library inference code for direct use in embedded device porting.
[0157] The foregoing has shown and described the basic principles, main features, and advantages of the present invention. Those skilled in the art should understand that the present invention is not limited to the above embodiments. The embodiments and descriptions in the specification are merely illustrative of the principles of the invention. Various changes and modifications can be made to the invention without departing from its spirit and scope, and all such changes and modifications fall within the scope of the present invention as claimed. The scope of protection of this invention is defined by the appended claims and their equivalents.
Claims
1. A terahertz defect identification and symbolic deployment method based on physically constrained KANs, characterized in that, Includes the following steps: S1. Terahertz Image Acquisition, Preprocessing, and Dataset Construction: Directly connect to the terahertz array detector, call the native application programming interface to read the raw floating-point image frames, and sequentially perform differential correction, spatial filtering, and grayscale transformation processing to generate standardized images and store them according to labels to construct the training dataset. S2. Terahertz Image Physically Constrained Data Augmentation: For the nine types of physical degradation mechanisms of terahertz detectors, a probabilistic configurable augmentation strategy is constructed. Augmentation is applied randomly to the training set samples in a fixed order, while no augmentation is applied to the validation set and test set. S3, KAN Defect Classification Model Training and Optimal Threshold Calibration: Construct a KAN based on the B-spline activation function, input the enhanced training set into the network for supervised training, iteratively update the network parameters using K-fold hierarchical cross-validation, and search for the optimal classification threshold based on the validation set with the maximization of the Youden exponent as the criterion and save it with the model. S4. KAN Model Multi-Template Symbolization and Threshold Recalibration: Traverse the B-spline activation function of each edge of the trained KAN, use multiple physical and mathematical templates for least squares fitting, filter qualified edges and prune unqualified edges through adaptive mean square error threshold, and generate a structured symbolic configuration file. After symbolization is completed, K-fold threshold calibration is re-executed, and the recalibrated optimal classification threshold is written to the configuration file; S5, Multi-engine Consistent Inference Deployment Architecture Construction: Construct four types of inference engines: deep learning engine, numerical computation engine, standard mathematical library engine, and embedded simulation engine. The four types of engines follow unified input preprocessing rules, numerical truncation rules, and floating-point precision standards.
2. The terahertz defect identification and symbolic deployment method based on physically constrained KAN according to claim 1, characterized in that, S1 specifically includes: Connect directly to the Terasense series 64×64 pixel terahertz array detector via USB cable and call the native application programming interface to read raw floating-point image frames. Three types of parameters are configured through the device control module: exposure index, cumulative frame count, and bad pixel threshold. Differential correction supports three differential modes: off, on, and calibration file. In on mode, the first defect-free image after acquisition starts is used as the reference frame to perform pixel-by-pixel differential operation. In calibration file mode, a pre-recorded background calibration file is loaded to perform background compensation. Spatial filtering is performed in a fixed order through three levels of processing: 3×3 kernel median filtering, Gaussian blurring with adjustable standard deviation, and bilateral filtering with adjustable spatial domain parameters. The grayscale transformation is performed in a fixed order with three levels of processing: linear transformation of contrast and brightness, non-linear correction of Gamma, and sharpening with adjustable intensity. The dataset uses a four-folder structured storage structure, with the four folders corresponding to normal samples in the training set, defective samples in the training set, normal samples in the test set, and defective samples in the test set, respectively.
3. The terahertz defect identification and symbolic deployment method based on physically constrained KAN according to claim 1, characterized in that, In S2, the enhancement operators corresponding to the nine types of physical degradation mechanisms are applied sequentially according to the terahertz imaging degradation chain, in the following order: geometric transformation, non-uniformity residual, thermal drift, fringe noise, coherent interference, gain drift, readout noise, electronic noise, and bad pixel injection; after all enhancements are applied, the image pixel values are cropped to the [0,1] interval. The probability of occurrence of each type of enhancement operator can be adjusted independently, with an adjustment range of 0% to 100%.
4. The terahertz defect identification and symbolic deployment method based on physically constrained KAN according to claim 3, characterized in that, In S2, the parameter ranges for each type of enhancement operator are as follows: The frequency range of the stripe noise is 0.5 to 2.5, the amplitude range is 0.005 to 0.03, and the direction supports four modes: X direction, Y direction, XY bidirectional, and random. The gain coefficient for gain drift ranges from 0.98 to 1.02; The electronic noise is additive Gaussian noise with a sigma range of 0.003 to 0.
012. The rotation angle range of geometric transformations is -5° to +5°, and it supports horizontal and vertical flipping. The percentage of bad pixels injected ranges from 0.1% to 1%, and the mode supports three modes: zeroing, saturation, and random. The standard deviation of gain for non-uniform residuals is 0.02, and the standard deviation of offset is 0.
01. The baseline amplitude of thermal drift is 0.02; The frequency range of the coherent interference is 0.1 to 0.5, and the amplitude range is 0.005 to 0.
02. The readout noise is a Poisson-Gaussian mixture, with a 1:1 ratio of amplitude weighting between the Poisson and Gaussian noise components.
5. The terahertz defect identification and symbolic deployment method based on physically constrained KAN according to claim 1, characterized in that, In S3, the input to KAN is a flattened 64×64 pixel terahertz image vector, and the input vector is input to the hidden layer after PCA dimensionality reduction. The PCA dimensionality reduction dimension can be adjusted from 16 to 256, and the number of hidden layer nodes can be adjusted from 8 to 256. Each connection edge of the network is equipped with a learnable B-spline activation function, and the hidden layer nodes perform a linear summation on the activation results of all input edges; The grid number of B-splines is adjustable from 2 to 20, and the order is adjustable from 2 to 5. The network parameters are initialized using a physical heuristic method, and a Gaussian perturbation with a mean of 0 and a standard deviation of 0.01 is applied to the coefficients of all B-spline basis functions.
6. The terahertz defect identification and symbolic deployment method based on physically constrained KAN according to claim 1, characterized in that, In step S3, the number of folds in the K-fold stratified cross-validation can be adjusted from 2 to 10. K-fold random partitioning is performed independently on normal samples and defective samples respectively. Then, the normal samples and defective samples in the corresponding fold are merged to form the training subset and validation subset of the fold, ensuring that the ratio of the two classes of samples in each fold is consistent with the sample ratio of the entire dataset. The training process uses the Adam optimizer, which supports switching between two loss functions: binary cross-entropy loss and mean squared error loss. The learning rate scheduling employs a decay strategy based on validation set loss, with a decay factor of 0.5, a patience value of 10 rounds, and a minimum learning rate of 1×10. -6 ; L2 norm gradient clipping was used with a clipping threshold of 10.
0.
7. The terahertz defect identification and symbolic deployment method based on physically constrained KAN according to claim 1, characterized in that, In step S3, the search process for the optimal classification threshold is as follows: Within the model output probability range of the validation set, exhaustively search all candidate thresholds in the range of 0.01 to 0.99 with a step size of 0.
01. For each candidate threshold, calculate the corresponding true positive rate and true negative rate, and calculate the Youden index using the formula J=TPR+TNR-1; The threshold corresponding to the maximum value of the Youden index is selected as the optimal classification threshold for the model, and saved together with the network weight parameters to the model file.
8. The terahertz defect identification and symbolic deployment method based on physically constrained KAN according to claim 1, characterized in that, In step S4, the various physical mathematical templates are exponential function template, sine function template, cubic polynomial template, Gaussian function template, and damped oscillation function template. The fitting process uniformly samples 200 to 500 sample points within the input interval [-1,1]. The Levenberg-Marquardt nonlinear least squares method is used to fit the parameters of the five types of templates respectively. The template with the smallest fitting residual is selected as the final symbolic expression of the edge.
9. The terahertz defect identification and symbolic deployment method based on physically constrained KAN according to claim 1, characterized in that, In step S4, the adaptive mean square error threshold is obtained by multiplying the threshold coefficient by the larger of the signal variance output by the side activation function and 0.
01. Edges with fitting residuals below a threshold are considered qualified edges, and their corresponding mathematical expressions and template parameters are retained. Edges with fitting residuals higher than a threshold are considered unqualified edges, and pruning is performed with a pruning log recorded. For output standard deviation less than 1×10 -8 The constant edges are directly recorded as constant functions; The symbolic configuration file is in JSON structured format, containing two parts: statistical metadata and node formula parameter array. The statistical metadata includes classification threshold, input standardized mean vector, input standard deviation vector, PCA transformation matrix, input dimension, and number of hidden layer nodes.
10. The terahertz defect identification and symbolic deployment method based on physically constrained KAN according to claim 1, characterized in that, In step S5, the reasoning logic of the four types of reasoning engines are as follows: The deep learning engine loads the original KAN model weight file, performs forward inference based on the deep learning framework, and outputs the classification probability through the Sigmoid function. The numerical computation engine loads the symbolic configuration file, calls the general numerical computation library to perform formula calculations according to the network level, and outputs the classification probability. The standard math library engine relies on the standard math library that comes with the programming language to perform formula calculations and performs input limiting on exponential and sine operations; The embedded simulation engine performs 32-bit single-precision floating-point truncation and layer-by-layer numerical overflow protection in the host computer environment, reproducing the operation logic after the embedded C language is ported. All inference engines uniformly implement the following numerical protection rules: hard truncation of input features is performed in the range of [-1,1], the input log probability of the Sigmoid function is limited to the range of [-50,50], and all floating-point operations adopt the 32-bit single-precision floating-point standard.