Methods for establishing feature libraries, defect detection methods and devices in defect detection
By selecting feature vectors to establish a target feature library, the problem of low efficiency caused by redundant data in defect detection is solved, and the detection efficiency and model robustness are improved.
Patent Information
- Application Number
- CN202211717422.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-12-29
- Publication Date
- 2026-01-30
- Estimated Expiration
- 2042-12-29
AI Technical Summary
Existing technologies contain redundant data in defect detection feature libraries, resulting in low defect detection efficiency.
Initial feature vectors are extracted using a pre-trained first network model. The first network model is then fitted with a second network model to select feature vectors that meet the frequency criteria, thereby establishing a target feature library and reducing redundant data.
It improves the efficiency of defect detection, reduces the memory usage of the feature library, and enhances the robustness of the model.
Smart Images

Figure CN115908397B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of industrial defect detection technology, and more specifically, to a method for establishing a feature library, a defect detection method, and an apparatus for defect detection. Background Technology
[0002] With the increasing application of deep learning models in the field of industrial defect detection, various defects in industrial products can be detected by learning sample features through deep learning models.
[0003] In some industrial defect detection scenarios: because it is difficult to collect negative samples (images with defects) and easy to collect positive samples (images without defects), defect detection can be achieved by training only on positive samples and determining whether there are any abnormalities in the image under test by comparing the feature library formed by the trained feature vectors with the image under test.
[0004] However, the feature library trained by the above methods contains redundant data, which weakens the effectiveness of positive sample learning and leads to low efficiency in the corresponding defect detection. Summary of the Invention
[0005] To address the problem of redundant data in feature libraries in defect detection methods, which leads to low defect detection efficiency, this application provides a method for establishing a defect detection feature library, a defect detection method, and an apparatus.
[0006] The embodiments of this application are implemented as follows:
[0007] The first aspect of this application provides a method for establishing a feature library in defect detection, comprising:
[0008] The positive sample image data is processed through a pre-trained first network model to extract the first initial feature vector, and an initial feature library is established based on the first initial feature vector.
[0009] The second network model is triggered to fit the first network model. The second feature vector is extracted from the positive sample image data through the fitted second network model. Based on the degree of matching between the second feature vector and the corresponding first initial feature vector, the frequency of the first initial feature vector is determined. The second network model has the same structure as the first network model.
[0010] First candidate feature vectors are selected from the first initial feature vectors, and a target feature library is established based on the first candidate feature vectors. The first candidate feature vectors are the first initial feature vectors whose frequency is greater than the first degree or less than the second degree.
[0011] A second aspect of this application provides a defect detection method, including:
[0012] The third feature vector of the image to be detected is extracted using the first network model;
[0013] Determine the second target feature vector that has the smallest distance to the first position of each third feature vector, wherein the first position is the position of the pixel of the third feature vector in the image to be tested, and the second target feature vector is a feature vector in the target feature library, which is a feature library established by the method for establishing a feature library in defect detection according to the first aspect of the invention.
[0014] Based on the second and third target feature vectors, the anomaly score at the first position is determined.
[0015] Defects in the image to be detected are determined based on the anomaly score.
[0016] A third aspect of this application provides an apparatus for establishing a feature library in defect detection, comprising:
[0017] The initial feature library building module is used to extract the first initial feature vector from the positive sample image data through the pre-trained first network model, and to build the initial feature library based on the first initial feature vector.
[0018] The degree determination module is used to trigger the second network model to fit the first network model, extract the second feature vector from the positive sample image data through the fitted second network model, and determine the frequency degree corresponding to the first initial feature vector based on the matching degree between the second feature vector and the corresponding first initial feature vector. The second network model has the same structure as the first network model.
[0019] The target feature library establishment module is used to select a first candidate feature vector from the first initial feature vector and establish a target feature library based on the first candidate feature vector. The first candidate feature vector is the first initial feature vector whose frequency is greater than the first degree or less than the second degree.
[0020] A fourth aspect of this application provides a defect detection apparatus, comprising:
[0021] The feature extraction module is used to extract the third feature vector of the image to be detected through the first network model;
[0022] The feature determination module determines the second target feature vector that is closest to the first position of the third feature vector, wherein the first position is the position of the pixel of the third feature vector in the image to be tested, and the second target feature vector is a feature vector in the target feature library, which is a feature library established by the feature library establishment method in the defect detection of the first aspect of the invention.
[0023] The anomaly detection module determines the anomaly score at the first position based on the second and third target feature vectors.
[0024] The defect detection module identifies defects in the image to be detected based on anomaly scores.
[0025] The fifth aspect of this application provides a terminal device, including a memory and a processor. The memory stores a computer program, and the processor executes the computer program to implement the steps of the defect detection method of the second aspect of the invention.
[0026] A sixth aspect of this application provides a computer storage medium on which a computer program is stored. When the computer program is executed by a processor, the processor performs the steps of the defect detection method of the second aspect of the invention.
[0027] The beneficial effects of this application are as follows: In the method for establishing a feature library in defect detection, positive sample image data is processed through a pre-trained first network model to extract a first initial feature vector, and an initial feature library is established based on the first initial feature vector. A second network model is triggered to fit the first network model, and a second feature vector is extracted from the positive sample image data using the fitted second network model. Based on the degree of matching between the second feature vector and the corresponding first initial feature vector, the frequency level corresponding to the first initial feature vector is determined. The second network model has the same structure as the first network model. A first candidate feature vector is selected from the first initial feature vector, and a target feature library is established based on the first candidate feature vector. The first candidate feature vector is the first initial feature vector whose frequency level is greater than the first level or less than the second level, reducing redundant data in the feature library and improving the corresponding defect detection efficiency. Attached Figure Description
[0028] To more clearly illustrate the technical solutions in the embodiments of this application or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0029] Figure 1 This paper illustrates a flowchart of a method for establishing a feature library in defect detection, as provided in an embodiment of this application.
[0030] Figure 2 This illustration shows a flowchart of another method for establishing a feature library in defect detection according to an embodiment of this application;
[0031] Figure 3 A flowchart illustrating a defect detection method provided in an embodiment of this application is shown;
[0032] Figure 4 This illustration shows a flowchart of a process for determining defects in an image to be detected, according to an embodiment of this application.
[0033] Figure 5 A flowchart illustrating yet another defect detection method provided in an embodiment of this application is shown;
[0034] Figure 6 This illustration shows a schematic diagram of a feature library establishment device for defect detection provided in an embodiment of this application;
[0035] Figure 7 A schematic diagram of the structure of a defect detection device provided in an embodiment of this application is shown. Detailed Implementation
[0036] To make the objectives, implementation methods and advantages of this application clearer, the exemplary implementation methods of this application will be clearly and completely described below with reference to the accompanying drawings of the exemplary embodiments of this application. Obviously, the described exemplary embodiments are only some embodiments of this application, and not all embodiments.
[0037] It should be noted that the brief descriptions of terms in this application are only for the convenience of understanding the embodiments described below, and are not intended to limit the embodiments of this application. Unless otherwise stated, these terms should be understood in their ordinary and common meaning.
[0038] The terms "first," "second," "third," etc., used in the specification, claims, and accompanying drawings of this application are used to distinguish similar or related objects or entities, and do not necessarily imply a specific order or sequence, unless otherwise specified. It should be understood that such terms are interchangeable where appropriate.
[0039] The terms “comprising” and “having”, and any variations thereof, are intended to cover but not exclude inclusion, for example, a product or device that includes a range of components is not necessarily limited to all of the components that are clearly listed, but may include other components that are not clearly listed or that are inherent to such product or device.
[0040] In some industrial defect detection scenarios, it is difficult to collect negative samples (images with defects) and their quantity is small, making it difficult for deep learning models to train. On the other hand, it is easy to collect positive samples and their quantity is large. Therefore, defect detection can be achieved by training only on positive samples and determining whether there are any abnormalities in the image under test by comparing the feature library formed by the trained feature vectors with the image under test.
[0041] The feature library obtained by training in the above method contains redundant data, which makes the learning effectiveness of positive samples weak and results in low efficiency of corresponding defect detection.
[0042] To address the issue of excessive redundant data in the trained feature library, this application provides a method for establishing a feature library, a defect detection method, and an apparatus for defect detection. The method for establishing a feature library in defect detection involves: extracting a first initial feature vector from positive sample image data using a pre-trained first network model; establishing an initial feature library based on the first initial feature vector; triggering a second network model to fit the first network model; extracting a second feature vector from the positive sample image data using the fitted second network model; determining the frequency level of the first initial feature vector based on the matching degree between the second feature vector and the corresponding first initial feature vector; wherein the second network model has the same structure as the first network model; selecting a first candidate feature vector from the first initial feature vector; and establishing a target feature library based on the first candidate feature vector. The first candidate feature vector is the first initial feature vector with a frequency level greater than the first level or less than the second level, thereby reducing redundant data in the feature library and improving the corresponding defect detection efficiency.
[0043] The following describes in detail, with reference to the accompanying drawings, a method for establishing a feature library, a defect detection method, and an apparatus for defect detection according to an embodiment of this application.
[0044] Figure 1 This application provides a flowchart illustrating a method for establishing a feature library in defect detection, as illustrated in an embodiment of this application. Figure 1 As shown in the figure, this application provides a method for establishing a feature library in defect detection.
[0045] The method for establishing the feature library in this defect detection includes the following steps:
[0046] S110. Extract the first initial feature vector from the positive sample image data through the pre-trained first network model, and establish an initial feature library based on the first initial feature vector.
[0047] Positive sample image data refers to defect-free image data obtained in specific industrial defect detection scenarios.
[0048] The first network model that is pre-trained can be a Convolutional Neural Network (CNN).
[0049] In some embodiments, the first network model may be one of the following: ResNet, RegNet, EfficientNet, ShuffleNet, MobileNet, etc.
[0050] In some embodiments, the first network model may be a variant structure of the above system, such as the ResNet18 network in the ResNet residual network.
[0051] Since the scale and complexity of positive sample image data vary, different scales and sizes of first network models can be selected.
[0052] Positive sample image data is processed by a pre-trained first network model to extract positive sample features. Positive sample features represent the image features of positive sample image data and are a feature vector (i.e., the first initial feature vector). An initial feature library is established based on the first initial feature vector.
[0053] The initial feature library is constructed with n*w*h*d feature vectors, where n is the number of positive sample image data, w*h is the image spatial dimension of the initial feature library, and d is the length of the feature vector at each spatial location point.
[0054] In some embodiments, the required training data can be adjusted by downsampling. However, it should be noted that feature images downsampled at too small a factor lack high-level semantic features and are subject to greater interference; feature images downsampled at too large a factor lack spatial information and are not conducive to detecting detailed anomalies. For example, an 8x downsampling factor can be used to adjust the required training data.
[0055] For example, with 200 512*512 positive sample images, the lengths of the feature vectors sampled by the ResNet18 pre-trained model at downsampling rates of 8x, 16x, and 32x are 128, 256, and 512, respectively. If the length of the feature vector at each spatial location point is 128+256+512, and the data storage is 4 bytes, then the size of the initial feature library is 200*(512*512 / 8)*((128+256+512)*4), approximately 2.7G. At this point, the initial feature library contains redundant data, which consumes a lot of GPU memory and is not very efficient when running on the device.
[0056] S120. Trigger the second network model to fit the first network model. Extract the second feature vector from the positive sample image data using the fitted second network model. Determine the frequency level corresponding to the first initial feature vector based on the degree of matching between the second feature vector and the corresponding first initial feature vector.
[0057] The second network model has the same structure as the first network model. That is, the first network model can be a convolutional neural network, and the second network model can also be a convolutional neural network. For example, if the first network model is a ResNet18 network, the second network model can also be a ResNet18 network.
[0058] Triggering the second network model to fit the first network model means that the second network model only learns the extraction of positive sample image data by the first network model, and extracts the second feature vector from the positive sample image data through the fitted second network model.
[0059] The frequency level of the first initial feature vector is determined based on the degree of matching between the second feature vector and the corresponding first initial feature vector. The degree of matching is the frequency level of the second feature vector extracted by the second network model relative to the first initial feature vector extracted by the first network model. For normal samples, a high frequency level corresponds to a low score; for abnormal samples, a low frequency level corresponds to a high score.
[0060] In some embodiments, the first initial feature vector can be sorted by frequency according to the degree of matching between the second feature vector and the corresponding first initial feature vector.
[0061] In some embodiments, the first network model and the second network model can be the teacher network and student network in the STFPM (Student-Teacher Feature Pyramid Matching for Anomaly Detection) algorithm, wherein the teacher network is pre-trained and the student network and teacher network have the same structure.
[0062] The student network learns the distribution of positive sample image data by matching features with corresponding features in the teacher network. Multi-scale feature matching is used to enhance robustness. This hierarchical feature matching enables the student network to receive multi-level mixtures from the feature pyramid, thus allowing for defect detection of various sizes.
[0063] S130. Select a first candidate feature vector from the first initial feature vector, and establish a target feature library based on the first candidate feature vector. The first candidate feature vector is the first initial feature vector whose frequency is greater than the first degree or less than the second degree.
[0064] Based on the frequency ranking of the first initial feature vectors, the first initial feature vectors are filtered to select the first candidate feature vectors, and a target feature library is established based on the first candidate feature vectors.
[0065] The frequency order of the first initial feature vector is Gaussian. According to the principle of Gaussian distribution, the first initial feature vectors of high frequency and low frequency are retained, while the first initial feature vectors of intermediate frequency are redundant data.
[0066] It should be understood that a first candidate feature vector can be selected from a first initial feature vector through a first degree and a second degree; wherein, the first candidate feature vector may be a first initial feature vector with a frequency degree greater than the first degree or less than the second degree.
[0067] In some embodiments, a first candidate feature vector can be selected from the first initial feature vector by a preset screening ratio; the preset screening ratio may include a preset first screening ratio for high-frequency programs and a preset second screening ratio for low-frequency programs. For example, the preset screening ratio may be 10%.
[0068] The above process reduces the capacity of the initial feature library to the capacity of the target feature library, thereby improving the effectiveness of the target feature library and reducing the memory usage of the defect detection model corresponding to the target feature library.
[0069] Figure 2 This illustration shows a flowchart of another method for establishing a feature library in defect detection, as provided in an embodiment of this application. Figure 2 As shown, step 130, which involves selecting a first candidate feature vector from the first initial feature vector and establishing a target feature library based on the first candidate feature vector, may further include:
[0070] S131. Select the first candidate feature vector from the first initial feature vector.
[0071] The first candidate feature vector is the first initial feature vector whose frequency is greater than the first degree or less than the second degree.
[0072] S132. Perform clustering on the first candidate feature vectors to determine at least one vector set, in which the first candidate feature vectors included in each vector set belong to the same category; and select the first target feature vector from the vector set.
[0073] For each first candidate feature vector, there may be identical or similar data. By clustering, at least one vector set is determined. The vector set is determined according to the category of each first candidate feature vector. That is, for each vector set, the first candidate feature vectors contained therein belong to the same category.
[0074] Clustering can be used to select the second target feature vector from the aforementioned set of vectors. It should be understood that the first target feature vector can be equal to the first candidate feature vector, or it can be data that is close to the first candidate feature vector.
[0075] In some embodiments, clustering can be achieved by sampling Coresets (key datasets, core sets). Extracting Coresets and then clustering can reduce the amount of computation and may also mitigate the impact of outliers, thereby making the model more robust.
[0076] S133. Establish a target feature library based on the first target feature vector.
[0077] Clustering can further reduce the size of the target feature library, improve its effectiveness, and reduce the memory usage of the defect detection model corresponding to the target feature library.
[0078] This application provides a method for establishing a feature library in defect detection. Positive sample image data is processed by a pre-trained first network model to extract a first initial feature vector, and an initial feature library is established based on the first initial feature vector. A second network model is triggered to fit the first network model, and a second feature vector is extracted from the positive sample image data using the fitted second network model. Based on the degree of matching between the second feature vector and the corresponding first initial feature vector, the frequency level corresponding to the first initial feature vector is determined. The second network model has the same structure as the first network model. A first candidate feature vector is selected from the first initial feature vector, and a target feature library is established based on the first candidate feature vector. The first candidate feature vector is the first initial feature vector whose frequency level is greater than the first level or less than the second level, reducing redundant data in the feature library and improving the corresponding defect detection efficiency.
[0079] Figure 3 This application provides a schematic flowchart of a defect detection method according to an embodiment of the present application. Figure 3 As shown, this application provides a defect detection method.
[0080] The defect detection method includes the following steps:
[0081] S210. Extract the third feature vector of the image to be detected through the first network model.
[0082] Acquire the image of the object to be inspected, which requires defect detection. The image can be obtained by acquiring the target object through a vision inspection device.
[0083] The image to be detected is passed through a first network model to extract the third feature vector of the image to be detected. The first network model is a pre-trained model. The first network model can be a convolutional neural network, such as the ResNet18 network in the ResNet residual network.
[0084] Each third feature vector corresponds to a position in the image to be detected.
[0085] In some embodiments, the third feature vector of the image to be detected is extracted through the first network model, and the length of the third feature vector can also be extracted.
[0086] S220. Determine the second target feature vector that has the smallest distance to the first position of each third feature vector, where the first position is the position of the pixel of the third feature vector in the image to be tested, and the second target feature vector is the feature vector in the target feature library.
[0087] It should be understood that by traversing the third feature vectors at each first position in the image to be detected, the second target feature vector with the smallest distance from the third feature vector can be found in the target feature library.
[0088] Among them, the target feature library is obtained through the above. Figure 1 , Figure 2 The feature library established by the method described in the defect detection is a feature library after removing redundant data. Therefore, in step 220, when determining the second target feature vector that is the smallest distance from the first position of each third feature vector, the amount of data of the second target feature vector to be compared is small, and the effectiveness of the target feature library is improved.
[0089] In some embodiments, the distance between the third feature vector and the second target feature vector can be determined by Euclidean distance calculation.
[0090] S230. Determine the anomaly score at the first position based on the second target feature vector and the third feature vector.
[0091] The anomaly score at the first position can be determined by calculating the third feature vector corresponding to the first position and the second target feature vector that is closest to the third feature vector.
[0092] In some embodiments, the outlier score at the first position is calculated using Euler's formula.
[0093] In some embodiments, the outlier score at the first position is calculated using the following formula:
[0094] S = ||xx n ||
[0095] In the formula, S is the anomaly score at the first position, and x is the third feature vector at the first position; x n This is the feature vector of the second target.
[0096] S240. Based on the anomaly score, determine the defects in the image to be detected.
[0097] Based on the anomaly score at each first position, defects in the image to be detected are determined, including the location of the defects.
[0098] Figure 4 This application provides a flowchart illustrating a process for determining defects in an image to be detected, as illustrated in an embodiment of this application. Figure 4As shown, step 240 includes the following steps:
[0099] S241. Based on the anomaly scores at each first position, determine the initial anomaly score map corresponding to the image to be detected.
[0100] It should be understood that the initial anomaly score map is composed of the anomaly scores at each first position, and the anomaly scores at each position of the initial anomaly score map correspond one-to-one with each pixel of the image to be detected. The initial anomaly score map and the image to be detected are the same size.
[0101] S242. Normalize the initial anomaly score map to determine the target anomaly score map. The target anomaly score map represents the anomaly probability score of each first position in the image to be detected.
[0102] The initial anomaly score map can be normalized to determine the normalized target anomaly score map. The data in the target anomaly score map are not the anomaly scores of each first position, but represent the anomaly probability scores of each first position in the image to be detected.
[0103] In some embodiments, the initial anomaly score map can be normalized to a grayscale space or a color space. That is, the normalized target anomaly score map can be a grayscale image or a color image.
[0104] S243. If the abnormal probability score is greater than the preset abnormal threshold, it is determined to be a defect in the image to be detected, and the defect is located at the corresponding first position.
[0105] The abnormal probability scores in the target abnormality score map are determined to be abnormal by using a preset threshold. If the abnormal probability score is greater than the preset abnormal threshold, the corresponding first position is determined to be a defect in the image to be detected. If the abnormal probability score is not greater than the preset abnormal threshold, the corresponding first position is determined to be a non-defect in the image to be detected.
[0106] At the same time, the position of the anomaly probability score can determine the location of the defect in the image to be detected.
[0107] Figure 5 The diagram illustrates a flowchart of yet another defect detection method provided in an embodiment of this application. Figure 5 As shown, this application provides a defect detection method, if Figure 3 In step 210, the image to be detected is the initial detection image downsampled by a preset downsampling factor. The corresponding step 230, based on the anomaly score, determines the defects in the image to be detected, which also requires upsampling the response data. The defect detection method includes the following steps:
[0108] S310. Acquire the initial detection image and downsample the initial detection image according to the preset downsampling factor to determine the image to be detected.
[0109] The initial detection image can be obtained by acquiring the target object through a visual inspection device. The obtained initial detection image is downsampled according to a preset downsampling factor to determine the image to be detected.
[0110] S320. Extract the third feature vector of the image to be detected through the first network model.
[0111] The image to be detected is passed through a first network model to extract the third feature vector of the image to be detected. The first network model is a pre-trained model. The first network model can be a convolutional neural network, such as the ResNet18 network in the ResNet residual network.
[0112] Each third feature vector corresponds to a position in the image to be detected.
[0113] S330. Determine the second target feature vector that has the smallest distance from the first position of each third feature vector, where the first position is the position of the pixel of the third feature vector in the image to be detected, and the second target feature vector is the feature vector in the target feature library.
[0114] Among them, the target feature library is obtained through the above. Figure 1 , Figure 2 The feature library established by the method described in the defect detection is a feature library after removing redundant data. Therefore, in step 220, when determining the second target feature vector that is the smallest distance from the first position of each third feature vector, the amount of data of the second target feature vector to be compared is small, and the effectiveness of the target feature library is improved.
[0115] S340. Determine the anomaly score at the first position based on the second target feature vector and the third feature vector.
[0116] The anomaly score at the first position can be determined by calculating the third feature vector corresponding to the first position and the second target feature vector that is closest to the third feature vector.
[0117] In some embodiments, the outlier score at the first position is calculated using Euler's formula.
[0118] In some embodiments, the outlier score at the first position is calculated using the following formula:
[0119] S = ||xx n ||
[0120] In the formula, S is the anomaly score at the first position, and x is the third feature vector at the first position; x n This is the feature vector of the second target.
[0121] S350. Based on the anomaly scores at each first position, determine the initial anomaly score map corresponding to the image to be detected.
[0122] The initial anomaly score map is composed of the anomaly scores at each first position, and the anomaly scores at each position of the initial anomaly score map correspond one-to-one with each pixel of the image to be detected. The initial anomaly score map and the image to be detected are the same size.
[0123] S360. Based on the upsampling factor corresponding to the preset downsampling factor, upsample the initial anomaly score map to determine the candidate anomaly score map.
[0124] The initial anomaly score map is upsampled by an upsampling factor corresponding to a preset downsampling factor to determine the candidate anomaly score map.
[0125] S370. Normalize the candidate anomaly score maps to determine the target anomaly score map. The target anomaly score map represents the anomaly probability score of each second position in the initial detection image.
[0126] The initial anomaly score map can be normalized to grayscale or color space to determine the normalized target anomaly score map. The data in the target anomaly score map are not the anomaly scores of each first position, but represent the anomaly probability scores of each first position in the image to be detected.
[0127] S380. If the abnormal probability score is greater than the preset abnormal threshold, the defect in the initial detection image is determined, and the defect is located at the corresponding second position.
[0128] The abnormal probability scores in the target abnormality score map are determined to be abnormal by using a preset threshold. If the abnormal probability score is greater than the preset abnormal threshold, the corresponding first position is determined to be a defect in the image to be detected. If the abnormal probability score is not greater than the preset abnormal threshold, the corresponding first position is determined to be a non-defect in the image to be detected.
[0129] This application provides a defect detection method. It extracts a third feature vector from an image to be detected using a first network model; determines a second target feature vector that has the smallest distance to a first position of each third feature vector, where the first position is the pixel position of the third feature vector in the image to be detected, and the second target feature vector is a feature vector in a target feature library. The target feature library is a feature library established using a defect detection feature library establishment method (a feature library after removing redundant data); determines anomaly scores at the first positions based on the second target feature vector and the third feature vector; and determines defects in the image to be detected based on the anomaly scores. This reduces redundant data in the feature library and improves the corresponding defect detection efficiency.
[0130] Figure 6 This illustration shows a schematic diagram of a feature library creation device for defect detection provided in an embodiment of this application. Figure 6 As shown, the feature library establishment device 600 for defect detection includes an initial feature library establishment module 610, a severity determination module 620, and a target feature library establishment module 630, wherein:
[0131] The initial feature library building module is used to extract the first initial feature vector from the positive sample image data through the pre-trained first network model, and to build the initial feature library based on the first initial feature vector.
[0132] The degree determination module is used to trigger the second network model to fit the first network model, extract the second feature vector from the positive sample image data through the fitted second network model, and determine the frequency degree corresponding to the first initial feature vector based on the matching degree between the second feature vector and the corresponding first initial feature vector. The second network model has the same structure as the first network model.
[0133] The target feature library establishment module is used to select a first candidate feature vector from the first initial feature vector and establish a target feature library based on the first candidate feature vector. The first candidate feature vector is the first initial feature vector whose frequency is greater than the first degree or less than the second degree.
[0134] In some embodiments, the target feature library establishment module further includes a clustering unit and an establishment unit. The clustering unit is used to perform clustering on the first candidate feature vectors to determine at least one vector set, wherein the first candidate feature vectors included in each vector set belong to the same category; and is also used to select a first target feature vector from the vector set. The establishment unit is used to establish a target feature library based on the first target feature vector.
[0135] The feature library establishment device for defect detection provided in this application includes an initial feature library establishment module, a degree determination module, and a target feature library establishment module. Positive sample image data is processed through a pre-trained first network model to extract a first initial feature vector, and an initial feature library is established based on the first initial feature vector. A second network model is triggered to fit the first network model, and a second feature vector is extracted from the positive sample image data using the fitted second network model. Based on the degree of matching between the second feature vector and the corresponding first initial feature vector, the frequency degree corresponding to the first initial feature vector is determined. The second network model has the same structure as the first network model. A first candidate feature vector is selected from the first initial feature vector, and a target feature library is established based on the first candidate feature vector. The first candidate feature vector is the first initial feature vector whose frequency degree is greater than the first degree or less than the second degree, reducing redundant data in the feature library and improving the corresponding defect detection efficiency.
[0136] Figure 7 This paper shows a schematic diagram of the structure of a defect detection device provided in an embodiment of this application, as shown below. Figure 7As shown, the defect detection device 700 includes a feature extraction module 710, a feature determination module 720, an anomaly determination module 730, and a defect detection module 740, wherein:
[0137] The feature extraction module is used to extract the third feature vector of the image to be detected through the first network model;
[0138] The feature determination module determines the second target feature vector that is closest to the first position of the third feature vector. The first position is the position of the pixel of the third feature vector in the image to be tested. The second target feature vector is a feature vector in the target feature library. The target feature library is a feature library established by the feature library establishment method in the feature library establishment device in the defect detection in the figure.
[0139] The anomaly detection module determines the anomaly score at the first position based on the second and third target feature vectors.
[0140] The defect detection module identifies defects in the image to be detected based on anomaly scores.
[0141] The implementation principle and technical effects are similar to those of the above-described method embodiments, and will not be repeated here.
[0142] The defect detection device provided in this application includes a feature extraction module, a feature determination module, an anomaly determination module, and a defect detection module. It extracts a third feature vector from the image to be detected using a first network model; determines a second target feature vector that has the smallest distance to a first position of each of the third feature vectors, where the first position is the pixel position of the third feature vector in the image to be detected, and the second target feature vector is a feature vector in a target feature library. The target feature library is a feature library established using a defect detection feature library establishment method (a feature library after removing redundant data); and determines the anomaly score at the first position based on the second target feature vector and the third feature vector. Based on the anomaly score, it determines the defect in the image to be detected, reducing redundant data in the feature library and improving the corresponding defect detection efficiency.
[0143] This application also provides a terminal device, including a memory and a processor. The memory stores a computer program. The processor executes the computer program to implement the above-mentioned defect detection method. The implementation principle and technical effect are similar to those of the above-mentioned method embodiments, and will not be repeated here.
[0144] This application also provides a computer storage medium on which a computer program is stored. When the computer program is executed by a processor, the processor performs the above-described defect detection method. The implementation principle and technical effect are similar to those of the above-described method embodiments, and will not be repeated here.
[0145] The following paragraphs will compare and list the Chinese terms used in this application specification and their corresponding English terms to facilitate reading and understanding.
[0146] For ease of explanation, the above description has been provided in conjunction with specific embodiments. However, the discussion in some embodiments above is not intended to be exhaustive or to limit the embodiments to the specific forms disclosed above. Various modifications and variations can be obtained based on the above teachings. The selection and description of the above embodiments are for the purpose of better explaining the principles and practical applications, thereby enabling those skilled in the art to better utilize the embodiments and various different variations of the embodiments suitable for specific application considerations.
Claims
1. A method of establishing a feature library in defect detection, characterized by, The method comprises the steps of: extracting a first initial feature vector from positive sample image data through a pre-trained first network model, and establishing an initial feature library according to the first initial feature vector; triggering a second network model to fit the first network model, extracting a second feature vector from the positive sample image data through the fitted second network model, and determining the frequency degree corresponding to the first initial feature vector based on the matching degree of the second feature vector and the corresponding first initial feature vector, wherein the second network model has the same structure as the first network model; screening a first candidate feature vector from the first initial feature vector, and establishing a target feature library according to the first candidate feature vector, wherein the first candidate feature vector is a first initial feature vector with a frequency degree greater than a first degree or less than a second degree.
2. The method of claim 1, wherein, The method of establishing a target feature library according to the first candidate feature vector comprises the steps of: performing clustering on the first candidate feature vector to determine at least one vector set, wherein the first candidate feature vectors included in each vector set belong to the same category; selecting a first target feature vector from the vector set; establishing a target feature library according to the first target feature vector.
3. A defect detection method characterized by, The method comprises the steps of: extracting a third feature vector of a to-be-detected image through a first network model; determining a second target feature vector with the minimum first position distance from each third feature vector, wherein the first position is the position of the third feature vector in the to-be-detected image, the second target feature vector is a feature vector in a target feature library, and the target feature library is a feature library established by the method of establishing a feature library in defect detection according to claim 1 or 2; determining an abnormal score of the first position according to the second target feature vector and the third feature vector, determining a defect of the to-be-detected image based on the abnormal score.
4. The defect detection method according to claim 3, characterized by, The abnormal score of the first position is obtained through Euler formula.
5. The defect detection method according to claim 3, wherein The method of determining a defect of the to-be-detected image based on the abnormal score comprises the steps of: determining an initial abnormal score map corresponding to the to-be-detected image based on the abnormal scores of the first positions; normalizing the initial abnormal score map to determine a target abnormal score map, wherein the target abnormal score map represents the abnormal probability scores of the first positions in the to-be-detected image; if the abnormal probability score is greater than a preset abnormal threshold, determining a defect of the to-be-detected image, wherein the defect is located at the corresponding first position.
6. An apparatus for establishing a feature library in defect detection, characterized by comprising: The method comprises the steps of: an initial feature library establishment module for extracting a first initial feature vector from positive sample image data through a pre-trained first network model, and establishing an initial feature library according to the first initial feature vector; a degree determination module for triggering a second network model to fit the first network model, extracting a second feature vector from the positive sample image data through the fitted second network model, and determining the frequency degree corresponding to the first initial feature vector based on the matching degree of the second feature vector and the corresponding first initial feature vector, wherein the second network model has the same structure as the first network model; The target feature library establishing module is configured to screen a first candidate feature vector from the first initial feature vector, and establish a target feature library according to the first candidate feature vector, the first candidate feature vector being a first initial feature vector with a frequency degree greater than a first degree or less than a second degree.
7. A defect detection apparatus characterized by comprising: The method comprises: The feature extraction module is configured to extract a third feature vector of the image to be detected by using the first network model. The feature determination module is configured to determine a second target feature vector with a minimum distance from a first position of the third feature vector, wherein the first position is a position of a pixel in the image to be detected, and the second target feature vector is a feature vector in a target feature library established by the method for establishing a feature library in defect detection according to claim 1 or 2. The anomaly determination module is configured to determine an anomaly score of the first position according to the second target feature vector and the third feature vector. The defect detection module is configured to determine a defect of the image to be detected based on the anomaly score. 8.A terminal device, comprising a memory and a processor, the memory storing a computer program, characterized in that, The processor executes the computer program to implement the steps of the defect detection method according to any one of claims 3 to 5.
9. A computer storage medium, characterized in that The computer readable storage medium stores a computer program, and the computer program is executed by the processor to make the processor execute the steps of the defect detection method according to any one of claims 3 to 5.
Citation Information
Patent Citations
Defect detection algorithm based on deep learning
CN113379689A
Unsupervised defect detection method based on deep learning feature correlation
CN114862772A