Defect detection model training method, defect detection method and related device

Through the target detection network and network loss value update technology, a model that can detect a variety of defects is quickly trained, which solves the problem of bottle cap detection accuracy and speed in the existing technology and achieves efficient and accurate defect identification.

CN111814850BActive Publication Date: 2024-10-18ZHEJIANG DAHUA TECH CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202010573557.X
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2020-06-22
Publication Date
2024-10-18
Estimated Expiration
2040-06-22

AI Technical Summary

Technical Problem

The existing technology relies on manual recognition and traditional image processing in bottle cap detection, resulting in reduced accuracy and slow speed of detection results, and cannot effectively identify multiple defects.

Method used

The target detection network is used to detect the training sample images, the distance between the true value frame and the detection frame is used to select the target detection frame, the model parameters are updated based on the network loss value, and a model that can detect a variety of defects is quickly trained.

Benefits of technology

It achieves high-efficiency and high-accuracy defect detection, reduces the amount of calculation, and improves the recognition speed and accuracy of bottle cap detection.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN111814850B_ABST
    Figure CN111814850B_ABST
Patent Text Reader

Abstract

The present application discloses a defect detection model training method, a defect detection method and a related device, including: obtaining at least one training sample image, wherein the training sample image is annotated with at least one first truth box corresponding to at least one type of defect; using a target detection network to detect the training sample image to obtain a first detection result, wherein the first detection result includes a first detection box corresponding to the defect; using the distance between the first truth box and the first detection box, selecting at least part of the first detection box as a target detection box; determining a network loss value based on the target detection box and the first truth box, and using the network loss value to update the parameters of the target detection network to obtain a final defect detection model. The technical solution provided by the present application can quickly and accurately train a defect detection model that can detect multiple defects at the same time.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of defect detection, and in particular to a defect detection model training method, a defect detection method and related devices. Background Art

[0002] With the rapid development of the intelligent manufacturing industry, computer vision and image processing technology have become one of the main means of post-process inspection of products. For example, in the manufacturing process of bottle caps, there are various problems such as broken bottle caps, scratches, slipping, abnormal coding, abnormal labeling, etc. If the problematic bottle caps cannot be screened out immediately, the appearance of the finished bottle caps will be affected at the least, and the preservation of the products sealed by the bottle caps will be affected at the worst. For the problem of bottle cap detection, most monitoring methods now use manual recognition, relying on the naked eye of the staff to identify and locate the wine bottles, and some will use traditional image processing methods for screening. However, these methods have obvious disadvantages. For example, if the staff performs object recognition for a long time, they will inevitably become fatigued and their attention will decrease. This will have a certain impact on the accuracy of the test results and reduce the recognition rate of problematic bottle caps; in addition, the speed of staff recognition with the naked eye is relatively slow, so a technical solution that can solve the above problems is needed. Summary of the invention

[0003] The main technical problem solved by the present application is to provide a defect detection model training method, a defect detection method and related devices, which can quickly train a defect detection model for detecting multiple defects.

[0004] In order to solve the above technical problems, a technical solution adopted by the present application is: to provide a defect detection model training method, the method comprising:

[0005] Acquire at least one training sample image, wherein the training sample image is annotated with at least one first truth value box corresponding to at least one type of defect;

[0006] Detecting the training sample image using an object detection network to obtain a first detection result, wherein the first detection result includes a first detection frame corresponding to the defect;

[0007] Selecting at least a portion of the first detection frame as a target detection frame by using a distance between the first true value frame and the first detection frame;

[0008] A network loss value is determined based on the target detection frame and the first true value frame, and the network loss value is used to update the parameters of the target detection network to obtain a final defect detection model.

[0009] In order to solve the above technical problems, another technical solution adopted by the present application is: to provide a defect detection method, the method comprising:

[0010] Acquire an image to be detected by photographing the object to be detected;

[0011] Performing defect detection on the image to be detected using a defect detection model to obtain a defect detection result;

[0012] Wherein, the object to be detected is a bottle cap, and / or the defect detection model is a model trained by any of the methods described above.

[0013] To solve the above technical problems, another technical solution adopted by the present application is: providing a defect detection model training device, the device comprising a coupled memory and a processor, wherein the memory comprises a local storage and stores a computer program;

[0014] The processor is used to run the computer program to execute the defect detection model training method as described above.

[0015] In order to solve the above technical problems, another technical solution adopted by the present application is: to provide a defect detection device, the device comprising a coupled memory and a processor, wherein:

[0016] The memory includes local storage and stores a computer program;

[0017] The processor is used to run the computer program to execute the defect detection method as described above.

[0018] To solve the above technical problems, another technical solution adopted in the present application is: providing a computer storage medium, wherein the computer storage medium stores a computer program that can be executed by a processor, and the computer program is used to implement the defect detection model training method or defect detection method as described above.

[0019] Compared with the solutions in the prior art, the technical solution provided in the present application obtains at least one training sample image and uses a target detection network to detect the training sample image to obtain a first detection result including a first detection frame corresponding to the defect, and then uses the distance between the first true value frame and the first detection frame to select at least part of the first detection frame as the target detection frame, determines the network loss value based on the target detection frame and the first true value frame, and uses the network loss value to update the parameters of the target detection network to obtain the final defect detection model. Compared with the solutions in the prior art, a defect detection model that can be trained quickly and can efficiently detect multiple defects with a high accuracy can be obtained. BRIEF DESCRIPTION OF THE DRAWINGS

[0020] Figure 1 This is a flow chart of an embodiment of a defect detection model training method of the present application;

[0021] Figure 2 This is a flow chart of another embodiment of a defect detection model training method of the present application;

[0022] Figure 3 This is a flow chart of another embodiment of a defect detection model training method of the present application;

[0023] Figure 4 This is a flow chart of another embodiment of a defect detection model training method of the present application;

[0024] Figure 5 This is a flow chart of another embodiment of a defect detection model training method of the present application;

[0025] Figure 6 This is a flow chart of another embodiment of a defect detection model training method of the present application;

[0026] Figure 7 This is a flow chart of another embodiment of a defect detection model training method of the present application;

[0027] Figure 8 This is a flow chart of a defect detection method in an embodiment of the present application;

[0028] Fig. 9 This is a structural diagram of an embodiment of a defect detection model training device of the present application;

[0029] Fig.10 This is a structural schematic diagram of an embodiment of a defect detection device of the present application;

[0030] Fig.11 This is a structural schematic diagram of a computer storage medium in an embodiment of the present application. DETAILED DESCRIPTION

[0031] The technical solutions in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application. It is to be understood that the specific embodiments described herein are only used to explain the present application, rather than to limit the present application. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in the field without making creative work are within the scope of protection of the present application.

[0032] In the description of the present application, the meaning of "plurality" is at least two, such as two, three, etc., unless otherwise clearly and specifically limited. In addition, the terms "including" and "having" and any variations thereof are intended to cover non-exclusive inclusions. For example, a process, method, system, product or device that includes a series of steps or units is not limited to the listed steps or units, but optionally includes steps or units that are not listed, or optionally includes other steps or units inherent to these processes, methods, products or devices.

[0033] Reference to "embodiments" herein means that a particular feature, structure, or characteristic described in conjunction with the embodiments may be included in at least one embodiment of the present application. The appearance of the phrase in various locations in the specification does not necessarily refer to the same embodiment, nor is it an independent or alternative embodiment that is mutually exclusive with other embodiments. It is explicitly and implicitly understood by those skilled in the art that the embodiments described herein may be combined with other embodiments.

[0034] See also Figure 1 , Figure 1 This is a flow chart of an embodiment of a defect detection model training method of the present application. In the current embodiment, the method provided by the present application includes:

[0035] S110: Acquire at least one training sample image.

[0036] The training sample image is annotated with at least one first truth value box corresponding to at least one type of defect.

[0037] When training a defect detection model that can detect defects on a certain type of target, it is first necessary to collect sample images of the target to be detected, and the target included in the sample image corresponds to at least one type of defect. The sample image including the target can be captured by an external shooting device and transmitted to the defect detection model training device, or it can be acquired by the defect detection model training device using its own image acquisition unit. The specific configuration of the defect detection model training device shall prevail.

[0038] In the current embodiment, the sample image at least includes the original RGB image. It is understandable that the type of sample image is not limited to only the original RGB image. When the sample image is the original RGB image, the training sample image can be obtained after marking at least one type of defect in the original RGB image. Specifically, at least one first truth value box corresponding to at least one type of defect can be manually marked in the training sample image in advance. In the current embodiment, one type of defect can correspond to one first truth value box. In another embodiment, multiple first truth value boxes corresponding to the same type of defect can also be marked in advance in the training sample image.

[0039] Furthermore, in another embodiment, in order to train a defect detection model that can simultaneously perform multiple different types of defect detection on a certain type of target, it is first necessary to collect multiple sample images of the target to be defect detected. In this embodiment, the multiple sample images include multiple types of defects that need to be detected, and specifically, the multiple sample images include: sample images that only include one type of defect, and sample images that simultaneously include multiple different types of defects.

[0040] For further information, see Figure 2 , Figure 2 This is a flow chart of another embodiment of a defect detection model training method of the present application. In the current embodiment, the steps included in the above step S110 of acquiring at least one training sample image are highlighted. Figure 2 In the corresponding embodiment, step S110 further includes step S201 to step S202.

[0041] S201: Acquire an original training sample image, wherein the training sample image is annotated with at least one true value box corresponding to at least one type of defect.

[0042] The original training sample image is a sample image that is obtained and annotated with at least one truth box corresponding to at least one type of defect, and before data enhancement processing is performed. In one embodiment, the process of obtaining the original training sample image is: using an image acquisition unit to take multi-directional photos of the target to be detected including the defect to be detected to obtain the original image, and then the user manually annotates the defects included in the target to be detected in the acquired original image on the defect detection model training device to obtain the original training sample image, so as to perform the following step S202. When the user annotates the defects included in the target in the original image, at least the defects are annotated with a box and the type of defect corresponding to the box is indicated to obtain a first truth box.

[0043] In another embodiment, the process of obtaining the original training sample image is: obtaining the original image obtained by multi-directionally photographing the target to be detected including the defect to be detected by an external shooting device, and then manually annotating the obtained original image by a user to obtain a first true value frame, and then obtaining at least one original training sample image, and then sending the obtained original training sample image to the defect detection model training device, so that the defect detection model training device obtains the original training sample image, and then executes the following step S202.

[0044] S202: Perform data enhancement processing on the original training sample image to obtain a new training sample image.

[0045] After obtaining the original training sample images, the obtained original training sample images are further subjected to data enhancement processing to obtain new training sample images. In the current embodiment, by performing data enhancement processing on the obtained original training sample images, a large number of new training sample images can be obtained, and after obtaining the new training sample images, the obtained new training sample images and the original training sample images are merged and output as a training set for training the defect detection model. In the current embodiment, the obtained new training sample images will also be labeled with the first true value box and the corresponding defect type. In the current embodiment, after performing data enhancement processing on the original training sample images, the total number of training sample images can be better expanded. Among them, the data enhancement processing method includes at least one of: flipping, rotating, color transformation, adding noise, radial transformation, translation, random cropping and style transfer network.

[0046] Furthermore, the above step S202 performs data enhancement processing on the original training sample image to obtain a new training sample image, further including: obtaining a defect-free image, and using a style transfer network to transfer the defect features in the original training sample image to the defect-free image to obtain a new training sample image. In another embodiment, the steps before and after obtaining the defect-free image and step 201 to obtain the original training sample image are not limited. Among them, the defect-free image can be an image that has been annotated and confirmed by the user, and in order to train a defect detection model with higher accuracy, defect-free images of multiple different angles of the object to be detected are obtained. In the current embodiment, the style transfer network is used to perform data enhancement processing on the training sample image to obtain a new training sample image, thereby increasing the number of training sample images, which can better improve the utilization rate of the data set and reduce the user's investment in manual annotation.

[0047] Specifically, since the defect features in the original training sample image may have other forms in different samples, the style transfer network is used to transfer the defect features in the original training sample image to other defect-free images. In the process of migrating the defect features, the position of the defect, the size of the defect, and the relative fusion effect between the defect and the surrounding image will all change adaptively, thereby obtaining a new training sample image containing defects and with different defect forms, and outputting the original training sample image and the new training sample image as training sample images to execute step S120.

[0048] S120: Detect the training sample image using the target detection network to obtain a first detection result.

[0049] After acquiring at least one training sample image, the training sample image is further detected using the target detection network to obtain a first detection result. Specifically, the acquired training sample is input into the target detection network so that the target detection network performs defect detection on the training sample image, thereby obtaining a first detection result. The first detection result at least includes a first detection frame corresponding to the defect.

[0050] Furthermore, when the target detection network is used to detect the training sample image, the target detection network is also used to further determine the type of defects detected, and the defect type corresponding to the first detection frame is marked at the first detection frame obtained. In the current embodiment, the defect type corresponding to the first detection frame is marked at the first detection frame.

[0051] Furthermore, the marked defect type is marked according to a pre-set defect identification code. In the current embodiment, a defect identification code is set in advance for each type of defect. When the target detection network is used to detect the training sample image to obtain a first detection frame, the defect corresponding to the first detection frame is marked with the defect identification code. Each defect identification code is unique, that is, different defect identification codes are only used to mark one type of defect in the technical solution provided in this application.

[0052] Furthermore, when training is performed for the first time, the target detection network used in executing step S120 can be an initial target detection network, and each parameter in the initial target detection network is an initial parameter. It should be noted that in the process of training to obtain the defect detection model, the parameters of the target detection network will be further adjusted according to the network loss value between the obtained target detection frame and the first true value frame to train and optimize the target detection network, thereby obtaining a more accurate defect detection model. Among them, the selection of the target detection frame can refer to the corresponding description in the following step S130, about the target detection network.

[0053] Furthermore, the target detection network includes an SSD network, and correspondingly, the first detection frame is a detection frame obtained by detection of a convolutional layer in the target detection network. The SSD network includes a basic network and a pyramid network. The basic network is the first 4 layers of the VGG-16 network, and the pyramid network is a simple convolutional network with a gradually smaller feature map (in other embodiments, the convolutional network can also be defined as a convolutional layer) and consists of 5 parts. In each part of the pyramid structure, there is a 3*3 convolution for prediction, and the first detection frame is detected at each position of the feature map. Each first detection frame corresponds to a set number of defect classification scores and 4 position offsets relative to the true value frame. The defect classification score is used to determine the type of defect corresponding to the first detection frame.

[0054] S130: Using the distance between the first true value frame and the first detection frame, select at least a portion of the first detection frame as the target detection frame.

[0055] After obtaining the first detection result including the first detection frame, further calculate and obtain the distance between the first true value frame and the first detection frame, and use the calculated distance between the first true value frame and the first detection frame to select a portion of the first detection frame from the first detection frame as the target detection frame. The target detection frame is a portion of the first detection frame used to adjust the parameters of the target detection network.

[0056] Furthermore, in another embodiment, after acquiring the first detection frame, the loss distance between the first true value frame and the first detection frame is calculated, that is, the loss value between the first true value frame and the first detection frame is calculated, and based on the calculated loss value, part of the first detection frame is selected from the first detection frame as the target detection frame.

[0057] Furthermore, in another embodiment, after calculating the loss value between the first true value frame and the first detection frame, the obtained loss value is further processed to determine the target detection frame according to the obtained processed loss value.

[0058] S140: Determine a network loss value based on the target detection frame and the first true value frame, and use the network loss value to update parameters of the target detection network to obtain a final defect detection model.

[0059] After the target detection frame is selected from the first detection frame, the network loss value between the target detection frame and the first true value frame is further calculated, and then the obtained network loss value is used to update the parameters of the target detection network to obtain the final defect detection model.

[0060] Furthermore, when there are multiple target detection frames, the network loss value between each target detection frame and the corresponding first true value frame is calculated respectively, and the network loss value between each target detection frame and the corresponding true value frame is further weighted and summed to obtain the total network loss value, and then the parameters of the target detection network are updated according to the obtained total loss value to obtain the final defect detection model. Among them, the final defect detection model is the defect detection model that is finally output after stopping the training optimization.

[0061] This application Figure 1In the corresponding embodiment, at least one training sample image is obtained, and the training sample image is detected using a target detection network to obtain a first detection result including a first detection frame corresponding to the defect, and then the distance between the first true value frame and the first detection frame is used to select at least part of the first detection frame as the target detection frame, and the network loss value is determined based on the target detection frame and the first true value frame. The network loss value is used to update the parameters of the target detection network to obtain the final defect detection model. Compared with the prior art solutions, a defect detection model that can efficiently detect multiple defects in the product and has a higher accuracy rate can be quickly trained.

[0062] Specifically, compared with the prior art which uses a large amount of calculation of the intersection-over-union ratios between all detection frames and true value frames, this application Figure 1 In the corresponding embodiment, based on the distance between the first detection frame and the first true value frame, part of the first detection frame is selected from the detected first detection frame as the target detection frame. Compared with the existing technology, the amount of calculation can be reduced significantly, thereby improving the training speed of the defect detection model.

[0063] See also Figure 3 , Figure 3 This is a flow chart of another embodiment of a defect detection model training method of the present application. In the current embodiment, the method provided by the present application focuses on the steps included in the above step S130 of using the distance between the first true value frame and the first detection frame to select at least part of the first detection frame as the target detection frame. Figure 3 In the corresponding embodiment, the above step S130 further includes steps S301 to S303.

[0064] S301: Calculate the distance between each first detection frame and the corresponding first true value frame respectively.

[0065] After detecting the training sample image using the target detection network and obtaining the first detection frame, the first true value frame corresponding to each first detection frame is determined respectively, and after determining each first true value frame, the distance between each first detection frame and the corresponding first true value frame is further calculated respectively.

[0066] Furthermore, step S301 is to respectively calculate the loss distance between each first detection frame and its corresponding first true value frame, so as to determine the accuracy of the first detection frame relative to the first true value frame according to the loss distance.

[0067] S302: Selecting a preset number of first detection frames with the shortest distances from the first detection frames as candidate detection frames.

[0068] After calculating the distance between each first detection frame and the corresponding first true value frame, a preset number of first detection frames with the smallest distances are further selected from the first detection frames as candidate detection frames, wherein the preset number is a fixed value set according to experience.

[0069] Furthermore, in another embodiment, when the number of training sample images for training is not fixed, or the number of defects included in the training sample images is not fixed, the number of first detection frames obtained by detecting in the training sample images using the target detection network is also uncertain, so in step S302, the first detection frame with the smallest distance in a preset ratio may be selected from the first detection frame as the candidate detection frame. The candidate detection frame is a detection frame selected from the first detection frame according to the distance between the first detection frame and the corresponding first true value frame, and is used to select the target detection frame. In other words, the candidate detection frames may also be sorted from large to small according to the loss distance, with a preset number or a preset ratio of first detection frames with a smaller loss distance.

[0070] S303: Calculate a first intersection-over-union ratio between each candidate detection frame and the corresponding first true value frame, and select at least part of the candidate detection frames as target detection frames according to the first intersection-over-union ratio.

[0071] After the candidate detection frames are determined, the first intersection-over-union ratios of each candidate detection frame and the corresponding first true value frame are further calculated, and at least part of the candidate detection frames are selected as target detection frames according to each first intersection-over-union ratio.

[0072] Furthermore, after obtaining a first intersection-and-union ratio between each candidate detection frame and the corresponding first true value frame, at least part of the candidate detection frames with a relatively large intersection-and-union ratio may be directly selected as the target detection frame.

[0073] Furthermore, after calculating the first IoU ratio of each candidate detection frame and the corresponding first true value frame, the obtained IoU ratio can be processed again, such as calculating the mean and variance value of the first IoU ratio, and then determining the IoU ratio threshold corresponding to the target detection frame according to the mean and variance value, and then selecting the candidate detection frame whose IoU ratio is greater than or equal to the determined IoU ratio threshold as the target detection frame. For details, please refer to the following Figure 4 In some embodiments, the selected target detection frame is defined as a positive sample, and correspondingly, other first detection frames that are not selected as target detection frames are defined as negative samples.

[0074] See also Figure 4 , Figure 4 This is a flow chart of another embodiment of a defect detection model training method of the present application. In the current embodiment, the method provided by the present application includes:

[0075] S401: Obtain at least one training sample image.

[0076] S402: Detect the training sample image using the object detection network to obtain a first detection result.

[0077] In the current embodiment, the above step S301 of respectively calculating the distance between each first detection frame and the corresponding first true value frame further includes step S403.

[0078] S403: Obtain the distance between the center point of each first detection frame and the center point of the corresponding first true value frame respectively, as the distance between the first detection frame and the first true value frame.

[0079] In the current embodiment, after obtaining the first detection result including the first detection frame, the distance between the center point of each first detection frame and the first true value frame corresponding to the first detection frame is calculated respectively. In the current embodiment, the distance between the center point of the first detection frame and the center point of the corresponding first true value frame may refer to the actual distance value between the two points.

[0080] Furthermore, in another embodiment, after obtaining the first detection result including the first detection frame, the loss distance between the center point of each first detection frame and the center point of the first true value frame corresponding to the first detection frame is calculated respectively. Here, the loss distance can also be understood as the loss value between the center point of the first detection frame and the center point of the first true value frame corresponding to the first detection frame.

[0081] Furthermore, in other embodiments, after the training sample image is detected using the target detection network to obtain the first detection result, the distances between the endpoints of each first detection frame and the endpoints of the corresponding first true value frame are further obtained, and then the distances between the obtained endpoints are weighted and summed as the distance between the first detection frame and the first true value frame. It can be understood that in some embodiments, the average of the distances between the obtained multiple endpoints can also be obtained, and the average of the distances between the multiple endpoints can be used as the distance between the first detection frame and the first true value frame.

[0082] S404: Selecting a preset number of first detection frames with the shortest distances from the first detection frames as candidate detection frames.

[0083] S405: Calculate a first intersection-over-union ratio between each candidate detection frame and the corresponding first true value frame.

[0084] In the current embodiment, the step S303 of selecting at least part of the candidate detection frames as the target detection frames according to the first IoU further includes steps S406 to S408.

[0085] S406: Obtain the mean and variance values ​​of the first intersection-over-union ratios of a preset number of candidate detection frames and the corresponding first true value frames.

[0086] In the current embodiment, after calculating the first intersection-and-union ratio of each candidate detection frame and the corresponding first true value frame, the mean and variance values ​​of the first intersection-and-union ratios of a preset number of candidate detection frames and the corresponding first true value frame are further calculated.

[0087] S407: The sum of the mean and the variance is used as the first selection threshold of the target detection frame.

[0088] After the mean and variance values ​​are calculated and obtained, the obtained mean and variance values ​​are used as the first selection threshold of the intersection-and-union ratio of the target detection frame, and step S408 is executed.

[0089] S408: Select a candidate detection frame whose first intersection-over-union ratio is greater than or equal to a first selection threshold as the target detection frame.

[0090] The candidate detection frame whose first intersection-over-union ratio is greater than or equal to the first selection threshold is selected as the target detection frame, that is, the candidate detection frame whose first intersection-over-union ratio is greater than or equal to the first selection threshold is output as the target detection frame to train and optimize the defect detection model; at the same time, other candidate detection frames whose first intersection-over-union ratio is less than the first selection threshold are discarded.

[0091] S409: Determine the network loss value based on the target detection frame and the first true value frame, and use the network loss value to update the parameters of the target detection network to obtain the final defect detection model. In the current embodiment, after calculating the first intersection-and-union ratio of each candidate detection frame and the corresponding first true value frame, further calculate and obtain the mean and variance values ​​of the first intersection-and-union ratios between a preset number of candidate detection frames and the corresponding first true value frame, and then further use the mean and variance values ​​of the first intersection-and-union ratios to determine the first selection threshold, and then select the target detection frame from the candidate detection frame based on the first selection threshold, so that more accurate selection of the target detection frame can be achieved, and the efficiency of training the defect detection model can be improved by selecting a more accurate target detection frame, and the accuracy of the training defect detection model can also be improved.

[0092] It should be noted that steps S401 to S402, steps S404 to S405 and step S409 in the current embodiment are respectively the same as those in the above Figure 1 or Figure 3 Some steps are the same as in the above, and the details can be found in the corresponding parts above, which will not be described in detail here.

[0093] See also Figure 5 , Figure 5This is a flow chart of another embodiment of a defect detection model training method of the present application. In the current embodiment, the focus is on the steps included after the step of using the network loss value to update the parameters of the target detection network to obtain the final defect detection model. After updating the parameters of the target detection network using the network loss value, that is, obtaining a new defect detection model, the obtained new defect detection model will be evaluated to determine whether the parameters of the new defect detection model are qualified, and then determine whether it is the final defect detection model. Specifically, the process of evaluating the new defect detection model includes the contents described in steps S501 to S504. Specifically, in the current embodiment, the method provided by the present application also includes:

[0094] S501: Inputting a test sample image into a defect detection model to obtain a second detection result of the test sample image.

[0095] After the parameters of the target detection network are updated using the network loss value and a new defect detection model is obtained, the test sample image is further input into the obtained new defect detection model to obtain a second detection result corresponding to the test sample image. The test sample image is a preset sample image for testing the defect detection model, and specifically can be an image set different from the training sample set. The second detection result includes a second detection frame corresponding to the defect, and the second detection result includes a defect type, specifically, the defect type is marked in the second detection frame using a defect identification code. It should be noted that the defect identification code used to mark the defect type corresponding to the second detection frame and the defect identification code used to mark the defect corresponding to the first detection frame are the same set of identification codes.

[0096] Further, in other embodiments, the steps S120 to S140 are executed a preset number of times according to the experience value in advance, so as to obtain a new defect detection model after multiple training optimizations, and then the obtained defect detection model is evaluated and tested using steps S501 to S504. The preset number of executions of the training optimization can be adjusted according to the experience value and is not limited here.

[0097] S502: Determine whether the position and / or size of the second detection frame of the defect meets the theoretical characteristics of the defect.

[0098] After obtaining the second detection result including the second detection frame, further determine whether the position and / or size of the second detection frame corresponding to the defect meets the theoretical characteristics of the defect. Furthermore, after obtaining the second detection result, further obtain the position and / or size of the second detection frame, and then compare the obtained position and / or size of the second detection frame with the preset theoretical characteristics of the defect to determine whether the position and / or size of the second detection frame of the defect meets the theoretical characteristics of the defect. The theoretical characteristics of the defect at least include the theoretical position range and theoretical size of the defect.

[0099] Specifically, the theoretical characteristics of the defect can also be pre-set by the user according to the product requirements and the defect characteristics that often appear in the product, and can also be understood as other common characteristics of defects in the product. For example, when the product is a bottle cap, the defect of the bottle cap coding abnormality can be pre-set to be on the side of the bottle cap, or the coding height of the bottle cap coding abnormality can be pre-set to be higher than two-thirds of the height of the bottle cap. It can be understood that the defect detection model training method provided in the present application can be used to train a defect detection model for defect detection of different products. Therefore, in actual application, the user can set the theoretical characteristics of the defect according to the application scenario of the defect detection model and the common characteristics of defects in the product to be defect detected. The theoretical characteristics of the defect are not limited here.

[0100] In another embodiment, the theoretical characteristics of the defect can also be obtained based on the observation of the training sample images. For example, in one embodiment, after observing the training sample images, it is found that: the defects of broken bottle caps can be located on the entire interface of the bottle cap; the defects of swirling bottle caps are mostly present on the side of the bottle cap and 1 / 3-1 / 2 above the height, the defects of abnormal coding are mostly present on the left middle side of the bottle cap, and the defects of breakpoints and bad edges of the bottle caps are mostly present below the bottle cap. Correspondingly, the defect conclusions of the above observations will be set as the theoretical characteristics of the defect. Based on this information, a method for verifying defect detection is further designed. The second detection result is input into the verification defect processing module, and it can be detected according to the defect type whether the defect currently detected meets the theoretical characteristics of this type of defect. If it meets the requirements, the second detection box corresponding to the defect will be retained, otherwise it will be discarded.

[0101] S503: If yes, keep the second detection frame; otherwise, discard the second detection frame.

[0102] If it is determined that the position and / or size of the second detection frame of the defect meets the theoretical characteristics of the defect, the second detection frame will be retained. Conversely, if it is determined that the position and / or size of the second detection frame of the defect does not meet the theoretical characteristics of the defect, the second detection frame will be discarded.

[0103] S504: Using the number of retained second detection frames, perform performance evaluation on the defect detection model.

[0104] After determining whether the position and / or size of the second detection frame of the defect meets the theoretical characteristics of the defect and obtaining the retained second detection frame, the performance of the current defect detection model is evaluated using the number of retained second detection frames. Specifically, the performance evaluation of the defect detection model can be seen below. Figure 6 The description in the corresponding embodiment.

[0105] Figure 5 In the corresponding embodiment, the test sample image is input into the defect detection model to obtain the second detection result of the test sample image, and it is determined whether the position and / or size of the second detection frame of the defect meets the theoretical characteristics of the defect. If so, the second detection frame is retained, otherwise the second detection frame is discarded, and then the number of retained second detection frames is used to perform performance evaluation on the defect detection model. The detection accuracy of the obtained defect detection model can be better evaluated, and the evaluation results can be used to determine whether to output the obtained defect detection model, thereby achieving a defect detection model with higher detection accuracy obtained during training.

[0106] For further information, see Figure 6 , Figure 6 This is a flow chart of another embodiment of a defect detection model training method of the present application. In the current embodiment, the test sample image is annotated with second truth value boxes corresponding to at least one type of defect.

[0107] The above step S504 uses the number of the reserved second detection frames to perform performance evaluation on the defect detection model, further comprising:

[0108] S601: Obtain a second intersection-over-union ratio between a retained second detection frame and a corresponding second truth frame.

[0109] The test sample image is input into the defect detection model to obtain the second detection result of the test sample image, and after determining that the position and / or size of the second detection frame of the defect meets the theoretical characteristics of the defect and retaining the second detection frame, the second intersection-and-union ratio between the retained second detection frame and the corresponding second true value frame is further calculated. It should be noted that the second intersection-and-union ratio between the second true value frames of the same defect type as the second detection frame is calculated and obtained in step S601.

[0110] S602: Determine the accuracy and recall of the defect detection model using at least part of the second intersection-over-union ratio.

[0111] After calculating and obtaining the second intersection-and-union ratio between the retained second detection frame and the corresponding second truth frame, the accuracy and recall rate of the defect detection model are further determined using at least part of the second intersection-and-union ratio.

[0112] Furthermore, in one embodiment, after obtaining the second intersection-and-union ratio between the retained second detection frame and the corresponding second truth frame, a second intersection-and-union ratio greater than or equal to a preset second selection threshold is further selected, and then the second intersection-and-union ratio whose intersection-and-union ratio is greater than or equal to the preset second selection threshold is used to determine the accuracy and recall of the defect detection model.

[0113] S603: Obtain a performance evaluation value of the defect detection model according to the second intersection-over-union ratio, the recall rate, and the precision rate, so as to evaluate the defect detection model according to the performance evaluation value.

[0114] According to the calculated second intersection-over-union ratio, recall rate and accuracy, it is further judged whether the performance of the current new defect detection model meets the requirements, and then it is judged whether the training of the defect detection model can be stopped and the current defect detection model output is used as the final defect detection model.

[0115] Among them, the accuracy rate indicates how many samples predicted as positive are truly positive samples. Then there are two possibilities for predicting positive, one is to predict the positive class as positive class (TP), and the other is to predict the negative class as positive class (FP). That is, in the current embodiment, the accuracy rate is equal to the ratio of the total number of second detection frames to the total number of second truth value frames, and the calculation formula is: accuracy rate = total number of retained second detection frames / total number of second truth value frames.

[0116] The recall rate refers to the original sample, which indicates how many positive examples in the sample are predicted correctly. Specifically, there are two possibilities, one is to predict the original positive class as the positive class (TP), and the other is to predict the original positive class as the negative class (FN). That is, in the current embodiment, the recall rate is equal to the ratio of the number of retained second detection frames to the total number of second truth value frames, that is, the recall rate = the ratio of the number of second detection frames / the total number of second truth value frames. It should be noted that in other embodiments, the accuracy rate and recall rate will be defined as the precision rate and the recall rate.

[0117] Furthermore, the average precision, mAP (meanAverage Precision), is calculated based on the second intersection-over-union ratio, recall rate, and accuracy. Specifically, the average precision is calculated according to the following formula: Among them, P and R are precision and recall respectively.

[0118] It should be noted that in order to conduct a more comprehensive evaluation of the defect detection model, it is necessary to limit the defect types included in the multiple test sample images to at least cover all the defect types in the training sample images used for training.

[0119] It should be noted that, in some embodiments, using the network loss value to update the parameters of the target detection network is defined as using the network loss value for gradient feedback to update the parameters of the target detection network. Furthermore, when the target detection network is an SSD network, the above steps are also understood as using the network loss value for gradient feedback to update the parameters of the SSD network.

[0120] See also Figure 7 , Figure 7 This is a flow chart of another embodiment of a defect detection model training method of the present application. In the current embodiment, determining the network loss value based on the target detection frame and the first true value frame in the above step S140 further includes:

[0121] S701: Obtain a position loss value according to the position difference between the target detection frame and the corresponding first true value frame.

[0122] After the target detection frame is selected, a network loss value between the target detection frame and the first true value frame is calculated, wherein the network loss value includes at least a position loss value and a confidence loss value.

[0123] Specifically, the position loss value is the Smooth L1 loss function.

[0124] S702: Obtain a confidence loss value according to the confidence of the target detection box in the first detection result.

[0125] Among them, the confidence loss value is the cross entropy loss function.

[0126] S703: Obtain a network loss value based on the position loss value and the confidence loss value.

[0127] After obtaining the position loss value and the confidence loss value respectively, the position loss value and the confidence loss value are further weighted and summed, and the result of the weighted sum of the position loss value and the confidence loss value is used as the network loss value, so as to update the parameters of the target detection network according to the obtained network loss value to obtain the final defect detection model. Among them, when performing the weighted summation of the position loss value and the confidence loss value, the weight ratio corresponding to the position loss value and the confidence loss value can be set according to the empirical value, which is not limited here.

[0128] The method provided in the present application can be used to train a defect detection model that can be used to detect multiple types of defects in a product. It only needs to provide the corresponding defect data that needs to be detected and conduct training. The defect detection model trained by the method provided in the present application can achieve more efficient defect detection and better guarantee the defect detection accuracy compared to traditional image processing technology.

[0129] See also Figure 8 , Figure 8 This is a flow chart of a defect detection method in an embodiment of the present application. In the current embodiment, the method provided by the present application includes:

[0130] S810: Acquire an image to be detected by photographing the object to be detected.

[0131] When detecting an object to be detected, it is first necessary to photograph the object to be detected and obtain an image of the object to be detected obtained by photographing the object to be detected.

[0132] Furthermore, in another embodiment, in order to perform more accurate detection of the object to be detected, step S810 is to obtain multiple images to be detected at different angles obtained by shooting the object to be detected at multiple angles. When the object to be detected is detected at multiple angles, when the images to be detected at different angles of the object to be detected are obtained, the shooting angle will be further marked in the image to be detected, so that when the defect detection is performed later, the defect can be determined according to the shooting angle, and after the defect detection result is obtained, the defect detection result and the shooting angle are output accordingly, so that the user or the subsequent machine can quickly distinguish the defect according to the defect detection result, or the obtained defect can be combined with the shooting angle and compared with the defect theoretical characteristics to determine the accuracy of the defect detection.

[0133] S820: Perform defect detection on the image to be detected using the defect detection model to obtain a defect detection result.

[0134] The image to be detected is input into the defect detection model, and the defect detection model is used to perform defect detection on the image to be detected to obtain a defect detection result, and the obtained defect detection result is output.

[0135] Wherein, the object to be detected is a bottle cap, and / or the defect detection model is as follows Figures 1 to 7 And the final defect detection model trained by the defect detection model training method in any corresponding embodiment.

[0136] Further, in another embodiment, please continue to refer to Figure 8 In step S820, after using the defect detection model to detect defects in the image to be detected and obtaining the defect detection result, the method provided by the present application further includes:

[0137] S830: Classify the bottle caps according to the types of defects included in the defect detection results.

[0138] After the defect detection model is used to perform defect detection on the image to be detected and the defect detection result is obtained, the bottle caps are further classified according to the types of defects contained in the defect detection result. Specifically, the defect detection result obtained by the detection is output to the processor, so that the processor determines the operation of classifying the bottle caps according to the types of defects contained in the defect detection result obtained by the detection, and generates a control instruction for the corresponding classification operation, so as to output the bottle caps to the corresponding workstations or work lines according to the types of defects, so as to subsequently process the defects on the bottle caps.

[0139] Furthermore, classification processing refers to determining to which workstation or workline the bottle caps will be output according to the defect type of the bottle caps, and feeding back to the processor to generate corresponding classification processing operation instructions and then output the bottle caps including different types of defects to different workstations or worklines to process the defects of the bottle caps and obtain qualified bottle caps.

[0140] The defect types included in the defect detection result include at least one of: bottle cap breakage, bottle cap deformation, bottle cap broken edge, bottle cap rotation, bottle cap breakpoint and coding abnormality.

[0141] Compared with the prior art, the technical solution provided by this application only requires images taken by a camera to perform defect detection. Compared with other methods, it does not require additional image processing technology. The method is simple and easy and can be quickly applied to factories.

[0142] For this application Figures 1 to 7 and Figure 8 In the technical solutions provided in any of the embodiments corresponding thereto, by using deep learning technology and combining the visual features of the image, an end-to-end deep neural network is used to train the RGB image to achieve accurate classification and positioning of the bottle cap defects. In addition, the deep learning-based defect detection method provided in this application can realize the recognition of multiple defect categories by only replacing the data of the training sample image and a small number of parameters, and can be easily upgraded when deployed in the product.

[0143] See also Fig. 9 , Fig. 9 1 is a schematic diagram of a structure of a defect detection model training device in an embodiment of the present application. In the current embodiment, the defect detection model training device 900 provided by the present application includes a coupled processor 901 and a memory 902. The defect detection model training device 900 can execute Figures 1 to 7 And the defect detection model training method described in any corresponding embodiment.

[0144] The memory 902 includes a local storage (not shown) and stores a computer program. When the computer program is executed, Figures 1 to 7 And the method described in any corresponding embodiment.

[0145] The processor 901 is coupled to the memory 902, and the processor 901 is used to run the computer program to perform the above Figures 1 to 7 And the defect detection model training method described in any corresponding embodiment.

[0146] Furthermore, in another embodiment, the defect detection model training device 900 provided in the present application may further include an image acquisition unit (not shown). The image acquisition unit is connected to the processor 901 and is used to capture and acquire original images, test sample images, or training sample images under the control of the processor 901.

[0147] Furthermore, in another embodiment, the defect detection model training device 900 provided in the present application will also include a communication circuit (not shown), which is connected to the processor 901 and is used to interact with an external terminal device under the control of the processor 901 to obtain training sample images or original images or test sample images, wherein the external terminal device may include a shooting device or a mobile terminal, etc.

[0148] See also Fig.10 , Fig.10 1 is a schematic diagram of a structure of a defect detection device in an embodiment of the present application. In the current embodiment, the defect detection device 1000 provided by the present application includes a coupled processor 1001 and a memory 1002. The defect detection device 1000 can execute Figure 8 And the defect detection model training method described in any corresponding embodiment.

[0149] The memory 1002 includes a local storage (not shown) and stores a computer program. When the computer program is executed, Figure 8 And the method described in any corresponding embodiment.

[0150] The processor 1001 is coupled to the memory 1002, and the processor 1001 is used to run the computer program to execute the above Figure 8 And the defect detection method described in any corresponding embodiment.

[0151] Furthermore, in another embodiment, the defect detection device 1000 provided in the present application may further include an image acquisition unit (not shown). The image acquisition unit is connected to the processor 1001 and is used to photograph and acquire the object to be detected under the control of the processor 1001 to acquire the image to be detected.

[0152] Furthermore, in another embodiment, the defect detection device 1000 provided in the present application may also include a communication circuit (not shown), which is connected to the processor 1001 and is used to interact with an external terminal device under the control of the processor 1001 to obtain an image to be detected, wherein the external terminal device may include a shooting device or a mobile terminal, etc.

[0153] See also Fig.11 , Fig.11 1 is a schematic diagram of a computer storage medium in an embodiment of the present application. The computer storage medium 1100 stores a computer program 1101 that can be executed by a processor. The computer program 1101 is used to implement the above Figures 1 to 7 and the defect detection model training method described in any one of the corresponding embodiments, or the computer program 1101 is used to implement Figure 8 Specifically, the computer storage medium 1100 may be a memory, a personal computer, a server, a network device, or a USB flash drive, and no limitation is made here.

[0154] The above description is only an implementation method of the present application, and does not limit the patent scope of the present application. Any equivalent structure or equivalent process transformation made using the contents of the present application specification and drawings, or directly or indirectly used in other related technical fields, are also included in the patent protection scope of the present application.

Claims

1. A defect detection model training method, characterized in that: The method comprises: Acquire at least one training sample image, wherein the training sample image is annotated with at least one first truth value box corresponding to at least one type of defect; Detecting the training sample image using an object detection network to obtain a first detection result, wherein the first detection result includes a first detection frame corresponding to the defect; Calculating the distance between each of the first detection frames and the corresponding first true value frame respectively, wherein the distance includes a loss distance, so as to determine the accuracy of the first detection frame relative to the corresponding first true value frame according to the loss distance; Selecting a preset number of first detection frames with the smallest distances from the first detection frames as candidate detection frames; Calculate a first intersection-over-union ratio between each of the candidate detection frames and the corresponding first true value frame; Obtaining a mean and a variance value of a first intersection-over-union ratio of the preset number of candidate detection frames to the corresponding first true value frame; The sum of the mean value and the variance value is used as a first selection threshold of the target detection frame; Selecting the candidate detection frame whose first intersection-over-union ratio is greater than or equal to the first selection threshold as the target detection frame; A network loss value is determined based on the target detection frame and the first true value frame, and the network loss value is used to update the parameters of the target detection network to obtain a final defect detection model.

2. The method according to claim 1, characterized in that The respectively calculating the distance between each of the first detection frames and the corresponding first true value frame includes: The distance between the center point of each of the first detection frames and the center point of the corresponding first true value frame is respectively obtained as the distance between the first detection frame and the first true value frame.

3. The method according to claim 1, characterized in that: After the network loss value is used to update the parameters of the target detection network to obtain a final defect detection model, the method further includes: Inputting the test sample image into the defect detection model to obtain a second detection result of the test sample image, wherein the second detection result includes a second detection frame corresponding to the defect; Determining whether the position and / or size of the second detection frame of the defect meets the theoretical characteristics of the defect; If yes, keep the second detection frame, otherwise discard the second detection frame; The performance of the defect detection model is evaluated by using the number of the second detection frames retained.

4. The method according to claim 3, characterized in that The test sample image is annotated with second truth value frames corresponding to at least one type of defect; The step of using the number of the second detection frames retained to perform performance evaluation on the defect detection model includes: Obtaining a second intersection-over-union ratio between the retained second detection frame and the corresponding second truth frame; Determine the accuracy and recall of the defect detection model using at least part of the second intersection-over-union ratio; A performance evaluation value of the defect detection model is obtained according to the second intersection-over-union ratio, the recall rate and the precision rate, so as to evaluate the defect detection model according to the performance evaluation value.

5. The method according to claim 4, characterized in that The determining of the network loss value based on the target detection frame and the first true value frame includes: Obtaining a position loss value according to a position difference between the target detection frame and the corresponding first true value frame; and Obtaining a confidence loss value according to the confidence of the target detection frame in the first detection result; Based on the position loss value and the confidence loss value, a network loss value is obtained.

6. The method according to claim 1, characterized in that The obtaining of at least one training sample image further comprises: Acquire an original training sample image, wherein the training sample image is annotated with at least one first truth value box corresponding to at least one type of defect; Perform data enhancement processing on the original training sample image to obtain a new training sample image.

7. The method according to claim 6, characterized in that The performing data enhancement processing on the original training sample image to obtain the new training sample image further includes: A defect-free image is obtained, and defect features in the original training sample image are transferred to the defect-free image using a style transfer network to obtain a new training sample image.

8. The method according to claim 1, characterized in that The target detection network includes an SSD network, and the first detection frame is a detection frame obtained by detection of each convolutional layer in the target detection network.

9. A defect detection method, characterized in that: The method comprises: Acquire an image to be detected by photographing the object to be detected; Performing defect detection on the image to be detected using a defect detection model to obtain a defect detection result; Wherein, the object to be detected is a bottle cap, and the defect detection model is a model trained by the method according to any one of claims 1 to 8.

10. The method according to claim 9, characterized in that After performing defect detection on the image to be detected by using the defect detection model to obtain a defect detection result, the method further includes: Classifying the bottle caps according to the types of defects included in the defect detection results; And / or, the types of defects included in the defect detection result include: at least one of: bottle cap damage, bottle cap deformation, bottle cap broken edge, bottle cap rotation, bottle cap breakpoint and coding abnormality.

11. A defect detection model training device, characterized in that: The device comprises a memory and a processor coupled, wherein: The memory includes local storage and stores a computer program; The processor is configured to run the computer program to perform the method according to any one of claims 1 to 8.

12. A defect detection device, characterized in that: The device comprises a memory and a processor coupled, wherein: The memory includes a local storage and stores a computer program; The processor is configured to run the computer program to perform the method according to any one of claims 9 to 10.

13. A computer storage medium, characterized in that: The computer storage medium stores a computer program that can be executed by a processor, and the computer program is used to implement the method according to any one of claims 1 to 8 or claims 9 to 10.

Citation Information

Patent Citations

  • Object detection network training method and device

    CN109409517A

  • Small target detection and recognition method for enhancing feature learning

    CN110503112A