Industrial defect detection model training method and industrial defect detection method

By optimizing weights and biases, and combining generative adversarial networks and manifold mapping learning, the problems of low efficiency and unstable gradients in traditional industrial defect detection are solved, achieving efficient and accurate industrial defect detection.

CN119295812BActive Publication Date: 2026-06-09WUYI UNIV

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
WUYI UNIV
Filing Date
2024-09-25
Publication Date
2026-06-09

Smart Images

  • Figure CN119295812B_ABST
    Figure CN119295812B_ABST
Patent Text Reader

Abstract

The application provides a training method of an industrial defect detection model and an industrial defect detection method. The weight and bias of the model are optimized through the energy value of the model. When the energy value reaches a dynamic balance state, the target weight is obtained by updating the candidate weight according to the updated temperature value, and the target bias is obtained by updating the candidate bias according to the updated temperature value. The trained industrial defect detection model is obtained according to the target weight and the target bias. The problem of gradient vanishing or explosion is avoided by optimizing the weight and bias of the network, and the stability of training and the performance of the model are improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of industrial inspection, and more particularly to a training method for an industrial defect detection model and an industrial defect detection method. Background Technology

[0002] In industrial production, even minor defects on the surface of industrial products, such as cracks, scratches, or corrosion, can seriously affect product quality and safety. Industrial defect detection has become an indispensable part of the production process. Traditional industrial defect detection mainly relies on manual visual inspection, which is inefficient, susceptible to subjective factors, and makes it difficult to guarantee consistency and reliability.

[0003] To improve detection efficiency and accuracy, automated defect detection technologies have emerged, with image processing and machine learning methods being widely used due to their efficiency and scalability. However, because industrial defects are diverse and varied in form, traditional machine learning models may encounter gradient vanishing or exploding problems during training, affecting the model's training stability and performance. Summary of the Invention

[0004] The following is an overview of the subject matter described in detail herein. This overview is not intended to limit the scope of the claims.

[0005] The purpose of this application is to at least partially solve one of the technical problems existing in the related technologies. The embodiments of this application provide a training method for an industrial defect detection model and an industrial defect detection method, which avoids the problem of gradient vanishing or exploding by optimizing weights and biases.

[0006] An embodiment of the first aspect of this application provides a method for training an industrial defect detection model, comprising:

[0007] Acquire training industrial product images and input the training industrial product images into the initial industrial defect detection model;

[0008] A first energy value is set according to the first weight, first bias and adaptive parameters of the initial industrial defect detection model, wherein the adaptive parameters are based on the importance of training industrial product images at different scales.

[0009] The first weight is updated according to the weight adjustment value to obtain the second weight, and the first bias is updated according to the bias adjustment value to obtain the second bias;

[0010] The second energy value is set according to the second weight, the second bias, and the adaptive parameter;

[0011] When the energy change is less than the energy change threshold, the second weight is used as a candidate weight and the second bias is used as a candidate bias, wherein the energy change is the difference between the first energy value and the second energy value.

[0012] A third energy value is obtained based on the probability of the target output data output from the candidate weights, the candidate biases, and the training industrial product images.

[0013] Update the temperature value based on the energy change;

[0014] When the third energy value reaches a dynamic equilibrium state, the candidate weights are updated according to the updated temperature value to obtain the third weights, and the candidate biases are updated according to the updated temperature value to obtain the third biases.

[0015] The trained industrial defect detection model is obtained based on the third weight and the third bias.

[0016] According to certain embodiments of the first aspect of this application, before inputting the trained industrial product image into the initial industrial defect detection model, the method further includes:

[0017] Generative adversarial training is performed using the trained industrial product images through a generative adversarial network to obtain generated images.

[0018] The generated image is scored based on multiple different quality indicators to obtain a quality score.

[0019] The loss function of the generator of the generative adversarial network is obtained based on the quality score, and the parameters of the generator are adjusted according to the loss function to obtain the target generator;

[0020] The training industrial product image is enhanced using the target generator to obtain the enhanced training industrial product image.

[0021] The quality metric is based on the similarity between the generated image and the reference image, as well as the variability of the generated image.

[0022] According to certain embodiments of the first aspect of this application, the first energy value is expressed by the following formula: In the formula, E1(w,b) represents the first energy value, and x i Let y represent the i-th training industrial product image. i Let w represent the first weight, b represent the first bias, N represent the number of training industrial product images, K represent the scale of the features of the training industrial product images, and α represent the output data of the i-th target. k (t) represents the adaptive parameter corresponding to the feature at the k-th scale.

[0023] According to certain embodiments of the first aspect of this application, the adaptive parameter is expressed by the following formula: In the formula, α k (t) represents the adaptive parameter, E k (t-1) represents the loss value of the feature corresponding to the k-th scale at time t-1, E j (t-1) represents the loss value of the feature corresponding to the j-th scale at time t-1, β k β represents the importance of the feature corresponding to the k-th scale. j This indicates the importance of the feature corresponding to the j-th scale.

[0024] According to certain embodiments of the first aspect of this application, the energy change threshold is updated according to the following formula: In the formula, Θ(t) represents the energy change threshold at time t, Θ(t-1) represents the energy change threshold at time t-1, E2(t-1) is the second energy value at time t-1, and σ E E represents the standard deviation of energy change. target Indicates the target energy value, ν eo It is a constant parameter.

[0025] According to certain embodiments of the first aspect of this application, the probability of outputting target output data from the candidate weights, the candidate biases, and the training industrial product images is expressed by the following formula: In the formula, p(y i |x i (w2, b2) represents the probability of outputting target data based on the candidate weights, the candidate bias, and the training industrial product image; x i Let y represent the i-th training industrial product image. i w represents the output data of the i-th target. j 'b' represents the candidate weight. k For candidate bias, σ std This represents the standard deviation of the target output data.

[0026] According to certain embodiments of the first aspect of this application, the third weight is expressed by the following formula: w new =w j '+ in, In the formula, w new Indicates the third weight, w j ' represents the candidate weight, b' k Indicates the candidate bias, β rate This indicates that the learning rate is being updated. μ represents the fusion adjustment factor. ea Δw represents the momentum coefficient, and Δw represents the update amount of the third weight. prev T represents the update amount of the previous third weight. new This indicates the updated temperature value. The gradient of the third weight is represented by the following formula: b new =b' k +β rate Δb; where, In the formula, b new Indicates the third bias, b' k Let Δb represent the candidate bias, and let Δb represent the update amount of the third bias. prev This indicates the update amount of the previous third bias. This represents the gradient of the third bias; where the fusion adjustment factor is dynamically set based on the historical changes of the third weight and the error rate of the current layer of the initial industrial defect detection model.

[0027] According to a second aspect of this application, an industrial defect detection method includes:

[0028] Acquire images of the industrial products to be inspected;

[0029] The image of the industrial product to be detected is input into a trained industrial defect detection model to perform industrial defect detection and obtain the detection result.

[0030] The trained industrial defect detection model is obtained by training the industrial defect detection model according to the training method of the first aspect of this application.

[0031] According to a third aspect of this application, an electronic device includes: a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the computer program, it implements a training method for an industrial defect detection model as described in an embodiment of a first aspect of this application or an industrial defect detection method as described in an embodiment of a second aspect of this application.

[0032] According to a fourth aspect of this application, a computer storage medium stores computer-executable instructions for performing a training method for an industrial defect detection model as described in an embodiment of a first aspect of this application or an industrial defect detection method as described in an embodiment of a second aspect of this application.

[0033] The above scheme has at least the following beneficial effects: A first energy value is set based on the first weight, first bias, and adaptive parameters of the initial industrial defect detection model; a second weight is obtained by updating the first weight based on the weight adjustment value, and a second bias is obtained by updating the first bias based on the bias adjustment value; a second energy value is set based on the second weight, second bias, and adaptive parameters; when the energy change is less than the energy change threshold, the second weight and the second bias are used as candidate weights and candidate biases, with the energy change being the difference between the first and second energy values; a third energy value is obtained based on the candidate weights, candidate biases, and the probability of output data from the target of the trained industrial product image; the temperature value is updated based on the energy change; when the third energy value reaches a dynamic equilibrium state, the candidate weights are updated based on the updated temperature value to obtain the third weight, and the candidate biases are updated based on the updated temperature value to obtain the third bias; a trained industrial defect detection model is obtained based on the third weight and the third bias; the problem of gradient vanishing or exploding is avoided by optimizing the network weights and biases, thus improving the stability of training and model performance. Attached Figure Description

[0034] The accompanying drawings are used to provide a further understanding of the technical solutions of this application and constitute a part of the specification. They are used together with the embodiments of this application to explain the technical solutions of this application and do not constitute a limitation on the technical solutions of this application.

[0035] Figure 1 This is a flowchart illustrating the steps of an industrial defect detection method provided in an embodiment of this application;

[0036] Figure 2 This is a flowchart illustrating the steps of the training method for the industrial defect detection model provided in the embodiments of this application;

[0037] Figure 3 This is a step diagram illustrating the image enhancement process for training industrial product images provided in an embodiment of this application;

[0038] Figure 4 This is a structural diagram of a generative adversarial network provided in an embodiment of this application;

[0039] Figure 5 This is a structural diagram of the feature dimensionality reduction model provided in the embodiments of this application. Detailed Implementation

[0040] To make the objectives, technical solutions, and advantages of this application clearer, the following detailed description is provided in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative and not intended to limit the scope of this application.

[0041] It should be noted that although functional modules are divided in the device schematic diagram and a logical order is shown in the flowchart, in some cases, the steps shown or described may be performed in a different order than the module division in the device or the order in the flowchart. The terms "first," "second," etc., in the specification, claims, or the aforementioned drawings are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence.

[0042] The embodiments of this application provide a training method for an industrial defect detection model and an industrial defect detection method.

[0043] The embodiments of this application will be further described below with reference to the accompanying drawings.

[0044] Reference Figure 1 An industrial defect detection method includes the following steps:

[0045] Step S10: Obtain an image of the industrial product to be inspected;

[0046] Step S20: Input the image of the industrial product to be detected into the trained industrial defect detection model to perform industrial defect detection and obtain the detection result.

[0047] The reference model obtained by training the well-trained industrial defect detection model according to the following industrial defect detection model training method Figure 2 The training method for an industrial defect detection model includes the following steps;

[0048] Step S100: Obtain training industrial product images and input the training industrial product images into the initial industrial defect detection model;

[0049] Step S200: Set the first energy value according to the first weight, first bias and adaptive parameters of the initial industrial defect detection model;

[0050] Step S300: Update the first weight according to the weight adjustment value to obtain the second weight, and update the first bias according to the bias adjustment value to obtain the second bias;

[0051] Step S400: Set the second energy value according to the second weight, the second bias, and the adaptive parameters;

[0052] Step S500: When the energy change is less than the energy change threshold, the second weight is used as a candidate weight and the second bias is used as a candidate bias.

[0053] Step S600: Obtain the third energy value based on the candidate weights, candidate biases, and the probability of the target output data from the training industrial product image;

[0054] Step S700: Update the temperature value based on the energy change.

[0055] Step S800: When the third energy value reaches a dynamic equilibrium state, the candidate weights are updated according to the updated temperature value to obtain the third weight, and the candidate biases are updated according to the updated temperature value to obtain the third bias.

[0056] Step S900: Obtain the trained industrial defect detection model based on the third weight and the third bias.

[0057] In step S100, training industrial product images are acquired. These images are obtained by capturing images of the industrial products using a high-resolution industrial camera. The industrial camera can capture minute defects on the product surface, such as cracks, scratches, or corrosion. The data is stored in JPG format. The data is manually labeled, indicating the type of defect in the image. Each sample is labeled to form a training dataset for subsequent model training. For example, the labeled categories include cracks, scratches, corrosion, and others, a total of four categories.

[0058] Since the acquisition, labeling, and preprocessing of training data are time-consuming and labor-intensive, and insufficient training samples can easily lead to poor model generalization ability and affect model accuracy, a multi-agent generative adversarial network is used to generate samples, thereby expanding the input data.

[0059] Reference Figure 3 Image enhancement of training industrial product images includes the following steps:

[0060] Step S110: Generative adversarial training is performed using the training industrial product images through a generative adversarial network to obtain generated images;

[0061] Step S120: The generated image is scored according to multiple different quality indicators to obtain a quality score.

[0062] Step S130: Obtain the loss function of the generator of the generative adversarial network based on the quality score, and adjust the parameters of the generator according to the loss function to obtain the target generator;

[0063] Step S140: Image enhancement is performed on the training industrial product image according to the target generator to obtain the enhanced training industrial product image.

[0064] The quality metrics are based on the similarity between the generated image and the reference image, as well as the variability of the generated image.

[0065] Reference Figure 4Generative Adversarial Networks (GANs) consist of a generator and a discriminator. The generator is responsible for generating new data that is as close to real data as possible, while the discriminator distinguishes the generated data from the real data. A multi-agent loss function is employed for adjustment. Each generated data sample not only needs to deceive the discriminator but also needs to meet specific quality indicators determined by the multi-agent system. This makes the generated data more suitable for the specific needs of defect detection tasks, improving the data's practicality and relevance.

[0066] Initialize the network parameters of the generator and discriminator. Set the initial parameters of the generator and discriminator based on a Gaussian distribution. The initial parameters of the generator can be expressed as follows: The initial parameters of the discriminator can be expressed as: In the formula, ~ indicates that it follows a specific distribution, θ g and θ d These represent the parameters of the generator and discriminator, respectively; σ 2 This represents the initial standard deviation. It is represented by a Gaussian distribution.

[0067] We select a set of real industrial product images as the training dataset, denoted as the real dataset. A random sample of data x can be represented as: The generator G receives random noise z and generates a batch of images based on the current network parameters and the input noise data. The noise follows a standard normal distribution, which can be expressed as: Generate image It can be represented as: In the formula, z represents the input noise vector; I is the identity matrix; This refers to the generated image produced by the generator G; G is the generator function. For example, the generator function G, implemented using a neural network with the tanh activation function, can be represented as: G(z; θ) g ) = tanh(W g ·z+b g In the formula, W g It is the weight matrix of the generator, b g is the bias vector of the generator; tanh is the activation function used to normalize the generated output image to the range [-1, 1].

[0068] A multi-agent system is used to evaluate the quality and diversity of generated images. Multi-agent system A evaluates the generated images, with each agent evaluating based on a preset quality metric f. i The scoring process can be represented as follows: In the formula, s i It is agent a iThe generated image is rated; S is the average rating of all agents; N is the total number of agents. For example, the rating function f... i It can be represented as: In the formula, α i and β i It is a weighting coefficient; preferably, α i and β i Set them to 0.3 and 0.7 respectively. Indicates the generated image Compared with reference image x ref Similarity measure between Indicates the generated image The degree of variability.

[0069] The discriminator receives fake and real images from the generator. Its training objective is to maximize its classification accuracy, hoping to correctly classify both types of images. The discriminator's loss function can be expressed as: In the formula, L d is the loss function of the discriminator; D(x) is the output of the discriminator to the real image x; For generated images The output of . Furthermore, the terms in the discriminator's loss function can be further expanded as follows: Where m and n represent the number of samples of real data and generated images, respectively, and x (j) It is the j-th real image. It is the kth generated image.

[0070] Based on the multi-agent scoring results, the generator's loss function is adjusted to optimize the generation process, making the generated fake images better meet the quality requirements. The generator's loss function can be expressed as: Among them, L g λ is the loss function of the generator; λ is the weight parameter that controls the influence of multi-agent scoring.

[0071] A multi-agent system is used to evaluate the quality and diversity of the generated data samples. Images are scored according to preset quality indicators, and these scores are used to adjust the loss function, thereby generating data that is more suitable for defect detection tasks.

[0072] Repeat the above steps iteratively until a preset stopping condition is met, indicating that the generative adversarial network training is complete. The preset stopping condition is reaching a preset maximum number of iterations, preferably set to 1000.

[0073] By using multi-agent generative adversarial networks (GANs), the training dataset can be effectively expanded, increasing sample diversity and thus improving the model's ability to identify different types of defects. Data augmentation helps avoid overfitting, ensuring that the trained model not only performs well on the training set but also maintains high recognition accuracy on unseen samples. The application of multi-agent systems makes the generated data more closely aligned with the actual needs of defect detection, helping to improve the model's accuracy in identifying subtle defects.

[0074] The image-enhanced training images of industrial products are input into the initial industrial defect detection model.

[0075] The initial industrial defect detection model uses a three-layer fully connected neural network for feature extraction and classification. The last layer is the classification layer, and the number of neurons in the last layer is the same as the number of categories, with four neurons. The fully connected neural network includes an input layer and two hidden layers, with a pre-defined output layer for supervised training of the categories. The definitions are as follows: Input layer: If the dimension of the input vector is *x*, then the input layer has *x* neurons, corresponding to *x* elements in the vector; Hidden layers: Both hidden layers have 128 neurons, using ReLU as the activation function; Output layer: The output layer uses the softmax function as the activation function.

[0076] For step S200, the first energy value is set according to the first weight, first bias and adaptive parameters of the initial industrial defect detection model.

[0077] Initialize the neural network parameters by assigning them random energy states. Specifically, initialize the weights w and biases b of the neural network.

[0078] The energy state is defined to describe the potential optimization capability of parameters, and can be expressed as: In the formula, E1(w,b) represents the first energy value, and x i Let y represent the i-th training industrial product image. i Let w represent the first weight, b represent the first bias, N represent the number of training industrial product images, K represent the scale of the features of the training industrial product images, and α represent the output data of the i-th target. k (t) represents the adaptive parameter corresponding to the feature at the k-th scale. The importance of training industrial product images at different scales depends on the training time t and the current performance state of the network, ensuring that the focus of the loss function is adjusted at different stages of training.

[0079] It is understandable that the initial weight is the first weight, the initial bias is the first bias, and the initial energy state is the first energy value.

[0080] Furthermore, α k(t) is dynamically updated at each iteration, allowing the model to focus on different feature levels at different training stages, thus more effectively learning the multi-level structure of complex data. Specifically, the weights α for each scale... k The update of (t) depends on the effect of this scale in the current training state, and the adaptive parameter update method can be expressed as: In the formula, α k (t) represents the adaptive parameter, E k (t-1) represents the loss value of the feature corresponding to the k-th scale at time t-1, E j (t-1) represents the loss value of the feature corresponding to the j-th scale at time t-1, β k β represents the importance of the feature corresponding to the k-th scale. j β represents the importance of the feature corresponding to the j-th scale. k and β j Pre-set assumptions are made based on the characteristics of the scale.

[0081] For each pair of parameters (weights and biases), a fusion candidate check is performed. If the second energy value corresponding to the two parameters can reduce the overall system energy, fusion is allowed, that is, the second weight is used as a candidate weight and the second bias is used as a candidate bias; otherwise, they are kept independent, that is, the first weight and the second weight are kept.

[0082] For step S300, the first weight is updated according to the weight adjustment value to obtain the second weight, and the first bias is updated according to the bias adjustment value to obtain the second bias.

[0083] The second weight is represented as: w j '=w j +δ tr The weight adjustment value is expressed as:

[0084] The second bias is represented as: b' k =b k +∈ tr The bias adjustment value is expressed as:

[0085] w j For the j-th first weight, w j ' is the j-th second weight; b k For the k-th first bias, b' k This is the kth second bias.

[0086] Where, σ to and η to It refers to the sensitivity and scaling factor for fusion adjustment. Preferably, σ to and η toSet them to 0.1 and 0.3 respectively.

[0087] For step S400, the second energy value is set according to the second weight, the second bias, and the adaptive parameters.

[0088] The second energy value can be expressed as:

[0089] For step S500, when the energy change is less than the energy change threshold, the second weight is used as a candidate weight and the second bias is used as a candidate bias.

[0090] The change in energy is the difference between the first energy value and the second energy value. The change in energy is expressed as: ΔE = E(w) j ',b' k )-E(w j ,b k ).

[0091] The energy threshold Θ(t) is updated at each iteration. By monitoring energy changes in real time during training, the sensitivity and frequency of parameter updates are dynamically adjusted accordingly. The energy change threshold is updated according to the following formula: In the formula, Θ(t) represents the energy change threshold at time t, Θ(t-1) represents the energy change threshold at time t-1, E2(t-1) is the second energy value at time t-1, and σ E E represents the standard deviation of energy change. target Indicates the target energy value, ν eo ν is a constant parameter. Preferably, ν eo Set to 0.01, E target Set it to 0.1.

[0092] For step S600, the candidate weights and candidate biases are re-evaluated using the third energy value to ensure energy minimization.

[0093] The third energy value is obtained based on the probability of the target output data from the candidate weights, candidate biases, and training industrial product images.

[0094] The probability of outputting target data from the candidate weights, candidate biases, and training industrial product images is expressed by the following formula: In the formula, p(y i |x i (w2,b2) represents the probability of outputting target data from the candidate weights, candidate biases, and training industrial product images, where x is the probability of outputting target data. i Let y represent the i-th training industrial product image. i w represents the output data of the i-th target. j 'b' represents the candidate weight. kFor candidate bias, σ std This represents the standard deviation of the target output data.

[0095] The third energy value is represented as: Here, E3(w,b) represents the third energy value.

[0096] For step S700, the temperature value is updated based on the energy change.

[0097] Specifically, the temperature value is adjusted based on the current network performance and stability. The temperature value can be expressed by the following formula: T new =T old ·exp(-α te ΔE); where α te T represents the temperature regulation factor. new This represents the updated temperature value, T. old The value represents the temperature before the update, and ΔE represents the change in energy.

[0098] For the temperature regulation factor, α te Dynamically adjusted based on energy changes. α te It can be represented as: Among them, κ te It is a preset adjustment coefficient, |ΔE| is the absolute energy change, and E avg It is the average energy of all current parameters.

[0099] For step S800, when the third energy value reaches a dynamic equilibrium state, the candidate weights are updated according to the updated temperature value to obtain the third weight, and the candidate biases are updated according to the updated temperature value to obtain the third bias.

[0100] When Var(E3) < ∈ mr If the value reaches a certain threshold, it is determined that the third energy value has reached a dynamic equilibrium state. Here, Var(E3) represents the variance function of the third energy value; preferably, ∈ mr Set to 10 -5 .

[0101] The decision to update the current parameter configuration is based on the principle of energy optimization, i.e., updating the candidate weights and candidate biases.

[0102] The third weight is expressed by the following formula: in, In the formula, w new Indicates the third weight, w j ' represents the candidate weight, b' k Indicates the candidate bias, β rate This indicates that the learning rate is being updated. μ represents the fusion adjustment factor.ea Δw represents the momentum coefficient, and Δw represents the update amount of the third weight. prev T represents the update amount of the previous third weight. new This indicates the updated temperature value. The gradient of the third weight is represented by the following formula: b new =b' k +β rate Δb; where, In the formula, b new Indicates the third bias, b' k Let Δb represent the candidate bias, and let Δb represent the update amount of the third bias. prev This indicates the update amount of the previous third bias. This represents the gradient of the third bias.

[0103] Among them, the fusion adjustment factor The fusion adjustment factor is dynamically set based on the historical changes of the third weight and the error rate of the current layer of the initial industrial defect detection model. Specifically, the fusion adjustment factor can be expressed as: In the formula,

[0104] It is the difference between the current weight and the weight of the previous iteration; It is the standard deviation of the change in the weights of the current layer; E l It is the error rate of the current layer; ρ yt and λ yt These are adjustment coefficients that control the influence of the weight change rate and the error rate, respectively; tanh is the hyperbolic tangent function. Preferably, ρ yt and λ yt Set them to 0.3 and 0.5 respectively.

[0105] The convergence of the algorithm is determined by the magnitude of parameter energy changes after multiple iterations. If convergent, the final optimized parameters are output; if not, the process returns to the previous steps to continue iterating. The convergence determination method can be expressed as: In the formula, E new For the updated energy state, E old The energy state before parameter update, γ ew This is the convergence threshold. Preferably, the convergence threshold γ ew Set to 10 -6 .

[0106] For step S900, the trained neural network is obtained based on the third weight and the third bias.

[0107] Feature extraction is performed using the neural network described above. The extracted features are then input into a feature dimensionality reduction model to train the model.

[0108] Feature dimensionality reduction is achieved using an autoencoder neural network (ANN) that learns from manifold maps. This ANN not only learns the intrinsic structure of the data during the encoding phase but also attempts to reconstruct the input during the decoding process, ensuring that the reduced features retain key information. (See reference...) Figure 5 The feature dimensionality reduction model consists of an encoder and a decoder. The encoder maps high-dimensional input data to a low-dimensional feature space, while the decoder reconstructs the original input data from this low-dimensional space. The Riemannian factor, learned from manifolds, is used to optimize the representation of the feature space. Leveraging the geometric properties of the Riemannian manifold allows for a better understanding of the local structure of the data, leading to more accurate data reconstruction.

[0109] The weights w of the autoencoder are initialized using a Gaussian distribution. cr and bias b cr The parameters, weights w cr It can be represented as: bias b cr It can be represented as: In the formula, σ represents the weight of the i-th layer. ch Indicates standard deviation, n ”in "This is the number of nodes in the input layer."

[0110] During encoding, the input data is encoded and mapped to a low-dimensional feature space by the encoder; during decoding, the decoder attempts to reconstruct the original data. Specifically, through an autoencoder, the data x... cr The way that is mapped to the low-dimensional feature space z can be represented as: The decoder attempts to reconstruct the original input x cr The ^ method can be represented as: In the formula, Sig is the activation function; and These are the encoder's weights and biases, respectively. and These are the decoder's weights and biases, respectively.

[0111] Weight The calculation method, which is pre-defined using principal component analysis, can be expressed as follows: In the formula, V k From the covariance matrix The matrix formed by the first k eigenvectors, Σ k It is the corresponding eigenvalue diagonal matrix.

[0112] In the low-dimensional space of the encoding, the Riemann factor R is used to achieve manifold learning. The way the Riemann factor constrains the encoding of the feature z can be expressed as: In the formula, μ cy σ represents the predefined manifold center. R It is a parameter that controls the compactness of the manifold. Preferably, μ cy Set as the mean vector of a low-dimensional space, σ R Set it to 0.1.

[0113] The loss function considers not only reconstruction error but also Riemannian manifold constraints. Reconstruction error ensures that the data can be effectively restored, while manifold constraints strengthen the geometric structure of the feature space. The loss function Lu can be expressed as: Lu = ||x cr -x cr ^∥ 2 +λ cm R; where λ cm It is the regularization coefficient. Preferably, λ cm Set it to 0.3.

[0114] Furthermore, the reconstruction error ∥x cr -x cr ^∥ 2 The calculation method can be expressed as: In the formula, z i μ is the value of z in the i-th dimension. i It is the value of the pre-defined manifold center in the i-th dimension.

[0115] Based on the loss function, the network parameters are adjusted using the backpropagation algorithm to optimize the performance of the encoder and decoder. (Based on weights) For example, its gradient can be calculated as follows: Furthermore, gradient Calculated using the error backpropagation method, it can be expressed as: Through decoder weights The transpose of can be represented as: Furthermore, since z is and x cr The result obtained by applying an activation function to a linear combination of these is then... The calculation method can be expressed as: In the formula, Sig' is the derivative of the Sigmoid activation function, and diag(vs) represents a diagonal matrix with vector vs as its diagonal elements. It is x cr The transpose of . Further, the parameters are updated using gradient descent, which can be expressed as: In the formula, α rv This represents the learning rate, and t represents the number of iterations. For the updated weight parameters, These are the weight parameters before the update. Preferably, α rv Set to 0.05.

[0116] Finally, repeat the above steps iteratively until a preset stopping iteration condition is met, indicating that the model training is complete. In one embodiment, the preset stopping iteration condition is reaching a preset maximum number of iterations; preferably, the preset maximum number of iterations is set to 1000.

[0117] By combining a trained neural network and a trained feature dimensionality reduction model, a trained industrial defect detection model is obtained.

[0118] An embodiment of this application provides an electronic device. The electronic device includes: a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the computer program, it implements the training method for the industrial defect detection model or the industrial defect detection method described above.

[0119] This electronic device can be any smart terminal, including computers.

[0120] In general, for the hardware structure of electronic devices, the processor can be implemented using a general-purpose CPU (Central Processing Unit), microprocessor, application-specific integrated circuit (ASIC), or one or more integrated circuits, to execute relevant programs and implement the technical solutions provided in the embodiments of this application.

[0121] The memory can be implemented in the form of read-only memory (ROM), static storage device, dynamic storage device, or random access memory (RAM). The memory can store the operating system and other applications. When the technical solutions provided in the embodiments of this specification are implemented through software or firmware, the relevant program code is stored in the memory and is called and executed by the processor.

[0122] Input / output interfaces are used to implement information input and output.

[0123] The communication interface is used to enable communication and interaction between this device and other devices. Communication can be achieved through wired means (such as USB, Ethernet cable, etc.) or wireless means (such as mobile network, WIFI, Bluetooth, etc.).

[0124] The bus transmits information between various components of a device, such as the processor, memory, input / output interfaces, and communication interfaces. The processor, memory, input / output interfaces, and communication interfaces communicate with each other within the device via the bus.

[0125] An embodiment of this application provides a computer storage medium. The computer storage medium stores computer-executable instructions for executing the training method or industrial defect detection method of the industrial defect detection model described above.

[0126] It will be understood by those skilled in the art that all or some of the steps and systems in the methods disclosed above can be implemented as software, firmware, hardware, and suitable combinations thereof. Some or all of the physical components can be implemented as software executed by a processor, such as a central processing unit, digital signal processor, or microprocessor, or as hardware, or as an integrated circuit, such as an application-specific integrated circuit. Such software can be distributed on a computer-readable medium, which can include computer storage media (or non-transitory media) and communication media (or transient media). As is known to those skilled in the art, the term computer storage media includes volatile and non-volatile, removable and non-removable media implemented in any method or technology for storing information (such as computer-readable instructions, data structures, program modules, or other data). Computer storage media includes, but is not limited to, RAM, ROM, EEPROM, flash memory or other memory technologies, CD-ROM, digital versatile disc (DVD) or other optical disc storage, magnetic cartridges, magnetic tape, disk storage or other magnetic storage devices, or any other medium that can be used to store desired information and is accessible to a computer. Furthermore, it is well known to those skilled in the art that communication media typically contain computer-readable instructions, data structures, program modules, or other data in modulated data signals such as carrier waves or other transmission mechanisms, and may include any information delivery medium. In the foregoing description of this specification, references to terms such as "one embodiment," "another embodiment," or "some embodiments," etc., indicate that a specific feature, structure, material, or characteristic described in connection with an embodiment or example is included in at least one embodiment or example of this application. In this specification, illustrative expressions of the above terms do not necessarily refer to the same embodiment or example. Moreover, the specific features, structures, materials, or characteristics described may be combined in any suitable manner in one or more embodiments or examples.

[0127] Those skilled in the art will understand that all or some of the steps in the methods disclosed above, as well as the functional modules / units in the systems and devices, can be implemented as software, firmware, hardware, or suitable combinations thereof.

[0128] The units described above as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the units can be selected to achieve the purpose of this embodiment according to actual needs.

[0129] Furthermore, the functional units in the various embodiments of this application can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The integrated unit can be implemented in hardware or as a software functional unit.

[0130] If the integrated unit is implemented as a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of this application, in essence, or the part that contributes to the prior art, or all or part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes multiple instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods of the various embodiments of this application. The aforementioned storage medium includes various media capable of storing programs, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.

[0131] In the several embodiments provided in this application, it should be understood that the disclosed apparatus and methods can be implemented in other ways. For example, the apparatus embodiments described above are merely illustrative; for instance, the division of the units described above is only a logical functional division, and in actual implementation, there may be other division methods. For example, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed. Furthermore, the coupling or direct coupling or communication connection shown or discussed between each other may be through some interfaces; the indirect coupling or communication connection between apparatuses or units may be electrical, mechanical, or other forms. Although embodiments of this application have been shown and described, those skilled in the art will understand that various changes, modifications, substitutions, and variations can be made to these embodiments without departing from the principles and spirit of this application, the scope of which is defined by the claims and their equivalents.

[0132] The above is a detailed description of the preferred embodiments of this application, but this application is not limited to the embodiments. Those skilled in the art can make various equivalent modifications or substitutions without departing from the spirit of this application, and these equivalent modifications or substitutions are all included within the scope defined by the claims of this application.

Claims

1. A training method for an industrial defect detection model, characterized in that, include: Acquire training industrial product images and input the training industrial product images into the initial industrial defect detection model; A first energy value is set according to the first weight, first bias and adaptive parameters of the initial industrial defect detection model, wherein the adaptive parameters are set based on the importance of training industrial product images at different scales. The first weight is updated according to the weight adjustment value to obtain the second weight, and the first bias is updated according to the bias adjustment value to obtain the second bias; The second energy value is set according to the second weight, the second bias, and the adaptive parameter; When the energy change is less than the energy change threshold, the second weight is used as a candidate weight and the second bias is used as a candidate bias, wherein the energy change is the difference between the first energy value and the second energy value. Determine the probability of outputting target output data based on the candidate weights, the candidate biases, and the training industrial product images; The third energy value is obtained based on the probability of the target output data. Update the temperature value based on the energy change; When the third energy value reaches a dynamic equilibrium state, the candidate weights are updated according to the updated temperature value to obtain the third weights, and the candidate biases are updated according to the updated temperature value to obtain the third biases. The trained industrial defect detection model is obtained based on the third weight and the third bias.

2. The training method for the industrial defect detection model according to claim 1, characterized in that, Before inputting the trained industrial product image into the initial industrial defect detection model, the method further includes: Generative adversarial training is performed using the trained industrial product images through a generative adversarial network to obtain generated images. The generated image is scored based on multiple different quality indicators to obtain a quality score. The loss function of the generator of the generative adversarial network is obtained based on the quality score, and the parameters of the generator are adjusted according to the loss function to obtain the target generator; The training industrial product image is enhanced using the target generator to obtain the enhanced training industrial product image. The quality metric is based on the similarity between the generated image and the reference image, as well as the variability of the generated image.

3. The training method for the industrial defect detection model according to claim 1, characterized in that, The first energy value is expressed by the following formula: In the formula, This represents the first energy value. This represents the i-th training industrial product image. This represents the output data of the i-th target. Let represent the first weight, b represent the first bias, N represent the number of training industrial product images, and K represent the scale of the features of the training industrial product images. This represents the adaptive parameter corresponding to the feature at the k-th scale at time t.

4. The training method for the industrial defect detection model according to claim 3, characterized in that, The adaptive parameter is expressed by the following formula: In the formula, This represents the adaptive parameter corresponding to the feature at the k-th scale at time t. This represents the feature corresponding to the k-th scale in time. The loss value, This represents the feature corresponding to the j-th scale in time. The loss value, This indicates the importance of the feature corresponding to the k-th scale. This indicates the importance of the feature corresponding to the j-th scale.

5. The training method for the industrial defect detection model according to claim 1, characterized in that, The energy change threshold is updated according to the following formula: In the formula, This represents the threshold value for the change in energy over time t. Indicates time The threshold for energy change For time The second energy value, The standard deviation of energy change Indicates the target energy value. It is a constant parameter.

6. The training method for the industrial defect detection model according to claim 1, characterized in that, The probability of outputting target data from the candidate weights, the candidate biases, and the training industrial product images is expressed by the following formula: In the formula, This represents the probability of outputting target data based on the candidate weights, the candidate biases, and the training industrial product images. This represents the i-th training industrial product image. This represents the output data of the i-th target. For candidate weights, For candidate bias, This represents the standard deviation of the target output data.

7. The training method for the industrial defect detection model according to claim 1, characterized in that, The third weight is expressed by the following formula: ;in, In the formula, Indicates the third weight. Indicates the candidate weights. Indicates candidate bias. This indicates that the learning rate is being updated. Indicates the fusion adjustment factor. Indicates the momentum coefficient. This indicates the update amount of the third weight. This indicates the update amount of the previous third weight. This indicates the updated temperature value. The gradient of the third weight is represented by the following formula: ;in, In the formula, Indicates the third bias. Indicates candidate bias. This indicates the update amount for the third bias. This indicates the update amount of the previous third bias. This represents the gradient of the third bias; where the fusion adjustment factor is dynamically set based on the historical changes of the third weight and the error rate of the current layer of the initial industrial defect detection model.

8. An industrial defect detection method, characterized in that, include: Acquire images of the industrial products to be inspected; The image of the industrial product to be detected is input into a trained industrial defect detection model to perform industrial defect detection and obtain the detection result. The trained industrial defect detection model is obtained by training according to the training method of the industrial defect detection model according to any one of claims 1 to 7.

9. An electronic device, characterized in that, include: A memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor, when executing the computer program, implements a training method for an industrial defect detection model as described in any one of claims 1 to 7 or an industrial defect detection method as described in claim 8.

10. A computer storage medium, characterized in that, The device stores computer-executable instructions for performing a training method for an industrial defect detection model as described in any one of claims 1 to 7 or an industrial defect detection method as described in claim 8.