Method and system for detecting threads of glass bottle through AI, electronic equipment and storage medium
Through the AI-based recognition model, the problem of difficult identification of complex structural defects of bottle mouth threads is solved in traditional methods, and a higher recognition success rate and efficiency is achieved, especially in dealing with light reflection and refraction. When the phenomenon.
Patent Information
- Application Number
- CN202411279726.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-09-12
- Publication Date
- 2024-11-01
AI Technical Summary
Traditional bottle body detection methods are difficult to effectively identify defects caused by the complex structure of glass bottle threads, especially shadow and reflection problems caused by light reflection and refraction, which lead to identification problems.
Using an AI-based recognition model, by training the abnormal bottle thread sample pictures, specific anchor frames and network structures are set, including input layer, reference network extraction feature layer and output prediction layer, and image scaling and preprocessing. Combined with Foucs module, Conv convolutional network and SPPF module, improve detection accuracy.
It significantly improves the success rate and efficiency of thread defect identification, can effectively distinguish bottle mouth threads that do not meet the standards or have defects, avoid shadow problems caused by light reflection and refraction, and improves the accuracy of detection.
Smart Images

Figure CN118887203A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of image recognition technology, and in particular to a method, system, electronic device and storage medium for detecting glass bottle threads through AI. Background Art
[0002] Glass containers go through many processes in the production process, and each link may cause quality defects such as missing threads, embedded tiny bubbles, residual stones, and occasional cracks in the threaded part of the bottle mouth due to various factors such as temperature control, raw material purity, and mold accuracy. These defects not only affect the sealing performance and aesthetics of the container, but also pose a potential threat to the safety and quality of the subsequent filled products.
[0003] Traditionally, manufacturers tend to use general bottle body inspection algorithms to identify various defects including bottle mouth threads. However, this inspection method has the following problems: the structure of the bottle mouth thread area is complex and changeable, and its unique spiral shape causes extremely complex light reflection and refraction phenomena, which easily produces imaging problems such as shadows and reflections. As a result, ordinary bottle body inspection methods are difficult to detect the threads of glass bottles, so a detection method that can identify bottle mouth threads is urgently needed. Summary of the invention
[0004] In view of the above defects, the purpose of the present invention is to propose a method, system, electronic device and storage medium for detecting glass bottle threads through AI, so as to improve the success rate and efficiency of identifying thread defects and ensure the quality of glass bottles.
[0005] To achieve this purpose, the present invention adopts the following technical solution: A method for detecting glass bottle threads by AI, comprising the following steps:
[0006] Acquire a detection image of the thread of the target glass bottle to be tested;
[0007] Perform result detection on the detection image based on the trained recognition model to obtain the recognition result of the bottle mouth thread;
[0008] The recognition model is trained based on sample images of abnormal bottle threads.
[0009] Preferably, the recognition model includes an input layer, a reference network extraction feature layer, a Neck processing feature layer and an output prediction layer connected in sequence.
[0010] Preferably, the input layer is used to scale the detection image to a size of 192*640, and is provided with three anchor frames of different multiples;
[0011] The settings of the anchor boxes for 8x downsampling are: [5,13; 16,30; 33,23];
[0012] The settings of the anchor boxes for 16x downsampling are: [30,61; 48,45; 59,119];
[0013] The anchor boxes are set to [70, 150; 90, 250; 170, 355] when downsampling by 32 times.
[0014] Preferably, the reference network feature extraction layer consists of 11 layers, including at least a Foucs module, a Conv convolutional network, a C3 module and an SPPF module;
[0015] The 11 layers that constitute the feature extraction layer of the baseline network are:
[0016] 1.Focus module;
[0017] 1. Conv convolutional network;
[0018] 1. Conv convolutional network;
[0019] 3, C3 module;
[0020] 1. Conv convolutional network;
[0021] 6, C3 module;
[0022] 1. Conv convolutional network;
[0023] 9, C3 module;
[0024] 1. Conv convolutional network;
[0025] 3, C3 module;
[0026] 1,SPPF module.
[0027] Preferably, before using the recognition model, the recognition model needs to be trained, wherein the training steps are as follows:
[0028] Obtain sample images and preprocess the sample images, wherein the preprocessing includes defect marking and size adjustment;
[0029] Perform normalization on the preprocessed sample images to obtain normalized data;
[0030] Divide the normalized data into training set data, validation set data, and test set data;
[0031] All the data in the training set are grouped according to the batch size and sent to the recognition model in sequence for forward propagation calculation. When all the data are calculated once, one cycle is completed.
[0032] After a cycle of training is completed, the prediction results of the current model are compared with the real labeled labels using the validation set data to obtain the judgment parameters of the cycle, where the judgment parameters include accuracy, precision, average of average precision, recall rate and loss function, and it is judged whether the judgment parameters all meet the threshold. If they all meet the threshold, the next cycle of training is carried out. If they do not all meet the threshold, the model parameters are adjusted.
[0033] When the number of cycles reaches the threshold, the data in the test set is put into the model for reasoning to obtain the position and confidence of the defect in the image. When the confidence is greater than the confidence threshold, the recognition model completes the training. If the confidence is less than the confidence threshold, the recognition model is retrained.
[0034] Preferably, the normalization operation is specifically performed as follows:
[0035]
[0036] Where x is the original data of the sample image;
[0037] The formula for obtaining the accuracy is as follows:
[0038]
[0039] Among them, TP is the number of samples predicted to be positive samples and actually positive samples, FP is the number of samples predicted to be positive samples and actually negative samples; TN is the number of samples predicted to be negative samples and actually negative samples, and FN is the number of samples predicted to be negative samples and actually positive samples;
[0040] The formula for obtaining accuracy is as follows:
[0041]
[0042] The formula for obtaining the recall rate is as follows:
[0043]
[0044] The formula for obtaining the average value of average precision is as follows:
[0045]
[0046] Where Q is the set of defect categories, q represents the qth defect, and AP(q) represents the average precision of the qth defect;
[0047] The formula for obtaining the loss function is as follows:
[0048] L = λ*L1+(1-λ)*L2;
[0049]
[0050] Where L1 is the category loss function value, L2 is the position loss function value, λ is the proportional coefficient, pij represents the probability that the i-th sample belongs to the j-th class, f(x i ) is the predicted position of the i-th sample, y i is the actual position of the sample, n is the total number of samples processed, and c is the total number of categories;
[0051] The confidence calculation formula is as follows:
[0052] confidence=pro(object)*IoU;
[0053] in IoU represents the ratio of the intersection and union of the areas of the real box and the predicted box.
[0054] A system for detecting glass bottle threads by AI, using the method for detecting glass bottle threads by AI, comprising an input module and a recognition module;
[0055] The input module is used to obtain a detection image of the thread of the target glass bottle to be tested;
[0056] The recognition module is used to perform result detection on the detection image based on the trained recognition model to obtain the recognition result of the bottle mouth thread.
[0057] A terminal device includes a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the computer program, a method for detecting glass bottle threads by using AI as described above is implemented.
[0058] A computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, a method for detecting glass bottle threads by using AI is implemented as described above.
[0059] One of the above technical solutions has the following advantages or beneficial effects: In the invention, a recognition model is set, and the recognition model is trained by using sample images of abnormal bottle thread. Since the recognition model is specially trained based on sample images of abnormal bottle thread, it is particularly good at identifying and distinguishing bottle threads that do not meet the standards or have defects. This highly targeted training method can significantly improve the model's ability to detect abnormal situations. When annotating sample images of abnormal bottle thread, shadow annotations can be added. This avoids the problem of being unable to recognize due to shadows caused by light reflection and refraction. BRIEF DESCRIPTION OF THE DRAWINGS
[0060] Figure 1is a flow chart of an embodiment of the method of the present invention.
[0061] Figure 2 It is a schematic diagram of the structure of an embodiment of the system of the present invention. DETAILED DESCRIPTION
[0062] The embodiments of the present invention are described in detail below, and examples of the embodiments are shown in the accompanying drawings, wherein the same or similar reference numerals represent the same or similar elements or elements having the same or similar functions from beginning to end. The embodiments described below with reference to the accompanying drawings are exemplary and are only used to explain the present invention, and cannot be understood as limiting the present invention.
[0063] In the description of the embodiments of the present invention, the terms "first" and "second" are used for descriptive purposes only and are not to be understood as indicating or implying relative importance or implicitly indicating the number of the indicated technical features. Thus, the features defined as "first" and "second" may explicitly or implicitly include one or more of the features. In the description of the embodiments of the present invention, the meaning of "plurality" is two or more, unless otherwise clearly and specifically defined.
[0064] In addition, the terms "first" and "second" are used for descriptive purposes only and should not be understood as indicating or implying relative importance or implicitly indicating the number of the indicated technical features. Therefore, the features defined as "first" and "second" may explicitly or implicitly include one or more of the features. In the description of the present invention, unless otherwise specified, the meaning of "plurality" is two or more. For those of ordinary skill in the art, the specific meanings of the above terms in the present invention can be understood according to specific circumstances.
[0065] like Figures 1-2 As shown, a method for detecting glass bottle threads by AI includes the following steps:
[0066] Acquire a detection image of the thread of the target glass bottle to be tested;
[0067] Perform result detection on the detection image based on the trained recognition model to obtain the recognition result of the bottle mouth thread;
[0068] The recognition model is trained based on sample images of abnormal bottle threads.
[0069] In the invention, a recognition model is set up, and the recognition model is trained by using sample images of abnormal bottle threads. Since the recognition model is specially trained based on sample images of abnormal bottle threads, it is particularly good at identifying and distinguishing bottle threads that do not meet the standards or have defects. This highly targeted training method can significantly improve the model's ability to detect abnormal situations. When annotating sample images of abnormal bottle threads, shadow annotations can be added. This avoids the problem of being unable to recognize due to shadows caused by light reflection and refraction.
[0070] Preferably, the recognition model includes an input layer, a reference network extraction feature layer, a Neck processing feature layer and an output prediction layer connected in sequence. In addition, the Neck processing feature layer and the output prediction layer are conventional settings and are not limited too much here.
[0071] Preferably, the input layer is used to scale the detection image to a size of 192*640, and is provided with three anchor frames of different multiples;
[0072] The settings of the anchor boxes for 8x downsampling are: [5,13; 16,30; 33,23];
[0073] The settings of the anchor boxes for 16x downsampling are: [30,61; 48,45; 59,119];
[0074] The anchor boxes are set to [70, 150; 90, 250; 170, 355] when downsampling by 32 times.
[0075] In the setting of the anchor box, two numbers form a group, which respectively represent the length and width of the anchor box. For example, the anchor box with 8x downsampling is set with three sizes of anchor boxes, namely the first anchor box with a length of 5 and a width of 13, the second anchor box with a length of 16 and a width of 30, and the third anchor box with a length of 33 and a width of 23.
[0076] The anchor frames are generally divided into three types: large, medium, and small according to the sampling ratio. In each type, the actual applicable defect size can be used. The 8x downsampling anchor frame is suitable for defects smaller than or close to this size. When defects are not found in this size, it will be replaced with a 16x downsampling anchor frame. Similarly, when defects are not found in the 16x downsampling anchor frame, it will be replaced with a 32x downsampling anchor frame for sampling and searching.
[0077] In thread detection, the thread occupies a small position and has many features. The size of 192*640 can ensure the detection accuracy while reducing the additional environmental feature input of the recognition model, reducing the amount of calculation and improving the detection speed.
[0078] It is worth mentioning that in the present invention, the shape of the anchor frame is basically a horizontal rectangle. Because in the image obtained from the bottle mouth thread, the thread is usually horizontal. By setting a horizontal rectangle, it can fit the shape of the thread and better identify whether there are defects in the thread.
[0079] Preferably, the reference network feature extraction layer consists of 11 layers, including at least a Foucs module, a Conv convolutional network, a C3 module and an SPPF module;
[0080] The 11 layers that constitute the feature extraction layer of the baseline network are:
[0081] 1.Focus module;
[0082] 1. Conv convolutional network;
[0083] 1. Conv convolutional network;
[0084] 3, C3 module;
[0085] 1. Conv convolutional network;
[0086] 6, C3 module;
[0087] 1. Conv convolutional network;
[0088] 9, C3 module;
[0089] 1. Conv convolutional network;
[0090] 3, C3 module;
[0091] 1,SPPF module.
[0092] The number before each module indicates the number of times the module is used in that layer. For example, 1, Foucs module means that in the first layer, the Foucs module is used to perform slicing, input channel expansion, splicing, and convolution operations once. Similarly, in the next layer, 1, Conv convolutional network means that in the second layer, the Conv convolutional network is used to perform feature map downsampling once.
[0093] Since the present invention is aimed at detecting the threads of glass bottles, and the threads are usually set at the mouth of the glass bottle, some features of the mouth of the bottle will be used during feature extraction and fusion. In order to distinguish the features of the mouth of the bottle from the features of the threads, after using the 9 C3 modules of the baseline network to extract the feature layer, 1 Conv convolution network and 3 C3 modules are added. After the fusion of the mouth of the bottle, downsampling and feature fusion are performed again to further distinguish the subtle differences between the partial features of the mouth of the bottle and the features of the threads. In order to enhance the network's recognition ability for complex scenes, setting an extra layer of C3 modules can also extract shadow features caused by light reflection and refraction, thereby increasing the success rate of recognition.
[0094] Preferably, before using the recognition model, the recognition model needs to be trained, wherein the training steps are as follows:
[0095] Obtain sample images and preprocess the sample images, wherein the preprocessing includes defect marking and size adjustment;
[0096] Perform normalization on the preprocessed sample images to obtain normalized data;
[0097] Normalization can eliminate the impact of differences in dimensions or numerical ranges between different samples, making the model easier to converge and improving training speed and effect.
[0098] Resizing refers to adjusting the size of the image input to the training model. The right image size can provide enough information for the model to accurately detect objects while meeting the computing resource constraints. Larger image sizes may provide more details, but will also increase computational complexity and memory requirements. Smaller image sizes may lose some details, but will reduce the computational burden. By resizing the image, you can balance the relationship between accuracy and efficiency.
[0099] Specifically, in one embodiment of the present invention, the image size is set to 224x224 pixels, because in the defect recognition training, the defects of glass containers that are easy to find are relatively small, so there is no need to set a too large image size format. In addition, when the size of the training image is larger than 224x224 pixels, the defective area of the image can be cropped separately to meet the format size of 224x224 pixels. However, after the image is cropped, there may be distortion. Under certain lighting conditions, the distorted pixels are similar to the defects of the glass container. Therefore, after cropping, methods such as bilinear interpolation or bicubic interpolation must be used to reduce the distortion. If some parts of the image are still distorted after using bilinear interpolation or bicubic interpolation, the distorted position can be filled with the color that is the most different from the background color. For example, the background color of a training image is white. When there is still partial distortion after using bilinear interpolation or bicubic interpolation, black is used to fill the distorted part and the image is marked. This is to facilitate the defect recognition training of the training model in the later stage.
[0100] Divide the normalized data into training set data, validation set data, and test set data;
[0101] All the data in the training set are grouped according to the batch size and sent to the recognition model in sequence for forward propagation calculation. When all the data are calculated once, one cycle is completed.
[0102] After one cycle of training is completed, the validation set data is used to compare the prediction results of the current model with the real labeled labels to obtain the judgment parameters of the cycle, where the judgment parameters include accuracy, precision, average of average precision, recall rate and loss function, and judge whether the judgment parameters all meet the threshold. If they all meet the threshold, the next cycle of training is carried out. If they do not all meet the threshold, the model parameters are adjusted; wherein adjusting the model parameters means reducing the learning rate of the recognition model, so that the recognition model can be more meticulous when searching in the parameter space, which helps to find a better solution, or adjust the ratio between L1 and L2 parameters, etc.
[0103] When the number of cycles reaches the threshold, the data in the test set is put into the model for reasoning to obtain the position and confidence of the defect in the image. When the confidence is greater than the confidence threshold, the recognition model completes the training. If the confidence is less than the confidence threshold, the recognition model is retrained.
[0104] Preferably, the normalization operation is specifically performed as follows:
[0105]
[0106] Where x is the original data of the sample image;
[0107] The formula for obtaining the accuracy is as follows:
[0108]
[0109] Among them, TP is the number of samples predicted to be positive samples and actually positive samples, FP is the number of samples predicted to be positive samples and actually negative samples; TN is the number of samples predicted to be negative samples and actually negative samples, and FN is the number of samples predicted to be negative samples and actually positive samples;
[0110] The formula for obtaining accuracy is as follows:
[0111]
[0112] The formula for obtaining the recall rate is as follows:
[0113]
[0114] The formula for obtaining the average value of average precision is as follows:
[0115]
[0116] Where Q is the set of defect categories, q represents the qth defect, and AP(q) represents the average precision of the qth defect;
[0117] The formula for obtaining the loss function is as follows:
[0118] L = λ*L1+(1-λ)*L2;
[0119]
[0120] Where L1 is the category loss function value, L2 is the position loss function value, λ is the proportional coefficient, pij represents the probability that the i-th sample belongs to the j-th class, f(x i ) is the predicted position of the i-th sample, y i is the actual position of the sample, n is the total number of samples processed, and c is the total number of categories;
[0121] The confidence calculation formula is as follows:
[0122] confidence=pro(object)*IoU;
[0123] in IoU represents the ratio of the intersection and union of the areas of the real box and the predicted box.
[0124] A system for detecting glass bottle threads by AI, using the method for detecting glass bottle threads by AI, comprising an input module and a recognition module;
[0125] The input module is used to obtain a detection image of the thread of the target glass bottle to be tested;
[0126] The recognition module is used to perform result detection on the detection image based on the trained recognition model to obtain the recognition result of the bottle mouth thread.
[0127] A terminal device includes a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the computer program, a method for detecting glass bottle threads by using AI as described above is implemented.
[0128] A computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, a method for detecting glass bottle threads by using AI is implemented as described above.
[0129] In the description of this specification, the description with reference to the terms "one embodiment", "some embodiments", "illustrative embodiments", "examples", "specific examples", or "some examples" means that the specific features, structures, materials or characteristics described in conjunction with the embodiment or example are included in at least one embodiment or example of the present invention. In this specification, the schematic representation of the above terms does not necessarily refer to the same embodiment or example. Moreover, the specific features, structures, materials or characteristics described may be combined in any one or more embodiments or examples in a suitable manner.
[0130] Although the embodiments of the present invention have been shown and described, it will be appreciated by those skilled in the art that various changes, modifications, substitutions and variations may be made to the embodiments without departing from the principles and spirit of the present invention, and that the scope of the present invention is defined by the claims and their equivalents.
Claims
1. A method for detecting glass bottle threads using AI, It is characterized in that The steps include: Acquire a detection image of the thread of the target glass bottle to be tested; Perform result detection on the detection image based on the trained recognition model to obtain the recognition result of the bottle mouth thread; The recognition model is trained based on sample images of abnormal bottle threads; The recognition model includes an input layer, a reference network extraction feature layer, a Neck processing feature layer and an output end prediction layer connected in sequence; The feature extraction layer of the baseline network consists of 11 layers, including at least the Foucs module, Conv convolutional network, C3 module and SPPF module; The 11 layers that constitute the feature extraction layer of the baseline network are: 1.Focus module; 1. Conv convolutional network; 1. Conv convolutional network; 3, C3 module; 1. Conv convolutional network; 6, C3 module; 1. Conv convolutional network; 9, C3 module; 1. Conv convolutional network; 3, C3 module; 1,SPPF module.
2. A method for detecting glass bottle threads by AI according to claim 1, It is characterized in that The input layer is used to scale the detection image to a size of 192*640, and is provided with three anchor frames of different multiples; The settings of the anchor boxes for 8x downsampling are: [5,13; 16,30; 33,23]; The anchor boxes are set to [30,61; 48,45; 59,119] when downsampling by 16 times. The anchor boxes are set to [70, 150; 90, 250; 170, 355] when downsampling by 32 times.
3. A method for detecting glass bottle threads by AI according to claim 1, It is characterized in that Before using the recognition model, it is necessary to train the recognition model. The training steps are as follows: Obtain sample images and preprocess the sample images, wherein the preprocessing includes defect marking and size adjustment; Perform normalization on the preprocessed sample images to obtain normalized data; Divide the normalized data into training set data, validation set data, and test set data; All the data in the training set are grouped according to the batch size and sent to the recognition model in sequence for forward propagation calculation. When all the data are calculated once, one cycle is completed. After a cycle of training is completed, the prediction results of the current model are compared with the real labeled labels using the validation set data to obtain the judgment parameters of the cycle, where the judgment parameters include accuracy, precision, average of average precision, recall rate and loss function, and it is judged whether the judgment parameters all meet the threshold. If they all meet the threshold, the next cycle of training is carried out. If they do not all meet the threshold, the model parameters are adjusted. When the number of cycles reaches the threshold, the data in the test set is put into the model for reasoning to obtain the position and confidence of the defect in the image. When the confidence is greater than the confidence threshold, the recognition model completes the training. If the confidence is less than the confidence threshold, the recognition model is retrained.
4. A method for detecting glass bottle threads by AI according to claim 3, It is characterized in that The normalization operation is specifically performed as follows: Where x is the original data of the sample image; The formula for obtaining the accuracy is as follows: Among them, TP is the number of samples predicted to be positive samples and actually positive samples, FP is the number of samples predicted to be positive samples and actually negative samples; TN is the number of samples predicted to be negative samples and actually negative samples, and FN is the number of samples predicted to be negative samples and actually positive samples; The formula for obtaining accuracy is as follows: The formula for obtaining the recall rate is as follows: The formula for obtaining the average value of average precision is as follows: Where Q is the set of defect categories, q represents the qth defect, and AP(q) represents the average precision of the qth defect; The formula for obtaining the loss function is as follows: L = λ*L1+(1-λ)*L2; Where L1 is the category loss function value, L2 is the position loss function value, λ is the proportional coefficient, pij represents the probability that the i-th sample belongs to the j-th class, f(x i ) is the predicted position of the i-th sample, y i is the actual position of the sample, n is the total number of samples processed, and c is the total number of categories; The confidence calculation formula is as follows: confidence=pro(object)*IoU; in IoU represents the ratio of the intersection and union of the areas of the real box and the predicted box.
5. A system for detecting glass bottle threads by AI, using the method for detecting glass bottle threads by AI as claimed in any one of claims 1 to 4, It is characterized in that It includes an input module and a recognition module; The input module is used to obtain a detection image of the thread of the target glass bottle to be tested; The recognition module is used to perform result detection on the detection image based on the trained recognition model to obtain the recognition result of the bottle mouth thread.
6. A terminal device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, It is characterized in that When the processor executes the computer program, the method for detecting glass bottle threads by using AI as described in any one of claims 1 to 4 is implemented.
7. A computer-readable storage medium storing a computer program, It is characterized in that When the computer program is executed by a processor, a method for detecting glass bottle threads by using AI as described in any one of claims 1 to 4 is implemented.
Citation Information
Patent Citations
Defect detection method for LED and storage medium
CN113160128A
Fruit detection and yield estimation method and system based on machine vision
CN114663814A
