Sample picture generation method, device and equipment
By increasing the number of uses and loss calculations of the discriminator in the GAN neural network, the method of generating model sample images solves the problem of lack of robustness in sample image generation in the existing technology and improves the quality and applicability of the generated images.
Patent Information
- Application Number
- CN202310212909.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2023-03-07
- Publication Date
- 2024-09-10
- Estimated Expiration
- 2043-03-07
AI Technical Summary
The existing GAN neural network only uses the discriminator twice during the training process, resulting in the generated sample pictures being biased towards the target sample pictures or reference sample pictures, lacking robustness, and making it difficult to generate mixed effect pictures.
By obtaining the target image, filter multiple reference images from the preset sample database, and use the pre-built generator and discriminator to calculate multiple discriminant losses respectively, train the discriminator and generator, and generate model sample images until it reaches Preset similarity requirements to enhance the robustness of images.
The quality and robustness of the model sample pictures generated by the GAN neural network are improved, so that the generated pictures can better mix the characteristics of the target and reference pictures, and are suitable for different application scenarios.
Smart Images

Figure CN118628850A
Abstract
Description
Technical Field
[0001] The invention relates to a sample picture generating method, a device and a equipment. Background Art
[0002] In some scenarios, since natural real pictures are very small, it is usually necessary to use technical means to generate some pictures that are highly similar to natural real pictures. For example, in the field of transportation, when collecting traffic sign data, it is very difficult to obtain some uncommon traffic signs. Conventional technology usually uses GAN neural networks to generate these difficult-to-obtain pictures.
[0003] GAN neural network is also called adversarial neural network, which includes generator (Generator Network) and discriminator (Discriminator Network). The core logic of GAN is that the generator and the discriminator compete with each other. The task of the generator network is to generate instances that look natural and real and similar to the original data. The task of the discriminator network is to judge whether the given instance looks natural and real or artificially forged. During the training process, the goal of the generator is to generate as many fake images as possible that are close to real images to deceive the discriminator, and the goal of the discriminator is to try to distinguish the fake images generated by the generator from the real images. After alternating optimization training, both models can be improved, and finally a generation model with a very high effect is obtained. In theory, the fake images generated by the final generation model can reach the point where it is difficult to distinguish between the real and the fake. Summary of the invention
[0004] The inventor of the present invention found that the GAN neural network in the prior art only uses the discriminator twice during the training process, and the generated sample images are biased towards the target sample images or the reference sample images, and cannot obtain a good mixed effect image, making the overall output image lack robustness. Based on this, the inventor proposed the present invention to provide a sample image generation method, device and equipment that overcomes the above problems or at least partially solves the above problems existing in the prior art.
[0005] In a first aspect, an embodiment of the present invention provides a sample image generation method, the method comprising:
[0006] Based on the acquired target image, multiple reference images are screened from a preset sample database, and a model sample image is obtained based on a pre-built generator;
[0007] Inputting the target image, the reference image and the model sample image into the discriminator corresponding to the generator respectively, and training the discriminator according to the obtained first discriminant loss, second discriminant loss and third discriminant loss;
[0008] Input the model sample image into the trained discriminator, and train the generator according to the obtained output result;
[0009] Saving model sample images whose similarity with the target image meets preset requirements;
[0010] Determine whether the number of all saved model sample images reaches a preset threshold. If not, repeat the above steps of obtaining model sample images, training the discriminator and the generator.
[0011] In one or some optional embodiments, the first discrimination loss, the second discrimination loss and the third discrimination loss are obtained in the following manner, including:
[0012] The target image is input into the discriminator to obtain a first output matrix, and a first discriminant loss is obtained according to the first output matrix and a preset first truth matrix; wherein the first output matrix and the first truth matrix are both n*n matrices, n is a positive integer, and the value of the element representing the foreground area of the target image in the first truth matrix is greater than the value of the element representing the background area of the target image;
[0013] The reference image is input into the discriminator to obtain a second output matrix, and a second discriminant loss is obtained according to the second output matrix and a preset second truth matrix; wherein the second output matrix and the second truth matrix are both n*n matrices, and the value of the element representing the foreground area of the reference image in the second truth matrix is smaller than the value of the element representing the background area of the reference image; the value of the element representing the foreground area of the reference image in the second truth matrix is smaller than the value of the element representing the foreground area of the target image in the first truth matrix, and the value of the element representing the background area of the reference image in the second truth matrix is smaller than the value of the element representing the background area of the target image in the first truth matrix;
[0014] The model sample image is input into the discriminator to obtain a third output matrix, and a third discriminant loss is obtained according to the third output matrix and a preset third truth matrix; wherein the third output matrix and the third truth matrix are both n*n matrices, and the value of the element representing the foreground area of the model sample image in the third truth matrix is equal to the value of the element representing the background area of the model sample image.
[0015] In one or some optional embodiments, training the discriminator according to the first discriminant loss, the second discriminant loss and the third discriminant loss includes:
[0016] Calculate the discriminant loss result of the discriminator according to the first discriminant loss, the second discriminant loss and the third discriminant loss;
[0017] The discriminator is trained according to the discriminant loss result to obtain a trained discriminator.
[0018] In one or some optional embodiments, the method further comprises:
[0019] After obtaining the first discriminant loss, the second discriminant loss and the third discriminant loss, back-propagation training is performed on the discriminator respectively.
[0020] In one or some optional embodiments, inputting the model sample image into the trained discriminator and training the generator according to the obtained output result includes:
[0021] The model sample image is input into the trained discriminator to obtain a fourth output matrix, a fourth discriminant loss is obtained according to the fourth output matrix and a preset fourth truth matrix, and the generator is updated according to the fourth discriminant loss to obtain a trained generator; wherein the fourth output matrix and the fourth truth matrix are both n*n matrices, and the value of the element representing the foreground area of the model sample image in the fourth truth matrix is equal to the value of the element representing the background area of the model sample image.
[0022] In one or some optional embodiments, the method further comprises:
[0023] After obtaining the fourth discriminant loss, back-propagation training is performed on the generator.
[0024] In one or some optional embodiments, the step of selecting a plurality of reference images from a preset sample database based on the acquired target image includes:
[0025] A target feature vector of the target image is obtained, and the target feature vector is compared with images in the sample database for similarity, so as to screen and obtain the multiple reference images.
[0026] In one or some optional embodiments, obtaining the target feature vector of the target image, comparing the target image with images in the sample database for similarity, and screening to obtain the multiple reference images includes:
[0027] Obtaining a target feature vector of the target image, comparing the target feature vector with images in the sample database for similarity, and screening to obtain a plurality of reference candidate images;
[0028] The multiple reference pictures are obtained by randomly selecting from the multiple reference candidate pictures.
[0029] In one or some optional embodiments, based on a pre-built generator, the model sample image is obtained in the following manner, including:
[0030] Constructing a model data pair with the target image and each reference image, inputting the reference image of the model data pair into the encoder of the generator for feature extraction, and obtaining a reference image feature vector;
[0031] Inputting the reference picture feature vector and the target feature vector into the attention module of the generator for calculation to obtain an attention feature vector;
[0032] The attention feature vector is input into the decoder of the generator for processing to obtain the model sample image.
[0033] In one or some optional embodiments, when repeatedly performing the above steps of obtaining a model sample image, training a discriminator and a generator, a plurality of reference images are randomly screened again from the plurality of reference candidate images.
[0034] In one or some optional embodiments, the target feature vector of the target image is determined in the following manner:
[0035] The target image is input into a pre-trained feature extraction model to obtain the target feature vector.
[0036] In one or some optional embodiments, the step of saving the model sample image whose similarity with the target image meets the preset requirement includes:
[0037] Determine whether the similarity between the model sample image and the target image reaches a preset threshold;
[0038] If yes, the model sample image is saved.
[0039] In a second aspect, an embodiment of the present invention provides a sample image generating device, the device comprising:
[0040] A generation module, used to screen multiple reference images from a preset sample database based on the acquired target image, and obtain a model sample image based on a pre-built generator;
[0041] A discriminator training module, used to input the target image, the reference image and the model sample image into the discriminator corresponding to the generator respectively, and train the discriminator according to the obtained first discriminant loss, second discriminant loss and third discriminant loss;
[0042] A generator training module, used for inputting the model sample images into the trained discriminator, and training the generator according to the obtained output results;
[0043] A saving module, used to save model sample images whose similarity with the target image meets preset requirements;
[0044] The judgment module is used to judge whether the number of all saved model sample images reaches a preset threshold.
[0045] In a third aspect, an embodiment of the present invention provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the sample image generating method as described above.
[0046] In a fourth aspect, an embodiment of the present invention provides a computer device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the sample image generation method as described above when executing the computer program.
[0047] The beneficial effects of the above technical solution provided by the embodiment of the present invention include at least:
[0048] The sample image generation method provided by the present invention uses the target image, the reference image and the model sample image at the same time, and adds two discriminator use processes in the training process of the GAN neural network, so that the generated model sample image is affected by the target image and the reference image at the same time, thereby enhancing the mixing effect of the model sample image, improving the quality of the generated image, and improving the robustness of the model sample image generated by the GAN neural network. In addition, compared with other images obtained by semantic training based on labels in the prior art, the model sample image obtained by this method is semantic-free, so it can be reused in different application scenarios and has better flexibility of use.
[0049] The sample image generation method provided by the present invention adopts a truth matrix with a mask property in the process of determining the discrimination loss by training the discriminator three times, and realizes controlling the area of the generated image, including the background area and the foreground area of the generated image, by setting the characteristic values of the elements of the background area and the foreground area of the truth matrix corresponding to the target image, the reference image and the model sample image respectively, so that the area is affected by the target image and the reference image respectively, thereby better controlling the quality of the generated model sample image.
[0050] Other features and advantages of the present invention will be described in the following description, and partly become apparent from the description, or understood by practicing the present invention. The purpose and other advantages of the present invention can be realized and obtained by the structures particularly pointed out in the written description, claims, and drawings.
[0051] The technical solution of the present invention is further described in detail below through the accompanying drawings and embodiments. BRIEF DESCRIPTION OF THE DRAWINGS
[0052] The accompanying drawings are used to provide a further understanding of the present invention and constitute a part of the specification. Together with the embodiments of the present invention, they are used to explain the present invention and do not constitute a limitation of the present invention. In the accompanying drawings:
[0053] Figure 1 A schematic diagram of a flow chart of a sample image generation method provided by an embodiment of the present invention;
[0054] Figure 2 A schematic diagram of a model of a generator of a GAN neural network provided in an embodiment of the present invention;
[0055] Figure 3 A schematic diagram of a model of another generator of a GAN neural network provided in an embodiment of the present invention;
[0056] Figure 4 A schematic diagram of a model of a discriminator of a GAN neural network provided in an embodiment of the present invention;
[0057] Figure 5 A schematic diagram of the structure of a sample image generating device provided in an embodiment of the present invention. DETAILED DESCRIPTION
[0058] The exemplary embodiments of the present disclosure will be described in more detail below with reference to the accompanying drawings. Although the exemplary embodiments of the present disclosure are shown in the accompanying drawings, it should be understood that the present disclosure can be implemented in various forms and should not be limited by the embodiments set forth herein. On the contrary, these embodiments are provided to enable a more thorough understanding of the present disclosure and to fully convey the scope of the present disclosure to those skilled in the art.
[0059] Embodiment 1
[0060] The embodiment of the present invention provides a sample image generation method, referring to Figure 1 As shown, the method includes:
[0061] S101: Based on the acquired target image, multiple reference images are screened from a preset sample database, and a model sample image is obtained based on a pre-built generator;
[0062] S102: inputting the target image, the reference image and the model sample image into the discriminator corresponding to the generator respectively, and training the discriminator according to the obtained first discriminant loss, second discriminant loss and third discriminant loss;
[0063] S103: Inputting the model sample image into the trained discriminator, and training the generator according to the obtained output result;
[0064] S104: Saving model sample images whose similarity with the target image meets preset requirements;
[0065] S105: Determine whether the number of all saved model sample images reaches a preset threshold. If not, repeat the above steps S101 to S105. If yes, end.
[0066] The sample image generation method provided by the present invention uses the target image, the reference image and the model sample image at the same time, and adds two discriminator use processes in the training process of the GAN neural network, so that the generated model sample image is affected by the target image and the reference image at the same time, thereby enhancing the mixing effect of the model sample image, improving the quality of the generated image, and improving the robustness of the model sample image generated by the GAN neural network. In addition, compared with other images obtained by semantic training based on labels in the prior art, the model sample image obtained by this method is semantic-free, so it can be reused in different application scenarios and has better flexibility of use.
[0067] In the embodiment of the present invention, the above step S101, based on the acquired target image, selects multiple reference images from a preset sample database, and obtains a model sample image based on a pre-built generator, specifically includes:
[0068] Based on the acquired target image, multiple reference images are selected from a preset sample database;
[0069] For the model data pairs constructed for the target image and each reference image, the model data pairs are input into a pre-constructed generator to obtain model sample images.
[0070] In a specific embodiment, the above-mentioned screening of multiple reference images from a preset sample database based on the acquired target image specifically includes:
[0071] A target feature vector of the target image is obtained, and the target feature vector is compared with images in the sample database for similarity, so as to screen and obtain the multiple reference images.
[0072] Specifically, it may be that a target feature vector of the target image is obtained, the target feature vector is compared with images in the sample database for similarity, and a plurality of reference candidate images are screened;
[0073] The multiple reference pictures are obtained by randomly selecting from the multiple reference candidate pictures.
[0074] For example, assuming that the target feature vector of the acquired target image A is a, the target feature vector a is used to retrieve the TopN candidate images with close similarity, large similarity difference or randomly selected from the preset sample database as reference candidate images. Finally, a preset number of images are randomly selected from the TopN candidate images as reference images, and a model data pair is constructed between the target image and each selected reference image. For example, taking the preset number of three as an example, three reference images can be randomly selected, such as reference images B, C and D. The target feature vector a of the target image is used to construct a model data pair with each reference image, that is, the generated model data pairs Ba, Ca and Da are obtained.
[0075] In the embodiment of the present invention, the preset sample database is a picture database of reference pictures. By repeatedly executing the above steps of randomly selecting a preset number of pictures from the TopN candidate pictures as reference pictures, and constructing model data pairs with the reference pictures and the target feature vectors, a training batch model data pair set can be generated.
[0076] In a specific example, the target feature vector of the target image is obtained in the following manner:
[0077] The target image is input into a pre-trained feature extraction model to obtain the target feature vector.
[0078] In an embodiment of the present invention, the pre-trained feature extraction model may use a network structure such as Resnet12, Convnet4, etc. to obtain a target feature vector.
[0079] In an embodiment of the present invention, when comparing the target feature vector with the image in the sample database for similarity, the feature vector of the reference image can be obtained first, and the feature vector comparison method can be adopted. Of course, other methods for implementing image similarity comparison recorded in the prior art can also be adopted. The specific implementation process can refer to the detailed description of the prior art, which will not be repeated here.
[0080] In a specific embodiment, referring to Figure 2As shown, the pre-built generator includes an encoder, an attention module and a decoder. The above-mentioned input of the model data pair into the pre-built generator to obtain a model sample image specifically includes:
[0081] Inputting the reference picture of the model data pair into the encoder of the generator for feature extraction to obtain a reference picture feature vector;
[0082] Inputting the reference image feature vector and the target feature vector into the attention module of the generator to perform attention calculation to obtain an attention feature vector;
[0083] The attention feature vector is input into the decoder of the generator for processing to obtain the model sample image.
[0084] In an embodiment of the present invention, the specific implementation method of the encoder and decoder of the generator can refer to the generation method of the encoder and decoder of the generator in the prior art, and the attention module can adopt the residual attention module in the prior art. The specific implementation process will not be repeated here.
[0085] As a specific implementation of the embodiment of the present invention, refer to Figure 3 As shown, the generator may also include a random vector module, which generates a random vector, merges (Concat) the random vector with the attention feature vector to obtain a concatenated feature vector, and then inputs the concatenated feature vector into the decoder of the generator for processing to obtain a model sample image.
[0086] In an embodiment of the present invention, the inventor considers that due to merging the reference image feature vector and the target feature vector to obtain a merged feature vector, and then performing attention calculation on the merged feature vector, the obtained attention feature vector will make the strong image features stronger and the weak image features weaker, and the relative difference becomes larger. Based on this, the inventor proposes to generate a random vector through a random vector module and splice it with the attention feature vector, thereby increasing random noise and increasing the randomness of the sample image of the generated model, so as to better train the discriminator of the GAN neural network.
[0087] In the embodiment of the present invention, the target image, the reference image and the model sample image are respectively input into the discriminator corresponding to the generator as described in the above step S102, and the discriminator is trained according to the obtained first discriminant loss, second discriminant loss and third discriminant loss, specifically including:
[0088] Inputting the target image, the reference image and the model sample image into the discriminator corresponding to the generator respectively, and obtaining the corresponding first discriminant loss, second discriminant loss and third discriminant loss;
[0089] The discriminator is trained according to the first discriminant loss, the second discriminant loss and the third discriminant loss.
[0090] In a specific embodiment, the target image, the reference image, and the model sample image are input into the discriminator corresponding to the generator to obtain the first discriminant loss, the second discriminant loss, and the third discriminant loss, specifically including:
[0091] Inputting the target image into the discriminator to obtain a first output matrix, and obtaining a first discriminant loss according to the first output matrix and a preset first true value matrix;
[0092] Inputting the reference image into the discriminator to obtain a second output matrix, and obtaining a second discriminant loss according to the second output matrix and a preset second true value matrix;
[0093] The model sample image is input into the discriminator to obtain a third output matrix, and a third discriminant loss is obtained according to the third output matrix and a preset third true value matrix.
[0094] In the embodiment of the present invention, the above-mentioned inputting the target image into the discriminator means inputting the target feature vector of the target image into the discriminator, thereby obtaining a first output matrix and calculating the first discriminant loss.
[0095] In the embodiment of the present invention, refer to Figure 4 As shown, the discriminant pictures, i.e., the target picture, the reference picture, and the model sample picture, are input into the discriminator, and the discriminant network of the discriminator will output the corresponding discriminant result matrix, i.e., the first output matrix, the second output matrix, and the third output matrix. It should be noted that, in the embodiment of the present invention, the discriminant network of the discriminator is different from the discriminator in the conventional technology in that the output of the last convolutional layer of the discriminant network is an n*n matrix with a length and width of n and a channel number of 1, rather than a feature vector with a length and width of 1 and a channel number of 1.
[0096] In a specific embodiment, assuming that n is 4, the first truth value matrix, the second truth value matrix and the third truth value matrix can be set to be 4*4 matrices.
[0097] In the embodiment of the present invention, the eigenvalues of the elements representing the foreground area and the eigenvalues of the elements representing the background area in each truth matrix can be set according to actual needs, but should meet the following conditions:
[0098] In the first truth matrix, the value of the element representing the foreground area of the target image is greater than the value of the element representing the background area of the target image;
[0099] The value of the element representing the foreground area of the reference picture in the second truth matrix is smaller than the value of the element representing the background area of the reference picture; and the value of the element representing the foreground area of the reference picture in the second truth matrix is smaller than the value of the element representing the foreground area of the target picture in the first truth matrix, and the value of the element representing the background area of the reference picture in the second truth matrix is smaller than the value of the element representing the background area of the target picture in the first truth matrix;
[0100] The value of the element representing the foreground area of the model sample image in the third truth value matrix is equal to the value of the element representing the background area of the model sample image.
[0101] For example, the eigenvalue of the element representing the foreground area of the first truth value matrix GT1 is 1, and the eigenvalue of the element representing the background area is 0.5, then the first truth value matrix GT1 is:
[0102] GT1=[[0.5,0.5,0.5,0.5],
[0103] [0.5, 1.0, 1.0, 0.5],
[0104] [0.5, 1.0, 1.0, 0.5],
[0105] [0.5, 0.5, 0.5, 0.5]];
[0106] The eigenvalue of the element representing the foreground area of the second truth matrix GT2 is 0.1, and the eigenvalue of the element representing the background area is 0.2, so the second truth matrix GT2 is:
[0107] GT2=[[0.2, 0.2, 0.2, 0.2],
[0108] [0.2, 0.1, 0.1, 0.2],
[0109] [0.2, 0.1, 0.1, 0.2],
[0110] [0.2, 0.2, 0.2, 0.2]];
[0111] The eigenvalues of the elements representing the foreground area and the eigenvalues of the elements representing the background area of the third truth matrix GT3 are both 0, so the third truth matrix GT3 is:
[0112] GT3=[[0.0, 0.0, 0.0, 0.0],
[0113] [0.0, 0.0, 0.0, 0.0],
[0114] [0.0, 0.0, 0.0, 0.0],
[0115] [0.0, 0.0, 0.0, 0.0]].
[0116] In a specific embodiment, the training of the discriminator according to the first discriminant loss, the second discriminant loss and the third discriminant loss specifically includes:
[0117] Calculate the discriminant loss result of the discriminator according to the first discriminant loss, the second discriminant loss and the third discriminant loss;
[0118] The discriminator is trained according to the discriminant loss result to obtain a trained discriminator.
[0119] In a specific embodiment, the discrimination loss result is calculated based on the first discrimination loss, the second discrimination loss and the third discrimination loss, and specifically includes:
[0120] Substitute the first discrimination loss, the second discrimination loss and the third discrimination loss into the following formula 1 to obtain the discrimination loss result:
[0121] LossD=(1-α)*Loss1+α * Loss2+Loss3 Formula 1;
[0122] In the formula, LossD represents the discriminant loss result, Loss1 represents the first discriminant loss, Loss2 represents the second discriminant loss, Loss3 represents the third discriminant loss, α is a hyperparameter, and 0<α<1.
[0123] The sample image generation method provided by the present invention adopts a truth matrix with a mask property in the process of determining the discrimination loss by training the discriminator three times, and realizes controlling the area of the generated image, including the background area and the foreground area of the generated image, by setting the characteristic values of the elements of the background area and the foreground area of the truth matrix corresponding to the target image, the reference image and the model sample image respectively, so that the area is affected by the target image and the reference image respectively, thereby better controlling the quality of the generated model sample image.
[0124] In a specific embodiment, the method further includes: after obtaining the first discriminant loss, the second discriminant loss and the third discriminant loss, respectively performing back propagation training on the discriminator. Based on this, as a specific implementation of an embodiment of the present invention, the specific process of training the discriminator based on the above step S102 may include:
[0125] Fix the generator and reset the discriminator gradient;
[0126] The target image A is input into the discriminator to obtain the first output matrix, and the first discriminant loss Loss1 is calculated using the corresponding first truth matrix GT1; since the target image is a strong true image, the first output matrix obtained by the discriminator at this time is a probability matrix for being discriminated as a strong true value;
[0127] Perform the first back propagation on the discriminator;
[0128] The reference image is input into the discriminator to obtain the second output matrix, and the corresponding second truth matrix GT2 is used to calculate the second discriminant loss Loss2; since the reference image is a weak true image close to the real target image, the second output matrix obtained by the discriminator at this time is a probability matrix of being discriminated as a weak true value;
[0129] Perform a second back propagation on the discriminator;
[0130] The model sample image, i.e., the generated image, is input into the discriminator to obtain the third output matrix, and the corresponding third truth matrix GT3 is used to calculate the third discriminant loss Loss; since the model sample image is a generated image, the third output matrix obtained by the discriminator at this time is a probability matrix of being judged as false;
[0131] Perform a third back propagation on the discriminator;
[0132] Finally, the discriminant loss result is obtained through the above formula 1, and the discriminant parameters are updated according to the discriminant loss result to obtain the trained discriminator.
[0133] In the embodiment of the present invention, the step S103 described above of inputting the model sample image into the trained discriminator and training the generator according to the obtained output result includes:
[0134] The model sample image is input into the trained discriminator to obtain a fourth output matrix, a fourth discriminant loss is obtained according to the fourth output matrix and a preset fourth truth matrix, and the generator is updated according to the fourth discriminant loss to obtain a trained generator. The fourth output matrix and the fourth truth matrix are both n*n matrices, and the value of the element representing the foreground area of the model sample image in the fourth truth matrix is equal to the value of the element representing the background area of the model sample image.
[0135] In the embodiment of the present invention, during the generator training process, the trained discriminator should be fixed. The trained discriminator performs a process of determining whether the discrimination result is true. Therefore, the values of the elements representing the foreground area of the model sample image and the values of the elements representing the background area of the model sample image in the fourth truth matrix used can both be 1. Then the fourth truth matrix GT_G is:
[0136] GT_G=[[1.0, 1.0, 1.0, 1.0],
[0137] [1.0, 1.0, 1.0, 1.0],
[0138] [1.0, 1.0, 1.0, 1.0],
[0139] [1.0, 1.0, 1.0, 1.0]].
[0140] It can be seen from the training process of the above discriminator and generator that the above discriminator is used three times in its own training process and once in the generator training process, that is, in the training process of a GAN network model, the discriminator is used four times and the generator is used once in the whole process. Therefore, compared with the method of using only the discriminator twice and the generator once in the prior art, the generated model sample image is affected by the target image and the reference image at the same time, which enhances the mixing effect of the model sample image, improves the quality of the generated image, and improves the robustness of the model sample image generated by the GAN neural network.
[0141] In a specific embodiment, the method further includes: after obtaining the fourth discriminant loss, performing back propagation training on the generator. Based on this, as a specific implementation of an embodiment of the present invention, the specific process of training the generator based on the above step S103 may include:
[0142] Fix the discriminator and combine the generator and the discriminator for training;
[0143] Reset the generator gradient;
[0144] Input the model sample image into the discriminator to obtain the fourth output matrix, and use the corresponding fourth truth matrix GT_G to calculate the fourth discriminant loss LossG; since it is hoped that the discriminator's judgment on the generated image is true at this time, the fourth output matrix obtained by the discriminator at this time is the probability matrix of the judgment being true;
[0145] Backpropagate the generator;
[0146] Update the generator parameters according to the fourth discriminant loss LossG to obtain the trained generator.
[0147] In the embodiment of the present invention, the step of saving the model sample images whose similarity with the target image meets the preset requirements as described in the above step S104 specifically includes:
[0148] Determine whether the similarity between the model sample image and the target image reaches a preset threshold;
[0149] If yes, save the model sample image;
[0150] If not, the model sample image is discarded.
[0151] In the embodiment of the present invention, the similarity between the model sample image and the target image can be determined by judging the Frechet Inception Distance (FID) value between the two. Other feature vector or hash table comparison methods can also be used. Of course, other methods for implementing image similarity comparison recorded in the prior art can also be used. The specific implementation process can refer to the detailed description of the prior art, which will not be repeated here.
[0152] In an embodiment of the present invention, when it is determined according to the above step S105 that the number of all saved model sample images does not reach a preset threshold and it is necessary to repeat the above steps of obtaining model sample images, training the discriminator and the generator, multiple reference images can be randomly screened again from the above multiple reference candidate images.
[0153] Embodiment 2
[0154] Based on the same inventive concept, the embodiment of the present invention further provides a sample image generating device, referring to Figure 5 As shown, the device comprises:
[0155] A generation module 101 is used to select multiple reference images from a preset sample database based on the acquired target image, and obtain a model sample image based on a pre-built generator;
[0156] A discriminator training module 102, used to input the target image, the reference image and the model sample image into the discriminator corresponding to the generator respectively, and train the discriminator according to the obtained first discriminant loss, second discriminant loss and third discriminant loss;
[0157] A generator training module 103, used for inputting the model sample images into the trained discriminator, and training the generator according to the obtained output results;
[0158] A saving module 104 is used to save model sample images whose similarity with the target image meets preset requirements;
[0159] The judgment module 105 is used to judge whether the number of all the saved model sample images reaches a preset threshold.
[0160] Embodiment 3
[0161] Based on the same inventive concept, an embodiment of the present invention further provides a computer-readable storage medium on which a computer program is stored. When the program is executed by a processor, the sample image generation method described in the above embodiment 1 is implemented.
[0162] Embodiment 4
[0163] Based on the same inventive concept, an embodiment of the present invention also provides a computer device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein when the processor executes the computer program, the sample image generation method described in the above-mentioned embodiment 1 is implemented.
[0164] Those skilled in the art will appreciate that embodiments of the present invention may be provided as methods, systems, or computer program products. Therefore, the present invention may take the form of a complete hardware embodiment, a complete software embodiment, or an embodiment combining software and hardware. Moreover, the present invention may take the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage and optical storage, etc.) containing computer-usable program code.
[0165] The present invention is described with reference to flowcharts and / or block diagrams of methods, devices (systems), and computer program products according to embodiments of the present invention. It should be understood that each process and / or block in the flowchart and / or block diagram, as well as the combination of processes and / or blocks in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to produce a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.
[0166] These computer program instructions may also be stored in a computer-readable memory capable of directing a computer or other programmable data processing device to operate in a specific manner, so that the instructions stored in the computer-readable memory produce an article of manufacture comprising an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.
[0167] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operating steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing instructions for implementing the process. Figure 1A process or multiple processes and / or boxes Figure 1 The steps for the functions specified in one or more boxes.
[0168] Obviously, those skilled in the art can make various changes and modifications to the present invention without departing from the spirit and scope of the present invention. Thus, if these modifications and variations of the present invention fall within the scope of the claims of the present invention and their equivalents, the present invention is also intended to include these modifications and variations.
Claims
1. A sample image generation method, characterized in that: include: Based on the acquired target image, multiple reference images are screened from a preset sample database, and a model sample image is obtained based on a pre-built generator; Inputting the target image, the reference image and the model sample image into the discriminator corresponding to the generator respectively, and training the discriminator according to the obtained first discriminant loss, second discriminant loss and third discriminant loss; Input the model sample image into the trained discriminator, and train the generator according to the obtained output result; Saving model sample images whose similarity with the target image meets preset requirements; Determine whether the number of all saved model sample images reaches a preset threshold. If not, repeat the above steps of obtaining model sample images, training the discriminator and the generator.
2. The method according to claim 1, characterized in that The first discrimination loss, the second discrimination loss and the third discrimination loss are obtained by the following method, including: Inputting the target image into the discriminator to obtain a first output matrix, and obtaining a first discriminant loss according to the first output matrix and a preset first true value matrix; Inputting the reference image into the discriminator to obtain a second output matrix, and obtaining a second discriminant loss according to the second output matrix and a preset second true value matrix; The model sample image is input into the discriminator to obtain a third output matrix, and a third discriminant loss is obtained according to the third output matrix and a preset third true value matrix.
3. The method according to claim 2, characterized in that Training the discriminator according to the first discriminant loss, the second discriminant loss and the third discriminant loss includes: Calculate the discriminant loss result of the discriminator according to the first discriminant loss, the second discriminant loss and the third discriminant loss; The discriminator is trained according to the discriminant loss result to obtain a trained discriminator.
4. The method according to claim 3, characterized in that The step of inputting the model sample image into the trained discriminator and training the generator according to the obtained output result comprises: Input the model sample image into the trained discriminator to obtain a fourth output matrix, obtain a fourth discriminant loss based on the fourth output matrix and a preset fourth truth matrix, and update the generator based on the fourth discriminant loss to obtain a trained generator.
5. The method according to claim 1, characterized in that Based on the acquired target image, multiple reference images are screened from the preset sample database, including: A target feature vector of the target image is obtained, and the target feature vector is compared with images in the sample database for similarity, so as to screen and obtain the multiple reference images.
6. The method according to claim 5, characterized in that The step of obtaining a target feature vector of the target image, comparing the target image with images in the sample database for similarity, and selecting the multiple reference images includes: Obtaining a target feature vector of the target image, comparing the target feature vector with images in the sample database for similarity, and screening to obtain a plurality of reference candidate images; The multiple reference pictures are obtained by randomly selecting from the multiple reference candidate pictures.
7. The method according to claim 5, characterized in that Based on the pre-built generator, the model sample image is obtained in the following manner, including: Constructing a model data pair with the target image and each reference image, inputting the reference image of the model data pair into the encoder of the generator for feature extraction, and obtaining a reference image feature vector; Inputting the reference picture feature vector and the target feature vector into the attention module of the generator for calculation to obtain an attention feature vector; The attention feature vector is input into the decoder of the generator for processing to obtain the model sample image.
8. The method according to claim 5, characterized in that When repeatedly executing the above steps of obtaining the model sample image, training the discriminator and the generator, a plurality of reference images are randomly screened again from the plurality of reference candidate images.
9. The method according to claim 1, characterized in that The step of storing the model sample images whose similarity with the target image meets the preset requirements includes: Determine whether the similarity between the model sample image and the target image reaches a preset threshold; If yes, the model sample image is saved.
10. A sample image generating device, characterized in that: include: A generation module, used to screen multiple reference images from a preset sample database based on the acquired target image, and obtain a model sample image based on a pre-built generator; A discriminator training module, used to input the target image, the reference image and the model sample image into the discriminator corresponding to the generator respectively, and train the discriminator according to the obtained first discriminant loss, second discriminant loss and third discriminant loss; A generator training module, used for inputting the model sample images into the trained discriminator, and training the generator according to the obtained output results; A saving module, used to save model sample images whose similarity with the target image meets preset requirements; The judgment module is used to judge whether the number of all saved model sample images reaches a preset threshold.
11. A computer-readable storage medium having a computer program stored thereon, wherein when the program is executed by a processor, the sample image generation method according to any one of claims 1 to 9 is implemented.
12. A computer device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the sample image generation method according to any one of claims 1 to 9 when executing the computer program.
Citation Information
Patent Citations
Defect judging device defect judging method
CN104952766A
Robot scheduling method and device, electronic equipment and storage medium
CN111340286A
Road arrow picture generation method and system based on adversarial network
CN113780068A
Image animation method based on cascade generative adversarial network
CN114140317A
Image processing method and device, equipment and storage medium
CN114998483A
