Industrial defect detection model training method and industrial defect detection method
By optimizing weights and biases, combining generative adversarial networks and multi-agent systems, the problem of industrial defect detection models disappearing or explosion during training is solved, the accuracy and consistency of detection is improved, and more stable and efficient Defect detection.
Patent Information
- Application Number
- CN202411338727.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-09-25
- Publication Date
- 2025-01-10
- Estimated Expiration
- 2044-09-25
AI Technical Summary
Traditional industrial defect detection models are prone to problems of gradient disappearance or explosion during training, which affects the stability and performance of the model. The artificial visual inspection is inefficient and susceptible to subjective factors, making it difficult to ensure the consistency and reliability of the detection. .
By optimizing weights and biases, image enhancement is performed using adaptive parameters and generative adversarial networks, avoiding gradient disappearance or explosion, improving model stability and performance, combining multi-agent systems to evaluate the quality and diversity of generated images, and generating more suitable results Data for defect detection tasks.
It realizes more stable and efficient industrial defect detection model training, improves the accuracy and consistency of detection, avoids the problem of gradient disappearance or explosion, and enhances the model's ability to identify different types of defects.
Smart Images

Figure CN119295812A_ABST
Abstract
Description
Technical Field
[0001] The embodiments of the present application relate to the field of industrial inspection, and in particular to a training method for an industrial defect detection model and an industrial defect detection method. Background Art
[0002] In the industrial production process, tiny defects on the surface of industrial products, such as cracks, scratches or corrosion, may seriously affect the quality and safety of the products. 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 and easily affected by subjective factors, making it difficult to ensure the consistency and reliability of detection.
[0003] In order to improve detection efficiency and accuracy, automated defect detection technology has emerged, among which image processing and machine learning methods are widely used due to their efficiency and scalability. However, due to the wide variety of industrial defects and their varied forms, traditional machine learning models may encounter gradient vanishing or exploding problems during training, affecting the training stability and performance of the model. Summary of the invention
[0004] The following is a summary of the subject matter described in detail herein. This summary is not intended to limit the scope of the claims.
[0005] The purpose of the present application is to solve at least one of the technical problems existing in the related art to a certain extent. The embodiments of the present application provide a training method for an industrial defect detection model and an industrial defect detection method, which avoid the problem of gradient vanishing or exploding by optimizing weights and biases.
[0006] An embodiment of the first aspect of the present application is a method for training an industrial defect detection model, comprising:
[0007] Acquire a training industrial product image, and input the training industrial product image into an initial industrial defect detection model;
[0008] setting a first energy value according to a first weight, a first bias, and an adaptive parameter of the initial industrial defect detection model, wherein the adaptive parameter is based on the importance of training industrial product images at different scales;
[0009] updating the first weight according to the weight adjustment value to obtain a second weight, and updating the first bias according to the bias adjustment value to obtain a second bias;
[0010] Setting a second energy value according to the second weight, the second bias and an adaptive parameter;
[0011] When the energy variation is less than the energy variation threshold, taking the second weight as a candidate weight, taking the second bias as a candidate bias, and the energy variation being the difference between the first energy value and the second energy value;
[0012] Obtaining a third energy value according to the probability of outputting target output data from the candidate weights, the candidate biases, and the training industrial product image;
[0013] Updating the temperature value according to the energy change;
[0014] When the third energy value reaches a dynamic equilibrium state, updating the candidate weight according to the updated temperature value to obtain a third weight, and updating the candidate bias according to the updated temperature value to obtain a third bias;
[0015] A trained industrial defect detection model is obtained according to the third weight and the third bias.
[0016] According to certain embodiments of the first aspect of the present application, before inputting the training industrial product image into the initial industrial defect detection model, the method further includes:
[0017] Performing generative adversarial training using the training industrial product image through a generative adversarial network to obtain a generated image;
[0018] Scoring the generated image according to a plurality of different quality indicators to obtain a quality score,
[0019] Obtaining a loss function of the generator of the generative adversarial network according to the quality score, and adjusting the parameters of the generator according to the loss function to obtain a target generator;
[0020] Performing image enhancement on the training industrial product image according to the target generator to obtain an enhanced training industrial product image;
[0021] The quality indicator is based on the similarity between the generated image and the reference image and the variability of the generated image.
[0022] According to certain embodiments of the first aspect of the present application, the first energy value is expressed by the following formula: Where E1(w,b) represents the first energy value, x i represents the i-th training industrial product image, y i represents the i-th target output data, w represents the first weight, b represents the first bias, N represents the number of training industrial product images, K represents the scale of the features of the training industrial product images, α k (t) represents the adaptive parameter corresponding to the feature of the kth scale.
[0023] According to certain embodiments of the first aspect of the present 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 kth scale at time t-1, E j (t-1) represents the loss value of the feature corresponding to the jth scale at time t-1, β k represents the importance of the feature corresponding to the kth scale, β j Indicates the importance of the feature corresponding to the jth scale.
[0024] According to some embodiments of the first aspect of the present application, the energy change threshold is updated according to the following formula: Where Θ(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, σ E represents the standard deviation of energy variation, E target represents the target energy value, ν eo is a constant parameter.
[0025] According to certain embodiments of the first aspect of the present application, the probability of outputting target output data from the candidate weights, the candidate biases, and the training industrial product image is expressed by the following formula: In the formula, p(y i |x i ; w2, b2) represents the probability of outputting the target output data by the candidate weight, the candidate bias and the training industrial product image, x i represents the i-th training industrial product image, y i represents the i-th target output data, w j ' is the candidate weight, b' k is the candidate bias, σ std Represents the standard deviation of the target output data.
[0026] According to some embodiments of the first aspect of the present application, the third weight is expressed by the following formula: new =w j '+ in, In the formula, w new represents the third weight, w j ' represents the candidate weight, b' k represents the candidate bias, β rate represents the updated learning rate, represents the fusion adjustment factor, μ ea represents the momentum coefficient, Δw represents the update amount of the third weight, Δw prev represents the update amount of the last third weight, T new Indicates the updated temperature value, represents the gradient of the third weight; the third bias is expressed by the following formula: b new =b' k +β rate Δb; where Where b new represents the third bias, b' k represents the candidate bias, Δb represents the update amount of the third bias, Δb prev represents the update amount of the last third bias, represents the gradient of the third bias; wherein the fusion adjustment factor is dynamically set according to the historical change of the third weight and the error rate of the current layer of the initial industrial defect detection model.
[0027] An embodiment of the second aspect of the present application is an industrial defect detection method, comprising:
[0028] Acquire images of industrial products to be inspected;
[0029] Inputting the industrial product image to be detected into a trained industrial defect detection model to perform industrial defect detection and obtain a detection result;
[0030] Among them, the trained industrial defect detection model is trained according to the industrial defect detection model training method described in the embodiment of the first aspect of the present application.
[0031] An embodiment of the third aspect of the present application is an electronic device, comprising: a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein when the processor executes the computer program, the training method for the industrial defect detection model as described in the embodiment of the first aspect of the present application or the industrial defect detection method as described in the embodiment of the second aspect of the present application is implemented.
[0032] An embodiment of the fourth aspect of the present application is a computer storage medium storing computer executable instructions, wherein the computer executable instructions are used to execute the training method of the industrial defect detection model as described in the embodiment of the first aspect of the present application or the industrial defect detection method as described in the embodiment of the second aspect of the present application.
[0033] The above scheme has at least the following beneficial effects: setting a first energy value according to a first weight, a first bias and an adaptive parameter of an initial industrial defect detection model; updating the first weight according to a weight adjustment value to obtain a second weight, and updating the first bias according to a bias adjustment value to obtain a second bias; setting a second energy value according to a second weight, a second bias and an adaptive parameter; when the energy change is less than an energy change threshold, taking the second weight as a candidate weight, taking the second bias as a candidate bias, and the energy change is the difference between the first energy value and the second energy value; obtaining a third energy value according to the probability of outputting target output data from the candidate weight, the candidate bias and the training industrial product image; updating the temperature value according to the energy change; when the third energy value reaches a dynamic equilibrium state, updating the candidate weight according to the updated temperature value to obtain a third weight, and updating the candidate bias according to the updated temperature value to obtain a third bias; obtaining a trained industrial defect detection model according to the third weight and the third bias; avoiding the problem of gradient disappearance or explosion by optimizing the weights and biases of the network, and improving the stability of training and model performance. BRIEF DESCRIPTION OF THE DRAWINGS
[0034] The accompanying drawings are used to provide further understanding of the technical solution of the present application and constitute a part of the specification. Together with the embodiments of the present application, they are used to explain the technical solution of the present application and do not constitute a limitation on the technical solution of the present application.
[0035] Figure 1 is a step diagram of an industrial defect detection method provided by an embodiment of the present application;
[0036] Figure 2 is a step diagram of a method for training an industrial defect detection model provided in an embodiment of the present application;
[0037] Figure 3 is a diagram of steps for performing image enhancement on training industrial product images provided by an embodiment of the present application;
[0038] Figure 4 is a structural diagram of a generative adversarial network provided in an embodiment of the present application;
[0039] Figure 5 It is a structural diagram of the feature dimensionality reduction model provided in the embodiments of the present application. DETAILED DESCRIPTION
[0040] In order to make the purpose, technical solution and advantages of the present application more clearly understood, the present application is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application and are not used to limit the present application.
[0041] It should be noted that, although the functional modules are divided in the device schematic diagram and the 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 above drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence.
[0042] The embodiments of the present application provide an industrial defect detection model training method and an industrial defect detection method.
[0043] The embodiments of the present application are further described below in conjunction with the accompanying drawings.
[0044] Reference Figure 1 , an industrial defect detection method, comprising the following steps:
[0045] Step S10, obtaining an image of an industrial product to be inspected;
[0046] Step S20: input the image of the industrial product to be inspected into the trained industrial defect detection model to perform industrial defect detection and obtain a detection result.
[0047] The trained industrial defect detection model is trained according to the following industrial defect detection model training method to obtain the reference Figure 2 ,The training method of the industrial defect detection model includes the following steps;
[0048] Step S100, obtaining a training industrial product image, and inputting the training industrial product image into an initial industrial defect detection model;
[0049] Step S200, setting a first energy value according to a first weight, a first bias and an adaptive parameter of an initial industrial defect detection model;
[0050] Step S300, updating the first weight according to the weight adjustment value to obtain the second weight, and updating the first bias according to the bias adjustment value to obtain the second bias;
[0051] Step S400, setting a second energy value according to a second weight, a second bias and an adaptive parameter;
[0052] Step S500, when the energy variation is less than the energy variation threshold, taking the second weight as a candidate weight and taking the second bias as a candidate bias;
[0053] Step S600, obtaining a third energy value according to the probability of outputting target output data from the candidate weights, the candidate biases and the training industrial product image;
[0054] Step S700, updating the temperature value according to the energy change;
[0055] Step S800, when the third energy value reaches a dynamic equilibrium state, updating the candidate weight according to the updated temperature value to obtain a third weight, and updating the candidate bias according to the updated temperature value to obtain a third bias;
[0056] Step S900: obtaining a trained industrial defect detection model according to a third weight and a third bias.
[0057] For step S100, obtain training industrial product images. The training industrial product images are obtained by collecting images of industrial products through high-resolution industrial cameras. Industrial cameras can capture tiny defects on the surface of products, such as cracks, scratches or corrosion, and the data is stored in JPG format. The data is annotated manually, annotated with the defect type of the identified image, and annotated for each sample to form a training data set for subsequent model training. For example, the annotated categories include cracks, scratches, corrosion, and others, a total of 4 categories.
[0058] Since the collection, labeling and preprocessing of training data are time-consuming and laborious, and insufficient training samples can easily lead to poor generalization of the model and affect the accuracy of the model, a multi-agent generative adversarial network is used to generate samples and thus expand the input data.
[0059] Reference Figure 3 , image enhancement is performed on the training industrial product images, including the following steps:
[0060] Step S110, performing generative adversarial training using a training industrial product image through a generative adversarial network to obtain a generated image;
[0061] Step S120, scoring the generated image according to a plurality of different quality indicators to obtain a quality score,
[0062] Step S130, obtaining a loss function of a generator of a generative adversarial network according to the quality score, adjusting the parameters of the generator according to the loss function, and obtaining a target generator;
[0063] Step S140, performing image enhancement on the training industrial product image according to the target generator to obtain an enhanced training industrial product image.
[0064] Among them, the quality index is based on the similarity between the generated image and the reference image and the variability of the generated image.
[0065] Reference Figure 4The generative adversarial network consists of a generator and a discriminator. The generator is responsible for generating new data that is as close to the real data as possible, and the discriminator's task is to distinguish the generated data from the real data. By using the multi-agent loss function adjustment, each generated data sample not only needs to deceive the discriminator, but also needs to meet the specific quality indicators determined by the multi-agent system, making the generated data more suitable for the special needs of the defect detection task, and improving the practicality and relevance of the data.
[0066] Initialize the network parameters of the generator and discriminator, and set the initial parameters of the generator and discriminator based on Gaussian distribution. The initial parameters of the generator can be expressed as: The initial parameters of the discriminator can be expressed as: In the formula, ~ means obeying a specific distribution, θ g and θ d Represent the parameters of the generator and the discriminator respectively; σ 2 represents the initialization standard deviation, Represented as a Gaussian distribution.
[0067] Select a batch of real industrial product images as the basic training data, and set the real data set as Randomly extract a batch of data x from it, which can be expressed as: The generator G receives random noise z and generates a batch of generated images based on the current network parameters and the input noise data. The noise follows a standard normal distribution and can be expressed as: Generate image It can be expressed as: Where z represents the input noise vector; I is the unit matrix; is the generated image generated by the generator G; G is the generating function of the generator. For example, the generating function G of the generator is implemented by a neural network with a tanh activation function and can be expressed as: G(z; θ g )=tanh(W g ·z+b g );W g 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 output generated image to the range of [-1,1].
[0068] A multi-agent system is used to evaluate the quality and diversity of generated images. The multi-agent system A evaluates the generated images, and each agent evaluates the generated images according to the preset quality index f i The scoring process can be expressed as: In the formula, s i is an intelligent agent iThe score of the generated image; S is the average score of all agents; N is the total number of agents. For example, the scoring function f i It can be expressed as: In the formula, α i and β i is a weight coefficient; preferably, α i and β i Set to 0.3 and 0.7 respectively. Represents the generated image With the reference image x ref The similarity measure between Represents the generated image The variability of .
[0069] The discriminator receives fake images and real images from the generator, and its training goal is to maximize its classification accuracy in order to correctly classify these two types of images. The loss function of the discriminator can be expressed as: Where, L d is the loss function of the discriminator; D(x) is the output of the discriminator for the real image x; It is to generate an image The output of . Furthermore, in the loss function of the discriminator, each item can be further expanded as: Among them, m and n represent the number of samples of real data and generated images respectively, and x (j) is the jth real image, is the kth generated image.
[0070] According to the scoring results of the multi-agent, the loss function of the generator is adjusted to optimize the generation process so that the generated fake images can better meet the quality requirements. The loss function of the generator can be expressed as: Among them, L g is the loss function of the generator; λ is the weight parameter that controls the impact of multi-agent scoring.
[0071] A multi-agent system is used to evaluate the quality and diversity of the generated data samples and score the images according to preset quality indicators. These scores are used to adjust the loss function to generate data that is more suitable for the defect detection task.
[0072] Repeat the above steps until the preset stop iteration condition is met, which means that the training of the generative adversarial network is completed. The preset stop iteration condition is to reach a preset maximum number of iterations. Preferably, the preset maximum number of iterations is set to 1000 times.
[0073] Through the multi-agent generative adversarial network, the training data set can be effectively expanded and the diversity of samples can be increased, thereby improving the model's ability to identify different types of defects. Data expansion helps to avoid overfitting, so that the trained model not only performs well on the training set, but also maintains a high recognition accuracy on unseen samples. The application of the multi-agent system makes the generated data more in line with the actual needs of defect detection, which helps to improve the model's recognition accuracy for subtle defects.
[0074] The image-enhanced training industrial product images are input into the initial industrial defect detection model.
[0075] The initial industrial defect detection model uses a 3-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 to be classified, which is 4. The fully connected neural network includes an input layer and 2 hidden layers, and an output layer is preset for supervised training of categories, which are defined as follows: Input layer, assuming the dimension of the input vector is, then the input layer has neurons, corresponding to the elements in the vector; Hidden layer, both hidden layers have 128 neurons, and ReLU is used as the activation function; Output layer, the output layer uses the softmax function as the activation function.
[0076] For step S200, a first energy value is set according to a first weight, a first bias and an adaptive parameter of an initial industrial defect detection model.
[0077] Initialize the neural network parameters and assign them a random energy state. Specifically, the weights w and biases b of the neural network are assigned initial values.
[0078] The energy state is defined to describe the potential optimization ability of the parameters, which can be expressed as: Where E1(w,b) represents the first energy value, x i represents the i-th training industrial product image, y i represents the i-th target output data, w represents the first weight, b represents the first bias, N represents the number of training industrial product images, K represents the scale of the features of the training industrial product images, α k (t) represents the adaptive parameter corresponding to the feature of the kth scale, based on the importance of training industrial product images of different scales, which 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 can be understood 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, which allows the model to focus on different feature levels at different training stages, thereby more effectively learning the multi-level structure of complex data. Specifically, the weight α of each scale k The update of (t) depends on the effect of the scale under the current training state. The update method of the adaptive parameters 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 kth scale at time t-1, E j (t-1) represents the loss value of the feature corresponding to the jth scale at time t-1, β k represents the importance of the feature corresponding to the kth scale, β j represents the importance of the feature corresponding to the jth scale, β k and β j The preset is based on the characteristics of the scale.
[0081] A fusion candidate check is performed on each pair of parameters (weight and bias). If the second energy values 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 remain independent, that is, the first weight and the second weight are maintained.
[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 expressed as: w j '=w j +δ tr . The weight adjustment value is expressed as:
[0084] The second bias is expressed as: b' k =b k +∈ tr . The bias adjustment value is expressed as:
[0085] w j is the jth first weight, w j ' is the jth second weight; b k is the kth first bias, b' k is the kth second bias.
[0086] Among them, σ to and η to is the sensitivity and scaling factor of the 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 parameter.
[0088] The second energy value can be expressed as:
[0089] For step S500, when the energy variation is less than the energy variation threshold, the second weight is used as a candidate weight, and the second bias is used as a candidate bias.
[0090] The energy change is the difference between the first energy value and the second energy value. The energy change is expressed as: ΔE = E(w j ',b' k )-E(w j ,b k ).
[0091] The energy threshold Θ(t) is updated at each iteration. The energy change during the training process is monitored in real time, and the energy threshold is adjusted dynamically to control the sensitivity and frequency of parameter updates. The energy change threshold is updated according to the following formula: Where Θ(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, σ E represents the standard deviation of energy variation, E target represents the target energy value, ν eo is a constant parameter. Preferably, ν eo Set to 0.01, E target Set 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] A third energy value is obtained according to the probability of outputting the target output data from the candidate weights, the candidate biases and the training industrial product images.
[0094] The probability of outputting the target output data from the candidate weights, candidate biases and training industrial product images is expressed as follows: In the formula, p(y i |x i ; w2, b2) represents the probability of outputting the target output data from the candidate weight, candidate bias and training industrial product image, x i represents the i-th training industrial product image, y i represents the i-th target output data, w j ' is the candidate weight, b' kis the candidate bias, σ std Represents the standard deviation of the target output data.
[0095] The third energy value is expressed as: Wherein, E3(w,b) represents the third energy value.
[0096] In step S700, the temperature value is updated according to the energy change amount.
[0097] Specifically, the temperature value is adjusted according to 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 represents the temperature adjustment factor, T new Indicates the updated temperature value, T old represents the temperature value before updating, and ΔE represents the energy change.
[0098] For the temperature adjustment factor, α te Dynamically adjust based on energy changes. te It can be expressed as: Among them, κ te is the preset adjustment coefficient, |ΔE| is the absolute energy change, E avg is the average value of all current parameter energies.
[0099] For step S800, when the third energy value reaches a dynamic equilibrium state, the candidate weight is updated according to the updated temperature value to obtain the third weight, and the candidate bias is updated according to the updated temperature value to obtain the third bias.
[0100] When Var(E3)<∈ mr , it is judged that the third energy value reaches a dynamic equilibrium state. Wherein Var(E3) represents the variance function of the third energy value; preferably, ∈ mr Set to 10 -5 .
[0101] According to the energy optimization principle, it is decided whether to update the current parameter configuration, that is, to update the candidate weights and candidate biases.
[0102] Among them, the third weight is expressed by the following formula: in, In the formula, w new represents the third weight, w j ' represents the candidate weight, b' k represents the candidate bias, β rate represents the updated learning rate, represents the fusion adjustment factor, μea represents the momentum coefficient, Δw represents the update amount of the third weight, Δw prev represents the update amount of the last third weight, T new Indicates the updated temperature value, represents the gradient of the third weight; the third bias is expressed by the following formula: b new =b' k +β rate Δb; where Where b new represents the third bias, b' k represents the candidate bias, Δb represents the update amount of the third bias, Δb prev represents the update amount of the last third bias, represents the gradient of the third bias.
[0103] Among them, the fusion adjustment factor The fusion adjustment factor is dynamically set according to 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] is the difference between the current weight and the weight of the previous iteration; is the standard deviation of the weight change of the current layer; E l is the error rate of the current layer; ρ yt and λ yt is the adjustment coefficient, which controls the influence intensity of weight change rate and 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 change in parameter energy after multiple consecutive iterations. If converged, the final optimized parameters are output; if not, return to the above steps to continue iterating. The convergence judgment method can be expressed as: In the formula, E new is the energy state after parameter update, E old is the energy state before parameter update, γ ew Preferably, the convergence threshold γ ew Set to 10 -6 .
[0106] For step S900, a trained neural network is obtained according to the third weight and the third bias.
[0107] Feature extraction is performed through the above neural network, and the extracted features are input into the feature dimensionality reduction model to train the feature dimensionality reduction model.
[0108] The autoencoder neural network with manifold mapping learning is used for feature dimensionality reduction. The autoencoder neural network not only learns the intrinsic structure of the data in the encoding stage, but also attempts to reconstruct the input through the decoding process to ensure that the features after dimensionality reduction can still retain key information. Figure 5 The feature dimensionality reduction model consists of an encoder and a decoder. The encoder is responsible for mapping the high-dimensional input data to a low-dimensional feature space, and the decoder reconstructs the original input data from this low-dimensional space. The Riemann factor of manifold learning is used to optimize the representation of the feature space. The geometric properties on the Riemann manifold can better understand the local structure of the data and achieve more accurate data reconstruction.
[0109] Use Gaussian distribution to initialize the weight w of the autoencoder cr and bias b cr The parameters, weights w cr It can be expressed as: Bias b cr It can be expressed as: In the formula, represents the weight of the i-th layer, σ ch represents the standard deviation, n ”in ” is the number of nodes in the input layer.
[0110] In the encoding process, the input data is mapped to a low-dimensional feature space through the encoder; in the decoding process, the decoder attempts to reconstruct the original data. Specifically, through the autoencoder, the data x cr The way it is mapped to the low-dimensional feature space z can be expressed as: The decoder attempts to reconstruct the original input x cr ^ can be expressed as: Where Sig is the activation function; and are the weights and biases of the encoder respectively; and are the weights and biases of the decoder respectively.
[0111] Weight By presetting it in the way of principal component analysis, the calculation method can be expressed as: Where V k is from the covariance matrix The matrix composed of the first k eigenvectors obtained, Σ k is the corresponding diagonal matrix of eigenvalues.
[0112] In the encoded low-dimensional space, the Riemann factor R is used to implement manifold learning. The way in which the Riemann factor constrains the encoded feature z can be expressed as: In the formula, μ cy represents the preset manifold center, σ R is a parameter that controls the compactness of the manifold. Preferably, μ cy Set to the mean vector of the low-dimensional space, σ R Set to 0.1.
[0113] The loss function not only considers the reconstruction error, but also the Riemann manifold constraint. The reconstruction error ensures that the data can be effectively restored. The manifold constraint strengthens the geometric structure of the feature space. The calculation method of the loss function Lu can be expressed as: Lu = ∥x cr -x cr ^∥ 2 +λ cm R; where λ cm is the regularization coefficient. Preferably, λ cm Set 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 is the value of the preset manifold center in the i-th dimension.
[0115] Based on the loss function, the network parameters are adjusted through the back propagation algorithm to optimize the performance of the encoder and decoder. For example, the calculation method of its gradient can be expressed as: Furthermore, the gradient It is calculated by the error back propagation method and can be expressed as: Through the decoder weights The transposed representation of can be expressed as: Furthermore, since z is and x cr The result obtained by the activation function after the linear combination of The calculation method can be expressed as: Where Sig' is the derivative of the Sigmoid activation function, diag(vs) represents a diagonal matrix with vector vs as the diagonal element, is x cr The transpose of . Further, the gradient descent method is used to update the parameters, and the update method can be expressed as: In the formula, α rv is the learning rate, t represents the number of iterations, is the updated weight parameter, is the weight parameter before updating. Preferably, α rv Set to 0.05.
[0116] Finally, the above steps are repeated until the preset stop iteration condition is met, indicating that the model training is completed. In one embodiment, the preset stop iteration condition is reaching a preset maximum number of iterations, preferably, the preset maximum number of iterations is set to 1000 times.
[0117] The trained neural network and the trained feature dimension reduction model are combined to obtain a trained industrial defect detection model.
[0118] An embodiment of the present application provides an electronic device, which includes a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the above-mentioned industrial defect detection model training method or industrial defect detection method when executing the computer program.
[0119] The electronic device may be any intelligent terminal including a computer.
[0120] In general, for the hardware structure of the electronic device, the processor can be implemented using a general-purpose CPU (Central Processing Unit), a microprocessor, an application-specific integrated circuit (Application Specific Integrated Circuit, ASIC), or one or more integrated circuits, etc., to execute related programs to implement the technical solutions provided in the embodiments of the present application.
[0121] The memory can be implemented in the form of a read-only memory (ROM), a static storage device, a dynamic storage device, or a random access memory (RAM). The memory can store an operating system and other applications. When the technical solutions provided in the embodiments of this specification are implemented by software or firmware, the relevant program codes are stored in the memory, and the processor is called to execute the methods of the embodiments of this application.
[0122] The input / output interface is used to realize information input and output.
[0123] The communication interface is used to realize the communication interaction between this device and other devices. Communication can be achieved through wired methods (such as USB, network cable, etc.) or wireless methods (such as mobile network, WIFI, Bluetooth, etc.).
[0124] The bus transmits information between the various components of the device (such as the processor, memory, input / output interface, and communication interface). The processor, memory, input / output interface, and communication interface communicate with each other within the device through the bus.
[0125] An embodiment of the present application provides a computer storage medium storing computer executable instructions for executing the above-mentioned industrial defect detection model training method or industrial defect detection method.
[0126] It will be appreciated by those skilled in the art that all or some of the steps and systems in the disclosed method above may be implemented as software, firmware, hardware and appropriate combinations thereof. Some physical components or all physical components may be implemented as software executed by a processor, such as a central processing unit, a digital signal processor or a microprocessor, or may be implemented as hardware, or may be implemented as an integrated circuit, such as an application specific integrated circuit. Such software may be distributed on a computer-readable medium, which may include a computer storage medium (or a non-transitory medium) and a communication medium (or a temporary medium). As known to those skilled in the art, the term computer storage medium 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 include, but are not limited to, RAM, ROM, EEPROM, flash memory or other memory technologies, CD-ROM, digital versatile disks (DVD) or other optical disk storage, magnetic cassettes, magnetic tapes, disk storage or other magnetic storage devices, or any other medium that may be used to store desired information and may be accessed by a computer. In addition, it is well known to those of ordinary skill 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 above description of this specification, the description of reference terms "one embodiment / example", "another embodiment / example" or "certain embodiments / examples" and the like means that the specific features, structures, materials or characteristics described in conjunction with the embodiments or examples are included in at least one embodiment or example of the present application. In this specification, the schematic representation of the above terms does not necessarily refer to the same embodiment or example. Moreover, the specific features, structures, materials or characteristics described may be combined in any one or more embodiments or examples in a suitable manner.
[0127] Those skilled in the art will appreciate that all or some of the steps in the methods disclosed above, and the functional modules / units in the systems and devices may be implemented as software, firmware, hardware, or a suitable combination thereof.
[0128] The units described above as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0129] In addition, each functional unit in each embodiment of the present application may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of software functional units.
[0130] If the integrated unit is implemented in the form of 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 the present application, 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, and the computer software product is stored in a storage medium, including multiple instructions to enable a computer device (which can be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods of various embodiments of the present application. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (Read-Only Memory, referred to as ROM), random access memory (Random Access Memory, referred to as RAM), disk or optical disk and other media that can store programs.
[0131] In the several embodiments provided in the present application, it should be understood that the disclosed devices and methods can be implemented in other ways. For example, the device embodiments described above are only schematic. For example, the division of the above-mentioned units is only a logical function division. There may be other division methods in actual implementation, such as multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of devices or units, which can be electrical, mechanical or other forms. Although the embodiments of the present application have been shown and described, it can be understood by those of ordinary skill in the art that various changes, modifications, substitutions and variations can be made to these embodiments without departing from the principles and purposes of the present application, and the scope of the present application is defined by the claims and their equivalents.
[0132] The above is a specific description of the preferred implementation of the present application, but the present application is not limited to the embodiments. Technical personnel familiar with the field can make various equivalent modifications or substitutions without violating the spirit of the present application. These equivalent modifications or substitutions are all included in the scope defined by the claims of the present application.
Claims
1. A training method for an industrial defect detection model, characterized in that: include: Acquire a training industrial product image, and input the training industrial product image into an initial industrial defect detection model; setting a first energy value according to a first weight, a first bias, and an adaptive parameter of the initial industrial defect detection model, wherein the adaptive parameter is based on the importance of training industrial product images at different scales; updating the first weight according to the weight adjustment value to obtain a second weight, and updating the first bias according to the bias adjustment value to obtain a second bias; Setting a second energy value according to the second weight, the second bias and an adaptive parameter; When the energy variation is less than the energy variation threshold, taking the second weight as a candidate weight, taking the second bias as a candidate bias, and the energy variation being the difference between the first energy value and the second energy value; Obtaining a third energy value according to the probability of outputting target output data from the candidate weights, the candidate biases, and the training industrial product image; updating the temperature value according to the energy change; When the third energy value reaches a dynamic equilibrium state, updating the candidate weight according to the updated temperature value to obtain a third weight, and updating the candidate bias according to the updated temperature value to obtain a third bias; A trained industrial defect detection model is obtained according to the third weight and the third bias.
2. The method for training an industrial defect detection model according to claim 1, characterized in that: Before inputting the training industrial product image into the initial industrial defect detection model, the method further includes: Performing generative adversarial training using the training industrial product image through a generative adversarial network to obtain a generated image; Scoring the generated image according to a plurality of different quality indicators to obtain a quality score, Obtaining a loss function of the generator of the generative adversarial network according to the quality score, and adjusting the parameters of the generator according to the loss function to obtain a target generator; Performing image enhancement on the training industrial product image according to the target generator to obtain an enhanced training industrial product image; The quality indicator is based on the similarity between the generated image and the reference image and the variability of the generated image.
3. The training method of the industrial defect detection model according to claim 1, characterized in that: The first energy value is expressed by the following formula: Where E1(w,b) represents the first energy value, x i represents the i-th training industrial product image, y i represents the i-th target output data, w represents the first weight, b represents the first bias, N represents the number of training industrial product images, K represents the scale of the features of the training industrial product images, α k (t) represents the adaptive parameter corresponding to the feature of the kth scale.
4. The method for training an industrial defect detection model according to claim 3, characterized in that: 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 kth scale at time t-1, E j (t-1) represents the loss value of the feature corresponding to the jth scale at time t-1, β k represents the importance of the feature corresponding to the kth scale, β j Indicates the importance of the feature corresponding to the jth scale.
5. The method for training an industrial defect detection model according to claim 1, characterized in that: The energy change threshold is updated according to the following formula: Where Θ(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, σ E represents the standard deviation of energy variation, E target represents the target energy value, ν eo is a constant parameter.
6. The method for training an industrial defect detection model according to claim 1, characterized in that: The probability of outputting the target output data from the candidate weights, the candidate biases and the training industrial product image is expressed by the following formula: In the formula, p(y i |x i ; w2, b2) represents the probability of outputting the target output data by the candidate weight, the candidate bias and the training industrial product image, x i represents the i-th training industrial product image, y i represents the i-th target output data, w j ' is the candidate weight, b' k is the candidate bias, σ std Represents the standard deviation of the target output data.
7. The method for training an industrial defect detection model according to claim 1, characterized in that: The third weight is expressed by the following formula: in, In the formula, w new represents the third weight, w j ' represents the candidate weight, b' k represents the candidate bias, β rate represents the updated learning rate, represents the fusion adjustment factor, μ ea represents the momentum coefficient, Δw represents the update amount of the third weight, Δw prev represents the update amount of the last third weight, T new Indicates the updated temperature value, represents the gradient of the third weight; the third bias is expressed by the following formula: b new =b' k +β rate Δb; where Where b new represents the third bias, b' k represents the candidate bias, Δb represents the update amount of the third bias, Δb prev represents the update amount of the last third bias, represents the gradient of the third bias; wherein the fusion adjustment factor is dynamically set according to the historical change 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 industrial products to be inspected; Inputting the industrial product image to be detected into a trained industrial defect detection model to perform industrial defect detection and obtain a detection result; Wherein, the trained industrial defect detection model is trained 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 when the processor executes the computer program, the training method for the industrial defect detection model according to any one of claims 1 to 7 or the industrial defect detection method according to claim 8 is implemented.
10. A computer storage medium, characterized in that: Computer executable instructions are stored, and the computer executable instructions are used to execute the training method of the industrial defect detection model according to any one of claims 1 to 7 or the industrial defect detection method according to claim 8.
Citation Information
Patent Citations
User interest area and feedback guided picture accurate retrieval method
CN112685591A
Image processing and image classification method and device, equipment and storage medium
CN114693993A
Power equipment small target defect identification method and system based on mobilenet
CN115100546A
Geologically constrained infrared imaging detection method and system for urban deeply-buried strip-like passage
US20230237221A1