Method and system for training efficient quality inspection model based on ultra-small samples
Through the quality inspection model trained by ultra-small samples, combined with Squeezenet Pro and generative adversarial network, the problem of light source demands in the detection of small defects is solved, and efficient and accurate quality inspection is achieved in the case of few samples, which is suitable for compatibility detection of multiple products and colors.
Patent Information
- Application Number
- CN202210197654.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2018-08-15
- Publication Date
- 2025-08-22
- Estimated Expiration
- 2038-08-15
AI Technical Summary
Traditional vision algorithms require strict light sources when detecting tiny defects, and due to the small number of defective samples, it is difficult to effectively apply big data analysis and artificial intelligence algorithms, resulting in inefficient industrial quality detection.
The efficient quality inspection model based on ultra-small sample training is adopted, and the small samples are expanded through simulation, and the model is trained using Squeezenet Pro, combining image enhancement and generation adversarial network to generate new samples, gradually adjusting the number of hidden neurons to achieve compatibility detection of multiple products and colors.
The training effect of hundreds of thousands of samples is achieved in a very small sample situation, which improves the efficiency and accuracy of industrial quality detection, reduces the sensitivity to light changes, and enhances system compatibility and recognition stability.
Smart Images

Figure CN114577812B_ABST
Abstract
Description
[0001] This invention is a divisional application of the invention entitled “Method and system for training efficient quality inspection models based on ultra-small samples”, in which the application number of the parent case is 201810929603.8 and the application date is 2018.08.15. Technical Field
[0002] The present invention relates to the field of quality inspection, and in particular to a method and system for training an efficient quality inspection model based on ultra-small samples. Background Art
[0003] Traditional visual algorithms have very stringent requirements on light source cameras when detecting tiny defects (tiny defects are defects that are approximately one percent of the total area of the item). In addition, a large number of recognition algorithm strategies are required to meet the detection requirements for products with uneven surfaces and varying colors, which greatly reduces the development efficiency of quality inspection projects.
[0004] As the pace of Internet penetration into various fields of society accelerates, reform and innovation in traditional industries are imperative. The current development trend is to continuously apply new technologies and make full use of Internet technologies, such as big data analysis and artificial intelligence algorithms, to achieve fast, accurate and convenient product quality testing. At the same time, it provides massive data testing and analysis information to accurately find multiple types of defects in the quality of multiple types of products, and then continuously upgrade the product quality testing level, improve quality and increase efficiency.
[0005] However, in industrial production, since the number of defective product samples is small, preparing a large number of defective products and normal samples will consume a lot of manpower. Therefore, it is almost impossible to provide large samples for big data analysis and training of artificial intelligence algorithms. This condition also limits the promotion of big data analysis and artificial intelligence algorithms in industrial applications. Summary of the Invention
[0006] The purpose of the present invention is to provide a method and system for training an efficient quality inspection model based on ultra-small samples, so as to ensure that the effect of a deep learning model trained with hundreds of thousands of samples can be achieved when the number of samples is very small, so as to be better applied to industrial quality inspection.
[0007] To achieve the above object, the present invention provides the following solutions:
[0008] A method for training an efficient quality inspection model based on ultra-small samples, comprising:
[0009] Step 1: Determine the collection type, which includes the defective and normal varieties to be tested, and classify them into N levels according to the percentage of the defect size to the total sample size, and collect small samples;
[0010] Step 2: simulate and expand small samples of various types and levels;
[0011] Step 3: Randomly sample to form training set, validation set and test set;
[0012] Step 4: Using Squeezenet Pro to train a quality inspection model based on the training set, the validation set, and the test set;
[0013] The fourth step specifically includes:
[0014] Initialize all weights W from Conv1 layer to Conv10 layer I The Squeezenet V1.1 model weight W I (0); If a Squeezenet Pro training model already exists, all weights W I Replaced by the latest Squeezenet Pro weights; where I = 1, 2, ..., 10;
[0015] Replace the hidden neurons σ in the top softmax layer with K, that is, j=1,2,……,K;
[0016] Open Squeezenet Pro W i Provide training and initialize the number of training times t n =0, the initial value of j is 10, input data, and use AdamGradient optimization algorithm to train W 10 , and observe the learning curve, when D valid The test results on the plateau are marked with l e is the training accuracy, where e is the training cycle epoch, ε is the minimum difference in training results, and E is the minimum upper limit of the training cycle. When , stop training and judge l e1 Is it greater than 0.99? If so, jump to the training number judgment; if not, set i = i-1 and open SqueezenetPro's W i Weights provide training, re-training Squeezenet Pro;
[0017] Determine the current number of training times train n <Q is established, where Q is the total number of training times under the nth level defect; if train n <Q, then train n =train n +1, jump to step 3 to re-screen the data for training; if train n >Q, then jump to step 5;
[0018] Step 5: Test the model results; control the next step based on the accuracy and number of tests;
[0019] Step 6: Publish the completed model. According to the test results of each defect level obtained in step 5, the recognition accuracy of each level of defects is given, and the weight of each level of Squeezenet Pro is saved and frozen, and the corresponding Squeezenet Pro model is published.
[0020] Optionally, the step 1 specifically includes:
[0021] Determine the number of defective varieties to be tested as K-1 times, K>=2, the total number of categories is the number of defective varieties + the number of normal varieties = K categories, and collect M samples for each category. k A small sample was collected samples, of which M k ∈[5,10],k=1,2,...,K;
[0022] Each type of defective product is divided into N levels according to the percentage of defect size to the total sample size, where
[0023] Each type of samples is divided into two groups: and in for 80% of the samples randomly selected from the dataset are used as the training set; for 20% of the samples are randomly selected as the test set.
[0024] Optionally, the step 2 specifically includes:
[0025] The kth type of defective goods of the nth level and the last type of normal goods By artificially manufacturing, the number of samples is expanded to α1 = 5 times the original number, that is, At this time, the total number of defective products A = α1M = 5M, k = 1, 2, ..., K;
[0026] The kth type of defective products and the last type of normal products of the nth level after manual simulation By unifying the samples under the same light source Light0 and camera Camera0, at different angles Angle p Direction p Position p The number of samples was expanded to α2 = 500 times the original number by taking continuous photos;
[0027] Angle p∈ANGLE, p=1,2,…,P, ANGLE is the set of possible angles of products on the actual production line; Direction p ∈DIRECTION, p=1,2,...,P, DIRECTION is the set of possible directions of products on the actual production line; Position p ∈POSITION, p=1,2,...,P,POSITION is the set of possible positions of the product on the actual production line;
[0028] Through this simulation, the number of samples is determined Each class of samples is divided into training sets and test set
[0029] For each b0∈B0 sample, take a photo with camera0 so that each b0 sample is expanded The data is expanded by the noise generated by the slight difference in camera sensitivity during each shot. The number of samples obtained by continuous shooting simulation is Then we get the training set and test set
[0030] The image enhancement algorithm simulates a good sample with β0 times the image size, rotates, translates, crops, fills, adjusts brightness, contrast, and color difference, and expands the number of samples of the good sample without affecting the product appearance and structure or causing defects, that is,
[0031] The defective product simulation algorithm is used to expand the defective products by β0 times, and each type of defective products k=1,2,…,K-1, generate an image library of this type of defective products Mainly by Capturing defective parts from defective product images, searching for images with similar defective parts on the Internet, and simulating defective images based on two-dimensional Gaussian distribution;
[0032] For a given defect type k and a given defect level n, randomly select from Randomly select product images And randomly select coordinates (w0, h0), Image placement A new defective product is generated at (w0, h0) and this process is repeated β0 times to obtain
[0033] All k=1,2,…,K is input into the Generative Adversarial Network DCGAN model to regenerate and expand new samples
[0034] Get the 3D model of the product and build a Randomly select coordinates (w1, h1) and map them to the product 3D model. Then add light source Light0 and camera Camera0 to the 3D model at different angles. p Direction p Position p Take a simulated photo and repeat the process times, get
[0035] Summarize all the new data generated and get Among them, α3=β0+β1+β2, β j ∈N + , j = 0, 1, 2; get the training set and test set
[0036] Optionally, the defect image simulation based on two-dimensional Gaussian distribution specifically includes:
[0037] According to the formula
[0038] Perform defect image simulation;
[0039] Among them, w,h∈[-2γ n ,2γ n ],μ1,μ2∈[-γ n ,γ n ],ρ∈(-1,1),σ1,σ2∈(0,2γ n ], γ n As n increases, it decreases, indicating that the simulation flaws become smaller and the difficulty of recognition gradually increases.
[0040] Optionally, the step five specifically includes:
[0041] The test set in step 3 is tested using the newly trained SqueezenetPro model. If the accuracy is greater than or equal to 0.99, n=n+1 is used to increase the difficulty of defect recognition, and the process jumps to step 2 for small sample simulation and training. If the accuracy is less than 0.99, the current test number test is determined. n <O is true, where O is the total number of tests under the nth level defect; if test n <O, then test n =testn +1, skip to step 2 for small sample simulation and training, if test n >O, then jump to step 6.
[0042] To achieve the above object, the present invention also provides the following technical solutions:
[0043] A system for training efficient quality inspection models based on ultra-small sample sizes, comprising:
[0044] Collection module: determines the collection type, which includes defective and normal varieties to be tested, and divides them into N levels according to the percentage of defect size to the total sample size, and collects small samples;
[0045] Expansion module: used to simulate and expand small samples of various types and levels;
[0046] Sampling module: random sampling to form training set, validation set and test set;
[0047] Training module: using Squeezenet Pro to train a quality inspection model based on the training set, the validation set, and the test set;
[0048] The training module includes:
[0049] Squeezenet Pro model weight copy unit: Initialize all weights W from Conv1 layer to Conv10 layer I The Squeezenet V1.1 model weight W I (0); if a Squeezenet Pro training model already exists, all weights W I Replaced by the latest Squeezenet Pro weights; where I = 1, 2, ..., 10;
[0050] Squeezenet Pro model weight replacement unit: replace the hidden neurons σ in the top softmax layer with K, that is,
[0051] Training Unit: Open SqueezenetPro W i Provide training and initialize the number of training times t n =0, the initial value of j is 10, input data, and use AdamGradient optimization algorithm to train W 10 , and observe the learning curve, when D valid The test results on the plateau are marked with l eis the training accuracy, where e is the training cycle epoch, ε is the minimum difference in training results, and E is the minimum upper limit of the training cycle. When the training accuracy difference |l e1 -l e2 |<ε, When , stop training and judge l e1 Is it greater than 0.99? If so, jump to the judgment unit; if not, set i=i-1 and open SqueezenetPro's W i The weights provide training, jump to this training unit to retrain;
[0052] Judgment unit: judge the current number of training times train n <Q is established, where Q is the total number of training times under the nth level defect; if train n <Q, then train n =train n +1, jump to the sampling module to re-screen the data training; if train n >Q, then jump to the test module;
[0053] Testing module: Test model results; control the next step based on accuracy and number of tests;
[0054] Release module: Release the completed model, give the recognition accuracy of each level of defects based on the test results of each defect level obtained by the test module, save and freeze the weight of each level of Squeezenet Pro, and release the corresponding SqueezenetPro model.
[0055] Optionally, the acquisition module includes:
[0056] Category unit: Determine the number of defective categories to be tested as K-1 times, K>=2, the total number of categories is the number of defective categories + the number of normal categories = K categories, and collect M samples for each category. k A small sample was collected samples, of which M k ∈[5,10],k=1,2,...,K;
[0057] Grade unit: Each type of defective product is divided into N grades according to the percentage of defect size to the total sample size, where
[0058] Grouping unit: Each type of sample is divided into two groups: and in for 80% of the samples randomly selected from the dataset are used as the training set; for 20% of the samples are randomly selected as the test set.
[0059] Optionally, the expansion module includes:
[0060] The kth type of defective goods of the nth level and the last type of normal goods By artificially manufacturing, the number of samples is expanded to α1 = 5 times the original number, that is, At this time, the total number of defective products A = α1M = 5M, k = 1, 2, ..., K;
[0061] The kth type of defective products and the last type of normal products of the nth level after manual simulation By unifying the samples under the same light source Light0 and camera Camera0, at different angles Angle p Direction p Position p The number of samples was expanded to α2 = 500 times the original number by taking continuous photos;
[0062] Angle p ∈ANGLE, p=1,2,…,P, ANGLE is the set of possible angles of products on the actual production line; Direction p ∈DIRECTION, p=1,2,...,P, DIRECTION is the set of possible directions of products on the actual production line; Position p ∈POSITION, p=1,2,...,P,POSITION is the set of possible positions of the product on the actual production line;
[0063] Through this simulation, the number of samples is determined Each class of samples is divided into two groups: training set and test set
[0064] For each b0∈B0 sample, take a photo with camera0 so that each b0 sample is expanded The data is expanded by the noise generated by the slight difference in camera sensitivity during each shot. The number of samples obtained by continuous shooting simulation is Then we get the training set and test set
[0065] The image enhancement algorithm simulates a good sample with β0 times the image size, rotates, translates, crops, fills, adjusts brightness, contrast, and color difference, and expands the number of samples of the good sample without affecting the product appearance and structure or causing defects, that is,
[0066] The defective product simulation algorithm is used to expand the defective products by β0 times, and each type of defective products k=1,2,…,K-1, generate an image library of this type of defective products Mainly by Capturing defective parts from defective product images, searching for images with similar defective parts on the Internet, and simulating defective images based on two-dimensional Gaussian distribution;
[0067] For a given defect type k and a given defect level n, randomly select from Randomly select product images And randomly select coordinates (w0, h0), Image placement A new defective product is generated at (w0, h0) and this process is repeated β0 times to obtain
[0068] All k=1,2,…,K is input into the Generative Adversarial Network DCGAN model to regenerate and expand new samples
[0069] Get the 3D model of the product and Randomly select coordinates (w1, h1) and map them to the product 3D model. Then add light source Light0 and camera Camera0 to the 3D model at different angles. p Direction p Position p Take a simulated photo and repeat the process times, get
[0070] Summarize all the new data generated and get Among them, α3=β0+β1+β2, β j ∈N + , j = 0, 1, 2; get the training set and test set
[0071] Optionally, the defect image simulation based on two-dimensional Gaussian distribution specifically includes:
[0072] According to the formula
[0073] Perform defect image simulation;
[0074] Among them, w,h∈[-2γ n ,2γn ],μ1,μ2∈[-γ n ,γ n ],ρ∈(-1,1),σ1,σ2∈(0,2γ n ], where γ n As n increases, it decreases, indicating that the simulation flaws become smaller and the difficulty of recognition gradually increases.
[0075] Optionally, the test module includes:
[0076] Accuracy judgment unit: The test set obtained by the sampling module is tested using the newly trained Squeezenet Pro model. If the accuracy is greater than or equal to 0.99, the defect recognition difficulty is increased by n=n+1, and the process jumps to the expansion module for small sample simulation and training. If the accuracy is less than 0.99, the process jumps to the number judgment unit.
[0077] Determine the current test number test n <O is true, where O is the total number of tests under the nth level defect; if test n <O, then test n =test n +1, jump to the expansion module for small sample simulation and training, if test n >O, then jump to the release module.
[0078] According to the specific embodiments provided by the present invention, the present invention discloses the following technical effects:
[0079] By making the top layer of SqueezeNet adjustable, the number of hidden neurons in the top layer is adjusted based on the type of defective product being identified, resulting in greater compatibility across multiple products and colors. Traditional vision systems require specialized lighting schemes and criteria for each defective product type, based on appearance characteristics such as color and size, resulting in poor system compatibility. However, the deep learning algorithm employed in this invention, through training on product models, can accommodate the inspection needs of multiple products and colors, enabling seamless transitions across multiple products. BRIEF DESCRIPTION OF THE DRAWINGS
[0080] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the following briefly introduces the drawings required for use in the embodiments. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other structural diagrams can be obtained based on these drawings without paying any creative work.
[0081] Figure 1 This is a schematic diagram of the combination of traditional vision algorithms and deep learning algorithms in an embodiment of the present invention;
[0082] Figure 2 This is a schematic diagram of small sample data expansion according to an embodiment of the present invention;
[0083] Figure 3 This is a schematic diagram of the application of SqueezeNet Pro version according to an embodiment of the present invention;
[0084] Figure 4 This is a schematic diagram of the adjustable SqueezeNet Pro version according to an embodiment of the present invention;
[0085] Figure 5 This is a schematic diagram of defective product classification training for SqueezeNet Pro version according to an embodiment of the present invention;
[0086] Figure 6 Schematic diagram of the step-by-step training model according to an embodiment of the present invention. DETAILED DESCRIPTION
[0087] The following will clearly and completely describe the technical solutions in the embodiments of the present invention in conjunction with the accompanying drawings. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without making creative efforts are within the scope of protection of the present invention.
[0088] The present invention provides a deep learning model algorithm based on small sample training. Through this method, it can be ensured that the effect of a deep learning model trained with hundreds of thousands of samples can be achieved when the number of samples is very small (a dozen or so samples), thereby being better applied to industrial quality inspection.
[0089] Step 1: Collect a small sample
[0090] 1.1. Determine the number of defective varieties to be tested as K-1 times, K>=2, the total number of categories is the number of defective varieties + normal varieties = K categories, and collect M samples for each category. k , k=1,2,...,K small samples, a total of samples, of which M k ∈[5, 10].
[0091] 1.2. Each type of defective product is divided into N grades according to the percentage of defect size to the total sample size, where
[0092] 1.3. Divide each type of sample into two groups: and in for 80% of the samples randomly selected from the dataset are used as the training set. for 20% of the samples randomly selected from the dataset are used as the testing set.
[0093] Step 2: Small sample expansion
[0094] 2.1. Manual simulation sample
[0095] The kth category of defective products of the nth level (the larger n is, the more difficult it is to identify) and the last category of normal products k=1, 2, ..., K, and is expanded to α1=5 times of the original number of samples by artificial manufacturing, that is, At this time, the total number of defective products A = α1M = 5M;
[0096] 2.2, continuous photo taking simulation;
[0097] 2.2.1、After manual simulation, the kth class defective products of the nth level and the last class normal products By unifying the samples under the same light source Light0 and camera Camera0, at different angles Angle p Direction p Position p The continuous photography method expands the number of samples to α2 = 500 times the original number.
[0098] Angle p ∈ANGLE, p=1,2,…,P, ANGLE is the set of possible angles of products on the actual production line; Direction p ∈DIRECTION, p=1,2,...,P, DIRECTION is the set of possible directions of products on the actual production line; Position p ∈POSITION, p=1,2,...,P,POSITION is the set of possible positions of the product on the actual production line.
[0099] Through this simulation, there are samples Similarly, there are Based on Generated training set (Training Set); Based on Generated testing set (Testing Set).
[0100] 2.2.2. For each b0∈B0 sample, take a photo with camera0 so that each b0 sample is expanded This step uses the noise generated by the subtle differences in camera sensitivity during each shot to perform data expansion, which can effectively simulate the actual production line inspection process, allowing deep learning to train a stable and noise-resistant model. The number of samples obtained after continuous shooting simulation is Similarly, there are Based on Generated training set (Training Set), Based on Generated testing set (Testing Set).
[0101] 2.3. Automatic simulation samples;
[0102] 2.3.1. The image enhancement algorithm simulates β0 times the good samples (β0 is usually 10), rotates, translates, crops, fills, brightness, contrast, and color difference operations on the image, and expands the number of samples of the good samples without affecting the product appearance structure or generating defects, that is,
[0103] 2.3.2. Use defective product simulation algorithm to expand defective products by β0 times, and for each type of defective products k=1,2,…,K-1, generate an image library of this type of defective products Mainly by The defect image part of the defective product image is intercepted, images similar to the defect part are searched on the Internet, and the defect image simulation based on the two-dimensional Gaussian distribution is performed. The defect image simulation based on the two-dimensional Gaussian distribution adopts the following formula w,h∈[-2γ n ,2γ n ],μ1,μ2∈[-γ n ,γ n ],ρ∈(-1,1),σ1,σ2∈(0,2γ n ],
[0104] where γ n As n increases, it decreases, indicating that the simulated defects become smaller and the difficulty of identification gradually increases; for a given defect type k and a given defect level n, randomly select from Randomly select product images And randomly select coordinates (w0, h0), Image placement A new defective product is generated at (w0, h0) and this process is repeated β0 times to obtain
[0105] 2.3.3、All k=1,2,…,K is input into the Generative Adversarial Network DCGAN model to regenerate and expand new samples
[0106] 2.3.4. Get the 3D model of the product and Randomly select coordinates (w1, h1) and map them to the product 3D model. Then add light source Light0 and camera Camera0 to the 3D model at different angles. p Direction p Position p Take a simulated photo and repeat the process times, get
[0107] 2.3.5. Summarize all the new data generated and get Among them, α3=β0+β1+β2, β j ∈N + , j=0,1,2.
[0108] Note: In this algorithm, α i , i=1, 2, 3 can be replaced by any natural number greater than 0. Similarly, there are Based on Generated training set (Training Set); Based on Generated testing set (Testing Set).
[0109] Step 3: Randomly sample to form a training set
[0110] 3.1. For a given defect type k and a given defect level n, Randomly extract 50% of the data as the training set Dtrain and 10% of the data as the validation set Dvalid; Randomly select 50% of the data as the test set Dtest. Shuffle the order of each D set and proceed to step 4.
[0111] Step 4: SqueezenetPro training quality inspection model
[0112] 4.1. SqueezenetPro model weight copy: Initialize all weights W from Conv1 layer to Conv10 layer I , I=1,2,...,10 is the weight W of SqueezenetV1.1 model I (0); if there is already a SqueezenetPro training model, all weights W IReplaced by the latest SqueezenetPro weights.
[0113] 4.2. Squeezenet Pro model weight replacement: Replace the hidden neurons σ in the top softmax layer with K, that is,
[0114] 4.3. Open Squeezenet Pro's W i Provide training and initialize the number of training times t n =0, the initial value of j is 10, input data, and use AdamGradient optimization algorithm to train W 10 , and observe the learning curve, when D valid The test results on the plateau are marked with l e is the training accuracy, where e is the training cycle epoch, ε is the minimum difference in training results, usually 0.5%, and E is the minimum upper limit of the training cycle, usually 50. When the training accuracy difference |l e1 -l e2 |<ε, When , stop training and judge l e1 Is it greater than 0.99? If so, jump to 4.4; if not, set i=i-1 and open SqueezenetPro's W i The weights are trained, so skip to 4.3 to retrain.
[0115] 4.4. Determine the current number of training times train n <Q is established, where Q is the total number of training times under the nth level defect, generally Q=5; if train n <Q, then train n =train n +1, skip to 3.1 to re-screen the data for training; if train n >Q, then jump to step 5.
[0116] Step 5: Test model results
[0117] 5.1、D test Use the latest trained Squeezenet Pro model for testing. If the accuracy is greater than or equal to 0.99, n=n+1 is used to increase the difficulty of defect recognition and jump to 2.1 for small sample simulation and training; if the accuracy is less than 0.99, the current test number is determined. n <O is true, where O is the total number of tests under the nth level defect, generally O=3; if test n <O, then test n =testn +1, skip to 2.1 for small sample simulation and training, if test n >O, then jump to step 6.
[0118] Step 6: Publish the completed model
[0119] According to the test results of each defect level obtained in step 5, the recognition accuracy of each level of defects is given, and the weight W of each level of Squeezenet Pro is saved and frozen. I n , released the corresponding Squeezenet Pro model.
[0120] The characteristics of the present invention are as follows:
[0121] like Figure 1 As shown in the figure, traditional vision algorithms are combined with deep learning algorithms to complete product quality inspection. Traditional vision algorithms preprocess images to highlight the differences between defective products and normal samples, while deep learning algorithms perform classification.
[0122] like Figure 2 As shown, after the small sample data of the present invention is provided, data expansion is performed by continuously taking pictures, manually simulating bad samples, automatically simulating bad samples, generating bad samples by three-dimensional models, and generating bad samples by generative adversarial networks, and the data is expanded 100,000 times.
[0123] like Figure 3 As shown, the present invention proposes for the first time the application of SqueezeNet Pro version in product quality inspection, which ensures the accuracy of the algorithm while being faster than other models.
[0124] like Figure 4 As shown, the top layer of the SqueezeNet Pro version of the present invention is modified to be adjustable compared to the traditional SqueezeNet, and the number of hidden neurons in the top layer is set according to the defective product category that needs to be judged.
[0125] like Figure 5 As shown, the parameters of all layers except the top layer of the SqueezeNet Pro version of the present invention are replaced by parameters pre-trained for 1000 types of image recognition, and the defective product category is trained through the transfer learning algorithm.
[0126] like Figure 6 As shown, the present invention gradually trains the model through a progressive algorithm during the training process. The most obvious defective products are trained after passing the data expansion algorithm, and the recognition difficulty is gradually increased to eventually achieve training for all types of defective products.
[0127] Compared with the prior art, the present invention also has the following advantages:
[0128] (1) Using traditional vision algorithms to pre-process images, highlighting the differences between defective products and normal samples, and deep learning algorithms for classification, the system achieves higher stability in light changes than using only traditional vision or deep learning algorithms. In traditional vision, even slight deviations in product lighting will affect the inspection effect and require parameter readjustment. However, deep learning algorithms can adapt to product lighting differences through model training, eliminating the need for parameter readjustment and making them easy to use and maintain.
[0129] (2) The top layer of SqueezeNet is modified to be adjustable, and the number of hidden neurons in the top layer is set according to the type of defective product to be judged, which makes it more compatible with multiple products and colors. Traditional vision requires a special lighting scheme and judgment criteria for each type of defective product based on appearance characteristics such as color and size, resulting in poor system compatibility. However, deep learning algorithms, through training of product models, can be compatible with the inspection needs of multiple products and different colors, and generate seamless conversions for multiple products.
[0130] (3) During the deep learning training process, the use of a progressive algorithm to gradually train the model makes the deep learning model more stable in detecting small product defects. When dealing with subtle differences less than 1% of the sample size, traditional visual solutions need to strictly determine features such as color and size in order to distinguish them from noise signals. The smaller the defect, the longer the debugging time and the poorer the stability. The use of a progressive algorithm reduces development time while enhancing recognition accuracy.
[0131] (4) The use of small sample training algorithm + SqueezeNet Pro version transfer training algorithm allows the deep learning model that originally required a large amount of training data to complete the training process with only a dozen training samples. At the same time, the occurrence of local optimal situations during training can be reduced to accelerate the convergence of the model.
[0132] This document uses specific examples to illustrate the principles and implementation methods of the present invention. The above examples are only intended to help understand the method and core concept of the present invention. At the same time, those skilled in the art will find that the specific implementation methods and application scopes may vary based on the concept of the present invention. In summary, the contents of this specification should not be construed as limiting the present invention.
Claims
1. A method for training an efficient quality inspection model based on ultra-small samples, characterized in that: include: Step 1: Determine the collection type, which includes the defective and normal varieties to be tested, and classify them into N levels according to the percentage of the defect size to the total sample size, and collect small samples; Step 2: simulate and expand small samples of various types and levels; The second step specifically includes: The kth type of defective goods of the nth level and the last type of normal goods , expanded to the original number of samples by artificial manufacturing =5 times, that is , at this time the total number of defective products of all grades and categories and the last category of normal products after expansion =5M, k=1, 2,...,K; The kth type of defective products and the last type of normal products of the nth level after manual simulation By unifying the samples under the same light source Light0 and camera Camera0, at different angles Angle p Direction p Position p Expand the number of samples to the original by taking photos continuously =500 times; Angle p ∈ANGLE, p=1,2,…,P, ANGLE is the set of possible angles of products on the actual production line; Direction p ∈DIRECTION, p=1,2,...,P, DIRECTION is the set of possible directions of products on the actual production line; Position p ∈POSITION, p=1,2,...,P,POSITION is the set of possible positions of the product on the actual production line; Through this simulation, the sample number B0=PA= , divide each class of samples into training sets and test set ; For each b0∈B0 sample, take a photo with camera0 so that each b0 sample is expanded ; The data is expanded by the noise generated by the slight difference in camera sensitivity during each shot. The number of samples obtained by continuous shooting simulation is , and then obtain the training set and test set ; The image enhancement algorithm simulates a good sample with β0 times the image size, rotates, translates, crops, fills, adjusts brightness, contrast, and color difference, and expands the number of samples of the good sample without affecting the product appearance and structure or causing defects, that is, ; When k=1,2,…,K-1, Corresponding to defective products; when k=K, Corresponding refers to normal goods; The defective product simulation algorithm is used to expand the defective products by β0 times, and each type of defective products , k=1,2,…,K-1, generate an image library of this type of defective products , Mainly by Capturing defective parts from defective product images, searching for images with similar defective parts on the Internet, and simulating defective images based on two-dimensional Gaussian distribution; For a given defect type k and a given defect level n, randomly select ,from Randomly select product images And randomly select coordinates (w0, h0), Image placement A new defective product is generated at (w0, h0) and this process is repeated β0 times to obtain ; All ,k=1,2,…,K is input into the generative adversarial network DCGAN model to regenerate and expand new samples ; Get the 3D model of the product and build a Randomly select coordinates (w1, h1) and map them to the product 3D model. Then add light source Light0 and camera Camera0 to the 3D model at different angles. p Direction p Position p Take a simulated photo and repeat the process times, get ; Summarize all the new data generated and get ,in , , j=0,1,2, is a set of positive integers; get the training set and test set ; Step 3: Randomly sample to form training set, validation set and test set; Step 4: Using Squeezenet Pro to train a quality inspection model based on the training set, the validation set, and the test set; The fourth step specifically includes: Initialize all weights W from Conv1 layer to Conv10 layer I The Squeezenet V1.1 model weight W I (0); If a Squeezenet Pro training model already exists, all weights W I Replaced by the latest SqueezenetPro weights; where I = 1, 2, ..., 10; Replace the hidden neurons σ in the top softmax layer with K, that is, , j=1,2,……,K; Open Squeezenet Pro W i Provide training and initialize the number of training times t n =0, the initial value of j is 10, input data, and use AdamGradient optimization algorithm to train W 10 , and observe the learning curve, when D valid The test results on the plateau are marked l e is the training accuracy, where e is the training cycle epoch, and The minimum difference in training results is marked as E, which is the minimum upper limit of the training cycle. , When , stop training and judge l e1 Is it greater than 0.99? If so, jump to the training number judgment; if not, set i = i-1 and open Squeezenet Pro's W i Weights provide training, re-training Squeezenet Pro; Determine the current number of training times train n <Q is established, where Q is the total number of training times under the nth level defect; if train n <Q, then train n =train n +1, jump to step 3 to re-screen the data for training; if train n >Q, then jump to step 5; Step 5: Test the model results; control the next step based on the accuracy and number of tests; Step 6: Release the completed model. According to the test results of each defect level obtained in step 5, the recognition accuracy of each level of defects is given, and the weight of each level of Squeezenet Pro is saved and frozen, and the corresponding SqueezenetPro model is released.
2. The method according to claim 1, characterized in that The step 1 specifically includes: Determine the number of defective varieties to be tested as K-1 times, K>=2, the total number of categories is the number of defective varieties + the number of normal varieties = K categories, and collect M samples for each category. k A small sample was collected samples, of which M k ∈[5,10],k=1,2,...,K; Each type of defective product is divided into N levels according to the percentage of defect size to the total sample size, where ; Each type of samples is divided into two groups: and ,in for 80% of the samples randomly selected from the dataset are used as the training set; for 20% of the samples are randomly selected as the test set.
3. The method according to claim 1, characterized in that The defect image simulation based on two-dimensional Gaussian distribution specifically includes: According to the formula Perform defect image simulation; in, , , , , As n increases, it decreases, indicating that the simulation flaws become smaller and the difficulty of recognition gradually increases.
4. The method according to claim 1, wherein The step five specifically includes: The test set in step 3 is tested using the newly trained Squeezenet Pro model. If the accuracy is greater than or equal to 0.99, n=n+1 is used to increase the difficulty of defect recognition, and the process jumps to step 2 for small sample simulation and training. If the accuracy is less than 0.99, the current test number test is determined. n <O is true, where O is the total number of tests under the nth level defect; if test n <O, then test n =test n +1, skip to step 2 for small sample simulation and training, if test n >O, then jump to step 6.
5. A system for training efficient quality inspection models based on ultra-small samples, characterized by: include: Collection module: determines the collection type, which includes defective and normal varieties to be tested, and divides them into N levels according to the percentage of defect size to the total sample size, and collects small samples; Expansion module: used to simulate and expand small samples of various types and levels; The expansion module includes: The kth type of defective goods of the nth level and the last type of normal goods , expanded to the original number of samples by artificial manufacturing =5 times, that is , at this time the total number of defective products of all grades and categories and the last category of normal products after expansion =5M, k=1, 2,...,K; The kth type of defective products and the last type of normal products of the nth level after manual simulation By unifying the samples under the same light source Light0 and camera Camera0, at different angles Angle p Direction p Position p By taking pictures continuously, the number of samples is expanded to the original =500 times; Angle p ∈ANGLE, p=1,2,…,P, ANGLE is the set of possible angles of products on the actual production line; Direction p ∈DIRECTION, p=1,2,...,P, DIRECTION is the set of possible directions of products on the actual production line; Position p ∈POSITION, p=1,2,...,P,POSITION is the set of possible positions of the product on the actual production line; Through this simulation, the sample number B0=PA= , each type of sample is divided into two groups: training set and test set ; For each b0∈B0 sample, take a photo with camera0 so that each b0 sample is expanded ; The data is expanded by the noise generated by the slight difference in camera sensitivity during each shot. The number of samples obtained by continuous shooting simulation is ; Get the training set and test set ; The image enhancement algorithm simulates a good sample with β0 times the image size, rotates, translates, crops, fills, adjusts brightness, contrast, and color difference, and expands the number of samples of the good sample without affecting the product appearance and structure or causing defects, that is, ; When k=1,2,…,K-1, Corresponding to defective products; when k=K, Corresponding refers to normal goods; The defective product simulation algorithm is used to expand the defective products by β0 times, and each type of defective products , k=1,2,…,K-1, generate an image library of this type of defective products , Mainly by Capturing defective parts from defective product images, searching for images with similar defective parts on the Internet, and simulating defective images based on two-dimensional Gaussian distribution; For a given defect type k and a given defect level n, randomly select ,from Randomly select product images And randomly select coordinates (w0, h0), Image placement A new defective product is generated at (w0, h0) and this process is repeated β0 times to obtain ; All ,k=1,2,…,K is input into the generative adversarial network DCGAN model to regenerate and expand new samples ; Get the 3D model of the product and build a Randomly select coordinates (w1, h1) and map them to the product 3D model. Then add light source Light0 and camera Camera0 to the 3D model at different angles. p Direction p Position p Take a simulated photo and repeat the process times, get ; Summarize all the new data generated and get ,in , , j=0,1,2, is a set of positive integers; get the training set and test set ; Sampling module: random sampling to form training set, validation set and test set; Training module: using Squeezenet Pro to train a quality inspection model based on the training set, the validation set, and the test set; The training module includes: Squeezenet Pro model weight copy unit: Initialize all weights W from Conv1 layer to Conv10 layer I The Squeezenet V1.1 model weight W I (0); if a Squeezenet Pro training model already exists, all weights W I Replaced by the latest Squeezenet Pro weights, I = 1, 2, ..., 10; Squeezenet Pro model weight replacement unit: replace the hidden neurons σ in the top softmax layer with K, that is, , j=1,2,……,K; Training Unit: Open Squeezenet Pro W i Provide training and initialize the number of training times t n =0, the initial value of j is 10, input data, and use AdamGradient optimization algorithm to train W 10 , and observe the learning curve, when D valid The test results on the plateau are marked l e is the training accuracy, where e is the training cycle epoch, and The minimum difference in training results is marked as E, which is the minimum upper limit of the training cycle. , When , stop training and judge l e1 Is it greater than 0.99? If so, jump to the judgment unit; if not, set i=i-1 and open Squeezenet Pro's W i The weights provide training, jump to this training unit to retrain; Judgment unit: judge the current number of training times train n <Q is established, where Q is the total number of training times under the nth level defect; if train n <Q, then train n =train n +1, jump to the sampling module to re-screen the data training; if train n >Q, then jump to the test module; Testing module: Test model results; control the next step based on accuracy and number of tests; Release module: Release the completed model, give the recognition accuracy of each level of defects based on the test results of each defect level obtained by the test module, save and freeze the weight of each level of Squeezenet Pro, and release the corresponding SqueezenetPro model.
6. The system according to claim 5, characterized in that The acquisition module includes: Category unit: Determine the number of defective categories to be tested as K-1 times, K>=2, the total number of categories is the number of defective categories + the number of normal categories = K categories, and collect M samples for each category. k A small sample was collected samples, of which M k ∈[5,10],k=1,2,...,K; Grade unit: Each type of defective product is divided into N grades according to the percentage of defect size to the total sample size, where ; Grouping unit: Each type of sample is divided into two groups: and ,in for 80% of the samples randomly selected from the dataset are used as the training set; for 20% of the samples are randomly selected as the test set.
7. The system according to claim 5, characterized in that The defect image simulation based on two-dimensional Gaussian distribution specifically includes: According to the formula Perform defect image simulation; in, , , , ,in As n increases, it decreases, indicating that the simulation flaws become smaller and the difficulty of recognition gradually increases.
8. The system according to claim 5, wherein: The test module includes: Accuracy judgment unit: The test set obtained by the sampling module is tested using the newly trained Squeezenet Pro model. If the accuracy is greater than or equal to 0.99, the defect recognition difficulty is increased by n=n+1, and the process jumps to the expansion module for small sample simulation and training. If the accuracy is less than 0.99, the process jumps to the number judgment unit. Determine the current test number test n <O is true, where O is the total number of tests under the nth level defect; if test n <O, then test n =test n +1, jump to the expansion module for small sample simulation and training, if test n >O, then jump to the release module.
Citation Information
Patent Citations
Detection and recognition method of various kinds of objects in monitoring image based on deep learning
CN107316007A
Industrial appearance inspection method based on smart vision
CN107657603A