Defective PCB detection method based on YOLOv5 model

By adding a channel attention module and a depthwise separable convolution module to the YOLOv5 model and replacing the loss function, the problem of insufficient recognition accuracy of the YOLO model in small defective PCB detection is solved, the detection accuracy is improved and the network parameters are reduced, achieving achieve more efficient feature extraction and recognition effects.

CN118747748AInactive Publication Date: 2024-10-08WUXI UNIV

Patent Information

Application Number
CN202410914272.6
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-07-09
Publication Date
2024-10-08
Estimated Expiration
Not applicable · inactive patent

AI Technical Summary

Technical Problem

The existing YOLO model has poor identification accuracy in the detection of small defective PCBs. While improving the detection accuracy, the increase in network parameters leads to an inability to reconcile the detection accuracy with the parameters.

Method used

Add the channel attention module SE to the Backbone network of the YOLOv5 model, replace the C3 module in the Neck network with the SWPC3 module, use the DWConv and SPDConv modules, and replace the CIoU loss function with the EIoU loss function.

Benefits of technology

The YOLOv5 model improves the recognition accuracy of small defects, reduces the amount of network parameters, enhances the model's feature representation capabilities and computing efficiency, and achieves higher detection accuracy.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118747748A_ABST
    Figure CN118747748A_ABST
Patent Text Reader

Abstract

The invention discloses a defective PCB detection method based on a YOLOv5 model. The method comprises the following steps: S1, acquiring a defective PCB image set; s2, a YOLOv5 model is improved, wherein the YOLOv5 model comprises a Backbone network, a Neck network and a Head network which are connected in sequence; a channel attention module SE is added behind each C3 module in the Backbone network; in a Neck network, an improved SWPC3 module is used for replacing an original C3 module; replacing the CIoU loss function with an EIoU loss function; s3, training the improved YOLOv5 model by adopting the defect PCB image set; and S4, inputting a to-be-detected image into the improved YOLOv5 model obtained by training to obtain an identification result. According to the method, the YOLOv5 model is used as a basic recognition network, the network model structure is improved, and the detection precision of the YOLOv5 model is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of image technology, and in particular to a defective PCB detection method based on a YOLOv5 model. Background Art

[0002] As one of the fastest-growing branches in the field of image processing, defective PCB detection has realized recognition and processing tasks in various states. However, the manufacturing process of PCB is complex and defects are prone to occur during the manufacturing process. These defects are relatively small, so it is necessary to detect PCB defects. In addition, the image background in the PCB defect dataset PKU-Market-PCB is single, and the YOLO model has poor detection effect on small defects. The existing YOLO improved model has added a small target detection layer, which improves the recognition accuracy of defects while increasing the network parameters at the same time. This irreconcilable contradiction between detection accuracy and network parameters limits the recognition accuracy of PCB defects. Summary of the invention

[0003] In view of the above-mentioned shortcomings of the prior art, the present invention provides a defective PCB detection method based on the YOLOv5 model, which uses the YOLOv5 network as the basis for identifying the network and improves its network model structure, thereby improving the detection accuracy of the YOLOv5 model.

[0004] To achieve the above effects, the technical solution of the present invention is as follows: The present invention provides a defective PCB detection method based on the YOLOv5 model, comprising the following steps: S1: Obtain defective PCB image set; S2: Improved YOLOv5 model: Add a channel attention module SE after each C3 module in the original YOLOv5 model Backbone network; Replace the C3 module in the Neck network with the SWPC3 module; The SWPC3 module uses the DWConv module to replace the Conv modules on the two branches of the C3 module, and inserts an SPDConv module into each of the two branches before concat; Replace the CIoU loss function with the EIoU loss function; S3: Train the improved YOLOv5 model using defective PCB image set; S4: Input the PCB image to be identified into the trained improved YOLOv5 model to obtain the PCB defect recognition result.

[0005] Further, the PCB defect dataset PKU-Market-PCB is preprocessed to obtain a processed PCB defect dataset PKU-Market-PCB, and the PCB defect dataset PKU-Market-PCB is divided into a training set, a test set and a validation set in a ratio of 8:1:1.

[0006] Furthermore, the image preprocessing of the PCB defect dataset PKU-Market-PCB is specifically as follows: The duplicate images of the PCB defect dataset PKU-Market-PCB were removed, and the brightness, rotation, cropping, translation and mirroring of the remaining PCB defect images were adjusted to obtain the processed PCB defect dataset PKU-Market-PCB.

[0007] Furthermore, the channel attention module SE is specifically: A channel attention module SE module is added after each C3 module in the Backbone network. The channel attention module SE module includes global average pooling, excitation operation and scaling.

[0008] The expressions of the global average pooling, excitation operation and scaling are:

[0009]

[0010]

[0011] Among them, the input feature map is , the number of channels is , represents the ReLU activation function, is the weight matrix used for dimensionality reduction, is the weight matrix used for dimensionality increase, is the Sigmoid activation function, is a weight vector in the channel dimension.

[0012] Furthermore, the DWConv module is used to replace the first two Conv modules in the C3 module in the Neck network, specifically: Use the DWConv module to replace the first two Conv modules in the C3 module in the Neck network, and insert the SPDConv module before the two branches enter concat; get the SWPC3 module; The parameter expressions of the depth separable DWConv module and the spatial depth conversion convolution SPDConv module are respectively:

[0013]

[0014] Among them, the number of input channels is , the number of output channels is , the number of groups is , the convolution kernel size is .

[0015] Furthermore, the EIoU loss function is specifically: Replace the CIoU loss function with the EIoU loss function; The EIoU loss function expression is:

[0016] in, is the IOU loss; For distance loss, is the height-width loss, and is the width and height of the predicted box and the actual minimum bounding rectangle, is the Euclidean distance between the center of the predicted box and the center of the true box, and are the width of the predicted box and the real box respectively, and are the heights of the predicted box and the true box respectively.

[0017] Compared with the prior art, the technical solution of the present invention has the following beneficial effects: The present invention improves the YOLOv5 model by adding a channel attention module SE module in Backbone, adding a DWConv module and an SPDConv module in the C3 module, and replacing the original CIoU loss function with the EIoU loss function, thereby improving the recognition accuracy of the YOLOv5 model on the target. BRIEF DESCRIPTION OF THE DRAWINGS

[0018] Figure 1 This is a structural block diagram of the improved YOLOv5 model of the present invention; Figure 2 This is a structural diagram of the channel attention module SE of the present invention; Figure 3 It is the structural block diagram of the SWPC3 module of the present invention; Figure 4 It is the structural diagram of the SPDConv module of the present invention; Figure 5 This is an example diagram of image preprocessing of the PCB defect dataset PKU-Market-PCB of the present invention; Figure 6The mAP curves of the improved YOLOv5 model (a) and the unimproved YOLOv5 model (b) of the present invention are shown in FIG. Figure 7 This is the PR curve of the original YOLOv5 model before improvement; Figure 8 It is a PR curve diagram of the improved YOLOv5 model of the present invention. DETAILED DESCRIPTION

[0019] The following will describe the embodiments of the present invention with reference to the accompanying drawings and preferred embodiments. Those skilled in the art can easily understand other advantages and effects of the present invention from the contents disclosed in this specification. The present invention can also be implemented or applied through other different specific embodiments, and the details in this specification can also be modified or changed in various ways based on different viewpoints and applications without departing from the spirit of the present invention. It should be understood that the preferred embodiments are only for illustrating the present invention, not for limiting the scope of protection of the present invention.

[0020] It should be noted that the illustrations provided in the following embodiments are only schematic illustrations of the basic concept of the present invention, and thus the drawings only show components related to the present invention rather than being drawn according to the number, shape and size of components in actual implementation. In actual implementation, the type, quantity and proportion of each component may be changed arbitrarily, and the component layout may also be more complicated.

[0021] Example This embodiment proposes a defective PCB detection method based on the YOLOv5 model. Figure 1~Figure 4 , including the following steps: S1: Obtain defective PCB (printed circuit board) image set; S2: Improved YOLOv5 model: Add a channel attention module SE after each C3 module in the original YOLOv5 model Backbone network; Replace the C3 module in the Neck network with the SWPC3 module; The SWPC3 module uses a DWConv (depthwise separable convolution) module to replace the Conv modules on the two branches of the C3 module, and inserts a SPDConv module into each branch before concat (fusion); The SWPC3 module includes a first branch and a second branch, wherein the first branch includes a first DWConv module, a BottleNeck module, a first SPDConv module, a concat module, and a ConvBNSiLU module connected in sequence; the second branch includes a second DWConv module and a second SPDConv module connected in sequence; the features output by the first SPDConv module and the second SPDConv module are fused in the concat module and then input into the ConvBNSiLU module for feature output; Replace the CIoU loss function with the EIoU loss function; S3: Train the improved YOLOv5 model using defective PCB image set; S4: Input the PCB image to be identified into the trained improved YOLOv5 model to obtain the PCB defect recognition result.

[0022] In the traditional YOLOv5 model Neck network, SPDConv is used for feature fusion and convolution with stride is removed, which can effectively reduce the semantic information lost due to stride or pooling.

[0023] As a preferred technical solution, in this embodiment, the PCB defect image set to be identified is the PCB defect data set PKU-Market-PCB, the PCB defect data set PKU-Market-PCB is preprocessed to obtain the processed PCB defect data set PKU-Market-PCB, and the PCB defect data set PKU-Market-PCB is divided into a training set, a test set and a validation set in a ratio of 8:1:1.

[0024] As a preferred technical solution, in this example, the image preprocessing of the PCB defect dataset PKU-Market-PCB is specifically as follows: The duplicate images of the PCB defect dataset PKU-Market-PCB were removed, and the brightness, rotation, cropping, translation and mirroring of the remaining PCB defect images were adjusted to obtain the processed PCB defect dataset PKU-Market-PCB.

[0025] It should be noted that, in this embodiment, the defect categories are: missing hole, mouse bite, open circuit, short circuit, spur and spurious copper; the improved YOLOv5 model network is trained in the PyTorch environment, with a learning rate of 0.001, 100 training rounds, and a batch_size value of 8; the final training mAP can reach 0.987, achieving an improvement in the performance of the improved YOLOv5 model.

[0026] In order to enhance the diversity of images to be identified and increase the number of samples in the PCB defect dataset, the dataset was expanded using data augmentation technology, and then the expanded dataset was randomly divided into training set, test set and validation set in a ratio of 8:1:1; Figure 5 (a) to (f) show different image types, including original image, mirror image + rotation image, crop image + rotation image + mirror image, translation image, brightness adjustment image + rotation image + crop image, and rotation image. The black occlusion in the image is to increase the diversity of the image and the number of samples in the PCB defect dataset.

[0027] As a preferred technical solution, in this embodiment, the added channel attention module SE is specifically: A channel attention module SE module is added after each C3 module in the Backbone network. The channel attention module SE module includes global average pooling, excitation operation and scaling.

[0028] The expressions of the global average pooling, excitation operation and scaling are:

[0029]

[0030]

[0031] Among them, the input feature map is , the number of channels is , represents the ReLU activation function, is the weight matrix used for dimensionality reduction, is the weight matrix used for dimensionality increase, is the Sigmoid activation function, is a weight vector in the channel dimension.

[0032] like Figure 3It can be understood that the channel attention module SE can better capture the important features in the data by learning the dependencies between the channels of the input data, thereby enhancing the feature representation ability of the model. By learning the dependencies between the channels of the input data, the channel attention module SE can better capture the important features in the data, thereby enhancing the feature representation ability of the model.

[0033] As a preferred technical solution, in this embodiment, the DWConv module is used to replace the first two Conv modules in the C3 module in the Neck network, specifically: like Figure 4 , use the DWConv module to replace the first two Conv modules in the C3 module in the Neck network, and insert the SPDConv module before the two branches enter the concat to obtain the SWPC3 module; The parameter expressions of the depth separable DWConv module and the spatial depth conversion convolution SPDConv module are respectively:

[0034]

[0035] Among them, the number of input channels is , the number of output channels is , the number of groups is , the convolution kernel size is .

[0036] It can be understood that DWconv reduces the computational complexity of the model by performing convolution operations on spaces of different scales, thus reducing the number of parameters and computational complexity of the model. SPDconv is responsible for enhancing the feature extraction capability of the model, extracting features on spaces of different scales, so as to better capture small objects with low resolution.

[0037] As a preferred technical solution, in this embodiment, the EIoU loss function is specifically: Replace the CIoU loss function with the EIoU loss function; The EIoU loss function expression is:

[0038] in, is the IOU loss; For distance loss, is the height-width loss, and is the width and height of the predicted box and the actual minimum bounding rectangle, is the Euclidean distance between the center of the predicted box and the center of the true box, and are the width of the predicted box and the real box respectively, and are the heights of the predicted box and the true box respectively.

[0039] It is understandable that the EIOU loss function is an improvement on the SIOU loss function. The EIOU loss function imposes a stronger penalty on errors (due to the exponential decay of e), has a stronger regularization effect, and helps prevent overfitting. It allows the model to better learn how to regress the position of the bounding box, thereby improving the accuracy of the prediction.

[0040] Specifically, the size of the defective PCB image set is 640×640×3.

[0041] The Backbone network includes two sequentially connected Conv modules, a first C3 module, a first channel attention module SE, a third convolution Conv module, a second C3 module, a second channel attention module SE, a fourth convolution Conv module, a third C3 module, a third channel attention module SE, a fifth convolution Conv module, a fourth C3 module, a fourth channel attention module SE, and a first spatial pyramid pooling module SPPF. The output end of the SPPF module is connected to the input end of the sixth convolution Conv module; Among them, the C3 module and the channel attention module SE module are used to extract features from the PCB image set to be identified to obtain a feature map; the convolution Conv module performs a convolution operation on the feature image to learn local feature information; the SPPF module (i.e., the receptive field expansion module) is used to expand the receptive field range of the feature map.

[0042] The Neck network includes a sixth convolution module Conv, a first upsampling module upsample, a first fusion module concat, a first SWPC3 module, a seventh convolution Conv module, a second upsampling module upsample, a second fusion module concat, a second SWPC3 module, an eighth convolution Conv module, a third fusion module concat, a third SWPC3 module, a ninth convolution Conv module, a fourth fusion module concat, and a fourth SWPC3 module, which are connected in sequence; the output end of the second SWPC3 module is connected to the input end of the first Detect module, the output end of the third SWPC3 module is connected to the input end of the second Detect module; the output end of the fourth SWPC3 module is connected to the input end of the third Detect module; Among them, the first upsampling module upsample is used to increase the resolution of the input data. The low-resolution feature map or data is enlarged to a higher resolution to perform more refined information extraction or produce a higher-resolution output. The first fusion module concat is used to fuse the feature map output by the third channel attention module SE and the upsampled feature map output by the first upsampling module upsample; the second fusion module concat is used to fuse the feature map output by the second channel attention module SE and the upsampled feature map output by the second upsampling module upsample; the third fusion module concat is used to fuse the feature map output by the seventh convolution Conv module and the feature map output by the eighth convolution Conv module; the fourth fusion module concat is used to fuse the feature map output by the sixth convolution Conv module and the feature map output by the ninth convolution Conv module; SPPF can aggregate deep semantic information on a larger receptive field, and can adaptively design and reconstruct the kernel according to the content information on the specific feature map to achieve upsampling of the feature map.

[0043] The sizes of the output feature maps of the third channel attention module SE, the first upsampling module upsample, the second channel attention module SE, the second upsampling module upsample, the seventh convolution Conv module, the eighth convolution Conv module, the sixth convolution Conv module, and the ninth convolution Conv module are 40×40×256, 40×40×256, 80×80×128, 80×80×128, 40×40×256, 40×40×256, 20×20×512, and 20×20×512, respectively.

[0044] The spatial depth conversion convolution module SPDConv in the SWPC3 module is used to strengthen the deep feature extraction of feature maps; the depth separable convolution module DWConv is used to reduce the number of model parameters.

[0045] The Head network includes a first detect module, a second detect module, and a third detect module.

[0046] Among them, the sizes of the feature maps output by the first detect module, the second detect module, and the third detect module are 80×80×128, 40×40×256, and 20×20×512, respectively.

[0047] In order to better describe the performance of the improved YOLOv5 model, the evaluation indicators are composed of Precision (P), Recall (R), Average Precision (AP), Mean Average Precision (mAP) and PR curve.

[0048]

[0049]

[0050]

[0051] Among them, True Positives (TP) is the number of samples correctly predicted by the model as positive, False Positives (FP) is the number of samples incorrectly predicted by the model as positive but actually negative. False Negatives (FN) is the number of samples incorrectly predicted by the model as negative but actually positive, and k is the number of categories. The AP value of each category is obtained by calculating the area under the precision-recall curve (AUC). is in the category In the figure, the precision rate corresponds to different recall rates. mAP is obtained by averaging the AP of n categories, where n represents the number of categories. mAP represents the average precision of all categories, which can be used to judge the performance improvement of the improved model.

[0052] Attached Figure 6 To improve the YOLOv5 model in this embodiment ( Figure 6 a) and unimproved YOLOv5 ( Figure 6 b) The mAP curve of the model shows that after adding the channel attention module SE module, improving the SWPC3 module and the EIoU loss function, the performance is significantly improved compared to before the improvement, and the mAP value is increased by 2.2% compared with the YOLOv5 model before the improvement.

[0053] Attached Figure 7 and 8The PR curves of the YOLOv5 model before improvement and the improved YOLOv5 model of the present invention are shown in the embodiment. It can be seen that the mAP value of the improved YOLOv5 model is improved by 2.2% compared with the YOLOv5 model before improvement. Due to the complex defect background in the defective PCB image set and the small size of most defects, the YOLOv5 model has the problems of false detection and missed detection, and cannot be well adapted to the task of industrial PCB defect detection; therefore, the present invention improves the YOLOv5 model, while improving the detection accuracy, appropriately reducing the amount of network parameters, and improving the recognition accuracy of small targets by obtaining position information, meeting the expected recognition requirements.

[0054] Obviously, the above embodiments of the present invention are merely examples for clearly illustrating the present invention, and are not intended to limit the embodiments of the present invention. For those skilled in the art, other different forms of changes or modifications can be made based on the above description. It is not necessary and impossible to list all the embodiments here. Any modifications, equivalent substitutions and improvements made within the spirit and principles of the present invention should be included in the protection scope of the claims of the present invention.

Claims

1. A defective PCB detection method based on the YOLOv5 model, characterized in that: The following steps are involved: S1: Obtain defective PCB image set; S2: Improved YOLOv5 model: Add a channel attention module SE after each C3 module in the original YOLOv5 model Backbone network; Replace the C3 module in the Neck network with the SWPC3 module; The SWPC3 module uses the DWConv module to replace the Conv modules on the two branches of the C3 module, and inserts an SPDConv module into each of the two branches before concat; Replace the CIoU loss function with the EIoU loss function; S3: Train the improved YOLOv5 model using defective PCB image set; S4: Input the PCB image to be identified into the trained improved YOLOv5 model to obtain the PCB defect recognition result.

2. According to the defective PCB detection method based on the YOLOv5 model of claim 1, it is characterized in that: The defective PCB image set includes a plurality of PCB images and a defect type corresponding to each PCB image.

3. According to the defective PCB detection method based on the YOLOv5 model of claim 1, it is characterized in that: Step 1 is as follows: The PCB defect image set to be identified is the PCB defect data set PKU-Market-PCB. The PCB defect data set PKU-Market-PCB is preprocessed to obtain the processed PCB defect data set PKU-Market-PCB. The PCB defect data set PKU-Market-PCB is divided into a training set, a test set and a validation set in a ratio of 8:1:

1.

4. According to the defective PCB detection method based on the YOLOv5 model of claim 3, it is characterized in that: The image preprocessing of the PCB defect dataset PKU-Market-PCB is performed as follows: The duplicate images of the PCB defect dataset PKU-Market-PCB are removed, and the brightness, rotation, cropping, translation and mirroring of the remaining PCB defect images are adjusted to obtain the processed PCB defect dataset PKU-Market-PCB.

5. According to the defective PCB detection method based on the YOLOv5 model of claim 1, it is characterized in that: The method adds a channel attention module SE after each C3 module in the Backbone network of the original YOLOv5 model, specifically: Add a channel attention module SE module after each C3 module in the Backbone network; the channel attention module SE module includes global average pooling, excitation operation and scaling; The expressions of the global average pooling, excitation operation and scaling are: Among them, the input feature map is , the number of channels is , represents the ReLU activation function, is the weight matrix used for dimensionality reduction, is the weight matrix used for dimensionality increase, is the Sigmoid activation function, is the weight vector in the channel dimension.

6. According to the defective PCB detection method based on the YOLOv5 model of claim 1, it is characterized in that: The DWConv module is used to replace the first two Conv modules in the C3 module in the Neck network, specifically: Use the DWConv module to replace the first two Conv modules in the C3 module in the Neck network, and insert the SPDConv module before the two branches enter concat; get the SWPC3 module; The parameter expressions of the depth separable DWConv module and the spatial depth conversion convolution SPDConv module are respectively: Among them, the number of input channels is , the number of output channels is , the number of groups is , the convolution kernel size is .

7. According to the defective PCB detection method based on the YOLOv5 model of claim 1, it is characterized in that: The EIoU loss function is specifically: Replace the CIoU loss function with the EIoU loss function; The EIoU loss function expression is: in, is the IOU loss; For distance loss, is the height-width loss, and is the width and height of the predicted box and the actual minimum bounding rectangle, is the Euclidean distance between the center of the predicted box and the center of the true box, and are the width of the predicted box and the real box respectively, and are the heights of the predicted box and the true box respectively.

Citation Information

Patent Citations

  • PCB surface defect detection method based on improved YOLOv5 algorithm

    CN116309427A

  • Pedestrian-first traffic light real-time timing method based on target detection

    CN117831318A

  • Steel plate surface defect detection method based on improved YOLOv8

    CN118279272A

  • KR20230153668A

Cited By

  • Cylinder inner wall wear detection method based on detail perception sampling attention module

    CN119477920A

  • Cylinder inner wall wear detection method based on detail-aware sampling attention module

    CN119477920B