Industrial visual quality inspection method and device, electronic equipment and storage medium
By generating the expanded sample data and optimizing feature extraction and dimensionality reduction models through the generation of adversarial networks, the problem of insufficient training samples in industrial vision quality inspection is solved, the generalization ability and accuracy of the model are improved, and the comprehensive automation and efficiency of industrial vision quality inspection is achieved.
Patent Information
- Application Number
- CN202411815046.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-10
- Publication Date
- 2025-03-14
AI Technical Summary
In industrial vision quality inspection, poor generalization ability and low accuracy of model due to insufficient training samples.
By using a generative adversarial network algorithm model based on an adaptive compensation mechanism, the training sample set is expanded, and the diversity and representativeness of the data are improved. At the same time, a neural network based on exploratory gradient descent is used for feature extraction, and a self-encoder combined with an inverse reconstruction to perform feature dimensionality reduction to optimize the performance of the classifier.
It effectively improves the generalization ability and accuracy of the model, enhances the reliability and efficiency of industrial vision quality inspection, and realizes comprehensive automation of industrial vision quality inspection.
Smart Images

Figure CN119625426A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of data processing technology, and specifically to an industrial visual quality inspection method, device, electronic equipment and storage medium. Background Art
[0002] Industrial visual quality inspection is a method that uses computer vision technology to detect, identify and evaluate the quality of products and parts or process in the manufacturing process. The process includes image acquisition, feature detection, decision classification, problem feedback, data recording and analysis, etc. It plays an important role in improving production efficiency, reducing human errors, reducing costs and ensuring product quality standards and consistency. With the development of intelligent manufacturing technology, the use of machine vision for quality inspection and traceability has become an inevitable choice for factories to pursue intelligence and keep up with the development of the times. Summary of the invention
[0003] In order to solve the above-mentioned technical problems, the present application provides an industrial visual quality inspection method, device, electronic device and storage medium, aiming to realize comprehensive automation of industrial visual quality inspection and greatly improve the accuracy, reliability and efficiency of industrial visual quality inspection.
[0004] According to a first aspect of the present application, an industrial visual quality inspection method is provided, comprising: Input the collected workpiece image into a pre-trained feature extraction model to obtain high-dimensional feature data; Inputting the high-dimensional feature data into a pre-trained feature dimensionality reduction model to obtain low-dimensional feature data; Input the low-dimensional feature data into a pre-trained classifier model to obtain a classification result, and perform quality inspection based on the classification result. The feature extraction model, the feature dimensionality reduction model and the classifier model are trained based on sample data, the sample data includes: collected sample data and expanded sample data, the expanded sample data is generated using a pre-trained generative adversarial network algorithm model, and the generative adversarial network algorithm model includes a generative adversarial network algorithm model based on an adaptive compensation mechanism; The generative adversarial network algorithm model based on the adaptive compensation mechanism includes a generator and a discriminator. The training process of the generative adversarial network algorithm model based on the adaptive compensation mechanism includes iteratively executing the following steps until a preset stop iteration condition is reached: Inputting a random noise vector into the generator to obtain a generated image; Providing the generated image to the discriminator, and calculating the loss of the generator according to the probability output by the discriminator; Inputting the generated image and the real image into the discriminator, and calculating the loss of the discriminator according to the probability output by the discriminator; Calculating an adaptive compensation loss based on the loss of the generator and the loss of the discriminator; Optimizing parameters of the generator and the discriminator according to the learning rate of the generative adversarial network and the adaptive compensation loss.
[0005] Optionally, the adaptive compensation loss is calculated in accordance with the following formula: ,in, represents the adaptive compensation loss, represents the traditional generative adversarial network loss, represents the structural similarity loss, represents pixel-level loss, represents the first loss coefficient, represents the second loss coefficient, represents the third loss coefficient. Preferably, Set to 0.3, Set to 0.5, Set to 0.2.
[0006] Optionally, each loss term is calculated in accordance with the following formula: , , , in, represents the loss function of the generator, represents the loss function of the discriminator, represents the L2 norm, represents the square of the L2 norm, is a structural similarity index item calculation function, used to measure the similarity between the generated image and the real image, represents the real image, represents the generated image.
[0007] Optionally, the calculation method of the structural similarity index item calculation function complies with the following formula: ,in, and Respectively represent the real images and the generated image The average brightness, and Respectively represent the real images and the generated image The standard deviation of Represents the real image and the generated image The covariance between represents the first constant, Represents the second constant.
[0008] Optionally, the training process of the feature extraction model includes iteratively executing the following steps until a preset stop iteration condition is reached: Inputting the sample data into the feature extraction model, performing linear transformation and nonlinear activation processing on the sample data according to the parameters of the feature extraction model, and obtaining a feature representation of an output layer; Perform linear regression prediction based on historical gradient data, and adjust the step size and direction of gradient update according to the prediction results; Performing gradient update according to the step size and direction, and calculating an update amount of the parameters of the feature extraction model according to the updated gradient and the learning rate of the feature extraction model; The parameters of the feature extraction model are updated according to the update amount.
[0009] Optionally, the training process of the feature dimension reduction model includes iteratively executing the following steps until a preset stop iteration condition is reached: Inputting the high-dimensional data after feature extraction into the feature dimensionality reduction model; Calculating the inverse reconstruction loss of the feature dimensionality reduction model; A gradient is calculated according to the inverse reconstruction loss, and a gradient descent algorithm is used to update the parameters of the feature dimensionality reduction model.
[0010] Optionally, the training process of the classifier model includes iteratively executing the following steps until a preset stop iteration condition is reached: The low-dimensional data after dimensionality reduction is input into the classifier model, and a preset vector decomposition algorithm is used to decompose the feature space of the low-dimensional data to obtain key feature vectors; Calculating the misclassification rate in the iteration process according to the key feature vector, and dynamically adjusting the constraint penalty factor of the classifier model according to the misclassification rate; Calculating a regularization coefficient of the classifier model, and calculating a loss function of the classifier model according to the regularization coefficient; A stochastic gradient descent algorithm is used to update the parameters of the classifier model according to the learning rate and loss function of the classifier model.
[0011] Optionally, the constraint penalty factor is adjusted in accordance with the following formula: ,in, represents the constraint penalty factor, Indicates The constraint penalty factor for the iteration, Represents the basic penalty value, represents the parameter that controls the adjustment strength of the penalty factor, represents the parameter that controls the adjustment speed of the penalty factor, Indicates The misclassification rate of iterations.
[0012] Optionally, the misclassification rate is calculated in accordance with the following formula: ,in, Indicates an indicator function. When the brackets The value is 1 if the condition is true, otherwise it is 0. Indicates The actual labels of samples, Indicates that the classifier model is The prediction results of samples are Indicates the total number of samples input in the current batch, Denotes the key feature vector.
[0013] Optionally, the loss function of the classifier model is calculated in accordance with the following formula: ,in, represents the loss function of the classifier model, represents the number of samples, Indicates The labels of samples, Indicates The characteristics of the samples, represents the maximum value function, represents the L2 norm, represents the regularization coefficient of the classifier model.
[0014] Optionally, the regularization coefficient is calculated in accordance with the following formula: ,in, represents the initial regularization coefficient, represents the regularization coefficient of the tth iteration, Indicates the current iteration number, represents the total number of iterations. Preferably, Set to 0.3.
[0015] Optionally, the classification result includes: one of no defect, crack, scratch and rust.
[0016] Optionally, the feature extraction model, the feature dimension reduction model and the classifier model are deployed in an edge device.
[0017] According to a second aspect of the present application, an industrial visual quality inspection device is provided, comprising: A feature extraction unit extracts high-dimensional features from the collected workpiece image according to a pre-trained feature extraction model to obtain high-dimensional feature data; A feature dimension reduction unit performs dimension reduction processing on the high-dimensional feature data according to a pre-trained feature dimension reduction model to obtain low-dimensional feature data; The classification quality inspection unit classifies the low-dimensional feature data according to a pre-trained classifier model and performs quality inspection according to the classification results. The feature extraction model, the feature dimension reduction model and the classifier model are trained based on sample data, and the sample data includes: collected sample data and expanded sample data, and the expanded sample data is generated by using a pre-trained generative adversarial network algorithm model, and the generative adversarial network algorithm model includes a generative adversarial network algorithm model based on an adaptive compensation mechanism; The generative adversarial network algorithm model based on the adaptive compensation mechanism includes a generator and a discriminator. The training process of the generative adversarial network algorithm model based on the adaptive compensation mechanism includes iteratively executing the following steps until a preset stop iteration condition is reached: Inputting a random noise vector into the generator to obtain a generated image; Providing the generated image to the discriminator, and calculating the loss of the generator according to the probability output by the discriminator; Inputting the generated image and the real image into the discriminator, and calculating the loss of the discriminator according to the probability output by the discriminator; Calculating an adaptive compensation loss based on the loss of the generator and the loss of the discriminator; Optimizing parameters of the generator and the discriminator according to the learning rate of the generative adversarial network and the adaptive compensation loss.
[0018] Optionally, the adaptive compensation loss is calculated in accordance with the following formula: ,in, represents the adaptive compensation loss, represents the traditional generative adversarial network loss, represents the structural similarity loss, represents pixel-level loss, represents the first loss coefficient, represents the second loss coefficient, represents the third loss coefficient.
[0019] Optionally, each loss term is calculated in accordance with the following formula: , , , in, represents the loss function of the generator, represents the loss function of the discriminator, represents the L2 norm, represents the square of the L2 norm, is a structural similarity index item calculation function, used to measure the similarity between the generated image and the real image, represents the real image, represents the generated image.
[0020] Optionally, the calculation method of the structural similarity index item calculation function complies with the following formula: ,in, and Respectively represent the real images and the generated image The average brightness, and Respectively represent the real images and the generated image The standard deviation of Represents the real image and the generated image The covariance between represents the first constant, Represents the second constant.
[0021] Optionally, the training process of the classifier model includes iteratively executing the following steps until a preset stopping iteration condition is reached: Inputting the reduced low-dimensional data into the classifier model, and using a preset vector decomposition algorithm to decompose the feature space of the low-dimensional data to obtain key feature vectors; Calculating the misclassification rate in the iteration process according to the key feature vector, and dynamically adjusting the constraint penalty factor of the classifier model according to the misclassification rate; Calculating a regularization coefficient of the classifier model, and calculating a loss function of the classifier model according to the regularization coefficient; A stochastic gradient descent algorithm is used to update the parameters of the classifier model according to the learning rate and loss function of the classifier model.
[0022] Optionally, the constraint penalty factor is adjusted in accordance with the following formula: ,in, represents the constraint penalty factor, Indicates The constraint penalty factor for the iteration, Represents the basic penalty value, represents the parameter that controls the adjustment strength of the penalty factor, represents the parameter that controls the adjustment speed of the penalty factor, Indicates The misclassification rate of iterations; The misclassification rate is calculated in accordance with the following formula: ,in, Indicates an indicator function. When the brackets The value is 1 if the condition is true, otherwise it is 0. Indicates The actual labels of samples, Indicates that the classifier model is The prediction results of samples are Indicates the total number of samples input in the current batch, Denotes the key feature vector.
[0023] Optionally, the loss function of the classifier model is calculated in accordance with the following formula: ,in, represents the loss function of the classifier model, represents the number of samples, Indicates The labels of samples, Indicates The characteristics of the samples, represents the maximum value function, represents the L2 norm, represents the regularization coefficient of the classifier model; The calculation method of the regularization coefficient conforms to the following formula: ,in, represents the initial regularization coefficient, represents the regularization coefficient of the tth iteration, Indicates the current iteration number, Indicates the total number of iterations.
[0024] According to the third aspect of the present application, an electronic device is provided, comprising: a processor, a memory, and a program stored in the memory and executable on the processor, wherein when the program is executed by the processor, the steps of the industrial visual quality inspection method as described in any embodiment of the present application are implemented.
[0025] According to a fourth aspect of the present application, a storage medium is provided, on which a computer program or instructions are stored. When the computer program or instructions are executed by a processor, the steps of the industrial visual quality inspection method as described in any embodiment of the present application are implemented.
[0026] By adopting the technical solution disclosed in the embodiments of the present application, the training sample set can be effectively expanded, the diversity and representativeness of the data can be improved, and the problem of poor model generalization ability and low precision caused by insufficient training samples in industrial visual quality inspection can be solved.
[0027] Furthermore, in the process of feature extraction and dimensionality reduction, the training stability of the neural network is optimized, the common gradient vanishing and explosion problems are avoided, and the convergence speed of the model and the quality of feature representation are improved.
[0028] Furthermore, in the classification task, the accuracy and adaptability of the classifier are improved by optimizing the processing of imbalanced data, ensuring the reliability and efficiency of industrial visual quality inspection.
[0029] It should be noted that the above general description and the following detailed description are merely exemplary and explanatory and do not limit the present application. BRIEF DESCRIPTION OF THE DRAWINGS
[0030] Figure 1 A schematic diagram showing an embodiment of an industrial visual quality inspection method provided according to an embodiment of the present application is shown;
[0031] Figure 2 A schematic diagram of the training process of a generative adversarial network algorithm model based on an adaptive compensation mechanism provided in an embodiment of the present application is shown;
[0032] Figure 3 A schematic diagram of the training process of the feature extraction model provided according to an embodiment of the present application is shown;
[0033] Figure 4 A schematic diagram of the training process of the feature dimensionality reduction model provided according to an embodiment of the present application is shown;
[0034] Figure 5 A schematic diagram of the training process of a classifier model provided according to an embodiment of the present application is shown;
[0035] Figure 6 A structural block diagram of an industrial visual quality inspection device provided according to an embodiment of the present application is shown;
[0036] Figure 7 A structural block diagram of an electronic device provided according to an embodiment of the present application is shown. DETAILED DESCRIPTION
[0037] In order to facilitate the understanding of the present application, the present application will be described more comprehensively below with reference to the relevant drawings. The preferred embodiments of the present application are given in the drawings. However, the present application can be implemented in different forms and is not limited to the embodiments described herein. On the contrary, the purpose of providing these embodiments is to make the understanding of the disclosure of the present application more thorough and comprehensive.
[0038] References to "one embodiment" or "some embodiments" etc. described in this specification mean that a particular feature, structure or characteristic described in conjunction with the embodiment is included in one or more embodiments of the present application. Thus, the phrases "in one embodiment", "in some embodiments", "in some other embodiments", "in some other embodiments", etc. that appear at different places in this specification do not necessarily refer to the same embodiment, but mean "one or more but not all embodiments", unless otherwise specifically emphasized in other ways. The terms "including", "comprising", "having" and their variations all mean "including but not limited to", unless otherwise specifically emphasized in other ways.
[0039] In the description of this application, words such as "exemplary" or "for example" are used to indicate examples, illustrations or descriptions. Any embodiment described as "exemplary" or "for example" in this application should not be interpreted as being more preferred or advantageous than other embodiments.
[0040] In addition, the same figure marks in the figures represent the same or similar structures, and thus their repeated description will be omitted. That is, the various parts in this specification are described in a combination of parallel and progressive manners, and each part focuses on the differences from other parts. The same or similar parts between the various parts can be referenced to each other.
[0041] In modern industrial production, in order to improve product quality and production efficiency, automated visual quality inspection technology plays an increasingly important role. Visual quality inspection systems help reduce human errors and improve inspection speed and accuracy by automatically identifying defects in images, such as cracks, scratches or rust.
[0042] Industrial visual quality inspection mainly includes using trained models to process newly collected image samples of industrial production lines to achieve quality inspection, and the accuracy and reliability of the inspection results of industrial visual quality inspection are mainly determined by the training results of each model in industrial visual quality inspection. Based on this, the training scheme for each model in industrial visual quality inspection is further optimized in this application. Compared with the existing scheme, the scheme of this application reduces the defective rate of production on the one hand, and by solidifying and precipitating the method process and digitizing the experience, it is more conducive to promoting the development of the industry and can be widely used in the field of automation control technology; on the other hand, it can achieve efficient and accurate industrial quality inspection and can be widely used in the field of data processing technology; on the other hand, it can improve the timeliness of quality inspection feedback, facilitate the tracing of products with problems, improve product quality and production efficiency, and effectively avoid data leakage.
[0043] Specifically, the industrial visual quality inspection method disclosed in the embodiments of the present application is as follows: Figure 1 As shown, it mainly includes the following steps: Step 110: Input the collected workpiece image into a pre-trained feature extraction model to obtain high-dimensional feature data.
[0044] In this step, the feature extraction model is mainly trained based on sample data, and the sample data includes: collected sample data and expanded sample data, and the expanded sample data is generated using a pre-trained generative adversarial network algorithm model, and the generative adversarial network algorithm model includes a generative adversarial network algorithm model based on an adaptive compensation mechanism.
[0045] The collected sample data is, for example, image data collected by a visual sensor device on an industrial production line when performing data collection. The visual sensor device is configured in a key production link to capture images of workpieces in real time.
[0046] In this embodiment, the collected sample data is stored in a matrix form, and each image data is represented as a three-dimensional array. Specifically, if represents an image data collected, then It can be defined as: ,in, and Represents the spatial dimension coordinates of the image, Represents color channels (such as RGB channels), and the pixel value of each channel is between 0 and 255.
[0047] Furthermore, when labeling the collected sample data, this embodiment adopts manual labeling, and experienced technicians label the collected image data with defect types. During the labeling process, each image is assigned a label, such as one of no defect, crack, scratch, and rust.
[0048] In industrial visual quality inspection, a large amount of sample data (also referred to as training samples or training data in this article) is required to train the model. Insufficient sample size can easily lead to poor generalization ability of the training model, and affect the accuracy of the model and the accuracy and reliability of the quality inspection. However, the collection, acquisition, labeling, and preprocessing of a large amount of high-quality sample data are often very time-consuming and difficult. Therefore, in the embodiment of the present application, in addition to obtaining some training samples (i.e., collecting sample data) by collection, samples are also generated by data expansion technology, that is, a generative adversarial network (GAN) algorithm model based on an adaptive compensation mechanism is used to automatically obtain expanded sample data, and the problem of poor model generalization ability caused by insufficient training samples in industrial visual quality inspection is solved by expanding the sample data. It can be understood that since the expanded sample data does not require actual collection and manual labeling, it can save the time cost of obtaining training samples while making up for the problem of insufficient data and increasing the diversity of training samples.
[0049] In this embodiment, the generative adversarial network algorithm model based on the adaptive compensation mechanism includes: a generator and a discriminator, wherein the generator and the discriminator adopt a convolutional neural network structure, the generator is responsible for generating visually credible image data, and the discriminator determines the authenticity of the input image. When using the trained generative adversarial network algorithm model based on the adaptive compensation mechanism to generate extended sample data, it includes inputting a random noise vector into the generator, generating a generated image with a size consistent with the real image through the generator's multi-layer convolutional network, and then inputting the generated image into the discriminator, and the discriminator outputs the probability of the generated image being true / false. Among them, during the iteration process, if the probability output by the discriminator exceeds a certain threshold (such as 50%), it means that the discriminator can hardly distinguish the authenticity of the image data, and at this time the generator has a strong sample generation capability.
[0050] Furthermore, in this embodiment, the training process of the generative adversarial network algorithm model based on the adaptive compensation mechanism is as follows: Figure 2 As shown, the training process includes the following steps: Step 210: Initialize the parameters of the generator and the discriminator.
[0051] In this step, let the generator be , the discriminator is , the way to initialize the parameters of the generator and discriminator conforms to the following formula: , ,in, represents the parameters of the generator, represents the parameters of the discriminator, Represents a normal distribution.
[0052] Step 220: Input the random noise vector into the generator to obtain a generated image.
[0053] In the generator During the training process, the fixed discriminator , the random noise vector Input Generator to obtain the generated image.
[0054] In this step, the generated image can meet the following formula: ,in, Representation Generator The output generated image, represents the input random noise vector, Representation Generator The network parameters, Represents a generator function.
[0055] Step 230: Provide the generated image to the discriminator and calculate the loss of the generator based on the probability output by the discriminator.
[0056] In this step, the discriminator The probability of the corresponding generated image output conforms to the following formula , train the generator The goal is to make the discriminator The probability of misjudging a generated image as a real image can exceed a predetermined threshold (eg, 50%).
[0057] The loss function of the generator conforms to the following formula: ,in, represents the discriminator function, Representation Generator The loss function is Representation Discriminator network parameters.
[0058] Step 240: Input the generated image and the real image into the discriminator, and calculate the loss of the discriminator based on the probability output by the discriminator.
[0059] In the discriminator During the training process, the fixed generator , the generator The generated image is output and fed into the discriminator together with the real image. , discriminator Its parameters are adjusted by determining the authenticity of the input image.
[0060] In this step, the discriminator The loss function conforms to the following formula: ,in, Representation Discriminator The loss function is represents the real image, that is, the original acquired image, Representation Discriminator The probability that the output corresponds to a real image.
[0061] Step 250: Calculate the adaptive compensation loss based on the loss of the generator and the loss of the discriminator.
[0062] In this step, an adaptive compensation loss is used as the optimization target in each iterative training process. The adaptive compensation loss improves the quality and diversity of generated images by combining the traditional generative adversarial network loss, structural similarity loss and pixel-level loss.
[0063] In this embodiment, the adaptive compensation loss is equal to the sum of the products of the traditional generative adversarial network loss, the structural similarity loss and the pixel-level loss and their respective loss coefficients. Specifically, the adaptive compensation loss is calculated in accordance with the following formula: ,in, represents the adaptive compensation loss, represents the traditional generative adversarial network loss, represents the structural similarity loss, represents pixel-level loss, represents the first loss coefficient, represents the second loss coefficient, represents the third loss coefficient.
[0064] In some preferred embodiments, is set to 0.3, is set to 0.5, is set to 0.2.
[0065] Furthermore, the calculation methods of each loss term in the above formula (traditional generative adversarial network loss, structural similarity loss, pixel-level loss) are respectively in accordance with the following formulas: , , , in, Representation Generator The loss function is Representation Discriminator The loss function is represents the L2 norm, represents the square of the L2 norm, Calculates a function for the structural similarity index term, which is used to measure the similarity between the generated image and the real image.
[0066] Furthermore, the calculation method of the structural similarity index item calculation function conforms to the following formula: ,in, and Represents the real image and generate images The average brightness, and Represents the real image and generate images The standard deviation of Represents a real image and generate images The covariance between represents the first constant, Represents the second constant.
[0067] Furthermore, pixel-level loss The calculation method of the L2 norm in conforms to the following formula: ,in, represents the total number of pixels in the image, Indicates that the real image is The pixel value of a pixel, Indicates that the generated image is The pixel value of a pixel.
[0068] Step 260: Optimize the parameters of the generator and the discriminator according to the learning rate of the generative adversarial network and the adaptive compensation loss.
[0069] In this step, the parameters of the generator and discriminator are optimized by gradient descent. Specifically, the optimization method (or update method) of the parameters of the generator and discriminator conforms to the following formula: , ,in, Indicates a parameter update operation. represents the learning rate of the generative adversarial network, represents the loss gradient of the adaptive compensation loss with respect to the generator parameters, represents the loss gradient of the adaptation compensation loss with respect to the discriminator parameters.
[0070] In this embodiment, the learning rate of the generative adversarial network is It is calculated through the adaptive adjustment strategy, and its calculation method conforms to the following formula: ,in, represents the initial learning rate, Indicated in The decay factor at the iteration, Represents the initial attenuation factor.
[0071] In some preferred embodiments, is set to 0.01, is set to 0.95.
[0072] Step 270: Determine whether the preset iteration stop condition is met. If so, execute step 280 and the training ends, which means that the model training is completed. If not, continue to iterate and execute steps 220 to 260 until the preset iteration stop condition is met.
[0073] Optionally, the preset iteration stop condition is reaching a preset maximum number of iterations or reaching a predetermined generation quality. Exemplarily, the preset maximum number of iterations is set to 1000 times.
[0074] It can be understood that the embodiment of the present application, through the joint training of the generator and the discriminator, enables the trained generative adversarial network algorithm model based on the adaptive compensation mechanism to generate higher quality image data, which is conducive to increasing the diversity of training samples and ensuring that sufficient sample data can still be provided when the collected sample data is scarce.
[0075] Furthermore, after obtaining enough sample data, the feature extraction model is trained by inputting the obtained sample data into the feature extraction model. However, in the training process, the existing feature extraction model is prone to gradient vanishing or gradient exploding, which leads to unstable model training and affects the effect of feature extraction. To solve this problem, the present application also provides a method based on exploratory gradient descent to optimize the training process of the feature extraction model. By adopting an exploratory gradient descent neural network as a feature extraction model and combining a forward exploration mechanism, the gradient change trend is predicted, the learning step size and direction during the gradient update are optimized, and the problems of gradient vanishing or gradient exploding in the feature extraction model training process are effectively avoided.
[0076] In this embodiment, the training process of the feature extraction model is as follows: Figure 3 As shown, the training process includes the following steps: Step 310: Initialize the parameters of the feature extraction model.
[0077] In this embodiment, the feature extraction model is a neural network model based on exploratory gradient descent, and the neural network model includes an input layer, an output layer, and at least one intermediate layer (such as a hidden layer). In some examples, the structure of the neural network model is as follows: Input layer: receives and transmits sample data after sample expansion; Hidden layer: For example, it includes the first hidden layer, the second hidden layer, the third hidden layer and the fourth hidden layer. Each hidden layer is composed of a certain number of neurons. Specifically, The first hidden layer: has 128 neurons, which is used for preliminary feature extraction; The second hidden layer has 256 neurons, which is used to further abstract features. The third hidden layer: has 512 neurons, which is used to further deepen feature extraction; The fourth hidden layer has 1024 neurons, which is used to further deepen feature extraction. Output layer: It has 512 neurons and outputs the extracted high-dimensional feature data.
[0078] In this step, the parameters of the feature extraction model include the weights and bias parameters of the neural network. In some embodiments, the parameters of the feature extraction model may be initialized in accordance with the following formula: , ,in, represents the weight matrix of the i-th layer of the neural network, represents the bias vector of the i-th layer of the neural network, represents the scaling factor of the neural network weights, represents the scaling factor of the bias of the neural network, represents a normal distribution with a mean of 0 and a standard deviation of 1. In some preferred embodiments, is a noise vector whose elements are all 0.001.
[0079] Step 320: Input the sample data into the feature extraction model, perform linear transformation and nonlinear activation processing on the sample data according to the parameters of the feature extraction model, and obtain the feature representation of the output layer.
[0080] In this step, inputting the sample data into the feature extraction model includes inputting the sample data into a neural network model based on exploratory gradient descent. The sample data input into the neural network model will be subjected to linear transformation and nonlinear activation function processing when passing through each layer of the neural network, and finally the extracted feature vector is output by the output layer to obtain the feature representation of the output layer. The calculation method of the output of each layer of the neural network conforms to the following formula: ,in, Represents the neural network The activation output of the layer, Represents the neural network The output of the layer, Represents the adaptive ReLU activation function.
[0081] In some embodiments, let the input of the adaptive ReLU activation function be , then the calculation method of the adaptive ReLU activation function conforms to the following formula: ,in, and denote the adaptive coefficients of the positive and negative parts respectively, represents the maximum value function, In some preferred embodiments, is set to 0.3, is set to 0.7.
[0082] Step 330: Perform linear regression prediction based on historical gradient data, and adjust the step size and direction of gradient update according to the prediction results.
[0083] The exploratory gradient descent update strategy adopted in this embodiment is to predict the possible gradient changes during the update before each update of the feature extraction model parameters, so as to adjust the step size and direction of the gradient update according to the prediction results, so as to optimize the parameter adjustment during the training process and avoid falling into the local optimum too early.
[0084] In some embodiments, the prediction of gradient changes mainly includes using an exploratory gradient prediction function to perform linear regression prediction based on historical gradient data, and the calculation method thereof may conform to the following formula: ,in, represents the gradient prediction function, Represents the loss function with respect to the parameter The gradient of Indicated in The loss function of the iteration is about the parameter The gradient of represents the attenuation factor, represents the exploration intensity coefficient, In some preferred embodiments, is set to 0.98, is set to 2.
[0085] In this step, the size and sign of the gradient prediction function represent the step size and direction of the gradient update.
[0086] Step 340: Perform gradient update according to the step size and direction, and calculate the update amount of the parameters of the feature extraction model according to the updated gradient and the learning rate of the feature extraction model.
[0087] In this step, the learning rate of the feature extraction model is the learning rate of the neural network model, and the update amount of the parameters of the feature extraction model is the update amount of the weight and bias parameters of the neural network model. Specifically, the calculation method of the update amount of the parameters of the feature extraction model conforms to the following formula: , ,in, and They represent the neural network Layer weights and The update amount of the layer bias, represents the learning rate of the neural network, Represents the loss function with respect to the parameter The gradient of Represents the loss function with respect to the parameter The gradient of represents the loss function of the neural network, represents the exploration intensity coefficient, Denotes a gradient prediction function. In some preferred embodiments, is set to 0.03, Cross entropy loss is used.
[0088] Step 350: Update the parameters of the feature extraction model according to the update amount.
[0089] In this step, updating the parameters of the feature extraction model according to the update amount means updating the weights and bias parameters of the calculation neural network model according to the update amount.
[0090] In some embodiments, the weights and bias parameters of the neural network model are updated by using error back propagation.
[0091] Step 360: Determine whether the preset iteration stop condition is met. If so, execute step 370 and the training ends, which means that the model training is completed. If not, continue to iterate and execute steps 320 to 350 until the preset iteration stop condition is met.
[0092] Optionally, the preset iteration stop condition is reaching a preset maximum number of iterations or reaching a predetermined generation quality. Exemplarily, the preset maximum number of iterations is set to 1000 times.
[0093] It can be understood that the present application adopts a neural network based on exploratory gradient descent as a feature extraction model. The exploratory gradient descent method not only considers the current gradient information, but also adopts a forward exploration mechanism. By predicting the possible change trend of the gradient before the gradient is updated and adjusting the learning step size and direction, faster convergence speed and better local minimum can be achieved, thereby enhancing the generalization ability of the feature.
[0094] Further, after executing step 110, step 120 is executed. In step 120: the high-dimensional feature data is input into a pre-trained feature dimensionality reduction model to obtain low-dimensional feature data.
[0095] In this step, the feature dimensionality reduction model is mainly trained based on the high-dimensional data obtained after the feature advance model performs feature extraction on the sample data.
[0096] In the process of feature dimensionality reduction of high-dimensional data, the strong dependence between features may cause the reduced features to lose representativeness, thus affecting the performance of the model. Based on this, the present application also provides an autoencoder algorithm based on inverse reconstruction to optimize the training process of the feature dimensionality reduction model. By compressing and reconstructing the extracted high-dimensional feature data using the inverse reconstruction autoencoder algorithm in the feature dimensionality reduction stage, the dependence between features is reduced, and the validity of the features after dimensionality reduction can be ensured, as well as ensuring that the features after dimensionality reduction are more representative.
[0097] In this embodiment, the training process of the feature dimensionality reduction model is as follows: Figure 4 As shown, the training process includes the following steps: Step 410: Initialize parameters of the feature dimensionality reduction model.
[0098] In this embodiment, an autoencoder algorithm based on inverse reconstruction is used as a feature dimensionality reduction model. The autoencoder includes: an encoder and a decoder. The encoder is responsible for compressing the input high-dimensional data into a low-dimensional representation, and the decoder is used to reconstruct data from the compressed low-dimensional representation.
[0099] In this step, the parameters of the feature dimensionality reduction model include the weights and bias parameters of the autoencoder. In some embodiments, the parameters of the feature dimensionality reduction model are initialized in accordance with the following formula: , ,in, represents the initial weight matrix of the autoencoder, represents the initial bias of the autoencoder, and denote the number of neurons in the input and output layers, respectively. Indicated in A uniformly distributed random number in the interval.
[0100] Step 420: Input the high-dimensional data after feature extraction into the feature dimensionality reduction model.
[0101] In this step, inputting the high-dimensional data after feature extraction into the feature dimensionality reduction model includes inputting the high-dimensional data after feature extraction into an autoencoder algorithm based on inverse reconstruction (also referred to as autoencoder or autoencoder model in this article), and the input high-dimensional data is converted into a representation of a low-dimensional space (i.e., a low-dimensional feature representation) through the encoder, and the low-dimensional feature representation is then reconstructed into an output with the same dimension as the original data through the decoder.
[0102] In some embodiments, during the forward propagation of the feature-extracted high-dimensional data in the autoencoder, the output calculation method of the encoder conforms to the following formula: , further, the calculation method of the reconstruction output of its decoder conforms to the following formula: ,in, represents the low-dimensional feature representation of the encoding, represents the Sigmoid activation function, and denote the weights of the encoder and decoder respectively, and denote the bias of the encoder and decoder respectively, represents the input high-dimensional data, represents the reconstructed output of the decoder.
[0103] Step 430: Calculate the inverse reconstruction loss of the feature dimensionality reduction model.
[0104] In this step, the calculation method of the inverse reconstruction loss of the feature dimensionality reduction model conforms to the following formula: ,in, represents the inverse reconstruction loss function, Indicates the number of samples input in the current batch, represents the L2 norm, represents the regularization parameter, Represents KL divergence. KL divergence is used to measure the original data distribution. and reconstructing data distribution The difference between them ensures that the key features of the data are not lost during the dimensionality reduction process.
[0105] In some embodiments, the KL divergence is calculated in accordance with the following formula: ,in, and Represent the original data and reconstructed data in The probability distribution of dimensions, Represents the feature dimension before feature dimensionality reduction.
[0106] Step 440: Calculate the gradient according to the inverse reconstruction loss, and use the gradient descent algorithm to update the parameters of the feature dimensionality reduction model.
[0107] In this step, updating the parameters of the feature dimensionality reduction model is to update the weights and bias parameters of the autoencoder, specifically including updating the weights and bias parameters of the encoder and decoder in the autoencoder respectively.
[0108] In this embodiment, the weight and bias parameters of the encoder and decoder are updated in accordance with the following formula: , , , ,in, represents the learning rate of the autoencoder, represents the updated encoder weights, represents the updated encoder bias, represents the updated decoder weights, represents the updated decoder bias.
[0109] Furthermore, the gradient For example, the calculation method conforms to the following formula: ,in, represents the partial derivative of the loss function with respect to the reconstructed output, represents the partial derivative during decoding, is the partial derivative during encoding.
[0110] Step 450: Determine whether the preset iteration stop condition is met. If so, execute step 460 and the training ends, which means that the model training is completed. If not, continue to iterate and execute steps 420 to 440 until the preset iteration stop condition is met.
[0111] Optionally, the preset iteration stop condition is reaching a preset maximum number of iterations or reaching a predetermined generation quality. Exemplarily, the preset maximum number of iterations is set to 1200 times.
[0112] It can be understood that the present application adopts an autoencoder algorithm based on inverse reconstruction as a feature dimensionality reduction model, and adopts an inverse reconstruction strategy to process the high-dimensional data after input feature extraction, thereby enhancing the feature dimensionality reduction adaptability of the feature dimensionality reduction model, and can minimize the dependency between different features, thereby improving the encoding quality and decoding accuracy during the feature dimensionality reduction process.
[0113] Furthermore, after executing step 120, step 130 is executed. In step 130: the low-dimensional feature data is input into a pre-trained classifier model to obtain a classification result, thereby implementing quality detection according to the classification result.
[0114] In this step, the classification result includes: one of: no defect, crack, scratch and rust. The classifier model is mainly trained based on the low-dimensional data obtained after the feature dimension reduction model performs feature dimension reduction on the high-dimensional data.
[0115] In industrial visual quality inspection, classification tasks often involve unbalanced data distribution. When processing such data, traditional classifiers are prone to misclassification or overfitting, which reduces the classification accuracy. Based on this, in the training of the classifier model, this application optimizes the performance of the classifier through the support vector machine algorithm with constraint penalty and combines it with the adaptive vector decomposition mechanism, optimizes the processing of unbalanced data, and improves the robustness and accuracy of the classifier.
[0116] In this embodiment, the training process of the feature extraction model is as follows: Figure 5 As shown, the training process includes the following steps: Step 510: Initialize parameters of the classifier model.
[0117] In this step, a support vector machine based on constrained multiplication is used as a classifier model. The parameters of the classifier model include the weight and bias parameters of the support vector machine.
[0118] In some embodiments, the parameters of the classifier model are initialized in accordance with the following formula: , ,in, represents the weight of the support vector machine, Represents the bias of the support vector machine.
[0119] Step 520: Input the reduced low-dimensional data into the classifier model, and use a preset vector decomposition algorithm to decompose the feature space of the low-dimensional data to obtain key feature vectors.
[0120] In this step, inputting the low-dimensional data after dimensionality reduction into the classifier model is to input the low-dimensional data after dimensionality reduction into the support vector machine.
[0121] In some embodiments, using a preset vector decomposition algorithm to decompose the feature space of low-dimensional data includes: using a singular value decomposition algorithm to adaptively decompose the feature space (i.e., the high-dimensional space formed by the input low-dimensional data features) to identify key feature vectors and improve the accuracy and speed of classification. Specifically, the adaptive decomposition method conforms to the following formula: ,in, represents the feature vector, that is, the feature vector input to the extreme learning machine, that is, the feature vector after feature dimensionality reduction; and Respectively represent the left and right singular vector matrices, each of which contains the singular values of the features, which can extract the main features of the data. represents a diagonal matrix.
[0122] Step 530: Calculate the misclassification rate in the iteration process according to the key feature vector, and dynamically adjust the constraint penalty factor of the classifier model according to the misclassification rate.
[0123] In this step, the misclassification rate is used to measure the performance of the classifier on a specific training set. The calculation method of the misclassification rate in the iteration process based on the key feature vector conforms to the following formula: ,in, Indicates The misclassification rate of the iteration, Indicates an indicator function. When the brackets The value is 1 if the condition is true, otherwise it is 0. Indicates The actual labels of samples, Represents the classifier model for The prediction results of samples are Indicates the total number of samples input in the current batch, Represents the key eigenvectors obtained after vector decomposition.
[0124] Furthermore, the adjustment method of dynamically adjusting the constraint penalty factor of the classifier model according to the misclassification rate conforms to the following formula: ,in, represents the constraint penalty factor, Indicates The constraint penalty factor for the iteration, Represents the basic penalty value, represents the parameter that controls the adjustment strength of the penalty factor, represents the parameter that controls the adjustment speed of the penalty factor, Indicates The misclassification rate of iterations.
[0125] It can be understood that this embodiment dynamically adjusts the constraint penalty factor of the classifier model according to the calculated misclassification rate. It can increase the constraint penalty factor when the classification boundary of the classifier model is too strict, resulting in an increase in classification errors, or reduce the constraint penalty factor when the classification boundary of the classifier model is too loose, resulting in overfitting, thereby optimizing the performance of the classifier in processing imbalanced data and enhancing the robustness of the model under various operating conditions.
[0126] Step 540: Calculate the regularization coefficient of the classifier model, and calculate the loss function of the classifier model according to the regularization coefficient.
[0127] In this step, the regularization coefficient of the classifier model is calculated according to the following formula: ,in, represents the regularization coefficient of the classifier model, represents the initial regularization coefficient, represents the regularization coefficient of the tth iteration, Indicates the current iteration number, In some preferred embodiments, is set to 0.3.
[0128] Furthermore, the calculation method of the loss function of the classifier model according to the regularization coefficient conforms to the following formula: , in, represents the loss function of the classifier model, represents the number of samples, Indicates The labels of samples, Indicates The characteristics of the samples, represents the maximum value function, represents the L2 norm, Represents the regularization coefficient of the classifier model.
[0129] Step 550: Using a stochastic gradient descent algorithm, update the parameters of the classifier model according to the learning rate and loss function of the classifier model.
[0130] In this step, the learning rate of the classifier model is the learning rate of the support vector machine, and the loss function of the classifier model is the loss function of the support vector machine. Therefore, updating the parameters of the classifier model according to the learning rate and loss function of the classifier model is to update the weight and bias parameters of the support vector machine according to the learning rate and loss function of the support vector machine. Specifically, the parameter update method is expressed as: , ,in, and They represent the support vector machine in The weights and biases for the iterations, represents the learning rate of the support vector machine, represents the loss function of the support vector machine. In some preferred embodiments, is set to 0.01.
[0131] Step 560: Determine whether the preset iteration stop condition is met. If so, execute step 570 and the training ends, which means that the model training is completed. If not, continue to iterate and execute steps 520 to 550 until the preset iteration stop condition is met.
[0132] Optionally, the preset iteration stop condition is reaching a preset maximum number of iterations or reaching a predetermined generation quality. Exemplarily, the preset maximum number of iterations is set to 1000 times.
[0133] It can be understood that the present application adopts a constrained penalty-based support vector machine algorithm as a classification algorithm, and adopts an adaptive vector decomposition mechanism for the traditional support vector machine algorithm, which optimizes the performance of the classifier model when processing unbalanced data and enhances the robustness of the classifier model under various operating conditions.
[0134] In summary, this application effectively expands the training sample set, improves the diversity and representativeness of the data, and thus enhances the generalization ability and accuracy of the model. In the process of feature extraction and dimensionality reduction, the training stability of the neural network is optimized, the common gradient vanishing and explosion problems are avoided, and the convergence speed of the model and the quality of feature representation are improved. Finally, in the classification task, the accuracy and adaptability of the classifier are improved by optimizing the processing of unbalanced data, ensuring the reliability and efficiency of industrial visual quality inspection.
[0135] It can be understood that the present application utilizes trained models (including feature extraction models, feature dimensionality reduction models, and classifier models) to process newly collected workpiece image samples from industrial production lines to realize industrial visual quality inspection, which can achieve comprehensive automation of industrial visual quality inspection and greatly improve production efficiency and product quality.
[0136] In some preferred embodiments, the industrial visual quality inspection method provided in the present application also includes selecting an edge device with sufficient computing power and storage space according to the requirements of the application scenario, such as using a device with GPU or TPU acceleration, so as to deploy the feature extraction model, feature dimensionality reduction model and classifier model in the edge device to realize edge computing, ensuring that the device can efficiently handle high-frequency data acquisition and industrial visual quality inspection.
[0137] Furthermore, the present application also provides an industrial visual quality inspection device, such as Figure 6 As shown, the industrial visual quality inspection device includes: a feature extraction unit 610, a feature dimension reduction unit 620 and a classification quality inspection unit 630.
[0138] The feature extraction unit 610 is used to perform high-dimensional feature extraction on the collected workpiece image according to a pre-trained feature extraction model to obtain high-dimensional feature data.
[0139] The feature dimension reduction unit 620 is used to perform dimension reduction processing on the high-dimensional feature data output by the feature extraction unit 610 according to a pre-trained feature dimension reduction model to obtain low-dimensional feature data.
[0140] The classification quality inspection unit 630 is used to classify the low-dimensional feature data output by the feature dimension reduction unit 620 according to a pre-trained classifier model, and implement quality inspection according to the classification result.
[0141] In this embodiment, the feature extraction model, the feature dimensionality reduction model and the classifier model are trained based on the sample data. The sample data includes: the collected sample data and the expanded sample data. The expanded sample data is generated using a pre-trained adversarial network algorithm model. The adversarial network algorithm model includes a generative adversarial network algorithm model based on an adaptive compensation mechanism.
[0142] Furthermore, the generative adversarial network algorithm model based on the adaptive compensation mechanism includes a generator and a discriminator, and the training process of the generative adversarial network algorithm model based on the adaptive compensation mechanism includes iteratively executing the following steps until a preset stop iteration condition is reached: inputting a random noise vector into the generator to obtain a generated image; providing the generated image to the discriminator, and calculating the loss of the generator according to the probability output by the discriminator; inputting the generated image and the real image into the discriminator, and calculating the loss of the discriminator according to the probability output by the discriminator; calculating the adaptive compensation loss based on the loss of the generator and the loss of the discriminator; and optimizing the parameters of the generator and the discriminator based on the learning rate of the generative adversarial network and the adaptive compensation loss.
[0143] In some embodiments, the adaptive compensation loss is calculated in accordance with the following formula: ,in, represents the adaptive compensation loss, represents the traditional generative adversarial network loss, represents the structural similarity loss, represents pixel-level loss, represents the first loss coefficient, represents the second loss coefficient, represents the third loss coefficient.
[0144] Furthermore, the calculation method of each loss item conforms to the following formula: , , , in, represents the loss function of the generator, represents the loss function of the discriminator, represents the L2 norm, represents the square of the L2 norm, It is a function for calculating the structural similarity index item, which is used to measure the similarity between the generated image and the real image. represents the real image, Indicates the generated image.
[0145] Furthermore, the calculation method of the structural similarity index item calculation function conforms to the following formula: ,in, and Represents the real image and generate images The average brightness, and Represents the real image and generate images The standard deviation of Represents a real image and generate images The covariance between represents the first constant, Represents the second constant.
[0146] In some embodiments, the training process of the feature extraction model includes iteratively executing the following steps until a preset stop iteration condition is reached: inputting sample data into the feature extraction model, performing linear transformation and nonlinear activation processing on the sample data according to the parameters of the feature extraction model, and obtaining the feature representation of the output layer; performing linear regression prediction based on historical gradient data, and adjusting the step size and direction of the gradient update according to the prediction results; performing gradient update according to the step size and direction, and calculating the update amount of the parameters of the feature extraction model according to the updated gradient and the learning rate of the feature extraction model; and updating the parameters of the feature extraction model according to the update amount.
[0147] In some embodiments, the training process of the feature dimensionality reduction model includes iteratively executing the following steps until a preset stop iteration condition is reached: inputting the high-dimensional data after feature extraction into the feature dimensionality reduction model; calculating the inverse reconstruction loss of the feature dimensionality reduction model; calculating the gradient based on the inverse reconstruction loss, and using the gradient descent algorithm to update the parameters of the feature dimensionality reduction model.
[0148] In some embodiments, the training process of the classifier model includes iteratively executing the following steps until a preset condition for stopping iteration is reached: inputting the reduced low-dimensional data into the classifier model, and using a preset vector decomposition algorithm to decompose the feature space of the low-dimensional data to obtain key feature vectors; calculating the misclassification rate in the iterative process based on the key feature vectors, and dynamically adjusting the constraint penalty factor of the classifier model based on the misclassification rate; calculating the regularization coefficient of the classifier model, and calculating the loss function of the classifier model based on the regularization coefficient; using a stochastic gradient descent algorithm to update the parameters of the classifier model based on the learning rate and loss function of the classifier model.
[0149] In specific implementation, the constraint penalty factor is adjusted in accordance with the following formula: ,in, represents the constraint penalty factor, Indicates The constraint penalty factor for the iteration, Represents the basic penalty value, represents the parameter that controls the adjustment strength of the penalty factor, represents the parameter that controls the adjustment speed of the penalty factor, Indicates The misclassification rate of iterations.
[0150] Furthermore, the misclassification rate is calculated in accordance with the following formula: ,in, Indicates an indicator function. When the brackets The value is 1 if the condition is true, otherwise it is 0. Indicates The actual labels of samples, Represents the classifier model for The prediction results of samples are Indicates the total number of samples input in the current batch, represents the key feature vector.
[0151] Furthermore, the loss function of the classifier model is calculated in accordance with the following formula: ,in, represents the loss function of the classifier model, represents the number of samples, Indicates The labels of samples, Indicates The characteristics of the samples, represents the maximum value function, represents the L2 norm, Represents the regularization coefficient of the classifier model.
[0152] Furthermore, the calculation method of the regularization coefficient conforms to the following formula: ,in, represents the initial regularization coefficient, represents the regularization coefficient of the tth iteration, Indicates the current iteration number, Indicates the total number of iterations.
[0153] In specific implementation, each module / unit in the industrial visual quality inspection device can be implemented as an independent entity, or can be arbitrarily combined and implemented as the same or several entities. At the same time, the specific implementation of each module / unit in the industrial visual quality inspection device described above and the technical effects that can be achieved can be referred to the aforementioned industrial visual quality inspection method embodiment, which will not be repeated here.
[0154] The embodiment of the present invention further provides an electronic device, such as Figure 7 As shown, it includes a memory 710 and a processor 720. The memory 710 stores a program that can be run on the processor 720. When the program is executed by the processor 720, the various processes of the industrial visual quality inspection methods shown in the aforementioned embodiments can be implemented, and the same technical effect can be achieved. To avoid repetition, it will not be repeated here.
[0155] Those skilled in the art can understand that all or part of the steps in the various methods of the above embodiments can be completed by instructions, or by controlling related hardware through instructions, and the instructions can be stored in a computer-readable storage medium and loaded and executed by a processor. To this end, an embodiment of the present invention also provides a storage medium, on which a computer program or instruction is stored, and when the computer program or instruction is executed by the processor, each process of each embodiment of the aforementioned industrial visual quality inspection method can be implemented. Among them, the storage medium is, for example, a U disk, a mobile hard disk, a read-only memory (ROM), a random access memory (RAM), a disk or an optical disk, and other media that can store program codes.
[0156] Since the instructions stored in the storage medium can execute the steps in the industrial visual quality inspection method provided in the embodiment of the present invention, the beneficial effects that can be achieved by the industrial visual quality inspection method provided in the embodiment of the present invention can be achieved. For details, please refer to the previous embodiment and will not be repeated here. The specific implementation of each of the above operations can be referred to the previous embodiment and will not be repeated here.
[0157] Finally, it should be noted that: Obviously, the above embodiments are only examples for clearly explaining the present application, and are not intended to limit the implementation methods. For ordinary technicians in the relevant field, other different forms of changes or modifications can be made based on the above description. It is not necessary and impossible to list all the implementation methods here. The obvious changes or modifications derived from this are still within the scope of protection of the present application.
Claims
1. An industrial visual quality inspection method, comprising: Input the collected workpiece image into a pre-trained feature extraction model to obtain high-dimensional feature data; Inputting the high-dimensional feature data into a pre-trained feature dimensionality reduction model to obtain low-dimensional feature data; Input the low-dimensional feature data into a pre-trained classifier model to obtain a classification result, and perform quality inspection based on the classification result. The feature extraction model, the feature dimensionality reduction model and the classifier model are trained based on sample data, the sample data includes: collected sample data and expanded sample data, the expanded sample data is generated using a pre-trained generative adversarial network algorithm model, and the generative adversarial network algorithm model includes a generative adversarial network algorithm model based on an adaptive compensation mechanism; The generative adversarial network algorithm model based on the adaptive compensation mechanism includes a generator and a discriminator. The training process of the generative adversarial network algorithm model based on the adaptive compensation mechanism includes iteratively executing the following steps until a preset stop iteration condition is reached: Inputting a random noise vector into the generator to obtain a generated image; Providing the generated image to the discriminator, and calculating the loss of the generator according to the probability output by the discriminator; Inputting the generated image and the real image into the discriminator, and calculating the loss of the discriminator according to the probability output by the discriminator; Calculating an adaptive compensation loss based on the loss of the generator and the loss of the discriminator; Optimizing parameters of the generator and the discriminator according to the learning rate of the generative adversarial network and the adaptive compensation loss.
2. The industrial visual quality inspection method according to claim 1, wherein: The calculation method of the adaptive compensation loss conforms to the following formula: , in, represents the adaptive compensation loss, represents the traditional generative adversarial network loss, represents the structural similarity loss, represents pixel-level loss, represents the first loss coefficient, represents the second loss coefficient, represents the third loss coefficient.
3. The industrial visual quality inspection method according to claim 2, wherein: The calculation method of each loss item conforms to the following formula: , , , in, represents the loss function of the generator, represents the loss function of the discriminator, represents the L2 norm, represents the square of the L2 norm, is a structural similarity index item calculation function, used to measure the similarity between the generated image and the real image, represents the real image, represents the generated image.
4. The industrial visual quality inspection method according to claim 3, wherein: The calculation method of the structural similarity index item calculation function conforms to the following formula: , in, and Respectively represent the real images and the generated image The average brightness, and Respectively represent the real images and the generated image The standard deviation of Represents the real image and the generated image The covariance between represents the first constant, Represents the second constant.
5. The industrial visual quality inspection method according to claim 1, wherein: The training process of the feature extraction model includes iteratively executing the following steps until a preset stop iteration condition is reached: Inputting the sample data into the feature extraction model, performing linear transformation and nonlinear activation processing on the sample data according to the parameters of the feature extraction model, and obtaining a feature representation of an output layer; Perform linear regression prediction based on historical gradient data, and adjust the step size and direction of gradient update according to the prediction results; Performing gradient update according to the step size and direction, and calculating an update amount of the parameters of the feature extraction model according to the updated gradient and the learning rate of the feature extraction model; The parameters of the feature extraction model are updated according to the update amount.
6. The industrial visual quality inspection method according to claim 1, wherein: The training process of the feature dimensionality reduction model includes iteratively executing the following steps until a preset stop iteration condition is reached: Inputting the high-dimensional data after feature extraction into the feature dimensionality reduction model; Calculating the inverse reconstruction loss of the feature dimensionality reduction model; A gradient is calculated according to the inverse reconstruction loss, and a gradient descent algorithm is used to update the parameters of the feature dimensionality reduction model.
7. The industrial visual quality inspection method according to claim 6, wherein: The training process of the classifier model includes iteratively executing the following steps until a preset stop iteration condition is reached: Inputting the reduced low-dimensional data into the classifier model, and using a preset vector decomposition algorithm to decompose the feature space of the low-dimensional data to obtain key feature vectors; Calculating the misclassification rate in the iteration process according to the key feature vector, and dynamically adjusting the constraint penalty factor of the classifier model according to the misclassification rate; Calculating a regularization coefficient of the classifier model, and calculating a loss function of the classifier model according to the regularization coefficient; A stochastic gradient descent algorithm is used to update the parameters of the classifier model according to the learning rate and loss function of the classifier model.
8. The industrial visual quality inspection method according to claim 7, wherein: The constraint penalty factor is adjusted in accordance with the following formula: , in, represents the constraint penalty factor, Indicates The constraint penalty factor for the iteration, Represents the basic penalty value, represents the parameter that controls the adjustment strength of the penalty factor, represents the parameter that controls the adjustment speed of the penalty factor, Indicates The misclassification rate of iterations.
9. The industrial visual quality inspection method according to claim 8, wherein: The misclassification rate is calculated in accordance with the following formula: , in, Indicates an indicator function. When the brackets The value is 1 if the condition is true, otherwise it is 0. Indicates The actual labels of samples, Indicates that the classifier model is The prediction results of samples are Indicates the total number of samples input in the current batch, Denotes the key feature vector.
10. The industrial visual quality inspection method according to claim 7, wherein: The loss function of the classifier model is calculated in accordance with the following formula: , in, represents the loss function of the classifier model, represents the number of samples, Indicates The labels of samples, Indicates The characteristics of the samples, represents the maximum value function, represents the L2 norm, Represents the regularization coefficient of the classifier model.
11. The industrial visual quality inspection method according to claim 10, wherein: The calculation method of the regularization coefficient conforms to the following formula: , in, represents the initial regularization coefficient, represents the regularization coefficient of the tth iteration, Indicates the current iteration number, Indicates the total number of iterations.
12. An industrial visual quality inspection device, comprising: A feature extraction unit extracts high-dimensional features from the collected workpiece image according to a pre-trained feature extraction model to obtain high-dimensional feature data; A feature dimension reduction unit performs dimension reduction processing on the high-dimensional feature data according to a pre-trained feature dimension reduction model to obtain low-dimensional feature data; The classification quality inspection unit classifies the low-dimensional feature data according to a pre-trained classifier model and performs quality inspection according to the classification results. The feature extraction model, the feature dimension reduction model and the classifier model are trained based on sample data, and the sample data includes: collected sample data and expanded sample data, and the expanded sample data is generated by using a pre-trained generative adversarial network algorithm model, and the generative adversarial network algorithm model includes a generative adversarial network algorithm model based on an adaptive compensation mechanism; The generative adversarial network algorithm model based on the adaptive compensation mechanism includes a generator and a discriminator. The training process of the generative adversarial network algorithm model based on the adaptive compensation mechanism includes iteratively executing the following steps until a preset stop iteration condition is reached: Inputting a random noise vector into the generator to obtain a generated image; Providing the generated image to the discriminator, and calculating the loss of the generator according to the probability output by the discriminator; Inputting the generated image and the real image into the discriminator, and calculating the loss of the discriminator according to the probability output by the discriminator; Calculating an adaptive compensation loss based on the loss of the generator and the loss of the discriminator; Optimizing parameters of the generator and the discriminator according to the learning rate of the generative adversarial network and the adaptive compensation loss.
13. The industrial visual quality inspection device according to claim 12, wherein: The calculation method of the adaptive compensation loss conforms to the following formula: , in, represents the adaptive compensation loss, represents the traditional generative adversarial network loss, represents the structural similarity loss, represents pixel-level loss, represents the first loss coefficient, represents the second loss coefficient, represents the third loss coefficient.
14. The industrial visual quality inspection device according to claim 13, wherein: The calculation method of each loss item conforms to the following formula: , , , in, represents the loss function of the generator, represents the loss function of the discriminator, represents the L2 norm, represents the square of the L2 norm, is a structural similarity index item calculation function, used to measure the similarity between the generated image and the real image, represents the real image, represents the generated image.
15. The industrial visual quality inspection device according to claim 14, wherein: The calculation method of the structural similarity index item calculation function conforms to the following formula: , in, and Respectively represent the real images and the generated image The average brightness, and Respectively represent the real images and the generated image The standard deviation of Represents the real image and the generated image The covariance between represents the first constant, Represents the second constant.
16. The industrial visual quality inspection device according to claim 12, wherein: The training process of the classifier model includes iteratively executing the following steps until a preset stop iteration condition is reached: Inputting the reduced low-dimensional data into the classifier model, and using a preset vector decomposition algorithm to decompose the feature space of the low-dimensional data to obtain key feature vectors; Calculating the misclassification rate in the iteration process according to the key feature vector, and dynamically adjusting the constraint penalty factor of the classifier model according to the misclassification rate; Calculating a regularization coefficient of the classifier model, and calculating a loss function of the classifier model according to the regularization coefficient; A stochastic gradient descent algorithm is used to update the parameters of the classifier model according to the learning rate and loss function of the classifier model.
17. The industrial visual quality inspection device according to claim 16, wherein: The constraint penalty factor is adjusted in accordance with the following formula: , in, represents the constraint penalty factor, Indicates The constraint penalty factor for the iteration, Represents the basic penalty value, represents the parameter that controls the adjustment strength of the penalty factor, represents the parameter that controls the adjustment speed of the penalty factor, Indicates The misclassification rate of iterations; The misclassification rate is calculated in accordance with the following formula: , in, Indicates an indicator function. When the brackets The value is 1 if the condition is true, otherwise it is 0. Indicates The actual labels of samples, Indicates that the classifier model is The prediction results of samples are Indicates the total number of samples input in the current batch, Denotes the key feature vector.
18. The industrial visual quality inspection device according to claim 16, wherein: The loss function of the classifier model is calculated in accordance with the following formula: , in, represents the loss function of the classifier model, represents the number of samples, Indicates The labels of samples, Indicates The characteristics of the samples, represents the maximum value function, represents the L2 norm, represents the regularization coefficient of the classifier model; The calculation method of the regularization coefficient conforms to the following formula: , in, represents the initial regularization coefficient, represents the regularization coefficient of the tth iteration, Indicates the current iteration number, Indicates the total number of iterations.
19. An electronic device comprising: A processor, a memory, and a program stored in the memory and executable on the processor, wherein the program implements the steps of the method according to any one of claims 1 to 11 when executed by the processor.
20. A storage medium having a computer program or instruction stored thereon, wherein the computer program or instruction, when executed by a processor, implements the steps of the method according to any one of claims 1 to 11.
Citation Information
Patent Citations
Desoldering detection method based on photovoltaic module image acquired by unmanned aerial vehicle
CN118657784A