Image defect detection method, device, electronic device and storage medium
By training autoencoders and deep learning models and combining them with Gaussian mixture models, the defect detection process is optimized, the problem of high computational complexity of Gaussian mixture models is solved, and more efficient defect detection is achieved.
Patent Information
- Application Number
- CN202110183338.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-02-09
- Publication Date
- 2025-09-23
- Estimated Expiration
- 2041-02-09
AI Technical Summary
The existing defect detection method based on Gaussian mixture model has a large amount of computation, which makes it impossible to optimize the program speed and reduce the execution time.
By training the autoencoder, deep learning model and Gaussian mixture model, the latent features generated by the autoencoder are used to reconstruct the image and calculate the reconstruction error and probability distribution. The model parameters are optimized by combining the Kulbeck-Leibler divergence, and the threshold is set to judge image defects.
More efficient defect detection is achieved by replacing the Gaussian mixture model with a deep learning model, thereby improving detection efficiency.
Smart Images

Figure CN114943672B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of image detection, providing the fields of defect detection and computer vision technology, and particularly to an image defect detection method, device, electronic device and storage medium. Background Art
[0002] To improve the quality of industrial products, they are typically inspected for defects before packaging. However, current defect detection methods based on Gaussian mixture models often require significant computational effort, making it difficult to optimize program speed and reduce execution time. Summary of the Invention
[0003] In view of the above, it is necessary to propose an image defect detection method, device, electronic device and storage medium to improve the efficiency of defect image detection.
[0004] A first aspect of the present application provides an image defect detection method, comprising:
[0005] Obtain flawless sample training images;
[0006] Inputting the flawless sample training image into an autoencoder, and calculating a first latent feature of the flawless sample training image through an encoding layer of the autoencoder;
[0007] Inputting the first latent feature into the decoding layer of the autoencoder and calculating a first reconstructed image of the flawless sample training image, and calculating a first reconstruction error between the flawless sample training image and the first reconstructed image using a preset error function;
[0008] Inputting the first latent feature into a deep learning model and calculating a first probability distribution of the first latent feature;
[0009] Inputting the first latent feature into a Gaussian mixture model and calculating a second probability distribution of the first latent feature;
[0010] calculating a Kullback-Leibler divergence between the first probability distribution and the second probability distribution;
[0011] Obtaining a total loss based on the first reconstruction error and the Kulbeck-Leibler divergence, optimizing the autoencoder, the deep learning model, and the Gaussian mixture model based on the total loss, and setting a threshold based on the total loss;
[0012] Obtaining a test sample image, inputting the test sample image into the autoencoder, calculating a second latent feature of the test sample image through the encoding layer of the autoencoder, inputting the second latent feature into the decoding layer of the autoencoder and calculating a second reconstructed image of the test sample image, calculating a second reconstruction error between the test sample image and the second reconstructed image using the preset error function, inputting the second latent feature into a trained deep learning model and calculating a third probability distribution of the second latent feature, and calculating a total error based on the third probability distribution and the second reconstruction error;
[0013] When the total error is greater than or equal to the threshold, the test sample image is determined to be a defective image; when the total error is less than the threshold, the test sample image is determined to be a flawless image.
[0014] Preferably, the first latent feature of the flawless sample training image is obtained by calculating the encoding layer of the autoencoder, including:
[0015] Vectorizing the flawless sample training image to obtain a feature vector of the flawless sample training image;
[0016] The encoding layer in the autoencoder is used to operate on the feature vector of the flawless sample training image to obtain the first latent feature.
[0017] Preferably, the step of inputting the first latent feature into the decoding layer of the autoencoder and calculating the first reconstructed image of the flawless sample training image comprises:
[0018] Using the decoding layer in the autoencoder to operate on the first latent feature;
[0019] The vector obtained after the operation is restored to obtain the first reconstructed image.
[0020] Preferably, inputting the first latent feature into a deep learning model and calculating a first probability distribution of the first latent feature includes:
[0021] Inputting the first latent feature into the deep learning model;
[0022] The first probability distribution is obtained by operating the first latent feature through one or more of a convolutional layer, a pooling layer, and at least one hidden layer in the deep learning model.
[0023] Preferably, calculating the Kullbeck-Leibler divergence between the first probability distribution and the second probability distribution comprises:
[0024] According to the formula Calculate the Kullback-Leibler divergence of the first probability distribution and the second probability distribution, where D KL (P||Q) is the Kullbeck-Leibler divergence between the first probability distribution and the second probability distribution, P(i) is the second probability distribution, and Q(i) is the first probability distribution.
[0025] Preferably, obtaining a total loss according to the first reconstruction error and the Kulbeck-Leibler divergence, and optimizing the autoencoder, the deep learning model, and the Gaussian mixture model according to the total loss include:
[0026] Calculating the product of the first reconstruction error and the Kullbeck-Leibler divergence to obtain the total loss;
[0027] The parameters of the autoencoder, the deep learning model, and the Gaussian mixture model are adjusted to minimize the total loss.
[0028] Preferably, calculating the total error according to the third probability distribution and the second reconstruction error includes:
[0029] The third probability distribution and the second reconstruction error are summed to obtain a total error.
[0030] A second aspect of the present application provides an image defect detection device, the device comprising:
[0031] A training image acquisition module is used to obtain flawless sample training images;
[0032] A first latent feature acquisition module is configured to input the flawless sample training image into an autoencoder, and calculate the first latent feature of the flawless sample training image through the encoding layer of the autoencoder;
[0033] a first reconstruction error acquisition module, configured to input the first latent feature into a decoding layer of the autoencoder and calculate a first reconstructed image of the flawless sample training image, and calculate a first reconstruction error between the flawless sample training image and the first reconstructed image using a preset error function;
[0034] A first probability distribution calculation module, configured to input the first latent feature into a deep learning model and calculate a first probability distribution of the first latent feature;
[0035] a second probability distribution calculation module, configured to input the first latent feature into a Gaussian mixture model and calculate a second probability distribution of the first latent feature;
[0036] a divergence calculation module, configured to calculate a Kullback-Leibler divergence between the first probability distribution and the second probability distribution;
[0037] a model training module, configured to obtain a total loss based on the first reconstruction error and the Kulbeck-Leibler divergence, optimize the autoencoder, the deep learning model, and the Gaussian mixture model based on the total loss, and set a threshold based on the total loss;
[0038] a total error calculation module, configured to obtain a test sample image, input the test sample image into the autoencoder, calculate a second latent feature of the test sample image through the encoding layer of the autoencoder, input the second latent feature into the decoding layer of the autoencoder and calculate a second reconstructed image of the test sample image, calculate a second reconstruction error between the test sample image and the second reconstructed image using the preset error function, input the second latent feature into the trained deep learning model and calculate a third probability distribution of the second latent feature, and calculate a total error based on the third probability distribution and the second reconstruction error;
[0039] The judgment module is configured to determine that the test sample image is a defective image when the total error is greater than or equal to the threshold, and to determine that the test sample image is a flawless image when the total error is less than the threshold.
[0040] A third aspect of the present application provides an electronic device, comprising: a memory storing at least one instruction; and a processor executing the instruction stored in the memory to implement the defect detection method.
[0041] A fourth aspect of the present application provides a computer storage medium having a computer program stored thereon, wherein the computer program implements the image defect detection method when executed by a processor.
[0042] In the present invention, by simultaneously training the autoencoder, deep learning model and Gaussian mixture model, the deep learning model and the Gaussian mixture model can output the same probability distribution prediction, so that the deep learning model can be used to replace the Gaussian mixture model to achieve higher efficiency in defect detection. BRIEF DESCRIPTION OF THE DRAWINGS
[0043] Figure 1 FIG. 4 is a flow chart of an image defect detection method according to an embodiment of the present invention.
[0044] Figure 2 FIG. 4 is a structural diagram of an image defect detection device according to an embodiment of the present invention.
[0045] Figure 3 FIG. 1 is a schematic diagram of an electronic device according to an embodiment of the present invention.
[0046] Description of main component symbols
[0047] Image defect detection device 30 Training image acquisition module 301 The first latent feature acquisition module 302 The first reconstruction error acquisition module 303 The first probability distribution calculation module 304 Second probability distribution calculation module 305 Divergence calculation module 306 Model training module 307 Total error calculation module 308 Judgment module 309 electronic devices 6 Memory 61 processor 62 computer program 63 DETAILED DESCRIPTION
[0048] In order to more clearly understand the above-mentioned objects, features and advantages of the present invention, the present invention is described in detail below with reference to the accompanying drawings and specific embodiments. It should be noted that, in the absence of conflict, the embodiments of the present application and the features therein may be combined with each other.
[0049] The following description sets forth numerous specific details to facilitate a thorough understanding of the present invention. The embodiments described are merely some, not all, of the present invention. All other embodiments derived by persons of ordinary skill in the art based on the embodiments of the present invention without inventive effort are intended to fall within the scope of protection of the present invention.
[0050] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as those commonly understood by those skilled in the art of the present invention. 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.
[0051] Preferably, the image defect detection method of the present invention is applied to one or more electronic devices. The electronic devices are devices capable of automatically performing numerical calculations and / or information processing according to pre-set or stored instructions, and their hardware includes but is not limited to microprocessors, application-specific integrated circuits (ASICs), field-programmable gate arrays (FPGAs), digital signal processors (DSPs), embedded devices, and the like.
[0052] The electronic device may be a computing device such as a desktop computer, a laptop computer, a tablet computer, a cloud server, etc. The electronic device may interact with a user via a keyboard, a mouse, a remote control, a touchpad, or a voice control device.
[0053] Example 1
[0054] Figure 1 This is a flowchart of an image defect detection method according to one embodiment of the present invention. The image defect detection method is applied to electronic devices. The order of the steps in the flowchart may be changed, and some steps may be omitted, depending on different requirements.
[0055] See Figure 1As shown, the image defect detection method specifically includes the following steps:
[0056] Step S11: Obtain flawless sample training images.
[0057] Step S12: inputting the flawless sample training image into an autoencoder, and calculating the first latent feature of the flawless sample training image through the encoding layer of the autoencoder.
[0058] In at least one embodiment of the present invention, calculating the first latent feature of the flawless sample training image through the encoding layer of the autoencoder includes:
[0059] Vectorizing the flawless sample training image to obtain a feature vector of the flawless sample training image;
[0060] The encoding layer in the autoencoder is used to operate on the feature vector of the flawless sample training image to obtain the first latent feature.
[0061] Step S13: input the first latent feature into the decoding layer of the autoencoder and calculate a first reconstructed image of the flawless sample training image, and use a preset error function to calculate the flawless sample training image and the first reconstructed image to obtain a first reconstruction error between the flawless sample training image and the first reconstructed image.
[0062] Preferably, the step of inputting the first latent feature into the decoding layer of the autoencoder and calculating the first reconstructed image of the flawless sample training image comprises:
[0063] Using the decoding layer in the autoencoder to operate on the first latent feature;
[0064] The vector obtained after the operation is restored to obtain the first reconstructed image.
[0065] Step S14: input the first latent feature into a deep learning model and calculate a first probability distribution of the first latent feature.
[0066] In at least one embodiment of the present invention, inputting the first latent feature into a deep learning model and calculating a first probability distribution of the first latent feature includes:
[0067] Inputting the first latent feature into the deep learning model;
[0068] The first probability distribution is obtained by operating the first latent feature through one or more of a convolutional layer, a pooling layer, and at least one hidden layer in the deep learning model.
[0069] Step S15: input the first latent feature into a Gaussian mixture model and calculate a second probability distribution of the first latent feature.
[0070] In at least one embodiment of the present invention, inputting the first latent feature into a Gaussian mixture model and calculating a second probability distribution of the first latent feature includes:
[0071] inputting the first latent feature into the Gaussian mixture model;
[0072] The second probability distribution is obtained by fitting the probability distribution of the first latent feature through the Gaussian mixture model.
[0073] Specifically, the Gaussian mixture model is Among them, x j Represents the vector corresponding to the first latent feature, t = 1, 2, 3..., M, M is the dimension of the first latent feature, α k is the weight of the kth Gaussian distribution, μ k , σ k are the mean and variance of the kth Gaussian distribution, N(x i |μ k , σ k ) represents the vector x i The mean is μ k And the variance is σ k Normal distribution, K is at least 3.
[0074] Step S16: Calculate the Kullbeck-Leibler divergence between the first probability distribution and the second probability distribution.
[0075] Preferably, calculating the Kullbeck-Leibler divergence between the first probability distribution and the second probability distribution comprises:
[0076] According to the formula Calculate the Kullback-Leibler divergence of the first probability distribution and the second probability distribution, where D KL (P||Q) is the Kullbeck-Leibler divergence between the first probability distribution and the second probability distribution, P(i) is the second probability distribution, and Q(i) is the first probability distribution.
[0077] Step S17: Obtain a total loss based on the first reconstruction error and the Kulbeck-Leibler divergence, optimize the autoencoder, the deep learning model, and the Gaussian mixture model based on the total loss, and set a threshold based on the total loss.
[0078] In at least one embodiment of the present invention, obtaining a total loss according to the first reconstruction error and the Kulbeck-Leibler divergence, and optimizing the autoencoder, the deep learning model, and the Gaussian mixture model according to the total loss includes:
[0079] Calculating the product of the first reconstruction error and the Kullbeck-Leibler divergence to obtain the total loss;
[0080] The parameters of the autoencoder, the deep learning model, and the Gaussian mixture model are adjusted to minimize the total loss.
[0081] In at least one embodiment of the present invention, the purpose of adjusting the parameters of the autoencoder, the deep learning model and the Gaussian mixture model to minimize the total loss is to optimize the autoencoder, the deep learning model and the Gaussian mixture model so that the deep learning model and the Gaussian mixture model have the same probability distribution according to the reconstructed image generated by the autoencoder.
[0082] Step S18: obtain a test sample image, input the test sample image into the autoencoder, calculate the second latent feature of the test sample image through the encoding layer of the autoencoder, input the second latent feature into the decoding layer of the autoencoder and calculate the second reconstructed image of the test sample image, and use the preset error function to calculate the second reconstruction error between the test sample image and the second reconstructed image, input the second latent feature into the trained deep learning model and calculate the third probability distribution of the second latent feature, and calculate the total error based on the third probability distribution and the second reconstruction error.
[0083] In at least one embodiment of the present invention, calculating the total error according to the third probability distribution and the second reconstruction error includes:
[0084] The third probability distribution and the second reconstruction error are summed to obtain a total error.
[0085] Step S19 : when the total error is greater than or equal to the threshold, determining that the test sample image is a defective image; when the total error is less than the threshold, determining that the test sample image is a flawless image.
[0086] In the present invention, by simultaneously training the autoencoder, deep learning model and Gaussian mixture model, the deep learning model and the Gaussian mixture model can output the same probability distribution prediction, so that the deep learning model can be used to replace the Gaussian mixture model to achieve higher efficiency in defect detection.
[0087] Example 2
[0088] Figure 2 FIG. 1 is a structural diagram of an image defect detection device 30 according to an embodiment of the present invention.
[0089] In some embodiments, the image defect detection device 30 operates in an electronic device. The image defect detection device 30 may include multiple functional modules composed of program code segments. The program code of each program segment in the image defect detection device 30 may be stored in a memory and executed by at least one processor to perform image defect detection functions.
[0090] In this embodiment, the image defect detection device 30 can be divided into multiple functional modules according to the functions it performs. Figure 2 As shown, the image defect detection device 30 may include a training image acquisition module 301, a first latent feature acquisition module 302, a first reconstruction error acquisition module 303, a first probability distribution calculation module 304, a second probability distribution calculation module 305, a divergence calculation module 306, a model training module 307, a total error calculation module 308, and a judgment module 309. As used herein, a module refers to a series of computer program segments that can be executed by at least one processor and can perform fixed functions, and is stored in a memory. In some embodiments, the functions of each module will be described in detail in subsequent embodiments.
[0091] The training image acquisition module 301 acquires a flawless sample training image.
[0092] The first latent feature acquisition module 302 inputs the flawless sample training image into an autoencoder, and calculates the first latent feature of the flawless sample training image through the encoding layer of the autoencoder.
[0093] In at least one embodiment of the present invention, the first latent feature acquisition module 302 calculates the first latent feature of the flawless sample training image through the encoding layer of the autoencoder, including:
[0094] Vectorizing the flawless sample training image to obtain a feature vector of the flawless sample training image;
[0095] The encoding layer in the autoencoder is used to operate on the feature vector of the flawless sample training image to obtain the first latent feature.
[0096] The first reconstruction error acquisition module 303 inputs the first latent feature into the decoding layer of the autoencoder and calculates a first reconstructed image of the flawless sample training image, and uses a preset error function to calculate the flawless sample training image and the first reconstructed image to obtain a first reconstruction error between the flawless sample training image and the first reconstructed image.
[0097] In at least one embodiment of the present invention, the first reconstruction error acquisition module 303 inputs the first latent feature into the decoding layer of the autoencoder and calculates the first reconstructed image of the flawless sample training image, including:
[0098] Using the decoding layer in the autoencoder to operate on the first latent feature;
[0099] The vector obtained after the operation is restored to obtain the first reconstructed image.
[0100] The first probability distribution calculation module 304 inputs the first latent feature into a deep learning model and calculates a first probability distribution of the first latent feature.
[0101] In at least one embodiment of the present invention, the first probability distribution calculation module 304 inputs the first latent feature into the deep learning model and calculates the first probability distribution of the first latent feature, including:
[0102] Inputting the first latent feature into the deep learning model;
[0103] The first probability distribution is obtained by operating the first latent feature through one or more of a convolutional layer, a pooling layer, and at least one hidden layer in the deep learning model.
[0104] The second probability distribution calculation module 305 inputs the first latent feature into a Gaussian mixture model and calculates a second probability distribution of the first latent feature.
[0105] In at least one embodiment of the present invention, the second probability distribution calculation module 305 inputs the first latent feature into a Gaussian mixture model and calculates the second probability distribution of the first latent feature, including:
[0106] inputting the first latent feature into the Gaussian mixture model;
[0107] The second probability distribution is obtained by fitting the probability distribution of the first latent feature through the Gaussian mixture model.
[0108] Specifically, the Gaussian mixture model is Among them, x i Represents the vector corresponding to the first latent feature, t = 1, 2, 3..., M, M is the dimension of the first latent feature, α k is the weight of the kth Gaussian distribution, μ k , σ k are the mean and variance of the kth Gaussian distribution, N(x i |μ k , σk ) represents the vector x i The mean is μ k And the variance is σ k Normal distribution, K is at least 3.
[0109] The divergence calculation module 306 calculates the Kullbeck-Leibler divergence between the first probability distribution and the second probability distribution.
[0110] Preferably, calculating the Kullbeck-Leibler divergence between the first probability distribution and the second probability distribution comprises:
[0111] According to the formula Calculate the Kullback-Leibler divergence of the first probability distribution and the second probability distribution, where D KL (P||Q) is the Kullbeck-Leibler divergence between the first probability distribution and the second probability distribution, P(i) is the second probability distribution, and Q(i) is the first probability distribution.
[0112] The model training module 307 obtains a total loss based on the first reconstruction error and the Kulbeck-Leibler divergence, optimizes the autoencoder, the deep learning model and the Gaussian mixture model based on the total loss, and sets a threshold based on the total loss.
[0113] In at least one embodiment of the present invention, the model training module 307 obtains a total loss based on the first reconstruction error and the Kulbeck-Leibler divergence, and optimizing the autoencoder, the deep learning model, and the Gaussian mixture model based on the total loss includes:
[0114] Calculating the product of the first reconstruction error and the Kullbeck-Leibler divergence to obtain the total loss;
[0115] The parameters of the autoencoder, the deep learning model, and the Gaussian mixture model are adjusted to minimize the total loss.
[0116] In at least one embodiment of the present invention, the purpose of adjusting the parameters of the autoencoder, the deep learning model and the Gaussian mixture model to minimize the total loss is to optimize the autoencoder, the deep learning model and the Gaussian mixture model so that the deep learning model and the Gaussian mixture model have the same probability distribution according to the reconstructed image generated by the autoencoder.
[0117] The total error calculation module 308 obtains a test sample image, inputs the test sample image into the autoencoder, calculates a second latent feature of the test sample image through the encoding layer of the autoencoder, inputs the second latent feature into the decoding layer of the autoencoder and calculates a second reconstructed image of the test sample image, and uses the preset error function to calculate a second reconstruction error between the test sample image and the second reconstructed image, inputs the second latent feature into the trained deep learning model and calculates a third probability distribution of the second latent feature, and calculates a total error based on the third probability distribution and the second reconstruction error.
[0118] In at least one embodiment of the present invention, the total error calculation module 308 calculates the total error according to the third probability distribution and the second reconstruction error, including:
[0119] The third probability distribution and the second reconstruction error are summed to obtain a total error.
[0120] The judgment module 309 determines that the test sample image is a defective image when the total error is greater than or equal to the threshold, and determines that the test sample image is a flawless image when the total error is less than the threshold.
[0121] In the present invention, by simultaneously training the autoencoder, deep learning model and Gaussian mixture model, the deep learning model and the Gaussian mixture model can output the same probability distribution prediction, so that the deep learning model can be used to replace the Gaussian mixture model to achieve higher efficiency in defect detection.
[0122] Example 3
[0123] Figure 3 FIG. 1 is a schematic diagram of an electronic device 6 according to an embodiment of the present invention.
[0124] 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, the steps in the above-mentioned image defect detection method embodiment are implemented, for example: Figure 1 Alternatively, when the processor 62 executes the computer program 63, the functions of each module / unit in the above-mentioned embodiment of the image defect detection device are realized, for example Figure 2 Modules 301 to 309 in .
[0125] 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 implementing 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 2 The training image acquisition module 301, the first latent feature acquisition module 302, the first reconstruction error acquisition module 303, the first probability distribution calculation module 304, the second probability distribution calculation module 305, the divergence calculation module 306, the model training module 307, the total error calculation module 308 and the judgment module 309, the specific functions of each module refer to Example 2.
[0126] In this embodiment, the electronic device 6 may be a computing device such as a desktop computer, a notebook computer, a PDA, a server, or a cloud terminal device. Those skilled in the art will appreciate that the schematic diagram is merely an example of the electronic device 6 and does not limit the electronic device 6 . The electronic device 6 may include more or fewer components than shown, or may combine certain components or different components. For example, the electronic device 6 may also include input and output devices, network access devices, buses, and the like.
[0127] The processor 62 may be a central processing unit (CPU), other general-purpose processors, digital signal processors (DSP), application-specific integrated circuits (ASIC), field-programmable gate arrays (FPGA), other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. A general-purpose processor may be a microprocessor, or the processor 62 may be any conventional processor, etc. The processor 62 is the control center of the electronic device 6, connecting various parts of the entire electronic device 6 using various interfaces and lines.
[0128] The memory 61 can be used to store the computer program 63 and / or modules / units. The processor 62 implements the various functions of the electronic device 6 by running or executing the computer program and / or modules / units stored in the memory 61 and accessing the data stored in the memory 61. The memory 61 may primarily include a program storage area and a data storage area. The program storage area may store an operating system and at least one application required for a function (such as a sound playback function or an image playback function); the data storage area may store data generated based on the use of the electronic device 6 (such as audio data, a phone book, etc.). Furthermore, the memory 61 may include high-speed random access memory and non-volatile memory, such as a hard disk, internal memory, a plug-in hard disk, a smart media card (SMC), a secure digital (SD) card, a flash card, at least one disk storage device, a flash memory device, or other volatile solid-state storage device.
[0129] If the module / unit integrated in the electronic device 6 is implemented in the form of a software functional module and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the present invention implements all or part of the process in the above-mentioned embodiment method, and can also be completed by instructing the relevant hardware through a computer program. The computer program can be stored in a computer-readable storage medium, and when the computer program is executed by the processor, it can implement the steps of the above-mentioned various method embodiments. Among them, the computer program includes computer program code, and the computer program code can be in source code form, object code form, executable file or some intermediate form. The computer-readable medium may include: any entity or device that can carry the computer program code, recording medium, U disk, mobile hard disk, magnetic disk, optical disk, computer memory, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), electrical carrier signal, telecommunication signal and software distribution medium, etc.
[0130] In the 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 module division is merely a logical function division, and actual implementation may employ other division methods.
[0131] In addition, the functional modules in various embodiments of the present invention may be integrated into the same processing module, each module may exist physically separately, or two or more modules may be integrated into the same module. The above-mentioned integrated modules may be implemented in the form of hardware or hardware plus software functional modules.
[0132] It is obvious to those skilled in the art that the present invention is not limited to the details of the exemplary embodiments described above, and that the present invention can be implemented in other specific forms without departing from the spirit or essential features of the invention. Therefore, from any point of view, the embodiments should be regarded as exemplary and non-restrictive, and the scope of the invention is defined by the appended claims rather than the above description, and it is intended that all changes that fall within the meaning and scope of the equivalent elements of the claims be included in the present invention. Any figure marks in the claims should not be regarded as limiting the claims involved. In addition, it is obvious that the word "comprising" does not exclude other modules or steps, and the singular does not exclude the plural. Multiple modules or electronic devices stated in the electronic device claim may also be implemented by the same module or electronic device through software or hardware. Words such as first and second are used to indicate names and do not indicate any particular order.
[0133] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention and are not limiting. Although the present invention has been described in detail with reference to the preferred embodiments, those skilled in the art should understand that the technical solutions of the present invention may be modified or replaced by equivalents without departing from the spirit and scope of the technical solutions of the present invention.
Claims
1. A method for detecting image defects, characterized in that: The method comprises: Obtain flawless sample training images; Inputting the flawless sample training image into an autoencoder, and calculating a first latent feature of the flawless sample training image through an encoding layer of the autoencoder; Inputting the first latent feature into the decoding layer of the autoencoder and calculating a first reconstructed image of the flawless sample training image, and calculating a first reconstruction error between the flawless sample training image and the first reconstructed image using a preset error function; Inputting the first latent feature into a deep learning model and calculating a first probability distribution of the first latent feature; Inputting the first latent feature into a Gaussian mixture model and calculating a second probability distribution of the first latent feature; calculating a Kullback-Leibler divergence between the first probability distribution and the second probability distribution; Obtaining a total loss based on the first reconstruction error and the Koolbeck-Leibler divergence, optimizing the autoencoder, the deep learning model, and the Gaussian mixture model based on the total loss, and setting a threshold based on the total loss, wherein obtaining the total loss based on the first reconstruction error and the Koolbeck-Leibler divergence includes: calculating a product of the first reconstruction error and the Koolbeck-Leibler divergence to obtain the total loss; Obtaining a test sample image, inputting the test sample image into the autoencoder, calculating a second latent feature of the test sample image through the encoding layer of the autoencoder, inputting the second latent feature into the decoding layer of the autoencoder and calculating a second reconstructed image of the test sample image, and calculating a second reconstruction error between the test sample image and the second reconstructed image using the preset error function, inputting the second latent feature into a trained deep learning model and calculating a third probability distribution of the second latent feature, and calculating a total error based on the third probability distribution and the second reconstruction error, wherein calculating the total error based on the third probability distribution and the second reconstruction error includes: summing the third probability distribution and the second reconstruction error to obtain the total error; When the total error is greater than or equal to the threshold, the test sample image is determined to be a defective image; when the total error is less than the threshold, the test sample image is determined to be a flawless image.
2. The image defect detection method according to claim 1, wherein: The first latent feature of the flawless sample training image obtained by calculating the encoding layer of the autoencoder includes: Vectorizing the flawless sample training image to obtain a feature vector of the flawless sample training image; The encoding layer in the autoencoder is used to operate on the feature vector of the flawless sample training image to obtain the first latent feature.
3. The image defect detection method according to claim 1, wherein: The step of inputting the first latent feature into the decoding layer of the autoencoder and calculating a first reconstructed image of the flawless sample training image includes: Using the decoding layer in the autoencoder to operate on the first latent feature; The vector obtained after the operation is restored to obtain the first reconstructed image.
4. The image defect detection method according to claim 1, wherein: Inputting the first latent feature into the deep learning model and calculating a first probability distribution of the first latent feature includes: Inputting the first latent feature into the deep learning model; The first probability distribution is obtained by operating the first latent feature through one or more of a convolutional layer, a pooling layer, and at least one hidden layer in the deep learning model.
5. The image defect detection method according to claim 1, wherein: Calculating the Kullbeck-Leibler divergence between the first probability distribution and the second probability distribution includes: According to the formula The Kullbeck-Leibler divergence of the first probability distribution and the second probability distribution is calculated, where is the Kullbeck–Leibler divergence of the first probability distribution and the second probability distribution, For the second probability distribution, is the first probability distribution.
6. The image defect detection method according to claim 1, wherein: Obtaining a total loss according to the first reconstruction error and the Kulbeck-Leibler divergence, and optimizing the autoencoder, the deep learning model, and the Gaussian mixture model according to the total loss includes: The parameters of the autoencoder, the deep learning model, and the Gaussian mixture model are adjusted to minimize the total loss.
7. An image defect detection device, characterized in that: The device comprises: A training image acquisition module is used to obtain flawless sample training images; A first latent feature acquisition module is configured to input the flawless sample training image into an autoencoder, and calculate the first latent feature of the flawless sample training image through the encoding layer of the autoencoder; a first reconstruction error acquisition module, configured to input the first latent feature into a decoding layer of the autoencoder and calculate a first reconstructed image of the flawless sample training image, and calculate a first reconstruction error between the flawless sample training image and the first reconstructed image using a preset error function; A first probability distribution calculation module, configured to input the first latent feature into a deep learning model and calculate a first probability distribution of the first latent feature; a second probability distribution calculation module, configured to input the first latent feature into a Gaussian mixture model and calculate a second probability distribution of the first latent feature; a divergence calculation module, configured to calculate a Kullback-Leibler divergence between the first probability distribution and the second probability distribution; a model training module, configured to obtain a total loss based on the first reconstruction error and the Koolbeck-Leibler divergence, optimize the autoencoder, the deep learning model, and the Gaussian mixture model based on the total loss, and set a threshold based on the total loss, wherein obtaining the total loss based on the first reconstruction error and the Koolbeck-Leibler divergence comprises: calculating the product of the first reconstruction error and the Koolbeck-Leibler divergence to obtain the total loss; a total error calculation module, configured to obtain a test sample image, input the test sample image into the autoencoder, calculate a second latent feature of the test sample image through the encoding layer of the autoencoder, input the second latent feature into the decoding layer of the autoencoder and calculate a second reconstructed image of the test sample image, calculate a second reconstruction error between the test sample image and the second reconstructed image using the preset error function, input the second latent feature into the trained deep learning model and calculate a third probability distribution of the second latent feature, and calculate a total error based on the third probability distribution and the second reconstruction error, wherein calculating the total error based on the third probability distribution and the second reconstruction error includes: summing the third probability distribution and the second reconstruction error to obtain the total error; The judgment module is configured to determine that the test sample image is a defective image when the total error is greater than or equal to the threshold, and to determine that the test sample image is a flawless image when the total error is less than the threshold.
8. An electronic device, characterized in that: The electronic device comprises: a memory storing at least one instruction; and A processor is configured to execute instructions 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: When the computer program is executed by a processor, the image defect detection method according to any one of claims 1 to 6 is implemented.
Citation Information
Patent Citations
Image processing based generation method of maximum interval depth generation model
CN105224948A
Unsupervised defect detection method based on an auto-encoder
CN109584225A