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

By constructing a defect detection model and training network parameters using mask images and label images, the problem of low accuracy in manual identification was solved, and efficient identification of product surface defects was achieved.

CN116883790BActive Publication Date: 2025-12-26MECH MIND ROBOTICS TECH LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202310899497.4
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2023-07-20
Publication Date
2025-12-26
Estimated Expiration
2043-07-20

AI Technical Summary

Technical Problem

In existing technologies, the accuracy of manual identification of product surface defects is low, and it is difficult to effectively identify surface quality problems such as cracks, dents and grooves in plastic products and metal parts.

Method used

A defect detection model is constructed and trained using defect images, label images, and mask images. The model is then restored and features are extracted using the first branch network, and the defect region is identified using the second branch network. The network parameters are adjusted by combining the cross loss function until the preset training conditions are met.

Benefits of technology

It improves the accuracy of identifying product surface defects, and can efficiently identify the location and presence of defects on the product surface.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN116883790B_ABST
    Figure CN116883790B_ABST
Patent Text Reader

Abstract

The present disclosure provides a defect detection model training method and device, a defect detection method and an electronic device. The defect detection model training method comprises: a first branch network performing restoration processing on an acquired mask image to obtain a plurality of first feature images output by the first branch network and a predicted restoration image; a second branch network is used to identify the position of the defect area of the defect image based on the plurality of first feature images to obtain a predicted defect image; a first loss value of the predicted restoration image relative to the defect image is determined, and the network parameters of the first branch network are adjusted using the first loss value; a second loss value of the predicted defect image relative to an acquired label image is determined, and the network parameters of the first branch network and the second branch network are adjusted using the second loss value, and the label image is used to represent the actual position of the defect area in the defect image. The present disclosure can obtain a defect detection model capable of accurately identifying product surface defects.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The present disclosure relates to the field of image processing, and in particular to a defect detection model training method and device, a defect detection method, and an electronic device. BACKGROUND

[0002] In the production and processing of plastic products, metal devices, etc., the products obtained after processing may have surface quality problems such as cracks, depressions, and grooves, which may affect the performance of the products and in turn affect the use of the products by users.

[0003] At present, artificial recognition of surface defect problems of products is usually adopted, but this approach has the problem of low recognition accuracy. SUMMARY

[0004] The present disclosure provides a defect detection model training method and device, a defect detection method, and an electronic device to improve the recognition accuracy of surface defects of products.

[0005] The first aspect of the embodiments of the present disclosure provides a defect detection model training method. The defect detection model includes a first branch network and a second branch network. The defect detection model training method includes: performing restoration processing on an acquired mask image through the first branch network to obtain a plurality of first feature images output by the first branch network and a predicted restoration image, the mask image being obtained by performing mask processing on a defect region in a defect image; identifying the position of the defect region in the defect image based on the plurality of first feature images through the second branch network to obtain a predicted defect image; determining a first loss value of the predicted restoration image relative to the defect image, and adjusting the network parameters of the first branch network using the first loss value; determining a second loss value of the predicted defect image relative to an acquired label image, and adjusting the network parameters of the first branch network and the second branch network using the second loss value, the label image being used to represent the actual position of the defect region in the defect image; ending the training and obtaining a trained defect detection model when it is determined that a preset training condition is met.

[0006] The second aspect of the embodiments of the present disclosure provides a defect detection method. The method includes: acquiring a target image, the target image including an object to be detected; inputting the target image into a first branch network and a second branch network of a defect detection model; performing defect prediction on the target image through the defect detection model to obtain a predicted defect image output by the second branch network of the defect detection model, the predicted defect image being used to represent the position of a defect in the object to be detected, the defect detection model being obtained according to the defect detection model training method of the first aspect.

[0007] The third aspect of the embodiments of the present disclosure provides a defect detection model training device. The defect detection model includes a first branch network and a second branch network. The defect detection model training device includes:

[0008] a restoration module configured to perform a restoration process on the obtained mask image through the first branch network to obtain a plurality of first feature images output by the first branch network and a predicted restoration image, the mask image being obtained by performing a mask process on a defect region in a defect image;

[0009] a recognition module configured to identify a position of the defect region in the defect image based on the plurality of first feature images through the second branch network to obtain a predicted defect image;

[0010] a first adjustment module configured to determine a first loss value of the predicted restoration image relative to the defect image, and adjust network parameters of the first branch network using the first loss value;

[0011] a second adjustment module configured to determine a second loss value of the predicted defect image relative to an obtained label image, and adjust network parameters of the first branch network and the second branch network using the second loss value, the label image being used to represent an actual position of the defect region in the defect image;

[0012] a determination module configured to end the training to obtain a trained defect detection model when it is determined that a preset training condition is met.

[0013] A fourth aspect of the embodiments of the present disclosure provides a defect detection device, comprising:

[0014] an acquisition module configured to acquire a target image, the target image comprising a to-be-detected object;

[0015] a prediction module configured to input the target image into the first branch network and the second branch network of the defect detection model, perform defect prediction on the target image through the defect detection model to obtain a predicted defect image output by the second branch network of the defect detection model, the predicted defect image being used to represent a position of a defect in the to-be-detected object, and the defect detection model being obtained according to the defect detection model training method of the first aspect.

[0016] A fifth aspect of the embodiments of the present disclosure provides an electronic device, comprising a processor, a memory, and a computer program stored on the memory and executable on the processor, wherein the processor implements the defect detection model training method of the first aspect and / or the defect detection method of the second aspect when executing the computer program.

[0017] A sixth aspect of the embodiments of the present disclosure provides a computer-readable storage medium, wherein the computer-readable storage medium stores computer execution instructions, and the computer execution instructions are used to implement the defect detection model training method of the first aspect and / or the defect detection method of the second aspect when executed by a processor.

[0018] The seventh aspect of the embodiments of the present disclosure provides a computer program product, the program product comprising: a computer program stored in a readable storage medium, at least one processor of an electronic device can read the computer program from the readable storage medium, and the at least one processor executes the computer program to enable the electronic device to execute the defect detection model training method of the first aspect and / or the defect detection method of the second aspect.

[0019] The embodiments of the present disclosure are applied in the identification scene of product surface defects, the first branch network is used for restoration processing on the obtained mask image, a plurality of first feature images and a predicted restoration image output by the first branch network are obtained, the mask image is obtained by performing mask processing on the defect region in the defect image; the second branch network is used for identifying the position of the defect region in the defect image based on the plurality of first feature images, and a predicted defect image is obtained; a first loss value of the predicted restoration image relative to the defect image is determined, and the network parameters of the first branch network are adjusted by using the first loss value; a second loss value of the predicted defect image relative to the obtained label image is determined, and the network parameters of the first branch network and the second branch network are adjusted by using the second loss value, the label image is used to represent the actual position of the defect region in the defect image; in the case of determining that the preset training condition is met, the training is ended, and the defect detection model for accurately identifying the product surface defects can be obtained. BRIEF DESCRIPTION OF DRAWINGS

[0020] The accompanying drawings, which are included to provide a further understanding of the present disclosure, constitute a part of the present disclosure, the illustrative embodiments of the present disclosure and the description thereof serve to explain the present disclosure, and do not constitute improper limitations on the present disclosure. In the drawings:

[0021] Figure 1 An application scene diagram of a defect detection model training method provided for an exemplary embodiment of the present disclosure is shown in the figure;

[0022] Figure 2 A structure diagram of a defect detection model provided for an exemplary embodiment of the present disclosure is shown in the figure;

[0023] Figure 3 A step flowchart of a defect detection model training method provided for an exemplary embodiment of the present disclosure is shown in the figure;

[0024] Figure 4 A schematic diagram of a defect image, a mask image and a label image provided for an exemplary embodiment of the present disclosure is shown in the figure;

[0025] Figure 5 A step flowchart of another defect detection model training method provided for an exemplary embodiment of the present disclosure is shown in the figure;

[0026] Figure 6A structural schematic diagram of an SE processing unit provided for an exemplary embodiment of the present disclosure is shown in FIG. 1.

[0027] Figure 7 A schematic diagram in a process of determining a loss value provided for an exemplary embodiment of the present disclosure is shown in FIG. 3.

[0028] Figure 8 Another schematic diagram in a process of determining a loss value provided for an exemplary embodiment of the present disclosure is shown in FIG. 4.

[0029] Figure 9 A schematic diagram of a first sub-prediction image provided for an exemplary embodiment of the present disclosure is shown in FIG. 5.

[0030] Figure 10 A step flowchart of a defect detection method provided for an exemplary embodiment of the present disclosure is shown in FIG. 6.

[0031] Figure 11 A schematic diagram of a defect detection method provided for an exemplary embodiment of the present disclosure is shown in FIG. 7.

[0032] Figure 12 A structural block diagram of a defect detection model training device provided for an exemplary embodiment of the present disclosure is shown in FIG. 8.

[0033] Figure 13 A structural block diagram of a defect detection device provided for an exemplary embodiment of the present disclosure is shown in FIG. 9.

[0034] Figure 14 A structural schematic diagram of an electronic device provided for an exemplary embodiment of the present disclosure is shown in FIG. 10. DETAILED DESCRIPTION

[0035] In order to make the purposes, technical solutions and advantages of the present disclosure clearer, the technical solutions of the present disclosure will be described clearly and completely below in combination with specific embodiments of the present disclosure and corresponding drawings. Obviously, the described embodiments are only some of the embodiments of the present disclosure, but not all the embodiments. Based on the embodiments in the present disclosure, all other embodiments obtained by those skilled in the art without creative labor fall within the scope of protection of the present disclosure.

[0036] In the production and processing of plastic products, metal devices, etc., the products obtained by processing may have surface quality problems such as cracks, depressions and grooves, etc. These defects may affect the performance of the products, and further affect the use of the products by users. At present, artificial recognition of surface defect problems of products is usually used, but this method has the problem of low recognition accuracy.

[0037] Based on the above problems, the defect detection model is constructed, and the defect image, the label image of the defect image and the mask image of the defect image are used to train the defect detection model, so that the trained defect detection model can accurately and efficiently identify the surface defects of the product.

[0038] In addition, one application scenario of the embodiment of the present disclosure is as follows Figure 1 , in Figure 1 , the trained defect detection model is deployed on the server 11, the terminal 12 collects the target image P1 of the object to be detected 13, and the terminal 12 sends the target image P1 to the server 11. The server 11 detects the target image P1 using the defect detection model to obtain a predicted defect image P1, which can represent whether the object to be detected 13 has defects and the defect position.

[0039] Among them, Figure 1 This is only an example of an application scenario, and the embodiment of the present disclosure can be applied to any object surface defect detection scenario. The embodiment of the present disclosure does not limit the specific application scenario.

[0040] Referring to Figure 2 , the structure diagram of the defect detection model provided by the embodiment of the present disclosure is shown. The defect detection model includes a first branch network and a second branch network. The first branch network includes a plurality of first convolution units and a first feature processing unit connected in sequence. The second branch network includes a plurality of second convolution units, a plurality of SE processing units and a second feature processing unit connected in sequence, and the output end of the i-th first convolution unit is connected to the input end of the i+1-th second convolution unit through the corresponding SE processing unit.

[0041] Further, the first feature processing unit includes a first splicing unit and a convolution unit; and the second feature processing unit includes a second splicing unit, a convolution unit and a normalization unit.

[0042] Referring to Figure 1 , the first branch network includes 0 to n first convolution units, and n is a positive integer. The corresponding second branch network includes 0 to n second convolution units and 0 to n-1 SE processing units.

[0043] Figure 3 The step flow chart of the defect detection model training method provided by the exemplary embodiment of the present disclosure is shown. The defect detection model includes the following steps of the defect detection model training method:

[0044] S301, the mask image obtained is processed by the first branch network to obtain a plurality of first feature images and a predicted restoration image output by the first branch network.

[0045] The mask image is obtained by performing mask processing on the defect region in the defect image. Figure 2 The defect image is subjected to mask processing to obtain a mask image, and the mask image is input into the first branch network to obtain a plurality of first feature images (such as Figure 2 first feature image a0 to first feature image an) and a predicted recovered image. In the embodiments of the present disclosure, the first branch network is used to predict the content of the mask region of the mask image in the defect image. The first loss value of the predicted recovered image and the defect image obtained by the trained first branch network is required to be less than the first loss value threshold.

[0046] Further, referring to Figure 4 The defect image, the mask image of the defect image, and the label image are exemplarily shown. The defect image includes a defect region and a normal region outside the defect region, wherein the defect region represents that the object contained in the defect image has defects in the region, and the difference between the pixel area of the defect region in the defect image and the pixel area of the defect itself in the defect image is less than a preset area threshold. The mask image is obtained by performing mask processing on the defect region in the defect image, and the normal region is not processed. In the mask image, the pixel values of the pixels in the defect region are the same, as shown in Figure 4 the defect region is all black. In the label image, the pixel values of the pixels in the normal region are the same, the pixel values of the pixels in the defect region are the same, and the pixel value of the normal region is different from the pixel value of the defect region. As shown in Figure 4 the normal region of the label image is black, and the defect region is white.

[0047] S302, the position of the defect region of the defect image is identified based on the plurality of first feature images by the second branch network, and a predicted defect image is obtained.

[0048] Referring to Figure 2 The defect image and the plurality of first feature images are input into the second branch network, and the second branch network outputs a predicted defect image. The second branch network is used to predict the position of the defect region of the defect image. The second loss value of the predicted defect image and the defect image obtained by the trained second branch network is required to be less than the second loss value threshold.

[0049] Further, the plurality of first feature images input into the second branch network can be part of the plurality of first feature images output by the first branch network. Exemplarily, referring to Figure 2 The first feature images (first feature image a0 to first feature image a(n-1)) other than the nth first feature image n are input into the second branch network.

[0050] S303, determine a first loss value of the predicted restored image relative to the defect image, and adjust the network parameters of the first branch network using the first loss value.

[0051] The first loss value of the predicted restored image and the defect image can be determined using a cross loss function.

[0052] In the embodiments of the present disclosure, the first branch network trained can restore the defect region of the defect image.

[0053] S304, determine a second loss value of the predicted defect image relative to the obtained label image, and adjust the network parameters of the first branch network and the second branch network using the second loss value.

[0054] The label image is used to represent the actual position of the defect region in the defect image.

[0055] In the embodiments of the present disclosure, the second loss value of the predicted defect image and the label image can be determined using a cross loss function. The second branch network trained can predict the position of the defect region of the defect image.

[0056] S305, end the training when it is determined that a preset training condition is met, and obtain a trained defect detection model.

[0057] In one case, the training condition is a training frequency threshold, that is, when the training frequency reaches the training frequency threshold, the training is ended, and the trained defect detection model is obtained. In another case, the training condition can be that the first loss value is less than a preset first loss value threshold, and the second loss value is less than a preset second loss value threshold.

[0058] In the embodiments of the present disclosure, the first branch network is used to restore the obtained mask image, to obtain a plurality of first feature images output by the first branch network and a predicted restored image. The mask image is obtained by performing mask processing on the defect region in the defect image. The second branch network is used to identify the position of the defect region in the defect image based on the plurality of first feature images, to obtain a predicted defect image. A first loss value of the predicted restored image relative to the defect image is determined, and the network parameters of the first branch network are adjusted using the first loss value. A second loss value of the predicted defect image relative to the obtained label image is determined, and the network parameters of the first branch network and the second branch network are adjusted using the second loss value. The label image is used to represent the actual position of the defect region in the defect image. When it is determined that a preset training condition is met, the training is ended, and a defect detection model capable of accurately identifying the surface defects of a product can be obtained.

[0059] Figure 5 Another step flowchart of a defect detection model training method provided by an exemplary embodiment of the present disclosure is provided. Specifically, the steps include:

[0060] S501, performing feature extraction on the mask image through a plurality of sequentially connected first convolution units to obtain a plurality of first feature images.

[0061] The first convolution unit outputs a corresponding first feature image, and the first feature image output by the i-th first convolution unit is the input of the (i+1)-th first convolution unit, i is an integer greater than or equal to 0, and the input of the 0-th first convolution unit is the mask image.

[0062] Referring to Figure 2 , the mask image is input into the first convolution unit 0, and the 0-th first feature image a0 is output. The 0-th first feature image a0 is input into the first convolution unit 1, and the 1-st first feature image a1 is output. The (n-1)-th first feature image a(n-1) is input into the first convolution unit n, and the n-th first feature image an is output. In this way, each first convolution unit corresponds to obtain a first feature image.

[0063] S502, processing part of the first feature images in the plurality of first feature images through a first feature processing unit to obtain a predicted restored image.

[0064] The part of the first feature images includes: the first feature image am to the first feature image an, where m is an integer between 0 (including 0) and n. For example, in Figure 2 , if n is 4 and m is 2, the part of the first feature images includes: the first feature image a2, the first feature image a3 and the first feature image a4.

[0065] In addition, referring to Figure 2 , the first feature processing unit includes a first splicing unit and a convolution unit.

[0066] The first splicing unit splices the part of the first feature images to obtain a first spliced image, and then the convolution unit convolves the first spliced image to obtain the predicted restored image.

[0067] S503, performing feature weight extraction processing on the first feature image output by the first convolution unit connected to the SE processing unit through the SE processing unit to obtain a third feature image.

[0068] The first feature image and the third feature image correspond one-to-one. The SE processing unit performs feature weight extraction processing on one first feature image to obtain one third feature image. Referring to Figure 2, the SE processing unit 0 is used to process the first feature image a0 to obtain the third feature image c0, the SE processing unit 1 is used to process the first feature image a1 to obtain the third feature image c1, and the SE processing unit 2 is used to process the first feature image a2 to obtain the third feature image c2. It can be understood that the SE processing unit i is used to process the first feature image ai to obtain the third feature image ci.

[0069] With reference to Figure 6 , the processing principle of the SE (Squeeze-and-Excitation Network) processing unit is shown, specifically: for any given transformation, F tr : X→U, where X is a first feature image, X∈R W ' ×H ' ×C ', U∈R W×H×C , F tr may represent a standard convolution operator. F sq (·) represents a global average pooling. F es (·, W) represents adaptive re-correction. F scale (·, ·) represents feature mapping. Wherein, is a third feature image. The structure and processing logic of the SE processing unit in the present disclosure are prior art, and will not be described here.

[0070] S504, feature extraction is performed on the defect image and the plurality of third feature images through the plurality of second convolution units to obtain a plurality of second feature images.

[0071] Wherein, each second convolution unit outputs a corresponding second feature image, the i-th third feature image and the second feature image output by the i-th second convolution unit are inputs of the i+1-th second convolution unit, and the input of the 0-th second convolution unit is the defect image.

[0072] With reference to Figure 2 , the number of second convolution units is the same as the number of first convolution units. The input of the second convolution unit 0 is the defect image and the output is the second feature image b0. The second feature image b0 and the third feature image c0 are input into the second convolution unit 1 to obtain the corresponding second feature image b1. The second feature image b(n-1) and the third feature image c(n-1) are input into the second convolution unit n to obtain the corresponding second feature image bn.

[0073] S505, processing is performed on part of the plurality of second feature images through a second feature processing unit to obtain a predicted defect image.

[0074] With reference to Figure 2The second feature processing unit comprises a second splicing unit, a convolution unit and a normalization unit. The partial second feature images comprise a second feature image bj to a second feature image bn, where j is an integer between 0 and n. For example, n is 4 and j is 1. The partial second feature images comprise a second feature image b1, a second feature image b2, a third feature image b3 and a fourth feature image b4.

[0075] Specifically, the partial second feature images are spliced by the second splicing unit to obtain a second spliced image, the second spliced image is convolved by the convolution unit, and then the normalized processing is performed by the normalization unit to obtain the predicted defect image.

[0076] S506, determining a first loss value of the predicted recovered image relative to the defect image, and adjusting the network parameters of the first branch network by using the first loss value.

[0077] S507, determining a first sub-label image under a first channel value and a second sub-label image under a second channel value according to the label image.

[0078] The values corresponding to the pixels of the normal area of the label image are the first channel value, the values corresponding to the pixels of the defect area of the label image are the second channel value, and the predicted defect image comprises a first sub-predicted image under the first channel value and a second sub-predicted image under the second channel value.

[0079] For example, if the first channel value is 0 and the second channel value is 1, the first sub-label image under the first channel value is a label image in which the defect area is represented by 0 and the normal area is represented by 1, and the second sub-label image under the second channel value is a label image in which the defect area is represented by 1 and the normal area is represented by 0. Figure 7 The values corresponding to the pixels of the label image are as shown in a value image P1. The first channel value 0 in the value image P1 represents the normal area in the label image, and the second channel value 1 in the value image P1 represents the defect area in the label image.

[0080] The values corresponding to the pixels in the defect area of the first sub-label image are the first channel value, the values corresponding to the pixels in the normal area of the first sub-label image are the second channel value, the values corresponding to the pixels in the defect area of the second sub-label image are the second channel value, and the values corresponding to the pixels in the normal area of the second sub-label image are the first channel value.

[0081] It can be understood that the first sub-label image is a sub-label image under the first channel value, and the second sub-label image is a sub-label image under the second channel value. For example, if the first channel value is 0 and the second channel value is 1, the first sub-label image is a label image in which the defect area is represented by 0 and the normal area is represented by 1, and the second sub-label image is a label image in which the defect area is represented by 1 and the normal area is represented by 0. Figure 7, the value corresponding to each pixel of the first sub-label image is like the value image P2, the first channel value 0 in the value image P2 represents the defect area in the label image, and the second channel value 1 in the value image P2 represents the normal area in the label image. The value corresponding to each pixel of the second sub-label image is like the value image P3, the first channel value 0 in the value image P3 represents the normal area in the label image, and the second channel value 1 in the value image P2 represents the defect area in the label image.

[0082] Further, the label image can also be obtained by inversely deducing the first sub-label image and the second sub-label image. Referring to Figure 7 , the value corresponding to the defect area in the first sub-label image is 0, and the value corresponding to the defect area in the second sub-label image is 1. Since 1 is greater than 0, the second channel value (second channel value 1) corresponding to the second sub-label image is selected for the defect area in the label image, so the channel value corresponding to the defect area in the label image is 1. Similarly, the value corresponding to the normal area in the first sub-label image is 1, and the value corresponding to the normal area in the second sub-label image is 0. Since 1 is greater than 0, the first channel value (first channel value 0) corresponding to the first sub-label image is selected for the normal area in the label image, so the channel value corresponding to the normal area in the label image is 0.

[0083] In the embodiments of the present disclosure, the second branch network outputs the first sub-prediction image under the first channel value and the second sub-prediction image under the second channel value, and then the final prediction defect image can be determined according to the first sub-prediction image and the second sub-prediction image.

[0084] , since the processing of the normalization unit, the values corresponding to each pixel in the first sub-prediction image and the second sub-prediction image are between -1 and 1. For example, referring to Figure 8 , the values corresponding to the same pixels in the first sub-prediction image and the second sub-prediction image are compared, and the channel value corresponding to the sub-prediction image with the larger value is obtained to obtain the value image corresponding to the prediction defect image. For example, the value corresponding to the pixel in the first row and the first column of the first sub-prediction image is 1, and the value corresponding to the pixel in the first row and the first column of the second sub-prediction image is -1. Among them, 1 is greater than -1, so it is determined that the value corresponding to the pixel in the first row and the first column of the prediction defect image is the first channel value 0. Similarly, the values corresponding to each pixel in the prediction defect image can be obtained, as shown in the value image P4. According to the value image P4, the first channel value is displayed as black, and the second channel value is displayed as white, so the prediction defect image as shown in Figure 8 can be obtained.

[0085] In the present disclosure, it can be understood that the first sub-prediction image and the second sub-prediction image output by the second branch network are the prediction defect image. It can also be understood that the second branch network outputs the first sub-prediction image and the second sub-prediction image, and then determines theFigure 8 the predicted defect image.

[0086] S508, determining a third loss value of the first sub-predicted image relative to the first sub-label image.

[0087] The third loss value of the first sub-predicted image relative to the first sub-label image can be determined by using a cross loss function.

[0088] In an embodiment of the present disclosure, a loss value can be calculated for each pixel of the first sub-predicted image relative to the first sub-label image, and then the loss values corresponding to the pixels are added to obtain the third loss value. For example, referring to Figure 7 and Figure 8 The third loss value is calculated according to the values corresponding to the pixels in the first sub-label image and the values corresponding to the pixels in the first sub-predicted image.

[0089] In another optional embodiment, determining the third loss value of the first sub-predicted image relative to the first sub-label image includes: determining a first region and a second region in the first sub-predicted image, the pixel position of the first region in the first sub-predicted image being the same as the pixel position of the defect region in the first sub-label image, and the difference between the pixel area of the second region and the pixel area of the first region being less than a first preset threshold; determining a fifth loss value of the first region relative to the defect region in the first sub-label image; determining a first label region in the normal region of the first sub-label image, the pixel position of the first label region in the first sub-label image being the same as the pixel position of the second region in the first sub-predicted image; determining a sixth loss value of the second region relative to the first label region; and determining the third loss value according to the fifth loss value and the sixth loss value.

[0090] The first sub-predicted image includes a first region and a second region, the first region corresponds to the defect region in the first sub-label image, and the second region corresponds to part of the normal region in the first sub-label image. For example, Figure 8 the first sub-predicted image in the first sub-label image.

[0091] In actual situations, the area of the defect region usually accounts for a very small proportion of the area of the defect image. If a loss value is calculated for each pixel of the first sub-predicted image and the first sub-label image, the proportion of the defect region will be very low, which will affect the prediction of the defect region by the second branch network. Therefore, in the present disclosure, a first preset threshold is set in advance, and the difference between the pixel area of the selected second region and the pixel area of the first region is less than the first preset threshold, which can improve the proportion of the defect region in calculating the loss value and further improve the training efficiency and quality of the defect detection model.

[0092] In the embodiments of the present disclosure, the fifth loss value and the sixth loss value can be directly added to obtain the third loss value. Alternatively, the third loss value can be determined according to the fifth loss value and the sixth loss value in other manners.

[0093] Further, the second region is determined by the following manner:

[0094] If the first channel value is 0 and the second channel value is 1, in the first sub-prediction image, a plurality of first prediction pixels corresponding to pixels with values less than or equal to a first preset value are determined in the region other than the first region, and the second region includes the plurality of first prediction pixels; if the first channel value is 1 and the second channel value is 0, in the first sub-prediction image, a plurality of second prediction pixels corresponding to pixels with values greater than or equal to the first preset value are determined in the region other than the first region, and the second region includes the plurality of second prediction pixels, and the first preset value is an integer between -1 and 1.

[0095] In the embodiments of the present disclosure, if the first channel value is 0 and the second channel value is 1, the value corresponding to the defect region of the label image is 1, and the value corresponding to the normal region is 0; the value corresponding to the defect region of the first sub-label image is 0, and the value corresponding to the normal region is 1. In order to make the value of the normal region of the first sub-prediction image predicted by the second branch network be 1 (the second channel value), it is necessary to make the value of the pixel other than the first region in the first sub-prediction image as large as possible (when the value of a pixel in the first sub-prediction image is greater than the value of the pixel in the second sub-prediction image, the value of the pixel in the obtained prediction defect image is 0), so in the present disclosure, the pixel less than or equal to the first preset value (such as 0) can be selected as the first prediction pixel of the second region. Since the value corresponding to the pixel less than or equal to the first preset value (such as 0) has a low probability of being greater than the value of the corresponding pixel in the second sub-prediction image, selecting this part of the pixel to calculate the loss value can improve the training efficiency of the second branch network. If the first channel value is 1 and the second channel value is 0, the opposite is true.

[0096] For example, referring to Figure 9 , the gray pixels are the first prediction pixels, and all the first prediction pixels form the second region.

[0097] Further, the loss value corresponding to the pixel of the first region is determined by the formula (1-e -x ) x, wherein x represents the value corresponding to the pixel of the first region. The loss value corresponding to the pixel of the second region is determined by the formula (1-e -(x-1) ) x, wherein x represents the value corresponding to the pixel of the second region.

[0098] In the embodiments of the present disclosure, the third loss value can be determined only according to the values corresponding to the pixels in the first region and the second region and the values corresponding to the pixels in the first sub-label image, the weight of the defect region is increased, and then the training efficiency and accuracy of the second branch network are improved.

[0099] S509, determining a fourth loss value of the second sub-prediction image relative to the second sub-label image.

[0100] The fourth loss value of the second sub-prediction image relative to the second sub-label image can be determined by using a cross loss function.

[0101] In an embodiment of the present disclosure, a loss value can be calculated for each pixel of the second sub-prediction image relative to the second sub-label image, and then the loss values corresponding to the pixels are added to obtain the fourth loss value. For example, referring to Figure 7 and Figure 8 , the third loss value is calculated according to the values corresponding to the pixels in the second sub-label image and the values corresponding to the pixels in the second sub-prediction image.

[0102] Further, the fourth loss value of the second sub-prediction image relative to the second sub-label image is determined, including: determining a third region and a fourth region in the second sub-prediction image, the pixel position of the third region in the second sub-prediction image is the same as the pixel position of the defect region in the second sub-label image, and the difference between the pixel area of the fourth region and the pixel area of the third region is less than a second preset threshold; determining a seventh loss value of the third region relative to the defect region in the second sub-label image; determining a second label region in the normal region of the second sub-label image, the pixel position of the second label region in the second total label image is the same as the pixel position of the fourth region in the second sub-prediction image; determining an eighth loss value of the fourth region relative to the second label region; and determining the fourth loss value according to the seventh loss value and the eighth loss value.

[0103] The second sub-prediction image includes a third region and a fourth region, the third region corresponds to the defect region in the second sub-label image, and the fourth region corresponds to part of the normal region in the second sub-label image. For example, Figure 8 the second sub-prediction image in the embodiment.

[0104] In actual situations, the area of the defect region usually accounts for a very small proportion of the area of the defect image. If the loss value is calculated for each pixel of the second sub-prediction image and the second sub-label image, the proportion of the defect region will be very low, which will affect the prediction of the defect region by the second branch network. Therefore, in the present disclosure, a second preset threshold is set in advance. The first preset threshold and the second preset threshold can be the same or different. The difference between the pixel area of the fourth region and the pixel area of the third region is less than the second preset threshold. In this way, the proportion of the defect region in the calculation of the loss value can be improved, and the training efficiency and quality of the defect detection model can be further improved.

[0105] In the embodiments of the present disclosure, the fourth loss value can be obtained by directly adding the seventh loss value and the eighth loss value. Alternatively, the fourth loss value can be determined according to the seventh loss value and the eighth loss value in other ways.

[0106] Further, the fourth region is determined in the following way:

[0107] If the first channel value is 0 and the second channel value is 1, a plurality of third prediction pixels with a value greater than or equal to a second preset value are determined in the region other than the third region in the second sub-prediction image, and the fourth region includes the plurality of third prediction pixels. If the first channel value is 1 and the second channel value is 0, a plurality of fourth prediction pixels with a value less than or equal to a second preset value are determined in the region other than the third region in the second sub-prediction image, and the fourth region includes the plurality of fourth prediction pixels. The second preset value is an integer between -1 and 1.

[0108] In the embodiments of the present disclosure, if the first channel value is 0 and the second channel value is 1, the value corresponding to the defect region of the label image is 1, and the value corresponding to the normal region is 0. The value corresponding to the defect region of the second sub-label image is 1, and the value corresponding to the normal region is 0. When training the second branch network, it is expected that the value corresponding to the normal region of the second sub-prediction image predicted by the second branch network is 0 (the first channel value). Therefore, the value of the pixel other than the third region in the second sub-prediction image needs to be as small as possible (when the value of a pixel in the second sub-prediction image is less than the value in the first sub-prediction image, the value of the pixel in the predicted defect image is 0). Therefore, in the present disclosure, the pixels greater than or equal to the first preset value (such as 0) can be selected as the third prediction pixels of the second region. Since the value corresponding to the pixels greater than or equal to the first preset value (such as 0) has a low probability of being less than the value of the corresponding pixel in the first sub-prediction image, selecting these pixels to calculate the loss value can improve the training efficiency of the second branch network. If the first channel value is 1 and the second channel value is 0, the opposite is true.

[0109] Further, the loss value corresponding to the pixel of the third region is calculated by formula (1-e -x) x (1-x) is determined, wherein x represents the value corresponding to the pixel of the fourth region. -(x-1) ) x (1-x) is determined, wherein x represents the value corresponding to the pixel of the fourth region.

[0110] In the embodiments of the present disclosure, the fourth loss value can be determined only according to the values corresponding to the pixels of the third region and the fourth region and the values corresponding to the pixels in the second sub-label image, the weight of the defect region is improved, and then the training efficiency and accuracy of the second branch network are improved.

[0111] S510, the second loss value is determined according to the third loss value and the fourth loss value.

[0112] In the embodiments of the present disclosure, the second loss value can be obtained by directly adding the third loss value and the fourth loss value. Alternatively, the second loss value can be determined according to the third loss value and the fourth loss value in other manners.

[0113] Further, a normal image and a label image of the normal image are obtained, the normal image has no defect region; and the defect detection model is trained by using the normal image and the label image of the normal image.

[0114] Since the normal image has no defect region, the mask image of the normal image is the normal image itself. The values corresponding to the pixels of the label image of the normal image are the same, such as 1 or 0. For example, the label image of the normal image is displayed as all black or all white.

[0115] Specifically, the normal image is processed by the first branch network to obtain a plurality of feature images output by the first branch network and a predicted restoration image of the normal image; the normal image is recognized based on the plurality of feature images by the second branch network to obtain a predicted image; a loss value of the predicted image relative to the normal image is determined, and the network parameters of the first branch network are adjusted by using the loss value; a loss value of the predicted image relative to the label image of the normal sample is determined, and the network parameters of the second branch network are adjusted by using the loss value. The specific process of training the defect detection model by using the normal image can refer to the above embodiments, and will not be described here.

[0116] S511, in a case where it is determined that the preset training condition is met, the training is ended, and a trained defect detection model is obtained.

[0117] The specific implementation process of this step refers to S305, and will not be described here.

[0118] In the present disclosure, a defect region of a defect image is added to a mask to obtain a mask image, and then the mask image is input into a first branch network. Convolution is performed on the mask image by a plurality of first convolution units in the first branch network to obtain a plurality of first feature images. Then, a first feature processing unit is used for restoration to obtain a predicted restoration image. The defect image and the first feature image are input into a second branch network for prediction of a defect position to obtain a predicted defect image. Then, a loss value is calculated, and the defect detection model is adjusted using the loss value to obtain a trained defect detection model. The defect detection model can accurately and efficiently detect whether there is a defect in the image and the position of the defect when there is a defect.

[0119] With reference to Figure 10 A flowchart of steps of a defect detection method according to the present disclosure is provided, and the steps include the following steps.

[0120] S1001, a target image is obtained.

[0121] The target image includes a to-be-detected object. In the present disclosure, the target image is collected for the to-be-detected image.

[0122] S1002, a defect prediction is performed on the target image by using a defect detection model to obtain a predicted defect image output by a second branch network of the defect detection model.

[0123] The predicted defect image is used to indicate a position of a defect in the to-be-detected object. The defect detection model is obtained according to the defect detection model training method of any one of the above.

[0124] In the inference stage, with reference to Figure 11 The target image is input into the first branch network and the second branch network of the defect detection model. After the target image is input into the first branch network and is processed by the first convolution unit 0 to the first convolution unit n-0, a plurality of feature images can be obtained. Then, part of the feature images and the target image are input into the second branch network, and the predicted defect image can be obtained after processing by the second branch network. If the target image is a defect-free image, the values of all pixels in the predicted defect image are the same, such as a black image or a white image. If the target image is a defective image, the values of pixels in the defect region of the predicted defect image are different from the values of pixels in a normal region, such as a white defect region and a black normal region.

[0125] In the present disclosure, the pre-trained defect detection model can accurately and efficiently detect whether the target image is a defective image and the position of the defect region when the target image is a defective image.

[0126] With reference to Figure 12A structural block diagram of a defect detection model training apparatus 120 is provided for the present disclosure, the defect detection model comprising a first branch network and a second branch network, and the defect detection model training apparatus 120 specifically comprises:

[0127] A restoration module 121 is configured to perform restoration processing on the obtained mask image through the first branch network to obtain a plurality of first feature images output by the first branch network and a predicted restoration image, the mask image being obtained by performing mask processing on the defect region in the defect image;

[0128] An identification module 122 is configured to identify the position of the defect region in the defect image based on the plurality of first feature images through the second branch network to obtain a predicted defect image.

[0129] A first adjustment module 123 is configured to determine a first loss value of the predicted restoration image relative to the defect image, and adjust the network parameters of the first branch network using the first loss value.

[0130] A second adjustment module 124 is configured to determine a second loss value of the predicted defect image relative to an obtained label image, and adjust the network parameters of the first branch network and the second branch network using the second loss value, the label image being used to represent the actual position of the defect region in the defect image.

[0131] A judgment module 125 is configured to end the training and obtain a trained defect detection model when it is determined that a preset training condition is met.

[0132] In an optional embodiment, the first branch network comprises a plurality of first convolution units and a first feature processing unit connected in sequence, and the restoration module 121 is specifically configured to: perform feature extraction on the mask image through the plurality of first convolution units connected in sequence to obtain a plurality of first feature images, wherein each first convolution unit outputs a corresponding first feature image, the first feature image output by an i-th first convolution unit being the input of an i+1-th first convolution unit, i being an integer greater than or equal to 0, and the input of a 0-th first convolution unit being the mask image; and perform processing on part of the plurality of first feature images through the first feature processing unit to obtain the predicted restoration image.

[0133] In an optional embodiment, the second branch network comprises: a plurality of sequentially connected second convolution units, a plurality of SE processing units, and a second feature processing unit, an output end of an i th first convolution unit is connected to an input end of an i+1 th second convolution unit through a corresponding SE processing unit, and the identification module 122 is specifically configured to: perform feature weight extraction processing on the first feature image output by the first convolution unit connected to the SE processing unit through the SE processing unit to obtain a third feature image, the first feature image and the third feature image are in one-to-one correspondence; performing feature extraction on the defect image and the plurality of third feature images through the plurality of second convolution units to obtain a plurality of second feature images, wherein each second convolution unit outputs a corresponding second feature image, the i th third feature image and the second feature image output by the i th second convolution unit are the input of the i+1 th second convolution unit, and the input of the 0 th second convolution unit is the defect image; performing processing on part of the plurality of second feature images through the second feature processing unit to obtain a predicted defect image.

[0134] In an optional embodiment, the value corresponding to the pixel of the normal region of the label image is a first channel value, the value corresponding to the pixel of the defect region of the label image is a second channel value, and the predicted defect image comprises: a first sub-predicted image under the first channel value and a second sub-predicted image under the second channel value, and the second adjusting module 124 is specifically configured to: determine a first sub-label image under the first channel value and a second sub-label image under the second channel value according to the label image, the value corresponding to each pixel in the defect region of the first sub-label image is the first channel value, the value corresponding to each pixel in the normal region of the first sub-label image is the second channel value, the value corresponding to each pixel in the defect region of the second sub-label image is the second channel value, and the value corresponding to each pixel in the normal region of the second sub-label image is the first channel value; determine a third loss value of the first sub-predicted image relative to the first sub-label image; determine a fourth loss value of the second sub-predicted image relative to the second sub-label image; and determine a second loss value according to the third loss value and the fourth loss value.

[0135] In an optional embodiment, the second adjusting module 124 is specifically configured to: determine a first region and a second region in the first sub-prediction image, the pixel position of the first region in the first sub-prediction image is the same as that of the defect region in the first sub-label image, and the difference between the pixel area of the second region and that of the first region is less than a first preset threshold; determine a fifth loss value of the first region relative to the defect region in the first sub-label image; determine a first label region in the normal region of the first sub-label image, the pixel position of the first label region in the first sub-label image is the same as that of the second region in the first sub-prediction image; determine a sixth loss value of the second region relative to the first label region; and determine the third loss value according to the fifth loss value and the sixth loss value.

[0136] In an optional embodiment, the second adjusting module 124 determines the second region in the following manner: if the first channel value is 0 and the second channel value is 1, the second region includes a plurality of first prediction pixels in the region other than the first region in the first sub-prediction image, the value corresponding to the pixels of the plurality of first prediction pixels being less than or equal to a first preset value; if the first channel value is 1 and the second channel value is 0, the second region includes a plurality of second prediction pixels in the region other than the first region in the first sub-prediction image, the value corresponding to the pixels of the plurality of second prediction pixels being greater than or equal to the first preset value, and the first preset value is an integer between -1 and 1.

[0137] In an optional embodiment, the second adjusting module 124 is specifically configured to: determine a third region and a fourth region in the second sub-prediction image, the pixel position of the third region in the second sub-prediction image is the same as that of the defect region in the second sub-label image, and the difference between the pixel area of the fourth region and that of the third region is less than a second preset threshold; determine a seventh loss value of the third region relative to the defect region in the second sub-label image; determine a second label region in the normal region of the second sub-label image, the pixel position of the second label region in the second sub-label image is the same as that of the fourth region in the second sub-prediction image; determine an eighth loss value of the fourth region relative to the second label region; and determine the fourth loss value according to the seventh loss value and the eighth loss value.

[0138] In an optional embodiment, the second adjusting module 124 determines the fourth region by the following manner: if the first channel value is 0 and the second channel value is 1, in the region other than the third region in the second sub-prediction image, a plurality of third prediction pixels corresponding to a pixel value greater than or equal to a second preset value are determined, and the fourth region includes the plurality of third prediction pixels; if the first channel value is 1 and the second channel value is 0, in the region other than the third region in the second sub-prediction image, a plurality of fourth prediction pixels corresponding to a pixel value less than or equal to a second preset value are determined, and the fourth region includes the plurality of fourth prediction pixels, and the second preset value is an integer between -1 and 1.

[0139] In an optional embodiment, the method further comprises: a training module (not shown) configured to obtain a normal image and a label image of the normal image, the normal image being free of defect regions; and training the defect detection model by using the normal image and the label image of the normal image.

[0140] The defect detection model training apparatus provided by the present disclosure can implement the defect detection model training method described above, and details are referred to the above, which will not be repeated here.

[0141] Reference Figure 13 FIG. 1 is a structural block diagram of a defect detection apparatus 130 provided by the present disclosure, and the defect detection model training apparatus 130 specifically comprises:

[0142] The acquisition module 131 is configured to acquire a target image, and the target image includes a to-be-detected object.

[0143] The prediction module 132 is configured to input the target image into the first branch network and the second branch network of the defect detection model, perform defect prediction on the target image by using the defect detection model, and obtain a predicted defect image output by the second branch network of the defect detection model, the predicted defect image being used to represent a position of a defect in the to-be-detected object, and the defect detection model is obtained according to any one of the defect detection model training methods described above.

[0144] The defect detection apparatus provided by the present disclosure can implement the defect detection method described above, and details are referred to the above, which will not be repeated here.

[0145] In addition, in some of the processes described in the above embodiments and the accompanying drawings, a plurality of operations appearing in a specific order are included, but it should be clearly understood that these operations can be executed in the order appearing in the present disclosure or in parallel, and the serial numbers themselves do not represent any execution order. In addition, these processes can include more or fewer operations, and the operations can be executed in sequence or in parallel. It should be noted that the descriptions of “second”, “first” and the like in the present disclosure are used to distinguish different messages, devices, modules and the like, and do not represent the order of precedence. “Second” and “first” are not of different types.

[0146] Figure 14 A structural schematic diagram of an electronic device is provided for an example embodiment of the present disclosure. As shown, the electronic device 140 includes a processor 141 and a memory 142 connected to the processor 141 in communication, and the memory 142 stores computer execution instructions. Figure 14

[0147] The processor executes the computer execution instructions stored in the memory to implement the defect detection model training method and / or the defect detection method provided by any of the above method embodiments, and the specific functions and technical effects that can be achieved are not repeated here.

[0148] The present disclosure also provides a computer-readable storage medium, which stores computer execution instructions, and the computer execution instructions are executed by a processor to implement any of the above methods.

[0149] The present disclosure also provides a computer program product, which includes a computer program stored in a readable storage medium, and at least one processor of an electronic device can read the computer program from the readable storage medium, and the at least one processor executes the computer program to make the electronic device execute any of the above methods.

[0150] In several embodiments provided by the present disclosure, it should be understood that the disclosed system and method can be implemented by other manners. For example, the system embodiments described above are merely schematic, for example, the division of units is merely a logical function division, and actual implementation can have another division manner, for example, a plurality of units or components can be combined or integrated into another system, or some features can be ignored or not executed. In addition, the coupling or direct coupling or communication connection between the units shown or discussed can be indirect coupling or communication connection through some interfaces, systems or units, which can be electrical, mechanical or other forms.

[0151] The units described as separate components can or can not be physically separate, and the components shown as units can or can not be physical units, that is, they can be located in one place, or can be distributed on a plurality of network units. Some or all of the units can be selected according to actual needs to achieve the purpose of the present embodiment.

[0152] In addition, each functional unit in each embodiment of the present disclosure can be integrated in one processing unit, or each unit can exist physically, or two or more units can be integrated in one unit. The integrated unit can be realized in the form of hardware, or in the form of hardware plus software function unit.

[0153] ​The integrated unit implemented in the form of software function unit can be stored in a computer readable storage medium. The software function unit is stored in a storage medium, and includes a plurality of instructions for enabling a computer device (which can be a personal computer, a server, or a network device, etc.) or a processor to execute part of steps of the method of various embodiments of the present disclosure. The aforementioned storage medium includes a U disk, a mobile hard disk, a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk, and various media capable of storing program codes.

[0154] Those skilled in the art can clearly understand that, for the convenience and brevity of description, only the above-mentioned division of functional modules is taken as an example, and in actual application, the above-mentioned functions can be completed by different functional modules according to needs, that is, the internal structure of the system is divided into different functional modules to complete all or part of the functions described above. The specific working process of the system described above can refer to the corresponding process in the foregoing method embodiments, and will not be described here.

[0155] Other embodiments of the present disclosure will be readily apparent to those skilled in the art upon considering the description hereof, based upon the disclosure herein. The present disclosure is intended to cover any variations, uses, or adaptations of the present disclosure following, in general, the principles of the present disclosure and including such departures from the present disclosure that come within known or customary practice in the art to which the present disclosure pertains or that involve known or customary practices. The specification and examples are to be regarded as exemplary in nature and not as restrictive, as the true scope and spirit of the present disclosure is indicated by the claims.

[0156] It should be understood that the present disclosure is not limited to the precise structures described and shown in the drawings, and that various modifications and changes can be made without departing from its scope. The scope of the present disclosure is limited only by the claims.

Claims

1. A defect detection model training method, characterized in that, The defect detection model comprises a first branch network and a second branch network, the defect detection model training method comprises: The first branch network is used for performing restoration processing on the obtained mask image, to obtain a plurality of first feature images and a predicted restoration image output by the first branch network, the mask image being obtained by performing mask processing on a defect region in a defect image; The second branch network is used for identifying a position of the defect region in the defect image based on the plurality of first feature images, to obtain a predicted defect image; A first loss value of the predicted restoration image relative to the defect image is determined, and the first loss value is used to adjust network parameters of the first branch network; A second loss value of the predicted defect image relative to an obtained label image is determined, and the second loss value is used to adjust network parameters of the first branch network and the second branch network, the label image being used to indicate an actual position of the defect region in the defect image; In a case where it is determined that a preset training condition is met, the training is ended, and a trained defect detection model is obtained. 2.The defect detection model training method of claim 1, wherein, The first branch network comprises a plurality of first convolution units and a first feature processing unit connected in sequence, and the restoration processing on the obtained mask image by the first branch network comprises: The mask image is subjected to feature extraction by the plurality of first convolution units connected in sequence, to obtain a plurality of first feature images, wherein each first convolution unit outputs a corresponding first feature image, and an i-th first convolution unit outputs a first feature image as an input of an i+1-th first convolution unit, i being an integer greater than or equal to 0, and an input of a 0-th first convolution unit being the mask image; The first feature processing unit is used for processing part of the plurality of first feature images, to obtain the predicted restoration image. 3.The defect detection model training method of claim 2, wherein, The second branch network comprises a plurality of second convolution units, a plurality of SE processing units and a second feature processing unit, an output end of an i-th first convolution unit being connected to an input end of an i+1-th second convolution unit through a corresponding SE processing unit, and the identification of the position of the defect region in the defect image based on the plurality of first feature images by the second branch network comprises: The SE processing unit is used for performing feature weight extraction processing on a first feature image output by the first convolution unit connected to the SE processing unit, to obtain a third feature image, the first feature image and the third feature image corresponding to each other; The plurality of second convolution units are used for performing feature extraction on the defect image and the plurality of third feature images, to obtain a plurality of second feature images, wherein each second convolution unit outputs a corresponding second feature image, an i-th third feature image and a second feature image output by an i-th second convolution unit being an input of an i+1-th second convolution unit, and an input of a 0-th second convolution unit being the defect image; The second feature processing unit processes part of the plurality of second feature images to obtain the predicted defect image. 4.The defect detection model training method of any one of claims 1 to 3, wherein, The value corresponding to a pixel in the normal area of the label image is a first channel value, the value corresponding to a pixel in the defect area of the label image is a second channel value, and the predicted defect image includes a first sub-predicted image under the first channel value and a second sub-predicted image under the second channel value. According to the label image, a first sub-label image under the first channel value and a second sub-label image under the second channel value are determined, the value corresponding to each pixel in the defect area of the first sub-label image is the first channel value, the value corresponding to each pixel in the normal area of the first sub-label image is the second channel value, the value corresponding to each pixel in the defect area of the second sub-label image is the second channel value, and the value corresponding to each pixel in the normal area of the second sub-label image is the first channel value. A third loss value of the first sub-predicted image relative to the first sub-label image is determined. A fourth loss value of the second sub-predicted image relative to the second sub-label image is determined. The second loss value is determined according to the third loss value and the fourth loss value. 5.The defect detection model training method of claim 4, wherein, The determination of the third loss value of the first sub-predicted image relative to the first sub-label image includes: A first area and a second area are determined in the first sub-predicted image, the pixel position of the first area in the first sub-predicted image is the same as that of the defect area in the first sub-label image, and the difference between the pixel area of the second area and that of the first area is less than a first preset threshold. A fifth loss value of the first area relative to the defect area in the first sub-label image is determined. A first label area is determined in the normal area of the first sub-label image, the pixel position of the first label area in the first sub-label image is the same as that of the second area in the first sub-predicted image. A sixth loss value of the second area relative to the first label area is determined. The third loss value is determined according to the fifth loss value and the sixth loss value.

6. The defect detection model training method of claim 5, wherein, The second area is determined in the following manner: If the first channel value is 0 and the second channel value is 1, a plurality of first predicted pixels whose corresponding values are less than or equal to a first preset value are determined in the area other than the first area in the first sub-predicted image, and the second area includes the plurality of first predicted pixels. If the first channel value is 1 and the second channel value is 0, a plurality of second predicted pixels whose corresponding values are greater than or equal to a first preset value are determined in the area other than the first area in the first sub-predicted image, and the second area includes the plurality of second predicted pixels, and the first preset value is an integer between -1 and 1. 7.The defect detection model training method of claim 4, wherein, The determination of the fourth loss value of the second sub-predicted image relative to the second sub-label image includes: determining a third region and a fourth region in the second sub-prediction image, the third region having a same pixel position in the second sub-prediction image as a pixel position of the defect region in the second sub-label image, and a difference between a pixel area of the fourth region and a pixel area of the third region being less than a second preset threshold value; determining a seventh loss value of the third region relative to the defect region in the second sub-label image; determining a second label region in a normal region of the second sub-label image, the second label region having a same pixel position in the second sub-label image as a pixel position of the fourth region in the second sub-prediction image; determining an eighth loss value of the fourth region relative to the second label region; determining the fourth loss value according to the seventh loss value and the eighth loss value. 8.The defect detection model training method of claim 7, wherein, The fourth region is determined by the following manner: if the first channel value is 0 and the second channel value is 1, determining a plurality of third prediction pixels in a region other than the third region in the second sub-prediction image, the plurality of third prediction pixels corresponding to a value greater than or equal to a second preset value, and the fourth region including the plurality of third prediction pixels; if the first channel value is 1 and the second channel value is 0, determining a plurality of fourth prediction pixels in a region other than the third region in the second sub-prediction image, the plurality of fourth prediction pixels corresponding to a value less than or equal to the second preset value, and the fourth region including the plurality of fourth prediction pixels, the second preset value being an integer between -1 and 1. 9.The defect detection model training method of any one of claims 1 to 3, wherein, Further comprising: obtaining a normal image and a label image of the normal image, the normal image having no defect region; training the defect detection model using the normal image and the label image of the normal image.

10. A defect detection method characterized by, Comprising: obtaining a target image, the target image including a to-be-detected object; inputting the target image into a first branch network and a second branch network of a defect detection model, performing defect prediction on the target image by using the defect detection model, and obtaining a prediction defect image output by the second branch network of the defect detection model, the prediction defect image being used to represent a position of a defect in the to-be-detected object, the defect detection model being obtained according to the defect detection model training method in any one of claims 1 to 9.

11. A defect detection apparatus characterized by comprising: Comprising: an obtaining module, configured to obtain a target image, the target image including a to-be-detected object; a prediction module, configured to input the target image into a first branch network and a second branch network of a defect detection model, perform defect prediction on the target image by using the defect detection model, and obtain a prediction defect image output by the second branch network of the defect detection model, the prediction defect image being used to represent a position of a defect in the to-be-detected object, the defect detection model being obtained according to the defect detection model training method in any one of claims 1 to 9.

12. An electronic device, comprising: Comprising: a processor, a memory, and a computer program stored on the memory and executable on the processor, the processor implementing the defect detection model training method in any one of claims 1 to 9 and / or the defect detection method in claim 10 when executing the computer program.

13. A computer-readable storage medium, characterized in that, The computer readable storage medium stores computer execution instructions, and the computer execution instructions are used for implementing the defect detection model training method in any one of claims 1 to 9 and / or the defect detection method in claim 10 when executed by the processor.

Citation Information

Patent Citations

  • Image data processing method and device, electronic equipment and storage medium

    CN113420770A

  • Defect detection network training method, defect detection method and related equipment

    CN115240023A