A workpiece defect detection method and device, electronic equipment and storage medium
By extracting image features of metal parts using a neural network model and generating a Gaussian distribution function, and combining features of both defect-free and defective types, the problem of low detection accuracy in existing technologies is solved, achieving more efficient defect detection.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- ANYANG INST OF TECH
- Filing Date
- 2023-04-28
- Publication Date
- 2026-04-10
AI Technical Summary
Existing deep learning-based methods for detecting defects in metal parts require massive amounts of sample images and struggle to cover all defects, resulting in low detection accuracy.
The features of the image to be detected are extracted by a pre-trained neural network model. A Gaussian distribution function is generated using the features of sample images without defects. The probability density value of the image features is calculated to determine whether there are defects in the image. The feature of sample images with defects is then combined for further judgment.
It improves the accuracy of defect detection, reduces the reliance on the accuracy of neural network models, and lowers the false negative rate.
Smart Images

Figure CN116523871B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the technical field of image processing, and particularly relates to a workpiece defect detection method and device, electronic equipment and a storage medium. BACKGROUND
[0002] In a metal processing process, by performing defect detection on a surface image of a metal workpiece, metal workpieces with defects can be screened out. In related technologies, a deep learning-based method can be used to perform defect detection on the surface image of the metal workpiece. However, this method needs to collect a large number of sample images in the training stage, and needs to cover as many possible defects as possible, which is difficult to achieve in actual scenarios. Moreover, the style of a defect cannot be defined and collected before it occurs, and therefore, the method based on this may cause a missed detection problem, resulting in low accuracy of defect detection. SUMMARY
[0003] To solve the above technical problems, the present application provides a workpiece defect detection method and device, electronic equipment and a storage medium.
[0004] According to a first aspect of the present application, a workpiece defect detection method is provided, comprising:
[0005] obtaining a to-be-detected image, performing feature extraction on the to-be-detected image by a pre-trained neural network model to obtain an image feature of the to-be-detected image;
[0006] obtaining a sample image feature from an image feature library; wherein each sample image feature is obtained by inputting a sample image into the neural network model for feature extraction; and the sample image feature includes a sample image feature of a non-defect type;
[0007] generating a Gaussian distribution function according to the sample image feature of the non-defect type;
[0008] calculating a probability density value of the image feature of the to-be-detected image in the Gaussian distribution function; wherein the probability density value represents a probability that the to-be-detected image is a non-defect image;
[0009] judging whether the to-be-detected image has a defect according to the probability density value.
[0010] Optionally, judging whether the to-be-detected image has a defect according to the probability density value comprises:
[0011] in a case where the probability density value is less than or equal to a probability density threshold, determining that the to-be-detected image has a defect;
[0012] determining that the image to be detected does not have a defect, or
[0013] in a case where the probability density value is greater than the probability density threshold value and the sample image feature comprises a sample image feature of a defective type, judging whether the image to be detected has a defect according to the sample image feature of the defective type.
[0014] Optionally, the judging whether the image to be detected has a defect according to the sample image feature of the defective type comprises:
[0015] calculating a first distance between the image feature of the image to be detected and a sample image feature of a non-defective type;
[0016] calculating a second distance between the image feature of the image to be detected and a sample image feature of a defective type;
[0017] judging whether the image to be detected has a defect according to the first distance and the second distance.
[0018] Optionally, the generating a Gaussian distribution function according to the sample image feature of the non-defective type comprises:
[0019] obtaining a mean value μ of the sample image feature of the non-defective type according to the sample image feature of the non-defective type, and generating the following Gaussian distribution function:
[0020]
[0021] wherein ∑ is a covariance, T is a transpose of a matrix, x is an input variable image feature, p(x) is a probability of an image corresponding to the input variable image feature x being a non-defective image, and n represents a dimension of the sample image feature.
[0022] Optionally, the calculating the first distance between the image feature of the image to be detected and the sample image feature of the non-defective type comprises:
[0023] calculating a distance between the image feature of the image to be detected and each sample image feature of the non-defective type, and selecting a minimum distance from the obtained distances as the first distance;
[0024] the calculating the second distance between the image feature of the image to be detected and the sample image feature of the defective type comprises:
[0025] calculating a distance between the image feature of the image to be detected and each sample image feature of the defective type, and selecting a minimum distance from the obtained distances as the second distance.
[0026] Optionally, the determining whether the to-be-detected image has defects according to the first distance and the second distance comprises:
[0027] According to the following formula:
[0028]
[0029] obtaining a confidence f of the to-be-detected image; wherein d1 is the first distance, and d2 is the second distance;
[0030] In a case where the confidence f is less than a confidence threshold, it is determined that the to-be-detected image has defects.
[0031] In a case where the confidence f is greater than or equal to the confidence threshold, it is determined that the to-be-detected image has no defects.
[0032] Optionally, the neural network model comprises an encoding module and a decoding module.
[0033] The training method of the neural network model comprises:
[0034] obtaining a plurality of training images and an actual image segmentation result corresponding to each of the training images;
[0035] encoding each of the training images by using the encoding module to obtain a training image feature;
[0036] decoding the training image feature by using the decoding module to obtain a predicted image segmentation result;
[0037] obtaining a loss function value according to the predicted image segmentation result and the actual image segmentation result;
[0038] updating network parameters in the encoding module and the decoding module according to the loss function value to obtain the neural network model.
[0039] According to a second aspect of the present application, a defect detection device is provided, comprising:
[0040] a to-be-detected image acquisition module configured to acquire a to-be-detected image;
[0041] an image feature extraction module configured to extract features of the to-be-detected image by using a pre-trained neural network model to obtain image features of the to-be-detected image;
[0042] a sample image feature acquisition module configured to acquire sample image features from an image feature library; wherein each of the sample image features is obtained by inputting a sample image into the neural network model for feature extraction; and the sample image features comprise sample image features of a non-defect type.
[0043] a Gaussian distribution function generation module, configured to generate a Gaussian distribution function according to the sample image features of the defect-free type;
[0044] a probability density value calculation module, configured to calculate a probability density value of the image feature of the image to be detected in the Gaussian distribution function; the probability density value represents a probability that the image to be detected is a defect-free image;
[0045] a defect judgment module, configured to judge whether the image to be detected has a defect according to the probability density value.
[0046] Optionally, the defect judgment module is specifically configured to determine that the image to be detected has a defect in a case where the probability density value is less than or equal to a probability density threshold; determine that the image to be detected does not have a defect in a case where the probability density value is greater than the probability density threshold, or, in a case where the probability density value is greater than the probability density threshold and the sample image features include sample image features of a defect type, judge whether the image to be detected has a defect according to the sample image features of the defect type.
[0047] Optionally, the defect judgment module is specifically configured to judge whether the image to be detected has a defect according to the sample image features of the defect type by the following steps:
[0048] calculating a first distance between the image feature of the image to be detected and the sample image features of the defect-free type;
[0049] calculating a second distance between the image feature of the image to be detected and the sample image features of the defect type;
[0050] judging whether the image to be detected has a defect according to the first distance and the second distance.
[0051] Optionally, the Gaussian distribution function generation module is specifically configured to obtain a mean μ of the sample image features of the defect-free type according to the sample image features of the defect-free type, and generate the following Gaussian distribution function:
[0052]
[0053] wherein Σ is a covariance, T is a transpose of a matrix, x is an input variable image feature, p(x) is a probability that an image corresponding to the input variable image feature x is a defect-free image, and n represents a dimension of the sample image feature.
[0054] Optionally, the defect judgment module is specifically configured to calculate the first distance between the image feature of the image to be detected and the sample image features of the defect-free type by the following steps:
[0055] calculate distances between the image feature of the image to be detected and the sample image features of each defect-free type, and select the minimum distance from the obtained distances as a first distance; and calculate a second distance between the image feature of the image to be detected and the sample image features of the defect type by the following steps:
[0056] calculate distances between the image feature of the image to be detected and the sample image features of each defect-free type, and select the minimum distance from the obtained distances as a first distance; and calculate a second distance between the image feature of the image to be detected and the sample image features of the defect type by the following steps:
[0057] Optionally, the defect judging module is specifically configured to judge whether the image to be detected has defects according to the first distance and the second distance by the following steps:
[0058] According to the following formula:
[0059]
[0060] obtain a confidence f of the image to be detected; wherein d1 is the first distance, and d2 is the second distance;
[0061] in a case where the confidence f is less than a confidence threshold, determine that the image to be detected has defects;
[0062] in a case where the confidence f is greater than or equal to the confidence threshold, determine that the image to be detected has no defects.
[0063] Optionally, the neural network model comprises an encoding module and a decoding module.
[0064] The defect detection device further comprises:
[0065] a model training module configured to obtain a plurality of training images and actual image segmentation results corresponding to each of the training images; encode each of the training images by the encoding module to obtain training image features; decode the training image features by the decoding module to obtain predicted image segmentation results; obtain a loss function value according to the predicted image segmentation results and the actual image segmentation results, and update network parameters in the encoding module and the decoding module according to the loss function value to obtain the neural network model.
[0066] According to a third aspect of the present application, an electronic device is provided, comprising: a processor configured to execute a computer program stored in a memory, the computer program being executed by the processor to implement the method of the first aspect.
[0067] According to a fourth aspect of the present application, a computer readable storage medium is provided, having stored thereon a computer program which, when executed by a processor, implements the method of the first aspect.
[0068] According to a fifth aspect of the present application, a computer program product is provided which, when running on a computer, causes the computer to perform the method of the first aspect.
[0069] The technical solution provided by the embodiments of the present application has the following advantages compared with the prior art.
[0070] The image features of the to-be-detected image are extracted by the pre-trained neural network model, and sample image features are obtained from the image feature library. Each sample image feature is obtained by inputting a sample image into the neural network model for feature extraction. The sample image features in the image feature library include sample image features of the no-defect type. In this way, the Gaussian distribution function can be generated by using the characteristic that the sample image features of the no-defect type conform to the Gaussian distribution. The probability density value of the image features of the to-be-detected image in the Gaussian distribution function is calculated, and the probability density value represents the probability that the to-be-detected image is a no-defect image. Then, whether the to-be-detected image has defects is determined according to the probability density value. In the embodiments of the present application, the neural network model is used as a tool to extract image features, and the image features of the to-be-detected image are compared with the sample image features in the image feature library to detect whether the image has defects. Compared with directly judging whether the image has defects by using the neural network model, the accuracy of the detection result is not affected by the accuracy of the neural network model. In addition, the Gaussian distribution characteristic of the sample image features of the no-defect type is used to detect whether the image has defects, that is, whether the image has defects is detected in a statistical sense, which can improve the accuracy of defect detection. BRIEF DESCRIPTION OF DRAWINGS
[0071] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the present application and serve to explain the principles of the present application together with the specification.
[0072] In order to more clearly illustrate the technical solutions in the embodiments of the present application or the prior art, the accompanying drawings needed to be used in the embodiments or prior art description will be briefly introduced. Obviously, those skilled in the art can obtain other drawings from these drawings without any creative effort.
[0073] Figure 1 A flowchart of the workpiece defect detection method in the embodiments of the present application;
[0074] Figure 2 A structural schematic diagram of the neural network model in the embodiments of the present application;
[0075] Figure 3 A flow chart of a training method of a neural network model in an embodiment of the present application;
[0076] Figure 4 A schematic diagram of a workpiece defect detection method in an embodiment of the present application;
[0077] Figure 5 A structural schematic diagram of a defect detection device in an embodiment of the present application;
[0078] Figure 6 A structural schematic diagram of an electronic device in an embodiment of the present application. DETAILED DESCRIPTION
[0079] In order to enable a more complete understanding of the above-mentioned purposes, features and advantages of the present application, the scheme of the present application will be further described below. It should be noted that the embodiments of the present application and the features in the embodiments can be combined with each other without conflict.
[0080] In the following description, many specific details are set forth in order to provide a thorough understanding of the present application, but the present application can also be implemented in other ways different from those described herein; obviously, the embodiments in the description are only some of the embodiments of the present application, not all the embodiments.
[0081] Reference should be made to Figure 1 , Figure 1 A flow chart of a workpiece defect detection method in an embodiment of the present application can include the following steps:
[0082] In step S110, an image to be detected is acquired, and a pre-trained neural network model is used to extract features of the image to be detected, to obtain image features of the image to be detected.
[0083] The image to be detected includes a surface image of a metal workpiece, and the metal workpiece can be produced by the same mold. The pixel features of the collected image are not completely consistent in the image coordinate system, but there are slight differences. These differences make it impossible to effectively extract the defect position by directly using traditional image processing algorithms (such as image difference algorithm, etc.). In addition, the metal surface has high light reflection and wire drawing characteristics, which can easily cause false alarm detection and missed detection problems. Among them, false alarm detection refers to that there is actually no defect in the image, but the defect is detected during defect detection. Therefore, in the embodiments of the present application, a pre-trained neural network model can be used to extract image features in the image to be detected, that is, higher-level features are used to identify defects, so as to eliminate the problems of misalignment of image features, and low accuracy of defect detection caused by light reflection and wire drawing of the metal surface.
[0084] The pre-trained neural network model can be an image classification model or an image segmentation model. The input of the image classification model is an image, and the output is whether the image has a defect or not. The input of the image segmentation model is also an image, and the output is an image segmentation result, i.e., the labels of each pixel in the image, which can indicate whether the pixel has a defect or not.
[0085] In some embodiments, the neural network model is an image segmentation model, which can include an encoding module and a decoding module. The network structure of the encoding module and the decoding module is not limited in the present application. Optionally, the encoding module can adopt a CNN (Convolutional Neural Network) or the like. See Figure 2 , Figure 2 A structure diagram of the neural network model in the embodiments of the present application is shown. The encoding module is used to extract image features from the input image, and the decoding module is used to restore the image features to an image with consistent size, to obtain an image segmentation result, i.e., the label of each pixel. In the case of the neural network model being an image segmentation model, the training method of the neural network model can refer to Figure 3 , which includes the following steps:
[0086] In step S310, a plurality of training images and actual image segmentation results corresponding to each training image are obtained.
[0087] The training images can include images with defects and images without defects, and the actual image segmentation result corresponding to the training image refers to the label result of each pixel in the training image.
[0088] In step S320, each training image is encoded by the encoding module to obtain a training image feature.
[0089] In step S330, the training image feature is decoded by the decoding module to obtain a predicted image segmentation result.
[0090] In step S340, a loss function value is obtained according to the predicted image segmentation result and the actual image segmentation result.
[0091] It can be understood that in the training process, the network parameters in the encoding module and the decoding module are constantly adjusted, and the predicted image segmentation result is usually different from the actual image segmentation result. Therefore, the predicted image segmentation result and the actual image segmentation result can be substituted into a loss function to obtain a loss function value.
[0092] In step S350, the network parameters in the encoding module and the decoding module are updated according to the loss function value to obtain a neural network model.
[0093] In the iteration process, the values of the network parameters in the encoding module and the decoding module are updated through the back propagation algorithm. The iteration is repeated until a convergence condition (e.g., the value of the loss function is less than a preset threshold) is met, the values of the network parameters in the model are obtained, and thus the training is completed to obtain the neural network model.
[0094] At step S120, a sample image feature is obtained from the image feature library.
[0095] In the embodiment of the present application, a plurality of sample image features are stored in the image feature library. Each sample image feature is obtained by inputting a sample image into the neural network model for feature extraction. That is, the neural network model is used to extract image features of a sample image, i.e., sample image features, in addition to extracting image features of the image to be detected. In the metal processing process, the number of defect-free metal workpieces is usually larger than the number of defective metal workpieces, and therefore it is easier to obtain defect-free metal workpieces. The surface image of a defect-free metal workpiece is a sample image of the defect-free type, and the sample image features in the image feature library can include sample image features of the defect-free type. The sample image features in the image feature library can be constantly increasing.
[0096] At step S130, a Gaussian distribution function is generated according to the sample image features of the defect-free type.
[0097] For sample image features of the defect-free type, the sample distribution generally obeys a Gaussian distribution, and therefore it can be statistically determined whether the image to be detected has a defect. That is, a Gaussian distribution function can be generated according to the sample image features of the defect-free type. Alternatively, the mean μ of the sample image features of the defect-free type is obtained from the sample image features of the defect-free type, and the following Gaussian distribution function is generated:
[0098]
[0099] wherein Σ is a covariance, T is a transpose of a matrix, x is an input variable image feature, p(x) is a probability that an image corresponding to the input variable image feature x is a defect-free image, and n represents a dimension of the sample image feature.
[0100] Suppose that the sample image feature is a feature map of c x w x h, c represents a number of channels, h represents a height of the feature map, and w represents a width of the feature map. The sample image feature can be stretched into a feature vector of 1 x n, n = c x w x h, i.e., a dimension of the sample image feature.
[0101] At step S140, a probability density value of the image feature of the image to be detected in the Gaussian distribution function is calculated.
[0102] Similarly, the image features of the image to be detected can also be represented as a 1 x n feature vector. By taking the feature vector as the input variable of the Gaussian distribution function, a corresponding probability density value can be obtained, which represents the probability that the image to be detected is a defect-free image.
[0103] In step S150, whether the image to be detected has defects is determined according to the probability density value.
[0104] The greater the probability density value, the more likely the image to be detected is defect-free. In some embodiments, whether the image to be detected has defects can be directly determined by judging whether the probability density value is greater than a probability density threshold. In the case where the probability density value is less than or equal to the probability density threshold, it is determined that the image to be detected has defects; in the case where the probability density value is greater than the probability density threshold, it is determined that the image to be detected is defect-free.
[0105] The processing piece defect detection method of the embodiments of the present application can generate a Gaussian distribution function by using the characteristic that the sample image features of the defect-free type conform to Gaussian distribution. The probability density value of the image features of the image to be detected in the Gaussian distribution function is calculated, and the probability density value represents the probability that the image to be detected is a defect-free image. Further, whether the image to be detected has defects is determined according to the probability density value. In the embodiments of the present application, the neural network model is used as a tool to extract image features, and the image features of the image to be detected are compared with the sample image features in the image feature library to detect whether the image has defects. Compared with directly judging whether the image has defects by using the neural network model, the accuracy of the detection result is not affected by the accuracy of the neural network model. Moreover, the Gaussian distribution characteristic of the sample image features of the defect-free type is used to detect whether the image has defects, i.e., whether the image has defects in a statistical sense, which can improve the accuracy of defect detection.
[0106] In some embodiments, in order to improve the accuracy of defect detection and avoid determining that the image with defects is defect-free, in the case where the probability density value is greater than the probability density threshold and the sample image features in the image feature library include sample image features of the defective type, whether the image to be detected has defects can be further determined according to the sample image features of the defective type.
[0107] Since the sample image features of the defective type have no fixed mode and their shapes vary, their feature distribution does not conform to Gaussian distribution, and therefore the Gaussian distribution function cannot be directly established to determine whether the image to be detected has defects. Therefore, the sample image features of the defective type and the sample image features of the defect-free type can be combined to determine whether the image to be detected has defects.
[0108] Suppose the number of sample image features of the defect-free type is N, and the number of sample image features of the defective type is M, which are respectively stored in the defect-free sample library and the defective sample library in the format of 1 x n feature vectors. In the case of M being 0, that is, directly judging whether the to-be-detected image has defects by judging whether the probability density value is greater than the probability density threshold.
[0109] Alternatively, the image features of the to-be-detected image can be compared with the sample image features of the defect-free type and the sample image features of the defective type respectively, and according to the comparison result, it is judged whether the to-be-detected image has defects. It can be understood that the greater the values of N and M, the more accurate the defect detection result, and therefore N and M can be a larger number. The value of N can be selected according to the complexity of the surface features of the metal workpiece, for example, N is a value greater than 500. When the accuracy of the detection result is low, the value of N can be increased, that is, more sample image features of the defect-free type can be obtained, and the image features are extracted by the neural network model to increase the number of sample image features of the defect-free type.
[0110] In some embodiments, a first distance between the image features of the to-be-detected image and the sample image features of the defect-free type can be calculated; a second distance between the image features of the to-be-detected image and the sample image features of the defective type can be calculated; and according to the first distance and the second distance, it is judged whether the to-be-detected image has defects.
[0111] Alternatively, the distance between the image features of the to-be-detected image and each sample image feature of the defect-free type can be calculated, and the smallest distance obtained is selected as the first distance. The first distance d1 can be represented as follows:
[0112]
[0113] x represents the image features of the to-be-detected image, x i represents the i-th sample image feature of the defect-free type, ||x-x i || represents the distance between the image features x of the to-be-detected image and the i-th sample image feature x i of the defect-free type.
[0114] In addition to the smallest distance as the first distance, the average of all distances obtained can also be used as the first distance.
[0115] The distance between the image features of the to-be-detected image and each sample image feature of the defective type is calculated, and the smallest distance obtained is selected as the second distance. The second distance d2 can be represented as follows:
[0116]
[0117] x represents the image feature of the image to be detected, x j represents the image feature of the jth sample image of the defect type, ||x-x j represents the distance between the image feature x of the image to be detected and the image feature x j of the jth sample image of the defect type.
[0118] Similarly, in addition to taking the minimum distance as the second distance, the average of all distances obtained can also be taken as the second distance.
[0119] The smaller the first distance is, and the larger the second distance is, the more likely the image to be detected is free of defects; on the contrary, the larger the first distance is, and the smaller the second distance is, the more likely the image to be detected is defective. Alternatively, the first distance and the second distance can be directly compared with different preset distance thresholds respectively to determine whether the image to be detected is defective. For example, in the case that the first distance is less than a first preset distance threshold, and the second distance is greater than a second preset distance threshold, it is determined that the image to be detected is free of defects; in the case that the first distance is greater than or equal to the first preset distance threshold, or the second distance is less than or equal to the second preset distance threshold, it is determined that the image to be detected is defective.
[0120] Alternatively, the first distance and the second distance can also be substituted into a preset formula to determine whether the image to be detected is defective according to the obtained value. For example, the following formula can be used:
[0121]
[0122] to obtain the confidence f of the image to be detected; wherein d1 is the first distance, and d2 is the second distance. The confidence represents the confidence degree that the image to be detected is free of defects, and the value range is [0, 1], when f is 0, it means that it is defective, and when f is 1, it means that it is free of defects. In the case that the confidence f is less than a confidence threshold (for example, 0.8, etc.), it is determined that the image to be detected is defective; in the case that the confidence f is greater than or equal to the confidence threshold, it is determined that the image to be detected is free of defects.
[0123] Referring to Figure 4 , Figure 4Fig. 1 is a schematic diagram of a processing piece defect detection method according to an embodiment of the present application. After the image to be detected is input into the neural network model, the corresponding image features can be extracted. The image feature library includes sample image features of the defect-free type and sample image features of the defective type. The sample image of the defect-free type is input into the neural network model for feature extraction, and the sample image features of the defect-free type can be obtained. The sample image of the defective type is input into the neural network model for feature extraction, and the sample image features of the defective type can be obtained. The image features of the image to be detected and the sample image features in the image feature library are compared, and the comparison result can be obtained. Whether the image to be detected has defects can be determined according to the comparison result.
[0124] Specifically, the Gaussian distribution function can be generated by using the characteristic that the sample image features of the defect-free type conform to the Gaussian distribution. The probability density value of the image features of the image to be detected in the Gaussian distribution function can be calculated. In the case that the probability density value is less than or equal to the probability density threshold, it is determined that the image to be detected has defects. In the case that the probability density value is greater than the probability density threshold, whether the image has defects can be further determined according to the distance between the image features of the image to be detected and the sample image features of the defect-free type and the sample image features of the defective type in the image feature library.
[0125] Compared with directly determining whether the image has defects by using the neural network model, the accuracy of the detection result of the processing piece defect detection method according to the embodiment of the present application is not affected by the accuracy of the neural network model. The Gaussian distribution characteristic of the sample image features of the defect-free type is used to detect whether the image has defects, i.e., whether the image has defects is detected in a statistical sense, which can improve the accuracy of the defect detection. In the case that the probability density value is greater than the probability density threshold, the first distance between the image features of the image to be detected and the sample image features of the defect-free type and the second distance between the image features of the image to be detected and the sample image features of the defective type are further calculated, and whether the image to be detected has defects can be determined according to the first distance and the second distance, which can avoid missing detection and further improve the accuracy of the defect detection.
[0126] Corresponding to the method embodiment, the embodiment of the present application also provides a defect detection device, as shown in Figure 5 The defect detection device 500 includes:
[0127] The image to be detected is obtained by the image to be detected acquisition module 510.
[0128] The image features of the image to be detected are obtained by the image feature extraction module 520 by using the pre-trained neural network model.
[0129] The sample image feature acquisition module 530 is configured to acquire sample image features from an image feature library; each sample image feature is obtained by inputting a sample image into a neural network model for feature extraction; and the sample image features include sample image features of a defect-free type.
[0130] The Gaussian distribution function generation module 540 is configured to generate a Gaussian distribution function according to the sample image features of the defect-free type.
[0131] The probability density value calculation module 550 is configured to calculate a probability density value of the image feature of the to-be-detected image in the Gaussian distribution function; the probability density value represents a probability that the to-be-detected image is a defect-free image.
[0132] The defect judgment module 560 is configured to judge whether the to-be-detected image has a defect according to the probability density value.
[0133] Optionally, the defect judgment module 560 is specifically configured to determine that the to-be-detected image has a defect when the probability density value is less than or equal to a probability density threshold; determine that the to-be-detected image does not have a defect when the probability density value is greater than the probability density threshold, or, when the probability density value is greater than the probability density threshold and the sample image features include sample image features of a defective type, judge whether the to-be-detected image has a defect according to the sample image features of the defective type.
[0134] Optionally, the defect judgment module 560 is specifically configured to judge whether the to-be-detected image has a defect according to the sample image features of the defective type by the following steps:
[0135] calculating a first distance between the image feature of the to-be-detected image and the sample image features of the defect-free type;
[0136] calculating a second distance between the image feature of the to-be-detected image and the sample image features of the defective type;
[0137] judging whether the to-be-detected image has a defect according to the first distance and the second distance.
[0138] Optionally, the Gaussian distribution function generation module 540 is specifically configured to obtain a mean μ of the sample image features of the defect-free type according to the sample image features of the defect-free type, and generate the following Gaussian distribution function:
[0139]
[0140] wherein ∑ is a covariance, T is a transpose of a matrix, x is an input variable image feature, p(x) is a probability that an image corresponding to the input variable image feature x is a defect-free image, and n represents a dimension of the sample image features.
[0141] Optionally, the defect judging module 560 is specifically configured to calculate the first distance between the image feature of the to-be-detected image and the sample image feature of the no-defect type by the following steps:
[0142] calculate the distance between the image feature of the to-be-detected image and the sample image feature of each no-defect type, and select the minimum distance from the obtained distances as the first distance; and calculate the second distance between the image feature of the to-be-detected image and the sample image feature of the defect type by the following steps:
[0143] calculate the distance between the image feature of the to-be-detected image and the sample image feature of each defect type, and select the minimum distance from the obtained distances as the second distance.
[0144] Optionally, the defect judging module 560 is specifically configured to judge whether the to-be-detected image has defects according to the first distance and the second distance by the following steps:
[0145] according to the following formula:
[0146]
[0147] obtain the confidence f of the to-be-detected image; wherein d1 is the first distance, and d2 is the second distance;
[0148] in the case that the confidence f is less than the confidence threshold, it is determined that the to-be-detected image has defects;
[0149] in the case that the confidence f is greater than or equal to the confidence threshold, it is determined that the to-be-detected image has no defects.
[0150] Optionally, the neural network model comprises an encoding module and a decoding module.
[0151] The defect detection device 500 further comprises:
[0152] a model training module configured to obtain a plurality of training images and an actual image segmentation result corresponding to each training image; encode each training image by the encoding module to obtain a training image feature; decode the training image feature by the decoding module to obtain a predicted image segmentation result; obtain a loss function value according to the predicted image segmentation result and the actual image segmentation result, and update the network parameters in the encoding module and the decoding module according to the loss function value to obtain the neural network model.
[0153] The specific details of each module or unit in the above device have been described in detail in the corresponding method, and therefore will not be repeated here.
[0154] It should be noted that although several modules or units for the device used to perform actions have been mentioned in the detailed description above, this division is not mandatory. In fact, according to the embodiments of this application, the features and functions of two or more modules or units described above can be embodied in one module or unit. Conversely, the features and functions of one module or unit described above can be further divided and embodied by multiple modules or units.
[0155] In this embodiment of the application, an electronic device is also provided, including: a processor; a memory for storing processor-executable instructions; wherein the processor is configured to execute the workpiece defect detection method described in this example embodiment.
[0156] Figure 6 This is a schematic diagram of the structure of an electronic device according to an embodiment of this application. It should be noted that... Figure 6 The electronic device 600 shown is merely an example and should not impose any limitation on the functionality and scope of use of the embodiments of this application.
[0157] like Figure 6 As shown, the electronic device 600 includes a central processing unit (CPU) 601, which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM) 602 or a program loaded from a storage section 608 into a random access memory (RAM) 603. The RAM 603 also stores various programs and data required for system operation. The CPU 601, ROM 602, and RAM 603 are interconnected via a bus 604. An input / output (I / O) interface 605 is also connected to the bus 604.
[0158] The following components are connected to I / O interface 605: an input section 606 including a keyboard, mouse, etc.; an output section 607 including a cathode ray tube (CRT), liquid crystal display (LCD), etc., and speakers, etc.; a storage section 608 including a hard disk, etc.; and a communication section 609 including a network interface card such as a local area network (LAN) card, modem, etc. The communication section 609 performs communication processing via a network such as the Internet. A drive 610 is also connected to I / O interface 605 as needed. A removable medium 611, such as a disk, optical disk, magneto-optical disk, semiconductor memory, etc., is installed on drive 610 as needed so that computer programs read from it can be installed into storage section 608 as needed.
[0159] In particular, according to embodiments of the present application, the processes described above with reference to the flowcharts can be implemented as a computer software program. For example, embodiments of the present application include a computer program product comprising a computer program carried on a computer readable medium, the computer program comprising program code for performing the methods illustrated by the flowcharts. In such embodiments, the computer program can be downloaded and installed from a network via the communication section 609, and / or installed from the removable media 611. When the computer program is executed by the central processing unit 601, various functions defined in the apparatus of the present application are performed.
[0160] In embodiments of the present application, there is also provided a computer readable storage medium having stored thereon a computer program, the computer program being executed by a processor to implement the above machining part defect detection method.
[0161] It should be noted that the computer readable storage medium shown in the present application may, for example, be, but is not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device or apparatus, or any suitable combination of the above. More specific examples of the computer readable storage medium can include, but are not limited to, an electrical connection having one or more wires, a portable computer diskette, a hard disk, a random access memory, a read-only memory, an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above. In the present application, the computer readable storage medium can be any tangible medium containing or storing a program that can be used by or in conjunction with an instruction execution system, device or apparatus. The program code contained on the computer readable storage medium can be transmitted in any suitable medium, including but not limited to wireless, wire, optical cable, radio frequency, etc., or any suitable combination of the above.
[0162] In embodiments of the present application, there is also provided a computer program product, which, when run on a computer, causes the computer to perform the above machining part defect detection method.
[0163] It has to be noted that, in the present document, relational terms are intended only to convey a possible relationship between elements or
[0164] The above description is merely that of the specific embodiments of the application and as such is not to be taken in a limiting sense. Various modifications and co nti n uations will be evident to those skilled in the art that do not depart from the spirit and scope of the application as defined by the appended claims. The specific embodiments presented, therefore, are not to be considered in a limiting sense, but are presented for purposes of illustration only in conformance with the above description. It is therefore contemplated to cover by the present application any and all modifications and variations that fall within the scope of the present application.
Claims
1. A method for detecting defects in machined parts, characterized in that, include: An image to be detected is acquired, and its features are extracted using a pre-trained neural network model to obtain the image features of the image to be detected; the neural network model is an image classification model or an image segmentation model. Sample image features are obtained from an image feature library; wherein each sample image feature is obtained by inputting the sample image into the neural network model for feature extraction; the sample image features include defect-free sample image features; Generate a Gaussian distribution function based on the features of the defect-free sample images; Calculate the probability density value of the image features of the image to be detected in the Gaussian distribution function; wherein the probability density value represents the probability that the image to be detected is a defect-free image; If the probability density value is less than or equal to the probability density threshold, it is determined that the image to be detected has a defect; If the probability density value is greater than the probability density threshold, it is determined that the image to be detected does not have defects, or... If the probability density value is greater than the probability density threshold, and the sample image features include sample image features with defects, then the presence of defects in the image to be detected is determined based on the sample image features with defects. The step of determining whether the image to be detected has defects based on the sample image features of the defect type includes: Calculate the first distance between the image features of the image to be detected and the image features of the sample image of the defect-free type; Calculate the second distance between the image features of the image to be detected and the image features of the sample image with defects; Based on the first distance and the second distance, determine whether the image to be detected has defects; The step of determining whether the image to be detected has defects based on the first distance and the second distance includes using the following formula: ; The confidence score f of the image to be detected is obtained; where d1 is the first distance and d2 is the second distance. If the confidence level f is less than the confidence threshold, it is determined that the image to be detected has a defect; If the confidence level f is greater than or equal to the confidence threshold, it is determined that the image to be detected does not have defects.
2. The method according to claim 1, characterized in that, The step of generating a Gaussian distribution function based on the features of the defect-free sample image includes: Based on the features of the defect-free sample images, the mean of the features of the defect-free sample images is obtained, and the following Gaussian distribution function is generated: ; Where S is the covariance, T is the transpose of the matrix, x is the input variable image feature, p(x) is the probability that the image corresponding to the input variable image feature x is a defect-free image, and n represents the dimension of the sample image feature.
3. The method according to claim 1, characterized in that, The calculation of the first distance between the image features of the image to be detected and the features of the sample image of the defect-free type includes: Calculate the distance between the image features of the image to be detected and the sample image features of each defect-free type, and select the smallest distance from the obtained distances as the first distance; The calculation of the second distance between the image features of the image to be detected and the sample image features of the defective type includes: Calculate the distance between the image features of the image to be detected and the sample image features of each defect type, and select the smallest distance from the obtained distances as the second distance.
4. The method according to claim 1, characterized in that, The neural network model includes: an encoding module and a decoding module; The training methods for the neural network model include: Obtain multiple training images and the actual image segmentation result corresponding to each training image; The training image features are obtained by encoding each training image through an encoding module. The training image features are decoded by the decoding module to obtain the predicted image segmentation result; The loss function value is obtained based on the predicted image segmentation result and the actual image segmentation result; The neural network model is obtained by updating the network parameters in the encoding and decoding modules using the loss function value.
5. A defect detection device for machined parts, characterized in that, The device includes: The image acquisition module is used to acquire the image to be detected. The image feature extraction module is used to extract features from the image to be detected using a pre-trained neural network model to obtain the image features of the image to be detected; the neural network model is an image classification model or an image segmentation model. The sample image feature acquisition module is used to acquire sample image features from an image feature library; wherein each sample image feature is obtained by inputting the sample image into the neural network model for feature extraction; the sample image features include defect-free sample image features; The Gaussian distribution function generation module is used to generate a Gaussian distribution function based on the features of the defect-free sample image. The probability density value calculation module is used to calculate the probability density value of the image features of the image to be detected in the Gaussian distribution function; wherein, the probability density value represents the probability that the image to be detected is a defect-free image; The defect determination module is used to determine that the image to be detected has a defect when the probability density value is less than or equal to the probability density threshold; to determine that the image to be detected does not have a defect when the probability density value is greater than the probability density threshold; or, when the probability density value is greater than the probability density threshold and the sample image features include sample image features with defect types, to determine whether the image to be detected has a defect based on the sample image features with defect types. Specifically, the defect determination module is used to determine whether the image to be detected has defects based on the features of the sample image of the defect type through the following steps: Calculate the first distance between the image features of the image to be detected and the image features of the sample image of the defect-free type; Calculate the second distance between the image features of the image to be detected and the image features of the sample image with defects; Based on the first distance and the second distance, determine whether the image to be detected has defects; The defect determination module is specifically used to determine whether the image to be detected has defects based on the first distance and the second distance through the following steps: According to the following formula: ; The confidence score f of the image to be detected is obtained; where d1 is the first distance and d2 is the second distance. If the confidence level f is less than the confidence threshold, it is determined that the image to be detected has a defect; If the confidence level f is greater than or equal to the confidence threshold, it is determined that the image to be detected does not have defects.
6. An electronic device, characterized in that, include: A processor for executing a computer program stored in a memory, wherein the computer program, when executed by the processor, implements the method of any one of claims 1-4.
7. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by a processor, it implements the method described in any one of claims 1-4.
Citation Information
Patent Citations
Contact net component defect detection method and device, electronic equipment and storage medium
CN114187441A
Image defect detection method, electronic equipment and storage medium
CN114943671A