Machine Vision Inspection of Electrical Connectors Based on Improved Yolo v3

Aiming at the problems of electrical connector defect detection, such as low automation, low detection accuracy, slow detection speed, and poor robustness, an improved Yolo v3 algorithm was proposed in this paper to detect electrical connector defects. First, the K-means clustering algorithm is used to perform cluster analysis on the data set of this paper to obtain three kinds of candidate frames with aspect ratios, aiming at improving the detection accuracy for the defective objects in this paper; the 8-fold downsampled feature map outputted by the third residual block of the backbone network is upsampled 4 times, and the obtained feature map is merged with the 2-fold downsampled feature map outputted by the second residual block to obtain the fusion feature detection layer; the 6 DBL units passed by the target detection layer are changed to 2 DBL unit plus 2 residual units to improve feature reuse and acquisition; In addition, single-scale feature maps are chose for target detection in this paper instead of multi-scale prediction of the original network, which not only saves the calculation amount, but also avoids false detection to a certain extent.; A new detection method is proposed for relative rotation defects between the inner ring area and the outer ring area of the electrical connector. The qualitative and quantitative experimental results show that the improved Yolo v3 algorithm in this paper has better performance and speed for defect detection of various types of electrical connectors, with an accuracy rate of 93.5%, which is more accurate than Faster R-CNN. The original Yolo v3 is faster and basically meets the requirements of the industrial field for electrical connector testing.


I. INTRODUCTION
The electrical connector is a very important part in the overall aerospace industry, which plays the role of power connection and data connection [1], Because of its sealing strength, high bending strength, good air tightness and other characteristics, it plays a pivotal role in connection and packaging of aerospace, household appliances and other fields [2]. Due to various defects in the production of circular electrical connectors, defect detection is essential. During the production process, the solder points are easy to fall on the solder cup (as shown in Figure 1), resulting in the appearance of solder point on the surface of the solder cup, which leads to the situation that the connection cannot be completely sealed or The associate editor coordinating the review of this manuscript and approving it for publication was Xianye Ben . even cannot be connected. Therefore, it is necessary to detect the presence of solder points so as to remove the solder. On the other hand, in the process of welding the ground wire, the ground wire will be wrongly welded caused by errors in the machine or manual operation, which will directly cause the pins of the electrical connector not grounded or even short-circuit, leading to the collapse of the entire system. Therefore, it is necessary to detect the location of the ground wire to determine whether the ground wire is wrongly soldered. The last defect is that the inner and outer rings of the circular electrical connector rotate relatively, so the plug and the socket cannot be connected together, resulting in the connector cannot be used normally. Once the defective electrical connector has a problem during the use, it will cause the entire system to crash or even endanger the safety of human life and property, the loss cannot be estimated. Therefore, the defect detection of electrical connectors is extremely important [3].
At present, the main detection methods of electrical connectors are as follows: 1) Human eye observation method, which has low detection efficiency and the detection is greatly affected by human subjective factors, so the accuracy cannot be guaranteed. In addition, the inspector needs to pick up the workpiece and place it under a magnifying glass for observation. The sweat stain on the hand and the knocking may cause corrosion or damage of the metal workpiece; 2) Machine vision inspection method. This method has a higher efficiency, accuracy and repeatability and is non-contact method, which is non-destructive to the workpiece. Machine vision has more obvious advantages compared with human eye detection, but currently most of the connector defect detection still uses human eye observation method which mainly relies on the human eye during detection, so the accuracy and results of the detection cannot be guaranteed and the repeatability and traceability are not accessible [4].
At present, there are few researches on the visual inspection of electrical connectors. Among them, the most researched problem is the defect of the electrical connector shell, and there is less research on the defect of the socket part of the electrical connector. The Li Jiankang research of Jiangsu University proposed a texture defect detection method based on wavelet analysis to detect the surface roughness of electrical connectors. He innovatively proposed the extraction of roughness characteristic parameters and established the roughness model. His main research area is the appearance inspection of the shell, and the focus of this article is the detection of functional defects of the electrical connector to determine whether it can be used normally. Its shell inspection can only detect offline and does not meet the needs of modern automated production lines [33]. Lu Jiayu of Harbin Institute of Technology proposed a template matching algorithm based on gray features for pin recognition and a gray-scale centroid algorithm for pin location. It mainly realizes the identification and positioning of the pins, but the next step of detection has not been performed, and the main defect detection has not been completed. This method can only identify one type of electrical connector and can only be placed in a specific position, otherwise it cannot be identified [34]. Du Fuzhou of Beijing University of Aeronautics and Astronautics proposed to use binocular vision based on support vector machine (SVM) to classify and recognize various types of pins and identify the defects of the corresponding pins, but the average recognition time of this method is 1.1 seconds and needs to be improved [35]. the electrical connector can not be identified in different positions. In summary, there are few researches on defect detection of multi-model electrical connectors, and traditional image processing methods are often used for detection, which has problems such as low accuracy, poor real-time performance, and poor robustness. In order to solve these problems, this paper proposes the use of deep learning to solve the three common defect detection methods of electrical connectors.
Deep learning originated from the research of neural networks. It is the core algorithm of modern artificial intelligence which bases on machine learning and has made significant progress in the field of target detection. At present, deep learning is developing rapidly, and the emerging new algorithms provide many new ideas for defect detection [36]. Yu Jun propose an end-to-end place recognition model based on a novel deep neural network. The SPE-VLAD layer and the WT-loss layer are integrated with the VGG-16 network or ResNet-18 network to form a novel end-to-end deep neural network that can be easily trained via the standard backpropagation method. They conduct experiments on three benchmark data sets, and the results demonstrate that the proposed model defeats the state-of-the-art deep learning approaches applied to place recognition [37]. They successfully achieved a better recognition effect by improving the network. Baoxian Li proposes a novel method using deep CNN to automatically classify image patches cropped from 3D pavement images. In all, four supervised CNNs with different sizes of receptive field are successfully trained. The experimental results demonstrate that all the proposed CNNs can perform the classification with a high accuracy. Overall classification accuracy of each proposed CNN is above 94% [38]. Compared with traditional image processing methods, deep learning is more efficient, faster in calculation, and more accurate in recognition. It will also have better results for the defects to be identified in this topic. In the field of target detection, the current Faster RCNN (faster region-based convolutional neural networks) model, Yolo (you only look once) model [6] and SSD (single shot multiBox detector) [7] models all have the advantages of high accuracy and fast speed [8]. Unlike the Faster RCNN model, which uses ''two-step detection'' approach, the Yolo model uses a regression mechanism, so as long as the entire graph is entered, the target can be detected. Therefore, the number of candidate frames selected of the Yolo model is less than that of the Faster RCNN model. Although the SSD model draws on the anchor frame mechanism of the Faster RCNN model, it has not been fine-tuned at every position, so the accuracy of the SSD is relatively low. For these reasons, the Yolo model and the SSD model are superior to the Faster RCNN model in terms of detection speed, while slightly worse than the Faster RCNN model in detection accuracy. Yolo v3, the third edition of Yolo's iterative, adds multi-scale prediction to improve the detection of small targets, and deepens the network to improve accuracy, making Yolo v3 more accurate than Faster RCNN and the speed is 100 times faster than Faster RCNN. The requirements for the speed and accuracy of electrical connector defect detection are very high in this paper, so the improved network based on Yolo v3 network are used to meet the requirements of industrial production, aiming at analyzing the characteristics of the electrical connector defects of the research object, and improving the network according to actual needs to meet the requirements of modern industrial production lines.

A. ANALYSIS OF DEFECT CHARACTERISTICS OF SOLDER POINT
One of the research objects in this paper is the scattered solder spots on the solder cup of the electrical connector caused by production process problems. The solder spot may be scattered at any position on the solder cup, and the shape and size are not fixed, as shown in Figure 1 is a solder spot defect. The solder cup is the fixed base of the pin, which is the connection part of the electrical connector. It may cause poor contact or even no connection in the presence of the solder points, so the workpiece must be tested to exclude this kind of situation before leaving the factory. The size and shape of the solder spot are not fixed. After grayscale preprocessing, different grayscale values will be displayed under uneven lighting conditions. It is difficult for traditional image processing technology to detect solder spot, and the accuracy and speed is difficult to meet the testing requirements of modern production lines.

B. DEFECT ANALYSIS OF GROUND WIRE WRONG WELDING
Another research object of this paper is the ground wire of the electrical connector. The ground wire may not be welded to the specified pin, but welded to the left or right sides of the pin due to the operation error of the operator or the machine during the production process, as shown in Figure 2 is a schematic diagram of ground wire wrong welding. The green box indicates the correct welding position of the ground wire, and the two red cross boxes indicates the positions where the ground wire may be welded incorrectly. The picture shows the correct welding position. In the case of wrong welding or missing welding of the ground wire, it may cause serious leakage accidents and even affect people's lives and property safety. The research content of this article is based on the premise of online testing requirements of the modern production line. During the testing, the position of the electrical connector is not fixed, which makes it impossible to determine the position of the ground wire relative to the entire electrical connector, and whether the ground wire is correctly welded. Ground line detection can be achieved by traditional image processing technology, but traditional image processing technology focuses on the extraction of features, For slightly complex scene with more diversified features, it cannot extract the features very well so it can only be used in a relatively simple background and scenarios with low real-time requirements. Obviously, this method cannot meet the needs of this topic, but the popular deep learning network model in recent years can solve this problem very well. Compared with traditional target detection algorithms, deep learning uses a multi-layer convolutional network to extract higher-level information and it can extract the underlying information with higher accuracy and stronger generalization ability at the same time. The Yolo v3 network model has a fast recognition speed while taking the accuracy into account, and the optimization of small target recognition is added, which is more suitable for this topic.

C. ANALYSIS OF RELATIVE ROTATION DEFECTS OF INNER AND OUTER RINGS OF ELECTRICAL CONNECTORS
The difficult research point of this paper is the relative rotation of the inner and outer rings of the circular electrical connector. As shown in Figure 3, the light-colored circular area inside the electrical connector is the inner ring, and the outer dark ring area is the outer ring. The yellow line represents the central axis of the outer ring, and the green line represents the central axis of the inner ring. The central axis of a normal electrical connector should be coincident. In the production process of the electrical connector, due to the worker's error, the positions of the inner and outer rings are not aligned, resulting in relative rotation of the central axis of the inner and outer rings. Because the position of the inner ring rotates, and the socket on the inner ring rotates at the same time, the position of the socket cannot be aligned with the correct pin. As a result, the outer ring cannot be inserted further after the guide rail is connected during the connection process, so it cannot be used normally. In order to avoid this situation, it is necessary to detect the unqualified workpiece, that is, to detect the relative rotation angle of the center line of the inner and outer rings. Traditional image processing technology does not have relevant research on this kind of defect detection. We can use template matching method to detect the inner and outer ring templates separately, establish a rectangular coordinate system on the two templates, and calculate the corresponding angle. However, template matching detection has problems such as slow detection, instability, poor robustness and so on. In addition, the requirements for real-time detection of industrial sites in this subject cannot be achieved, and the detection effect of electrical connectors placed in different positions is poor. This paper innovatively proposes to use the improved Yolo v3 to identify and locate the inner and outer ring areas, map the centerline directions of the inner and outer ring areas to the image, calculate the centerline angles of the inner and outer rings respectively, and obtain the relative rotation angle difference to represent the relative rotation degree. So as to complete the detection of such defects. Turn Yolo v3 from the detection of the entire object to the recognition of a certain part of the object, and apply it to actual production operations. The use of deep learning network for target detection will greatly improve the recognition accuracy and enhance the robustness of recognition. For different scenarios, electrical connectors in different locations have better detection results.

III. YOLO v3
The Yolo algorithm was proposed by Redmon et al. [6] in 2016 which takes the entire image as input and transforms the object detection problem into a simple regression problem. In 2018, it has developed to the third generation, Yolo V3 [9]. As the name implies, it can complete the target detection as long as it performs a forward operation. Because of this feature, its operation speed is faster than other target detection algorithms, but its accuracy is reduced. While maintaining the speed of Yolo v2 [10], Yolo v3 has greatly improved the detection accuracy, especially for the recognition of small targets.

A. NETWORK STRUCTURE
A large part of the promotion of each generation of Yolo is largely achieved by improving the existing backbone network structure, and Yolo v3 is no exception. Yolo v3 has been upgraded from Darknet-19 of Yolo v2 to Darknet-53 [5], and the convolutional layer has been increased to 53 layers. Its network framework is shown in Figure 4. Darknet-53 draws on the idea of residual neural network (resnet) and adds 5 residual blocks (residual) to the network. Each residual block contains a different number of residual units [11] (res_unit). The residual unit is mainly composed of input and two digital cumulative modeling (DBL) units [12]. Among them, the DBL unit is the basic constituent unit of Yolo v3 which contains convolution, batch normalization (BN) and Leaky relu activation function. It is because the residual unit is added to the Darknet-53 network, the problem of gradient disappearance is solved, and the reuse of features is improved on the basis of deepening the network. In addition, there is no pooling layer and fully connected layer in the entire v3 network, so in the process of forward propagation, the size change of the tensor is achieved by changing the step size of the convolution kernel. When the step size is set to 2, the size of the image will become half of the original image after each pass through the convolutional layer, and the area will become a quarter of the original image.

B. MULTI-SCALE DETECTION
Yolo v3 draws on the idea of FPN [13] (feature pyramid networks) in the detection of small-size targets, and the detection of different sizes targets are realized by multi-scale prediction. The final output of the Yolo v3 network is 1/32, 1/16, and 1/8 feature map of the original image. The main implementation process is to obtain a 1/32 (13 × 13) feature map after several convolution processes behind the 79th layer, which has a large receptive field and is suitable for large-scale VOLUME 8, 2020 target detection. Then the result is upsampled and concatenated with the result of the 61th layers (tensor stitching), and then convolved to obtain a 1/16 (26 × 26) feature map which is good for medium-scale target detection. Then the above results are up-sampled and concatenated with the 36th layer results, and then convolved to obtain a 1/8 (52 × 52) feature map, which has a small receptive field and is better for the detection of small targets. As shown in Figure 5, Yolo v3 outputs three feature maps of different sizes when the input image size is 416 × 416 × 3, and the output feature maps are y1, y2, and y3, which represent feature maps of 13 × 13, 26 × 26, and 52 × 52 grids, respectively. In Yolo v3, 3 boxes are predicted for each grid, and each box requires (x, y, w, h, confidence) 5 parameters. In the COCO category, each box needs to recognize80 classes, so the depth of the feature map is 255. The shallow feature maps are superimposed to the adjacent channels by Yolo v3 network, which enables the network to learn deep and shallow features at the same time, and the model has more fine-grained features, thereby improving the model's detection ability of small targets.

C. TARGET BOUNDING BOX PREDICTION
Like Yolo v2, Yolo v3 uses K-means [14] (mean clustering method) to obtain the size of the priors anchor of the target in the image. Because Yolo v3 outputs a total of three scale feature maps, and there are three priori frame corresponding to large, medium and small size, so there are nine sizes of priori boxes. For the COCO dataset, the priors anchor obtained from 9 clusters are shown in Table 1, and the feature maps of different scales correspond to the priors anchor of different sizes.
Before predicting the bounding box, Yolo v3 uses Logistic regression [15] to perform an objective score on the area around the prior anchor point to determine whether the area is the target area. For the target area that is not the best, the model will not predict it, only the region with the highest probability of target existence will be predicted. With this step, the unnecessary prior anchor can be removed and calculation amount can be reduced, and the model will run faster. After screening, Yolo v3 uses the same direct prediction method as Yolo v2 instead of the anchor mechanism in TABLE 1. COCO data set 9 kinds of prior boxes.
the RPN (regional candidate network), as shown in Figure 6 among which (tx, ty) represents the distance between the upper left corner of the box where the point is located and the target center point. The sigmoid function is used for normalization instead of the original softmax regression method, because the softmax method will increase the probability of the most possible category and suppress the value of other categories, which is not suitable for the multi-label classification. Sigmoid function is more accurate than other methods. (Cx, Cy) represents the difference of lattice number between the grid where the point is located and the grid at the upper left corner.(Pw, Ph) represents the width and height of the prior anchor.
It can be seen from formula (1) that the width, height and confidence of the Bounding-box can be directly calculated by (tx, ty, tw, th, to).

D. LOSS FUNCTION
The loss function in Yolo v3 has three main parts, the target confidence loss function Lconf(o,c), the target classification loss function Lcla(O,C) and the target positioning loss function Lloc(l,g), As shown in the formula (2) As shown.
The target positioning loss includes the prediction frame width and height (w, h) loss function and the center point (x, y) loss function. The former uses the error square sum method to calculate the loss function, the latter uses the binary cross entropy method to calculate the loss function. The purpose of calculation is to be able to cope with more complex situations, such as the same target may be classified into multiple categories. The target confidence loss function and the target classification loss function also use this method.

IV. IMPROVED YOLO v3
The small defects existing on the circular electrical connector is the research object of this paper, and the detection of small targets is the main inspection task. The 9 size prior anchors in Yolo v3 are obtained by K-means clustering analysis based on the COCO data set, but it is obviously not suitable for the research object of this subject. On the other hand, although the multi-scale prediction method is added to the Yolo v3 network to optimize the detection of small targets, the effect is not as good as expected. Therefore, the improvement of Yolo v3 is mainly in the clustering method and the network Structural modification in this article.

A. ANCHOR BOXES CLUSTER ANALYSIS
Yolo v3 uses the anchor box [16] mechanism in Faseter R-CNN. The anchor box is a set of a priori candidate boxes with fixed width and height, whose size and proportion will directly affect the accuracy and speed of network model in target detection. In Yolo v3, K-means clustering is used to determine size and proportion. For the COCO data set, 9 sizes of Anchor boxes are clustered, as shown in Table 1. However, these nine sizes are not suitable for the research object of this subject. The size of the Anchor boxes clustered by this data set cannot meet the defect size requirements of circular electrical connectors. Therefore, K-means clustering analysis is required for the data set of this subject. Avg IOU is used as the criterion of the clustering result when clustering the data set. The higher the Avg IOU value is, the better the clustering effect is. Formula (3) shows the calculation method of Avg IOU.
where T represents the real target box, which is the sample; P represents the center of the cluster, which is the cluster box. IIOU(T,P) [17] represents the IOU (intersection ratio) between the target center box and the cluster box; k represents the total number of clusters; n represents the total number of samples; nk represents the number of samples at the kth cluster center; i represents the sample number; j represents the sample number of the cluster center. K represents the number of clusters in the K-means clustering, which is the number of clusters you want to obtain finally, and you can freely choose the number. In this experiment, k = 1 ∼ 20 was selected, and a total of 20 clusters were used for cluster analysis on the image data set. The clustering results are shown in Figure 7. It can be seen from the clustering result graph, as the number of clusters increases, the judgment indicator Avg IOU [18] becomes higher and higher, and the growth rate also decreases continuously, and the change becomes slow, so the point after the maximum slope of the curve can be regarded as the optimal point. On the one hand, fewer points can reduce the amount of calculation and speed up the convergence of the loss function. On the other hand, it can also remove the error caused by the candidate box can be removed, and anchor boxes that with number and size which are more in line with this topic can be selected. It can be seen from Fig. 6 that the optimal point is when the number of clusters is 3 and the dimensions of the three cluster centers obtained on this dataset are (13, 20) (18, 19) (23, 12), respectively.

B. IMPROVED YOLO v3 NETWORK STRUCTURE
With the deepening of the network level in Yolo v3, the details and location information of the image will continue to decrease, but the semantic information will continue to strengthen [16]- [19]. For the positioning of the target, more detailed information is needed, so more characteristics of the underlying network are needed. For category detection, more high-level semantic information is required. For target detection, both the target location and the category must be determined. Therefore, the multi-scale fusion prediction method is used to detect the target in the original network structure of Yolo v3. The upsampling is used to fuse the high-level network with the bottom-level network, so as to obtain more feature information for positioning and classi-fication. Yolo v3 uses the 8-fold downsampled feature map for the prediction of small targets, but when the detection target is less than 8 × 8 pixels, there will be disadvantages, and the defects to be detected in this article are very small, which leads to the detection difficulty. In order to solve this problem, this paper proposes to use the network information of the upper layer, that is, the 2-fold downsampled feature map in the original network for detection, which contains more details and location information, and it is more accurate for the identification of small targets in this article. In order to obtain more high-level features and improve the accuracy of target classification, the 8-fold downsampled map outputted from the Yolo v3 network is upsampled 4 times to obtain a 2-fold downsampled feature map, and then the feature map and the 2-folddownsampled maps outputted from the second residual block in the network are stitched together, thus the target detection feature map of 2-fold downsampled are obtained, as shown in FIGURE 8 [20]. In order to better identify the small defects r in this subject, two residual units are added to the original residual block output. As shown in Figure 9, 6 DBL units and 1 1 × 1 convolution kernel convolution unit are required to pass through [22] before the output layer of Yolo v3 [21]. In this paper, it is changed to 2 DBL [23] units and 2 residual units to enhance the use of features to a certain extent and avoid the disappearance of gradients. This is similar to the use of the residual structure in the main network, so that more bottom-level details and location information are obtained.
As mentioned above, the multi-scale prediction method used in the Yolo v3 network is used to detect large, medium and small targets [24]. The three scales of large, medium and small correspond to three different Anchor boxes sizes, as shown in Table 1. However, the defect target of this subject belongs to small target, so it does not need three scales, and only the 2-fold downsampled fusion feature map is used as the target detection layer, in which the fusion feature map selects to fuse the feature map outputted by the next two residual blocks, and does not add the 4-fold downsampled feature map. On the one hand, it simplifies the network, reduces the calculation, and improves the detection speed. On the other hand, this part is redundant for the recognition of small targets and has little practical effect. In this paper, the single-scale prediction method improves the model's recall rate for small targets on the one hand, and improves the detection accuracy of the model on the other hand, which is more suitable for the defect detection of electrical connectors. This method is also suitable for defect detection of the determined target size.

V. DEFECT DETECTION EXPERIMENT OF CIRCULAR ELECTRICAL CONNECTORS BASED ON IMPROVED YOLO v3 MODEL A. EXPERIMENTAL DATA SET AND EXPERIMENTAL CONDITIONS
Unlike traditional target detection, the data set in deep learning plays a crucial role, and even largely determines the quality of the model. Since there is no public data set that can be used for the defects of circular electrical connectors, a data set of 50,000 pictures was made in this paper. The experimental device is shown in Figure 10, through which the original image is obtained. In order to enhance the robustness of the network model, it is necessary to obtain as many electrical connector images as possible in different situations. First ensure that the workpieces are placed in the same position, and only by changing the light intensity to obtain a part of the image. Secondly, rotate the workpiece to obtain images of different angles of the workpiece, and then a part of the images are obtained by changing the light intensity at each different angle. Then move the workpiece horizontally to obtain images of the workpiece at different positions of the lens, and then the lighting is repeatedly changed and the workpiece is rotated to obtain more different images.
The 50000 data sets are mainly divided into three categories, including 20,000 images of individual ground wire labels, 20,000 images of individual solder point labels, and 10,000 mixed labels of ground wires and solder points. In this article, labelImg is the tool to labele the data set. In the use of labeling, you only need to frame the target point and customize its category. An xml file that can be recognized by the network will be automatically generated, which contains some location information and category information. The labelImg operation interface is shown in Figure 11.  The conditions of the target detection experiment in this paper: operating system Windows10, CPU i5-8300H, GPU 1050ti, memory 16GB, deep learning framework tensorflow.

B. IMPROVED YOLO v3 NETWORK TRAINING
When the improved Yolo v3 network is trained, the ratio of the training set to the validation set is 9:1, and the main parameters of the network are initialized. The learning rate (learning rate) is set to 0.0005, the number of iterations (epoch) is set to 110, the batch size is set to 2, and the weight decay is set to 0.0005. The loss (loss) value obtained by the improved Yolo v3 in network training is shown in Figure 12. It can be seen that the loss has approached 0.09 after 100 iterations of all samples. From the convergence of loss value, it can be seen that the results of the network training are relatively ideal and can be used as a qualified network model for testing.

VI. TEST OF DEFECT DETECTION NETWORK FOR CIRCULAR ELECTRICAL CONNECTORS A. SINGLE DEFECT DETECTION EXPERIMENT
Recall rate R and precision rate P [25] are the most basic indicators to judge the quality of network model detection in the field of target detection network. Recall rate R and precision rate P can be calculated by formulas (4) and (5). (5) where N TP represents the number of targets detected correctly by the network; N FN represents the number of targets not detected by the network; N FP represents the number of targets detected by the network incorrectly. A total of 5,000 images were tested, including a total of 6,000 solder spot defects and 6,000 defects including ground wires. The trained network model was used to test the data set to obtain the recall rate R and accuracy rate P [25]. The results are shown in Table 2. It can be seen from Table 2 that the improved Yolo v3 has a corresponding improvement in the identification of two types defects. The defect recall rate of solder point defects increased from 85.7% to 92.8%, and the recall rate of ground wire increased from 88.6 % to 94.8%, the target recall rate of the inner and outer rings increased from 91.1% to 99.5%, the accuracy rate of solder spot defects increased from 85.3% to 92.2%, and the accuracy rate of ground defects increased from 88.3% to 93.8%. The target accuracy rate of the inner and outer loops increased from 90.1% to 98.5%, which shows that the improved algorithm in this paper has significantly improved the recall rate and accuracy rate for the three defects.
The concept of average accuracy (AP) is introduced in the target detection field in order to better characterize the accuracy of the model. The average accuracy rate evaluates the accuracy of the network in terms of recall rate and accuracy rate, which is suitable for a single type of detection evaluation and its quantification method is to calculate the area under the Precision-recall curve. Generally, the higher the AP value, the better the classification effect of the model is. The calculation method of AP [26] is called 11piont method. First, the maximum 11 precision rate values in the data set are sorted from high to low and the corresponding recall rate and precision rate are calculated, and then the recall VOLUME 8, 2020  (6), where x represents one of the 11 maximum predicted values at the current recall rate.
After putting the single-type defect data set in the data set into the Yolo v3 network and the improved Yolo v3 network, the results after calculating the corresponding average accuracy are shown in Table 3. It can be seen that compared with the original Yolo v3 network, the improved Yolo v3 network improved the average accuracy by different degree in detecting defects 1 and 2, and the AP value of solder point defect detection increased from 85.6% to 92.5%. The ground defect detection AP value increased from 88.4% to 94.5%. The more intuitive detection effect improvement can be seen through the different network detection results in Figure 13.
Among them, Fig. 12 (a) is the identification result of the original Yolo v3 network, and Fig. 12 (b) is the improved network identification result of this paper. Comparison figures (a) and (b) shows that the original Yolo v3 network has errors and missed detection in solder point defects detection. The red box represents the location detected by the network, the yellow box represents the location of incorrect detection or missed detection, and the green box represents the location of the correct frame. In summary, the improved algorithm of this paper reduces the situation of false detection and missed detection to a certain extent.
The detection of inner and outer ring rotation defects is different from the other two kinds of defect detection. An innovative detection method of relative rotation inside the workpiece is proposed in this paper. The detection model of the inner and outer rings of the electrical connector is created respectively. After the inner and outer ring templates are detected, the central axis angles of the two parts are calculated, and the angle difference is calculated based on the angles of the two central axis, so as to complete the detection of the relative rotation of the inner and outer rings. Not only the accuracy of target detection is required, but also the accuracy of the detected angle difference and the   the inner ring area, but the central axis direction detected by the Yolo v3 network is opposite to the central axis of the inner ring. The inner ring area detected by the improved Yolo v3 in this paper is shown in the blue box in Figure 14(b), and the direction is the same as the actual central axis, and the central axis of the outer ring area is shown in the purple box in Figure (b), which is consistent with the actual situation. The actual detection process is shown in Figure 15. The human-computer interaction interface written by QT5 can accurately identify the current electrical connector model and the relative rotation angle of the inner and outer rings, and judge whether the product is qualified according to the rotation angle.
In order to test the accuracy of this method for detecting the inner and outer ring defects of different types of electrical connectors, 8 types of electrical connectors are selected. There are 16 categories of qualified products and unqualified products, and 100 workpieces of each category are tested. The test results are shown in Table 3. It can be seen that compared with the original network, the improved Yolo v3 detection error in this paper is maintained at about 0.2 • , and the maximum detection error is only 0.4 • , the detection effect is betterwhich is close to the actual deviation angle. Through the electrical connector socket and plug test, the electrical connector can still be used normally when the relative rotation angle of the inner and outer rings of the electrical connector is less than 4 • . Therefore, the detection method in this paper can meet the detection accuracy of the electrical connector in the industrial field.

B. MIXED DEFECT DETECTION EXPERIMENT
To judge the quality of a target detection model is not only to judge the detection effect of a single type of target. Using the original Yolo v3 network respectively, the improved Yolo v3 network in this paper detects the mixed defect 1, 2 targets. Due to the particularity of the rotation angle detection of the inner and outer rings, the defect 3 detection is not added to the experiment. The self-made data set are adopted in this paper, and the evaluation standard is characterized by the mean accuracy rate (mAP). The higher the value of mAP, the better the detection effect and the stronger the comprehensive performance of the network for the detection of different types of targets. The mAP calculation formula is shown in formula (7) In the formula, AP [26] represents the average accuracy rate, N represents the number of detected target types, and mAP [27] is the mean value of different types of APs. The test results are shown in Table 4. It can be seen that the improved Yolo v3 network increases mAP from 86.9% to 93.5%, the false detection rate is reduced from 8.3% to 3.9%, and the missed detection rate is reduced from 4.8% to 2.6%. The network improved in this paper has better performance in the data level. The actual defects in this paper are chose to detect and compare in order to better check the effect of defect detection.
From Figure 16, we can see the results of the two networks in the actual detection process. Figure 16 (a) is the detection result of the original Yolo v3 network, and Figure 16 (b) is the result graph obtained by the improved algorithm in this paper.
Compared Figure 16 (a) with (b), we can see that the original Yolo v3 network has made some wrong detections,   and some light spots are mistakenly identified as solder joints [28], while the improved Yolo v3 network can accurately identify solder joints and reduce the occurrence of false detection to a certain extent. In addition, it can be seen that the Yolo v3 network has not identified all the ground wires, which leads to missed detection. The improved algorithm of this paper accurately identified all the defects which indicates that the improved algorithm in this paper is more accurate than the original Yolo v3 network in detecting single-type defects or multi-type defects.

C. COMPARISON OF DIFFERENT TARGET DETECTION MODELS
Because the defect of the circular electrical connector is the identification target of this paper, the accuracy and real-time performance of the network model is the most important for the identification task of this paper. The accuracy rate can be characterized by mAP, and the real-time performance can be judged by detection time. The same data set is used in this paper, and Faster R-CNN, SSD, Yolo v3 [29], and the improved Yolo v3 network in this paper are used for detection. The results are shown in Table 5.
As can be seen from Table 5, the mAP score of Yolo v3 in this paper is the highest, reaching 93.5%, followed by Faster R-CNN [30], reaching 91.2%, indicating that the improved network in this paper has better detection performance, is faster than other networks. From the perspective of mAP and inspection time, the improved algorithm performance in this paper is more balanced, it can accelerates the inspection speed and better serve the inspection task of electrical connector defects, while ensuring the accuracy.

VII. CONCLUSION
The improved algorithm in this paper is mainly based on the Yolo v3 network whose main improvement points are the selection of anchor boxes, the cluster analysis of self-made data sets, and the calculation of the suitable number and size of candidate boxes for this paper. Candidate boxes are very important for different detection tasks; In addition, the backbone network structure is reconstructed, and the 2-fold downsampled feature map in the network and the output feature map of the deep network are stitched and merged to obtain the 2-fold downsampled fusion feature map; in order to better identify small defect targets, 2 residual units are added to the final residual block output, which has a better effect on the detection of small defects. Because the detection target of this paper is defect detection of circular electrical connectors, which is small, single-scale prediction is used instead of three scales of large, medium and small scale prediction used in the original network, and 6 DBL [31] units before the target detection layer are changed to 2 DBL units and 2 residual units in order to meet the real-time requirements of the network model and better support for small defect recognition; In addition, an innovative method for detecting defects in the relative rotation of the inner and outer rings of the electrical connector is proposed, which can accurately identify multiple types of electrical connectors, and has a good detection effect for the three types of defects described in this article. Through experiments, we can see that the improved Yolo v3 network in this article has a more balanced performance compared with different target detection algorithms The recall rate, accuracy rate and mAP of the defects in this article have been improved to a certain extent compared with the original Yolo v3 network, The recognition speed also has been increased in the case of ensuring accuracy, basically meeting the requirements of industrial field for the accuracy and real-time detection of circular electrical connectors. All these show that the algorithm in this paper has certain practical significance, and can be used for reference in the identification of small target defects in industrial field. The improved network in this paper will obtain a more ideal detection results by performing cluster analysis on different data sets. The improved Yolo v3 in this paper obtains a higher mAP than Faster R-CNN, and its detection speed isless than 1% of Faster R-CNN [32]. Yolo V3 has a great progress compared to other models, but there is still a lot of room for improvement of network detection performance, and the next main research direction is to continue to improve accuracy and speed.