Text-driven image generation method based on generative adversarial network
By using generative adversarial networks and bidirectional LSTM neural networks in text generation image technology, combined with the upsampling module and word-level optimization module, the shortcomings of the single-stage generation model in semantic consistency and diversity are solved, and high semantic consistency is achieved. and diverse image generation, improving the effect of text-driven image generation.
Patent Information
- Application Number
- CN202310719123.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-06-16
- Publication Date
- 2024-10-22
- Estimated Expiration
- Not applicable · inactive patent
AI Technical Summary
In the existing text generation image technology, the single-stage generation model is insufficient in semantic consistency and diversity, especially the inability to fully utilize text semantic information and bimodal information, resulting in insufficient semantic consistency and diversity of generated images.
Using a text-driven image generation method based on generative adversarial networks, by extracting keyword features of text information, combined with a bidirectional LSTM neural network and an upsampling module, a multi-layer perceptron and a word-level optimization module are used for feature embedding and optimization, and the generated image has high Semantic consistency and diversity in images.
It achieves image generation under given text conditions, improving the semantic consistency and diversity of images. Especially for text descriptions with characteristic colors, the generated images can accurately reflect key features, and quantitative analysis shows an improvement in IS scores. , the FID value is reduced, which proves the effectiveness of the method.
Smart Images

Figure CN116978039B_ABST
Abstract
Description
Technical Field
[0001] The present invention belongs to the technical field of computer vision, and relates to a text-driven image generation algorithm, and specifically to a text-driven image generation method based on a generative adversarial network. Background Art
[0002] With the continuous development of artificial intelligence technology, text-to-image technology has become a highly anticipated application field. Its background significance is not only to improve work efficiency and creation quality, but also to promote the development of fields such as computer vision and natural language processing, and bring us a broader imagination space.
[0003] Text-to-image generation aims to digitize the input text through deep learning encoding, and then use artificial intelligence related technologies to process it, and finally achieve the translation and generation task of the image. Text-to-image technology is a technology that can generate diverse images that can perfectly cover all descriptive features given a certain text with descriptive features. However, due to technical difficulties such as the uncertainty contained in the text itself and the fusion of multimodal information between text and image, it is still difficult to design a network model algorithm that can achieve this function.
[0004] In the task of generating images from text, traditional methods use a two-stage generative adversarial network and conduct research through multiple generator-discriminator pairs. Reference [1] (Zhang H, Xu T, Li H, et al. Stackgan: Text to photo-realistic image synthesis with stacked generative adversarial networks [C] / / Proceedings of the IEEE international conference on computer vision. 2017: 5907-5915.) first proposed a two-stage generative method to achieve the task of generating images from text. The first stage is to generate a relatively simple low-resolution image from text information. The result of this stage usually only includes relatively basic text features such as the overall layout of the image; the second stage is to correct the defects of the generated image by fusing the text information vector with the low-resolution image and stacking it, and then correct the defects of the generated image through a deeper convolutional network layer, thereby improving the details and quality. In addition, the conditional enhancement technology was proposed for the first time, laying a solid foundation for subsequent research methods on this task. Reference [2] (Zhang H, Xu T, Li H, et al. Stackgan++: Realistic image synthesis with stacked generative adversarial networks [J]. IEEE transactions on pattern analysis and machine intelligence, 2018, 41 (8): 1947-1962.) is based on reference [1] and designs multiple pairs of generative discriminator groups into a tree structure. The underlying features before the convolution of the generated image are used to replace the previously generated image as the input of the next stage, which directly enhances the stability of the network structure from a structural perspective. Both methods have preliminarily achieved the requirements of the text-to-image task, but because they simply consider the corresponding conditional loss, there are still major problems in the semantic consistency of text images.
[0005] Reference [3] (Xu T, Zhang P, Huang Q, et al. Attngan: Fine-grained text to image generation with attentional generative adversarial networks [C] / / Proceedings of the IEEE conference on computer vision and pattern recognition. 2018: 1316-1324.) first applied the attention mechanism that can fully reflect human will to the task of generating images from text. The model encodes text into word vectors and sentence vectors. While using sentence vectors to generate images based on StackGAN, it uses word vectors as key-value pairs of the attention mechanism to generate attention maps to increase the proportion of generated images consistent with word vectors, thereby making the generated images more related to word vectors. At the same time, the DAMSM model was proposed for the first time, which played a good supervisory role in the training of encoding features for training the generator. MCAGAN (Sun J, Zhang B. MCA-GAN: Text-to-Image Generation Adversarial Network Based on Multi-Channel Attention [C] / / 2019 IEEE 4th Advanced Information Technology, Electronic and Automation Control Conference (IAEAC). IEEE, 2019, 1: 1845-1849.) adds a multi-channel attention mechanism to provide the model with a larger receptive field, aiming to enhance the specific semantic response ability of the channel by modeling the correlation between channels. Explore the use of a larger generation space to achieve richer synthesis by building multiple intermediate generations to generate fine-grained images. MirrorGAN (Qiao T, Zhang J, Xu D, et al. MirrorGAN: Learning Text-to-image Generation by Redescription[C] / / 2019IEEE / CVF Conference on Computer Vision and Pattern Recognition(CVPR). IEEE, 2019.) uses the idea of mirror loop. In the big framework, it is mainly divided into three parts: word meaning encoding, global local attention image generation, word meaning regeneration and alignment model. It can better ensure the semantic consistency in the text-to-image generation task through text reconstruction.In the image generation module, not only the local attention mechanism in AttnGAN is used, but also the sentence vector is used as the key-value pair of the global attention mechanism to ensure the overall quality of the image. DCFGAN (Tao M, Wu S, Zhang X, et al. DCFGAN: Dynamic Convolutional Fusion Generative Adversarial Network for Text-to-Image Synthesis [C] / / 2020 IEEE International Conference on Information Technology, Big Data and Artificial Intelligence (ICIBA). IEEE, 2020, 1: 1250-1254.) introduces the transformer structure and uses the multi-head attention mechanism to extract key word-level information and summarize it to generate a better global sentence vector. The article also proposes a dynamic convolution fusion block DCFB module, which generates different convolution layer parameters according to different texts to help the generator generate images that are closer to the text information. Reference [7] (Yin G, Liu B, Sheng L, et al. Semantics disentangling for text-to-image generation [C] / / Proceedings of the IEEE / CVF conference on computer vision and pattern recognition. 2019: 2327-2336.) Based on the principle of word meaning decomposition, the decomposed semantics are conditionally normalized so that different languages for the same image can generate similar images according to the established purpose. At the same time, different text semantics are learned by using the doublet mechanism in the discriminator, so that it can eventually adapt to a series of problems caused by the diversity of text. Zhu et al. (Zhu M, Pan P, Chen W, et al. Dm-gan: Dynamic memory generative adversarial networks for text-to-image synthesis [C] / / Proceedings of the IEEE / CVF conference on computer vision and pattern recognition. 2019: 5802-5810.) proposed a dynamic memory model. This paper decomposes the up- and down-sampling process into multiple up- and down-sampling blocks, and proposes a memory storage-based model for the first time.This module mainly introduces a variety of gate operations, among which the memory write gate is used to select keywords, and the response gate is used to adaptively fuse information. In order to train the generator faster, conditional enhancement loss is also added in this paper. Reference [9] (Ruan S, Zhang Y, Zhang K, et al. Dae-gan: Dynamic aspect-aware gan for text-to-image synthesis [C] / / Proceedings of the IEEE / CVF International Conference on Computer Vision. 2021: 13960-13969.) proposed a dynamic aspect-aware generative model to extract sentence, word, and keyword information from text information. Sentence vectors are used to generate images of general resolution in a general sense, and word and character information is used to form an attention distribution module, which generates images of higher resolution with more consistent semantics between text and image in multiple stages.
[0006] However, although there are many multi-stage generation methods in the text-to-image task, there are some problems with the generated images, such as the final effect depends largely on the initially generated image, the semantic consistency of the text and image is basically guaranteed by additional models such as DAMSM, and the fusion calculation is large. Therefore, the single-stage generation method is currently the main one, and its main feature is that it includes a pair of generators and discriminators. So far, there are several classic single-stage models.
[0007] Reed et al. (Reed S, Akata Z, Yan X, et al. Generative adversarial text to image synthesis [C] / / International conference on machine learning. PMLR, 2016: 1060-1069.) used GAN for the first time to perform the task of generating images from text. The article not only used the most original DCGAN model for experiments, but also made the more important contribution of proposing GAN-CLS, GAN-INT, and GAN-CLS-INT. On the one hand, by using a matching-aware discriminator to judge the two types of false samples, unreal images and real images that do not match the text description, the final generated model has a higher semantic consistency. On the other hand, by using manifold interpolation technology, the generated text data is more diversified, and the final generated model is more robust and stable. Reference
[11] (Tao M, Tang H, Wu S, et al. Df-gan: Deep fusion generative adversarial networks for text-to-image synthesis [J]. arXiv preprint arXiv: 2008.05865, 2020.) first proposed a classic single-stage generative model. Its main contributions are: (1) It proposed an innovative single-stage generative model that directly generates the final image without the entanglement coupling of different stages. (2) It proposed a new matching-aware discriminator, which consists of MAGP and a single output. It can enhance semantic consistency without introducing an additional network. In addition, it can output loss outputs with equal benefits directly, unlike the previous output of conditional loss and unconditional loss. (3) It proposed a new deep text-image fusion block DFBlock. This module mainly obtains conditional parameters through affine multi-layer perception technology and generates higher resolution images through conditional convolution. This method can make more full use of text information, improve the diversity of visual features, and is conducive to generating semantically consistent images from different texts.DTGAN (Zhang Z, Schomaker L.DTGAN:Dual attention generative adversarial networks for text-to-image generation[C] / / 2021International Joint Conference on Neural Networks(IJCNN).IEEE,2021:1-8.) added an attention mechanism to a single-stage model for the first time, and optimized the experimental generation results through conditional adaptive normalization.
[0008] Although there have been many similar studies in the past, there is no single-stage generative model that can fully utilize text semantic information and study from both modalities at the same time. Summary of the invention
[0009] In order to solve the deficiencies in the prior art, the present invention provides a text-driven image generation method based on a generative adversarial network, which is jointly driven by text and image bimodal fields and has high semantic consistency and text semantic robustness.
[0010] The objective of the present invention is achieved through the following technical solutions:
[0011] A text-driven image generation method based on a generative adversarial network comprises the following steps:
[0012] Step (1) extracting keyword feature information of text information, encoding the input text through a bidirectional LSTM neural network to obtain relevant character, word, and sentence semantic feature vectors;
[0013] Step (2) generates random Gaussian input noise to add uncertainty to the model and serve as the initial input vector of the generator network, which is then input into the fully connected layer to form the initial feature mapping vector X1;
[0014] Step (3) inputs the semantic feature vectors of the characters, words and sentences obtained in step (1) into an upsampling module, wherein the upsampling module includes a feature embedding module and a character-level optimization module, wherein the feature embedding module includes a multi-layer perceptron and a word-level optimization module; after the sentence vector is subjected to conditional processing, the related conditional parameters (scaling parameter γ, shift parameter β) are extracted by the multi-layer perceptron, and then linearly mapped with the original input feature mapping vector, namely: in It represents the conditional input X c , the feature of the jth channel of the preceding input X1; γ j , β jIt represents the scaling and movement parameters of the key parameters in the jth channel. The conditional convolution and normalization of the feature vector are realized by performing convolution and normalization. Then, the obtained image feature vector and word vector are input into the word-level optimization module (the word-level optimization module includes the word-level channel attention module and the word-level pixel attention module), the image feature vector is optimized, and a new image feature vector is generated. Then, the image feature vector and the word vector are input into the word-level optimization module, and the optimization purpose is achieved through feature scanning, rewriting and feature reconstruction, and the image feature vector X'1 amplified by the first module is generated.
[0015] Step (4) Upsample X'1 to twice the original width and height, record the image feature vector as X2, and then input it into the upsampling module, repeat step (3) to generate a new image feature vector X'2;
[0016] Step (5) After repeating step (4) 5 times, the structure realizes the conversion of input noise into original image feature mapping vector X'7 through 7 upsampling modules with the same structure;
[0017] Step (6) converting the image feature mapping vector X'7 obtained in step (5) into a three-channel image feature vector output image through RGB convolution;
[0018] Step (7) inputs the image generated by step (6) into the discriminator to determine whether the image is true or false and whether the image and text are consistent.
[0019] A method for generating text-image dual-domain joint-driven images based on a generative adversarial network comprises the following steps:
[0020] Step (1) extracting keyword feature information of text information, encoding the input text through a bidirectional LSTM neural network to obtain relevant character, word, and sentence semantic feature vectors;
[0021] Step (2) generates random Gaussian input noise to add uncertainty to the model and serve as the initial input vector of the generator network, which is then input into the fully connected layer to form the initial feature mapping vector X1;
[0022] Step (3) inputs the semantic feature vectors of the characters, words and sentences obtained in step (1) into an upsampling module, wherein the upsampling module includes a feature embedding module and a character-level optimization module, wherein the feature embedding module includes a multi-layer perceptron and a word-level optimization module; after the sentence vector is subjected to conditional processing, the related conditional parameters (scaling parameter γ, shift parameter β) are extracted by the multi-layer perceptron, and then linearly mapped with the original input feature mapping vector, namely: in It represents the conditional input Xc , the feature of the jth channel of the preceding input X1; γ j , β j It represents the scaling and movement parameters of the key parameters in the jth channel. The conditional convolution and normalization of the feature vector are realized by performing convolution and normalization. Then, the obtained image feature vector and word vector are input into the word-level optimization module (the word-level optimization module includes a word-level channel attention module and a word-level pixel attention module. The word-level channel attention module adopts a word-level channel attention mechanism, and the word-level pixel attention module adopts a word-level pixel attention mechanism), the image feature vector is optimized, and a new image feature vector is generated. Then, the image feature vector and the word vector are input into the word-level optimization module, and the optimization purpose is achieved through feature scanning, rewriting and feature reconstruction, and the image feature vector X'1 amplified by the first module is generated.
[0023] Step (4) Upsample X'1 to twice the original width and height, record the image feature vector as X2, and then input it into the upsampling module, repeat step (3) to generate a new image feature vector X'2;
[0024] Step (5) After repeating step (4) 5 times, the structure realizes the conversion of input noise into original image feature mapping vector X'7 through 7 upsampling modules with the same structure;
[0025] Step (6) directly inputs the image feature mapping vector X'7 obtained in step (5) into the image autonomous optimization module for optimization, and then converts it into a three-channel image feature vector output image through RGB convolution;
[0026] Step (7) inputs the image generated by step (6) into the discriminator to determine whether the image is true or false and whether the image and text are consistent.
[0027] Compared with the prior art, the present invention has the following advantages:
[0028] Given a certain descriptive text, the present invention can not only make the generated image cover all the text description features, but also greatly improve the diversity of the generated image, and the semantic consistency of the text image is also strengthened. In particular, for text descriptions with characteristic colors, the corresponding generated images can always reflect the key features. In addition, the images generated by the two generator networks designed by the present invention can have higher brightness, contrast, and clarity. More importantly, based on the experimental results, the present invention is also compared with DFGAN through quantitative analysis. The results show that the IS score of the text-based domain-driven image algorithm in the present invention is increased by about 0.4, and the FID value is reduced by about 1.9; the IS score of the algorithm based on the joint driving of text and image dual fields is increased by about 0.3, and the FID value is reduced by about 2.6. BRIEF DESCRIPTION OF THE DRAWINGS
[0029] Figure 1 This is the overall framework diagram of the text-based domain-driven image algorithm;
[0030] Figure 2 This is the overall framework diagram of the image algorithm driven jointly by text and image fields;
[0031] Figure 3 For the keyword extraction process;
[0032] Figure 4 This is the UPBLOCK module structure diagram;
[0033] Figure 5 is the Word Meaning Channel Attention Module (WCAM);
[0034] Figure 6 is the Word Pixel Attention Module (WPAM);
[0035] Figure 7 It is the word-level optimization module (KOM);
[0036] Figure 8 This is the IROM structure diagram;
[0037] Fig. 9 This is the LSA network structure diagram;
[0038] Fig.10 This is the LCA network structure diagram;
[0039] Fig.11 This is the GSA network structure diagram;
[0040] Fig.12 This is the GCA network structure diagram;
[0041] Fig.13 Generate results for text-based domain-driven image algorithms;
[0042] Fig.14 The results of the diversity experiment;
[0043] Fig.15 These are the experimental results based on the dual-domain joint driving algorithm. DETAILED DESCRIPTION
[0044] The technical solution of the present invention is further described below in conjunction with the accompanying drawings, but is not limited thereto. Any modification or equivalent replacement of the technical solution of the present invention without departing from the spirit and scope of the technical solution of the present invention should be included in the protection scope of the present invention.
[0045] Based on the existing single-stage approach, this paper designs a text-driven image generator based on a generative adversarial network that can take into account both text and image domains and fully utilize text semantic information. The structure of the generator is as follows: Figure 1 and Figure 2 As shown in the figure, it mainly consists of the following three parts: (1) Text encoding module: extracts the multi-level semantic information of the text; (2) Upsampling module: realizes multimodal fusion and semantic embedding of the generated image, including word-level optimization module and character-level optimization module; (3) Image autonomous optimization module: realizes the smoothing of image pixels from the image perspective.
[0046] 1. Text encoding module
[0047] In the previous single-stage generation model, because it only considers sentence and word-level semantic information, the image generation process fails to fully utilize text features, which adds certain difficulties to the model training and even causes the final generated image to fail to fully cover all the semantic information required in the text information. Therefore, in order to make model training simpler and the semantic consistency of text images stronger, natural language processing is used in the encoding process to extract the key adjective-noun pairs mentioned in the text. The specific implementation example is Figure 3 Given a text, after sentence segmentation, part-of-speech tagging, rule classification and design of extraction rules, the corresponding keywords are obtained. The number of keywords used in the present invention is 5 (this value can be adjusted as appropriate according to the number of upsampling modules).
[0048] After semantic feature extraction, the text is encoded through the bidirectional LSTM (Bidirectional Long-Short Term Memory, Bi-LSTM) model. This is mainly because Bi-LSTM can achieve encoding results that are related to the input in chronological order and can fully utilize the input information in reverse chronological order. This feature coincides with the inherent property of the text that the meaning of the words itself is directly related to the context. The encoding process can be defined as:
[0049] s,w:=Bi_LSTM(T) (1)
[0050] k:=Bi_LSTM(K i ) (2) Where s, w, k are the encoded sentence, word, and character vectors respectively; T, K i They are input text and keywords extracted from the text respectively.
[0051] 2. Upsampling module
[0052] The single-stage text-driven image generation model is mainly based on the design of the upsampling module. The structure diagram is as follows: Figure 4 As shown in the figure. The structure of each module is exactly the same, and they are all output image features of the previous module. The sentence, word, and character semantic feature information extracted from the input text is used as input, and after being processed by the upsampling module for affine conditioning, conditional convolution, conditional normalization, activation, and word-level optimization modules, it is combined with the previous image feature f i-1 Add the residuals and finally output the fused image features where c i 、h i 、w i The number of channels, height and width of the image features generated for the i-th module are respectively. Since the present invention implements the text-driven image generation task, the first upsampling module is different from the other modules in two aspects. One is that the module does not perform upsampling; the second is that the input of the module is a virtual feature tensor of size 512×4×4 that is fully connected and reshaped by Gaussian noise. Two Embedding Blocks are included in the same upsampling module, which are exactly the same in composition structure, but slightly different in content. In order to fully extract the relevant information of the image in channels and space and improve the receptive field of word information in the optimization module, the present invention uses a word-level channel attention mechanism in the WOM (word-level optimization module) of Embedding Block 1, and a word-level pixel attention mechanism is used in Embedding Block 2.
[0053] In order to enhance the semantic robustness of text, a conditional augmentation module (Conditional Augmentation, hereinafter referred to as CA) is introduced. Since the space mapped to the text during the embedding process is a high-dimensional space (256 dimensions in the present invention), and the data exists in the high-dimensional space in the form of a manifold, this directly leads to the fact that in experiments with limited data volume, there will always be a situation where the data is discontinuous in the high-dimensional space manifold, which directly makes the model less robust. In addition, without loss of generality, a descriptive sentence can often correspond to different postures, styles and other features. The CA module can just be the most direct and simple to generate a large amount of relevant data for experimental use through a small amount of existing information. In the present invention, its actual role is to be able to generate more text embedding vectors that match real pictures, so that the model is more adaptable to the actual scene of one text to multiple images in real life, thereby satisfying the text semantic robustness required by the present invention in the experimental design. This module first places the sentence vector s in a fully connected layer (multi-layer perceptron MLP) to obtain the mean μ(s) and covariance Σ(s) of the text embedding sentence vector through the perception function, and then randomly samples from an independent Gaussian distribution Ν(μ(s),Σ(s)) to obtain a new conditional enhanced sentence vector s ca , use F ca To represent this process function, it can be written as:
[0054] s ca =F ca (s) (3)
[0055] In order to enhance the semantic consistency of text images, the present invention fully conditions the text sentence vector and finally realizes conditional convolution and conditional normalization. The most critical thing in the conditional processing process is to obtain the key parameters corresponding to the sentence meaning feature vector (including scaling parameter γ and shift parameter β). In the present invention, based on the experience of the paper, two multi-layer perceptron networks (MLP) are directly applied to process the conditional enhanced sentence vector s ca ,Through the autonomous perception function of the neural network, these two key parameters are extracted for subsequent conditioning.
[0056] In the entire upsampling structure, except for the first upsampling module that directly uses Gaussian distributed noise as input and does not perform upsampling, the output features of the previous module are used as the pre-order outputs of the remaining modules, denoted as Among them, B, C, H, and W are the batch size, number of channels, height, and width of the feature tensor respectively. Based on the advantage that bilinear upsampling can make pixels interpolated more smoothly during the upsampling process, thereby making the image more realistic, the image features of the previous output are bilinearly upsampled to expand the size of the input image features, which is called the previous input and is recorded as Then, after the conditional processing of the key parameters, the conditional input X is obtained. c In the whole processing process, channels are used as the basic unit for multiplication or addition. The process can be defined as:
[0057]
[0058] in It represents the conditional input X c 、Previous input X i The feature of the jth channel; γ j , β j It represents the scaling and movement parameters of the key parameters in the jth channel.
[0059] After obtaining the condition input, you can directly enter X for the condition c Convolution and normalization are performed in sequence to achieve conditional convolution and conditional normalization. Secondly, further collaborative processing is performed with the word-level optimization module (WOM) and the character-level optimization module (KOM) to enhance the utilization of text information.
[0060] 2.1 Word Level Optimization Module (WOM)
[0061] The module is mainly composed of two parts: word-level channel attention module and word-level pixel attention module. During use, the two modules play a role in embedding layer 1 and embedding layer 2 respectively. The implementation process of the word-level channel attention module (WCAM) is as follows: Figure 5 As shown in the figure, the image features generated by the previous network are processed by the global average pooling layer and the global maximum pooling layer to generate the feature vector convolution fusion as the query vector Q, and the text word embedding vector w is used as the input source of the key K and the value V. In the implementation process, for an image feature After the input is processed by the global average pooling layer and the global maximum pooling layer, the average pixel features of the image features in each channel can be extracted. Maximum pixel feature After stacking convolution, the final query vector Q is generated. The difference is that K and V are composed of After expanding the dimension, it is obtained through convolution, where the final generated After a series of vector dot products and softmax activation operations, the image feature attention distribution focused on by the text word embedding vector w can be obtained. Then, we continue to dot-product the obtained attention distribution (i.e., receptive field) with the value V to obtain the final attention weight. Finally, the obtained attention weight is multiplied and added with the original input image feature X through the residual idea, thereby realizing the semantic enhancement effect of this module.
[0062] The implementation process of the word-level pixel attention module (WPAM) is as follows Figure 6 As shown in Figure 2. Similar to the word-level channel attention module, this module also uses the image features and text word meaning embedding vector w generated by the previous network as the input source of the query vector Q, key K and value V. The difference is that in the implementation process, for an image feature After the input is processed by the spatial average pooling layer and the spatial maximum pooling layer, the extracted image feature vector is based on the average pixel feature of each pixel. Maximum pixel feature After stacked convolution, the final query vector Q is generated. The process of forming the key K and value V is similar to the above process. In the calculation process, the query vector is first dot-producted with the transposed key to generate the image feature attention distribution focused on by the text word embedding vector w. Then, the obtained attention distribution is multiplied by the value V to obtain the final attention weight Finally, the residual idea is used to multiply and add the original input image features X, thereby realizing the attention optimization of the image features at the pixel level, making the generated image smoother and more realistic.
[0063] 2.2 Word-level Optimization Module (KOM)
[0064] In order to strengthen the network model's collection of key information on text features and better adapt to the sensitivity of humans to key feature information in the real world, the present invention also specifically introduces a word-level optimization module. Unlike the word-level optimization module, this module uses a keyword feature vector that embeds the meaning of words from text information in the design of key K. The present invention first stacks the five keyword Ki (i=0~4) vectors obtained after processing through convolution, and after the autonomous weights are aggregated, the key K is finally generated through dimensionality expansion, convolution and other means. The input of the query vector Q and value V is still generated by the image features and text word meaning embedding vector w generated by the previous network. The implementation process of this module is mainly to first scan the image feature map (query vector Q) through the keyword information (key K) and find the attention distribution of concern. By enhancing the weight of the attention area and weakening the weight of the irrelevant range, the semantic feature w can modify and improve the image features according to the different needs of keyword information, and finally obtain the required attention weight. In addition, in order to further strengthen the role of keyword information in image generation results, this module also directly maps the keyword information to a fully connected state, and then adds it element by element with the image features by spatial reshaping and stacking, which ultimately produces a good effect. The implementation structure of this module is as follows: Figure 7 shown.
[0065] 3. Image autonomous optimization module
[0066] The main function of the image autonomous optimization module is to introduce a global-local spatial-channel attention mechanism from the perspective of the image itself, based on the two different receptive fields of the whole and the local, and the two different dimensions of space and channel, to smoothly optimize each pixel in the image features, so that the final generated image texture is clearer, and the image defects are improved while making the image more realistic. This module consists of Local Spatial Attention (LSA), Local Channel Attention (LCA), Global Spatial Attention (GSA), and Global Channel Attention (GCA). Its structure is shown in the figure below. Figure 8 shown.
[0067] 3.1 Local Spatial Attention Module (LSA)
[0068] The local spatial attention module mainly maps the channel dimension based on image features, aggregates pixel point sources from different channels by extracting features through convolution, and finally outputs a feature space with a channel number of 1 as the attention distribution generated by the local spatial attention mechanism. The design of this module adopts the idea of multiple convolution kernel sizes proposed in the Inception model to ensure that local spatial features of multiple sizes are extracted. Its structure is as follows Fig. 9 As shown. For an image feature tensor The input is firstly summarized and generalized through the convolution layer with a convolution kernel of 1×1 and the channels are compressed (in the present invention, due to the problem of computational complexity, the compression is adopted to 0.125 times of the original number of channels). Secondly, the obtained information is respectively input into the convolution layers with convolution kernels of 3×3, 5×5, and 7×7 to extract the relevant feature information of the image in different receptive field sizes. Finally, these four kinds of information are stacked in the channel dimension and input into the convolution layer with a convolution kernel of 1×1 again for compression and induction, and the attention distribution of the module is output.
[0069] 3.2 Local Channel Attention Module (LCA)
[0070] The local channel attention module maps the spatial dimensions based on image features, and finally obtains the relevant information parameters in different channels as the attention distribution generated by the local channel attention mechanism. The network structure diagram is shown in the figure Fig.10 As shown. Similarly, an image feature tensor Take the input of as an example, firstly, the mapping information of the feature map in each channel is extracted through the global maximum pooling layer and the global average pooling layer, then the two different information are compressed and amplified respectively and stacked, after the number of channels is restored to the original value through the two-dimensional convolution layer with a convolution kernel of 1×1, a one-dimensional convolution layer (Conv1d) with a convolution kernel size of 3 is used to summarize and improve the entire information, and finally the attention distribution of the module is output.
[0071] 3.3 Global Spatial Attention Module (GSA)
[0072] The global spatial attention module is based on the idea of self-attention mechanism and key-value pair attention mechanism. It maps from the spatial perspective to the channel dimension, and finally generates the global feature correlation coefficient of the image feature in each channel. The network structure diagram is as follows: Fig.11 As shown in the figure. Since the 2D convolution layer with a convolution kernel of 1×1 can reduce the computational complexity of the entire network and freely change the number of channels of each feature tensor when extracting features. Therefore, for an input feature of The tensor is first processed through three 2D convolutional layers with a kernel of 1×1 and then spatially reshaped to obtain the query vector Q, key K, and value V tensors. Secondly, the pairwise similarity between the two tensors is obtained by scanning the query vector using the key, and the spatial attention map is generated by activation processing through the Softmax function. Finally, the attention map is multiplied with the value V and the channel is restored to c again using a 2D convolutional layer with a kernel of 1×1 to obtain the final global spatial attention.
[0073] 3.4 Global Channel Attention Module (GCA)
[0074] The global channel attention module combines the ideas of non-local neural networks and one-dimensional convolutional layers with the attention mechanism to ultimately generate a feature map of image features between channels. The network structure is shown in the figure below. Fig.12 As shown. Since the one-dimensional convolution layer can realize a feature tensor After convolution, the width is modified as needed. Therefore, in order to extract the relevant features between channels, the spatial reshaping method is used to transpose the channels and widths before performing one-dimensional convolution. Consider an input feature of The tensor is first pooled through the global maximum pooling layer and the global average pooling layer for activation, and then stacked in the channel dimension and restored to a size of 1×1 through a two-dimensional convolution layer. The feature tensor of is used as the information source of the query vector Q and the key K. In order to realize the function of convolutional feature extraction of the channel, F t Reshape the space to size Then, the key vector K is used to scan the query vector Q to query the relevant perception area, and multiply it with the value V to finally obtain the global channel attention
[0075] However, relying solely on the model is not enough to maximize the advantages of the model. Since the present invention is a text-to-image algorithm driven by the dual fields of text and image, the loss function is designed to carry out fusion training from these two perspectives. The loss function of the present invention consists of the following parts:
[0076] (1) Generate adversarial loss function. As the core part of the entire loss function combination, it includes three possible situations in the training process: the image identification result is true (real), the identification result is false (fake), and the image and text do not match (mismatch). Therefore, the loss functions of the generator G and the discriminator D can be defined as:
[0077]
[0078] Where e represents the text sentence embedding information, z is the Gaussian noise of the initial input, and G(z) is the false image feature generated by the network.
[0079] (2) Matching-aware gradient penalty (MAGP) loss function. The discriminator based on this loss function was first proposed by DFGAN. It mainly smoothes the gradient around the actual real data, so that the data points generated by the network can converge to the specified position faster and better, and then synthesize images that match the text required by more tasks. Since this idea is mainly proposed to enable the discriminator to better identify the authenticity of the image, the loss function derived from it is also mainly used to optimize the discriminator, thereby indirectly optimizing the generator. The loss function can be defined as:
[0080]
[0081] where λ MA , p are two hyperparameters of the loss function. Since the discriminator is not the main content of the model design of this topic, we use the parameter value in DFGAN, that is, λ MA =2, p=6.
[0082] (3) DAMSM loss function. This loss function mainly uses the deep attention multi-module similarity model to calculate the pixel distance between the text semantic vector and the generated image in the latent space. The generator can minimize this loss to make the feature representation of the two in the latent space closer. The definition of the DAMSM loss function is as follows:
[0083]
[0084] in It represents the sum of the conditional probabilities of matching the corresponding word meaning information and sentence meaning information when the image is known; It represents the sum of the conditional probabilities of matching the corresponding image given the known word meaning information and sentence meaning information.
[0085] For M image-text matching pairs (Q, D), only when Di = Qi, the corresponding image and text can be matched. For T image-text matching pairs (C, E), only when C i =E i , the corresponding image part and word meaning information can be matched. It can be defined as:
[0086]
[0087] Where w refers to the word meaning information. Using a similar definition method, we can get
[0088] (4) KL loss function. In the conditional enhancement process, the input features are made more diverse by obtaining the mean and covariance matrix of the sentence features. Therefore, in order to prevent overfitting during the training process, KL loss is introduced, which is defined as follows:
[0089]
[0090] Where D KL It is the KL divergence, which is mainly used to indicate the KL distance between two distributions.
[0091] (5) Visual loss function. This function is based on the idea of mean absolute error. It calculates the error between the corresponding pixel points of the corresponding channel of the generated image and the real image, and then obtains the final loss by summing and averaging. The biggest advantage of this function is that it can make the pixel points far away from the real pixel converge quickly, and it has strong robustness. Its mathematical expression can be defined as:
[0092] L v =||I G -I R ||1 (13)
[0093] Where ||·||1 is the L1 norm, I G ,I R They represent generated image and real image respectively.
[0094] (6) SSIM loss function. SSIM (Structural Similarity Index Module) is an indicator used to measure the difference between the generated image and the original image in terms of image structure (including brightness, contrast, etc.). In this paper, this function is directly used as part of the loss required for model update, which can further guide and optimize the model during the training process. SSIM loss can be expressed as:
[0095] L SSIM (I G ,I R )=l(I G ,I R )·c(I G ,I R )·s(I G ,I R ) (14)
[0096] where l(·), c(·), and s(·) represent the loss in brightness, contrast, and structure between the image generated by the generator and the real image, respectively.
[0097] (7) VGG loss function. As an indicator for analyzing image semantic information, this function mainly extracts image features through a VGG network and then calculates the relevant loss. During the training process, the present invention solves the deficiency of image features at the pixel level by minimizing the VGG loss. The loss can be expressed as:
[0098]
[0099] where F i (·) represents the output features of the image after the i-th layer of the VGG network acts on it, and ||·||2 represents the L2 norm.
[0100] The image loss L is defined in the present invention as I for:
[0101] L I =λ v L v +λ VGG L VGG +λ SSIM L SSIM (16)
[0102] Among them, λ v , VGG, SSIM is the experimental hyperparameter.
[0103] In summary, the loss function of the network structure based on the text and image dual-domain joint driving algorithm can be defined as:
[0104]
[0105] Among them, L D is the total loss function of the discriminator D, L G is the total loss function of the generator G, is the generative adversarial loss function of the discriminator D, is the generative adversarial loss function of the generator G, L I is the image loss function, L MAGP is the MAGP loss function, L DAMSM is the DAMSM loss function, L KL is the KL loss function.
[0106] Example:
[0107] In this embodiment, there are two network inference processes, and the implementation flowcharts are as follows: Figure 1 and Figure 2 shown.
[0108] Since both implementations involved in this embodiment are single-stage generation, the subject steps are the same during the implementation process, with only one difference, namely, whether to add an image autonomous optimization module and an image-related loss function. The algorithm for image generation based on the joint drive of text and image dual domains specifically includes the following steps:
[0109] Step (1) Extracting text semantic features: Using natural language processing related methods to extract keyword feature information of text information, and then encoding the input text through a bidirectional LSTM neural network to obtain relevant character, word, and sentence semantic feature vectors.
[0110] Step (2) generates random Gaussian input noise to add uncertainty to the model and serve as the initial input vector of the network.
[0111] Step (3) inputs the semantic feature vectors of the characters, words and sentences obtained in step (1) into the upsampling module. Among them: after the sentence vector extracts the relevant conditional parameters through the multi-layer perceptron, the conditional convolution and conditional normalization of the feature vector are realized by the simplest and most direct method; the word vector is input into the corresponding word-level optimization module, and the image feature vector is optimized by two word-level optimization methods; the word vector is input into the word-level optimization module, and the optimization purpose is achieved by feature scanning, rewriting and feature reconstruction.
[0112] Step (4) converts the input noise into the original image feature mapping vector through 6 upsampling modules with the same structure.
[0113] Step (5) directly inputs the image feature mapping vector obtained in step (4) into the image autonomous optimization module for optimization, and then converts it into a three-channel image feature vector through RGB convolution to output the image.
[0114] Note: In the algorithm based on text-driven image generation, step (5) is changed to directly convert the image feature mapping vector obtained in step (4) into a three-channel image feature vector output image through RGB convolution.
[0115] This embodiment mainly carries out the text-driven image generation task from the dual fields of text and image. According to the experimental results, both the qualitative analysis of the experimentally generated images and the quantitative analysis of the corresponding evaluation indicators are carried out. The final experimental results show that this embodiment can not only make the generated images cover all the text description features, but also greatly improve the diversity of the generated images, and the semantic consistency of the text images is also strengthened.
[0116] (1) Relying only on text for single-domain driving
[0117] Without considering the relevant information of the image domain, the results of image generation driven by text domain are as follows: Fig.13 As shown. In the figure, 8 sentences of text covering different features are input, and finally 8 images with high text semantic consistency are output. Although the feature information covered by the input text has great differences in color, position, etc., the image generated by this embodiment can perfectly cover all the semantic information contained in the text to a large extent, especially for text descriptions with characteristic colors, the corresponding generated images can always reflect the key features. In addition, the clarity of the generated images has also been greatly improved.
[0118] In order to further verify the diversity of the generated results of the experimental model in this embodiment, during the research process, multiple experimental results generated by inputting the same text are as follows: Fig.14 The model proposed in this embodiment has high diversity. For the same sentence describing the features of white abdomen, chest and blue crown and neck, it is easy to generate images covering all the description features and with very different backgrounds. As shown in the figure, the environment includes mountains, tree trunks, grasslands, etc.
[0119] Moreover, in order to fully compare the experimental results of this embodiment with the results shown in the DFGAN paper, this embodiment not only performs a qualitative analysis through the above-mentioned image comparison method, but also performs a quantitative analysis of the experimental results by comparing the commonly used IS and FID indicators. The comparison results are shown in Table 1.
[0120] Table 1 Comparison of evaluation indicators
[0121]
[0122] Table 1 shows the evaluation indicators corresponding to the generated images based on the CUB and COCO datasets at 64-1 (32 channels), 64-2 (64 channels), 128, and 256. By analyzing the table, it can be concluded that for images of fixed size, the higher the number of channels, the greater the diversity of the generated images and the lower the FID index. For the CUB dataset, when the number of channels is the same, as the number of pixels of the generated images increases, the evaluation index IS of the generated images gradually increases and the FID gradually decreases.
[0123] (2) Dual-domain joint driving based on text and images
[0124] The experimental results based on the joint drive of the two fields are as follows: Fig.15 shown.
[0125] In the figure, three diversified images with different environmental factors covering all the descriptive features of five different texts are generated respectively. From the image results, it can be concluded that this embodiment can well complete the text-driven image generation algorithm, and its diversity and semantic consistency have been improved to a certain extent.
[0126] Similarly, in order to fully compare the experimental results of this embodiment with the results shown in the DFGAN paper, this embodiment quantitatively analyzes the experimental results by comparing the commonly used IS and FID indicators. The comparison results are shown in Table 2.
[0127] Table 2 Comparison of evaluation indicators
[0128]
[0129]
[0130] Table 2 shows the evaluation indicators corresponding to the generated images based on the CUB and COCO datasets at 64-1 (32 channels), 64-2 (64 channels), 64-3 (64 channels and no autonomous optimization model), 128, and 256. It is not difficult to see that for images of fixed size, the higher the number of channels, the greater the diversity of the generated images and the lower the FID index. For the CUB dataset, when the number of channels is the same, as the number of pixels of the generated image increases, the evaluation index IS of the generated image gradually increases and the FID gradually decreases. In addition, adding image field research methods to the text-driven image generation algorithm can greatly improve the diversity of the algorithm and the consistency of text semantics.
Claims
1. A text-driven image generation method based on generative adversarial networks, characterized in that The method comprises the following steps: Step (1) extracting keyword feature information of text information, encoding the input text through a bidirectional LSTM neural network to obtain relevant character, word, and sentence semantic feature vectors; Step (2) generates random Gaussian input noise to add uncertainty to the model and serve as the initial input vector of the generator network, which is then input into the fully connected layer to form the initial feature mapping vector X1; Step (3) inputs the semantic feature vectors of the characters, words and sentences obtained in step (1) into an upsampling module, wherein the upsampling module includes a feature embedding module and a character-level optimization module, wherein the feature embedding module includes a multi-layer perceptron and a word-level optimization module; after the sentence vector is subjected to conditional processing, the scaling parameter γ and the shift parameter β are extracted by the multi-layer perceptron, and then linearly mapped with the original input feature mapping vector, namely: in It represents the conditional input X c , the feature of the jth channel of the preceding input X1; γ j , β j It represents the scaling and movement parameters of the key parameters in the jth channel. The convolution and normalization are performed to realize the conditional convolution and conditional normalization of the feature vector; then the obtained image feature vector and word vector are input into the word-level optimization module to optimize the image feature vector and generate a new image feature vector; then the image feature vector and word vector are input into the word-level optimization module to realize the optimization purpose through feature scanning, rewriting and feature reconstruction, and generate the image feature vector X'1 amplified by the first module; The word-level optimization module includes a word-level channel attention module and a word-level pixel attention module; The implementation process of the word-level channel attention module is as follows: for an image feature The input of , where B, C, H, and W are the batch size, number of channels, height, and width of the feature tensor respectively. After being processed by the global average pooling layer and the global maximum pooling layer, the average pixel features of the image features in each channel can be extracted. Maximum pixel feature After stacking convolution, the final query vector Q is generated, and the key K and value V are the embedding vectors of the text meaning. After expanding the dimension, it is obtained through convolution, where the final generated After a series of vector dot products and softmax activation operations, the image feature attention distribution focused on by the text word embedding vector w is obtained. Then, the obtained attention distribution is dot-producted with the value V to obtain the final attention weight Finally, the obtained attention weight is multiplied by the original input image feature X through the residual idea and then added; The implementation process of the word-level pixel attention module is as follows: for an image feature After the input is processed by the spatial average pooling layer and the spatial maximum pooling layer, the extracted image feature vector is based on the average pixel feature of each pixel. Maximum pixel feature After stacked convolution, the final query vector Q is generated. In the calculation process, the query vector is first dot-producted with the transposed key K to generate the image feature attention distribution focused on by the text word embedding vector w. Then, the obtained attention distribution is multiplied by the value V to obtain the final attention weight Finally, the residual idea is used to multiply the obtained attention weight with the original input image feature X and then add them together; The process of implementing the word-level optimization module is as follows: first, scan the query vector Q through the key K and find the attention distribution of interest By enhancing the weight of the attention area and weakening the weight of the irrelevant range, the semantic feature w can modify the image features according to the different needs of keyword information, and finally obtain the required attention weight. Step (4) Upsample X'1 to twice the original width and height, record the image feature vector as X2, and then input it into the upsampling module, repeat step (3) to generate a new image feature vector X'2; Step (5) After repeating step (4) 5 times, the structure realizes the conversion of input noise into original image feature mapping vector X'7 through 7 upsampling modules with the same structure; Step (6) converting the image feature mapping vector X'7 obtained in step (5) into a three-channel image feature vector output image through RGB convolution; Step (7) inputs the image generated by step (6) into the discriminator to determine whether the image is true or false and whether the image and text are consistent.
2. The text-driven image generation method based on generative adversarial network according to claim 1 is characterized in that The encoding process is defined as: s,w:=Bi_LSTM(T) k:=Bi_LSTM(K i ) Among them, s, w, k are the encoded sentence, word, and character vectors respectively; T, K i They are input text and keywords extracted from the text respectively.
3. A method for generating text-image dual-domain joint-driven images based on a generative adversarial network, characterized in that The method comprises the following steps: Step (1) extracting keyword feature information of text information, encoding the input text through a bidirectional LSTM neural network to obtain relevant character, word, and sentence semantic feature vectors; Step (2) generates random Gaussian input noise to add uncertainty to the model and serve as the initial input vector of the generator network, which is then input into the fully connected layer to form the initial feature mapping vector X1; Step (3) inputs the semantic feature vectors of the characters, words and sentences obtained in step (1) into an upsampling module, wherein the upsampling module includes a feature embedding module and a character-level optimization module, wherein the feature embedding module includes a multi-layer perceptron and a word-level optimization module; after the sentence vector is subjected to conditional processing, the scaling parameter γ and the shift parameter β are extracted by the multi-layer perceptron, and then linearly mapped with the original input feature mapping vector, namely: in It represents the conditional input X c , the feature of the jth channel of the preceding input X1; γ j , β j It represents the scaling and movement parameters of the key parameters in the jth channel. The convolution and normalization are performed to realize the conditional convolution and conditional normalization of the feature vector; then the obtained image feature vector and word vector are input into the word-level optimization module to optimize the image feature vector and generate a new image feature vector; then the image feature vector and word vector are input into the word-level optimization module to realize the optimization purpose through feature scanning, rewriting and feature reconstruction, and generate the image feature vector X'1 amplified by the first module; The word-level optimization module includes a word-level channel attention module and a word-level pixel attention module; The implementation process of the word-level channel attention module is as follows: for an image feature The input of , where B, C, H, and W are the batch size, number of channels, height, and width of the feature tensor respectively. After being processed by the global average pooling layer and the global maximum pooling layer, the average pixel features of the image features in each channel can be extracted. Maximum pixel feature After stacking convolution, the final query vector Q is generated, and the key K and value V are the embedding vectors of the text meaning. After expanding the dimension, it is obtained through convolution, where the final generated After a series of vector dot products and softmax activation operations, the image feature attention distribution focused on by the text word embedding vector w is obtained. Then, the obtained attention distribution is dot-producted with the value V to obtain the final attention weight Finally, the obtained attention weight is multiplied by the original input image feature X through the residual idea and then added; The implementation process of the word-level pixel attention module is as follows: for an image feature After the input is processed by the spatial average pooling layer and the spatial maximum pooling layer, the extracted image feature vector is based on the average pixel feature of each pixel. Maximum pixel feature After stacked convolution, the final query vector Q is generated. In the calculation process, the query vector is first dot-producted with the transposed key K to generate the image feature attention distribution focused on by the text word embedding vector w. Then, the obtained attention distribution is multiplied by the value V to obtain the final attention weight Finally, the residual idea is used to multiply the obtained attention weight with the original input image feature X and then add them together; The process of implementing the word-level optimization module is as follows: first, scan the query vector Q through the key K and find the attention distribution of interest By enhancing the weight of the attention area and weakening the weight of the irrelevant range, the semantic feature w can modify the image features according to the different needs of keyword information, and finally obtain the required attention weight. Step (4) Upsample X'1 to twice the original width and height, record the image feature vector as X2, and then input it into the upsampling module, repeat step (3) to generate a new image feature vector X'2; Step (5) After repeating step (4) 5 times, the structure realizes the conversion of input noise into original image feature mapping vector X'7 through 7 upsampling modules with the same structure; Step (6) directly inputs the image feature mapping vector X'7 obtained in step (5) into the image autonomous optimization module for optimization, and then converts it into a three-channel image feature vector output image through RGB convolution; The image autonomous optimization module introduces a global-local space-channel attention mechanism from the perspective of the image itself. Based on the two different receptive fields of global and local, the module performs smooth optimization on each pixel in the image features in two different dimensions, space and channel. The module consists of local space attention, local channel attention, global space attention, and global channel attention. Step (7) inputs the image generated by step (6) into the discriminator to determine whether the image is true or false and whether the image and text are consistent.
4. The method for generating text-image dual-domain joint-driven images based on a generative adversarial network according to claim 3 is characterized in that The encoding process is defined as: s,w:=Bi_LSTM(T) k:=Bi_LSTM(K i ) Among them, s, w, k are the encoded sentence, word, and character vectors respectively; T, K i They are input text and keywords extracted from the text respectively.
5. The method for generating text-image dual-domain joint-driven images based on a generative adversarial network according to claim 3 is characterized in that The loss function of the network structure is defined as: Among them, L D is the total loss function of the discriminator D, L G is the total loss function of the generator G, is the generative adversarial loss function of the discriminator D, is the generative adversarial loss function of the generator G, L I is the image loss function, L MAGP is the MAGP loss function, L DAMSM is the DAMSM loss function, L KL is the KL loss function; Among them, λ MA , p are two hyper parameters of the loss function; in It represents the sum of the conditional probabilities of matching the corresponding word meaning information and sentence meaning information when the image is known; It represents the sum of the conditional probabilities of matching the corresponding image given the known word meaning information and sentence meaning information.
