An artificial intelligence-based method and system for detecting bottle cap defects

Through the bottle cap detection method based on EfficientNetV1 and hybrid Gaussian discrimination module, the problem of difficulty in obtaining samples and poor generalization in bottle cap defect detection is solved, and efficient and low-cost identification of various abnormal forms is achieved.

CN118657974BActive Publication Date: 2025-08-05BEIJING ONE CODE TECH CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202410548544.5
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-05-06
Publication Date
2025-08-05
Estimated Expiration
2044-05-06

AI Technical Summary

Technical Problem

In the prior art, bottle cap defect detection requires a large number of abnormal samples, which is costly to obtain, and traditional methods are poorly generalized, making it difficult to effectively identify small target defects.

Method used

Using the bottle cap detection method based on artificial intelligence, the EfficientNetV1 model is used for hierarchical feature extraction, combined with a hybrid Gaussian discrimination module and a robust covariance determinant method, bottle cap abnormal detection is achieved through normal sample training, reducing the error detection rate.

Benefits of technology

No abnormal sample annotation is required, which reduces labor and time costs, improves model generalization capabilities, reduces missed and missed detection, and can identify multiple abnormal patterns.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118657974B_ABST
    Figure CN118657974B_ABST
Patent Text Reader

Abstract

The present invention proposes an artificial intelligence-based bottle cap defect detection method and system. The purpose is to perform training without the need for abnormal data, achieve high generalization performance using only normal samples, fully learn the feature representation of positive samples, significantly reduce the probability of missed detection and false detection, and reduce the waste of manpower and material resources. First, the EfficientNetV1 model is used as a pre-training network, and the convolutional layer features are extracted as network input. A hierarchical feature extractor is designed, and the representation ability of each layer of the convolutional neural network is used to model the Gaussian space. In the feature learning stage, block processing is adopted, and a mixed Gaussian discriminant module is proposed. The Gaussian mixture model strategy is integrated to perform pixel-by-pixel probability density estimation. A weight distribution mechanism is designed to emphasize the role of low-frequency features in the Gaussian space. In the inference stage, a minimum Mahalanobis distance calculation method based on robust covariance determinant estimation is developed and applied to the MMAHS module to realize bottle cap anomaly detection.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to an artificial intelligence-based bottle cap defect detection method and system, and relates to the field of industrial product manufacturing detection. Background Art

[0002] The industrial manufacturing sector places great importance on product quality compliance. Every component in the production process is crucial. Problems at any stage can lead to substandard product quality, impacting product usability. This is particularly true in bottle cap manufacturing, where defects such as scratches, missing pieces, and stains can directly impact product quality and sales, even leading to food safety incidents and unforeseen consequences. Traditional image processing algorithms are slow to detect defects, require customized algorithms for each defect, are complex to operate, have poor generalizability, and rely on specialized personnel for detection, which can be subjective.

[0003] Supervised deep learning methods for bottle cap defect detection require a large number of abnormal defect samples. However, supervised learning presents several challenges. First, defect samples are scarce and expensive to obtain on actual production lines. Manually generated defect samples are often required, but they cannot fully replicate the characteristics of real defect samples, resulting in inadequate network model learning during training. This leads to low model recognition accuracy when presented with image samples not previously learned in the training set. Second, supervised learning requires that all abnormal samples be labeled before network training. In the case of bottle cap anomaly detection, the number of defect samples often reaches tens of thousands, and manual labeling is prone to errors, resulting in low efficiency and time-consuming processing. Unsupervised anomaly detection models, which have emerged in recent years, effectively circumvent the tedious manual labeling process. However, the distribution of normal samples on production lines is highly variable, and existing models are unable to fully learn the characteristic distribution relationships. This results in a large number of false positives and poor detection rates for small defects. Consequently, unsupervised anomaly detection models have not been widely used in industrial bottle cap anomaly detection scenarios. Summary of the Invention

[0004] The purpose of the present invention is to overcome the problems in the prior art, such as the small number of defective samples, high acquisition cost, and low model recognition accuracy, and to provide a bottle cap detection method and system based on artificial intelligence:

[0005] The object of the present invention is achieved through the following technical solutions:

[0006] A bottle cap detection method based on artificial intelligence includes the following steps:

[0007] S1. Take images of bottle caps in the production plant, build a bottle cap dataset, and perform corresponding preprocessing on the dataset;

[0008] S2. Input the preprocessed and enhanced normal image into the MGAD network model to obtain the learned feature distribution of positive samples. The MGAD model includes: using a hierarchical feature extractor to extract the final convolutional layer features of the 3rd, 4th, and 5th modules of the pre-trained network EfficientNetV1 and inputting them into the distribution learning stage; integrating the Gaussian mixture model (GMM) strategy into the mixed Gaussian discriminant module to perform pixel-by-pixel probability density estimation, designing a weight distribution mechanism to assign the same proportion of extraction probability to different categories of feature distributions, fully considering the morphological appearance of various normal samples; introducing a robust covariance determinant (MCD) method to calculate the Gaussian distribution of the preserved positive samples, and implementing bottle cap anomaly detection in the inference calculation using the minimum robust Mahalanobis distance calculation method;

[0009] S3. Input the image to be detected into the bottle cap anomaly detection model MGAD to obtain an anomaly segmentation map of the relevant image.

[0010] Furthermore, in the step S1, the data set is subjected to a corresponding preprocessing method, and the image preprocessing method includes:

[0011] The image is corrected for the bottle cap posture according to the bottle cap LOGO area; the corrected bottle cap image is cropped in the bottle cap area through template matching.

[0012] Furthermore, the specific steps of correcting the bottle cap posture of the image according to the bottle cap LOGO area are as follows:

[0013] Randomly select an image from the bottle cap dataset and frame the LOGO area of the bottle cap to obtain the shape features of the bottle cap. After selecting the LOGO area, use the template matching algorithm to match the LOGO area with the entire image to be processed to find the area that is most similar to the template. In the template matching process, the algorithm used is:

[0014]

[0015] in, and are the pixel values of the template area and the image area respectively; the rigid transformation is described by the combination of rotation matrix and translation vector to correct the posture of the bottle cap image; first calculate the difference between the shape model and the image center of gravity, and determine the translation vector :

[0016]

[0017] in, and Represent the center of gravity of the shape model, and Represents the center of gravity of the image; the rotation matrix is obtained by calculating the difference between the angle of the shape model and the angle of the image :

[0018]

[0019] in, is the angular difference between the shape model and the image;

[0020] Finally, by combining the translation vector and the rotation matrix, we get the complete rigid transformation parameters relative to the image:

[0021]

[0022] Through this process, the image is accurately rotated, so that the image is accurately adjusted and positioned according to the position and angle information of the shape model while maintaining its shape and content.

[0023] In this way, the rotation and translation transformations are completed for each image according to the above operations to achieve the alignment of the bottle cap LOGO.

[0024] Furthermore, the bottle cap area of the rectified bottle cap image is cropped through template matching. Specifically, based on the normalized cross correlation (NCC) template matching principle, a template image is first selected from the bottle cap dataset, and two circular contours are selected along the outer and inner sides of the bottle cap in the image. The circular contour at the middle intersection is deducted as a matching template, and the local features of the template image are extracted and the pixel value of each feature point is calculated to create an NCC model; in the template matching process, the rectified bottle cap image is matched with the created NCC model; specifically, the NCC matching operation is performed on the rectified image, and the similarity between the image and the template is calculated at each position. This similarity is measured by comparing the correlation between the pixel values of the template image and the image to be matched at each position; the NCC algorithm aligns the template image and the image to be matched, compares them at different positions, and then finds the position where the correlation is maximized as the best matching position; for a given template image and the image to be matched , the NCC matching operation calculation formula is:

[0025]

[0026] in, represents the pixel value of the template image, Indicates that the image to be matched is at position The pixel value at and Represent the average pixel values of the template image and the image to be matched, The larger the value of , the more similar the two images are;

[0027] By performing NCC-based template matching, the position most similar to the template can be accurately found in the rectified bottle cap image, thereby achieving precise positioning of the bottle cap area; finally, based on the matching results, the bottle cap area can be cropped to complete the area extraction operation of the bottle cap image.

[0028] Furthermore, the preprocessed and enhanced normal image is input into the MGAD network model to obtain the learned positive sample feature distribution and calculate the anomaly score, including:

[0029] The preprocessed image is input into the hierarchical feature extractor, and three middle-level convolutional feature maps are selected. 、 、 Combined input hierarchical feature concatenation module (Hierarchy Feature Concatenation, ) becomes the embedding vector :

[0030]

[0031] in, It is a hierarchical feature concatenation module, which operates through a sliding window Preprocess the feature map to ensure consistent dimensions; The operation algorithm is:

[0032]

[0033] described Operation pair feature map Resampling and region extraction are performed to achieve scale and dimension consistency; the processed feature maps are connected in series Forming embedding vectors , the algorithm is:

[0034]

[0035] Among them, each For the resized and normalized feature maps, the concatenation operation generates a comprehensive feature representation by stacking these feature maps; the feature map set obtained by the pre-trained neural network It constitutes a multi-level feature representation of the input image from local detail structure information to global semantic structure.

[0036] Furthermore, the Gaussian mixture model (GMM) strategy is integrated into the mixture Gaussian discriminant module (MGD) to perform pixel-by-pixel probability density estimation, and the feature set extracted from N training images in the c-th channel at a specific position (i, j) of the image is The analysis is performed assuming that it follows a mixture distribution composed of several single Gaussian distributions;

[0037] With Group distribution , represents the different distributions of the current features; among them, represents the mth distribution, whose probability distribution is given by the following formula:

[0038]

[0039] in, represents the probability that the mth Gaussian distribution is selected, represents the probability density function of the mth Gaussian distribution, and are the mean vector and covariance matrix of the distribution respectively. The entire GMM is expressed as A linear combination of single Gaussian distributions, namely:

[0040]

[0041] in, Represents the probability distribution of GMM;

[0042] If there is a set of feature data , the goal is to construct the likelihood function L, which represents the probability of the observed data occurring under the current distribution; specifically, the likelihood function is constructed as follows:

[0043]

[0044] Calculate the posterior probability to get the likelihood that each point comes from each Gaussian distribution for:

[0045]

[0046] Under the premise of maximum likelihood function, by Taking the derivative and setting it equal to 0, we get for:

[0047]

[0048] For variables Derivative, using the Lagrange method to find the maximum formula through the constraints is:

[0049]

[0050] According to the large value, we can get The algorithm is:

[0051]

[0052] By the variables Taking the derivative and setting it equal to 0, we get for:

[0053]

[0054] Introducing boundary thresholds , the auxiliary GMM algorithm will not misclassify a single Gaussian distribution as a mixed Gaussian distribution, assuming is a set of k means, judging for all and , whether it satisfies:

[0055]

[0056] in: Represent the elements in the set S respectively, Represents the absolute difference between two elements, that is, their distance. and When the difference between When established, this paper believes that the two means represent two independent Gaussian distributions in the data, and the algorithm is:

[0057]

[0058]

[0059] On the contrary, if the above formula is satisfied, it means that the two means represent a single Gaussian distribution; in this case, the one with the larger weight is selected. The Gaussian distribution of the position The representatives are:

[0060]

[0061] Shared Satisfy on the channel Group mixture Gaussian distribution, setting a distribution number threshold ,like , then the feature of the pixel at (i, j) is a mixed Gaussian distribution.

[0062] Furthermore, in the core set selection stage, the feature set filtered by MGD Used in the MCD method; it is necessary to find a subset ,Depend on The sample consists of a proportion of , so that its covariance determinant is Minimum:

[0063]

[0064] Among them, the sample proportion parameter Decided from The proportion of samples selected from the core set ;

[0065] In the robust covariance estimation stage, calculate The sample mean on and covariance matrix , the estimation reflects the statistical characteristics of the selected subset and is used for the subsequent calculation of the anomaly score. The algorithm is:

[0066]

[0067]

[0068] Furthermore, when calculating the covariance matrix When , a regularization term I (identity matrix) and regularization parameter Ensure that it is full rank and reversible;

[0069] Based on robust feature set , calculate the Mahalanobis distance to measure the feature points of the test sample and normal distribution The distance between them, robust Mahalanobis distance Calculated as:

[0070]

[0071] At each pixel (i, j), if there is Heavy Gaussian distribution, calculation Subrobust Mahalanobis distance, defining the minimum distance as the anomaly score :

[0072]

[0073] Then normalize the Mahalanobis distance to the interval [0,255], the algorithm is:

[0074]

[0075] Finally, the anomaly score of each pixel in the test image is calculated to determine the anomaly location.

[0076] In some embodiments, a method performed by a computer system is disclosed for implementing one or more functions.

[0077] According to some embodiments, a computing system includes a processor and a memory storing instructions that, when executed, cause the one or more processors to perform the methods described herein. According to some embodiments, an electronic device includes one or more processors and a memory storing one or more programs; the one or more programs are configured to be executed by the one or more processors, and the one or more programs include instructions for performing or causing the operations of any of the methods described herein to be performed.

[0078] The beneficial effects of the present invention are:

[0079] 1. During training, only normal images are needed without collecting abnormal images. Pixel-level annotation of training samples is not required, which reduces manpower and time costs. It can identify multiple abnormal forms and enhance the generalization ability of the model.

[0080] 2. We designed a hierarchical feature extractor, using the EfficientNetV1 model as a pre-trained network. We extracted features from the 3rd, 4th, and 5th convolutional layers as network inputs. We leveraged the representational capabilities of each layer of the convolutional neural network to model Gaussian space, fully understanding image semantic information and reducing missed detection of small defects.

[0081] 3. In the feature learning stage, block processing is adopted, a mixed Gaussian discriminant module is proposed, and the Gaussian mixture model (GMM) strategy is integrated to perform pixel-by-pixel probability density estimation. A weight distribution mechanism is designed to emphasize the role of low-frequency features in the Gaussian space, thereby enhancing the model's ability to learn the multimodal features of normal samples and effectively reducing the probability of false detection. BRIEF DESCRIPTION OF THE DRAWINGS

[0082] Figure 1 The rotation positioning original image based on shape template matching provided by the embodiment of the present invention;

[0083] Figure 2 A schematic diagram of a template based on shape template matching provided in an embodiment of the present invention;

[0084] Figure 3 The target original image based on shape template matching provided by the embodiment of the present invention;

[0085] Figure 4 A schematic diagram of a target after rotation based on shape template matching provided by an embodiment of the present invention;

[0086] Figure 5 A schematic diagram of a bottle cap positioning template based on NCC template matching provided in an embodiment of the present invention;

[0087] Figure 6A schematic diagram of the bottle cap positioning target after positioning based on NCC template matching provided by an embodiment of the present invention;

[0088] Figure 7 A framework diagram of the artificial intelligence-based anomaly detection model MGAD provided in an embodiment of the present invention;

[0089] Figure 8 A diagram showing the framework of a DFE hierarchical feature extractor provided in an embodiment of the present invention;

[0090] Figure 9 A schematic diagram of pixel-by-pixel Gaussian distribution provided by an embodiment of the present invention;

[0091] Figure 10 This is a diagram of anomaly detection results provided by an embodiment of the present invention. DETAILED DESCRIPTION

[0092] The following will clearly and completely describe the technical solutions of the present invention in conjunction with the embodiments. Obviously, the embodiments described are only some embodiments of the present invention, not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative work shall fall within the scope of protection of the present invention.

[0093] See Figure 1 , select the LOGO area of the bottle cap to obtain the shape features of the bottle cap. After selecting the LOGO area, Figure 2 , using the template matching algorithm, the LOGO area is matched with the entire image to be processed to find the area that is most similar to the template. During the template matching process, the algorithm used can calculate the matching score according to the following formula:

[0094]

[0095] in, and Represent the pixel values of the template area and the image area respectively. Then, a combination of rotation matrix and translation vector is used to describe the rigid transformation to correct the position of the bottle cap image. First, the difference between the center of gravity of the shape model and the image is calculated to determine the translation vector:

[0096]

[0097] in, and Represent the center of gravity of the shape model, and Indicates the center of gravity of the image.

[0098] Second, the rotation matrix is obtained by calculating the difference between the angle of the shape model and the angle of the image:

[0099]

[0100] in, Represents the angular difference between the shape model and the image.

[0101] Finally, by combining the translation vector and the rotation matrix, we get the complete rigid transformation parameters:

[0102]

[0103] in, Represents the rigid transformation parameters of the shape model relative to the image. Through this process, the image is accurately rotated, so that the image is accurately adjusted and positioned according to the position and angle information of the shape model while maintaining the shape and content.

[0104] In this way, Figure 3 As shown, we perform the rotation and translation transformation on each image according to the above operations to achieve Figure 4 The bottle cap logo alignment image is shown.

[0105] Furthermore, the bottle cap region of the rectified bottle cap image is cropped by template matching. Specifically, based on the normalized cross correlation (NCC) template matching principle, a template image is first selected from the bottle cap dataset, such as Figure 5 As shown, two circular contours are selected along the outer and inner sides of the bottle cap in the image, and the circular contour at the middle intersection is selected as the matching template. The local features of the template image are extracted and the pixel value of each feature point is calculated to create an NCC model. In the template matching process, the corrected bottle cap image is matched with the created NCC model. Specifically, the NCC matching operation is performed on the corrected image, and the similarity between the image and the template is calculated at each position. This similarity is measured by comparing the correlation between the pixel values of the template image and the image to be matched at each position. The NCC algorithm aligns the template image and the image to be matched, compares them at different positions, and then finds the position where the correlation is maximized as the best matching position. For a given template image and the image to be matched , the NCC calculation formula is as follows:

[0106]

[0107] in, represents the pixel value of the template image, Indicates that the image to be matched is at position The pixel value at and Represent the average pixel values of the template image and the image to be matched, The larger the value of , the more similar the two images are.

[0108] By performing NCC-based template matching, the position most similar to the template can be accurately found in the rectified bottle cap image, thereby achieving precise positioning of the bottle cap area. Finally, based on the matching results, the bottle cap area can be cropped, such as Figure 6 As shown, the region extraction operation of the bottle cap image is completed.

[0109] Furthermore, in step S2, the normal image after preprocessing and enhancement is input into Figure 7 In the MGAD network model shown, the learned positive sample feature distribution is obtained and the anomaly score is calculated. Figure 7 (a) is a deep feature extractor, which connects the input image through a pre-trained network to form a multi-layer feature vector. (b) represents the feature distribution of the training image, which consists of a single Gaussian and a mixture of Gaussian distributions. (c) The Mixed Gaussian Discriminant (MGD) module is used to identify the number of distributions. (d) The robust mean and covariance are calculated using the MCD algorithm and saved as the MCD distribution matrix. The test image is extracted through DFS and passed to the MMAHS module in (e) to calculate the minimum robust Mahalanobis distance with the MCD distribution matrix, and the output is an anomaly map. Specifically, it includes:

[0110] a. Input the pre-processed image into a hierarchical feature extractor, such as Figure 8 As shown, three mid-level convolutional feature maps are selected 、 、 Combined input hierarchical feature concatenation module (Hierarchy Feature Concatenation, ) becomes the embedding vector :

[0111]

[0112] in, Represents a hierarchical feature concatenation module, operated by a sliding window Preprocess the feature map to ensure consistent dimensions. Operations can be defined as:

[0113]

[0114] It represents the feature map Resampling and region extraction are performed to achieve scale and dimension consistency. The processed feature maps are processed through a series operation Forming embedding vectors ,Right now:

[0115]

[0116] Among them, each For the resized and normalized feature maps, the concatenation operation generates a comprehensive feature representation by stacking these feature maps.

[0117] A collection of feature maps obtained by pre-training the neural network It constitutes a multi-level feature representation of the input image from local detail structure information to global semantic structure.

[0118] b. Figure 7 As shown in (c), the Gaussian mixture model (GMM) strategy is integrated into the mixed Gaussian discriminant module (MGD) to perform pixel-by-pixel probability density estimation, as shown in Figure 9 As shown, the feature set extracted from N training images in the cth channel of a specific image position (i, j) is The analysis is performed and it is assumed that it follows a mixture distribution composed of several single Gaussian distributions

[0119] With Group distribution , represents the different distribution of the current features. Among them, represents the mth distribution, whose probability distribution is given by the following formula:

[0120]

[0121] In the above formula, represents the probability that the mth Gaussian distribution is selected, represents the probability density function of the mth Gaussian distribution, and are the mean vector and covariance matrix of the distribution respectively. The entire GMM is expressed as A linear combination of single Gaussian distributions, namely:

[0122]

[0123] in, Represents the probability distribution of GMM;

[0124] Now there is a set of feature data , the goal is to construct the likelihood function L, which represents the probability of the observed data occurring under the current distribution. Specifically, the likelihood function is constructed as follows:

[0125]

[0126] This can be done by calculating the posterior probability to get the likelihood that each point came from each Gaussian distribution:

[0127]

[0128] Under the premise of maximum likelihood function, by Taking the derivative and setting it equal to 0, we can get Right now:

[0129]

[0130] Likewise for variables Derivative, use the Lagrange method to find the maximum formula through the constraints:

[0131]

[0132] According to the large value, we can get The calculation formula is as follows:

[0133]

[0134] Similarly, by changing the variable Taking the derivative and setting it equal to 0, we can get Right now:

[0135]

[0136] In this process, a boundary threshold is introduced , the auxiliary GMM algorithm will not misclassify a single Gaussian distribution as a mixed Gaussian distribution. is a set of k means, judging for all and , whether it satisfies:

[0137]

[0138] in: Represent the elements in the set S respectively, Represents the absolute difference between two elements, that is, their distance. and When the difference between them is greater than the threshold T, that is, when When established, this paper believes that the two means represent two independent Gaussian distributions in the data, namely:

[0139]

[0140]

[0141] On the contrary, if the above formula is satisfied, it means that the two means represent a single Gaussian distribution. In this case, this paper chooses the one with greater weight The Gaussian distribution of is used as the representative of the position, that is:

[0142]

[0143] Shared Satisfy on the channel Group mixture Gaussian distribution, setting a distribution number threshold ,like , this paper believes that the feature of the pixel at (i, j) is a mixed Gaussian distribution.

[0144] c. In the core set selection stage, the feature set after MGD screening is used in the MCD method. It is necessary to find a subset ,Depend on The sample consists of a proportion of , so that its covariance determinant is Minimum:

[0145]

[0146] Among them, the sample proportion parameter Decided from The proportion of samples selected to form the core set .

[0147] In the robust covariance estimation stage, calculate The sample mean on and covariance matrix ,These estimates reflect the statistical properties of the selected subset and are ,used in the subsequent calculation of anomaly scores.

[0148]

[0149]

[0150] In calculating the covariance matrix When , a regularization term I (identity matrix) and regularization parameter Make sure it is full rank and reversible.

[0151] Based on robust feature set , calculate the Mahalanobis distance to measure the feature points of the test sample and normal distribution The distance between them, the robust Mahalanobis distance is calculated as follows:

[0152]

[0153] At each pixel (i, j), if there is Heavy Gaussian distribution, calculation Subrobust Mahalanobis distance, defining the minimum distance as the anomaly score:

[0154]

[0155] Next, the Mahalanobis distance is normalized to the interval [0,255] and recorded as:

[0156]

[0157] Figure 10 From left to right, the following are: original image, anomaly score heat map, a mixture of original image and heat map, binary segmentation result, and original image segmentation result. In the heat map, blue to red indicates the severity of the anomaly.

[0158] The foregoing description is merely a preferred embodiment of the present invention. It should be understood that the present invention is not limited to the form disclosed herein and should not be construed as excluding other embodiments. Rather, the present invention can be used in various other combinations, modifications, and environments and can be modified within the scope of the concept described herein through the above teachings or techniques or knowledge in the relevant field. Modifications and variations made by those skilled in the art that do not depart from the spirit and scope of the present invention are intended to be protected by the appended claims.

Claims

1. A bottle cap defect detection method based on artificial intelligence, characterized in that: The following steps are involved: S1. Take images of bottle caps in the production plant, build a bottle cap dataset, and preprocess the dataset; S2. Inputting the preprocessed and enhanced normal image into the MGAD network model to obtain the learned positive sample feature distribution; wherein the MGAD model includes: Use a hierarchical feature extractor to extract the convolutional features of the last layer of the 3rd, 4th, and 5th modules of the pre-trained network EfficientNetV1; The Gaussian mixture model (GMM) strategy is integrated into the mixed Gaussian discriminant module to perform pixel-by-pixel probability density estimation. A weight distribution mechanism is designed to assign the same proportion of extraction probability to different categories of feature distributions. The weight distribution mechanism adjusts the weight of low-frequency features according to the morphological appearance of normal samples. The robust covariance determinant MCD method is introduced to calculate the Gaussian distribution of the saved positive samples, and the minimum robust Mahalanobis distance calculation method is used to realize the bottle cap anomaly detection; S3. Input the image to be detected into the bottle cap anomaly detection model MGAD to obtain an anomaly segmentation map of the image.

2. The artificial intelligence-based bottle cap defect detection method according to claim 1, characterized in that: In the step S1, the data set is preprocessed accordingly, and the image preprocessing is: the image is corrected for the bottle cap posture according to the bottle cap LOGO area, and the bottle cap area is cropped by template matching on the corrected bottle cap image.

3. The bottle cap defect detection method based on artificial intelligence according to claim 2, characterized in that: The specific steps of correcting the bottle cap posture according to the bottle cap LOGO area of the image are as follows: An image is selected from the bottle cap dataset, and the LOGO area of the bottle cap is framed to obtain the shape features of the bottle cap; after the LOGO area is selected, the LOGO area is matched with the entire image to be processed using a template matching algorithm to find the area that is most similar to the template; In the template matching process Score, the algorithm used is: ; in, and are the pixel values of the template area and the image area respectively; Use a combination of rotation matrix and translation vector to describe the rigid transformation to correct the posture of the bottle cap image; first calculate the difference between the shape model and the image center of gravity to determine the translation vector : and Represent the center of gravity of the shape model, and Represents the center of gravity of the image; by calculating the difference between the angle of the shape model and the angle of the image , get the rotation matrix , Combine the translation vector and the rotation matrix to get the complete rigid transformation parameters relative to the image , the algorithm is: 。 4. The bottle cap defect detection method based on artificial intelligence according to claim 3, characterized in that: The bottle cap region of the corrected bottle cap image is cropped by template matching as follows: a template image is selected from the bottle cap data set, local features and pixel values of each feature point are extracted; an NCC model is created, an NCC matching operation is performed on the corrected image, and the similarity between the image and the template is calculated, wherein, For the template image, is the image to be matched, and the NCC matching operation calculation formula is: ; in, represents the pixel value of the template image, Indicates that the image to be matched is at position The pixel value at and Represent the average pixel values of the template image and the image to be matched respectively.

5. The bottle cap defect detection method based on artificial intelligence according to claim 1, characterized in that: In step S2, the pre-processed and enhanced normal image is input into the MGAD network model to obtain the learned positive sample feature distribution and calculate the abnormality score. The specific steps include: The pre-processed image is input into the hierarchical feature extractor, and three middle-layer convolutional feature maps are selected and combined to input the hierarchical feature concatenation module. Become an embedding vector; the hierarchical feature concatenation module operates through a sliding window Preprocess the feature map to ensure consistent dimensions.

6. The artificial intelligence-based bottle cap defect detection method according to claim 5, characterized in that: In the step S2, the Gaussian mixture model GMM strategy is integrated into the mixed Gaussian discriminant module MGD to perform pixel-by-pixel probability density estimation, and the feature set extracted from N training images in the c-th channel at a specific position (i, j) of the image is The analysis is performed assuming that it follows a mixture distribution composed of several single Gaussian distributions; With Group distribution , represents the different distributions of the current features; among them, represents the mth distribution, whose probability distribution is given by the following formula: ; in, represents the probability that the mth Gaussian distribution is selected, represents the probability density function of the mth Gaussian distribution, and are the mean vector and covariance matrix of the distribution respectively, and the entire GMM is expressed as A linear combination of single Gaussian distributions, namely: ; in, Represents the probability distribution of GMM; If there is a set of feature data , the goal is to construct the likelihood function L, which represents the probability of the observed data occurring under the current distribution; the likelihood function is constructed as follows: ; Calculate the posterior probability to get the likelihood that each point comes from each Gaussian distribution for: ; Under the premise of maximum likelihood function, by Taking the derivative and setting it equal to 0, we get for: ; For variables Derivative, using the Lagrange method to find the maximum formula through the constraints is: ; According to the large value, we can get The algorithm is: ; By the variables Taking the derivative and setting it equal to 0, we get for: ; Introducing boundary thresholds , the auxiliary GMM algorithm will not misclassify a single Gaussian distribution as a mixed Gaussian distribution, assuming is a set of k means, judging for all and , whether it satisfies: ; in: Represent the elements in the set S respectively, Represents the absolute difference between two elements, that is, their distance; when the two means and When the difference between When , the two means represent two independent Gaussian distributions in the data, and the algorithm is: ; ; If satisfied, and If the mean is represented by a single Gaussian distribution, then the one with the larger weight is selected. The Gaussian distribution of the position The representative algorithm is: ; Shared Satisfy on the channel Group mixture Gaussian distribution, setting a distribution number threshold ,like , then the feature of the pixel at (i, j) is a mixed Gaussian distribution.

7. The artificial intelligence-based bottle cap defect detection method according to claim 6, characterized in that: In step S2, in the core set selection stage, the feature set after MGD screening was used in the MCD method; Need to find a subset ,Depend on The sample consists of a proportion of , so that its covariance determinant is Minimum: ; Among them, the sample proportion parameter Decided from The proportion of samples selected from the core set ; In the robust covariance estimation stage, calculate The sample mean on and covariance matrix , the algorithm is: ; 。 8. The artificial intelligence-based bottle cap defect detection method according to claim 7, characterized in that: In calculating the covariance matrix When using a regularization term I and regularization parameter Ensure that it is full rank and reversible; Based on robust feature set , calculate the Mahalanobis distance to measure the feature points of the test sample and normal distribution The distance between them, robust Mahalanobis distance The algorithm is: ; At each pixel (i, j), if there is Heavy Gaussian distribution, calculation Subrobust Mahalanobis distance, defining the minimum distance as the anomaly score , the algorithm is: ; Then normalize the Mahalanobis distance to the interval [0,255], the algorithm is: ; Finally, the anomaly score of each pixel in the test image is calculated to determine the anomaly location.

9. A bottle cap defect detection system based on artificial intelligence, characterized in that: The system is used to perform the method according to any one of claims 1-8.

10. A readable storage medium storing instructions, characterized in that: The instructions, when executed by one or more processors of a machine, cause the processors to perform the method according to any one of claims 1-8.

Citation Information

Patent Citations

  • Industrial product surface defect detection method based on deep learning and Gaussian mixture

    CN113421223A

  • Industrial product appearance anomaly detection method and system based on two-stage learning

    CN114862857A