Diode glass bulb defect detection methodTechnical Field
The invention relates to the field of computer vision, in particular to a method for detecting defects of a diode glass shell.
Background
Because the diode glass bulb is transparent and has internal structure and outline characteristics, the interference with defect characteristics is easily formed in the imaging process, in addition, the interference of external environment is avoided, the detection is very difficult, the classification accuracy is difficult to improve, and the application to the industry needs very high indexes as guarantee.
The invention discloses CN201510053437.6, a cylindrical diode surface defect detection device based on machine vision, and discloses hardware and software algorithm design of the cylindrical diode surface defect detection device. The hardware design comprises the following steps: selecting the type of an industrial camera, selecting the type of a lens and building an optical platform; the design of the software defect detection algorithm comprises the following steps: the method comprises the steps of tube body segmentation, tube body pretreatment, defect ROI segmentation, feature extraction and decision tree classifier design. The invention aims at the design of an optical platform, and tests out a reasonable lighting mode and a light source placing mode through an optical principle and the self structural characteristics of an object. Aiming at the design of a defect detection operator, the difficulty lies in the segmentation and texture feature extraction of a defect ROI, and improved stroke width conversion and a method for extracting the features of a patterned gradient histogram are respectively provided; and finally, classifying the defects through a decision tree classifier, wherein the defect identification rate is close to 100%, the classification rate reaches 96.2%, and a better identification and classification effect is obtained.
Therefore, a method capable of identifying the defects on the surface of the diode glass bulb is needed, which can rapidly detect the defects of the diode glass bulb and accurately realize the positioning of the defects.
Disclosure of Invention
The invention aims to provide a method for detecting the defects of the diode glass bulb, which can accurately position the defect detection of the diode glass bulb, has reasonable structure and ingenious design and is suitable for popularization;
the technical scheme adopted by the invention is as follows: the method for detecting the defects of the diode glass bulb comprises the following steps:
step 1: placing a diode glass bulb to be detected on an industrial camera platform, and starting a backlight source at the bottom of the industrial camera platform; step 2: an industrial camera is arranged on the industrial camera platform, and a diode glass bulb image is captured through a telecentric lens on the industrial camera;
and step 3: and sending the collected diode glass shell image as input to a trained defect identification model in a computer, wherein the output of the defect identification model is the positioned diode glass shell image, and the defect on the positioned diode glass shell image is marked and displayed.
Preferably, instep 2, the defect identification model is a YOLOv3 model.
Preferably, instep 2, the industrial camera platform further includes a light source controller, the light source controller is respectively connected to the industrial camera and the backlight source, and the industrial camera is connected to the computer through the light source controller.
Preferably, in thestep 3, the training process of the defect recognition model includes the following steps,
step 11: 4000 defective diode glass shell images of different types are obtained, and thestep 2 is carried out;
step 22: expanding the obtained diode glass shell image to obtain a 50000 sample set, and marking the image of the processed sample set;
step 33: and (3) carrying out YOLOv3 model training on the marked diode glass bulb crack image, wherein 42000 sheets are used as a training set, 8000 sheets are used as a verification set, and the trained defect identification model is obtained.
Preferably, in the step 11, the acquired image is flipped left and right to obtain a flipped image; performing different-size cutting to obtain images of various sizes; carrying out multi-scale scaling to obtain a multi-size scaled image; and the turning image, the images with various sizes and the scaling images with various sizes form a processed sample set.
Preferably, the number of images of the processed sample set is a multiple of the number of envelope samples.
Preferably, the anchor frame size is obtained by performing a plurality of iterations of the K-means algorithm on the VOC data set, and when the input image size is 416 × 416, the YOLOv3 anchor frame size is { [10, 13], [16, 30], [33, 23], [30, 61], [62, 45], [59, 119], [116, 90], [156, 198], [373, 326 }.
Preferably, the loss function integrates anchor frame center coordinate loss, width and height loss, confidence coefficient loss and classification, the anchor frame loss is calculated by a sum of squares, and the classification error and the confidence coefficient error are calculated by a binary cross loss entropy, and the specific formula is as follows:
wherein
Indicating a certain real target contained in the jth anchor frame of the ith grid. The
parts 1 and 2 are anchor frame loss, the
parts 3 and 4 are confidence loss, the confidence error comprises a target part and a non-target part, and the number of the anchor frames without the target is far more than that of the anchor frames with the target, so that the anchor frames without the target have a coefficient lambda before the target
noobj0.5, reducing the contribution weight; part 5 is the classification error.
Preferably, the training process of the training diagram set on the YOLOv3 model is as follows:
dividing the images of the input training atlas into S-S grids;
generating 3 bounding boxes for each grid in the S-S grid, wherein the attributes comprise a central coordinate, a width, a height, a confidence coefficient and a probability of belonging to a workpiece crack target; and (3) eliminating a candidate frame which does not contain the target through the object confidence coefficient being less than the threshold th1, and then utilizing a non-maximum value to inhibit and select a candidate frame which has the maximum intersection ratio (IoU) with the real frame for target prediction, wherein the prediction is as follows:
bx=σ(tx)+cx(1)
by=σ(ty)+cy(2)
bx,by,bw,bhi.e. the center coordinates, width and height of the final predicted bounding box for the network. Wherein c isx,cyIs the coordinate offset of the grid; p is a radical ofw,phIs the width and height of the anchor box mapped into the feature map; t is tx,ty,tw,thIs a parameter to be learned in the network training process, tw,thRepresenting the degree of scaling of the prediction box, tx,tyRepresents the degree of center coordinate shift of the prediction box, and σ represents the sigmoid function. Updating t by continuous learningx,ty,tw,thParameters are set so that the prediction box is closer to the real box, and the training is stopped when the network loss is less than the set threshold th2 or the training number reaches the maximum iteration number N.
It is worth noting that the training of the data set on the YOLOv3 model uses 3 scales to perform 3 bounding box predictions:
scale 1, adding convolution layers after the feature extraction network, wherein the down-sampling proportion is 32, the scale of an output feature graph is 13 x 13, and the feature graph is suitable for detecting small targets;
thescale 2 is used for sampling the last-but-one convolution layer (namely, 2) in the scale 1, the down-sampling proportion is 16, and the up-sampling proportion is connected with a characteristic diagram with the scale of 26 and 26 in series, is increased by 2 times compared with the scale 1, and is suitable for detecting a medium-scale target;
dimension 3: analogy toscale 2, a 52 x 52 size signature was obtained, suitable for detecting larger targets.
Compared with the prior art, the invention has the beneficial effects that:
1. machine identification, high accuracy and high recall rate;
2. the YOLOv3 model is used for measurement and calculation, the training process is fast, and the allocation is convenient.
Drawings
FIG. 1 is a schematic view of the apparatus of the present invention in use;
FIG. 2 is a schematic diagram of a method for detecting defects of a diode glass bulb according to an embodiment of the present invention;
FIG. 3 is a diagram of the YOLOv3 model in an embodiment of the invention;
fig. 4 is a diagram illustrating the effect of diode glass envelope defects in an embodiment of the present invention.
Description of reference numerals: 1. an industrial camera stand; 2. an industrial camera; 3. a telecentric lens; 4. a glass envelope; 5. a backlight light source; 6. A light source controller; 7. a computer.
Detailed Description
The technical solutions in the embodiments of the present invention are clearly and completely described below with reference to fig. 1 to 4 of the present invention, and it is obvious that the described embodiments are only a part of the embodiments of the present invention, but not all embodiments. All other implementations made by those of ordinary skill in the art based on the embodiments of the present invention are obtained without inventive efforts.
Referring to fig. 1, the method for detecting defects of a diode glass bulb includes the following steps:
step 1: placing a diode glass bulb to be detected on an industrial camera platform, and starting a backlight source at the bottom of the industrial camera platform;
step 2: an industrial camera is arranged on the industrial camera platform, and a diode glass bulb image is captured through a telecentric lens on the industrial camera;
and step 3: and sending the collected diode glass shell image as input to a trained defect identification model in a computer, wherein the output of the defect identification model is the positioned diode glass shell image, and the defect on the positioned diode glass shell image is marked and displayed.
It should be noted that, referring to fig. 3, instep 2, the defect recognition model is a YOLOv3 model, instep 2, the industrial camera platform further includes a light source controller, the light source controller is respectively connected to the industrial camera and the backlight light source, the industrial camera is connected to the computer through the light source controller, instep 3, the training process of the defect recognition model includes the following steps,
step 11: acquiring 4000 glass shell images of diodes with different types of defects, and entering thestep 2;
step 22: expanding the image of the diode glass shell sample to obtain 50000 sample sets, and marking the image of the processed sample set;
step 33: and carrying out YOLOv3 model training on the marked diode glass bulb crack image to obtain a trained defect identification model.
It should be noted that, in the step 11, the acquired image is flipped left and right to obtain a flipped image; performing different-size cutting to obtain images of various sizes; carrying out multi-scale scaling to obtain a multi-size scaled image; and the turning image, the images with various sizes and the scaling images with various sizes form a processed sample set.
It is worth mentioning that the number of images of the processed sample set is a multiple of the number of samples of the diode bulb,
it is worth mentioning that the anchor frame size is obtained by performing a plurality of iterations of the K-means algorithm on the VOC data set, and when the input image size is 416 x 416, the YOLOv3 anchor frame size is { [10, 13], [16, 30], [33, 23], [30, 61], [62, 45], [59, 119], [116, 90], [156, 198], [373, 326 }.
It is worth to be noted that the loss function integrates the anchor frame center coordinate loss, the width and height loss, the confidence coefficient loss and the classification, the anchor frame loss is calculated by the sum of squares, and the classification error and the confidence coefficient error are calculated by the binary cross loss entropy, and the specific formula is as follows:
wherein
Indicating a certain real target contained in the jth anchor frame of the ith grid. The
parts 1 and 2 are anchor frame loss, the
parts 3 and 4 are confidence loss, the confidence error comprises a target part and a non-target part, and the number of the anchor frames without the target is far more than that of the anchor frames with the target, so that the anchor frames without the target have a coefficient lambda before the target
noobj0.5, reducing the contribution weight; part 5 is the classification error.
It should be noted that the training process of the training diagram set on the YOLOv3 model is as follows:
dividing the images of the input training atlas into S-S grids;
generating 3 bounding boxes for each grid in the S-S grid, wherein the attributes comprise a central coordinate, a width, a height, a confidence coefficient and a probability of belonging to a workpiece crack target; and (3) eliminating a candidate frame which does not contain the target through the object confidence coefficient being less than the threshold th1, and then utilizing a non-maximum value to inhibit and select a candidate frame which has the maximum intersection ratio (IoU) with the real frame for target prediction, wherein the prediction is as follows:
bx=σ(tx)+cx(1)
by=σ(ty)+cy(2)
bx,by,bw,bhi.e. the center coordinates, width and height of the final predicted bounding box for the network. Wherein c isx,cyIs the coordinate offset of the grid; p is a radical ofw,phIs the width and height of the anchor box mapped into the feature map; t is tx,ty,tw,thIs a parameter to be learned in the network training process, tw,thRepresenting the degree of scaling of the prediction box, tx,tyRepresents the degree of center coordinate shift of the prediction box, and σ represents the sigmoid function. Updating t by continuous learningx,ty,tw,thParameters are set so that the prediction box is closer to the real box, and the training is stopped when the network loss is less than the set threshold th2 or the training number reaches the maximum iteration number N.
It is worth noting that the training of the data set on the YOLOv3 model uses 3 scales to perform 3 bounding box predictions:
scale 1, adding convolution layers after the feature extraction network, wherein the down-sampling proportion is 32, the scale of an output feature graph is 13 x 13, and the feature graph is suitable for detecting small targets;
thescale 2 is used for sampling the last-but-one convolution layer (namely, 2) in the scale 1, the down-sampling proportion is 16, and the up-sampling proportion is connected with a characteristic diagram with the scale of 26 and 26 in series, is increased by 2 times compared with the scale 1, and is suitable for detecting a medium-scale target;
dimension 3: analogy toscale 2, a 52 x 52 size signature was obtained, suitable for detecting larger targets.
In the specific embodiment, after sample expansion, 50000 diode glass shell samples with defects are selected as training sets at random, and 5000 samples are selected as test sets. The training times are 80000 times in total, the weight is automatically saved every 5000 times of training, the basic learning rate is 0.001, the batch size is 32, the momentum is 0.9, the weight attenuation coefficient is 0.0005, and overfitting is reduced by adopting L2 regularization.
The method is characterized in that the detection performance of the YOLOv3 target detection model on the tubular workpiece is measured by adopting Accuracy (Accuracy), Recall rate (Recall) and video test frame number (FPS), the higher the Accuracy and Recall rate are, the better the detection effect is represented, and the practical application can be better met, and the larger the FPS value is, the better the real-time detection effect is represented by the YOLOv3 target detection model.
It is worth noting that one type of defect on the diode envelope is shown in fig. 4.
The FPS of the YOLOv3 target detection model operated on a 1080TI video card computer is 18.3f/s, the Accuracy (Accuracy) and the Recall (Recall) of defect sample (bad) detection are shown in Table 1, and the Table 1 shows the detection condition of the YOLOv3 target detection model on the diode glass shell:
TABLE 1
| Type (B) | Rate of accuracy | Recall rate |
| Diode glass shell | 98.21 | 96.38 |
As can be seen from table 1, the accuracy of the YOLOv3 target detection model on the diode glass bulb detection is 98.21%, and the recall rate is 96.38%. The method has high accuracy and recall rate for detecting the tubular workpiece, and detects defects by using a Yolov3 target detection model, and tests the diode glass shell image as shown in figure 2. Fig. 2 is a schematic diagram of a diode glass bulb detection by a YOLOv3 target detection model, and the YOLOv3 target detection model can meet the actual requirements of diode glass bulb detection in industrial production and has a good application prospect.
In summary, the implementation principle of the invention is as follows: comprises the following steps of 1: placing a diode glass bulb to be detected on an industrial camera platform, and starting a backlight source at the bottom of the industrial camera platform; step 2: an industrial camera is arranged on the industrial camera platform, and a diode glass bulb image is captured through a telecentric lens on the industrial camera; and step 3: the method comprises the steps of taking the collected diode glass shell image as input and sending the input to a trained defect identification model in a computer, wherein the output of the defect identification model is the positioned diode glass shell image, and the defects on the positioned diode glass shell image are marked and displayed.