Cross-modal text-to-image generation method based on generative adversarial networks
By introducing adversarial learning and semantic distance measurement in the regeneration module of the adversarial generation network, the text-to-image generation method is optimized, which solves the problem of insufficient semantic consistency between the generated pictures and the text in the existing technology, and significantly improves the semantic consistency of the generated pictures. performance and quality.
Patent Information
- Application Number
- CN202111271415.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-10-29
- Publication Date
- 2024-10-18
- Estimated Expiration
- 2041-10-29
AI Technical Summary
Existing text-to-image generation methods have shortcomings in ensuring the semantic consistency between generated images and text. Conventional regeneration networks may lead to inaccurate optimization distances, and the discriminator structure ignores the semantic consistency between images.
Adversarial learning is introduced in the regeneration module of the adversarial generative network. Through semantic distance metric optimization, text sentence vectors are extracted and combined with a deep semantic fusion generator and a Top-Down reverse generation model to optimize the generated images to improve semantic consistency.
It effectively improves the semantic consistency performance in text generation image tasks. The semantic correlation between the generated pictures and text descriptions is better, and the effect of optimizing defective pictures is significantly improved.
Smart Images

Figure CN114329025B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of computer image generation, and in particular to a cross-modal text-to-image generation method based on a generative adversarial network. Background Art
[0002] With the development of information technology and the application of multimedia technology, the information we receive and the experience of the world have gradually become multimodal. When we see an object, we will think of the name of the object. Visual information and text information are experienced by us at the same time. Multimodal machine learning aims to build models that can process and associate information from multiple modes. This is an increasingly important and vibrant field with great potential. Generating realistic images that match a given text description (text-to-image) in this field is one of the multimodal tasks. This task has good application prospects and has great development potential in image editing, video editing, user personalized generation, personalized recommendation and other fields. Due to the success of generative adversarial networks (GANs) in generating realistic images, text-to-image generation has made significant progress. Text-to-image generation requires a deep understanding of the object being created, whether it is a single type of object or an event involving various people. It requires computers to understand the semantic information of text and images in different modes and ensure that the generated images have good consistency with the corresponding text. Automatic image generation can help design work. In the future, algorithms for customized images and videos may replace image and video search engines or simple image design modification software to respond to the personal preferences of each user. Compared with image description, the information contained in images is more complex, so the task of generating images was proposed later than image description, but it has also made significant progress.
[0003] In the present invention, the training set and the test set are from the MSCOCO2014 dataset and the CUB2011 bird dataset, each MSCOCO image corresponds to 5 descriptions, and each CUB image corresponds to 10 descriptions. At present, the research on text-to-image generation uses a symmetrical regeneration network to ensure that the regenerated text retains the semantic consistency with the original image. However, this method may lead to inaccurate optimization distance when optimizing defective images, thereby misleading the generator to generate images whose semantic meaning is inconsistent with the original text. In addition, the conventional discriminator structure is often aimed at fitting the image distribution, ignoring the semantic consistency between the image pairs.
[0004] The main technical problem to be solved by the present invention is: how to use adversarial learning and semantic distance measurement to ensure better semantic consistency in the task of generating images from text, that is, to find a good semantic association between the generated image and the corresponding description text. Summary of the invention
[0005] In order to overcome the shortcomings of the above-mentioned prior art, the present invention provides a cross-modal text-to-image generation method based on an adversarial generative network, which improves the effect of optimizing defective images by introducing adversarial learning in the regeneration module; in addition, semantic distance metric optimization is used to ensure the semantic consistency between image pairs, and the generated images have better semantic consistency performance.
[0006] The technical solution adopted by the present invention is:
[0007] A cross-modal text-to-image generation method based on a generative adversarial network is characterized by comprising the following steps:
[0008] S100. Extract sentence vector of text:
[0009] The text is input into the collaborative attention encoder and the BERT pre-trained encoder for sentence-level feature extraction, and the collaborative attention sentence-level feature vector S1 and the pre-trained BERT sentence-level feature vector s2 are obtained respectively;
[0010] S200. Linearly optimize the collaborative attention sentence-level feature vector s1 and the pre-trained BERT sentence-level feature vector S2, and optimize the sentence-level feature vector S1 and the sentence-level feature vector S2 obtained in step S100 to optimize the text sentence vector S t , assuming that the linear coefficient λ1 related to the collaborative attention sentence-level feature vector S1, the linear coefficient of the pre-trained BERT sentence-level feature vector S2 is λ2, and linear optimization is performed to obtain the optimized text sentence vector S t :
[0011] S1=TextEncoder(X)
[0012] S2=Bert(T)
[0013] S t =λ1*S1+λ2*S2
[0014] S300. The linear text sentence vector S of step S200 is t Together with random noise Z, it is input into the deep semantic fusion generator to generate an image, and the generated image is negatively correlated with the Top-Down reverse generation model.
[0015] Sample sentence-level feature vector S n ;
[0016] S400. Generate a positive sample sentence feature vector S from the real image through the Top-Down reverse generation model p ; S500. The negative sample sentence-level feature vector S generated in step S300 nand the positive sample sentence feature vector S generated in step S400 p , the optimized text sentence vector S formed in step S200 t Form an adversarial network and conduct adversarial training. The specific training steps are as follows:
[0017] S501. Define the negative sample sentence-level feature vector S n and optimize the text sentence vector S t The score function of the semantic distance between n ,S t )=L1, positive sample sentence feature vector S p and optimize the text sentence vector S t The score function L(S p ,S t )=L2, then:
[0018]
[0019] Where: C sent is a sentence encoder for extracting the global sentence feature vector, where the positive sample sentence feature vector S is p And the negative sample sentence-level feature vector S n , τ is a hyperparameter;
[0020] S502. Use the score function of step S501 to train the negative sample sentence-level feature vector Sn and the positive sample sentence feature vector S respectively p :
[0021] When the value of L1 approaches 1 and the score value no longer increases, and the value of L2 approaches 0 and the score value no longer decreases, an optimized image that meets the text description is generated.
[0022] Preferably, step S502 is to train the negative sample sentence-level feature vector S n If the value of L1 does not reach the predetermined target, the negative sample sentence-level feature vector S n By calculating the loss function L D Generate an image again, and the generated image is again passed through the Top-Down reverse generation model and the negative sample sentence-level feature vector S n 'Train repeatedly, and repeat this cycle until the image generation meets the image generation conditions of step S502.
[0023] Preferably, when generating the optimized image in step S502, Faster-RCNN and a pre-trained VGG-16 network are used to extract image features from the generated image and the real image generated by the deep semantic fuser, respectively, and the matching score L3 between the image descriptions is performed:
[0024]
[0025] L img =|f(G(z i ,si))-f(x i )|2
[0026] where x i is a real image from the dataset, G(z i· s i ) is used to generate images, and the distance between images is the Euclidean distance L img to measure;
[0027] When the value of L3 approaches 0 and the score no longer decreases, a picture that matches the text description is generated. Otherwise, the acquired image features are calculated using the loss function and input into the deep semantic fusion generator to generate the picture again, and then the image feature matching is repeated.
[0028] Preferably, for a real image x i And generate the image G(z i ,s i )) and the real text S t , positive sample sentence feature vector S p and optimize the text sentence vector S t The following objective optimization function V(φ,θ) is used for optimization:
[0029]
[0030] Where: x i is a real image from the dataset, G(z i ,s i ) is used to generate the image.
[0031] Preferably, in order to better calculate the gap between text features, in order to make the positive sample text features and S t Closer to the negative sample sentence-level feature vector S n and is further away from the positive sample sentence feature vector S p, Use the following Euclidean distance L θ , L φ To determine:
[0032] L θ =|f(G(z i ,s i ))-f(x i )|2;
[0033]
[0034] L θ , Lφ They are the generated image G(zi,si) and the real image x i The Euclidean distance between text vectors and the Euclidean distance between image feature vectors of the dataset.
[0035] Preferably, the loss function L D The calculation formula is:
[0036]
[0037] in To optimize the text sentence vector S t and the positive sample sentence feature vector S p Data pairs;
[0038] E s~C(G(z)) To optimize the text sentence vector S t and the negative sample sentence-level feature vector S n Data pairs;
[0039] A data pair of image features of a generated image and image features of a real image;
[0040] L(S p , S t ) is the optimized text sentence vector S t And the positive sample sentence feature vector S generated in reverse p The distance metric of
[0041] L(S n , S t ) is the optimized text sentence vector St and the reverse generated negative sample sentence level feature vector S n The distance metric of
[0042] L img (X,X real ) is the semantic distance between the generated image and the real image, where X is the generated real image, X real are real pictures in the dataset; λ1, λ2, and λ3 are all hyperparameters.
[0043] Preferably, the collaborative attention encoder for converting text into sentence-level features in step S100 is
[0044] Pre-trained text encoder for AttnGAN.
[0045] Preferably, when performing semantic discrimination in step S502, it is determined whether the generated image text and the original image are reversed.
[0046] The distance between the text after the text L y Is it close to 0?
[0047] Ly=min θ L θ =|f(G(zi,si))-f(x i )|2
[0048] Among them: θ is to distinguish the difference between the distance between images and the distance between texts, which refers to the semantic distance between images, and x i is a real picture, G(zi,si) is the picture generated by the deep semantic fuser, and L θ is the Euclidean distance.
[0049] Preferably, the real pictures obtained in step S400 are from the MSCOC02014 dataset and the CUB2011 bird dataset, each COC0 picture corresponds to 5 descriptions, and each CUB picture corresponds to 10 descriptions.
[0050] Compared with the prior art, the present invention has the following beneficial effects:
[0051] The present invention is based on a cross-modal text-to-image generation method based on a generative adversarial network. It introduces adversarial learning into the regeneration module of the GAN network, proposes semantic distance metric learning based on the regeneration module of the adversarial network, and ultimately effectively improves the semantic consistency between the original text and the generated image in the text-to-image task. By calculating and optimizing the semantic distance between different text pairs and image pairs and optimizing them separately, the quality and diversity of image generation are effectively improved.
[0052] The generation method of the invention improves the effect of optimizing defective images by introducing adversarial learning in the regeneration module; in addition, semantic distance metric optimization is used to ensure the semantic consistency between image pairs, and the generated images have better semantic consistency performance. BRIEF DESCRIPTION OF THE DRAWINGS
[0053] Figure 1 A flowchart of an embodiment of a cross-modal text-to-image generation method based on a generative adversarial network;
[0054] Figure 2 A flowchart of another embodiment of a cross-modal text-to-image generation method based on a generative adversarial network;
[0055] Figure 3 The structural diagram of the image generation module and the re-description module;
[0056] Figure 4 An embodiment of sample pictures generated from a set of CUB datasets using the cross-modal text-to-image generation method of the present invention;
[0057] Figure 5Sample pictures generated from a set of MSCOCO datasets using the cross-modal text-to-image generation method of the present invention;
[0058] Figure 6 Comparison chart between the existing method and the image generated by the present invention;
[0059] Figure 7 Another set of sample pictures generated from a set of MSCOCO datasets using the cross-modal text-to-image generation method of the present invention;
[0060] Figure 8 The process of cross-modal text-to-image generation method based on generative adversarial networks;
[0061] Fig. 9 Flowchart S500 of a cross-modal text-to-image generation method based on a generative adversarial network. DETAILED DESCRIPTION
[0062] Embodiments of the present invention are described in detail below, examples of which are shown in the accompanying drawings, wherein the same or similar reference numerals throughout represent the same or similar elements or elements having the same or similar functions. The embodiments described below with reference to the accompanying drawings are exemplary and are only used to explain the present invention, and cannot be understood as limiting the present invention.
[0063] like Figure 1 and Figure 8 As shown, the cross-modal text-to-image generation method based on the adversarial generative network is characterized by comprising the following steps:
[0064] S100. Extract sentence vectors of text: In the text-to-image generation task, the first step that the model needs to do is often to understand the text content. In the adversarial generative network, existing work is to express the text by extracting sentence vectors and word vectors of the text, because sentence vectors have better feature representation than sentences themselves, and can find cross-modal relationships between text and images during training. The present invention uses a pre-trained text encoder based on collaborative attention and a large-scale pre-trained model to extract sentence vectors from text. The former is to extract semantic information more relevant to the MSCOCO dataset, and the latter enriches the details on this basis.
[0065] In this module, the image generation module input in the present invention is a random Gaussian distribution and a text sentence vector calculated by the following formula:
[0066] The text is input into the collaborative attention encoder and the BERT pre-trained encoder for sentence-level feature extraction, and the collaborative attention sentence-level feature vector S1 and the pre-trained BERT sentence-level feature vector S2 are obtained respectively; the sentence vector of the text is extracted using the collaborative attention text encoder and the pre-trained BERT model;
[0067] S200. Linearly optimize the collaborative attention sentence-level feature vector S1 and the pre-trained BERT sentence-level feature vector S2, and optimize the sentence-level feature vector S1 and the sentence-level feature vector S2 obtained in step S100 to the optimized text sentence vector S t , assuming that the linear coefficient λ1 associated with the collaborative attention sentence-level feature vector S1 and the linear coefficient of the pre-trained BERT sentence-level feature vector S2 is λ2, a linear optimization is performed to obtain the optimized text sentence vector S t :
[0068] S1=TextEncoder(X)
[0069] S2=Bert(T)
[0070] S t =λ1*S1+λ2*S2
[0071] The two parts of the sentence vectors are linearly added, and the parameters λ1 and λ2 can be set to 0.5 and 0.5 in this implementation. In addition, the present invention adopts a One-Stage generation-optimization structure. Compared with the common multi-layer generation model, the invention is more lightweight, but can also generate high-quality and diverse images. S300. Add the linear text sentence vector S of step S200 t Together with random noise Z, it is input into the deep semantic fusion generator to generate an image, and the generated image is reversely generated by the Top-Down model to generate a negative sample sentence-level feature vector S n Compared with the previous regeneration module, this invention uses a pre-trained Top-Down attentional LSTM to replace the previous regeneration network. In this description model, the input of each time step of LSTM includes the LSTM output of the previous time step, the average pooled image features, and the encoding corresponding to a previously generated word.
[0072] S400. Generate a positive sample sentence feature vector S from the real image through the Top-Down reverse generation model p ;
[0073] S500. The negative sample sentence-level feature vector S generated in step S300 is n and the positive sample sentence feature vector S generated in step S400 p , the optimized text sentence vector S formed in step S200 t Form an adversarial network and conduct adversarial training, combined with Figure 1 , Figure 8 and Fig. 9 As shown, the specific training steps are as follows:
[0074] S501. Define the negative sample sentence-level feature vector S n and optimize the text sentence vector S t The score function of the semantic distance between n , S t )=L1, positive sample sentence feature vector S p and optimize the text sentence vector S t The score function L(S p , S t )=L2, then:
[0075]
[0076]
[0077] Where: C sent The sentence encoder is used to extract the global sentence feature vector, where Sp is the positive sample sentence feature vector and Sn is the negative sample sentence-level feature vector, and τ is a hyperparameter;
[0078] S502. Use the score function of step S501 to train the negative sample sentence-level feature vector Sn and the positive sample sentence feature vector S respectively p :
[0079] When the value of L1 approaches 1 and the score value no longer increases, and the value of L2 approaches 0 and the score value no longer decreases, an optimized image that meets the text description is generated.
[0080] In the cross-modal text-to-image generation method based on a generative adversarial network, step S502 trains the sentence-level feature vector S of the negative sample n If the value of L1 does not reach the predetermined target, the negative sample sentence-level feature vector S n By calculating the loss function L D Generate the image again, and pass the generated image again
[0081] Top-Down reverse generation model and negative sample sentence-level feature vector S n 'Train repeatedly, and repeat this cycle until the image generation meets the image generation conditions of step S502.
[0082] from Figure 2 It can be seen from the embodiment that in the cross-modal text-to-image generation method based on the adversarial generative network, when generating the optimized image in step S502, it is necessary to consider the relationship between the generated image and the real image at the same time, and use Faster-RCNN and the pre-trained VGG-16 network to extract image features from the generated image generated by the deep semantic fuser and the real image respectively, and perform image description.
[0083] The matching score L3 between the above:
[0084]
[0085] L img =|f(G(z i ,si))-f(x i )|2;
[0086] where x i is a real image from the dataset, G(z i· s i ) is used to generate images, and the distance between images is the Euclidean distance L img To measure, use this distance to minimize the distance between the generated image and the real image pair, and supervise the generation of the image globally;
[0087] When the value of L3 approaches 0 and the score no longer decreases, a picture that conforms to the text description is generated. Otherwise, the acquired image features are calculated using the loss function and input into the deep semantic fusion generator to generate the picture again. Then, the image feature matching is repeated in a cycle. The image generated using this method can take into account both image features and text features, and can better express the semantic consistency of the input text.
[0088] from Figure 1 and Figure 2 As can be seen from the flowchart, after the sentence vector passes through the image generation model, we will get the real image and the generated image generated by the generator; considering the relationship between the original text description, the generated image synthetic text, and the real image synthetic text. We proposed an optimization method based on the relationship between the two images and the three texts: a cross-modal text-to-image generation method based on adversarial generative networks, for real images x i And generate the image G(z i ,s i )) and the real text S t , positive sample sentence feature vector S p and optimize the text sentence vector S t The following objective optimization function V(φ,θ) can also be used for optimization to calculate the difference between the real image features and the generated image features to ensure that the final generated image is more consistent with the text description of the input text and the real image:
[0089]
[0090] Where: x i is a real image from the dataset, G(z i ,s i ) is used to generate the image.
[0091] A cross-modal text-to-image generation method based on a generative adversarial network is used to better calculate the gap between text features and to make the positive sample text features and S t Closer to the negative sample sentence-level feature vector S n
[0092] and is further away from the positive sample sentence feature vector S p , using the following Euclidean distance L θ , L φ To determine:
[0093] L θ =|f(G(zi,si))-f(xi)|2;
[0094]
[0095] L θ , L φ Generate image G(zi,si) and real image x respectively i The Euclidean distance between the text vectors of the dataset and the Euclidean distance between the image feature vectors, L θ , L φ The generated image can be closer to the real image, and the text generated from the generated image should be farther from the original text. Even if the generator generates a defective image and generates a good text description, we will regard it as a negative sample, and the text generated from the real image will be regarded as a positive sample. We can use this to ensure that different images are distinguishable through the same backward network, so that the parameters passed back to the generator can always make the image tend to the real image, and the training will be more effective.
[0096] The cross-modal text-to-image generation method based on the adversarial generative network, the calculation formula of the loss function LD is: Apply several UPblocks to upsample the image features. UPBlock consists of an upsampling layer, a residual block and DFBlocks, which are used to fuse text and image features. Finally, the convolution layer is used to convert the image features into an image. Figure 3 In the re-description module shown, we apply a text-to-image loss function inspired by recent models proposed for unsupervised image generation and a contrastive loss to ensure that the generated images semantically reflect the original description text.
[0097]
[0098] in To optimize the text sentence vector S t and the positive sample sentence feature vector Sp Data pairs;
[0099] E s~C(G(z)) To optimize the text sentence vector S t and the negative sample sentence-level feature vector S n Data pairs;
[0100] A data pair of image features of a generated image and image features of a real image;
[0101] L(S p ,S t ) is the optimized text sentence vector S t And the positive sample sentence feature vector S generated in reverse p The distance metric of
[0102] L(S n ,S t ) is the optimized text sentence vector S t And the negative sample sentence-level feature vector S generated in reverse n The distance metric of
[0103] L img (X,X real ) is the semantic distance between the generated image and the real image, where X is the generated real image, X real are real pictures in the dataset; λ1, λ2, and λ3 are all hyperparameters.
[0104] In the cross-modal text-to-image generation method based on the generative adversarial network, the collaborative attention encoder that converts the text into sentence-level features in step S100 is a pre-trained text encoder of AttnGAN, which can well realize multi-stage and multi-modal image refinement, and lay a good data foundation for the subsequent adversarial network to provide a better sentence-level feature vector collaborative attention sentence-level feature vector S1.
[0105] In the cross-modal text-to-image generation method based on the adversarial generative network, step S502 determines whether the distance Ly between the generated image text and the original image after the reverse text is close to 0 when performing semantic discrimination, so that the re-description module generates text by reversely inputting the image, and maximizes / minimizes the distance between these positive sample / negative sample texts and the real text by comparison. The semantic distance optimization focuses more on generating images with consistent semantic content, rather than just determining whether the generated image distribution is close to the real image. This method can achieve better optimization in terms of image content:
[0106] min θ L θ =|f(G(zi,si))-f(x i )|2
[0107] Among them: θ is to distinguish the difference between the distance between images and the distance between texts, which refers to the semantic distance between images, x i is a real picture, G(zi,si) is the picture generated by the deep semantic fuser, and L θ is the Euclidean distance.
[0108] In the cross-modal text-to-image generation method based on the generative adversarial network, the real pictures obtained in step S400 are from the MSCOCO2014 dataset and the CUB2011 bird dataset. Each COCO picture corresponds to 5 descriptions and each CUB picture corresponds to 10 descriptions. Both can achieve good training effects and generate more consistent images. For specific embodiments, please refer to Figure 4 , Figure 5 and Figure 7 In each embodiment of the present invention, corresponding implementation effects can be seen.
[0109] The present invention is applicable to the data sources in CUB and MSCOCO2014 datasets. In order to evaluate the present invention, the present invention refers to the common practice of T2I and selects Inception Score (IS) reference and Frechet Inception Distance (FID) to evaluate the performance of our model. Specifically, Inception Score is based on the Inception Net-V3 network trained by Google. The quality and diversity of the generated images are determined by calculating the KL divergence. A higher IS means a higher quality of the synthesized image, and each image clearly belongs to a specific category.
[0110] FID calculates the difference between the real image distribution and the synthetic image distribution. It calculates the Frechet distance between the synthetic image and the real image distribution in the feature space of the pre-trained Inception v3 network. Lower FID means more realistic synthetic images. To calculate IS and FID, each model generates 40,000 images from randomly selected text descriptions in the test dataset.
[0111] Figure 5 The comparison of the IS and FID indicators of the invention with the existing model on two data sets shows that both FID and IS have been significantly improved. The image generation effect is also obviously more semantically relevant to the given text. For example, the generation of our model in the first column pays more attention to the difference between the snow and the sky. In the second column, our generation pays more attention to the semantic information of "pizza on the plate", and the generation of the semantics of "horses" in the last column is more consistent with its original semantics. Figure 6The comparison table shows that the two indicators for measuring image quality and diversity are that the IS indicator is as large as possible and the FID indicator is as small as possible. It can be seen that the overall indicators of the present invention are good.
[0112] The embodiments of the present invention disclose preferred embodiments, but are not limited thereto. A person skilled in the art can easily understand the spirit of the present invention based on the above embodiments and make different extensions and changes. However, as long as they do not deviate from the spirit of the present invention, they are all within the protection scope of the present invention.
Claims
1. A cross-modal text-to-image generation method based on a generative adversarial network, characterized by: The steps include: S100. Extract sentence vector of text: The text is input into the collaborative attention encoder and the BERT pre-trained encoder for sentence-level feature extraction, and the collaborative attention sentence-level feature vector S1 and the pre-trained BERT sentence-level feature vector S2 are obtained respectively; S200. Linearly optimize the collaborative attention sentence-level feature vector S1 and the pre-trained BERT sentence-level feature vector S2, and optimize the sentence-level feature vector S1 and the sentence-level feature vector S2 obtained in step S100 to the optimized text sentence vector S t , assuming that the linear coefficient λ1 related to the collaborative attention sentence-level feature vector S1, the linear coefficient of the pre-trained BERT sentence-level feature vector S2 is λ2, and linear optimization is performed to obtain the optimized text sentence vector S t : S1=TextEncoder(X) S2=Bert(T) S t =λ1*S1+λ2*S2 S300. The linear text sentence vector S of step S200 is t Together with random noise Z, it is input into the deep semantic fusion generator to generate an image, and the generated image is reversely generated by the Top-Down model to generate a negative sample sentence-level feature vector S n ; S400. Generate a positive sample sentence feature vector S from the real image through the Top-Down reverse generation model p ; S500. The negative sample sentence-level feature vector S generated in step S300 is n and the positive sample sentence feature vector S generated in step S400 p , the optimized text sentence vector S formed in step S200 t Form an adversarial network and conduct adversarial training. The specific training steps are as follows: S501. Define the negative sample sentence-level feature vector S n and optimize the text sentence vector S t The score function of the semantic distance between n ,S t )=L1, positive sample sentence feature vector S p and optimize text sentence vectors S t The score function L(S p ,S t )=L2, then: Where: C sent is a sentence encoder for extracting the global sentence feature vector, where they are the positive sample sentence feature vectors S p And the negative sample sentence-level feature vector S n , τ is a hyperparameter; S502. Use the score function of step S501 to train the negative sample sentence-level feature vector Sn and the positive sample sentence feature vector S respectively p : When the value of l1 approaches 1 and the score value no longer increases, and the value of l2 approaches 0 and the score value no longer decreases, an optimized image that meets the text description is generated; When generating the optimized image in step S502, Faster-RCNN and the pre-trained VGG-16 network are used to extract image features from the generated image and the real image generated by the deep semantic fuser, respectively, and the matching score L3 between the image descriptions is performed: L img =|f(G(z i ,s i ))-f(x i )|2 where x i is a real image from the dataset, G(z i .s i ) is used to generate images, and the distance between images is the Euclidean distance L img to measure; When the value of L3 approaches 0 and the score value no longer decreases, a picture that matches the text description is generated. Otherwise, the acquired image features are calculated using the loss function and input into the deep semantic fusion generator to generate the picture again, and then the image feature matching is repeated in a cycle. For real pictures x i And generate the image G(z i ,s i )) and the real text S t , positive sample sentence feature vector Sp and optimized text sentence vector S t The following objective optimization function is used To optimize: Where: x i is a real image from the dataset, G(z i ,s i ) is to generate an image; In order to better calculate the gap between text features, in order to make the positive sample text features and S t Closer to the negative sample sentence-level feature vector S n and is further away from the positive sample sentence feature vector S p , using the following Euclidean distance L θ , L φ To determine: L θ =|f(G(zi,si))-f(xi)|2; L θ , L φ They are the generated image G(zi,si) and the real image x i The Euclidean distance between the text vectors of the dataset and the Euclidean distance between the image feature vectors; The loss function L D The calculation formula is: in To optimize the text sentence vector S t and the positive sample sentence feature vector S p Data pairs; E s~C(G(z)) To optimize the text sentence vector S t and the negative sample sentence-level feature vector S n Data pairs; A data pair of image features of a generated image and image features of a real image; L(S p ,S t ) is the optimized text sentence vector S t And the positive sample sentence feature vector S generated in reverse p The distance metric of L(S n ,S t ) is the optimized text sentence vector S t And the negative sample sentence-level feature vector S generated in reverse n The distance metric of L img (X,X real ) is the semantic distance between the generated image and the real image, where X is the generated real image, X real are real pictures in the dataset; λ1, λ2, and λ3 are all hyperparameters.
2. The cross-modal text-to-image generation method based on a generative adversarial network according to claim 1, characterized in that: In step S502, when training the negative sample sentence-level feature vector Sn, if the value of L1 does not reach the predetermined target, the negative sample sentence-level feature vector Sn is regenerated into an image by calculating the loss function LD, and the generated image is again repeatedly trained with the negative sample sentence-level feature vector Sn' through the Top-Down reverse generation model, and this cycle is repeated until the image generation meets the image generation conditions of step S502.
3. The cross-modal text-to-image generation method based on a generative adversarial network according to claim 1, characterized in that: The collaborative attention encoder that converts text into sentence-level features in step S100 is a pre-trained text encoder of AttnGAN.
4. The cross-modal text-to-image generation method based on a generative adversarial network according to claim 3, characterized in that: Step S502 determines the distance L between the generated image text and the original image text after the reverse text is generated during semantic discrimination. y Is it close to 0? Ly=min θ L θ =|f(G(z i ,s i ))-f(x i )|2 Where: θ is the semantic distance between images, x i is a real picture, G(zi,si) is the picture generated by the deep semantic fuser, and L θ is the Euclidean distance.
5. The cross-modal text-to-image generation method based on a generative adversarial network according to claim 4, characterized in that: Step S400 obtains real pictures from the MSCOCO2014 dataset and the CUB2011 bird dataset. Each COCO picture corresponds to 5 descriptions, and each CUB picture corresponds to 10 descriptions.
Citation Information
Patent Citations
Social network cross-media search method based on adversarial learning and semantic similarity
CN110502743A
Video content replacement method and system based on adversarial generative network
CN110868598A
