Image defect detection method, device, electronic equipment and medium

By performing size conversion and feature extraction of the image to be detected, combined with error calculation of the decoder and Gaussian hybrid model, the problem of low accuracy in detecting image defects at various scales in the prior art is solved, and higher detection accuracy is achieved.

CN114663335BActive Publication Date: 2025-03-28FU TAI HUA IND SHENZHEN +1
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202011527501.7
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2020-12-22
Publication Date
2025-03-28
Estimated Expiration
2040-12-22

AI Technical Summary

Technical Problem

The prior art cannot effectively detect image defects of various scales, resulting in a decrease in detection accuracy.

Method used

By converting the image to be detected into a number of size images of different preset sizes, a pre-constructed encoder is used for feature extraction, and the latent vector is obtained, and the error of each size image is calculated to determine the detection result of the image.

Benefits of technology

It improves the accuracy of image defect detection and can cover various sizes of defect changes.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114663335B_ABST
    Figure CN114663335B_ABST
Patent Text Reader

Abstract

The present application relates to image analysis technology, and the present application provides an image defect detection method, device, electronic device and medium. The method can extract an image to be detected from an image defect detection request, convert the image to be detected into multiple size images of different preset sizes, use a pre-built encoder to extract features of the multiple size images to obtain multiple latent vectors, input the multiple latent vectors into a decoder corresponding to the encoder to obtain multiple reconstructed images, and input the multiple latent vectors into a pre-trained Gaussian mixture model to obtain an estimated probability corresponding to each size image, compare each reconstructed image with each size image, obtain a calculated error of each size image, determine the total error of each size image according to each estimated probability and each calculated error, and determine the detection result of the image to be detected according to each total error and a preset threshold value corresponding to each total error, thereby improving the accuracy of defect detection.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of image analysis technology, and in particular to an image defect detection method, device, electronic equipment and medium. Background Art

[0002] In the field of industrial inspection, the detection of defects such as breakage and scratches in product images can ensure the high quality of products. Since defects vary in different scales, the current image defect detection methods cannot cover the changes in defect types of various scales, thereby reducing the accuracy of defect detection. Summary of the invention

[0003] In view of the above, it is necessary to provide an image defect detection method, device, electronic device and medium that can improve the accuracy of defect detection.

[0004] A first aspect of the present application provides an image defect detection method, the image defect detection method comprising:

[0005] When receiving an image defect detection request, extracting an image to be detected from the image defect detection request;

[0006] Converting the image to be detected into a plurality of size images of different preset sizes;

[0007] Using a pre-built encoder to extract features from the images of the multiple sizes to obtain multiple latent vectors;

[0008] Inputting the multiple latent vectors into a decoder corresponding to the encoder to obtain multiple reconstructed images, and inputting the multiple latent vectors into a pre-trained Gaussian mixture model to obtain an estimated probability corresponding to each size image;

[0009] Compare each reconstructed image with each size image to obtain the calculated error of each size image;

[0010] The total error of each size image is determined according to each estimated probability and each calculated error, and the detection result of the image to be detected is determined according to each total error and a preset threshold corresponding to each total error.

[0011] According to a preferred embodiment of the present application, extracting the image to be detected from the image defect detection request includes:

[0012] Get an idle thread from the thread connection pool;

[0013] Utilizing the idle thread to parse the method body of the image defect detection request to obtain all information carried in the image defect detection request;

[0014] A preset label is obtained, and information corresponding to the preset label is extracted from all the information according to the preset label as the image to be detected.

[0015] According to a preferred embodiment of the present application, converting the image to be detected into a plurality of size images of different preset sizes comprises:

[0016] Determining a detection object according to the image defect detection request;

[0017] Extracting a region image containing the detection object from the image to be detected;

[0018] The regional image is converted into images of the multiple sizes according to the different preset sizes.

[0019] According to a preferred embodiment of the present application, the step of extracting features from the images of the multiple sizes using a pre-built encoder to obtain multiple latent vectors includes:

[0020] Encode each size image to obtain a feature vector of each size image;

[0021] Each feature vector is input into a plurality of hidden layers in the encoder for operation, and an output vector of the last hidden layer is determined as a latent vector corresponding to an image of each size.

[0022] According to a preferred embodiment of the present application, before inputting the multiple latent vectors into a pre-trained Gaussian mixture model to obtain an estimated probability corresponding to each size image, the image defect detection method further includes:

[0023] Obtain multiple training images;

[0024] Encoding the multiple training images to obtain multiple encoding vectors, and performing dimensionality reduction and normalization processing on the multiple encoding vectors to obtain multiple low-dimensional vectors;

[0025] Dividing the multiple low-dimensional vectors into a training set, a test set, and a validation set;

[0026] Based on the maximum expectation algorithm, iteratively train the low-dimensional vectors in the training set to obtain a learner;

[0027] Testing the learner using the low-dimensional vectors in the test set to obtain a test result;

[0028] When the test result is less than the configured value, the parameters of the learner are adjusted using the low-dimensional vectors in the validation set to obtain the Gaussian mixture model.

[0029] According to a preferred embodiment of the present application, the step of comparing each reconstructed image with each size image to obtain a calculation error of each size image includes:

[0030] For any reconstructed image, extract all reconstructed pixel points in the arbitrary reconstructed image, and calculate a first number of all the reconstructed pixel points;

[0031] Extract all target pixels in each size image;

[0032] Comparing each reconstructed pixel with each target pixel to obtain a comparison result, wherein a comparison result that is different between the reconstructed pixel and the target pixel is determined as a target comparison result;

[0033] A second number of the target comparison results is calculated, and the second number is divided by the first number to obtain a calculation error for each size image.

[0034] According to a preferred embodiment of the present application, determining the detection result of the image to be detected according to each total error and a preset threshold value corresponding to each total error includes:

[0035] Determining a minimum preset threshold value from the corresponding preset threshold values;

[0036] When each total error is less than the minimum preset threshold, the detection result is determined as the image to be detected is flawless; or

[0037] When any total error is greater than or equal to the corresponding preset threshold, the detection result is determined as the image to be detected having defects; or

[0038] When each total error is smaller than the corresponding preset threshold, and each total error is greater than or equal to the minimum preset threshold, the detection result is determined as the image to be detected has defects.

[0039] A second aspect of the present application provides an image defect detection device, the image defect detection device comprising:

[0040] an extraction unit, configured to extract the image to be detected from the image defect detection request when receiving the image defect detection request;

[0041] A conversion unit, used for converting the image to be detected into a plurality of size images of different preset sizes;

[0042] The extraction unit is further used to extract features from the images of the multiple sizes using a pre-built encoder to obtain multiple latent vectors;

[0043] An input unit, configured to input the plurality of latent vectors into a decoder corresponding to the encoder to obtain a plurality of reconstructed images, and input the plurality of latent vectors into a pre-trained Gaussian mixture model to obtain an estimated probability corresponding to each size image;

[0044] A comparison unit, used for comparing each reconstructed image with each size image to obtain a calculation error of each size image;

[0045] The determination unit is used to determine the total error of each size image according to each estimated probability and each calculated error, and to determine the detection result of the image to be detected according to each total error and a preset threshold value corresponding to each total error.

[0046] According to a preferred embodiment of the present application, the extracting unit extracts the image to be detected from the image defect detection request, comprising:

[0047] Get an idle thread from the thread connection pool;

[0048] Utilizing the idle thread to parse the method body of the image defect detection request to obtain all information carried in the image defect detection request;

[0049] A preset label is obtained, and information corresponding to the preset label is extracted from all the information according to the preset label as the image to be detected.

[0050] According to a preferred embodiment of the present application, the conversion unit is specifically used for:

[0051] Determining a detection object according to the image defect detection request;

[0052] Extracting a region image containing the detection object from the image to be detected;

[0053] The region image is converted into images of the multiple sizes according to the different preset sizes.

[0054] According to a preferred embodiment of the present application, the extraction unit uses a pre-built encoder to extract features from the multiple size images, and obtains multiple latent vectors including:

[0055] Encode each size image to obtain a feature vector of each size image;

[0056] Each feature vector is input into a plurality of hidden layers in the encoder for operation, and an output vector of the last hidden layer is determined as a latent vector corresponding to an image of each size.

[0057] According to a preferred embodiment of the present application, the image defect detection device further includes:

[0058] An acquisition unit, configured to acquire a plurality of training images before inputting the plurality of latent vectors into a pre-trained Gaussian mixture model to obtain an estimated probability corresponding to each size image;

[0059] A processing unit, configured to encode the plurality of training images to obtain a plurality of encoding vectors, and perform dimensionality reduction and normalization processing on the plurality of encoding vectors to obtain a plurality of low-dimensional vectors;

[0060] A division unit, used for dividing the multiple low-dimensional vectors into a training set, a test set and a validation set;

[0061] A training unit, used for iteratively training the low-dimensional vectors in the training set based on a maximum expectation algorithm to obtain a learner;

[0062] A testing unit, used to test the learner using the low-dimensional vectors in the test set to obtain a test result;

[0063] An adjustment unit is used to adjust the parameters of the learner using the low-dimensional vector in the validation set to obtain the Gaussian mixture model when the test result is less than the configuration value.

[0064] According to a preferred embodiment of the present application, the comparison unit is specifically used for:

[0065] For any reconstructed image, extract all reconstructed pixel points in the arbitrary reconstructed image, and calculate a first number of all the reconstructed pixel points;

[0066] Extract all target pixels in each size image;

[0067] Comparing each reconstructed pixel with each target pixel to obtain a comparison result, wherein a comparison result that is different between the reconstructed pixel and the target pixel is determined as a target comparison result;

[0068] A second number of the target comparison results is calculated, and the second number is divided by the first number to obtain a calculation error for each size image.

[0069] According to a preferred embodiment of the present application, the determination unit determines the detection result of the image to be detected according to each total error and a preset threshold value corresponding to each total error, including:

[0070] Determining a minimum preset threshold value from the corresponding preset threshold values;

[0071] When each total error is less than the minimum preset threshold, the detection result is determined as the image to be detected is flawless; or

[0072] When any total error is greater than or equal to the corresponding preset threshold, the detection result is determined as the image to be detected having defects; or

[0073] When each total error is smaller than the corresponding preset threshold, and each total error is greater than or equal to the minimum preset threshold, the detection result is determined as the image to be detected has defects.

[0074] A third aspect of the present application provides an electronic device, the electronic device comprising:

[0075] a memory storing at least one instruction; and

[0076] The processor obtains the instruction stored in the memory to implement the image defect detection method.

[0077] A fourth aspect of the present application provides a computer-readable storage medium, wherein the computer-readable storage medium stores at least one instruction, and the at least one instruction is acquired by a processor in an electronic device to implement the image defect detection method.

[0078] It can be seen from the above technical solutions that the present application covers the changes in defect types of various scales by performing size conversion on the image to be detected, thereby improving the accuracy of defect detection. BRIEF DESCRIPTION OF THE DRAWINGS

[0079] Figure 1 It is a flow chart of a preferred embodiment of the image defect detection method of the present application.

[0080] Figure 2 It is a functional module diagram of a preferred embodiment of the image defect detection device of the present application.

[0081] Figure 3 It is a schematic diagram of the structure of an electronic device of a preferred embodiment of the image defect detection method of the present application. DETAILED DESCRIPTION

[0082] In order to make the objectives, technical solutions and advantages of the present application clearer, the present application is described in detail below with reference to the accompanying drawings and specific embodiments.

[0083] like Figure 1 FIG. 1 is a flowchart of a preferred embodiment of the image defect detection method of the present application. According to different requirements, the order of the steps in the flowchart can be changed, and some steps can be omitted.

[0084] The image defect detection method is applied to one or more electronic devices 1, and the electronic device 1 is a device that can automatically perform 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.

[0085] The electronic device 1 can be any electronic product that can perform human-computer interaction with a user, such as a personal computer, a tablet computer, a smart phone, a personal digital assistant (PDA), a game console, an interactive network television (IPTV), a smart wearable device, etc.

[0086] The electronic device 1 may also include a network device and / or a user device, wherein the network device includes, but is not limited to, a single network server, a server group consisting of multiple network servers, or a cloud consisting of a large number of hosts or network servers based on cloud computing.

[0087] The network where the electronic device 1 is located includes but is not limited to the Internet, a wide area network, a metropolitan area network, a local area network, a virtual private network (VPN), etc.

[0088] S10, when an image defect detection request is received, extracting an image to be detected from the image defect detection request.

[0089] In at least one embodiment of the present application, the image defect detection request may be triggered by a user (eg, triggered by a preset function button) or may be automatically triggered within a preset time, which is not limited by the present application.

[0090] The preset time may be a time point (eg, 9:00 a.m. every day) or a time period.

[0091] In at least one embodiment of the present application, the information carried in the image defect detection request includes, but is not limited to: a detection object and an image to be detected. It is understandable that the image to be detected contains the detection object.

[0092] In at least one embodiment of the present application, the electronic device extracting the image to be detected from the image defect detection request includes:

[0093] The electronic device obtains an idle thread from a thread connection pool. Further, the electronic device uses the idle thread to parse the method body of the image defect detection request to obtain all information carried in the image defect detection request. Furthermore, the electronic device obtains a preset tag and extracts information corresponding to the preset tag from all the information as the image to be detected based on the preset tag.

[0094] Wherein, the thread connection pool stores a plurality of threads; further, the preset tag refers to a tag used to identify the image to be detected.

[0095] By obtaining an idle thread from the thread connection pool, the thread creation time can be saved, and by parsing the method body of the image defect detection request, the parsing time of the image defect detection request can be shortened, and by the mapping relationship between the preset label and the image to be detected, the image to be detected can be accurately determined.

[0096] S11, converting the image to be detected into a plurality of size images of different preset sizes.

[0097] In at least one embodiment of the present application, the multiple different preset sizes may include, but are not limited to: 32*32, 64*64, 128*128.

[0098] In at least one embodiment of the present application, the electronic device converting the image to be detected into a plurality of size images of different preset sizes comprises:

[0099] The electronic device determines the detection object according to the image defect detection request, extracts a region image including the detection object from the image to be detected, and further converts the region image into images of the multiple sizes according to the different preset sizes.

[0100] Through the above implementation, it can be ensured that the detection object is included in the multiple size images after conversion. In addition, since only the area image containing the detection object needs to be resized and there is no need to resize the image to be detected, the image pixels before the size conversion are reduced, which can improve the size conversion efficiency.

[0101] Specifically, the electronic device may utilize an open source opencv tool to convert the area image into the multiple size images having the different preset sizes.

[0102] S12, using a pre-built encoder to perform feature extraction on the images of the multiple sizes to obtain multiple latent vectors.

[0103] In at least one embodiment of the present application, the encoder may be an encoder in an autoencoder (AE). Further, the encoder includes multiple hidden layers, and the number of the multiple hidden layers can be arbitrarily set according to the application scenario.

[0104] In at least one embodiment of the present application, the electronic device uses a pre-built encoder to perform feature extraction on the multiple size images to obtain multiple latent vectors including:

[0105] The electronic device performs encoding processing on each size image to obtain a feature vector of each size image. Further, the electronic device inputs each feature vector into multiple hidden layers in the encoder for calculation, and determines the output vector of the last hidden layer as the latent vector corresponding to each size image.

[0106] Specifically, the electronic device inputs each feature vector into a plurality of hidden layers in the encoder for operation, including:

[0107] For any hidden layer, the electronic device obtains the weight matrix and bias value corresponding to the arbitrary hidden layer. Further, the electronic device multiplies each eigenvector with the weight matrix to obtain a calculation result, and adds the bias value to the calculation result to obtain an output vector of the arbitrary hidden layer.

[0108] S13, inputting the multiple latent vectors into a decoder corresponding to the encoder to obtain multiple reconstructed images, and inputting the multiple latent vectors into a pre-trained Gaussian mixture model to obtain an estimated probability corresponding to each size image.

[0109] In at least one embodiment of the present application, the decoder may be a decoder in an autoencoder (AE). Further, the decoder includes a plurality of operation layers corresponding to the hidden layers in the encoder, and the number of the plurality of operation layers is the same as the number of the plurality of hidden layers.

[0110] In at least one embodiment of the present application, the Gaussian Mixture Model (GMM) can accurately quantize the multiple latent vectors using a Gaussian probability density function (normal distribution curve).

[0111] In at least one embodiment of the present application, before inputting the multiple latent vectors into a pre-trained Gaussian mixture model to obtain an estimated probability corresponding to each size image, the image defect detection method further includes:

[0112] The electronic device acquires a plurality of training images. Further, the electronic device encodes the plurality of training images to obtain a plurality of encoding vectors, and performs dimensionality reduction and normalization processing on the plurality of encoding vectors to obtain a plurality of low-dimensional vectors. Further, the electronic device divides the plurality of low-dimensional vectors into a training set, a test set and a validation set. Further, the electronic device iteratively trains the low-dimensional vectors in the training set based on a maximum expectation algorithm to obtain a learner. Further, the electronic device tests the learner using the low-dimensional vectors in the test set to obtain a test result. When the test result is less than a configuration value, the electronic device adjusts the parameters of the learner using the low-dimensional vectors in the validation set to obtain the Gaussian mixture model.

[0113] Through the above implementation, the generated Gaussian mixture model can be made more accurate.

[0114] In at least one embodiment of the present application, before dividing the multiple low-dimensional vectors into a training set, a test set, and a validation set, the method further includes:

[0115] The electronic device calculates the number of the multiple low-dimensional vectors, and when the number is less than a preset number, the electronic device increases the number of the multiple low-dimensional vectors by using a data enhancement algorithm.

[0116] Through the above implementation, it is possible to avoid the poor generalization ability of the estimated probability generated by the trained Gaussian mixture model due to the insufficient number of multiple low-dimensional vectors.

[0117] In at least one embodiment of the present application, the electronic device dividing the multiple low-dimensional vectors into a training set, a test set, and a validation set includes:

[0118] The electronic device randomly divides the multiple low-dimensional vectors into multiple data packets according to a preset ratio, determines any two of the multiple data packets as the verification set and the test set, respectively, and determines the remaining data packets as the training set, and repeats the above steps until all the data packets are used as the verification set in turn.

[0119] Among them, the preset ratio can be customized and is not limited in this application.

[0120] Through the above implementation, each of the multiple low-dimensional vectors is involved in training and verification, thereby improving the fit of the training Gaussian mixture model.

[0121] S14, comparing each reconstructed image with each size image to obtain a calculation error of each size image.

[0122] In at least one embodiment of the present application, the electronic device compares each reconstructed image with each size image, and the calculated error of each size image obtained includes:

[0123] For any reconstructed image, the electronic device extracts all reconstructed pixels in the any reconstructed image and calculates a first number of all the reconstructed pixels. Further, the electronic device extracts all target pixels in each size image. The electronic device compares each reconstructed pixel with each target pixel to obtain a comparison result, wherein a comparison result in which the reconstructed pixel is different from the target pixel is determined as a target comparison result. Further, the electronic device calculates a second number of the target comparison results and divides the second number by the first number to obtain a calculation error for each size image.

[0124] Through the above implementation, the calculation error of each size image can be accurately determined.

[0125] S15, determining a total error of each size image according to each estimated probability and each calculated error, and determining a detection result of the image to be detected according to each total error and a preset threshold corresponding to each total error.

[0126] In at least one embodiment of the present application, the detection result includes whether the image to be detected has defects or whether the image to be detected has no defects.

[0127] In at least one embodiment of the present application, the electronic device determines the total error of each size image according to each estimated probability and each calculated error, including:

[0128] The electronic device obtains a first preset weight corresponding to the estimated probability, and obtains a second preset weight corresponding to the calculated error, the sum of the first preset weight and the second preset weight is 1. Further, the electronic device multiplies each estimated probability by the first preset weight to obtain a first value, and multiplies each calculated error by the second preset weight to obtain a second value. Further, the electronic device adds each first value to each second value to obtain a total error of each size image.

[0129] Through the above implementation, the total error of each size image can be quickly determined.

[0130] In at least one embodiment of the present application, the electronic device determines the detection result of the image to be detected according to each total error and a preset threshold corresponding to each total error, including:

[0131] The electronic device determines a minimum preset threshold from the corresponding preset thresholds, and when each total error is smaller than the minimum preset threshold, the electronic device determines the detection result as that the image to be detected is flawless; or, when any total error is greater than or equal to the corresponding preset threshold, the electronic device determines the detection result as that the image to be detected has defects; or, when each total error is smaller than the corresponding preset threshold and each total error is greater than or equal to the minimum preset threshold, the electronic device determines the detection result as that the image to be detected has defects.

[0132] In at least one embodiment of the present application, when the image to be detected has defects, the electronic device generates reminder information according to the image to be detected, and sends the reminder information to a terminal device of a designated contact.

[0133] It can be seen from the above technical solutions that the present application covers the changes in defect types of various scales by performing size conversion on the image to be detected, thereby improving the accuracy of defect detection.

[0134] like Figure 2 , which is a functional module diagram of a preferred embodiment of the image defect detection device of the present application. The image defect detection device 11 includes an extraction unit 110, a conversion unit 111, an input unit 112, a comparison unit 113, a determination unit 114, an acquisition unit 115, a processing unit 116, a division unit 117, a training unit 118, a test unit 119, an adjustment unit 120, a calculation unit 121 and a generation unit 122. The module / unit referred to in the present application refers to a series of computer program segments that can be acquired by the processor 13 and can complete fixed functions, which are stored in the memory 12. In this embodiment, the functions of each module / unit will be described in detail in subsequent embodiments.

[0135] When receiving an image defect detection request, the extraction unit 110 extracts the image to be detected from the image defect detection request.

[0136] In at least one embodiment of the present application, the image defect detection request may be triggered by a user (eg, triggered by a preset function button) or may be automatically triggered within a preset time, which is not limited by the present application.

[0137] The preset time may be a time point (eg, 9:00 a.m. every day) or a time period.

[0138] In at least one embodiment of the present application, the information carried in the image defect detection request includes, but is not limited to: a detection object and an image to be detected. It is understandable that the image to be detected contains the detection object.

[0139] In at least one embodiment of the present application, the extracting unit 110 extracts the image to be detected from the image defect detection request, including:

[0140] The extraction unit 110 obtains an idle thread from a thread connection pool. Further, the extraction unit 110 uses the idle thread to parse the method body of the image defect detection request to obtain all information carried in the image defect detection request. Further, the extraction unit 110 obtains a preset tag and extracts information corresponding to the preset tag from all the information as the image to be detected according to the preset tag.

[0141] Wherein, the thread connection pool stores a plurality of threads; further, the preset tag refers to a tag used to identify the image to be detected.

[0142] By obtaining an idle thread from the thread connection pool, the thread creation time can be saved, and by parsing the method body of the image defect detection request, the parsing time of the image defect detection request can be shortened, and by the mapping relationship between the preset label and the image to be detected, the image to be detected can be accurately determined.

[0143] The conversion unit 111 converts the image to be detected into a plurality of size images of different preset sizes.

[0144] In at least one embodiment of the present application, the multiple different preset sizes may include, but are not limited to: 32*32, 64*64, 128*128.

[0145] In at least one embodiment of the present application, the converting unit 111 converts the image to be detected into a plurality of size images of different preset sizes, including:

[0146] The conversion unit 111 determines the detection object according to the image defect detection request, extracts a region image including the detection object from the image to be detected, and further converts the region image into the multiple size images according to the different preset sizes.

[0147] Through the above implementation, it can be ensured that the detection object is included in the multiple size images after conversion. In addition, since only the area image containing the detection object needs to be resized and there is no need to resize the image to be detected, the image pixels before the size conversion are reduced, which can improve the size conversion efficiency.

[0148] Specifically, the conversion unit 111 may use an open source opencv tool to convert the region image into the multiple size images having the different preset sizes.

[0149] The extraction unit 110 uses a pre-built encoder to perform feature extraction on the images of the multiple sizes to obtain multiple latent vectors.

[0150] In at least one embodiment of the present application, the encoder may be an encoder in an autoencoder (AE). Further, the encoder includes multiple hidden layers, and the number of the multiple hidden layers can be arbitrarily set according to the application scenario.

[0151] In at least one embodiment of the present application, the extraction unit 110 uses a pre-built encoder to perform feature extraction on the multiple size images to obtain multiple latent vectors including:

[0152] The extraction unit 110 performs encoding processing on each size image to obtain a feature vector of each size image. Further, the extraction unit 110 inputs each feature vector into multiple hidden layers in the encoder for operation, and determines the output vector of the last hidden layer as the latent vector corresponding to each size image.

[0153] Specifically, the extraction unit 110 inputs each feature vector into a plurality of hidden layers in the encoder for operation including:

[0154] For any hidden layer, the extraction unit 110 obtains the weight matrix and bias value corresponding to the arbitrary hidden layer. Further, the extraction unit 110 multiplies each feature vector with the weight matrix to obtain a calculation result, and adds the calculation result to the bias value to obtain the output vector of the arbitrary hidden layer.

[0155] The input unit 112 inputs the multiple latent vectors into a decoder corresponding to the encoder to obtain multiple reconstructed images, and inputs the multiple latent vectors into a pre-trained Gaussian mixture model to obtain an estimated probability corresponding to each size image.

[0156] In at least one embodiment of the present application, the decoder may be a decoder in an autoencoder (AE). Further, the decoder includes a plurality of operation layers corresponding to the hidden layers in the encoder, and the number of the plurality of operation layers is the same as the number of the plurality of hidden layers.

[0157] In at least one embodiment of the present application, the Gaussian Mixture Model (GMM) can accurately quantize the multiple latent vectors using a Gaussian probability density function (normal distribution curve).

[0158] In at least one embodiment of the present application, before the multiple latent vectors are input into a pre-trained Gaussian mixture model to obtain the estimated probability corresponding to each size image, the acquisition unit 115 acquires multiple training images. Further, the processing unit 116 encodes the multiple training images to obtain multiple encoding vectors, and performs dimensionality reduction and normalization on the multiple encoding vectors to obtain multiple low-dimensional vectors. Further, the division unit 117 divides the multiple low-dimensional vectors into a training set, a test set and a validation set. Further, the training unit 118 iteratively trains the low-dimensional vectors in the training set based on the maximum expectation algorithm to obtain a learner. Further, the testing unit 119 tests the learner using the low-dimensional vectors in the test set to obtain a test result. When the test result is less than the configuration value, the adjustment unit 120 adjusts the parameters of the learner using the low-dimensional vectors in the validation set to obtain the Gaussian mixture model.

[0159] Through the above implementation, the generated Gaussian mixture model can be made more accurate.

[0160] In at least one embodiment of the present application, before dividing the multiple low-dimensional vectors into a training set, a test set, and a validation set, the computing unit 121 calculates the number of the multiple low-dimensional vectors. When the number is less than a preset number, the computing unit 121 uses a data enhancement algorithm to increase the number of the multiple low-dimensional vectors.

[0161] Through the above implementation, it is possible to avoid the poor generalization ability of the estimated probability generated by the trained Gaussian mixture model due to the insufficient number of multiple low-dimensional vectors.

[0162] In at least one embodiment of the present application, the dividing unit 117 divides the multiple low-dimensional vectors into a training set, a test set, and a validation set, including:

[0163] The division unit 117 randomly divides the multiple low-dimensional vectors into multiple data packets according to a preset ratio. Further, the division unit 117 determines any two of the multiple data packets as the verification set and the test set, respectively, and determines the remaining data packets as the training set. The above steps are repeated until all the data packets are used as the verification sets in turn.

[0164] Among them, the preset ratio can be customized and is not limited in this application.

[0165] Through the above implementation, each of the multiple low-dimensional vectors is involved in training and verification, thereby improving the fit of the training Gaussian mixture model.

[0166] The comparison unit 113 compares each reconstructed image with each size image to obtain a calculation error of each size image.

[0167] In at least one embodiment of the present application, the comparison unit 113 compares each reconstructed image with each size image, and the calculation error of each size image obtained includes:

[0168] For any reconstructed image, the comparison unit 113 extracts all reconstructed pixels in the any reconstructed image and calculates a first number of all the reconstructed pixels. Further, the comparison unit 113 extracts all target pixels in each size image. The comparison unit 113 compares each reconstructed pixel with each target pixel to obtain a comparison result, wherein a comparison result in which the reconstructed pixel is different from the target pixel is determined as a target comparison result. Further, the target comparison unit 113 calculates a second number and divides the second number by the first number to obtain a calculation error for each size image.

[0169] Through the above implementation, the calculation error of each size image can be accurately determined.

[0170] The determination unit 114 determines the total error of each size image according to each estimated probability and each calculated error, and determines the detection result of the image to be detected according to each total error and a preset threshold corresponding to each total error.

[0171] In at least one embodiment of the present application, the detection result includes whether the image to be detected has defects or whether the image to be detected has no defects.

[0172] In at least one embodiment of the present application, the determining unit 114 determines the total error of each size image according to each estimated probability and each calculated error, including:

[0173] The determination unit 114 obtains a first preset weight corresponding to the estimated probability, and obtains a second preset weight corresponding to the calculated error, the sum of the first preset weight and the second preset weight is 1. Further, the determination unit 114 multiplies each estimated probability by the first preset weight to obtain a first value, and multiplies each calculated error by the second preset weight to obtain a second value. Further, the determination unit 114 adds each first value to each second value to obtain a total error of each size image.

[0174] Through the above implementation, the total error of each size image can be quickly determined.

[0175] In at least one embodiment of the present application, the determining unit 114 determines the detection result of the image to be detected according to each total error and a preset threshold corresponding to each total error, including:

[0176] The determination unit 114 determines a minimum preset threshold from the corresponding preset thresholds, and when each total error is less than the minimum preset threshold, the determination unit 114 determines the detection result as the image to be detected is flawless, or, when any total error is greater than or equal to the corresponding preset threshold, the determination unit 114 determines the detection result as the image to be detected has defects, or, when each total error is less than the corresponding preset threshold and each total error is greater than or equal to the minimum preset threshold, the determination unit 114 determines the detection result as the image to be detected has defects.

[0177] In at least one embodiment of the present application, when the image to be detected has defects, the generating unit 122 generates reminder information according to the image to be detected, and sends the reminder information to a terminal device of a designated contact.

[0178] It can be seen from the above technical solutions that the present application covers the changes in defect types of various scales by performing size conversion on the image to be detected, thereby improving the accuracy of defect detection.

[0179] like Figure 3 , is a schematic diagram of the structure of an electronic device of a preferred embodiment of the image defect detection method of the present application.

[0180] In one embodiment of the present application, the electronic device 1 includes, but is not limited to, a memory 12, a processor 13, and a computer program stored in the memory 12 and executable on the processor 13, such as an image defect detection program.

[0181] Those skilled in the art will understand that the schematic diagram is merely an example of the electronic device 1 and does not constitute a limitation on the electronic device 1. The electronic device 1 may include more or fewer components than shown in the diagram, or a combination of certain components, or different components. For example, the electronic device 1 may also include input and output devices, network access devices, buses, etc.

[0182] The processor 13 may be a central processing unit (CPU), or other general-purpose processors, digital signal processors (DSP), application-specific integrated circuits (ASIC), field-programmable gate arrays (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. A general-purpose processor may be a microprocessor or any conventional processor, etc. The processor 13 is the computing core and control center of the electronic device 1, and uses various interfaces and lines to connect various parts of the entire electronic device 1, and obtain the operating system of the electronic device 1 and various installed applications, program codes, etc.

[0183] The processor 13 obtains the operating system of the electronic device 1 and various installed applications. The processor 13 obtains the applications to implement the steps in the above-mentioned various image defect detection method embodiments, for example Figure 1 Steps shown.

[0184] Exemplarily, the computer program may be divided into one or more modules / units, which are stored in the memory 12 and acquired by the processor 13 to complete the present application. The one or more modules / units may be a series of computer program instruction segments capable of completing specific functions, which are used to describe the acquisition process of the computer program in the electronic device 1. For example, the computer program may be divided into an extraction unit 110, a conversion unit 111, an input unit 112, a comparison unit 113, a determination unit 114, an acquisition unit 115, a processing unit 116, a division unit 117, a training unit 118, a testing unit 119, an adjustment unit 120, a calculation unit 121, and a generation unit 122.

[0185] The memory 12 can be used to store the computer program and / or module, and the processor 13 implements various functions of the electronic device 1 by running or acquiring the computer program and / or module stored in the memory 12, and calling the data stored in the memory 12. The memory 12 can mainly include a program storage area and a data storage area, wherein the program storage area can store an operating system, an application required for at least one function (such as a sound playback function, an image playback function, etc.), etc.; the data storage area can store data created according to the use of the electronic device, etc. In addition, the memory 12 can include a non-volatile memory, such as a hard disk, a memory, a plug-in hard disk, a smart memory card (Smart Media Card, SMC), a secure digital (Secure Digital, SD) card, a flash card (Flash Card), at least one disk storage device, a flash memory device, or other non-volatile solid-state storage devices.

[0186] The memory 12 may be an external memory and / or an internal memory of the electronic device 1. Furthermore, the memory 12 may be a memory in a physical form, such as a memory stick, a TF card (Trans-flash Card), and the like.

[0187] If the module / unit integrated in the electronic device 1 is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the present application implements all or part of the processes 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 obtained by the processor, the steps of each of the above-mentioned method embodiments can be implemented.

[0188] The computer program includes computer program code, which may be in source code form, object code form, an accessible file or some intermediate form, etc. The computer readable medium may 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 disk, a computer memory, and a read-only memory (ROM).

[0189] Combination Figure 1, the memory 12 in the electronic device 1 stores multiple instructions to implement an image defect detection method, and the processor 13 can obtain the multiple instructions to achieve: when receiving an image defect detection request, extract the image to be detected from the image defect detection request; convert the image to be detected into multiple size images of different preset sizes; use a pre-built encoder to extract features from the multiple size images to obtain multiple latent vectors; input the multiple latent vectors into a decoder corresponding to the encoder to obtain multiple reconstructed images, and input the multiple latent vectors into a pre-trained Gaussian mixture model to obtain an estimated probability corresponding to each size image; compare each reconstructed image with each size image to obtain a calculated error of each size image; determine the total error of each size image according to each estimated probability and each calculated error with each total error, and determine the detection result of the image to be detected according to each total error and the corresponding preset threshold.

[0190] Specifically, the specific implementation method of the processor 13 for the above instructions can refer to Figure 1 The description of the relevant steps in the corresponding embodiments will not be repeated here.

[0191] In the several embodiments provided in this application, it should be understood that the disclosed systems, devices and methods can be implemented in other ways. For example, the device embodiments described above are only illustrative, for example, the division of the modules is only a logical function division, and there may be other division methods in actual implementation.

[0192] The modules described as separate components may or may not be physically separated, and the components shown as modules may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the solution of this embodiment.

[0193] In addition, each functional module in each embodiment of the present application can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The above integrated unit can be implemented in the form of hardware or in the form of hardware plus software functional modules.

[0194] Therefore, no matter from which point of view, the embodiments should be regarded as illustrative and non-restrictive, and the scope of the present application is limited by the appended claims rather than the above description, so it is intended that all changes falling within the meaning and scope of the equivalent elements of the claims are included in the present application. Any attached figure mark in the claims should not be regarded as limiting the claims involved.

[0195] In addition, it is clear that the word "comprising" does not exclude other units or steps, and the singular does not exclude the plural. Multiple units or devices stated in this application can also be implemented by one unit or device through software or hardware. The words first, second, etc. are used to indicate names, and do not indicate any particular order.

[0196] Finally, it should be noted that the above embodiments are only used to illustrate the technical solution of the present application and are not intended to limit it. Although the present application has been described in detail with reference to the preferred embodiments, a person of ordinary skill in the art should understand that the technical solution of the present application may be modified or replaced by equivalents without departing from the spirit and scope of the technical solution of the present application.

Claims

1. A method for detecting image defects, characterized in that: The image defect detection method comprises: When receiving an image defect detection request, extracting an image to be detected from the image defect detection request; Converting the image to be detected into a plurality of size images of different preset sizes; Using a pre-built encoder to extract features from the images of the multiple sizes to obtain multiple latent vectors; Inputting the multiple latent vectors into a decoder corresponding to the encoder to obtain multiple reconstructed images, and inputting the multiple latent vectors into a pre-trained Gaussian mixture model to obtain an estimated probability corresponding to each size image; Compare each reconstructed image with each size image to obtain the calculated error of each size image; The total error of each size image is determined according to each estimated probability and each calculated error, and the detection result of the image to be detected is determined according to each total error and the preset threshold corresponding to each total error, including: determining a minimum preset threshold from the corresponding preset thresholds; when each total error is less than the minimum preset threshold, determining the detection result as the image to be detected is flawless; or when any total error is greater than or equal to the corresponding preset threshold, determining the detection result as the image to be detected has a defect; or when each total error is less than the corresponding preset threshold and each total error is greater than or equal to the minimum preset threshold, determining the detection result as the image to be detected has a defect.

2. The image defect detection method according to claim 1, characterized in that: The extracting the image to be detected from the image defect detection request comprises: Get an idle thread from the thread connection pool; Utilizing the idle thread to parse the method body of the image defect detection request to obtain all information carried in the image defect detection request; A preset label is obtained, and information corresponding to the preset label is extracted from all the information according to the preset label as the image to be detected.

3. The image defect detection method according to claim 1, characterized in that: The step of converting the image to be detected into a plurality of size images of different preset sizes comprises: Determining a detection object according to the image defect detection request; Extracting a region image containing the detection object from the image to be detected; The regional image is converted into images of the multiple sizes according to the different preset sizes.

4. The image defect detection method according to claim 1, characterized in that: The using of a pre-built encoder to extract features from the images of the multiple sizes to obtain multiple latent vectors includes: Encode each size image to obtain a feature vector of each size image; Each feature vector is input into a plurality of hidden layers in the encoder for operation, and an output vector of the last hidden layer is determined as a latent vector corresponding to an image of each size.

5. The image defect detection method according to claim 1, characterized in that: Before inputting the multiple latent vectors into a pre-trained Gaussian mixture model to obtain an estimated probability corresponding to each size image, the image defect detection method further includes: Obtain multiple training images; Encoding the multiple training images to obtain multiple encoding vectors, and performing dimensionality reduction and normalization processing on the multiple encoding vectors to obtain multiple low-dimensional vectors; Dividing the multiple low-dimensional vectors into a training set, a test set, and a validation set; Based on the maximum expectation algorithm, iteratively train the low-dimensional vectors in the training set to obtain a learner; Testing the learner using the low-dimensional vectors in the test set to obtain a test result; When the test result is less than the configured value, the parameters of the learner are adjusted using the low-dimensional vectors in the validation set to obtain the Gaussian mixture model.

6. The image defect detection method according to claim 1, characterized in that: The step of comparing each reconstructed image with each size image to obtain a calculation error of each size image includes: For any reconstructed image, extract all reconstructed pixel points in the arbitrary reconstructed image, and calculate a first number of all the reconstructed pixel points; Extract all target pixels in each size image; Comparing each reconstructed pixel with each target pixel to obtain a comparison result, wherein a comparison result that is different between the reconstructed pixel and the target pixel is determined as a target comparison result; A second number of the target comparison results is calculated, and the second number is divided by the first number to obtain a calculation error for each size image.

7. An image defect detection device, characterized in that: The image defect detection device comprises: an extraction unit, configured to extract an image to be detected from the image defect detection request when receiving the image defect detection request; A conversion unit, used for converting the image to be detected into a plurality of size images of different preset sizes; The extraction unit is further used to extract features from the images of the multiple sizes using a pre-built encoder to obtain multiple latent vectors; An input unit, configured to input the plurality of latent vectors into a decoder corresponding to the encoder to obtain a plurality of reconstructed images, and input the plurality of latent vectors into a pre-trained Gaussian mixture model to obtain an estimated probability corresponding to each size image; A comparison unit, used for comparing each reconstructed image with each size image to obtain a calculation error of each size image; A determination unit is used to determine the total error of each size image according to each estimated probability and each calculated error, and determine the detection result of the image to be detected according to each total error and a preset threshold corresponding to each total error, including: determining a minimum preset threshold from the corresponding preset thresholds; when each total error is less than the minimum preset threshold, determining the detection result as the image to be detected is flawless; or when any total error is greater than or equal to the corresponding preset threshold, determining the detection result as the image to be detected has a defect; or when each total error is less than the corresponding preset threshold and each total error is greater than or equal to the minimum preset threshold, determining the detection result as the image to be detected has a defect.

8. An electronic device, characterized in that: The electronic device comprises: a memory storing at least one instruction; and A processor is configured to obtain instructions stored in the memory to implement the image defect detection method according to any one of claims 1 to 6.

9. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores at least one instruction, and the at least one instruction is acquired by a processor in an electronic device to implement the image defect detection method according to any one of claims 1 to 6.

Citation Information

Patent Citations

  • Industrial product surface defect identification method and device based on machine learning

    CN110232404A

  • Defect detection method and device, defect detection equipment and computer storage medium

    CN111507974A