Industrial defect image generation method, device, medium and product

By introducing self-attention and skip connection mechanisms into the generative adversarial network, a cyclic generative adversarial network with dual generators and dual discriminators is constructed, which solves the problems of loss of detailed information and poor quality in industrial defect image generation, and achieves a more stable and efficient High quality image generation.

CN118521498BActive Publication Date: 2024-10-18NANCHANG HANGKONG UNIVERSITY
View PDF 1 Cites 0 Cited by

Patent Information

Application Number
CN202410985255.1
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-07-23
Publication Date
2024-10-18
Estimated Expiration
2044-07-23

AI Technical Summary

Technical Problem

It is difficult for existing generative adversarial network models to generate stable and complex industrial defect images, especially when the defect scale is uneven and the shape is irregular, resulting in the loss of important detailed information and low quality during the image generation process.

Method used

A defect image generation model based on a recurrent generative adversarial network is adopted, a self-attention mechanism and a skip connection mechanism are introduced, and a model is built through dual generators and dual discriminators to reduce information loss, improve the global vision and multi-scale capabilities of feature extraction, and generate more Stable and high-quality images of industrial defects.

Benefits of technology

It improves the stability and quality of industrial defect image generation, maintains the consistency of generated image content, enhances the robustness of the model, and can generate controllable high-quality defect images in complex scenes.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118521498B_ABST
    Figure CN118521498B_ABST
Patent Text Reader

Abstract

The present application discloses an industrial defect image generation method, device, medium and product, which relates to the field of image processing. The method comprises: obtaining an industrial defect-free image; according to the industrial defect-free image, using a defect image generation model to generate an industrial defect image; the defect image generation model is constructed based on a cyclic generative adversarial network; the defect image generation model comprises two generators and two discriminators, each generator comprises an encoder, a converter and a decoder connected in sequence; the encoder uses a convolution operation to extract the features of the input image, the converter uses a residual network based on a self-attention mechanism to convert the image output by the encoder, and the decoder uses a skip connection mechanism and a deconvolution operation to decode the image output by the converter to obtain the generated image. The present application reduces the loss of important detail information in the process of industrial defect image generation, improves the feature extraction capability, and thus improves the stability and quality of industrial defect image generation.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of image processing, and in particular to an industrial defect image generation method, device, medium and product. Background Art

[0002] Surface defect detection of industrial products has become a key link in industrial manufacturing. Industrial defect detection aims to detect appearance defects of various industrial products and is one of the important technologies to ensure product quality and maintain stable production. However, in actual production, it is usually difficult to collect defect image samples. Without a sufficient number of defect image samples, it is difficult to train a defect detection model. At present, there are many research directions for enhancing the sample size of image data. Compared with other traditional image generation algorithms, the generative adversarial network (GAN) based on feature learning can generate higher resolution and clearer images at a faster speed. Therefore, it has been favored by more and more scholars and has become one of the important application technologies in the field of industrial defect image generation.

[0003] At present, most of the images generated by the generative adversarial network models have a high accuracy rate. However, the scale distribution of industrial defects is uneven, and the defect shapes are irregular, which makes the industrial defect images more complex than general images in terms of contour, texture, background and other features. The existing generative adversarial network models are often unable to generate controllable, stable and complex industrial defect images. Summary of the invention

[0004] The purpose of this application is to provide an industrial defect image generation method, device, medium and product, which can improve the stability and quality of industrial defect image generation.

[0005] To achieve the above objectives, this application provides the following solutions.

[0006] In a first aspect, the present application provides an industrial defect image generation method comprising the following steps.

[0007] Get industrial defect-free images.

[0008] According to the industrial defect-free image, a defect image generation model is used to generate an industrial defect image; the defect image generation model is constructed based on a cyclic generative adversarial network; the defect image generation model includes two generators and two discriminators, each generator includes an encoder, a converter and a decoder connected in sequence; the encoder uses a convolution operation to extract the features of the input image, the converter uses a residual network based on a self-attention mechanism to convert the image output by the encoder, and the decoder uses a skip connection mechanism and a deconvolution operation to decode the image output by the converter to obtain a generated image; the two generators of the defect image generation model are the first generator and the second generator, respectively.

[0009] According to the industrial defect-free image, an industrial defect image is generated by using a defect image generation model, specifically including: using a pre-trained encoder of a first generator, using a convolution operation to extract features of the industrial defect-free image to obtain a preliminary feature map; using a pre-trained converter of the first generator, using a residual network based on a self-attention mechanism, integrating features in the preliminary feature map to obtain an integrated feature map; using a pre-trained decoder of the first generator, using a jump connection mechanism and a deconvolution operation, restoring the integrated feature map to a target domain to obtain an industrial defect image.

[0010] In a second aspect, the present application provides a computer device, comprising: a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the computer program to implement the above-mentioned industrial defect image generation method.

[0011] In a third aspect, the present application provides a computer-readable storage medium having a computer program stored thereon, and when the computer program is executed by a processor, the above-mentioned industrial defect image generation method is implemented.

[0012] In a fourth aspect, the present application provides a computer program product, including a computer program, which implements the above-mentioned industrial defect image generation method when executed by a processor.

[0013] According to the specific embodiments provided by the present application, the present application discloses the following technical effects: the present application provides an industrial defect image generation method, device, medium and product, constructs a defect image generation model based on a recurrent generative adversarial network of dual generators and dual discriminators, reduces the loss of important detail information in the industrial defect image generation process, maintains the consistency of the generated image content, introduces a self-attention mechanism and a jump connection mechanism in the generator, performs long-distance and multi-scale feature extraction on the input image, improves the global field of view of feature extraction and the ability to extract multi-scale features, thereby improving the stability and quality of industrial defect image generation. BRIEF DESCRIPTION OF THE DRAWINGS

[0014] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings required for use in the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.

[0015] Figure 1 This is a diagram of the application environment of an industrial defect image generation method in one embodiment of the present application.

[0016] Figure 2 A schematic flow chart of a method for generating an industrial defect image provided in one embodiment of the present application.

[0017] Figure 3 A schematic diagram of a process for generating an industrial defect image by a first generator provided in an embodiment of the present application.

[0018] Figure 4 A schematic diagram of the structure of a residual network based on a self-attention mechanism provided in one embodiment of the present application.

[0019] Figure 5 A schematic diagram of the structure of a generator provided in one embodiment of the present application.

[0020] Figure 6 A schematic diagram of the structure of a recurrent generative adversarial network provided in one embodiment of the present application.

[0021] Figure 7 A schematic diagram of the structure of a computer device provided in one embodiment of the present application. DETAILED DESCRIPTION

[0022] The following will be combined with the drawings in the embodiments of the present application to clearly and completely describe the technical solutions in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application.

[0023] In order to make the above-mentioned objects, features and advantages of the present application more obvious and easy to understand, the present application is further described in detail below with reference to the accompanying drawings and specific implementation methods.

[0024] The industrial defect image generation method provided in the embodiment of the present application can be applied to Figure 1In the application environment shown. Among them, the terminal 102 communicates with the server 104 through the network. The data storage system can store the data that the server 104 needs to process. The data storage system can be set up separately, integrated on the server 104, or placed on the cloud or other servers. The terminal 102 can send an industrial defect-free image to the server 104. After the server 104 receives the industrial defect-free image, it uses the defect image generation model to generate the industrial defect image. The server 104 can feedback the generated industrial defect image to the terminal 102. In addition, in some embodiments, the industrial defect image generation method can also be implemented separately by the server 104 or the terminal 102, such as the terminal 102 can directly generate the industrial defect image based on the industrial defect-free image, or the server 104 can obtain the industrial defect-free image from the data storage system and generate the industrial defect-free image.

[0025] The terminal 102 may be, but is not limited to, various desktop computers, laptop computers, smart phones, tablet computers, IoT devices, and portable wearable devices. The IoT devices may be smart speakers, smart TVs, smart air conditioners, smart vehicle-mounted devices, etc. The portable wearable devices may be smart watches, smart bracelets, head-mounted devices, etc. The server 104 may be implemented as an independent server or a server cluster consisting of multiple servers, or may be a cloud server.

[0026] In an exemplary embodiment, Figure 2 As shown, a method for generating an industrial defect image is provided. The method is executed by a computer device, and can be executed by a computer device such as a terminal or a server alone, or by a terminal and a server together. In the embodiment of the present application, the method is applied to Figure 1 The server 104 in the example is used for explanation, and the steps include the following steps 201 to 202.

[0027] Step 201, obtaining an industrial defect-free image.

[0028] Step 202: Generate an industrial defect image using a defect image generation model based on the industrial defect-free image.

[0029] This application can generate one or more industrial defect images based on an industrial defect-free image. The defect detection model is further trained based on the generated industrial defect images to detect surface defects of industrial products. The defects in the industrial defect images mainly include inclusions, plaques and scratches.

[0030] The defect image generation model is constructed based on a cyclic generative adversarial network. The defect image generation model includes two generators and two discriminators, each of which includes an encoder, a converter and a decoder connected in sequence. The encoder uses a convolution operation to extract the features of the input image, the converter uses a residual network based on a self-attention mechanism to convert the image output by the encoder, and the decoder uses a skip connection mechanism and a deconvolution operation to decode the image output by the converter to obtain a generated image.

[0031] In this embodiment, the defect image generation model is obtained by pre-using a training sample set to perform cyclic adversarial training on two generators and two discriminators. The training sample set includes multiple positive and negative sample pairs, wherein the positive sample is a non-defective sample image and the negative sample is a defective sample image.

[0032] The two generators of the defect image generation model are the first generator and the second generator, and the two discriminators of the defect image generation model are the first discriminator and the second discriminator. In the cyclic adversarial training process, the first generator is used to generate a defect image based on a defect-free sample image or a defect-free image generated by the second generator, the second generator is used to generate a defect-free image based on a defect sample image or a defect image generated by the first generator, the first discriminator is used to discriminate the data distribution of the defect image generated by the first generator, and the second discriminator is used to discriminate the data distribution of the defect image generated by the second generator.

[0033] In an exemplary embodiment, Figure 3 As shown, step 202 includes steps 301 to 303 .

[0034] Step 301 , using a pre-trained encoder of a first generator, a convolution operation is used to extract features from the industrial defect-free image to obtain a preliminary feature map.

[0035] In this embodiment, the encoder extracts features of the image through a series of convolutions, that is, the encoder of the pre-trained first generator uses the following formula to extract features of the industrial defect-free image.

[0036] .

[0037] in, i is the serial number of the convolutional layer in the encoder, i =1,2,..., n , n is the number of convolutional layers, For the i -1 convolutional layer output, when i =1 is the output of the 0th convolutional layer, representing an industrial defect-free image. For the i The output of the convolutional layer, For the n The output of the convolutional layer, i.e., the preliminary feature map, For the i The convolution kernel of the convolution layer, For the i The bias term of the convolutional layer, is the convolution operation, is the rectified linear activation function.

[0038] Step 302, using a pre-trained converter of the first generator and a residual network based on a self-attention mechanism, the features in the preliminary feature map are integrated to obtain an integrated feature map.

[0039] In this embodiment, Figure 4 As shown in the figure, the self-attention mechanism is combined with the residual network to form a residual network based on self-attention. The self-attention mechanism is widely used in the field of natural language processing. It can establish semantic connections between multiple features input into a fully connected neural network and construct a global receptive field between feature vectors. Residual networks are widely used in many computer vision tasks. By introducing residual blocks and shortcut connections, they can effectively alleviate the difficulty of training deep neural networks, making it possible to train very deep neural networks and significantly improving the performance of the model. The residual network is composed of multiple residual blocks stacked together.

[0040] The pre-trained converter of the first generator integrates the features in the preliminary feature map using the following formula.

[0041] .

[0042] .

[0043] .

[0044] in, j is the serial number of the residual block based on the self-attention mechanism, j =1,2,..., m , m is the number of residual blocks based on the self-attention mechanism, where m Take 6, For the j The output of the residual block based on the self-attention mechanism, For the j -1 output of a residual block based on the self-attention mechanism, when j =1 represents the preliminary feature map, i.e., the output of the 0th residual block based on the self-attention mechanism and the n The output of each convolutional layer is the same. For the m The output of the residual block based on the self-attention mechanism is the integrated feature map. is a 3×3 convolution kernel, is a 1×1 convolution kernel, For the j -1 bias term of the residual block based on the self-attention mechanism, is the self-attention mechanism, For the j -1 query matrix for the residual block based on the self-attention mechanism, For the j -1 key matrix for the residual block based on the self-attention mechanism, For the j -1 value matrix of the residual block based on the self-attention mechanism, for and The number of matrix columns, superscript T represents the transpose operation, is the multinomial logistic regression activation function. Establish semantic associations between features, i.e., distance matrix, The role is to prevent and After the inner product of each row, the value is too large, which affects the semantic relevance. The role of is to calculate the correlation coefficient of each feature corresponding to other features. Each row in the distance matrix obtained represents the correlation coefficient of a certain feature to all other features. Finally, the distance matrix is ​​compared with Perform matrix multiplication to obtain an output matrix with global correlation.

[0045] Step 303, through the decoder of the pre-trained first generator, using a skip connection mechanism and a deconvolution operation, the integrated feature map is restored to the target domain to obtain an industrial defect image.

[0046] In this embodiment, a skip connection mechanism is introduced in the decoder part, and then the integrated feature map is restored to the target domain image through a series of deconvolution operations or upsampling operations. The skip connection mechanism connects the feature maps of the generator downsampling path and the upsampling path, and promotes the transmission and sharing of information by directly connecting the low-level and high-level feature maps. This design allows the network to generate images using features at different levels, better retain and utilize the detailed information of the image, so that information can be transmitted more directly, reducing the loss of information in the network, thereby improving the performance and accuracy of the model.

[0047] The decoder of the pre-trained first generator restores the integrated feature map to the target domain using the following formula.

[0048] .

[0049] .

[0050] in, c is the serial number of the deconvolution layer in the decoder, c =0,1,..., o , o is the number of deconvolution layers, the number of deconvolution layers is the same as the number of convolution layers, that is, o = n , For the c The output of the deconvolution layer, For the c +1 deconvolution layer output, when c =0 Represents the integrated feature map, that is, the output of the 0th deconvolution layer and the m The output of the residual block based on the self-attention mechanism is the same. For the n - c The output of the convolutional layer, For the c The convolution kernel of the deconvolution layer, For the c The bias term of the deconvolution layer, is the deconvolution operation, For the skip connection operation, the feature maps are concatenated in the channel dimension. For industrial defect images, is the hyperbolic tangent activation function.

[0051] In an exemplary embodiment, Figure 5 As shown, the size of the industrial defect-free image input by the first generator is 256×256×3, and after padding, the size becomes 256×256×64 ( Figure 5 The first rectangular box in the image), and then the convolution operation is performed through the first encoder ( Figure 5 ), normalization and activation ( Figure 5 The image size is changed to 128×128×128, and the convolution operation is performed through the second encoder ( Figure 5 5th to 7th rectangles in ), normalization and activation ( Figure 5The 8th rectangular box in the image is resized to 64×64×256 and convolution is performed through the 3rd encoder ( Figure 5 9th to 11th rectangular boxes in ), normalization and activation ( Figure 5 The image size is still 64×64×256, and then it is integrated through the converter ( Figure 5 13th to 15th rectangular boxes in the image), and then perform one-dimensional transposed convolution through the first decoder ( Figure 5 16th to 18th rectangles in ), normalization and activation ( Figure 5 The image size is restored to 128×128×128, and a one-dimensional transposed convolution is performed through the second decoder ( Figure 5 20th to 22nd rectangles in ), normalization and activation ( Figure 5 The 23rd rectangular box in the image is restored to 256×256×64, and then the image is filled ( Figure 5 The 24th rectangular box in the figure), after padding, the size is restored to 256×256×3, and then a convolution and hyperbolic tangent activation function are performed ( Figure 5 The 25th to 26th rectangular boxes in the figure are used to output the final industrial defect image.

[0052] Furthermore, the discriminator of the cyclic generative adversarial network maps the input image to a probabilistic feature map through a series of convolution, activation and downsampling operations. , which represents the probability that each local area of ​​the image is judged as a real image. The calculation formula is: .

[0053] in, x The image generated by the generator, that is, the target domain image generated by the generative adversarial network, is the first s The convolution kernel of the layer, is the first s The bias term of the layer, is the downsampling operation, for sigmoid Function, used to map the output to the range of [0,1]. The ellipsis in the formula represents the discriminator from the second layer to the first layer. s -1 layer activation and downsampling operation.

[0054] The Generative Adversarial Network uses a generator and a discriminator to continuously conduct dynamic confrontation, and uses the adversarial generation loss to optimize its own parameters so that the generator can learn the characteristic distribution of real data. The role of the generator is to make the generated data distribution closer to the real data distribution by learning the distribution of real data, making it difficult for the discriminator to distinguish the authenticity of the data distribution. The role of the discriminator is to determine whether the input data distribution is the data distribution generated by the generator or the real data distribution and then score it. If it is judged to be the real data distribution, the discriminator outputs 1, otherwise the output is 0. Therefore, when training the Generative Adversarial Network, the generator and the discriminator are cross-trained, and through continuous adversarial training, the generator and the discriminator eventually reach Nash equilibrium.

[0055] The loss function of the generative adversarial network is as follows.

[0056] .

[0057] in, G represents the first generator, D represents the discriminator, is the loss function value of the generated adversarial network, z represents the source domain image that generates the adversarial network input, x represents the target domain image generated by the generative adversarial network, express x The score in the discriminator, It means that the first generator is based on z The generated image, express x The distribution of express z The distribution of express exist x From The expectation of the distribution, express exist z From Expectations of distribution.

[0058] The purpose of the recurrent generative adversarial network is to generate a mapping relationship between the source domain and the target domain, that is, the generated image has a high structural similarity with the content dataset in terms of content, and a high structural similarity with the style dataset in terms of style. A single generative adversarial network will have uncertainty in the mapping combination, resulting in only one image in the target domain being connected to the source domain, that is, the generated image is always an image in the same style dataset.

[0059] Therefore, the cyclic generative adversarial network inherits the idea of ​​adversarial training of the generative adversarial network. It transforms the adversarial training of the generative adversarial network into a cyclic adversarial mode in a dual training and learning manner. The network is transformed from the original one generator and one discriminator to two generators, defined as G and F , two discriminator networks, defined as and , and then add a cycle consistency loss function to constrain the structural similarity between the generated image and the real image.

[0060] Specifically, the input industrial defect-free image is defined as real_X Domain image, the generated industrial defective image is fake_Y Domain image, the input industrial defective image is real_Y Domain image, the generated industrial defect-free image is fake_ X Domain image.

[0061] like Figure 6 As shown, the cyclic generative adversarial network has a structure in the upper part. real_X The images in the domain are passed through the first generator G Mapping Generation fake_Y Domain Image , the first discriminator D Y Will judge G ( x ) is the real data distribution or the generated data distribution. Then, using the idea of ​​cycle consistency, the generated image Through the second generator F Remap Generation fake_X Images in the domain To prevent the generated image from lose real_X The content of the domain image is determined by generating an image and real_X Domain Image L The 2-norm loss function is calculated to make the two images as similar as possible, that is, .

[0062] The structure of the cyclic generative adversarial network is to first real_Y The domain is passed through the second generator F Mapping Generation fake_X Domain Image , and then through the first generator G Mapping Generation fake_Y Domain Image , and finally achieve At this time, the two generators can realize style transfer, that is, industrial defect-free images can be used to generate stable industrial defective images, or industrial defective images can be used to generate stable industrial defect-free images.

[0063] Among them, the adversarial generation loss function of the first generator is: .

[0064] The adversarial generation loss function of the second generator is: .

[0065] The cycle consistency loss function is L The 2-norm loss function, also known as the least square error, is formulated as: .

[0066] The loss function of the defect image generation model during cyclic adversarial training is: .

[0067] in, is the total loss function value, Generate the loss function value for the adversarial generation of the first generator, Generate the loss function value for the adversarial generation of the second generator, is the cycle consistency loss function value, G is the first generator, F is the second generator, is the first discriminator, is the second discriminator, X is the source domain image, indicating a defect-free image, Y is the target domain image, representing the defect image.

[0068] The positive and negative sample pairs of collected industrial products are sent to the cyclic generative adversarial network based on self-attention and jump connection for cyclic adversarial training. Specifically, the parameters of the two generators and two discriminators are adjusted through back propagation according to the generative adversarial loss and the cycle consistency loss to constrain the structural similarity between the generated image and the real image, and finally the defect image generation model is obtained. Then, an industrial defect-free image is sent to the corresponding generator in the defect image generation model, that is, the source domain image is an industrial defect-free image, and the target domain image is an industrial defective image. The first generator runs the defect image generation model once, and the first generator can output an industrial defect image. Further, the parameters of the number of output images are set in the defect image generation model, and the trained first generator can generate multiple stable and high-quality industrial defect images.

[0069] This application aims to solve the problems of uncontrollable and poor quality industrial defect image generation caused by complex scenes such as complex background, large defect differences, and noise interference. By introducing a self-attention mechanism and a jump connection mechanism in the generator, long-distance and multi-scale feature extraction is performed on the input source domain image, thereby improving the global field of view and multi-scale feature extraction capabilities of feature extraction, generating a generated image similar to the target domain image, and using a recurrent generative adversarial network with dual generators and dual discriminators to optimize the original generative adversarial network, reducing the loss of important detail information in the process of industrial defect image generation, improving the stability and quality of industrial defect image generation, maintaining the consistency of generated image content, and improving the robustness of the defect image generation model.

[0070] The present application also provides an application scenario, which applies the above-mentioned industrial defect image generation method. Specifically: The industrial defect image generation method provided in this embodiment can be applied in the industrial product surface defect detection scenario. The industrial product surface defect detection scenario includes a sample acquisition link, a defect detection model training link, and a defect detection link; first, the industrial defect image generation method provided in this application is used to generate multiple industrial defect images as a sample set, and then the defect detection model training link is entered, and the above-mentioned sample set is used to train the defect detection model, and finally the trained defect detection model is used to perform defect detection on the actual industrial product.

[0071] In an exemplary embodiment, a computer device is provided. The computer device may be a server or a terminal. The internal structure diagram thereof may be as follows: Figure 7 As shown. The computer device includes a processor, a memory, an input / output interface (Input / Output, referred to as I / O) and a communication interface. Among them, the processor, the memory and the input / output interface are connected through a system bus, and the communication interface is connected to the system bus through the input / output interface. Among them, the processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system, a computer program and a database. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The database of the computer device is used to store industrial defect-free images and defect image generation models. The input / output interface of the computer device is used to exchange information between the processor and an external device. The communication interface of the computer device is used to communicate with an external terminal through a network connection. When the computer program is executed by the processor, an industrial defect image generation method is implemented.

[0072] Those skilled in the art will understand that Figure 7The structure shown in the figure is only a block diagram of a part of the structure related to the solution of the present application, and does not constitute a limitation on the computer device to which the solution of the present application is applied. The specific computer device may include more or fewer components than those shown in the figure, or combine certain components, or have a different arrangement of components. In an exemplary embodiment, a computer device is provided, including a memory and a processor, wherein a computer program is stored in the memory, and the processor implements the steps in the above-mentioned method embodiments when executing the computer program.

[0073] In an exemplary embodiment, a computer-readable storage medium is provided, storing a computer program, and when the computer program is executed by a processor, the steps in the above method embodiments are implemented.

[0074] In an exemplary embodiment, a computer program product is provided, including a computer program, and when the computer program is executed by a processor, the steps in the above method embodiments are implemented.

[0075] It should be noted that the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, stored data, displayed data, etc.) involved in this application are all information and data authorized by the user or fully authorized by all parties, and the collection, use and processing of relevant data must comply with relevant regulations.

[0076] Those skilled in the art can understand that all or part of the processes in the above-mentioned embodiment methods can be completed by instructing the relevant hardware through a computer program, and the computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, any reference to the memory, database or other medium used in the embodiments provided in this application can include at least one of non-volatile and volatile memory. Non-volatile memory can include read-only memory (ROM), magnetic tape, floppy disk, flash memory, optical memory, high-density embedded non-volatile memory, resistive random access memory (ReRAM), magnetoresistive random access memory (MRAM), ferroelectric random access memory (FRAM), phase change memory (PCM), graphene memory, etc. Volatile memory can include random access memory (RAM) or external cache memory, etc. By way of illustration and not limitation, RAM may be in various forms, such as Static Random Access Memory (SRAM) or Dynamic Random Access Memory (DRAM).

[0077] The database involved in each embodiment provided in this application may include at least one of a relational database and a non-relational database. The non-relational database may include a distributed database based on blockchain, etc., but is not limited thereto. The processor involved in each embodiment provided in this application may be a general-purpose processor, a central processing unit, a graphics processor, a digital signal processor, a programmable logic device, a data processing logic device based on quantum computing, etc., but is not limited thereto.

[0078] The technical features of the above embodiments may be combined arbitrarily. To make the description concise, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.

[0079] This article uses specific examples to illustrate the principles and implementation methods of this application. The description of the above embodiments is only used to help understand the method and core ideas of this application. At the same time, for those skilled in the art, according to the ideas of this application, there will be changes in the specific implementation methods and application scope. In summary, the content of this specification should not be understood as limiting this application.

Claims

1. A method for generating an industrial defect image, characterized in that: The industrial defect image generation method comprises: Get industrial defect-free images; According to the industrial defect-free image, a defect image generation model is used to generate an industrial defect image; the defect image generation model is constructed based on a cyclic generative adversarial network; the defect image generation model includes two generators and two discriminators, each generator includes an encoder, a converter and a decoder connected in sequence; the encoder uses a convolution operation to extract the features of the input image, the converter uses a residual network based on a self-attention mechanism to convert the image output by the encoder, and the decoder uses a skip connection mechanism and a deconvolution operation to decode the image output by the converter to obtain a generated image; the two generators of the defect image generation model are a first generator and a second generator respectively; According to the industrial defect-free image, a defect image generation model is used to generate an industrial defect image, specifically including: The encoder of the pre-trained first generator uses a convolution operation to extract features from the industrial defect-free image to obtain a preliminary feature map; the encoder of the pre-trained first generator uses the following formula to extract features from the industrial defect-free image: ; in, i is the serial number of the convolutional layer in the encoder, i =1,2,..., n , n is the number of convolutional layers, For the i - the output of 1 convolutional layer, For the i The output of the convolutional layer, For industrial defect-free images, For the i The convolution kernel of the convolution layer, For the i The bias term of the convolutional layer, is the convolution operation, is the corrected linear activation function; The converter of the pre-trained first generator uses a residual network based on a self-attention mechanism to integrate the features in the preliminary feature map to obtain an integrated feature map; the converter of the pre-trained first generator uses the following formula to integrate the features in the preliminary feature map: ; ; ; in, j is the serial number of the residual block based on the self-attention mechanism, j =1,2,..., m , m is the number of residual blocks based on the self-attention mechanism, For the j The output of the residual block based on the self-attention mechanism, For the j -1 output of a residual block based on the self-attention mechanism, represents the preliminary feature map, is a 3×3 convolution kernel, is a 1×1 convolution kernel, For the j A bias term of the residual block based on the self-attention mechanism, is the self-attention mechanism, For the j -1 query matrix for the residual block based on the self-attention mechanism, For the j -1 key matrix for the residual block based on the self-attention mechanism, For the j -1 value matrix of the residual block based on the self-attention mechanism, for and The number of matrix columns, superscript T represents the transpose operation, is the multinomial logistic regression activation function; The integrated feature map is restored to the target domain through the decoder of the pre-trained first generator by adopting a skip connection mechanism and a deconvolution operation to obtain an industrial defect image.

2. The industrial defect image generation method according to claim 1, characterized in that: The defect image generation model is obtained by pre-using a training sample set to perform cyclic adversarial training on two generators and two discriminators; the training sample set includes a plurality of positive and negative sample pairs, wherein the positive sample is a non-defective sample image and the negative sample is a defective sample image; The two discriminators of the defect image generation model are the first discriminator and the second discriminator; in the cyclic adversarial training process, the first generator is used to generate a defect image based on a defect-free sample image or a defect-free image generated by the second generator, and the second generator is used to generate a defect-free image based on a defect sample image or a defective image generated by the first generator, the first discriminator is used to discriminate the data distribution of the defective image generated by the first generator, and the second discriminator is used to discriminate the data distribution of the defective image generated by the second generator.

3. The industrial defect image generation method according to claim 1, characterized in that: The decoder of the pre-trained first generator restores the integrated feature map to the target domain using the following formula: ; ; in, c is the serial number of the deconvolution layer in the decoder, c =0,2,..., o , o is the number of deconvolution layers, For the c The output of the deconvolution layer, For the c +1 output of the deconvolution layer, represents the integrated feature map, For the n - c The output of the convolutional layer, For the c The convolution kernel of the deconvolution layer, For the c The bias term of the deconvolution layer, is the deconvolution operation, For skip connection operation, For industrial defect images, is the hyperbolic tangent activation function.

4. The industrial defect image generation method according to claim 2, characterized in that: The loss function of the defect image generation model during cyclic adversarial training is: ; in, is the total loss function value, Generate the loss function value for the adversarial generation of the first generator, Generate the loss function value for the adversarial generation of the second generator, is the cycle consistency loss function value, G is the first generator, F is the second generator, is the first discriminator, is the second discriminator, X is the source domain image, indicating a defect-free image, Y is the target domain image, representing the defect image.

5. A computer device comprising: A memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the computer program to implement the industrial defect image generating method according to any one of claims 1 to 4.

6. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the industrial defect image generating method according to any one of claims 1 to 4 is implemented.

7. A computer program product, comprising a computer program, characterized in that When the computer program is executed by a processor, the industrial defect image generating method according to any one of claims 1 to 4 is implemented.

Citation Information

Patent Citations

  • Light guide plate defect small sample data expansion method, system and equipment and storage medium

    CN118115835A