Image Defect Detection Method, Device, Electronic Device and Storage Medium
By training the autoencoder and selecting the appropriate latent feature dimension, the problem of difficulty in setting latent feature dimensions in the prior art is solved, and the efficiency of image defect judgment is improved.
Patent Information
- Application Number
- CN202110164687.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-02-05
- Publication Date
- 2025-06-10
- Estimated Expiration
- 2041-02-05
AI Technical Summary
In the prior art, it is difficult to directly set the latent feature dimensions of the autoencoder, resulting in low efficiency in judging defective images.
By obtaining sample image training data, selecting the latent feature dimension of the autoencoder, and by training the autoencoder, dimensionality reduction latent features, calculating the distribution center point and distance score, the suitability of the latent feature dimension is judged, and the optimal latent feature dimension is finally determined for image defect detection.
The latent feature dimension with distinction ability is effectively confirmed, and the efficiency of image defect judgment is improved.
Smart Images

Figure CN114881913B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of product yield detection, and particularly relates to an image defect detection method, device, electronic device and storage medium. Background Art
[0002] In the prior art, an algorithm model can be used to detect the image of a product to determine whether there are defects. However, the current method for adjusting the latent feature dimension of an autoencoder is difficult to directly set the size of the latent feature dimension, resulting in low judgment efficiency for defective images. Summary of the Invention
[0003] In view of the above, it is necessary to propose an image defect detection method, device and electronic device to improve the judgment efficiency of defective images.
[0004] The first aspect of the present application provides an image defect detection method, and the method includes:
[0005] Obtain sample image training data;
[0006] Select the latent feature dimension of the autoencoder and obtain a score, including:
[0007] Set the latent feature dimension of the autoencoder;
[0008] Use the sample image training data to train the autoencoder and obtain a trained autoencoder;
[0009] Input normal sample image data and defective sample image data into the trained autoencoder respectively, and obtain the latent features of the normal sample image data and the latent features of the defective samples through the trained autoencoder;
[0010] Reduce the dimension of the latent features of the normal sample image data to obtain a plurality of first latent features corresponding to the normal sample image data, and reduce the dimension of the latent features of the defective sample image data to obtain a plurality of second latent features corresponding to the defective samples;
[0011] Calculate the distribution center point of the plurality of first latent features according to the plurality of first latent features;
[0012] Calculate the distance value of each second latent feature in the plurality of second latent features from the distribution center point respectively, and sum the distance values of the plurality of second latent features from the distribution center point to obtain the score;
[0013] Determine whether the score is greater than the reference score. When the score is greater than the reference score, use the score as the new reference score, and re - execute the selection of the latent feature dimension of the auto - encoder to obtain a score. Or when the score is less than or equal to the reference score, use the currently set latent feature dimension as the optimal latent feature dimension;
[0014] Use the optimal latent feature dimension as the latent feature dimension of the auto - encoder, input the test image into the auto - encoder, and use the auto - encoder to obtain a reconstructed image;
[0015] Calculate the reconstruction error between the test image and the reconstructed image. When the reconstruction error is greater than a preset threshold, output the judgment result that the test image is a defective image; or when the reconstruction error is less than or equal to the threshold, output the judgment result that the test image is a normal image.
[0016] Preferably, setting the latent feature dimension of the auto - encoder includes:
[0017] Set the dimension of the latent feature extracted by the encoding layer of the auto - encoder.
[0018] Preferably, using the sample image training data to train the auto - encoder and obtaining the trained auto - encoder includes:
[0019] Vectorize the sample image training data to obtain the feature vector of the sample image training data;
[0020] Use the encoding layer of the auto - encoder to operate on the feature vector to obtain the latent feature of the sample image training data;
[0021] Use the decoding layer of the auto - encoder to operate on the latent feature and perform a reduction process on the latent feature obtained after the operation;
[0022] Optimize the auto - encoder to obtain the trained auto - encoder.
[0023] Preferably, respectively inputting the normal sample image data and the defective sample image data into the trained auto - encoder and obtaining the latent feature of the normal sample image data and the latent feature of the defective sample by the trained auto - encoder includes:
[0024] Input the normal sample image data into the trained auto - encoder, and obtain the latent feature of the normal sample image data through the encoding layer of the trained auto - encoder; and
[0025] Input the defective sample image data into the trained auto - encoder, and obtain the latent feature of the defective sample image data through the encoding layer of the trained auto - encoder.
[0026] Preferably, the step of reducing the latent features of the normal sample image data to obtain a plurality of first latent features corresponding to the normal sample image data, and reducing the latent features of the defective sample image data to obtain a plurality of second latent features corresponding to the defective samples includes:
[0027] Using the t-distributed Stochastic Neighbor Embedding (t-SNE) algorithm to reduce the latent features of the normal sample image data to obtain a plurality of first latent features corresponding to the normal sample image data, and reducing the latent features of the defective sample image data to obtain a plurality of second latent features corresponding to the defective samples.
[0028] Preferably, the step of calculating the distribution center points of the plurality of first latent features includes:
[0029] Calculating the average value of the plurality of first latent features in each dimension of three dimensions, and taking the point corresponding to the coordinates composed of the average values of each dimension of the three dimensions as the center point of the plurality of first latent features.
[0030] Preferably, the step of respectively calculating the distance values between each second latent feature in the plurality of second latent features and the distribution center point, and summing the distance values between the plurality of second latent features and the distribution center point to obtain a score includes:
[0031] Respectively calculating the Euclidean distance between each second latent feature in the plurality of second latent features and the distribution center point, and summing the Euclidean distances between the plurality of second latent features and the distribution center point to obtain the score.
[0032] A second aspect of the present application provides an image defect detection device, the device includes:
[0033] A training data acquisition module, configured to acquire sample image training data;
[0034] A latent feature dimension selection module, configured to select the latent feature dimension of the autoencoder and obtain a score, including:
[0035] A setting module, configured to set the latent feature dimension of the autoencoder;
[0036] A training module, configured to train the autoencoder using the sample image training data and obtain a trained autoencoder;
[0037] A latent feature acquisition module, configured to respectively input normal sample image data and defective sample image data into the trained autoencoder, and obtain the latent features of the normal sample image data and the latent features of the defective samples through the trained autoencoder;
[0038] A dimensionality reduction module, configured to reduce the dimensionality of the latent features of the normal sample image data to obtain a plurality of first latent features corresponding to the normal sample image data, and reduce the dimensionality of the latent features of the defective sample image data to obtain a plurality of second latent features corresponding to the defective samples;
[0039] A center point calculation module, configured to calculate the distribution center point of the plurality of first latent features according to the plurality of first latent features;
[0040] A score calculation module, configured to calculate the distance value of each of the plurality of second latent features from the distribution center point, and sum up the distance values of the plurality of second latent features from the distribution center point to obtain a score;
[0041] A judgment module, configured to judge whether the score is greater than a reference score, and when the score is greater than the reference score, use the score as a new reference score and re - call the latent feature dimension selection module, or when the score is less than or equal to the reference score, use the currently set latent feature dimension as the optimal latent feature dimension;
[0042] A reconstruction module, configured to output the optimal latent feature dimension as the latent feature dimension of the auto - encoder, input a test image into the auto - encoder, and obtain a reconstructed image using the auto - encoder;
[0043] An output module, configured to calculate the reconstruction error between the test image and the reconstructed image, and when the reconstruction error is greater than a preset threshold, output a judgment result that the test image is a defective image; or when the reconstruction error is less than or equal to the threshold, output a judgment result that the test image is a normal image.
[0044] The third aspect of the present application provides an electronic device, which includes:
[0045] A memory, storing at least one instruction; and
[0046] A processor, configured to execute the instructions stored in the memory to implement the image defect detection method described above.
[0047] The fourth aspect of the present application provides a computer storage medium, on which a computer program is stored, and when the computer program is executed by a processor, the image defect detection method described above is implemented.
[0048] The present invention can effectively confirm the latent feature dimensions with discrimination ability, and improve the efficiency of image defect judgment. Description of the Drawings
[0049] Figure 1 It is a flowchart of the image defect detection method in an embodiment of the present invention.
[0050] Figure 2 Flowchart of selecting the latent feature dimension of the autoencoder and obtaining scores in an embodiment of the present invention.
[0051] Figure 3 Structural diagram of the image defect detection device in an embodiment of the present invention.
[0052] Figure 4 Schematic diagram of an electronic device in an embodiment of the present invention.
[0053] Description of main component symbols
[0054]
[0055] Specific embodiments
[0056] In order to more clearly understand the above objects, features and advantages of the present invention, the present invention will be described in detail below with reference to the accompanying drawings and specific embodiments. It should be noted that, without conflict, the embodiments of the present application and the features in the embodiments may be combined with each other.
[0057] Many specific details are set forth in the following description in order to provide a thorough understanding of the present invention. The described embodiments are only a part of the embodiments of the present invention, rather than all of the embodiments. All other embodiments obtained by those of ordinary skill in the art based on the embodiments of the present invention without creative efforts shall fall within the protection scope of the present invention.
[0058] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as commonly understood by those of ordinary skill in the technical field to which the present invention belongs. The terms used in the specification of the present invention herein are only for the purpose of describing specific embodiments and are not intended to limit the present invention.
[0059] Preferably, the image defect detection method of the present invention is applied to one or more electronic devices. The electronic device is a device capable of automatically performing numerical calculations and / or information processing according to pre-set or stored instructions, and its hardware includes but is not limited to a microprocessor, an application specific integrated circuit (ASIC), a field-programmable gate array (FPGA), a digital signal processor (DSP), an embedded device, etc.
[0060] The electronic device may be a computing device such as a desktop computer, a laptop computer, a tablet computer, or a cloud server. The device may interact with the user through a keyboard, a mouse, a remote control, a touchpad, or a voice control device.
[0061] Embodiment 1
[0062] Figure 1 It is a flowchart of an image defect detection method in an embodiment of the present invention. The image defect detection method is applied to an electronic device. According to different requirements, the order of the steps in the flowchart can be changed, and some steps can be omitted.
[0063] Referring to Figure 1 as shown, the image defect detection method specifically includes the following steps:
[0064] Step S11, obtaining sample image training data.
[0065] In this embodiment, the sample image training data includes defective sample training images and normal sample training images.
[0066] Step S12, selecting the latent feature dimension of the autoencoder and obtaining a score.
[0067] Combined with Figure 2 , the selecting the latent feature dimension of the autoencoder and obtaining a score includes:
[0068] Step S21, setting the latent feature dimension of the autoencoder.
[0069] In this embodiment, the setting the latent feature dimension of the autoencoder includes:
[0070] Setting the dimension of the latent feature extracted by the encoding layer of the autoencoder. In this embodiment, the autoencoder extracts the latent feature according to the image data.
[0071] Step S22, training the autoencoder using the sample image training data and obtaining a trained autoencoder.
[0072] In this embodiment, the training the autoencoder using the sample image training data and obtaining a trained autoencoder includes:
[0073] Performing vectorization processing on the sample image training data to obtain a first feature vector of the sample image training data;
[0074] Using the encoding layer of the autoencoder to perform an operation on the first feature vector to obtain the latent feature of the sample image training data;
[0075] Operate on the latent features using the decoding layer of the autoencoder, and perform restoration processing on the latent features obtained after the operation;
[0076] Optimize the autoencoder to obtain a trained autoencoder.
[0077] In this embodiment, the dimension of the latent features of the sample image training data is the same as the dimension of the latent features of the autoencoder set in step S21.
[0078] The optimizing the autoencoder to obtain a trained autoencoder includes:
[0079] Set a loss function, and train the autoencoder to minimize the loss function to obtain the trained autoencoder. In this embodiment, the loss function may include a cross-entropy function or a mean squared error function.
[0080] Step S23, input normal sample image data and defective sample image data into the trained autoencoder respectively, and obtain the latent features of the normal sample image data and the latent features of the defective sample through the trained autoencoder.
[0081] In this embodiment, the inputting normal sample image data and defective sample image data into the trained autoencoder respectively, and obtaining the latent features of the normal sample image data and the latent features of the defective sample includes:
[0082] Input normal sample image data into the trained autoencoder, and obtain the latent features of the normal sample image data through the encoding layer of the trained autoencoder; and input defective sample image data into the trained autoencoder, and obtain the latent features of the defective sample image data through the encoding layer of the trained autoencoder.
[0083] In this embodiment, the dimension of the latent features of the normal sample image data is the same as the dimension of the latent features of the autoencoder set in step S21, and the dimension of the latent features of the defective sample image data is the same as the dimension of the latent features of the autoencoder set in step S21.
[0084] Step S24, reduce the dimension of the latent features of the normal sample image data to obtain a plurality of first latent features corresponding to the normal sample image data, and reduce the dimension of the latent features of the defective sample image data to obtain a plurality of second latent features corresponding to the defective sample.
[0085] In this embodiment, the reducing the dimension of the latent features of the normal sample image data to obtain a plurality of first latent features corresponding to the normal sample image data, and reducing the dimension of the latent features of the defective sample image data to obtain a plurality of second latent features corresponding to the defective sample includes:
[0086] Use the t-distributed Stochastic Neighbor Embedding (t-SNE) algorithm to reduce the dimensionality of the latent features of the normal sample image data to obtain a plurality of first latent features corresponding to the normal sample image data, and reduce the dimensionality of the latent features of the defective sample image data to obtain a plurality of second latent features corresponding to the defective samples.
[0087] In this embodiment, using the t-distributed Stochastic Neighbor Embedding (t-SNE) algorithm to reduce the dimensionality of the latent features of the normal sample image data to obtain a plurality of first latent features corresponding to the normal sample image data includes:
[0088] Solve the Gaussian probability distribution matrix P1 of the latent features of the normal sample image data;
[0089] Randomly initialize the low-dimensional latent feature Y1, and solve the t-distribution probability matrix Q1 of the low-dimensional latent feature Y1, where the low-dimensional latent feature Y1 is a randomly generated vector, and the dimension of the low-dimensional latent feature Y1 is the same as the dimension of the latent features of the autoencoder set in step S11;
[0090] Taking the KL divergence between the Gaussian probability distribution matrix P1 and the t-distribution probability matrix Q1 as the loss function, use the gradient descent method to iteratively solve the low-dimensional latent feature Y1 based on the loss function, and use the low-dimensional latent feature Y1 obtained after the iteration is completed as the plurality of first latent features.
[0091] In this embodiment, using the t-distributed Stochastic Neighbor Embedding (t-SNE) algorithm to reduce the dimensionality of the latent features of the defective sample image data to obtain a plurality of second latent features corresponding to the defective sample image data includes:
[0092] Solve the Gaussian probability distribution matrix P2 of the latent features of the defective sample image data;
[0093] Randomly initialize the low-dimensional latent feature Y2, and solve the t-distribution probability matrix Q2 of the low-dimensional latent feature Y2, where the low-dimensional latent feature Y2 is a randomly generated vector, and the dimension of the low-dimensional latent feature Y2 is the same as the dimension of the latent features of the autoencoder set in step S11;
[0094] Taking the KL divergence between the Gaussian probability distribution matrix P2 and the t-distribution probability matrix Q2 as the loss function, use the gradient descent method to iteratively solve the low-dimensional latent feature Y2 based on the loss function, and use the low-dimensional latent feature Y2 obtained after the iteration is completed as the plurality of second latent features.
[0095] Step S25, calculate the distribution center points of the plurality of first latent features according to the plurality of first latent features.
[0096] In this embodiment, calculating the distribution center point of the plurality of first latent features based on the plurality of first latent features includes:
[0097] Calculating the average value of each dimension of the three dimensions of the plurality of first latent features, and taking the point corresponding to the coordinates composed of the average values of each dimension of the three dimensions as the distribution center point of the plurality of first latent features.
[0098] For example, when the coordinates of the plurality of first latent features [A 1 , A 2 , …, A N are [(x 1 , y 1 , z 1 ), (x 2 , y 2 , z 2 ), …, (x N , y N , z N )], the coordinates of the distribution center point of the plurality of first latent features [A 1 , A 2 , …, A N are
[0099] Step S26: Calculate the distance value of each second latent feature in the plurality of second latent features from the distribution center point, and sum the distance values of the plurality of second latent features from the distribution center point to obtain the score.
[0100] In this embodiment, calculating the distance value of each second latent feature in the plurality of second latent features from the distribution center point, and summing the distance values of the plurality of second latent features from the distribution center point to obtain a score includes:
[0101] Calculate the Euclidean distance of each second latent feature in the plurality of second latent features from the distribution center point, and sum the Euclidean distances of the plurality of second latent features from the distribution center point to obtain the score.
[0102] For example, when the coordinates of the plurality of second latent features [B 1 , B 2 , …, B N are [(X 1 , Y 1 , Z 1 ), (X 2 , Y 2 , Z 2 ), …, (X N , Y N , Z N )], feature Bj (X j , Y j , Z j ) to the center point of the distribution The Euclidean distance is The score is
[0103] Step S13: Determine whether the score is greater than the reference score. When the score is greater than the reference score, use the score as the new reference score and re - execute the step of selecting the latent feature dimension of the auto - encoder to obtain a score. Or when the score is less than or equal to the reference score, use the currently set latent feature dimension as the optimal latent feature dimension.
[0104] Step S14: Use the optimal latent feature dimension as the latent feature dimension of the auto - encoder, input the test image into the auto - encoder, and use the auto - encoder to obtain a reconstructed image.
[0105] In this embodiment, inputting the test image into the auto - encoder and using the auto - encoder to obtain a reconstructed image includes:
[0106] Vectorize the test image to obtain a second feature vector of the test image;
[0107] Use the encoding layer of the auto - encoder to operate on the second feature vector to obtain the latent feature of the test image;
[0108] Use the decoding layer of the auto - encoder to operate on the latent feature of the test image and perform a reduction process on the obtained latent feature after the operation to obtain the reconstructed image.
[0109] Step S15: Calculate the reconstruction error between the test image and the reconstructed image. When the reconstruction error is greater than a preset threshold, output the judgment result that the test image is a defective image; or when the reconstruction error is less than or equal to the threshold, output the judgment result that the test image is a normal image.
[0110] In this embodiment, calculating the reconstruction error between the test image and the reconstructed image includes:
[0111] Calculate the mean square error between the test image and the reconstructed image, and use the mean square error as the reconstruction error.
[0112] In other embodiments, calculating the reconstruction error between the test image and the reconstructed image may include:
[0113] Calculate the cross - entropy between the test image and the reconstructed image, and use the cross - entropy as the reconstruction error.
[0114] The present invention can effectively confirm the latent feature dimensions with discrimination ability, improving the efficiency of image defect judgment.
[0115] Embodiment 2
[0116] Figure 3 It is a structural diagram of an image defect detection device 30 in an embodiment of the present invention.
[0117] In some embodiments, the image defect detection device 30 runs in an electronic device. The image defect detection device 30 may include a plurality of functional modules composed of program code segments. The program code of each program segment in the image defect detection device 30 can be stored in a memory and executed by at least one processor to perform the image defect detection function.
[0118] In this embodiment, the image defect detection device 30 can be divided into a plurality of functional modules according to the functions it performs. Refer to Figure 3 As shown, the image defect detection device 30 may include a training data acquisition module 301, a latent feature dimension selection module 302, a judgment module 303, a reconstruction module 304, and an output module 305. The module referred to in the present invention means a series of computer program segments that can be executed by at least one processor and can complete fixed functions, and are stored in a memory. In some embodiments, the functions of each module will be described in detail in subsequent embodiments.
[0119] The training data acquisition module 301 acquires sample image training data.
[0120] In this embodiment, the sample image training data includes defective sample training images and normal sample training images.
[0121] The latent feature dimension selection module 302 selects the latent feature dimensions of the autoencoder and obtains scores.
[0122] In this embodiment, the latent feature dimension selection module 302 includes a setting module 311, a training module 312, a latent feature acquisition module 313, a dimensionality reduction module 314, a center point calculation module 315, and a score calculation module 316.
[0123] The setting module 311 sets the latent feature dimensions of the autoencoder.
[0124] In this embodiment, setting the latent feature dimensions of the autoencoder includes:
[0125] Setting the dimension of the latent feature extracted by the encoding layer of the autoencoder. In this embodiment, the autoencoder extracts latent features according to image data.
[0126] The training module 312 trains the autoencoder using the sample image training data and obtains a trained autoencoder.
[0127] In this embodiment, training the autoencoder using the sample image training data and obtaining a trained autoencoder includes:
[0128] Vectorize the sample image training data to obtain a first feature vector of the sample image training data;
[0129] Use the encoding layer of the autoencoder to operate on the first feature vector to obtain the latent features of the sample image training data;
[0130] Use the decoding layer of the autoencoder to operate on the latent features and perform reduction processing on the latent features obtained after the operation;
[0131] Optimize the autoencoder to obtain a trained autoencoder.
[0132] In this embodiment, the dimension of the latent features of the sample image training data is the same as the dimension of the latent features of the autoencoder set in the setting module 311.
[0133] Optimizing the autoencoder to obtain a trained autoencoder includes:
[0134] Set a loss function and train the autoencoder to minimize the loss function to obtain the trained autoencoder. In this embodiment, the loss function may include a cross-entropy function or a mean squared error function.
[0135] The latent feature acquisition module 313 inputs normal sample image data and defective sample image data into the trained autoencoder respectively, and obtains the latent features of the normal sample image data and the latent features of the defective samples through the trained autoencoder.
[0136] In this embodiment, inputting normal sample image data and defective sample image data into the trained autoencoder respectively and obtaining the latent features of the normal sample image data and the latent features of the defective samples includes:
[0137] Input normal sample image data into the trained autoencoder, and obtain the latent features of the normal sample image data through the encoding layer of the trained autoencoder; and input defective sample image data into the trained autoencoder, and obtain the latent features of the defective sample image data through the encoding layer of the trained autoencoder.
[0138] In this embodiment, the latent feature dimension of the normal sample image data is the same as the latent feature dimension of the autoencoder set in the setting module 311, and the latent feature dimension of the defective sample image data is the same as the latent feature dimension of the autoencoder set in the setting module 311.
[0139] The dimensionality reduction module 314 reduces the dimension of the latent features of the normal sample image data to obtain a plurality of first latent features corresponding to the normal sample image data, and reduces the dimension of the latent features of the defective sample image data to obtain a plurality of second latent features corresponding to the defective samples.
[0140] In this embodiment, reducing the dimension of the latent features of the normal sample image data to obtain a plurality of first latent features corresponding to the normal sample image data, and reducing the dimension of the latent features of the defective sample image data to obtain a plurality of second latent features corresponding to the defective samples includes:
[0141] Using the t-distributed Stochastic Neighbor Embedding (t-SNE) algorithm to reduce the dimension of the latent features of the normal sample image data to obtain a plurality of first latent features corresponding to the normal sample image data, and reducing the dimension of the latent features of the defective sample image data to obtain a plurality of second latent features corresponding to the defective samples.
[0142] In this embodiment, using the t-distributed Stochastic Neighbor Embedding (t-SNE) algorithm to reduce the dimension of the latent features of the normal sample image data to obtain a plurality of first latent features corresponding to the normal sample image data includes:
[0143] Solving the Gaussian probability distribution matrix P1 of the latent features of the normal sample image data;
[0144] Randomly initializing the low-dimensional latent feature Y1, and solving the t-distribution probability matrix Q1 of the low-dimensional latent feature Y1, where the low-dimensional latent feature Y1 is a randomly generated vector, and the dimension of the low-dimensional latent feature Y1 is the same as the latent feature dimension of the autoencoder set in step S11;
[0145] Taking the KL divergence between the Gaussian probability distribution matrix P1 and the t-distribution probability matrix Q1 as the loss function, and using the gradient descent method to iteratively solve the low-dimensional latent feature Y1 based on the loss function, and taking the low-dimensional latent feature Y1 obtained after the iteration is completed as the plurality of first latent features.
[0146] In this embodiment, using the t-distributed Stochastic Neighbor Embedding (t-SNE) algorithm to reduce the dimension of the latent features of the defective sample image data to obtain a plurality of second latent features corresponding to the defective sample image data includes:
[0147] Solving the Gaussian probability distribution matrix P2 of the latent features of the defective sample image data;
[0148] Randomly initialize the low-dimensional latent feature Y2, and solve the t-distribution probability matrix Q2 of the low-dimensional latent feature Y2, where the low-dimensional latent feature Y2 is a randomly generated vector, and the dimension of the low-dimensional latent feature Y2 is the same as the latent feature dimension of the autoencoder set in step S11;
[0149] Taking the KL divergence between the Gaussian probability distribution matrix P2 and the t-distribution probability matrix Q2 as the loss function, iteratively solve the low-dimensional latent feature Y2 based on the loss function using the gradient descent method, and use the low-dimensional latent feature Y2 obtained after the iteration is completed as the multiple second latent features.
[0150] The center point calculation module 315 calculates the distribution center point of the multiple first latent features according to the multiple first latent features.
[0151] In this embodiment, calculating the distribution center point of the multiple first latent features according to the multiple first latent features includes:
[0152] Calculate the average value of each dimension of the multiple first latent features in three dimensions, and use the point corresponding to the coordinates composed of the average values of each dimension of the three dimensions as the distribution center point of the multiple first latent features.
[0153] The score calculation module 316 respectively calculates the distance values of each second latent feature in the multiple second latent features from the distribution center point, and sums the distance values of the multiple second latent features from the distribution center point to obtain the score.
[0154] In this embodiment, respectively calculating the distance values of each second latent feature in the multiple second latent features from the distribution center point, and summing the distance values of the multiple second latent features from the distribution center point to obtain the score includes:
[0155] Respectively calculate the Euclidean distances of each second latent feature in the multiple second latent features from the distribution center point, and sum the Euclidean distances of the multiple second latent features from the distribution center point to obtain the score.
[0156] The judgment module 303 judges whether the score is greater than the reference score. When the score is greater than the reference score, use the score as the new reference score and re-call the latent feature dimension selection module. Or when the score is less than or equal to the reference score, use the currently set latent feature dimension as the optimal latent feature dimension.
[0157] The reconstruction module 304 uses the optimal latent feature dimension as the latent feature dimension of the autoencoder, inputs the test image into the autoencoder, and obtains the reconstructed image using the autoencoder.
[0158] In this embodiment, inputting the test image into the autoencoder and obtaining the reconstructed image using the autoencoder includes:
[0159] Vectorize the test image to obtain a second feature vector of the test image;
[0160] Use the encoding layer of the autoencoder to operate on the second feature vector to obtain the latent feature of the test image;
[0161] Use the decoding layer of the autoencoder to operate on the latent feature of the test image, and perform reduction processing on the obtained latent feature after the operation to obtain the reconstructed image.
[0162] The output module 305 calculates the reconstruction error between the test image and the reconstructed image. When the reconstruction error is greater than a preset threshold, it outputs a judgment result that the test image is a defective image; or when the reconstruction error is less than or equal to the threshold, it outputs a judgment result that the test image is a normal image.
[0163] In this embodiment, calculating the reconstruction error between the test image and the reconstructed image includes:
[0164] Calculate the mean square error between the test image and the reconstructed image, and use the mean square error as the reconstruction error.
[0165] In other embodiments, calculating the reconstruction error between the test image and the reconstructed image may include:
[0166] Calculate the cross entropy between the test image and the reconstructed image, and use the cross entropy as the reconstruction error.
[0167] The present invention can effectively confirm the latent feature dimensions with discrimination ability, improving the efficiency of image defect judgment.
[0168] Embodiment 3
[0169] Figure 4 It is a schematic diagram of an electronic device 6 in an embodiment of the present invention.
[0170] The electronic device 6 includes a memory 61, a processor 62, and a computer program 63 stored in the memory 61 and executable on the processor 62. When the processor 62 executes the computer program 63, it implements the steps in the above-mentioned embodiment of the image defect detection method, such as Figure 1 The steps S11 to S15 shown. Alternatively, when the processor 62 executes the computer program 63, it implements the functions of each module / unit in the above-mentioned embodiment of the image defect detection device, such as Figure 3 The modules 301 to 305 in.
[0171] Exemplarily, the computer program 63 may be divided into one or more modules / units, which are stored in the memory 61 and executed by the processor 62 to implement the present invention. The one or more modules / units may be a series of computer program instruction segments capable of performing specific functions, and the instruction segments are used to describe the execution process of the computer program 63 in the electronic device 6. For example, the computer program 63 may be divided into Figure 3 the training data acquisition module 301, the latent feature dimension selection module 302, the judgment module 303, the reconstruction module 304, and the output module 305 in [reference], and the specific functions of each module are described in Embodiment 2.
[0172] In this embodiment, the electronic device 6 may be a computing device such as a desktop computer, a notebook, a palm computer, a server, and a cloud terminal device. Those skilled in the art can understand that the schematic diagram is only an example of the electronic device 6, and does not constitute a limitation on the electronic device 6. It may include more or fewer components than shown in the figure, or combine some components, or different components. For example, the electronic device 6 may further include input / output devices, network access devices, buses, etc.
[0173] The so-called processor 62 may be a central processing module (Central Processing Unit, CPU), or may also be other general-purpose processors, digital signal processors (Digital Signal Processor, DSP), application specific integrated circuits (Application Specific Integrated Circuit, ASIC), field programmable gate arrays (Field-Programmable Gate Array, FPGA), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. The general-purpose processor may be a microprocessor, or the processor 62 may also be any conventional processor, etc. The processor 62 is the control center of the electronic device 6, and connects various parts of the entire electronic device 6 through various interfaces and lines.
[0174] The memory 61 can be used to store the computer program 63 and / or modules / units. By running or executing the computer program and / or modules / units stored in the memory 61, and invoking the data stored in the memory 61, the processor 62 realizes various functions of the electronic device 6. The memory 61 mainly includes a program storage area and a data storage area. Among them, the program storage area can store an operating system, application programs required for at least one function (such as a sound playback function, an image playback function, etc.); the data storage area can store data created according to the use of the electronic device 6 (such as audio data, phone book, etc.). In addition, the memory 61 can include high-speed random access memory, and can also include non-volatile memory, such as a hard disk, a memory, a plug-in hard disk, a Smart Media Card (SMC), a Secure Digital (SD) card, a Flash Card, at least one magnetic disk storage device, a flash memory device, or other volatile solid-state storage devices.
[0175] If the modules / units integrated in the electronic device 6 are implemented in the form of software functional modules and sold or used as independent products, they can be stored in a computer-readable storage medium. Based on this understanding, to implement all or part of the processes in the above-mentioned embodiment methods of the present invention, it can also be completed by a computer program instructing related hardware. The computer program can be stored in a computer-readable storage medium. When the computer program is executed by a processor, the steps of the above-mentioned various method embodiments can be realized. Among them, the computer program includes computer program code, and the computer program code can be in the form of source code, object code, executable file, or some intermediate form, etc. The computer-readable medium can include: any entity or device capable of carrying the computer program code, a recording medium, a USB flash drive, a mobile hard disk, a magnetic disk, an optical disc, a computer memory, a read-only memory (ROM), a random access memory (RAM), an electrical carrier signal, a telecommunication signal, and a software distribution medium, etc.
[0176] In several embodiments provided by the present invention, it should be understood that the disclosed devices and methods can be implemented in other ways. For example, the device embodiments described above are merely illustrative. For example, the division of the modules is only a logical function division, and there can be other division methods in actual implementation.
[0177] In addition, in each embodiment of the present invention, each functional module can be integrated in the same processing module, can exist separately as individual physical modules, or two or more modules can be integrated in the same module. The above integrated modules can be implemented in the form of hardware, or in the form of a combination of hardware and software functional modules.
[0178] For those skilled in the art, it is obvious that the present invention is not limited to the details of the above-described exemplary embodiments, and without departing from the spirit or basic characteristics of the present invention, the present invention can be implemented in other specific forms. Therefore, from any point of view, the embodiments should be regarded as exemplary and non-limiting. The scope of the present invention is defined by the appended claims rather than the above description. Therefore, all changes falling within the meaning and scope of the equivalent elements of the claims are intended to be included in the present invention. Any reference signs in the claims should not be construed as limiting the claims involved. In addition, it is obvious that the term "comprising" does not exclude other modules or steps, and the singular does not exclude the plural. The multiple modules or electronic devices stated in the claims of the electronic device can also be implemented by the same module or electronic device through software or hardware. The terms "first", "second", etc. are used to denote names and do not denote any particular order.
[0179] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention and not to limit them. Although the present invention has been described in detail with reference to the preferred embodiments, those of ordinary skill in the art should understand that the technical solutions of the present invention can be modified or equivalently replaced without departing from the spirit and scope of the technical solutions of the present invention.
Claims
1. An image defect detection method, characterized in that, the method includes: Obtaining sample image training data; Selecting the latent feature dimension of the autoencoder and obtaining a score, including: Setting the latent feature dimension of the autoencoder, and the autoencoder extracts image data to obtain latent features; Training the autoencoder using the sample image training data and obtaining a trained autoencoder; Inputting normal sample image data and defective sample image data into the trained autoencoder respectively, and obtaining the latent features of the normal sample image data and the latent features of the defective samples through the trained autoencoder; Reducing the dimension of the latent features of the normal sample image data to obtain a plurality of first latent features corresponding to the normal sample image data, and reducing the dimension of the latent features of the defective sample image data to obtain a plurality of second latent features corresponding to the defective samples, including: Using the T-stochastic neighbor embedding algorithm to reduce the dimension of the latent features of the normal sample image data to obtain a plurality of first latent features corresponding to the normal sample image data, and reducing the dimension of the latent features of the defective sample image data to obtain a plurality of second latent features corresponding to the defective samples; Calculating the distribution center point of the plurality of first latent features based on the plurality of first latent features; Calculating the distance value of each second latent feature in the plurality of second latent features from the distribution center point respectively, and summing the distance values of the plurality of second latent features from the distribution center point to obtain the score; Judging whether the score is greater than the reference score, and when the score is greater than the reference score, using the score as the new reference score and re-executing the step of selecting the latent feature dimension of the autoencoder and obtaining the score, or when the score is less than or equal to the reference score, using the currently set latent feature dimension as the optimal latent feature dimension; Using the optimal latent feature dimension as the latent feature dimension of the autoencoder, inputting the test image into the autoencoder, and using the autoencoder to obtain a reconstructed image; Calculating the reconstruction error between the test image and the reconstructed image, and when the reconstruction error is greater than a preset threshold, outputting a judgment result that the test image is a defective image; or when the reconstruction error is less than or equal to the threshold, outputting a judgment result that the test image is a normal image.
2. The image defect detection method according to claim 1, characterized in that, the setting of the latent feature dimension of the autoencoder includes: Setting the dimension of the latent features extracted by the encoding layer of the autoencoder.
3. The image defect detection method according to claim 1, characterized in that, the training of the autoencoder using the sample image training data and obtaining a trained autoencoder includes: Performing vectorization processing on the sample image training data to obtain the feature vector of the sample image training data; Using the encoding layer of the autoencoder to perform operations on the feature vector to obtain the latent features of the sample image training data; Using the decoding layer of the autoencoder to perform operations on the latent features and performing reduction processing on the latent features obtained after the operations; Optimizing the autoencoder to obtain a trained autoencoder.
4. The image defect detection method according to claim 1, characterized in that the steps of respectively inputting normal sample image data and defective sample image data into the trained autoencoder, and obtaining the latent features of the normal sample image data and the latent features of the defective samples by the trained autoencoder include: Inputting normal sample image data into the trained autoencoder, and obtaining the latent features of the normal sample image data through the encoding layer of the trained autoencoder; and Inputting defective sample image data into the trained autoencoder, and obtaining the latent features of the defective sample image data through the encoding layer of the trained autoencoder.
5. The image defect detection method according to claim 1, characterized in that the step of calculating the distribution center point of the multiple first latent features according to the multiple first latent features includes: Calculating the average value of the multiple first latent features in each dimension of three dimensions, and taking the point corresponding to the coordinates composed of the average values of each dimension of the three dimensions as the center point of the multiple first latent features.
6. The image defect detection method according to claim 5, characterized in that the steps of respectively calculating the distance values of each second latent feature in the multiple second latent features from the distribution center point, and summing the distance values of the multiple second latent features from the distribution center point to obtain a score include: Respectively calculating the Euclidean distance of each second latent feature in the multiple second latent features from the distribution center point, and summing the Euclidean distances of the multiple second latent features from the distribution center point to obtain the score.
7. An image defect detection device for an autoencoder, characterized in that the device includes: A training data acquisition module, configured to acquire sample image training data; A latent feature dimension selection module, configured to select the latent feature dimension of the autoencoder and obtain a score, including: A setting module, configured to set the latent feature dimension of the autoencoder, and the autoencoder extracts image data to obtain latent features; A training module, configured to train the autoencoder using the sample image training data and obtain a trained autoencoder; A latent feature acquisition module, configured to respectively input normal sample image data and defective sample image data into the trained autoencoder, and obtain the latent features of the normal sample image data and the latent features of the defective samples through the trained autoencoder; A dimensionality reduction module, configured to reduce the dimensionality of the latent features of the normal sample image data to obtain multiple first latent features corresponding to the normal sample image data, and reduce the dimensionality of the latent features of the defective sample image data to obtain multiple second latent features corresponding to the defective samples, including: using the T-stochastic neighbor embedding algorithm to reduce the dimensionality of the latent features of the normal sample image data to obtain multiple first latent features corresponding to the normal sample image data, and reducing the dimensionality of the latent features of the defective sample image data to obtain multiple second latent features corresponding to the defective samples; A center point calculation module, configured to calculate the distribution center point of the multiple first latent features according to the multiple first latent features; A fraction calculation module, configured to calculate the distance value of each of the plurality of second latent features from the distribution center point respectively, and sum up the distance values of the plurality of second latent features from the distribution center point to obtain a fraction; A judgment module, configured to judge whether the fraction is greater than a reference fraction, and when the fraction is greater than the reference fraction, use the fraction as a new reference fraction and re - call the latent feature dimension selection module, or when the fraction is less than or equal to the reference fraction, use the currently set latent feature dimension as the optimal latent feature dimension; A reconstruction module, configured to use the output optimal latent feature dimension as the latent feature dimension of the auto - encoder, input a test image into the auto - encoder, and obtain a reconstructed image using the auto - encoder; An output module, configured to calculate the reconstruction error between the test image and the reconstructed image, and when the reconstruction error is greater than a preset threshold, output a judgment result that the test image is a defective image; or when the reconstruction error is less than or equal to the threshold, output a judgment result that the test image is a normal image.
8. An electronic device, characterized in that, the electronic device includes: a memory, storing at least one instruction; and a processor, executing the instruction stored in the memory to implement the image defect detection method according to any one of claims 1 to 6.
9. A computer storage medium, having a computer program stored thereon, characterized in that: the computer program, when executed by a processor, implements the image defect detection method according to any one of claims 1 to 6.
Citation Information
Patent Citations
Single image patch reconstruction method based on undirected graph learning model
CN110163974A
Appearance defect detection method, electronic device and storage medium
CN111598827A