Method, device, storage medium and electronic device for training model
By adding a prediction module with a larger feature map scale in the YOLO layer and using the CIoU boundary loss function to optimize model training, the problem of missed detection of printed circuit board defects caused by the enlargement of the receptive field of small targets in the deep learning algorithm is solved, and the recognition accuracy is improved.
Patent Information
- Application Number
- CN202310028098.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-01-09
- Publication Date
- 2025-09-26
- Estimated Expiration
- 2043-01-09
AI Technical Summary
The deep convolution in the deep learning algorithm will cause the receptive field of small targets to continue to expand. After multiple downsampling, the target feature map will be reduced, resulting in missed detection of printed circuit board defects and poor recognition result accuracy.
A prediction module with a larger feature map scale is added to the YOLO layer. By adjusting the number and feature scale of the prediction modules and combining the CIoU boundary loss function, the model training is optimized to improve the detection accuracy.
The missed detection of printed circuit board defects is reduced and the accuracy of recognition results is improved.
Smart Images

Figure CN116188940B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of printed circuit board detection, and more specifically, to a method, device, storage medium, and electronic device for training a model. Background Art
[0002] In recent years, with the continuous development of deep learning, deep learning-based PCB defect detection methods have been mainly divided into single-stage PCB defect detection methods and two-stage PCB defect detection methods. Two-stage PCB defect detection methods first perform region recommendation and then target classification. These algorithms generally have slow detection speed but high detection accuracy, such as the RCNN series of algorithms. Single-stage PCB defect detection methods directly regress the target location and category and output defect detection results. These algorithms are generally fast but have slightly lower detection accuracy, such as the YOLO series of algorithms. With the continuous improvement of single-stage object detection methods, single-stage object detection methods are increasingly used in industry. However, PCB defects have a small surface area. For small target areas, the deep convolution layers in deep learning algorithms will continuously expand the receptive field of small targets. After multiple downsampling, the target feature map will continue to decrease, which can easily lead to missed detection of PCB defects and poor recognition accuracy.
[0003] To address the above-mentioned problems, no effective solutions have been proposed so far. Summary of the Invention
[0004] The embodiments of the present application provide a method, device, storage medium, and electronic device for training a model to at least solve the technical problem of missed detection of printed circuit board defects and poor accuracy of recognition results due to the fact that deep convolution in a deep learning algorithm causes the receptive field of a tiny target to continue to expand, and the target feature map is reduced after multiple downsampling.
[0005] According to one aspect of an embodiment of the present application, a method for training a model is provided, including: obtaining a first target detection algorithm model, wherein the YOLO layer of the first target detection algorithm model is provided with a first number of first prediction modules, wherein the scale of the first feature map corresponding to each first prediction module is different; obtaining a first size of a defective part of a first printed circuit board in a historical period and a preset threshold, determining a difference between a minimum value of the clustered first size and the preset threshold, wherein the preset threshold is used to indicate that no additional prediction module critical value is required; when the difference is less than zero, adding a second number of second prediction modules to the YOLO layer in the first target detection algorithm model to obtain a second target detection algorithm model, wherein the scale of the second feature map corresponding to the second prediction module is greater than the maximum scale of the first feature map corresponding to the first prediction module; obtaining a plurality of labeled second printed circuit board images, and performing model training and testing on the second target detection algorithm model based on the plurality of second printed circuit board images to obtain a third target detection algorithm model.
[0006] Optionally, the second target detection algorithm model is trained and tested based on multiple second printed circuit board images to obtain a third target detection algorithm model, including: dividing the multiple second printed circuit boards into a training set and a test set according to a predetermined ratio; training the second target detection algorithm model based on the training set to obtain a first weight value occupied by each layer of the network in the second target detection algorithm model, wherein each layer of the network includes: a Darknet layer network and a YOLO layer network; verifying the validity of the first weight value based on the test set to determine a valid second weight value, and constructing the third target detection algorithm model based on the second weight value.
[0007] Optionally, in the process of training the second target detection algorithm model based on the training set, the loss function adopted by the second target detection algorithm is a CIOU boundary loss function.
[0008] Optionally, the scale of the second feature map corresponding to the second prediction module is determined according to the minimum value corresponding to the first size clustering in the historical period. The smaller the minimum value, the larger the scale of the second feature map corresponding to the second prediction module.
[0009] Optionally, after obtaining the third target detection algorithm model, the above method also includes: obtaining a third printed circuit board image to be detected; using the third target detection algorithm model to analyze the third printed circuit board image to obtain a recognition result of the third printed circuit board image, wherein the recognition result is used to indicate the defect type of the third printed circuit board.
[0010] Optionally, a third target detection algorithm model is used to analyze the third printed circuit board image to obtain a recognition result of the third printed circuit board image, including: clustering the respective third printed circuit board defect sizes in multiple third printed circuit board images into multiple categories of defect sizes based on a clustering algorithm; and evenly distributing the clustered multiple categories of defect sizes to the third target detection algorithm model to obtain a recognition result of the third printed circuit board image.
[0011] Optionally, the identification result includes at least one of the following: line welding leakage, line defect, line open circuit and line short circuit.
[0012] According to another aspect of an embodiment of the present application, a device for training a model is also provided, including: a first acquisition module, used to acquire a first target detection algorithm model, wherein the YOLO layer of the first target detection algorithm model is provided with a first number of first prediction modules, wherein the first feature map scales corresponding to each first prediction module are different; a second acquisition module, used to acquire the first size of the defective part of the first printed circuit board in a historical period and a preset threshold, and determine the difference between the minimum value of the clustered first size and the preset threshold, wherein the preset threshold is used to indicate that no additional prediction module critical value is required; a first determination module, used to add a second number of second prediction modules to the YOLO layer in the first target detection algorithm model to obtain a second target detection algorithm model when the difference is less than zero, wherein the second feature map scale corresponding to the second prediction module is greater than the maximum scale of the first feature map scale corresponding to the first prediction module; a second determination module, used to acquire multiple labeled second printed circuit board images, and perform model training and testing on the second target detection algorithm model based on the multiple second printed circuit board images to obtain a third target detection algorithm model.
[0013] According to another aspect of an embodiment of the present application, a non-volatile storage medium is also provided, the storage medium including a stored program, wherein when the program is running, the device where the storage medium is located is controlled to execute any method of training model.
[0014] According to another aspect of an embodiment of the present application, an electronic device is also provided, including: a processor; a memory for storing processor-executable instructions; wherein the processor is configured to execute instructions to implement any method of training a model.
[0015] In an embodiment of the present application, a first target detection algorithm model is obtained, wherein the YOLO layer of the first target detection algorithm model is provided with a first number of first prediction modules, wherein the first feature map scales corresponding to each first prediction module are different; a first size of a defective part of a first printed circuit board in a historical period and a preset threshold are obtained, and a difference between a minimum value of the clustered first size and the preset threshold is determined, wherein the preset threshold is used to indicate that no additional prediction module critical value is required; when the difference is less than zero, a second number of second prediction modules are added to the YOLO layer in the first target detection algorithm model to obtain a second target detection algorithm model, wherein the second prediction module corresponds to The scale of the second feature map is greater than the maximum scale of the first feature map corresponding to the first prediction module; a plurality of labeled second printed circuit board images are obtained, and a second target detection algorithm model is trained and tested based on the plurality of second printed circuit board images to obtain a third target detection algorithm model, thereby achieving the purpose of adjusting the number of prediction modules and the feature scale according to the size of the printed circuit board, and realizing the technical effect of improving the model recognition accuracy and reducing the missed detection of defects, thereby solving the technical problem of missed detection of printed circuit board defects and poor recognition accuracy caused by the deep convolution in the deep learning algorithm causing the receptive field of small targets to continue to expand and the reduction of the target feature map after multiple downsampling. BRIEF DESCRIPTION OF THE DRAWINGS
[0016] The drawings described herein are used to provide a further understanding of the present application and constitute a part of the present application. The illustrative embodiments of the present application and their descriptions are used to explain the present application and do not constitute an improper limitation on the present application. In the drawings:
[0017] Figure 1 is a flowchart of a method for training a model according to an embodiment of the present application;
[0018] Figure 2 This is a schematic diagram of the basic structure of the YOLO3 algorithm model;
[0019] Figure 3 1 is a flow chart of a printed circuit board defect detection method in one embodiment of the present application;
[0020] Figure 4 This is a schematic diagram of common defects in this application;
[0021] Figure 5 is a structural diagram of a device for training a model according to an embodiment of the present application;
[0022] Figure 6 A schematic block diagram of an example electronic device 600 that can be used to implement embodiments of the present application is shown. DETAILED DESCRIPTION
[0023] In order to enable those skilled in the art to better understand the present invention, the following will clearly and completely describe the technical solutions in the embodiments of the present invention in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments in the present invention, all other embodiments obtained by ordinary technicians in this field without making creative efforts should fall within the scope of protection of this application.
[0024] It should be noted that the terms "first", "second", etc. in the specification and claims of the present application and the above-mentioned drawings are used to distinguish similar objects and are not necessarily used to describe a specific order or sequential order. It should be understood that the data used in this way can be interchangeable where appropriate, so that the embodiments of the present application described herein can be implemented in a sequence other than those illustrated or described herein. In addition, the terms "including" and "having" and any of their variations are intended to cover non-exclusive inclusions, for example, a process, method, system, product or device comprising a series of steps or units is not necessarily limited to those steps or units clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.
[0025] According to an embodiment of the present application, an embodiment of a method for training a model is provided. It should be noted that the steps shown in the flowchart of the accompanying drawings can be executed in a computer system such as a set of computer-executable instructions, and although a logical order is shown in the flowchart, in some cases, the steps shown or described can be executed in an order different from that shown here.
[0026] Figure 1 is a method for training a model according to an embodiment of the present application, such as Figure 1 As shown, the method includes the following steps:
[0027] Step S102: obtaining a first object detection algorithm model, wherein a YOLO layer of the first object detection algorithm model is provided with a first number of first prediction modules, wherein first feature maps corresponding to the first prediction modules have different scales;
[0028] Step S104, obtaining a first size of a defective portion of a first printed circuit board in a historical period and a preset threshold, and determining a difference between a minimum value of the clustered first sizes and the preset threshold, wherein the preset threshold is used to indicate a critical value at which no additional prediction module is required;
[0029] It can be understood that the first size of defects after clustering the first printed circuit board in the historical period can be used to determine whether to add a prediction module. For example, if the minimum value of the first size after clustering is less than the preset threshold, a prediction module with a larger scale (i.e., a prediction module with higher detection accuracy) can be set to meet the test requirements of different sizes.
[0030] It is easy to notice that the defect size after clustering can basically predict the size of printed circuit board defects that may be detected now or in the future. Therefore, the size of the first printed circuit board defect after clustering can be used to determine whether to add a prediction module with a larger feature scale.
[0031] Step S106: If the difference is less than zero, a second number of second prediction modules is added to the YOLO layer in the first object detection algorithm model to obtain a second object detection algorithm model, wherein the second feature map scale corresponding to the second prediction module is larger than the maximum scale of the first feature map scale corresponding to the first prediction module. Preferably, the second number is 1;
[0032] As you can understand, if the difference is greater than or equal to zero, it means that the current prediction module meets the accuracy requirements, and no additional prediction modules are required. If the difference is less than zero, it means that the defect image of the inspected PCB is relatively small, that is, the accuracy requirement is relatively high, and therefore, a new prediction module is needed to inspect smaller PCBs.
[0033] For example, if the first size pixel of the defective part of the first printed circuit board in the historical period is 5×5 and the preset pixel threshold is 10×10, and the difference is less than 0, it can be determined that the number of prediction modules to be added now is 1, and the feature scale is 104×104.
[0034] Step S108 , obtaining a plurality of labeled second printed circuit board images, and performing model training and testing on the second object detection algorithm model based on the plurality of second printed circuit board images to obtain a third object detection algorithm model.
[0035] It should be noted that the above-mentioned first target detection algorithm model includes but is not limited to: YOLO3 algorithm model, and may also be YOLO4 algorithm model and YOLO5 algorithm model, etc.
[0036] Now let’s take the YOLO3 algorithm model as an example to introduce it. Figure 2 This is a schematic diagram of the basic structure of the YOLO3 algorithm model, such as Figure 2As shown in the figure, the algorithm model is mainly composed of two networks, namely Darknet53 network and YOLO layer network. Darknet53 is mainly used to extract input image features. It is composed of a series of 1×1 and 3×3 convolutional layers, and introduces a residual control structure, breaking through the limitation of the number of convolutional neural network layers and being able to extract image features well; the YOLO layer network is mainly responsible for the function of detecting objects. It has three prediction modules of different scales, and uses the image feature fusion pyramid idea to splice feature maps of different scales for information transmission. It fuses high-channel and small-size feature semantics into low-channel and large-size feature semantic information through upsampling and splicing.
[0037] like Figure 2 As shown in the figure, assuming that the three scale feature maps finally output by the original YOLOv3 are 13×13, 26×26 and 52×52 respectively, the present application can now add an output scale 104×104 module. Specifically, a prediction scale can be derived from Res2 and fused with the upsampling of the third prediction scale feature vector to form an output feature map with a scale of 104×104.
[0038] In the method for training the model, a first target detection algorithm model is obtained, wherein the YOLO layer of the first target detection algorithm model is provided with a first number of first prediction modules, wherein the first feature map scales corresponding to each first prediction module are different; the first size of the first printed circuit board defect detected in the historical period and the preset threshold are obtained, and the difference between the minimum value of the clustered first size and the preset threshold is determined, wherein the preset threshold is used to indicate that no additional prediction module critical value is required; when the difference is less than zero, a second number of second prediction modules are added to the YOLO layer in the first target detection algorithm model to obtain a second target detection algorithm model, wherein the second prediction module is for The scale of the second feature map corresponding to the prediction module is greater than the maximum scale of the first feature map corresponding to the first prediction module; a plurality of labeled second printed circuit board images are obtained, and a second target detection algorithm model is trained and tested based on the plurality of second printed circuit board images to obtain a third target detection algorithm model, thereby achieving the purpose of adjusting the number of prediction modules and the feature scale according to the size of the printed circuit board, and realizing the technical effect of improving the model recognition accuracy and reducing the missed detection of defects, thereby solving the technical problem that the deep convolution in the deep learning algorithm will cause the receptive field of small targets to continue to expand, and the target feature map is reduced after multiple downsampling, resulting in the missed detection of printed circuit board defects and poor recognition result accuracy.
[0039] In some embodiments of the present application, a third target detection algorithm model is obtained by performing model training and testing on the second target detection algorithm model based on multiple second printed circuit board images, which can be determined in the following manner. Specifically, the multiple second printed circuit boards can be divided into a training set and a test set according to a predetermined ratio; the second target detection algorithm model is trained based on the training set to obtain a first weight value occupied by each layer of the network in the second target detection algorithm model, wherein each layer of the network includes: a Darknet layer network and a YOLO layer network; the validity of the first weight value is verified based on the test set to determine a valid second weight value, and the third target detection algorithm model is constructed based on the second weight value.
[0040] For example, Figure 3 FIG. 1 is a flow chart of a printed circuit board defect detection method in an embodiment of the present application. Figure 3 As shown, the multiple labeled second printed circuit board images can be divided into a training set and a test set according to a predetermined ratio, for example, a ratio of 2:1, and then the second target detection algorithm model (i.e., the improved target detection algorithm model) is trained based on the training set to obtain the weight values of each layer of the network (i.e., the authority detection weights), and the validity of the weight values of the second target detection algorithm model is verified based on the test set to obtain the final verified effective detection weights, and then the detection weights can be used to construct a defect detection software system. Finally, the image collected by the circuit board image acquisition device is input into the defect detection software system to obtain the defect detection results.
[0041] It should be noted that, in the process of training the second target detection algorithm model based on the training set, the loss function adopted by the second target detection algorithm is the CIOU boundary loss function.
[0042] It can be understood that the scale of the second feature map corresponding to the second prediction module is determined according to the minimum value corresponding to the first size clustering in the historical period. The smaller the minimum value, the larger the scale of the second feature map corresponding to the second prediction module.
[0043] Taking YOLO3 as an example in the above embodiment, the IoU boundary loss function in the original YOLO3 can be replaced by the CIoU boundary loss function. It should be noted that IoU is the result of dividing the overlapping part of the two target areas by the set part of the two target areas. It is a standard for measuring the accuracy of detecting target objects on a specific data set. However, IoU does not take into account the position information between the two frames. When the predicted frame and the true frame do not intersect, the IoU is 0, and the model will not be able to continue to optimize, which greatly increases the missed detection rate of defect detection. CIoU increases the loss calculation of the detection frame scale and increases the loss calculation of length and width, so that the predicted frame will be more consistent with the true frame. The calculation formula of CIoU is as follows:
[0044]
[0045]
[0046]
[0047] It is understandable that the appearance image of the printed circuit board defect is small. By selecting the CIoU boundary loss function, its location can be determined more accurately, which can greatly reduce the missed detection rate.
[0048] In some embodiments of the present application, after obtaining the third target detection algorithm model, a third printed circuit board image to be inspected can also be obtained; the third target detection algorithm model is used to analyze the third printed circuit board image to obtain a recognition result of the third printed circuit board image, wherein the recognition result is used to indicate the defect type of the third printed circuit board.
[0049] In some optional embodiments of the present application, a third target detection algorithm model is used to analyze the third printed circuit board image to obtain a recognition result of the third printed circuit board image. This can be achieved in the following manner. Specifically, based on a clustering algorithm, the defect scales of each third circuit board in multiple third printed circuit boards can be clustered into multiple categories of defect sizes; and the clustered multiple categories of defect sizes are evenly distributed to the third target detection algorithm model to obtain a recognition result of the third printed circuit board image.
[0050] For example, there are four detection scales, namely the aforementioned 13×13, 26×26, and 52×52, as well as an additional output scale module of 104×104. For these four detection scales, a clustering algorithm can be used to cluster the labeled defect appearance image sizes, and the 12 prior frames obtained by clustering are evenly distributed to the four detection scales. The added 104×104 output feature map can detect smaller defects, and the clustering algorithm is used to cluster the actual size of the defect appearance image, which can make the detection model converge more quickly, thereby improving the efficiency of defect detection.
[0051] It should be noted that the identification result includes at least one of the following: line welding failure, line defect, line open circuit and line short circuit. Figure 4 This is a schematic diagram of common defects in this application, such as Figure 4 As shown, from left to right are schematic diagrams of line welding leakage, line defect, line open circuit and line short circuit.
[0052] Figure 5 is a device for training a model according to an embodiment of the present application, such as Figure 5 As shown, the device includes:
[0053] A first acquisition module 50 is configured to acquire a first object detection algorithm model, wherein a YOLO layer of the first object detection algorithm model is provided with a first number of first prediction modules, wherein first feature maps corresponding to the first prediction modules have different scales;
[0054] A second acquisition module 52 is configured to obtain a first size of a defective portion of a first printed circuit board during a historical period and a preset threshold, and determine a difference between a minimum value of the clustered first sizes and the preset threshold, wherein the preset threshold is used to indicate a critical value that does not require a prediction module.
[0055] A first determining module 54 is configured to, when the difference is less than zero, add a second number of second prediction modules to the YOLO layer in the first object detection algorithm model to obtain a second object detection algorithm model, wherein the scale of the second feature map corresponding to the second prediction module is greater than the maximum scale of the first feature map corresponding to the first prediction module;
[0056] The second determination module 56 is configured to obtain a plurality of labeled second printed circuit board images, and perform model training and testing on the second target detection algorithm model based on the plurality of second printed circuit board images to obtain a third target detection algorithm model.
[0057] In the device for training the model, a first acquisition module 50 is used to obtain a first target detection algorithm model, wherein the YOLO layer of the first target detection algorithm model is provided with a first number of first prediction modules, wherein the first feature map scales corresponding to each first prediction module are different; a second acquisition module 52 is used to obtain a first size of a defective part of a first printed circuit board in a historical period and a preset threshold, and determine the difference between the minimum value of the clustered first size and the preset threshold, wherein the preset threshold is used to indicate that no additional prediction module critical value is required; a first determination module 54 is used to add a second number of second prediction modules to the YOLO layer in the first target detection algorithm model to obtain a second target detection algorithm model when the difference is less than zero, wherein , the scale of the second feature map corresponding to the second prediction module is greater than the maximum scale of the first feature map corresponding to the first prediction module; the second determination module 56 is used to obtain a plurality of labeled second printed circuit board images, and perform model training and testing on the second target detection algorithm model based on the plurality of second printed circuit board images to obtain a third target detection algorithm model, thereby achieving the purpose of adjusting the number of prediction modules and the feature scale according to the size of the printed circuit board, and realizing the technical effect of improving the model recognition accuracy and reducing the missed detection of defects, thereby solving the technical problem that the deep convolution in the deep learning algorithm will cause the receptive field of small targets to continue to expand, and the target feature map is reduced after multiple downsampling, resulting in missed detection of printed circuit board defects and poor recognition result accuracy.
[0058] According to another aspect of an embodiment of the present application, a non-volatile storage medium is also provided, the storage medium including a stored program, wherein when the program is running, the device where the storage medium is located is controlled to execute any method of training model.
[0059] Specifically, the above storage medium is used to store program instructions for the following functions to implement the following functions:
[0060] A first target detection algorithm model is obtained, wherein the YOLO layer of the first target detection algorithm model is provided with a first number of first prediction modules, wherein the first feature map scales corresponding to each first prediction module are different; a first size of a defective part of a first printed circuit board in a historical period and a preset threshold are obtained, and a difference between a minimum value in the first size after clustering and the preset threshold is determined, wherein the preset threshold is used to indicate that no additional prediction module critical value is required; when the difference is less than zero, a second number of second prediction modules are added to the YOLO layer in the first target detection algorithm model to obtain a second target detection algorithm model, wherein the second feature map scale corresponding to the second prediction module is greater than the maximum scale of the first feature map corresponding to the first prediction module; a plurality of labeled second printed circuit board images are obtained, and model training and testing of the second target detection algorithm model are performed based on the plurality of second printed circuit board images to obtain a third target detection algorithm model.
[0061] Alternatively, in this embodiment, the storage medium may include, but is not limited to, electronic, magnetic, optical, electromagnetic, infrared, or semiconductor systems, devices, or any suitable combination thereof. More specific examples of the storage medium may include an electrical connection based on one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination thereof.
[0062] In an exemplary embodiment of the present application, a computer program product is also provided, including a computer program, which implements any of the above-mentioned methods for training a model when executed by a processor.
[0063] Optionally, the computer program may implement the following steps when executed by a processor:
[0064] A first target detection algorithm model is obtained, wherein the YOLO layer of the first target detection algorithm model is provided with a first number of first prediction modules, wherein the first feature map scales corresponding to each first prediction module are different; a first size of a defective part of a first printed circuit board in a historical period and a preset threshold are obtained, and a difference between a minimum value in the first size after clustering and the preset threshold is determined, wherein the preset threshold is used to indicate that no additional prediction module critical value is required; when the difference is less than zero, a second number of second prediction modules are added to the YOLO layer in the first target detection algorithm model to obtain a second target detection algorithm model, wherein the second feature map scale corresponding to the second prediction module is greater than the maximum scale of the first feature map corresponding to the first prediction module; a plurality of labeled second printed circuit board images are obtained, and model training and testing of the second target detection algorithm model are performed based on the plurality of second printed circuit board images to obtain a third target detection algorithm model.
[0065] According to an embodiment of the present application, an electronic device is provided, which includes: at least one processor; and a memory communicatively connected to the at least one processor; wherein the memory stores instructions that can be executed by the at least one processor, and the instructions are executed by the at least one processor to enable the at least one processor to execute any of the above-mentioned methods for training a model.
[0066] Optionally, the electronic device may further include a transmission device and an input / output device, wherein the transmission device is connected to the processor, and the input / output device is connected to the processor.
[0067] Figure 6 A schematic block diagram of an example electronic device 600 that can be used to implement an embodiment of the present application is shown. The electronic device is intended to represent various forms of digital computers, such as laptop computers, desktop computers, workstations, personal digital assistants, servers, blade servers, mainframe computers, and other suitable computers. The electronic device can also represent various forms of mobile devices, such as personal digital assistants, cellular phones, smart phones, wearable devices, and other similar computing devices. The components shown herein, their connections and relationships, and their functions are merely examples and are not intended to limit the implementation of the present application described and / or claimed herein.
[0068] like Figure 6As shown, the device 600 includes a computing unit 601, which can perform various appropriate actions and processes according to a computer program stored in a read-only memory (ROM) 602 or a computer program loaded from a storage unit 608 into a random access memory (RAM) 603. Various programs and data required for the operation of the device 600 can also be stored in the RAM 603. The computing unit 601, the ROM 602, and the RAM 603 are connected to each other via a bus 604. An input / output (I / O) interface 605 is also connected to the bus 604.
[0069] Various components in device 600 are connected to I / O interface 605, including an input unit 606, such as a keyboard, mouse, etc.; an output unit 607, such as various types of displays, speakers, etc.; a storage unit 608, such as a magnetic disk, optical disk, etc.; and a communication unit 609, such as a network card, modem, wireless communication transceiver, etc. The communication unit 609 allows device 600 to exchange information / data with other devices via a computer network such as the Internet and / or various telecommunication networks.
[0070] The computing unit 601 can be a variety of general and / or special processing components with processing and computing capabilities. Some examples of the computing unit 601 include, but are not limited to, a central processing unit (CPU), a graphics processing unit (GPU), various dedicated artificial intelligence (AI) computing chips, various computing units that run machine learning model algorithms, digital signal processors (DSPs), and any appropriate processors, controllers, microcontrollers, etc. The computing unit 601 performs the various methods and processes described above, such as the method for training a model. For example, in some embodiments, the method for training a model can be implemented as a computer software program that is tangibly contained in a machine-readable medium, such as a storage unit 608. In some embodiments, part or all of the computer program can be loaded and / or installed on the device 600 via the ROM 602 and / or the communication unit 609. When the computer program is loaded into the RAM 603 and executed by the computing unit 601, one or more steps of the method for training a model described above can be performed. Alternatively, in other embodiments, the computing unit 601 can be configured to perform the method for training a model by any other appropriate means (e.g., by means of firmware).
[0071] Various embodiments of the systems and techniques described herein can be implemented in digital electronic circuit systems, integrated circuit systems, field programmable gate arrays (FPGAs), application specific integrated circuits (ASICs), application specific standard products (ASSPs), system-on-chip systems (SOCs), programmable logic devices (CPLDs), computer hardware, firmware, software, and / or combinations thereof. These various embodiments can include being implemented in one or more computer programs that are executable and / or interpreted on a programmable system that includes at least one programmable processor, which can be a special purpose or general purpose programmable processor that can receive data and instructions from a storage system, at least one input device, and at least one output device, and transmit data and instructions to the storage system, the at least one input device, and the at least one output device.
[0072] The program code for implementing the methods of the present application can be written in any combination of one or more programming languages. Such program code can be provided to a processor or controller of a general-purpose computer, a special-purpose computer, or other programmable data processing device, so that when the program code is executed by the processor or controller, the functions / operations specified in the flow charts and / or block diagrams are implemented. The program code can be executed entirely on the machine, partially on the machine, as a stand-alone software package, partially on the machine and partially on a remote machine, or entirely on a remote machine or server.
[0073] In the context of the present application, a machine-readable medium can be a tangible medium that can contain or store a program for use by an instruction execution system, device or equipment or used in combination with an instruction execution system, device or equipment. A machine-readable medium can be a machine-readable signal medium or a machine-readable storage medium. A machine-readable medium can include, but is not limited to, an electronic, magnetic, optical, electromagnetic, infrared or semiconductor system, device or equipment, or any suitable combination of the foregoing. A more specific example of a machine-readable storage medium can include an electrical connection based on one or more lines, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.
[0074] To provide interaction with a user, the systems and techniques described herein can be implemented on a computer having: a display device (e.g., a CRT (cathode ray tube) or LCD (liquid crystal display) monitor) for displaying information to the user; and a keyboard and pointing device (e.g., a mouse or trackball) through which the user can provide input to the computer. Other types of devices can also be used to provide interaction with the user; for example, the feedback provided to the user can be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user can be received in any form (including acoustic input, voice input, or tactile input).
[0075] The systems and techniques described herein can be implemented in a computing system that includes back-end components (e.g., as a data server), or a computing system that includes middleware components (e.g., an application server), or a computing system that includes front-end components (e.g., a user computer having a graphical user interface or a web browser through which a user can interact with implementations of the systems and techniques described herein), or a computing system that includes any combination of such back-end components, middleware components, or front-end components. The components of the system can be interconnected by any form or medium of digital data communication (e.g., a communication network). Examples of communication networks include a local area network (LAN), a wide area network (WAN), and the Internet.
[0076] A computer system may include a client and a server. The client and server are generally remote from each other and typically interact through a communication network. The client-server relationship arises through computer programs running on the respective computers and having a client-server relationship with each other. The server may be a cloud server, a server in a distributed system, or a server integrated with a blockchain.
[0077] In a related embodiment of the present application, a first target detection algorithm model is obtained, wherein the YOLO layer of the first target detection algorithm model is provided with a first number of first prediction modules, wherein the first feature map scales corresponding to each first prediction module are different; the first size of the defective part of the first printed circuit board in the historical period and the preset threshold are obtained, and the difference between the minimum value of the clustered first size and the preset threshold is determined, wherein the preset threshold is used to indicate that no additional prediction module critical value is required; when the difference is less than zero, a second number of second prediction modules are added to the YOLO layer in the first target detection algorithm model to obtain a second target detection algorithm model, wherein the second prediction module is for The scale of the second feature map corresponding to the prediction module is greater than the maximum scale of the first feature map corresponding to the first prediction module; a plurality of labeled second printed circuit board images are obtained, and a second target detection algorithm model is trained and tested based on the plurality of second printed circuit board images to obtain a third target detection algorithm model, thereby achieving the purpose of adjusting the number of prediction modules and the feature scale according to the size of the printed circuit board, and realizing the technical effect of improving the model recognition accuracy and reducing the missed detection of defects, thereby solving the technical problem that the deep convolution in the deep learning algorithm will cause the receptive field of small targets to continue to expand, and the target feature map is reduced after multiple downsampling, resulting in the missed detection of printed circuit board defects and poor recognition result accuracy.
[0078] The serial numbers of the above-mentioned embodiments of the present application are for description only and do not represent the advantages or disadvantages of the embodiments.
[0079] In the above embodiments of the present application, the description of each embodiment has its own focus. For parts that are not described in detail in a certain embodiment, please refer to the relevant description of other embodiments.
[0080] In the several embodiments provided in this application, it should be understood that the disclosed technical content can be implemented in other ways. Among them, the device embodiments described above are only exemplary. For example, the division of the units can be a logical function division. In actual implementation, there may be other division methods, such as multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of units or modules, which can be electrical or other forms.
[0081] The units described as separate components may or may not be physically separate, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed across multiple units. Some or all of the units may be selected according to actual needs to achieve the purpose of the present embodiment.
[0082] In addition, the functional units in the various embodiments of the present application may be integrated into a single processing unit, or each unit may exist physically separately, or two or more units may be integrated into a single unit. The aforementioned integrated units may be implemented in the form of hardware or software functional units.
[0083] If the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present application is essentially or the part that contributes to the prior art or all or part of the technical solution can be embodied in the form of a software product, and the computer software product is stored in a storage medium, including a number of instructions for enabling a computer device (which can be a personal computer, a server or a network device, etc.) to execute all or part of the steps of the method described in each embodiment of the present application. The aforementioned storage medium includes: various media that can store program codes, such as a USB flash drive, a read-only memory (ROM), a random access memory (RAM), a mobile hard disk, a magnetic disk or an optical disk.
[0084] The above is only a preferred embodiment of the present application. It should be pointed out that for ordinary technicians in this technical field, several improvements and modifications can be made without departing from the principles of the present application. These improvements and modifications should also be regarded as the scope of protection of the present application.
Claims
1. A method for training a model, characterized in that: include: Obtain a first object detection algorithm model, wherein a YOLO layer of the first object detection algorithm model is provided with a first number of first prediction modules, wherein first feature maps corresponding to the first prediction modules have different scales; Obtaining a first size of a defective portion of a first printed circuit board during a historical period and a preset threshold, and determining a difference between a minimum value of the clustered first sizes and the preset threshold, wherein the preset threshold is used to indicate a critical value at which no additional prediction module is required; When the difference is less than zero, adding a second number of second prediction modules to the YOLO layer in the first object detection algorithm model to obtain a second object detection algorithm model, wherein the scale of the second feature map corresponding to the second prediction module is greater than the maximum scale of the first feature map corresponding to the first prediction module; A plurality of labeled second printed circuit board images are obtained, and model training and testing are performed on the second target detection algorithm model based on the plurality of second printed circuit board images to obtain a third target detection algorithm model.
2. The method according to claim 1, characterized in that The second target detection algorithm model is trained and tested based on the plurality of second printed circuit board images to obtain a third target detection algorithm model, including: Dividing the plurality of second printed circuit boards into a training set and a test set according to a predetermined ratio; Training the second target detection algorithm model based on the training set to obtain a first weight value occupied by each layer network in the second target detection algorithm model, wherein the each layer network includes: a Darknet layer network and a YOLO layer network; The validity of the first weight value is verified based on the test set to determine a valid second weight value, and the third target detection algorithm model is constructed based on the second weight value.
3. The method according to claim 2, characterized in that In the process of training the second target detection algorithm model based on the training set, the loss function adopted by the second target detection algorithm is the CIOU boundary loss function.
4. The method according to claim 1, wherein The scale of the second feature map corresponding to the second prediction module is determined according to the minimum value corresponding to the first size clustering in the historical period. The smaller the minimum value, the larger the scale of the second feature map corresponding to the second prediction module.
5. The method according to claim 1, wherein After obtaining the third target detection algorithm model, the method further includes: Acquiring an image of a third printed circuit board to be inspected; The third printed circuit board image is analyzed using the third target detection algorithm model to obtain a recognition result of the third printed circuit board image, wherein the recognition result is used to indicate a defect type of the third printed circuit board.
6. The method according to claim 5, characterized in that Analyzing the third printed circuit board image using the third target detection algorithm model to obtain a recognition result of the third printed circuit board image includes: clustering each third printed circuit board defect size in the plurality of third printed circuit board images into multiple categories of defect sizes based on a clustering algorithm; The clustered multiple defect sizes are evenly distributed to a third target detection algorithm model to obtain a recognition result of the third printed circuit board image.
7. The method according to claim 5, characterized in that The identification result includes at least one of the following: line welding leakage, line defect, line open circuit and line short circuit.
8. A device for training a model, characterized in that: include: A first acquisition module is configured to acquire a first target detection algorithm model, wherein a YOLO layer of the first target detection algorithm model is provided with a first number of first prediction modules, wherein first feature maps corresponding to the first prediction modules have different scales; A second acquisition module is configured to obtain a first size of a defective portion of a first printed circuit board during a historical period and a preset threshold, and determine a difference between a minimum value of the clustered first sizes and the preset threshold, wherein the preset threshold is used to indicate a critical value for which no additional prediction module is required; A first determination module is configured to, when the difference is less than zero, add a second number of second prediction modules to the YOLO layer in the first object detection algorithm model to obtain a second object detection algorithm model, wherein the scale of the second feature map corresponding to the second prediction module is greater than the maximum scale of the first feature map corresponding to the first prediction module; The second determination module is used to obtain multiple labeled second printed circuit board images, and perform model training and testing on the second target detection algorithm model based on the multiple second printed circuit board images to obtain a third target detection algorithm model.
9. A non-volatile storage medium, characterized in that: The storage medium includes a stored program, wherein when the program is running, the device where the storage medium is located is controlled to execute the method for training a model according to any one of claims 1 to 7.
10. An electronic device, characterized in that: include: processor; a memory for storing instructions executable by the processor; The processor is configured to execute the instructions to implement the method for training a model as described in any one of claims 1 to 7.
Citation Information
Patent Citations
PCB defect image detection method based on improved YOLOv3
CN113962933A
Printed circuit board defect detection method based on improved YOLOv5s
CN114820486A