Method and system for detecting surface defects of industrial workpieces based on TSK fuzzy mapping
By employing a dual-view model of TSK fuzzy mapping in the detection of surface defects in industrial workpieces, combined with consistency constraints and rule entropy regularization terms, the problems of detection accuracy and interpretability are solved, and efficient and stable detection in complex environments is achieved.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- NANTONG UNIV
- Filing Date
- 2026-01-23
- Publication Date
- 2026-05-29
AI Technical Summary
Existing technologies for detecting surface defects in industrial workpieces suffer from poor interpretability, severe domain offset, and gradient conflicts, making it difficult to maintain high accuracy and stability in complex environments.
A dual-view model is constructed using a TSK-based fuzzy mapping method, and consistency constraints are introduced during training. By calculating the cross-entropy loss and gradient consistency loss of the parameter update direction, the model parameters are optimized. Combined with regular entropy and sparse regularization terms, the stability and generalization ability of the model are improved.
It improves detection accuracy and stability in complex industrial environments, reduces gradient conflict risk, achieves interpretable rule-level characterization, and is suitable for auditable multi-source data analysis and efficient detection in resource-constrained environments.
Smart Images

Figure CN122115331A_ABST
Abstract
Description
Technical Field
[0001] This invention discloses a method and system for detecting surface defects in industrial workpieces based on TSK fuzzy mapping, belonging to the field of industrial machine vision technology. Background Technology
[0002] In the field of precision manufacturing, physical defects on the surface of workpieces not only affect the aesthetic appearance of products, but can also directly damage the physical properties, mechanical strength, and subsequent assembly accuracy of the workpieces, and even cause serious safety accidents. Therefore, achieving efficient and accurate surface defect detection is an indispensable part of the industrial production process. In the early days, industrial sites mainly relied on manual visual inspection, but manual quality inspection has inherent disadvantages such as strong subjectivity, susceptibility to fatigue, low inspection efficiency, and inability to adapt to high-speed production lines. With the development of machine vision technology, surface defect detection technology based on automated optical inspection (AOI) has gradually replaced manual inspection. In existing invention patents and disclosed technologies, the detection and classification methods for surface defects of industrial workpieces are mainly divided into two categories: The first category is based on traditional digital image processing and machine learning methods. These methods usually rely on manually designed feature extraction operators (such as LBP, HOG, gray-level co-occurrence matrix, etc.) combined with edge detection, threshold segmentation, or SVM (support vector machine) classifiers for identification. This type of technology performs reasonably well in simple scenarios with a single background and constant illumination, but its feature design is highly dependent on expert experience, has poor generalization ability, and is difficult to deal with workpieces with complex background textures or varied defect shapes. The second category is deep learning methods based on deep convolutional neural networks (CNNs). In recent years, deep learning models represented by ResNet [patent number: CN202510425853.8], YOLO [patent numbers: CN202510518990; CN202510422293.0], and Faster R-CNN have achieved significantly higher accuracy than traditional algorithms in industrial defect detection due to their powerful feature extraction capabilities, becoming the mainstream direction of current patent applications. However, these mainstream deep learning models still face severe challenges in practical industrial applications, mainly in two aspects: First, the harsh environment of industrial production sites, such as fluctuating lighting, sensor aging noise, and conveyor belt vibration, often leads to a decline in image quality, resulting in a significant "domain shift" phenomenon. Models trained in ideal laboratory environments often experience a significant drop in accuracy when deployed in the field, and labeling large amounts of field data is costly. To solve this problem, researchers have begun to adopt dual-view or multi-view learning frameworks based on consistency constraints (such as semi-supervised learning or domain adaptation), but this also introduces complex optimization problems. Secondly, most existing deep learning models are purely data-driven "black box" models, lacking interpretability and unable to tell quality inspectors "why it was judged as a crack", making it difficult to meet the strict requirements of high-end manufacturing for the traceability of the quality inspection process.
[0003] To address interpretability issues, TSK (Takagi-Sugeno-Kang) fuzzy systems have gained increasing attention due to their ability to model nonlinear relationships using rules and soft membership degrees, exhibiting good interpretability and robustness. The antecedent of a TSK fuzzy system is often described by a Gaussian membership function to depict the local subspace, while the consequent is a linear submodel characterizing the local mapping. Normalized rule activation can serve as a measure of rule confidence, characterizing the association between samples and rules. However, traditional approaches often use TSK as an independent classifier or merely as a static feature transformation layer. When facing high-dimensional dual-view (or multi-view) learning scenarios constructed to address domain offset, traditional TSK methods are prone to rule redundancy and parameter sensitivity issues, and lack constraint mechanisms for deep integration with the optimization process of deep neural networks, making it difficult to fundamentally alleviate the gradient conflict and erroneous consensus problems commonly encountered in dual-view training.
[0004] In summary, existing technologies generally lack a solution that simultaneously satisfies the following three requirements: characterizing the complementarity and uncertainty of the two perspectives at an interpretable rule mapping layer; directly constraining the gradient direction of the loss function relative to the mapped features to achieve cross-perspective collaboration at the optimization level and reduce the risk of gradient conflicts and erroneous consensus; and improving the usability of pseudo-labels by combining rule confidence and rule entropy mechanisms under semi-supervised or weakly supervised conditions, and suppressing redundancy and overfitting through rule sparsity or smoothing. Summary of the Invention
[0005] The technical problem to be solved by this invention is to propose a surface defect detection method for industrial workpieces based on TSK fuzzy mapping, so as to improve the stability and generalization performance of the model under complex heterogeneity, multiple noise and interpretability constraints, and adapt to various typical industrial workpiece application scenarios.
[0006] To address the above technical problems, this invention constructs interpretable TSK fuzzy mappings for both perspectives and, innovatively, introduces consistency constraints at the parameter gradient level during training. By calculating and aligning the update directions of the two perspective model parameters and combining this with specific optimization strategies, the two perspectives collaboratively optimize during the learning process, thereby improving the model's stability and generalization performance. This invention adopts the following technical solution:
[0007] First, this invention proposes a method for detecting surface defects in industrial workpieces based on TSK fuzzy mapping, the specific steps of which are as follows:
[0008] The surface image data of the workpiece to be inspected on the industrial production line is acquired using an image acquisition device, and the data is preprocessed. The data is constructed in a dual-view form, including global semantic feature representation and local texture rule feature representation of the same workpiece. The dual-view data is input into TSK, and TSK fuzzy rule mapping is performed on the input features of the two views respectively. The features are mapped to the rule space through antecedent fuzzy inference, and then the preliminary prediction result is output through consequent linear discrimination.
[0009] Based on labeled samples, calculate cross-entropy supervision loss and add rule entropy, rule center separation and rule weight sparsity regularization terms;
[0010] The gradient of the supervision loss with respect to the two-view model parameters is calculated. After normalization, the bidirectional cosine alignment loss is calculated as the cross-view gradient consistency loss. The gradient stopping operation is used in the calculation process.
[0011] Construct a total objective function, which is a weighted sum of the supervision loss, the cross-view gradient consistency loss, the rule entropy regularization term, the rule center separation regularization term, and the rule weight sparsity regularization term; and update the model parameters using a two-step alternating optimization strategy.
[0012] If there are unlabeled samples, an additional output consistency loss based on the KL divergence of the predicted output for unlabeled samples from two perspectives is added to the overall objective function;
[0013] The image of the workpiece to be inspected is input into the trained model to obtain its corresponding defect category; and control instructions are generated according to the defect category to control the sorting equipment to classify or reject the workpiece.
[0014] Preferably, the data is preprocessed, including: dividing the data into training set, validation set and test set, and performing normalization, standardization, missing value handling and feature encoding.
[0015] Preferably, constructing the overall objective function specifically includes the following steps:
[0016] (1) Calculate the monitoring loss :
[0017] ;
[0018] in, Corresponding to first-person and second-person perspectives, collection This represents the set of manually labeled sample indices in the training set. This represents the number of elements in the set, for any labeled sample. , This is the true category label for the sample; For the first Viewpoint classifier for samples The output is the predicted class probability distribution vector; The standard multi-class cross-entropy loss function is used to measure the true label. With predicted probability The differences between them;
[0019] (2) Calculate the rule entropy :
[0020] ;
[0021] in, Indicates the number of samples. It is the number of fuzzy rules for each viewpoint. It is a sample From the perspective Next Normalization activation of the rule, It is a constant that makes the value stable;
[0022] (3) Separation of computation center :
[0023] ;
[0024] in, Indicates perspective No. The antecedent center of the rule, Indicates perspective No. The antecedent center of the rule, This represents the Euclidean distance between the center vectors of two rules. It is a temperature coefficient used to control the separation sensitivity between regular centers;
[0025] (4) Calculation of sparse rule weights :
[0026] ;
[0027] in, It's a perspective The linear parameter matrix of the TSK aftermath. It is an L1 norm, used to promote the sparsity of rule weights.
[0028] (5) Calculate the consistency loss of unlabeled sample outputs :
[0029] ;
[0030] Through the and The symmetric summation is performed and averaged over all unlabeled samples to constrain the prediction probability distributions of the two perspectives to remain consistent on the unlabeled data.
[0031] (6) Calculate the cross-view gradient consistency loss :
[0032] Define the gradient as That is, in the first From the perspective of all parameters, the gradient direction vector is obtained, where, For gradient operators, For the first All trainable parameters of the viewpoint The supervised loss is expressed with respect to the parameter. The gradient tensor, This is a flattening operator used to expand the gradient tensor into a one-dimensional vector in a fixed order. The normalized gradient direction vector is defined as follows: , Let L be the Euclidean L2 norm of the vector. To prevent the use of tiny constants with a denominator of zero, the gradient consistency loss is therefore...
[0033] ;
[0034] By minimizing the 1-inner product between the normalized gradient directions of the two views, the gradient directions of the first and second views in the supervised loss are made consistent; at the same time, the following is utilized: By restricting each term to updating only the parameters of one viewpoint, we can avoid calculating the second gradient and reduce optimization overhead.
[0035] (7) Calculate the overall objective function :
[0036] ;
[0037] in, , , , and These are the weights of each type of loss.
[0038] Preferably, in the parameter update phase, in each training iteration, the second viewpoint is first fixed, and only the parameters of the first viewpoint are updated; then the first viewpoint is fixed, and only the parameters of the second viewpoint are updated, thereby alternately aligning the gradient direction between the two viewpoints; the two-step alternating optimization strategy specifically includes:
[0039] (1) Calculate the single-step loss of the first-view perspective using the following formula:
[0040] ;
[0041] Calculate the normalized gradients for the two perspectives using the current mini-batch training samples. and In the gradient consistency term, for use The operation is treated as a constant, and only applies to the parameter set of viewpoint 1. Backpropagation and updates are performed while the parameters of viewpoint 2 remain unchanged;
[0042] (2) Calculate the single-step loss of the second perspective using the following formula:
[0043] ;
[0044] In this step, also based on the current mini-batch training samples, we first calculate the normalized gradients of the two-view supervised loss with respect to their respective parameters. and In the gradient consistency term, for use The operation is treated as a constant, and only applies to the parameter set of viewpoint 2. Backpropagation and updates are performed, and the parameters of viewpoint 1 remain unchanged.
[0045] Preferably, during the two-step alternating optimization strategy for updating model parameters, the Adam optimizer or SGD optimizer is used for parameter updates; the classification head consequent parameters and antecedent parameters in the TSK module are set with grouped learning rates, where the learning rate of the antecedent parameters is 0.2 to 0.5 times the total learning rate; gradient norm clipping is applied to the gradient vector of each viewpoint, constraining its L2 norm to satisfy... To avoid gradient explosion, among which, The gradient norm clipping threshold.
[0046] Preferably, the parameter settings include the following value ranges:
[0047] Number of rules per perspective The two perspectives take the same number of rules; the fuzzy index of fuzzy C-means clustering. The maximum number of iterations is 200; the total learning rate is 0.001, and the antecedent parameter learning rate is 0.2 to 0.5 times the total learning rate; the batch size is 64; the training epochs are 10; and the gradient consistency loss weights are... Rule entropy and center separation regularization term weights Rule weights sparse regularization term weights The output consistency loss weight is set to in this embodiment. ; Central separation temperature parameters Gradient norm clipping threshold .
[0048] Meanwhile, this invention proposes an industrial workpiece surface defect detection and classification system based on TSK fuzzy mapping, comprising:
[0049] The data preparation and preprocessing module is configured to perform the following process: acquire surface image data of the workpiece to be inspected on the industrial production line using an image acquisition device, and preprocess the data; construct the data into dual-view data, including global semantic feature representation and local texture rule feature representation of the same workpiece;
[0050] The TSK calculation module is configured to perform the following process: input dual-view data into TSK, perform TSK fuzzy rule mapping on the input features of the two views respectively, map the features to the rule space through antecedent fuzzy inference, and then output the preliminary prediction result through consequent linear discriminant.
[0051] The supervision and regularization loss calculation module is configured to perform the following process: calculate the cross-entropy supervision loss based on labeled samples, and add rule entropy, rule center separation and rule weight sparsity regularization terms;
[0052] The gradient consistency constraint module is configured to perform the following process: calculate the gradient of the supervised loss with respect to the two-view model parameters, normalize it, and calculate the bidirectional cosine alignment loss as the cross-view gradient consistency loss, using a gradient-stopping operation during the calculation.
[0053] The joint optimization module is configured to perform the following process: constructing a total objective function, which is a weighted sum of the supervised loss, the cross-view gradient consistency loss, the rule entropy regularization term, the rule center separation regularization term, and the rule weight sparsity regularization term; and updating the model parameters using a two-step alternating optimization strategy, first applying a gradient-stopping operation to the second-view normalized gradient as a reference, updating only the first-view parameters, and then repeating the process by switching views.
[0054] The semi-supervised extension module is configured to perform the following process: if there are unlabeled samples, add an output consistency loss based on the KL divergence of the predicted outputs for the unlabeled samples from two perspectives to the total objective function;
[0055] The classification decision module is configured to perform the following process: inputting the image of the workpiece to be inspected into the trained model to obtain its corresponding defect category; generating control instructions based on the defect category to control the sorting equipment to classify or reject the workpiece.
[0056] Meanwhile, the present invention proposes an electronic device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein when the computer program is executed, it implements the steps of the method described in the present invention.
[0057] Furthermore, the present invention proposes a computer-readable storage medium having a computer program stored thereon, the computer program being configured to implement the steps of the method described in the present invention when invoked by a processor.
[0058] Finally, the present invention proposes a computer program product, including a computer program / instructions, characterized in that the computer program / instructions, when executed by a processor, implement the steps of the method described in the present invention.
[0059] The industrial workpiece surface defect detection method and system based on TSK fuzzy mapping described in this invention has the following technical advantages compared with the prior art:
[0060] (1) This invention introduces cross-view gradient consistency in a two-view pipeline and adopts a two-step alternating gradient stopping optimization strategy to align parameter update directions without introducing second-order overhead, reducing the risk of similar outputs but potentially incorrect optimization directions; combined with the rule-level representation of TSK fuzzy mapping, it can output Top-K rule contributions, facilitating review and cause tracing. Rule collapse is suppressed by rule entropy and center separation, maintaining training stability in small sample and class imbalance scenarios; the inference stage only involves rule activation and one linear mapping, with a complexity of approximately ,in and These represent the number of rules from two different perspectives. and These are the corresponding perspective feature dimensions.
[0061] (2) This invention relies on rule-level interpretable output and a stable cross-perspective gradient consistency training paradigm to improve the auditability and reproducibility of multi-source data analysis, and is suitable for scenarios with high requirements for interpretability and compliance, such as medical and industrial monitoring; low-complexity reasoning and customizable rule numbers This enables cost-effective deployment even in resource-constrained environments, promoting the popularization and standardization of intelligent analysis capabilities. Attached Figure Description
[0062] The accompanying drawings are provided to further illustrate the invention and form part of the specification. They are used together with the embodiments of the invention to explain the invention and do not constitute a limitation thereof.
[0063] Figure 1 This invention relates to a flowchart of a method for detecting and classifying surface defects in industrial workpieces based on TSK fuzzy mapping.
[0064] Figure 2 This is a schematic diagram of the structure of a TSK fuzzy mapping module according to the present invention. Detailed Implementation
[0065] 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. Of course, the specific embodiments described herein are merely illustrative and not intended to limit the invention.
[0066] Example 1: This example proposes a specific implementation process for an industrial workpiece surface defect detection method based on TSK fuzzy mapping, referencing... Figure 1 This includes the following steps:
[0067] Acquire dual-view data and preprocess and initialize the data. The dual views can be observation data of the same object in different modalities, or two feature representations obtained from the same modality under different feature extraction paths or different network branches. For any sample, the first-view feature is denoted as the first feature vector, and the second-view feature is denoted as the second feature vector; both jointly describe the same object.
[0068] The dual-view data is input into TSK, and a TSK fuzzy mapping layer containing several fuzzy rules is constructed for each view: First, fuzzy C-means clustering is performed on the preprocessed first and second view features to obtain the antecedent center vector and variance parameter of each rule under each view; then, based on this center and variance, the membership degree of any sample on each rule is calculated using a Gaussian membership function, and the membership degree is used as the rule activation intensity. The activation intensity of the same sample on all rules is normalized to obtain the normalized rule response; then, the normalized rule response is concatenated with the original feature vector of the corresponding view to construct the consequent linear basis of the TSK module for that view, and the classification logits output of that view is obtained through linear mapping. If necessary, the TSK output is weighted and fused with the original depth features according to preset coefficients to obtain the first and second view feature representations used for subsequent loss calculation. The specific structure of TSK is as follows: Figure 2 As shown.
[0069] Based on labeled samples, cross-entropy supervision loss is calculated, and rule entropy, rule center separation, and rule weight sparsity regularization terms are added.
[0070] The gradient of the supervision loss with respect to the two-view model parameters is calculated. After normalization, the bidirectional cosine alignment loss is calculated as the cross-view gradient consistency loss. The gradient stopping operation is used in the calculation process.
[0071] Construct a total objective function, which is a weighted sum of the supervision loss, the cross-view gradient consistency loss, the rule entropy regularization term, the rule center separation regularization term, and the rule weight sparsity regularization term; and update the model parameters using a two-step alternating optimization strategy.
[0072] If there are unlabeled samples, an additional output consistency loss based on the KL divergence of the predicted output for the unlabeled samples from two perspectives is added to the overall objective function.
[0073] Input the dual-view test data to be classified into the model trained by the above steps, obtain the corresponding classification results and output them.
[0074] Specifically, the data is preprocessed and initialized, including: dividing the data into training, validation and test sets, and performing operations such as normalization, standardization, missing value handling and feature encoding.
[0075] Specifically, a TSK blur mapping layer module is constructed for any viewpoint. Passing the exam The TSK fuzzy mapping process for each sample can be formally represented as follows:
[0076] First, perform fuzzy C-means clustering on the feature space of this perspective to obtain the number of rules. The fuzzy rule set. For the ... The first perspective Rule number 1, denoted by its antecedent center vector as . The corresponding front element width is .Will Let it be the square root of the mean of the squared Euclidean distances between samples within its cluster and the center, i.e. .in, Indicates the first From the perspective of belonging to the first A set of sample indexes for each cluster. This represents the number of samples within the cluster. For the first The sample at the th Feature vectors from a given perspective.
[0077] (1) Gaussian membership degree: the first From the perspective of the first The nth sample pair The membership degree of the rule is .
[0078] (2) Normalized activation: Sample From the perspective Next The normalization activation of the rule is .
[0079] (3) Linear basis construction of consequents: Let the first linear basis be denoted as the first linear basis. The dimension of viewpoint features is , No. The vector of a sample from this perspective is denoted as... Then construct the first TSK afterword linear basis from the perspective: .in, This represents the extended feature vector obtained by concatenating the normalized activation with the original features.
[0080] (4) Linear consequent and logits output: The first From the perspective of the first The classification logits output for each sample can be represented as: ,in, For the first The linear parameter matrix of the consequent of the viewpoint TSK module.
[0081] (5) Residual Fusion: Perspective The final feature representation after fusing the TSK output is as follows: ,in, is the residual fusion coefficient.
[0082] By following the steps above, the original features can be captured from each viewpoint. Mapped to a representation containing rule-level semantics This serves as the input basis for supervised loss, regular entropy regularization, center separation regularization, and gradient consistency constraints in subsequent steps.
[0083] Specifically, constructing the overall objective function includes the following steps:
[0084] (1) Calculate the monitoring loss :
[0085] ;
[0086] in, Corresponding to first-person and second-person perspectives, collection This represents the set of manually labeled sample indices in the training set. This represents the number of elements in the set, for any labeled sample. , This is the true category label for the sample; For the first Viewpoint classifier for samples The output is the predicted class probability distribution vector; The standard multi-class cross-entropy loss function is used to measure the true label. With predicted probability The differences between them.
[0087] (2) Calculate the rule entropy :
[0088] ;
[0089] in, Indicates the number of samples. It is the number of fuzzy rules for each viewpoint. It is a sample From the perspective Next Normalization activation of the rule, It is a constant that makes the value stable.
[0090] (3) Separation of computation center :
[0091] ;
[0092] in, Indicates perspective No. The antecedent center of the rule, Indicates perspective No. The antecedent center of the rule, This represents the Euclidean distance between the center vectors of two rules. It is a temperature coefficient used to control the separation sensitivity between regular centers.
[0093] (4) Calculation of sparse rule weights :
[0094] ;
[0095] in, It's a perspective The linear parameter matrix of the TSK aftermath. It is an L1 norm, used to promote the sparsity of rule weights.
[0096] (5) Calculate the consistency loss of unlabeled sample outputs :
[0097] ;
[0098] Through the and The symmetric summation is performed and averaged over all unlabeled samples to constrain the prediction probability distributions of the two perspectives to remain consistent on the unlabeled data. (6) Calculate the cross-perspective gradient consistency loss. :
[0099] Define the gradient as and normalization Then the gradient consistency loss is By minimizing the 1-inner product between the normalized gradient directions of the two views, the gradient directions of the first and second views in the supervised loss are made consistent; at the same time, the following is utilized: By restricting each term to updating only the parameters of one viewpoint, we can avoid calculating the second gradient and reduce optimization overhead.
[0100] (7) Calculate the overall objective function :
[0101] ;
[0102] in, , , , and These are the weights of each type of loss.
[0103] Specifically, in the parameter update phase, the following two-step alternating optimization strategy is adopted: In each training iteration, this invention first fixes the second viewpoint and updates only the parameters of the first viewpoint; then fixes the first viewpoint and updates only the parameters of the second viewpoint, thereby alternately aligning the gradient direction between the two viewpoints. The two-step alternating optimization strategy includes:
[0104] (1) Calculate the single-step loss of the first-view perspective using the following formula:
[0105] ;
[0106] Calculate the normalized gradients for the two perspectives using the current mini-batch training samples. and In the gradient consistency term, for use The operation is treated as a constant, and only applies to the parameter set of viewpoint 1. Backpropagation and updates are performed while the parameters of viewpoint 2 remain unchanged;
[0107] (2) Calculate the single-step loss of the second perspective using the following formula:
[0108] ;
[0109] In this step, also based on the current mini-batch training samples, we first calculate the normalized gradients of the two-view supervised loss with respect to their respective parameters. and In the gradient consistency term, for use The operation is treated as a constant, and only applies to the parameter set of viewpoint 2. Backpropagation and updates are performed, and the parameters of viewpoint 1 remain unchanged.
[0110] By optimizing in two alternating steps, bidirectional alignment can be achieved, with viewpoint 1 moving towards viewpoint 2 and viewpoint 2 moving towards viewpoint 1. This gradually makes the update directions of the two views more consistent, improving the classification performance after dual-view fusion.
[0111] Specifically, during the two-step alternating optimization strategy for updating model parameters, the Adam optimizer or SGD optimizer is used for parameter updates; the classification head consequent parameters and antecedent parameters in the TSK module are grouped with a learning rate setting, where the learning rate of the antecedent parameters is 0.2 to 0.5 times the total learning rate; gradient norm clipping is applied to the gradient vector of each viewpoint, constraining its L2 norm to satisfy... To avoid gradient explosion, among which, The gradient norm clipping threshold.
[0112] Specifically, parameter settings may include, but are not limited to, the following value ranges: the number of rules per viewpoint. The two perspectives take the same number of rules; the fuzzy index of fuzzy C-means clustering. The maximum number of iterations is 200; the total learning rate is 0.0003, and the antecedent parameter learning rate is 0.2 to 0.5 times the total learning rate; the batch size is 64; the training epochs are 10; and the gradient consistency loss weights are... Rule entropy and center separation regularization term weights Rule weights sparse regularization term weights The output consistency loss weight is set to in this embodiment. ; Central separation temperature parameters Gradient norm clipping threshold .
[0113] Based on the publicly available industrial dataset NEU-DET, a reproducible embodiment for workpiece surface defect detection is presented. In this embodiment, "dual perspective" refers to two representations of the same input image obtained through different feature extraction paths. Perspective 1 is the backbone feature extracted by the ResNet50 backbone network, and perspective 2 is the rule response feature generated by inputting the backbone feature into TSK fuzzing. Both datasets originate from the same image but have different mathematical forms and representation structures, thus forming a dual-perspective collaborative learning system.
[0114] This embodiment uses the NEU-DET hot-rolled steel strip surface defect dataset released by Northeastern University. This dataset contains six typical industrial defects: cracks, inclusions, patches, pitting, indented oxide scale, and scratches. To verify the anti-interference capability of this invention in complex industrial environments, we constructed a simulated industrial noise migration experiment:
[0115] Source domain: Uses original, clear training set images to simulate an offline acquisition environment under ideal lighting conditions.
[0116] Target domain: Gaussian noise (σ=0.05) and motion blur are applied to the original image to simulate environmental interference caused by conveyor belt vibration and sensor aging on the production line.
[0117] First, the input is an image from NEU-DET. After scaling and tensor quantization, it is normalized using the ImageNet standard mean and standard deviation. ,in , and These are the results of statistics obtained based on the ImageNet training set. The pixel mean and standard deviation of each channel are taken in this embodiment. , For the original image in the first The pixel values of each channel. These are the normalized pixel values. The preprocessed image is input into the deep backbone network and the TSK module respectively, forming two viewpoints. Viewpoint 1 features a 2048-dimensional depth representation, denoted as... The first feature is extracted from the ResNet50 backbone network; the second feature is obtained by transforming this depth feature using the TSK fuzzy system. To construct the TSK module, this embodiment performs fuzzy C-means clustering on the feature matrix of the first feature to obtain the number of rules. One (in this embodiment, take) ) Regular center vector and its corresponding predecessor width After obtaining the antecedent parameters, the TSK system uses the Gaussian membership function to calculate any eigenvector. Membership degree of the r-th rule To ensure that rule activation represents the relative contribution of each rule to the sample, the membership degrees of all rules are normalized to obtain normalized activation. ,in This is the numerical stability constant. Then, the normalized activation vector is concatenated with the original deep features to form the TSK consequent linear basis. And obtain the logits output of viewpoint 2 through linear mapping. ,in, This represents the learnable weight matrix of the TSK consequent linear mapping. To preserve the expressive power of deep features, this embodiment employs a residual fusion method, proportionally fusing the TSK output with the backbone features to form the final representation. .
[0118] During the supervised training phase, cross-entropy loss is used for labeled images. Furthermore, to improve the interpretability and discriminability of the rule set, rule entropy regularization is introduced. To constrain the sharpness of the activation distribution of the rules, a center separation regularization is introduced. This is used to avoid excessive overlap between different rule centers.
[0119] To address the training instability caused by inconsistent optimization directions between two perspectives, this invention proposes a cross-perspective gradient consistency constraint. The core idea is to calculate and normalize the gradients of the supervised loss with respect to the parameters of perspective 1 and perspective 2, introduce a bidirectional cosine alignment loss, and employ a strategy of first fixing the second perspective and updating only the first perspective, then fixing the first perspective and updating only the second perspective during training. This avoids the overhead of second-order gradients while enhancing optimization stability.
[0120] If unlabeled target domain samples exist, this embodiment further introduces cross-view output consistency constraints. This ensures that the prediction results from both perspectives are consistent on unlabeled samples.
[0121] In summary, the overall objective function of this embodiment is: ,in , , , , In this embodiment, we set the weight hyperparameters for each loss term. The training process used the Adam optimizer with a learning rate of 0.0003, a batch size of 64, and a total of 50 training epochs.
[0122] During the inference phase, the test images are input into the model using the same preprocessing method. The final 12-class probability predictions are obtained through dual-view feature fusion, and the classification results are output.
[0123] Table 1 compares the accuracy of surface defect detection in hot-rolled steel strip under noisy conditions. The results show that the gradient consistency method based on TSK proposed in this invention can maintain a high defect detection accuracy of 93.84% under common noise interference in industrial settings, verifying its effectiveness and reliability in actual industrial quality inspection.
[0124] Table 1
[0125]
[0126] Example 2: This example proposes an industrial workpiece surface defect detection system based on TSK fuzzy mapping. The system includes:
[0127] The data preparation and preprocessing module is configured to perform the following process: acquire surface image data of the workpiece to be inspected on the industrial production line using an image acquisition device, and preprocess the data; construct the data into dual-view data, including global semantic feature representation and local texture rule feature representation of the same workpiece;
[0128] The TSK calculation module is configured to perform the following process: input dual-view data into TSK, perform TSK fuzzy rule mapping on the input features of the two views respectively, map the features to the rule space through antecedent fuzzy inference, and then output the preliminary prediction result through consequent linear discriminant.
[0129] The supervision and regularization loss calculation module is configured to perform the following process: calculate the cross-entropy supervision loss based on labeled samples, and add rule entropy, rule center separation and rule weight sparsity regularization terms;
[0130] The gradient consistency constraint module is configured to perform the following process: calculate the gradient of the supervised loss with respect to the two-view model parameters, normalize it, and calculate the bidirectional cosine alignment loss as the cross-view gradient consistency loss, using a gradient-stopping operation during the calculation.
[0131] The joint optimization module is configured to perform the following process: constructing a total objective function, which is a weighted sum of the supervised loss, the cross-view gradient consistency loss, the rule entropy regularization term, the rule center separation regularization term, and the rule weight sparsity regularization term; and updating the model parameters using a two-step alternating optimization strategy, first applying a gradient-stopping operation to the second-view normalized gradient as a reference, updating only the first-view parameters, and then repeating the process by switching views.
[0132] The semi-supervised extension module is configured to perform the following process: if there are unlabeled samples, add an output consistency loss based on the KL divergence of the predicted outputs for the unlabeled samples from two perspectives to the total objective function;
[0133] The classification decision module is configured to perform the following process: inputting the image of the workpiece to be inspected into the trained model to obtain its corresponding defect category; generating control instructions based on the defect category to control the sorting equipment to classify or reject the workpiece.
[0134] Example 3: This example proposes an electronic device, including a memory, a processor, and a computer program stored in the memory and executable on the processor. When the computer program is executed, it implements the steps of the method described in this invention.
[0135] Example 4: This example proposes a computer-readable storage medium storing a computer program thereon. When the computer program is executed by a processor, it implements the steps of the method described in this invention, which will not be repeated here.
[0136] Example 5: This example proposes a computer program product, including a computer program / instructions. When the computer program / instructions are executed by a processor, they implement the steps of the method described in this invention, which will not be repeated here.
[0137] It should be noted that the processing flow of embodiments 2-5 corresponds to the specific steps of the method provided in embodiment 1 of the present invention, and has the corresponding functional modules and beneficial effects of the method. Technical details not described in detail in this embodiment can be found in the method provided in embodiment 1 of the present invention.
[0138] The program code used to implement the methods of this application may be written in any combination of one or more programming languages. This program code may be provided to a processor or controller of a general-purpose computer, special-purpose computer, or other programmable data processing device, such that when executed by the processor or controller, the functions / operations specified in the flowcharts and / or block diagrams are implemented. The program code may be executed entirely on a machine, partially on a machine, as a standalone software package partially on a machine and partially on a remote machine, or entirely on a remote machine or server.
[0139] The specific implementation schemes described above further illustrate the purpose, technical solution, and beneficial effects of the present invention. It should be understood that the above descriptions are merely specific implementation schemes of the present invention and are not intended to limit the scope of the present invention. Any equivalent changes and modifications made by those skilled in the art without departing from the concept and principles of the present invention should fall within the scope of protection of the present invention.
Claims
1. A method for detecting surface defects in industrial workpieces based on TSK fuzzy mapping, characterized in that, Includes the following steps: The surface image data of the workpiece to be inspected on the industrial production line is acquired using an image acquisition device, and the data is preprocessed; the data is constructed into dual-view data, including global semantic feature representation and local texture rule feature representation of the same workpiece; The dual-view data is input into TSK, and the input features of the two views are mapped by TSK fuzzy rules respectively. The features are mapped to the rule space through antecedent fuzzy inference, and the preliminary prediction results are output through consequent linear discriminant. Based on labeled samples, calculate cross-entropy supervision loss and add rule entropy, rule center separation and rule weight sparsity regularization terms; The gradient of the supervision loss with respect to the two-view model parameters is calculated. After normalization, the bidirectional cosine alignment loss is calculated as the cross-view gradient consistency loss. The gradient stopping operation is used in the calculation process. Construct a total objective function, which is the weighted sum of the supervision loss, the cross-view gradient consistency loss, the rule entropy regularization term, the rule center separation regularization term, and the rule weight sparsity regularization term; and update the model parameters using a two-step alternating optimization strategy. If there are unlabeled samples, an additional output consistency loss based on the KL divergence of the predicted output for unlabeled samples from two perspectives is added to the overall objective function; Input the image of the workpiece to be inspected into the trained model to obtain its corresponding defect category; Control instructions are generated based on the defect category to control the sorting equipment to classify or reject workpieces.
2. The method for detecting surface defects in industrial workpieces based on TSK fuzzy mapping according to claim 1, characterized in that, The data is preprocessed, including: dividing the data into training, validation and test sets, and performing normalization, standardization, missing value handling and feature encoding.
3. The method for detecting surface defects in industrial workpieces based on TSK fuzzy mapping according to claim 2, characterized in that, Constructing the overall objective function specifically includes the following steps: (1) Calculate the monitoring loss : ; in, Corresponding to first-person and second-person perspectives, collection This represents the set of manually labeled sample indices in the training set. This represents the number of elements in the set, for any labeled sample. , This is the true category label for the sample; For the first Viewpoint classifier for samples The output is the predicted class probability distribution vector; The standard multi-class cross-entropy loss function is used to measure the true label. With predicted probability The differences between them; (2) Calculate the rule entropy : ; in, Indicates the number of samples. It is the number of fuzzy rules for each viewpoint. It is a sample From the perspective Next Normalization activation of the rule, It is a constant that makes the value stable; (3) Separation of computation center : ; in, Indicates perspective No. The antecedent center of the rule, Indicates perspective No. The antecedent center of the rule, This represents the Euclidean distance between the center vectors of two rules. It is the temperature coefficient; (4) Calculation of sparse rule weights : ; in, It's a perspective The linear parameter matrix of the TSK aftermath. It is an L1 norm; (5) Calculate the consistency loss of unlabeled sample outputs : ; Among them, set This represents the set of unlabeled target domain sample indices. The number of elements in the set. and These are prediction probabilities from two perspectives. This represents the Kullback-Leibler divergence between two discrete probability distributions. (6) Calculate the cross-view gradient consistency loss : Define the gradient as That is, in the first From the perspective of all parameters, the gradient direction vector is obtained, where, For gradient operators, For the first All trainable parameters of the viewpoint The supervised loss is expressed with respect to the parameter. The gradient tensor, The flattening operator is used to expand the gradient tensor into a one-dimensional vector in a fixed order; the normalized gradient direction vector is defined as follows: , Let L be the Euclidean L2 norm of the vector. To prevent the denominator from being a tiny constant, the gradient consistency loss is defined as: ; By minimizing the 1-inner product between the normalized gradient directions of the two views, the gradient directions of the first and second views in the supervised loss are made consistent; at the same time, the following is utilized: Each item is restricted to updating parameters only from one viewpoint; where, This is the inner product operation of two vectors. This indicates that gradient propagation has stopped; (7) Calculate the overall objective function : ; in, , , , and These are the weights of each type of loss.
4. The method for detecting surface defects in industrial workpieces based on TSK fuzzy mapping according to claim 3, characterized in that, During the parameter update phase, in each training iteration, the second viewpoint is fixed first, and only the first viewpoint parameters are updated; Then, fix the first viewpoint and only update the parameters of the second viewpoint, thereby alternately aligning the gradient direction between the two views; the two-step alternating optimization strategy specifically includes: (1) Calculate the single-step loss of the first-view perspective using the following formula: ; Calculate the normalized gradients for the two perspectives using the current mini-batch training samples. and In the gradient consistency term, for use The operation is treated as a constant, and only applies to the parameter set of viewpoint 1. Backpropagation and updates are performed while the parameters of viewpoint 2 remain unchanged; (2) Calculate the single-step loss of the second perspective using the following formula: ; In this step, also based on the current mini-batch training samples, the normalized gradients of the supervised loss from each viewpoint with respect to their respective parameters are calculated. and In the gradient consistency term, for use The operation is treated as a constant; only the parameter set of viewpoint 2 is considered. Backpropagation and updates are performed, and the parameters of viewpoint 1 remain unchanged.
5. The method for detecting surface defects in industrial workpieces based on TSK fuzzy mapping according to claim 4, characterized in that, During the two-step alternating optimization strategy for updating model parameters, either the Adam optimizer or the SGD optimizer is used. Group learning rates are applied to the classification head consequent and antecedent parameters in the TSK module, with the antecedent parameter's learning rate being 0.2 to 0.5 times the total learning rate. Gradient norm clipping is applied to the gradient vectors of each viewpoint, constraining their L2 norm to satisfy... To avoid gradient explosion, among which, The gradient norm clipping threshold.
6. The method for detecting surface defects in industrial workpieces based on TSK fuzzy mapping according to claim 5, characterized in that, The parameter settings used in the method include the following value ranges: Number of rules per perspective The two perspectives take the same number of rules; the fuzzy index of fuzzy C-means clustering. The maximum number of iterations is 200; The total learning rate is 0.001, and the antecedent parameter learning rate is 0.2 to 0.5 times the total learning rate; the batch size is 64; the training epochs are 10; and the gradient consistency loss weights are used. Rule entropy and center separation regularization term weights Rule weights sparse regularization term weights ; In this embodiment, the output consistency loss weight is set to ; Central separation temperature parameters Gradient norm clipping threshold .
7. An industrial workpiece surface defect detection and classification system based on TSK fuzzy mapping, characterized in that, The system includes: The data preparation and preprocessing module is configured to perform the following process: acquire surface image data of the workpiece to be inspected on the industrial production line using an image acquisition device, and preprocess the data; construct the data into dual-view data, including global semantic feature representation and local texture rule feature representation of the same workpiece; The TSK calculation module is configured to perform the following process: input dual-view data into TSK, perform TSK fuzzy rule mapping on the input features of the two views respectively, map the features to the rule space through antecedent fuzzy inference, and then output the preliminary prediction result through consequent linear discriminant. The supervision and regularization loss calculation module is configured to perform the following process: calculate the cross-entropy supervision loss based on labeled samples, and add rule entropy, rule center separation and rule weight sparsity regularization terms; The gradient consistency constraint module is configured to perform the following process: calculate the gradient of the supervised loss with respect to the two-view model parameters, normalize it, and calculate the bidirectional cosine alignment loss as the cross-view gradient consistency loss, using a gradient-stopping operation during the calculation. The joint optimization module is configured to perform the following process: constructing a total objective function, which is the weighted sum of the supervised loss, the cross-view gradient consistency loss, and the rule entropy regularization term, the rule center separation regularization term, and the rule weight sparsity regularization term; and updating the model parameters using a two-step alternating optimization strategy, first applying a gradient-stopping operation to the second-view normalized gradient as a reference, updating only the first-view parameters, and then repeating the process by switching views. The semi-supervised extension module is configured to perform the following process: if there are unlabeled samples, add an additional output consistency loss based on the KL divergence of the predicted output for the unlabeled samples from two perspectives to the total objective function; The classification decision module is configured to perform the following process: inputting the image of the workpiece to be inspected into the trained model to obtain its corresponding defect category; generating control instructions based on the defect category to control the sorting equipment to classify or reject the workpiece.
8. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that, When the computer program is executed, it implements the steps of the method as described in any one of claims 1 to 6.
9. A computer-readable storage medium having a computer program stored thereon, characterized in that, The computer program is configured to implement the steps of the method according to any one of claims 1 to 6 when invoked by a processor.
10. A computer program product comprising a computer program / instructions, characterized in that, When the computer program / instructions are executed by the processor, they implement the steps of the method according to any one of claims 1 to 6.