Industrial defect image pixel-level label generation method and device

Through the combination of VAE decoder and U-Net encoder, high-resolution features are integrated to generate refined features, which solves the problem of inaccurate annotation of defective areas in industrial scenes, achieves precise alignment of high-resolution pixel-level annotations, and improves The effectiveness of industrial defect detection.

CN118823780AActive Publication Date: 2024-10-22HUAZHONG UNIV OF SCI & TECH

Patent Information

Application Number
CN202410796706.7
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-06-20
Publication Date
2024-10-22
Estimated Expiration
2044-06-20

AI Technical Summary

Technical Problem

Existing technology cannot achieve high-resolution pixel-level annotation accurately aligned with defective areas in industrial scenes, especially in the case of a small number of annotated defect images, which affects the performance of industrial defect detection tasks.

Method used

Using a combination of VAE decoder and U-Net encoder decoder, discriminative features are extracted through defect image branches and normal image branches, and high-resolution features are fused to generate refined features for high-resolution pixel-level annotation, and through The objective function optimizes the annotation generation model.

Benefits of technology

It achieves high-resolution pixel-level annotation that is accurately aligned with the defect area, improving the application effect of industrial defect detection, especially in the case of small samples, and can effectively generate high-quality annotations.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118823780A_ABST
    Figure CN118823780A_ABST
Patent Text Reader

Abstract

The invention relates to the technical field of computer vision, and provides an industrial defect image pixel-level label generation method and device. The method comprises the following steps of: extracting discriminative characteristics of a defect image, and performing low-resolution pixel-level labeling on the defect image by using the discriminative characteristics of the defect image; extracting discriminative features of the normal image, and performing low-resolution pixel-level labeling on the normal image by using the discriminative features of the normal image; fusing the discriminative feature of the defect image and the high-resolution feature output by the VAE decoder to obtain a refined feature, and performing high-resolution pixel-level labeling on the defect image by using the refined feature; and generating an objective function according to the low-resolution pixel-level annotations and the high-resolution pixel-level annotations of the defect image and the normal image, the defect image mask and the normal image mask, and optimizing the annotation generation model by using the objective function. According to the invention, high-resolution pixel-level labeling which is accurately aligned with the defect area can be realized.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of computer vision technology, and in particular to a method and device for generating pixel-level annotations for industrial defect images. Background Art

[0002] Existing methods for generating pixel-level annotations for industrial defect images cannot meet the requirements of accurate alignment of annotations with defect parts in industrial scenarios. Methods based on generative adversarial networks usually require hundreds of manually annotated training images, which cannot meet the requirements of using only a small number of annotated defect images (generally less than 5 images) in industrial scenarios to train annotation generation models. Based on the diffusion model, some recent works generate pixel-level annotations by utilizing the cross-attention map between text and image. However, due to the low resolution of the cross-attention map, upsampling is required to obtain pixel-level annotations with the same high resolution as the image. The upsampling process causes the pixel-level annotations of the defect area boundaries in the defect image to be unable to be accurately aligned with the defect area, affecting the application effect of industrial defect images and annotations in industrial defect detection tasks.

[0003] In view of this, overcoming the defects of the prior art is an urgent problem to be solved in the field of this technology. Summary of the invention

[0004] The technical problem to be solved by the present invention is that in the prior art, it is impossible to achieve high-resolution pixel-level annotation that is precisely aligned with the defect area.

[0005] The present invention adopts the following technical solution:

[0006] In a first aspect, the present invention provides a method for generating pixel-level annotations for industrial defect images, training an annotation generation model, and using the trained annotation generation model to generate pixel-level annotations; the annotation generation model includes a VAE encoder, a U-Net encoder, a U-Net decoder, a VAE decoder, a feature refinement module, and a mask prediction module; wherein the method is further divided into a defect image branch and a normal image branch, the VAE encoder, the U-Net encoder, the U-Net decoder, the VAE decoder, the feature refinement module, and the mask prediction module constitute the defect image branch, and the VAE encoder, the U-Net encoder, the U-Net decoder, the VAE decoder, and the mask prediction module also constitute the normal image branch; the training of the annotation generation model specifically includes:

[0007] The defect image branch extracts discriminative features of the defect image, and uses the discriminative features of the defect image to perform low-resolution pixel-level annotation on the defect image;

[0008] The normal image branch extracts discriminative features of the normal image, and uses the discriminative features of the normal image to perform low-resolution pixel-level annotation on the normal image;

[0009] The defect image branch fuses the discriminative features of the defect image with the high-resolution features output by the VAE decoder to obtain refined features, and uses the refined features to perform high-resolution pixel-level annotation on the defect image.

[0010] Upsampling the low-resolution pixel-level annotations of the normal image to obtain high-resolution pixel-level annotations of the normal image;

[0011] According to the low-resolution pixel-level annotation of the defect image, the low-resolution pixel-level annotation of the normal image, the high-resolution pixel-level annotation of the defect image, the high-resolution pixel-level annotation of the normal image, the defect image mask and the normal image mask, an objective function is generated, and the annotation generation model is optimized using the objective function.

[0012] Preferably, the discriminative features of the defect image include a first feature F1 and a second feature F2; extracting the discriminative features of the defect image and using the discriminative features of the defect image to perform low-resolution pixel-level annotation on the defect image specifically includes:

[0013] Use a 3×3 convolution block to compress the number of channels of the first feature F1 output by the U-Net decoder to obtain a first compressed feature F′1, and use a convolution block to compress the number of channels of the second feature F2 output by the U-Net decoder to obtain a second compressed feature F′2; wherein the first feature F1 is a feature output by the second level of the U-Net decoder, and the second feature F2 is a feature output by the third level of the U-Net decoder;

[0014] Upsample the first compressed feature F′1, and concatenate the upsampled result of the first compressed feature F′1 with the second compressed feature F′2 to obtain a concatenated feature F;

[0015] Apply multiple transformation layers to the spliced ​​feature F to obtain a rough feature

[0016] In the rough features A 3×3 convolutional layer and a softmax function are applied to generate low-resolution pixel-level annotations of the defect image.

[0017] Preferably, the high-resolution feature includes the i-th high-resolution feature, where i is an integer, i is greater than 0 and i is less than 4; the discriminative feature of the defect image and the high-resolution feature output by the VAE decoder are fused to obtain the refined feature, specifically including:

[0018] The i-th level feature and the i-th high-resolution feature are sequentially merged to obtain the i+1-th level feature, and the fourth-level feature is used as the refined feature; wherein the discriminative feature of the defect image is used as the first-level feature;

[0019] The step of fusing the i-th level feature with the i-th high-resolution feature to obtain the i+1-th level feature specifically includes:

[0020] Align the i-th level feature with the i-th high-resolution feature;

[0021] After performing 1×1 convolution and upsampling on the i-th level feature in sequence, it is element-wise multiplied with the corresponding aligned i-th high-resolution feature to obtain the i-th optimized boundary feature;

[0022] After the i-th level feature is processed by two convolution blocks, it is added to the i-th optimized boundary feature to obtain the i+1-th level feature.

[0023] Preferably, the use of refined features to perform high-resolution pixel-level annotation on the defect image specifically includes:

[0024] A 3×3 convolutional layer and a softmax function are applied to the refined features to generate pixel-level annotations of defects.

[0025] Use the preset threshold τ to annotate the defect pixel level The second channel of is binarized to obtain high-resolution pixel-level annotation of the defect image.

[0026] Preferably, the defect image mask includes a low-resolution real mask of the defect image and a high-resolution real mask of the defect image, and the normal image mask includes a low-resolution real mask of the normal image and a high-resolution real mask of the normal image; the generating the objective function according to the low-resolution pixel-level annotation of the defect image, the low-resolution pixel-level annotation of the normal image, the high-resolution pixel-level annotation of the defect image, the high-resolution pixel-level annotation of the normal image, the defect image mask and the normal image mask specifically includes:

[0027] The objective function is

[0028]

[0029] Among them, F() represents the calculation of Focal loss, and They represent low-resolution pixel-level annotation of defect images and high-resolution pixel-level annotation of defect images, respectively. and They represent the low-resolution pixel-level annotation of normal images and the high-resolution pixel-level annotation of normal images, respectively. df and M′df denote the low-resolution true mask of the defect image and the high-resolution true mask of the defect image, respectively, and M ob and M′ ob They represent the low-resolution true mask of the normal image and the high-resolution true mask of the normal image, respectively.

[0030] Preferably, the defect image is generated in advance using a few-sample defect image generation model, the few-sample defect image generation model includes the U-Net encoder, the U-Net decoder, the attention module, the first objective function, the second objective function and the third objective function; wherein the attention module, the first objective function and the second objective function are divided into a defect image branch, and the third objective function is divided into a normal image branch; the training process of the two branches is carried out separately, but is implemented on a shared U-Net; the few-sample defect image generation model is trained using a hybrid training strategy, specifically including:

[0031] Combining multiple defect words and a single product word to obtain an unbalanced abnormal text prompt, and inputting the unbalanced abnormal text prompt and the product-related part of the unbalanced abnormal text prompt as guiding conditions into the defect image branch and the normal image branch respectively;

[0032] Selecting a few-sample defect image and a corresponding defect image mask as input of a defect image branch, the defect image branch obtains features of the defect image, and aligns defect words in the unbalanced abnormal text prompt to the defect area in the image according to the defect image mask corresponding to the defect image, so as to optimize the first objective function and the second objective function;

[0033] A fixed number of normal images are selected as input of the normal image sample branch, the normal image branch obtains the features of the normal images, and uses the product-related parts of the unbalanced abnormal text prompts to optimize the third objective function; wherein the hybrid training strategy is used to enable defect images of different defect categories to participate in training together.

[0034] Preferably, the first objective function is in, is the cross-attention map corresponding to the nth defective word, N is the number of defective words, L represents the number of U-Net layers corresponding to the cross-attention map used in the alignment process, and M l is a binary mask with a size of r×r pixels, where the value of the defective area is 1 and the value of the non-defective area is 0. is the cross attention map corresponding to the product word, ⊙ is the multiplication operation per pixel;

[0035] The second objective function is Among them, edf represents the conditional vector obtained after the unbalanced abnormal text prompt passes through the text encoder, z df is the defect image x df The latent vector obtained by the VAE encoder, ∈ df is random noise, t df is the number of noise adding steps, To use ∈ df and ∈ df Right df The noise latent vector obtained by adding noise is the predicted noise.

[0036] Preferably, the third objective function is

[0037]

[0038] ; Among them, e ob represents the conditional vector obtained after the product-related part of the unbalanced abnormal text prompt passes through the text encoder, z ob For the normal image x ob The latent vector obtained by the VAE encoder, ∈ ob is random noise, t ob is the number of noise adding steps, To use ∈ ob and t ob Right ob The noisy latent vector obtained by adding noise is is the predicted noise.

[0039] In a second aspect, the present invention further provides a device for generating pixel-level annotations for industrial defect images, which is used to implement the method for generating pixel-level annotations for industrial defect images described in the first aspect, and the device comprises:

[0040] At least one processor; and a memory communicatively connected to the at least one processor; wherein the memory stores instructions executable by the at least one processor, and the instructions are executed by the processor to execute the method for generating pixel-level annotations for industrial defect images described in the first aspect.

[0041] In a third aspect, the present invention further provides a non-volatile computer storage medium, wherein the computer storage medium stores computer executable instructions, which are executed by one or more processors to complete the method described in the first aspect and / or the method described in the second aspect.

[0042] In a fourth aspect, a chip is provided, comprising: a processor and an interface, for calling and running a computer program stored in the memory from a memory to execute the method of the first aspect.

[0043] In a fifth aspect, a computer program product comprising instructions is provided, which, when executed on a computer or a processor, causes the computer or the processor to execute the method of the first aspect.

[0044] The present invention introduces a VAE decoder to obtain high-resolution features of the defect image, and then obtains refined features by fusing the discriminative features and high-resolution features of the defect image. The refined features are used to perform high-resolution pixel-level annotation on the defect image, thereby achieving high-resolution pixel-level annotation that is precisely aligned with the defect area. BRIEF DESCRIPTION OF THE DRAWINGS

[0045] In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the following briefly introduces the drawings required for use in the embodiments of the present invention. Obviously, the drawings described below are only some embodiments of the present invention, and for ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work.

[0046] Figure 1 It is a schematic diagram of the architecture of an annotation generation model in a method for generating pixel-level annotations for industrial defect images provided by an embodiment of the present invention;

[0047] Figure 2 It is a flow chart of a first method for generating pixel-level annotations for industrial defect images provided by an embodiment of the present invention;

[0048] Figure 3 It is a flow chart of a second method for generating pixel-level annotations for industrial defect images provided by an embodiment of the present invention;

[0049] Figure 4 It is a schematic diagram of a method for generating pixel-level annotations for industrial defect images provided by an embodiment of the present invention;

[0050] Figure 5 It is a flow chart of a third method for generating pixel-level annotations for industrial defect images provided by an embodiment of the present invention;

[0051] Figure 6 It is a flowchart of a fourth method for generating pixel-level annotations for industrial defect images provided by an embodiment of the present invention;

[0052] Figure 7 It is a schematic diagram of the architecture of a few-sample defect image generation model in a method for generating pixel-level annotations of industrial defect images provided by an embodiment of the present invention;

[0053] Figure 8 It is a flowchart of a fifth method for generating pixel-level annotations for industrial defect images provided by an embodiment of the present invention;

[0054] Fig. 9 It is a flowchart of a sixth method for generating pixel-level annotations for industrial defect images provided by an embodiment of the present invention;

[0055] Fig.10 is a flow chart of a seventh method for generating pixel-level annotations for industrial defect images provided by an embodiment of the present invention;

[0056] Fig.11 It is a flowchart of an eighth method for generating pixel-level annotations for industrial defect images provided by an embodiment of the present invention;

[0057] Fig.12 It is a flow chart of a ninth method for generating pixel-level annotations for industrial defect images provided by an embodiment of the present invention;

[0058] Fig.13 It is a schematic diagram of another method for generating pixel-level annotations for industrial defect images provided by an embodiment of the present invention;

[0059] Fig.14 It is a schematic diagram of the architecture of a device for generating pixel-level annotations for industrial defect images provided by an embodiment of the present invention. DETAILED DESCRIPTION

[0060] In order to make the purpose, technical solution and advantages of the present invention more clearly understood, the present invention is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present invention and are not intended to limit the present invention.

[0061] Unless the context requires otherwise, throughout the specification and claims, the term "including" is to be interpreted as open inclusion, that is, "including, but not limited to". In the description of the specification, the terms "one embodiment", "some embodiments", "exemplary embodiments", "examples", "specific examples" or "some examples" and the like are intended to indicate that specific features, structures, materials or characteristics associated with the embodiment or example are included in at least one embodiment or example of the present disclosure. The schematic representation of the above terms does not necessarily refer to the same embodiment or example. In addition, the specific features, structures, materials or characteristics may be included in any one or more embodiments or examples in any appropriate manner, that is, although they may be carried in the embodiments or examples of the above terms due to reasons such as the order and position of appearance, it is not limited to that they can be carried in combination by one embodiment or example.

[0062] In the description of the present invention, the terms "first" and "second" are used only for descriptive purposes, and cannot be understood as indicating or implying relative importance or implicitly indicating the number of indicated technical features. Thus, the features defined as "first" and "second" may explicitly or implicitly include one or more of the features. In the description of the embodiments of the present disclosure, unless otherwise specified, the meaning of "multiple" is two or more. In addition, for example, the same type of nouns may be described as two independent individuals by adding "A" and "B" at the end. In this case, the corresponding features defined as "A" and "B" are only used to distinguish the same type of individuals for description purposes, and cannot be understood as indicating or implying relative importance or implicitly indicating the number of indicated technical features.

[0063] In the description of the present invention, the expression "A and / or B" (where A and B are used to formally represent specific characteristic contents) will be involved, and the corresponding expressions include the following three combinations: only A, only B, and a combination of A and B.

[0064] As used herein, "about," "substantially," or "approximately" includes the stated value and an average value that is within an acceptable range of deviation from the particular value as determined by one of ordinary skill in the art taking into account the measurements in question and the errors associated with the measurement of the particular quantity (i.e., the limitations of the measurement system).

[0065] In addition, the technical features involved in the various embodiments of the present invention described below can be combined with each other as long as they do not conflict with each other.

[0066] Embodiment 1:

[0067] Embodiment 1 of the present invention provides a method for generating pixel-level annotations for industrial defect images, training an annotation generation model, and using the trained annotation generation model to generate pixel-level annotations; Figure 1 As shown, the annotation generation model includes a VAE encoder, a U-Net encoder, a U-Net decoder, a VAE decoder, a feature refinement module and a mask prediction module; wherein, it is further divided into a defect image branch and a normal image branch, the VAE encoder, the U-Net encoder, the U-Net decoder, the VAE decoder, the feature refinement module and the mask prediction module constitute the defect image branch, and the VAE encoder, the U-Net encoder, the U-Net decoder, the VAE decoder and the mask prediction module also constitute the normal image branch; the annotation generation model is trained, as shown in FIG. Figure 2 As shown, specifically including:

[0068] In step 201, the defect image branch extracts discriminative features of the defect image, and uses the discriminative features of the defect image to perform low-resolution pixel-level annotation on the defect image.

[0069] In step 202, the normal image branch extracts discriminative features of the normal image, and uses the discriminative features of the normal image to perform low-resolution pixel-level annotation on the normal image.

[0070] In step 203, the defect image branch fuses the discriminative features of the defect image with the high-resolution features output by the VAE decoder to obtain refined features, and uses the refined features to perform high-resolution pixel-level annotation on the defect image.

[0071] In step 204, the low-resolution pixel-level annotation of the normal image is upsampled to obtain a high-resolution pixel-level annotation of the normal image.

[0072] In step 205, an objective function is generated based on the low-resolution pixel-level annotation of the defect image, the low-resolution pixel-level annotation of the normal image, the high-resolution pixel-level annotation of the defect image, the high-resolution pixel-level annotation of the normal image, the defect image mask and the normal image mask, and the objective function is used to optimize the annotation generation model.

[0073] The defect image may be a real image actually collected in an industrial scenario. The low-resolution pixel-level annotation and the high-resolution pixel-level annotation are relative. In actual application scenarios, the low-resolution pixel-level annotation may refer to an annotation with a pixel resolution of 64×64, and the high-resolution pixel-level annotation may refer to an annotation with a pixel resolution of 512×512.

[0074] In the defect image branch, the defect image is input to the VAE encoder, the output result of the VAE encoder is input to the U-Net encoder, the output result of the U-Net encoder is input to the U-Net decoder, the output result of the U-Net decoder is input to the VAE decoder, and the VAE decoder processes the output result of the U-Net decoder to obtain the high-resolution feature. The output result of the U-Net decoder is the discriminative feature of the defect image.

[0075] In the normal image branch, the normal image is input to the VAE encoder, the output result of the VAE encoder is input to the U-Net encoder, the output result of the U-Net encoder is input to the U-Net decoder, and the U-Net decoder outputs the discriminative features of the normal image.

[0076] In the processing branch, the feature refinement module receives the high-resolution features output by the VAE decoder and the discriminative features of the defective image output by the U-Net decoder, processes them to obtain refined features, and transmits the refined features to the mask prediction module. The defective image is also input into the mask prediction module. The mask prediction module uses the refined features to perform high-resolution pixel-level annotation on the defective image. The mask prediction module also receives the discriminative features of the defective image output by the U-Net decoder, and uses the discriminative features to perform low-resolution pixel-level annotation on the defective image. The mask prediction module also receives the discriminative features of the normal image and the normal image output by the U-Net decoder, and performs low-resolution pixel-level and high-resolution pixel-level annotation on the normal image according to the discriminative features of the normal image.

[0077] The process of using the objective function to optimize the annotation generation model can be understood as performing multiple iterations, calculating the value of the objective function in each iteration, and adjusting the values ​​of each parameter in the annotation generation model according to the value of the objective function, so that the calculated values ​​of each objective function tend to the ideal value, wherein the iterative process and the specific adjustment process of the parameters are well known to those skilled in the art and will not be elaborated here.

[0078] This embodiment introduces a VAE decoder to obtain high-resolution features of the defect image, and then obtains refined features by fusing the discriminative features and high-resolution features of the defect image. The refined features are used to perform high-resolution pixel-level annotation on the defect image, thereby achieving high-resolution pixel-level annotation that is precisely aligned with the defect area.

[0079] In an actual application scenario, the discriminative features of the defect image include a first feature F1 and a second feature F2; the discriminative features of the defect image are extracted, and the discriminative features of the defect image are used to perform low-resolution pixel-level annotation on the defect image, such as Figure 3 As shown, specifically including:

[0080] In step 301, a 3×3 convolution block is used to compress the number of channels of the first feature F1 output by the U-Net decoder to obtain a first compressed feature F′1, and a convolution block is used to compress the number of channels of the second feature F2 output by the U-Net decoder to obtain a second compressed feature F′2; wherein the first feature F1 is a feature output by the second level of the U-Net decoder, and the second feature F2 is a feature output by the third level of the U-Net decoder; After compression, The second layer is also referred to as the "up-2" layer by those skilled in the art in actual use, and the third layer is also referred to as the "up-3" layer by those skilled in the art in actual use. The hierarchical structure of the U-Net decoder is as follows: Figure 4 As shown, there are four levels: "up-1", "up-2", "up-3" and "up-4".

[0081] In step 302, the first compressed feature F'1 is upsampled, and the upsampled result of the first compressed feature F'1 is concatenated with the second compressed feature F'2 to obtain a concatenated feature F; the upsampling converts the first compressed feature F'1 to a resolution of 64×64.

[0082] In step 303, multiple transformation layers are applied to the spliced ​​feature F to obtain a rough feature Specifically, four transformation layers are applied to fuse the concatenated features F to obtain

[0083] In step 304, the roughness feature A 3×3 convolutional layer and a softmax function are applied to generate low-resolution pixel-level annotations of the defect image. The low-resolution pixel-level annotations of the defect image are

[0084] The implementation method of using the discriminative features of the normal image to perform low-resolution pixel-level annotation on the normal image is based on the same concept as the above steps 301 to 304, and will not be described in detail here.

[0085] In an optional implementation, the high-resolution feature includes an i-th high-resolution feature, where i is an integer, i is greater than 0 and i is less than 4; the discriminative feature of the defect image and the high-resolution feature output by the VAE decoder are fused to obtain a refined feature, such as Figure 5 As shown, specifically including:

[0086] The i-th level feature and the i-th high-resolution feature are sequentially merged to obtain the i+1-th level feature, and the fourth-level feature is used as the refined feature; wherein the discriminative feature of the defect image is used as the first-level feature;

[0087] The step of fusing the i-th level feature with the i-th high-resolution feature to obtain the i+1-th level feature specifically includes:

[0088] In step 401 , the i-th level feature is aligned with the i-th high-resolution feature.

[0089] In step 402, the i-th level feature is sequentially subjected to 1×1 convolution and upsampling, and then element-wise multiplication is performed with the corresponding aligned i-th high-resolution feature to obtain the i-th optimized boundary feature.

[0090] In step 403, the i-th level feature is processed by two convolution blocks and then added to the i-th optimized boundary feature to obtain the i+1-th level feature.

[0091] Among them, the first high-resolution feature is the output of the first up-blocks of the VAE decoder, the second high-resolution feature is the output of the second up-blocks of the VAE decoder, and the third high-resolution feature is the output of the third up-blocks of the VAE decoder.

[0092] After each round of fusion, the obtained features will be more refined than the previous round. In this embodiment, multiple progressive fusions are performed in a cascade manner, thereby gradually optimizing the boundaries of the rough features and finally obtaining refined features.

[0093] The use of refined features to perform high-resolution pixel-level annotation on defect images, such as Figure 6 As shown, specifically including:

[0094] In step 501, a 3×3 convolution layer and a softmax function are applied to the refined features to generate defect pixel-level annotations.

[0095] In step 502, the defective pixel level is marked using a preset threshold τ. The second channel of is binarized to obtain a high-resolution pixel-level annotation of the defect image. The preset threshold τ is obtained by those skilled in the art according to demand analysis.

[0096] The defect image mask includes a low-resolution real mask of the defect image and a high-resolution real mask of the defect image, and the normal image mask includes a low-resolution real mask of the normal image and a high-resolution real mask of the normal image; the objective function is generated according to the low-resolution pixel-level annotation of the defect image, the low-resolution pixel-level annotation of the normal image, the high-resolution pixel-level annotation of the defect image, the high-resolution pixel-level annotation of the normal image, the defect image mask and the normal image mask, specifically including:

[0097] The objective function is

[0098]

[0099] Among them, F() represents the calculation of Focal loss, and They represent low-resolution pixel-level annotation of defect images and high-resolution pixel-level annotation of defect images, respectively. and They represent the low-resolution pixel-level annotation of normal images and the high-resolution pixel-level annotation of normal images, respectively. df and M′ df denote the low-resolution true mask of the defect image and the high-resolution true mask of the defect image, respectively, and M ob and M′ ob They represent the low-resolution true mask of the normal image and the high-resolution true mask of the normal image, respectively.

[0100] Embodiment 2:

[0101] At present, the generation methods in industrial scenarios can be roughly divided into two categories: defect generation and defect image generation. Defect generation methods simulate defects by pasting cropped normal areas onto normal images, generate defects and then merge them into real normal images through different strategies, or generate defects using diffusion models and edit defects onto normal images based on defect mask guidance.

[0102] However, the defect generation method relies on the defect mask as input. If the mask position is unreasonable, the generated defects are prone to low fidelity and poor consistency. In contrast, the defect image generation method can directly generate complete industrial defect images, which include both industrial defects and industrial products with industrial defects. This type of method avoids the reliance on masks, and thus may generate more natural and diverse defect instances, but the defect image generation method requires the use of a large number of defect images to train the diffusion model in advance. Few-sample industrial defect image generation refers to the training of industrial defect image generation models based on a small number of training images (generally less than 5 images). For the same industrial product, there are usually multiple defect images of different defect categories. Under normal circumstances, the occurrence of defects in industrial scenes is a low-probability event, so it is impossible to quickly collect a large number of defect images for each defect, so few samples are a common situation in industrial scenes. As a result, the number of samples used for training is small, and it is difficult to achieve ideal training results. In order to solve this problem, this embodiment also provides a method for generating pixel-level annotations of industrial defect images based on Embodiment 1. The defect image used in the method for generating pixel-level annotations of industrial defect images is generated in advance using a few-sample defect image generation model, such as Figure 7 As shown, the few-sample defect image generation model includes the U-Net encoder described in Example 1, the U-Net decoder described in Example 1, the attention module, the first objective function, the second objective function and the third objective function; wherein the attention module, the first objective function and the second objective function are divided into the defect image branch, and the third objective function is divided into the normal image branch; the training process of the two branches is carried out separately, but is implemented on the shared U-Net; the few-sample defect image generation model is trained using a hybrid training strategy, such as Figure 8 As shown, the method includes:

[0103] In step 601, multiple defect words and a single product word are combined to obtain an unbalanced abnormal text prompt, and the unbalanced abnormal text prompt and the product-related part of the unbalanced abnormal text prompt are respectively input into the defect image branch and the normal image branch as guiding conditions; the total number of defect categories used is obtained by technical personnel in this field based on demand analysis.

[0104] In step 602, a fixed number of normal images are selected as inputs of the normal image sample branch, the defect image branch obtains features of the defect image, and aligns defect words in the unbalanced abnormal text prompt to the defect area in the image according to the defect image mask corresponding to the defect image, so as to optimize the first objective function and the second objective function; wherein the defect image can be a defect image corresponding to any defect category of the corresponding product.

[0105] In step 603, a fixed number of normal images are selected as inputs of the normal image sample branch, the normal image branch obtains features of the normal images, and uses the product-related parts of the unbalanced abnormal text prompts to optimize the third objective function; wherein the hybrid training strategy is used to enable defect images of different defect categories to participate in training together.

[0106] The U-Net encoder and the U-Net decoder can be understood as the U-Net architecture in the diffusion model that needs to be fine-tuned.

[0107] In the defect image branch, the output result of the U-Net encoder is input into the U-Net decoder, and the value of the second objective function is calculated based on the output result of the U-Net decoder and the defect image. The output result of the U-Net encoder is also input into the attention module, and the value of the first objective function is calculated based on the output result of the attention module and the corresponding defect image mask.

[0108] The output result of the U-Net encoder is input to the U-Net decoder, and the value of the third objective function is calculated based on the output result of the U-Net decoder and the normal image.

[0109] The process of optimizing the first objective function and the second objective function and optimizing the third objective function can be understood as performing multiple iterations, calculating the values ​​of the first objective function, the second objective function and the third objective function in each iteration, and adjusting the values ​​of each parameter in the U-Net architecture according to the values ​​of the first objective function, the second objective function and the third objective function, so that the calculated values ​​of each objective function tend to the ideal value. The specific adjustment process of the parameters is well known to those skilled in the art and will not be elaborated here.

[0110] This embodiment introduces an unbalanced abnormal text prompt, uses multiple defect words and a single product word in the unbalanced abnormal text prompt, and under the guidance of the unbalanced abnormal text prompt, proposes a dual-branch diffusion model fine-tuning method, that is, using two branches, namely a defect image branch and a normal image branch, and further uses a hybrid training strategy to introduce defect images of different categories, thereby alleviating the overfitting problem that may be caused by the limited number of samples of each defect category, and increasing the diversity of defect images. At the same time, the authenticity of the defect images is still maintained. Therefore, when the number of defect images of each defect category in the industrial scenario is small, a relatively ideal training effect can still be achieved, so that the defect image is generated using the trained diffusion model.

[0111] It should be noted here that the above-mentioned use of the hybrid training strategy to train the U-Net encoder and the U-Net decoder can be understood as an overall training strategy, and the steps 601 to 603 can be understood as actual actions performed in each training.

[0112] In actual application scenarios, the combination of multiple defect words and a single product word to obtain an unbalanced abnormal text prompt specifically includes:

[0113] Combine the product word of a single product with the defect word of N different defect categories of the product to obtain the unbalanced abnormal text prompt 'a <ob>with <df1> <df2>… <df N >'; <ob>is the product word, <df1> 、 <df2>, …, <df N > is defect words of N different defect categories, N is a preset value, the N defect words of each product correspond to a defect category, N is obtained by technical personnel in this field based on demand analysis, in an optional implementation, N is 4, and K*N defect words are used to obtain unbalanced abnormal text prompts of K shared product words, covering all defect categories of the product, K is a preset value, corresponding to K defect categories of a product, K is obtained by technical personnel in this field based on empirical analysis.

[0114] In an optional embodiment, if Fig. 9 As shown, the hybrid training strategy is specifically:

[0115] In step 701, a defect image set is generated based on defect images of all defect categories of the corresponding product. in, is the defect image of the i-th defect category.

[0116] In step 702, a preset number of normal images of the product are selected to generate a normal image set. in, is the i-th normal image.

[0117] In step 703, from the defect image set X df Select the first number of defective images from the normal image set X ob A first number of normal images are selected, the selected first number of defect images and the first number of normal images are mixed into a batch of data, and each batch of data is input into the defect image branch and the normal image branch for multiple batches of training. The first number and the preset number are obtained by those skilled in the art based on empirical analysis. One batch of data is used for one batch of training, and the specific implementation process of each batch of training is as described in the above steps 601 to 603.

[0118] Based on the above defective image branch and normal image branch, this embodiment also provides a specific implementation of each objective function. For example, in an optional implementation, the first objective function is in, is the cross attention map corresponding to the n-th defective word, N is the number of defective tokens, L is the number of U-Net layers corresponding to the cross-attention map used in the alignment process, and M is l is a binary mask with a size of r×r pixels, where the value of the defective area is 1 and the value of the non-defective area is 0. is the cross attention map corresponding to the product word, ⊙ is the pixel-by-pixel multiplication operation. In order to remove the defective word <df n >The value of cross-attention in defective areas is increased, This is to prevent product words from being <ob>Align to defect area.

[0119] The second objective function is Among them, e df represents the conditional vector obtained after the unbalanced abnormal text prompt passes through the text encoder, z df is the defect image x df The latent vector obtained by the VAE encoder, ∈ df is random noise, t df is the number of noise adding steps, To use ∈ df and ∈ df Right df The noise latent vector obtained by adding noise is the predicted noise, is the value of the first objective function.

[0120] The third objective function is

[0121]

[0122] ; Among them, e ob represents the conditional vector obtained after the product-related part of the unbalanced abnormal text prompt passes through the text encoder, z ob For the normal image x ob The latent vector obtained by the VAE encoder, ∈ ob is random noise, t ob is the number of noise adding steps, To use ∈ ob and t ob Right ob The noisy latent vector obtained by adding noise is is the predicted noise.

[0123] A few-sample defect image generation model is obtained by using the method described in this embodiment, and then a large number of defect images are generated using the few-sample defect image generation model for training the annotation generation model described in Example 1. The method described in Example 1 is applicable to this embodiment and will not be described in detail here.

[0124] Embodiment 3:

[0125] The present invention is based on the method described in Example 1, combined with specific application scenarios, and uses technical descriptions in related scenarios to illustrate the implementation process of the present invention in characteristic scenarios.

[0126] like Fig.10 As shown, the method for generating pixel-level annotations for industrial defect images provided in this embodiment includes the following steps:

[0127] In step 801, dual-branch image feature extraction is performed. Specifically, a defect image branch and a normal image branch are designed, and both branches participate in the training of the annotation generation model. Each branch extracts the discriminative features of the corresponding image through the U-Net in the diffusion model, and uses the features to predict low-resolution pixel-level annotations.

[0128] In step 802, a feature refinement module is designed for the defect image branch, which fuses the discriminative features of the U-Net of the defect image and the high-resolution features of the VAE decoder in a cascade manner to obtain refined features, which are used to predict pixel-level annotations of high-resolution images.

[0129] In step 803, the image pixel-level annotation is generated. Specifically, based on the low-resolution and high-resolution image pixel-level annotations of the defective image and the normal image, and the corresponding defective image mask and normal image mask, an annotation generation objective function is proposed to provide refined pixel-level annotations for the generated defective image. The segmentation results of defective pixels in the defective image are predicted, and all pixels therein are divided into two categories: defective pixels and normal pixels.

[0130] There are three main implementation parts: 1) dual-branch image feature extraction; 2) feature refinement module of defect image branch; 3) image pixel-level annotation generation. Each step is explained in detail below.

[0131] The dual-branch image feature extraction is specifically as follows: based on a given few-sample defect image generation model, a label generation model based on U-Net features and VAE decoder features in the diffusion model is trained. In this embodiment, a defect image branch and a normal image branch are designed. Each branch extracts the discriminative features of the corresponding image through the U-Net in the diffusion model, and uses the features to predict low-resolution pixel-level labels, which specifically includes:

[0132] The output features of the "up-2" and "up-3" layers in U-Net are convolved using a 3×3 convolutional block. and The number of channels is compressed to obtain and

[0133] F′1 is upsampled to a resolution of 64×64 and concatenated with F′2.

[0134] Apply four transformation layers to fuse the concatenated features and obtain a unified rough feature

[0135] Using a 3×3 convolutional layer and softmax function, based on rough features Generate low-resolution pixel-level annotations

[0136] For the defect image branch, this embodiment designs a feature refinement module, each of which receives two features, namely, the high-resolution features from VAE and the discriminative features from U-Net. Then, the discriminative features of U-Net and the high-resolution features of VAE decoder are fused in a cascade manner to gradually refine the rough features of the defect image. Specifically, it includes:

[0137] The discriminative features of U-Net are upsampled to align with the high-resolution features of VAE decoder.

[0138] After 1×1 convolution, the upsampled discriminative features are element-wise multiplied with the high-resolution features of the VAE decoder to enhance the boundary regions of the defects.

[0139] The upsampled discriminative features are processed through two convolutional blocks and added with the features after optimizing the boundary to maintain the discriminative features.

[0140] This embodiment uses three cascaded multi-resolution feature refinement modules, namely the above operation, to gradually optimize the rough feature Each multi-resolution feature refinement module uses the discriminant features output by the previous multi-resolution feature refinement module as the input to be refined, while the first multi-resolution feature refinement module directly uses the coarse features as the initial discriminant input. For the other input of each multi-resolution feature refinement module, this embodiment uses the outputs of the first, second and third "up-sampling blocks" in the VAE decoder respectively.

[0141] The mask prediction module uses a 3×3 convolutional layer and a softmax function to generate refined defect pixel-level annotations based on the output of the last multi-resolution feature refinement module. In this embodiment, a threshold τ is set to binarize the second channel of the defective pixel level annotation, so as to obtain the final defective pixel level annotation.

[0142] After generating pixel-level annotations for the image, the objective function is calculated and used to optimize the annotation generation model. The objective function to be optimized in this embodiment is:

[0143]

[0144] Among them, F() represents the calculation of Focal loss, and They represent low-resolution pixel-level annotation of defect images and high-resolution pixel-level annotation of defect images, respectively. and They represent the low-resolution pixel-level annotation of normal images and the high-resolution pixel-level annotation of normal images, respectively. df and M′ df denote the low-resolution true mask of the defect image and the high-resolution true mask of the defect image, respectively, and M ob and M′ ob They represent the low-resolution true mask of the normal image and the high-resolution true mask of the normal image respectively. It is worth noting that in the pixel-level annotation of the normal image, each pixel value is set to 0 to eliminate the potential noise effect in the normal image.

[0145] The present embodiment discloses a method for generating pixel-level annotations for industrial defect images. First, the present embodiment proposes a dual-branch image feature extraction method, designs a defect image branch and a normal image branch, and the two branches participate in the training of the annotation generation model at the same time. Each branch extracts the discriminative features of the corresponding image through the U-Net in the diffusion model, and uses the features to predict low-resolution pixel-level annotations. Furthermore, for the defect image branch, the present embodiment designs a feature refinement module, which fuses the U-Net discriminative features of the defect image and the high-resolution features of the VAE decoder in a cascade manner to obtain refined features, and uses the refined features to predict high-resolution pixel-level annotations. Finally, based on the low-resolution and high-resolution pixel-level annotations of the defect image and the normal image, an annotation generation objective function is proposed. The present embodiment uses defect images and normal images for training to provide refined pixel-level annotations for the generated defect images.

[0146] The few-sample defect image generation model needs to be trained in advance using a small number of defect images and normal images, such as Fig.11 As shown in Figure 1, the training process of the few-shot defect image generation model includes the following steps:

[0147] In step 901, a small number of defective images and corresponding defective image masks are selected as inputs of the defective image branch, and a fixed number of normal images are selected as inputs of the normal image sample branch.

[0148] In step 902, an unbalanced abnormal text prompt is designed. Specifically, a plurality of defect words applicable to industrial scenarios and a single product word are combined to obtain an unbalanced abnormal text prompt, which is used as a guiding condition to control the generation of a diffusion model image.

[0149] In step 903, the defect area is aligned, specifically: design a defect image branch, obtain the features of the defect image. Based on the defect image mask corresponding to the defect image, the defect word in the unbalanced abnormal text prompt is aligned to the defect area in the image through the attention module; optimize the noise prediction objective function under the unbalanced abnormal text prompt.

[0150] In step 904, the normal image is fine-tuned, specifically: in the design of the normal image branch, the features of the normal image are obtained. The product-related parts of the unbalanced abnormal text prompt are used to optimize the noise prediction objective function.

[0151] In step 905, a hybrid training strategy is used, specifically: a unified U-Net is fine-tuned for each product containing different defect categories. The defect image set includes a small number of defect images of all defect categories of the same product, and the normal image set includes a fixed number of normal images of the product. Each time, an equal number of images are extracted from the defect image set and the normal image set, and mixed into a batch for training.

[0152] Among them, the imbalance abnormal text prompt design specifically includes: using the imbalance abnormal text prompt 'a <ob>with <df1> <df2>… <df N >', where <ob>is the product word, <df1> <df2>… <df N > is N defective word-grams. The unbalanced abnormal text prompt of each product consists of a single product word-gram of the product and N defective word-grams.

[0153] The defect area alignment specifically includes: decoupling the defect area as the foreground from the defect image through a cross attention mechanism and separating it from the defect word <df n >Align and optimize the noise prediction objective function under unbalanced abnormal text prompts. Fig.12 As shown, specifically including:

[0154] In step 1001, based on the features output by the U-Net encoder and the defect image mask, the defect word is divided into <df n >Align to the defect area in the defect image to optimize the first objective function:

[0155]

[0156] in, is the nth defective word <df n >The corresponding cross attention map, N is the number of defective tokens. L represents the number of U-Net layers corresponding to the cross attention map used in the alignment process, M l It is a binary mask with a size of r×r pixels, where the value of the defect area is 1 and the value of the non-defect area is 0. Product word <ob>The corresponding cross attention map, ⊙ is the pixel-by-pixel multiplication. This objective function decouples the defect area from the defect image. The first term decouples the defect word <df n >The cross-attention value in the defect area is increased, and the second item is to prevent the product word from being <ob>Align to defect area.

[0157] In step 1002, the defect image branch uses the imbalanced abnormal text prompt 'a <ob>with <df1> <df2>… <df N >', optimize and fine-tune the second objective function of U-Net:

[0158]

[0159] Among them, e df represents the conditional vector obtained after the unbalanced abnormal text prompt passes through the CLIP text encoder, and the defect image x df Get the latent vector z through the VAE encoder df , and use random noise ∈ df and the number of noise adding steps t df Right df Add noise to get the noise latent vector Then, under condition e df Noise prediction is carried out under the guidance of and ∈ df Compute the loss for fine-tuning U-Net.

[0160] The normal image fine-tuning specifically includes: the normal image branch uses the product-related part of the unbalanced abnormal text prompt 'a <ob>', optimize and fine-tune the third objective function of U-Net:

[0161]

[0162] Among them, c ob Indicates the product-related part of the imbalance exception text prompt 'a <ob>'Conditional vector obtained after CLIP text encoder, normal image x ob Get the latent vector z through the VAE encoder ob , and use random noise ∈ ob and the number of noise adding steps t ob Right ob Add noise to get the noise latent vector Then under condition e ob Noise prediction is carried out under the guidance of and ∈ ob Compute the loss for fine-tuning U-Net.

[0163] The hybrid training strategy specifically includes: using the hybrid training strategy to fine-tune a unified U-Net for each product. Given a product image set, which covers 15 products, each product corresponds to defect images with multiple defect categories and corresponding defect image masks and normal images. The defect images of all products are aggregated into a unified defect image set. For each defect category, an unbalanced abnormal text prompt consisting of different defect words is used. In addition, a fixed number of normal images are extracted to form a normal image set In each fine-tuning step, from X df and X ob The same number of images are extracted from the dataset and combined into a batch for training. This not only alleviates the overfitting problem caused by the limited number of samples for each defect category, but also increases the diversity of defect images while still maintaining the authenticity of the defect images.

[0164] The U-Net architecture obtained through the above training process is used in the diffusion model, which is used to achieve image generation under specific conditions. Given an input image x0, the diffusion model first converts it into a representation z=ε(x0) in the latent space, and then adds randomly sampled noise ∈~N(0,I) to z, obtaining Where t is a randomly selected time step. Next, use U-Net to predict the noise ∈. Let c θ (P) is the CLIP text encoder, which maps the conditional text prompt P to the conditional vector e. The noise prediction objective function that the diffusion model needs to optimize is:

[0165]

[0166] in is the predicted noise.

[0167] This embodiment proposes an unbalanced abnormal text prompt generated for industrial defect images, which includes multiple defect words and a single product word. Furthermore, under the guidance of the unbalanced abnormal text prompt, a dual-branch diffusion model fine-tuning method is proposed. For the defect image branch, the present invention proposes a defect area alignment objective function to align the defect word and the defect area, and optimizes the noise prediction objective function under the unbalanced abnormal text prompt to achieve high diversity of defects. For the normal image branch, only the product-related part of the unbalanced abnormal text prompt is used to optimize the noise prediction objective function and synthesize product images with global consistency and local changes. The training process of the two branches is carried out separately, but is implemented on a shared U-Net, such as Fig.13 As shown, Representing each unbalanced abnormal text prompt, both the defect image branch and the normal image branch act on the U-Net architecture. In addition, this embodiment adopts a hybrid training strategy to fine-tune a unified U-Net for each product. Thus, a large number of defect images with high authenticity and diversity are generated by training with a small number of defect images and some normal images. The generated defect images are used for the training of the above-mentioned annotation generation model, thereby obtaining a trained annotation generation model for high-resolution pixel-level annotation of images.

[0168] Embodiment 4:

[0169] like Fig.14 , is a schematic diagram of the architecture of the device for generating pixel-level annotations for industrial defect images according to an embodiment of the present invention. The device for generating pixel-level annotations for industrial defect images according to this embodiment includes one or more processors 21 and a memory 22. Fig.14 A processor 21 is taken as an example.

[0170] The processor 21 and the memory 22 may be connected via a bus or other means. Fig.14 The example of connecting through bus is taken in the following.

[0171] The memory 22 is a non-volatile computer-readable storage medium that can be used to store non-volatile software programs and non-volatile computer executable programs, such as the industrial defect image pixel-level annotation generation method in Example 1. The processor 21 executes the industrial defect image pixel-level annotation generation method by running the non-volatile software programs and instructions stored in the memory 22.

[0172] The memory 22 may include a high-speed random access memory, and may also include a non-volatile memory, such as at least one disk storage device, a flash memory device, or other non-volatile solid-state storage devices. In some embodiments, the memory 22 may optionally include a memory remotely arranged relative to the processor 21, and these remote memories may be connected to the processor 21 via a network. Examples of the above-mentioned network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and combinations thereof.

[0173] The program instructions / modules are stored in the memory 22 , and when executed by the one or more processors 21 , the method for generating pixel-level annotations for industrial defect images in the above-mentioned embodiment 1 is executed.

[0174] It is worth noting that the information interaction, execution process, etc. between the modules and units within the above-mentioned devices and systems are based on the same concept as the processing method embodiment of the present invention. The specific contents can be found in the description of the method embodiment of the present invention and will not be repeated here.

[0175] A person skilled in the art may understand that all or part of the steps in the various methods of the embodiments may be completed by instructing related hardware through a program, and the program may be stored in a computer-readable storage medium, and the storage medium may include: a read-only memory (ROM), a random access memory (RAM), a disk or an optical disk, etc.

[0176] The above description is only a preferred embodiment of the present invention and is not intended to limit the present invention. Any modifications, equivalent substitutions and improvements made within the spirit and principles of the present invention should be included in the protection scope of the present invention.< / ob> < / ob> < / df1> < / ob> < / ob> < / ob> < / df1> < / ob> < / df1> < / ob> < / ob> < / df1> < / ob> < / df1> < / ob>

Claims

1. A method for generating pixel-level annotations for industrial defect images, characterized in that: The annotation generation model is trained, and pixel-level annotations are generated using the trained annotation generation model; the annotation generation model includes a VAE encoder, a U-Net encoder, a U-Net decoder, a VAE decoder, a feature refinement module, and a mask prediction module; wherein the annotation generation model is further divided into a defect image branch and a normal image branch, the VAE encoder, the U-Net encoder, the U-Net decoder, the VAE decoder, the feature refinement module, and the mask prediction module constitute the defect image branch, and the VAE encoder, the U-Net encoder, the U-Net decoder, the VAE decoder, and the mask prediction module also constitute the normal image branch; the training of the annotation generation model specifically includes: The defect image branch extracts discriminative features of the defect image, and uses the discriminative features of the defect image to perform low-resolution pixel-level annotation on the defect image; The normal image branch extracts discriminative features of the normal image, and uses the discriminative features of the normal image to perform low-resolution pixel-level annotation on the normal image; The defect image branch fuses the discriminative features of the defect image with the high-resolution features output by the VAE decoder to obtain refined features, and uses the refined features to perform high-resolution pixel-level annotation on the defect image. Upsampling the low-resolution pixel-level annotations of the normal image to obtain high-resolution pixel-level annotations of the normal image; According to the low-resolution pixel-level annotation of the defect image, the low-resolution pixel-level annotation of the normal image, the high-resolution pixel-level annotation of the defect image, the high-resolution pixel-level annotation of the normal image, the defect image mask and the normal image mask, an objective function is generated, and the annotation generation model is optimized using the objective function.

2. The method for generating pixel-level annotations for industrial defect images according to claim 1, characterized in that: The discriminative features of the defect image include a first feature F1 and a second feature F2; extracting the discriminative features of the defect image and using the discriminative features of the defect image to perform low-resolution pixel-level annotation on the defect image specifically includes: Use a 3×3 convolution block to compress the number of channels of the first feature F1 output by the U-Net decoder to obtain the first compressed feature F ′ 1. Use the convolution block to compress the number of channels of the second feature F2 output by the U-Net decoder to obtain the second compressed feature F ′ 2; wherein the first feature F1 is a feature of the second level output of the U-Net decoder, and the second feature F2 is a feature of the third level output of the U-Net decoder; For the first compression feature F ′ 1 is upsampled and the first compressed feature F ′ 1 The upsampling result and the second compressed feature F ′ 2. Perform splicing to obtain splicing feature F; Apply multiple transformation layers to the spliced ​​feature F to obtain a rough feature In the rough features A 3×3 convolutional layer and a softmax function are applied to generate low-resolution pixel-level annotations of the defect image.

3. The method for generating pixel-level annotations for industrial defect images according to claim 1, characterized in that: The high-resolution features include the i-th high-resolution features, where i is an integer, i is greater than 0 and i is less than 4; the discriminative features of the defect image and the high-resolution features output by the VAE decoder are fused to obtain refined features, specifically including: The i-th level feature and the i-th high-resolution feature are sequentially merged to obtain the i+1-th level feature, and the fourth-level feature is used as the refined feature; wherein the discriminative feature of the defect image is used as the first-level feature; The step of fusing the i-th level feature with the i-th high-resolution feature to obtain the i+1-th level feature specifically includes: Align the i-th level feature with the i-th high-resolution feature; After performing 1×1 convolution and upsampling on the i-th level feature in sequence, it is element-wise multiplied with the corresponding aligned i-th high-resolution feature to obtain the i-th optimized boundary feature; After the i-th level feature is processed by two convolution blocks, it is added to the i-th optimized boundary feature to obtain the i+1-th level feature.

4. The method for generating pixel-level annotations for industrial defect images according to claim 1, characterized in that: The use of refined features to perform high-resolution pixel-level annotation on the defect image specifically includes: A 3×3 convolutional layer and a softmax function are applied to the refined features to generate pixel-level annotations of defects. Use the preset threshold τ to annotate the defect pixel level The second channel of is binarized to obtain high-resolution pixel-level annotation of the defect image.

5. The method for generating pixel-level annotations for industrial defect images according to claim 1, characterized in that: The defect image mask includes a low-resolution real mask of the defect image and a high-resolution real mask of the defect image, and the normal image mask includes a low-resolution real mask of the normal image and a high-resolution real mask of the normal image; The objective function is generated according to the low-resolution pixel-level annotation of the defect image, the low-resolution pixel-level annotation of the normal image, the high-resolution pixel-level annotation of the defect image, the high-resolution pixel-level annotation of the normal image, the defect image mask and the normal image mask, specifically including: The objective function is Among them, F() represents the calculation of Focal loss, and They represent low-resolution pixel-level annotation of defect images and high-resolution pixel-level annotation of defect images, respectively. and They represent the low-resolution pixel-level annotation of normal images and the high-resolution pixel-level annotation of normal images, respectively. df and M ′ df denote the low-resolution true mask of the defect image and the high-resolution true mask of the defect image, respectively, and M ob and M ′ ob They represent the low-resolution true mask of the normal image and the high-resolution true mask of the normal image, respectively.

6. The method for generating pixel-level annotations for industrial defect images according to claim 1, characterized in that: The defect image is generated in advance using a few-sample defect image generation model, which includes the U-Net encoder according to claim 1, the U-Net decoder according to claim 1, an attention module, a first objective function, a second objective function and a third objective function; wherein the attention module, the first objective function and the second objective function are divided into a defect image branch, and the third objective function is divided into a normal image branch; the training process of the two branches is carried out separately, but is implemented on a shared U-Net; the few-sample defect image generation model is trained using a hybrid training strategy, specifically including: Combining multiple defect words and a single product word to obtain an unbalanced abnormal text prompt, and inputting the unbalanced abnormal text prompt and the product-related part of the unbalanced abnormal text prompt as guiding conditions into the defect image branch and the normal image branch respectively; Selecting a few-sample defect image and a corresponding defect image mask as input of a defect image branch, the defect image branch obtains features of the defect image, and aligns defect words in the unbalanced abnormal text prompt to the defect area in the image according to the defect image mask corresponding to the defect image, so as to optimize the first objective function and the second objective function; A fixed number of normal images are selected as input of the normal image sample branch, the normal image branch obtains the features of the normal images, and uses the product-related parts of the unbalanced abnormal text prompts to optimize the third objective function; wherein the hybrid training strategy is used to enable defect images of different defect categories to participate in training together.

7. The method for generating pixel-level annotations for industrial defect images according to claim 6, characterized in that: The first objective function is in, is the cross-attention map corresponding to the nth defective word, N is the number of defective words, L represents the number of U-Net layers corresponding to the cross-attention map used in the alignment process, and M 1 is a binary mask with a size of r×r pixels, where the value of the defective area is 1 and the value of the non-defective area is 0. is the cross attention map corresponding to the product word, ⊙ is the multiplication operation per pixel; The second objective function is Among them, e df represents the conditional vector obtained after the unbalanced abnormal text prompt passes through the text encoder, z df is the defect image x df The latent vector obtained by the VAE encoder, ∈ df is random noise, t df is the number of noise adding steps, To use ∈ df and ∈ df Right df The noise latent vector obtained by adding noise is the predicted noise.

8. The method for generating pixel-level annotations for industrial defect images according to claim 6, characterized in that: The third objective function is ; Among them, e ob represents the conditional vector obtained after the product-related part of the unbalanced abnormal text prompt passes through the text encoder, z ob For the normal image x ob The latent vector obtained by the VAE encoder, ∈ ob is random noise, t ob is the number of noise adding steps, To use ∈ ob and t ob Right ob The noisy latent vector obtained by adding noise is is the predicted noise.

9. A device for generating pixel-level annotations for industrial defect images, characterized in that: include: at least one processor; And, a memory communicatively connected to the at least one processor; wherein the memory stores instructions executable by the at least one processor, and the instructions are executed by the processor to execute the method for generating pixel-level annotations for industrial defect images as described in any one of claims 1-8.

10. A non-volatile computer storage medium, characterized in that: The computer storage medium stores computer executable instructions, which are executed by one or more processors to implement any of the methods described in claims 1-8.

Citation Information

Patent Citations

  • Defect detection model training method and device, defect detection method and device and storage medium

    CN111784673A

  • Fine and weak defect segmentation method for industrial scene

    CN114863098A

  • Image super-resolution reconstruction method and device and computer readable storage medium

    CN116844024A

  • Super-resolution reconstruction method for single image with potential features

    CN117078510A

  • Small sample surface defect identification method based on inter-domain common feature migration generation

    CN117636096A

Cited By

  • Workpiece defect image generation method, device, equipment and medium

    CN119559276A