Method and device for generating image from text, storage medium and electronic equipment
By obtaining the candidate keywords in the text description information and selecting the target text and image generation model, combined with the advantages of multiple candidate text and image generation models, more accurate images are generated, which solves the problem of insufficient accuracy of images generated by a single model and improves text quality. Accuracy of generated images.
Patent Information
- Application Number
- CN202310196619.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2023-03-02
- Publication Date
- 2024-09-03
AI Technical Summary
In the existing technology, the task of generating images from text based on a single model or a single method results in insufficient accuracy of generated images, it is difficult to quickly obtain an excellent model, and there is an error accumulation effect in the processing link.
By obtaining the candidate keywords in the text description information, based on the keywords associated with multiple candidate text and image generation models, the target text and image generation model is determined from the multiple candidate text and image generation models, and an image is generated based on the target model, combining different models advantages to improve image accuracy.
The target model is determined by the evaluation scores of multiple candidate text and image generation models, and images corresponding to more accurate text descriptions are generated, which improves the accuracy of image generation based on text description information and avoids the shortcomings of a single model.
Smart Images

Figure CN118587303A
Abstract
Description
Background Art
[0002] Text-to-image generation is to generate an image that matches the description of the text content for a given text. In the related art, a single method or a single model is used to generate the image corresponding to the text, and the accuracy of the generated image is low.
[0003] It should be noted that the information disclosed in the above background technology section is only used to enhance the understanding of the background of the present disclosure, and therefore may include information that does not constitute the prior art known to ordinary technicians in the field. Summary of the invention
[0004] The purpose of the present disclosure is to provide a method for generating an image from text, an apparatus for generating an image from text, a computer-readable medium and an electronic device, thereby improving the accuracy of images generated based on text at least to a certain extent.
[0005] According to a first aspect of the present disclosure, a method for generating an image from text is provided, comprising: obtaining candidate keywords in text description information; determining a target text-image generation model corresponding to the candidate keywords from a plurality of candidate text-image generation models based on keywords associated with the candidate text-image generation models; generating an image corresponding to the text description information based on the target text-image generation model; wherein, target text-image generation models corresponding to different keywords are selected in advance based on evaluation scores of images generated by the plurality of candidate text-image generation models for different keyword texts, so as to determine the keywords associated with each candidate text-image generation model.
[0006] According to a second aspect of the present disclosure, a device for generating an image from text is provided, comprising: a candidate keyword acquisition module, configured to acquire candidate keywords from text description information; a target text-image generation model determination module, configured to determine a target text-image generation model corresponding to the candidate keywords from a plurality of candidate text-image generation models according to the keywords associated with the plurality of candidate text-image generation models; an image generation module, configured to generate an image corresponding to the text description information based on the target text-image generation model; wherein the target text-image generation models corresponding to different keywords are selected in advance according to evaluation scores of images generated by the plurality of candidate text-image generation models for different keyword texts, so as to determine the keywords associated with each candidate text-image generation model.
[0007] According to a third aspect of the present disclosure, a computer-readable storage medium is provided, on which a computer program is stored. When the computer program is executed by a processor, the method for generating an image from text described in the first aspect is implemented.
[0008] According to a fourth aspect of the present disclosure, an electronic device is provided, characterized in that it includes: one or more processors; and a memory for storing one or more programs, which, when the one or more programs are executed by the one or more processors, enables the one or more processors to implement the method of generating images from text as described in the first aspect above.
[0009] According to a fifth aspect of the present disclosure, a computer program product comprising instructions is provided, which, when executed on a computer, enables the computer to execute the steps of the method for generating an image from text as described in the first aspect.
[0010] The technical solution disclosed in this disclosure has the following beneficial effects:
[0011] The present invention evaluates the scores of images generated for texts with different keywords through multiple candidate text-image generation models, and can determine, from the multiple candidate text-image generation models, a target text-image generation model used when generating images for texts including different keywords, so that the image corresponding to the text description information can be generated based on the keywords in the text description information in combination with the advantages of different models, so as to improve the accuracy of the image generated based on the text description information.
[0012] It is to be understood that the foregoing general description and the following detailed description are exemplary and explanatory only and are not restrictive of the present disclosure. BRIEF DESCRIPTION OF THE DRAWINGS
[0013] The drawings herein are incorporated into the specification and constitute a part of the specification, showing embodiments consistent with the present disclosure, and together with the specification, are used to explain the principles of the present disclosure. Obviously, the drawings described below are only some embodiments of the present disclosure, and for ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work. In the drawings:
[0014] Figure 1 A schematic diagram showing a system architecture to which exemplary embodiments of the present disclosure may be applied;
[0015] Figure 2 A method for generating an image from text in an exemplary embodiment of the present disclosure is shown;
[0016] Figure 3 A schematic diagram showing a model architecture in an exemplary embodiment of the present disclosure;
[0017] Figure 4 A schematic diagram showing a training process of a picture-text similarity model in an exemplary embodiment of the present disclosure;
[0018] Figure 5 A schematic diagram showing a process of generating training samples of a text semantic similarity model in an exemplary embodiment of the present disclosure;
[0019] Figure 6 A schematic diagram showing a flow chart of a training method for a fourth model in an exemplary embodiment of the present disclosure;
[0020] Figure 7 A schematic diagram showing a training process of an autoregressive model in an exemplary embodiment of the present disclosure;
[0021] Figure 8 A schematic diagram showing a training process of a diffusion model in an exemplary embodiment of the present disclosure;
[0022] Fig. 9 A schematic flow chart showing a method for generating an image corresponding to text description information according to a first model in an exemplary embodiment of the present disclosure;
[0023] Fig.10 A schematic flow chart showing a method for generating an image corresponding to text description information according to a second model in an exemplary embodiment of the present disclosure;
[0024] Fig.11 A schematic diagram showing a result of an image generated based on text description information in an exemplary embodiment of the present disclosure;
[0025] Fig.12 A schematic diagram showing another result of an image generated based on text description information in an exemplary embodiment of the present disclosure;
[0026] Fig.13 A schematic diagram showing the structure of a device for generating an image from text in an exemplary embodiment of the present disclosure is shown;
[0027] Fig.14 A schematic diagram showing an electronic device to which the exemplary embodiments of the present disclosure can be applied. DETAILED DESCRIPTION
[0028] Example embodiments will now be described more fully with reference to the accompanying drawings. However, example embodiments can be implemented in a variety of forms and should not be construed as limited to the examples set forth herein; rather, these embodiments are provided so that the disclosure will be more comprehensive and complete and to fully convey the concepts of the example embodiments to those skilled in the art. The described features, structures, or characteristics may be combined in any suitable manner in one or more embodiments.
[0029] In addition, the accompanying drawings are only schematic illustrations of the present disclosure and are not necessarily drawn to scale. The same reference numerals in the figures represent the same or similar parts, and their repeated description will be omitted. Some of the block diagrams shown in the accompanying drawings are functional entities and do not necessarily correspond to physically or logically independent entities. These functional entities can be implemented in software form, or implemented in one or more hardware modules or integrated circuits, or implemented in different networks and / or processor devices and / or microcontroller devices.
[0030] Text-generated images, that is, generating images that match the text content for a given text, have the ability of intelligent creation. On the one hand, it needs to understand the low-dimensional information of the text modality and convert it into high-dimensional information of the image language; on the other hand, for the text description of non-realistic scenes, it is necessary to abstract the unified representation of the text modality and generate a surreal image that matches the description, which is very challenging for machines.
[0031] Since the introduction of deep learning, especially the introduction of GAN (Generative Adversarial Network), the task of generating images from text has gradually come into the field of vision of researchers. At present, there are three main technical implementation routes for the task of generating images from text: one is to generate images from text based on the GAN network. The main approach is to use natural language processing technology to convert text descriptions into latent variables, and generate images through the generative network in GAN; the second is to generate images from text based on the autoregressive architecture. The main approach is to process text features through the Transformer text encoder, and use the Transformer decoder or the autoregressive technology of the recurrent neural network and the VAE-like image encoder and decoder to generate images; the third is to generate images from text based on the diffusion model. The main approach is to divide the image into the noise addition and denoising processes, and use the text description as a condition to generate the image in the denoising process.
[0032] In a related technology, the text encoder of Transformer is used to encode the input text into a word feature matrix and a sentence feature vector, and the image is generated through the network model generated by GAN. At the same time, a text-generated image similarity model based on a graph convolutional network is established to detect the consistency between phrases and images. However, the GAN network has a slow training speed and poor convergence, making it difficult to quickly obtain an excellent model.
[0033] In another related technology, natural language text is encoded to obtain semantic embedding representation, the semantic embedding and random noise are mixed, and a recurrent neural network is used to decode the image latent code step by step, and then each step of the latent code is decoded, and finally all the step images are fused to obtain the generated image. However, the decoding speed of the recurrent neural network is slow and the decoding effect is not good.
[0034] In another related technology, based on the Transformer and GAN networks, a text encoder is used to encode sentence features and word features, which are fused with random noise vectors and input into the Transformer module to output an improved feature vector, which is then input into the generator to generate an initial image of 64×64 pixels, and at the same time input into the discriminator for discrimination and training the generator according to the loss; the obtained fused vector is input into the generator to obtain images of 128×128 and 256×256 pixels. However, the processing link of this method is poor, and it is easy to produce an error accumulation effect, resulting in poor quality of the final generated image.
[0035] In summary, currently, related technologies all use a single model or a single method to implement text-based image generation tasks, resulting in insufficient accuracy of the generated images.
[0036] In view of the above problems, exemplary embodiments of the present disclosure provide a method and apparatus for generating an image from text.
[0037] Next, combine Figure 1 The system architecture of the operating environment of this exemplary embodiment is exemplarily described.
[0038] Figure 1 The schematic diagram of the system architecture is shown, and the system architecture 100 may include a terminal 110 and a server 120. The terminal 110 may be a terminal device such as a smart phone, a smart wearable electronic device (such as a smart watch), a tablet computer, a desktop computer, a laptop computer, etc. The server 120 generally refers to a background system that provides related services of the method for generating an image from text in this exemplary embodiment, and may be a server or a cluster formed by multiple servers. The terminal 110 and the server 120 may be connected via a wired or wireless communication link to perform data exchange.
[0039] In an exemplary implementation, the above method may be performed by the server 120. For example, the server 120 may obtain candidate keywords of the text description information of the image to be generated, and then determine a target text-image generation model corresponding to the candidate keywords from a plurality of candidate text-image generation models stored in the server 120, and then obtain an image corresponding to the text description information of the image to be generated based on the target text-image generation model.
[0040] In another exemplary implementation, the above method may also be performed by the terminal 110. For example, the terminal 110 may pre-store multiple candidate text-image generation models, and then when it is necessary to generate an image based on the text description information, obtain the candidate keywords in the text description information, determine the target text-image generation model corresponding to the candidate keywords from the stored multiple candidate text-image generation models, and then obtain the image corresponding to the text description information based on the target text-image generation model.
[0041] As can be seen from the above, the execution subject of the method for generating an image from text in this exemplary embodiment may be the terminal 110 or the server 120 , and the present disclosure does not limit this.
[0042] Combine the following Figure 2 A method of generating an image from text in this exemplary embodiment is described. Figure 2 An exemplary process of the method of generating an image from text is shown, which may include:
[0043] In step S210, candidate keywords in the text description information are obtained;
[0044] In step S220, according to the keywords associated with the multiple candidate text-image generation models, a target text-image generation model corresponding to the candidate keyword is determined from the multiple candidate text-image generation models;
[0045] In step S230, an image corresponding to the text description information is generated based on the target text-image generation model;
[0046] Wherein, target text-image generation models corresponding to different keywords are selected in advance according to evaluation scores of images generated by a plurality of candidate text-image generation models for different keyword texts, so as to determine the keywords associated with each candidate text-image generation model.
[0047] Based on the above method, by evaluating the scores of images generated by multiple candidate text-image generation models for texts with different keywords, the target text-image generation model used for image generation for texts including different keywords can be determined from the multiple candidate text-image generation models, so that the image corresponding to the text description information can be generated according to the keywords in the text description information by combining the advantages of different models, so as to improve the accuracy of the image generated based on the text description information.
[0048] Below Figure 2 Each step in the illustrated embodiment is described in detail.
[0049] In step S210, candidate keywords in the text description information are obtained.
[0050] The text description information in step S210 may be understood as the text description information of the image to be generated, that is, a corresponding image may be generated for the text description information in step S210.
[0051] Exemplarily, a specific implementation of step S210 may include: obtaining candidate keywords and the weight of each candidate keyword in the text description information; and determining a target keyword according to the candidate keyword with the largest weight.
[0052] For example, the keyword extraction method in the prior art can be used to extract keywords from the text description information and determine the weight of each extracted keyword. The extracted keywords are then used as candidate keywords, and the target keyword is determined based on the candidate keyword with the largest weight.
[0053] In step S220, according to the keywords associated with the plurality of candidate text-image generation models, a target text-image generation model corresponding to the candidate keywords is determined from the plurality of candidate text-image generation models.
[0054] Exemplarily, based on the target keyword determined in step S210, a specific implementation of step S220 may include: determining a target text-image generation model corresponding to the target keyword from multiple candidate text-image generation models according to keywords associated with multiple candidate text-image generation models.
[0055] In an exemplary implementation, target text-image generation models corresponding to different keywords may be selected in advance based on evaluation scores of images generated by multiple candidate text-image generation models for different keyword texts to determine the keywords associated with each candidate text-image generation model.
[0056] For example, multiple candidate text-image generation models can be obtained by training according to the training samples. Then, for each candidate text-image generation model, an evaluation data set can be used to evaluate it, wherein the evaluation data set includes text description information sets of different categories in different fields and their corresponding images, and the keywords of the text description information in the text description information sets of different fields and different categories are different, so that each candidate text-image generation model is evaluated separately according to the text description information sets of different categories in different fields. For example, the evaluation data set includes text description information of 10 categories (such as landscape, grassland scenery, real people, cartoon characters, reptiles, flying animals, amphibians, vehicles, etc.), and the text description information in the text description information sets of these 10 categories is input into each candidate text-image generation model to obtain images generated by each candidate text-image generation model for the text description information of these 10 categories. For each candidate text-image generation model, the evaluation score of the image generated by each candidate question generation model for each category of text description information is determined based on the similarity between the images generated by the model for the 10 categories of text description information and the corresponding images of each text description information in the evaluation data set. For each category of text description information, the target text-image generation model corresponding to the text description information of that category is determined based on the candidate text-image generation model with the highest evaluation score.
[0057] After determining the target text-image generation model corresponding to the text description information of each category, the keywords associated with the target text-image generation model corresponding to the text description of the category can be determined based on the keywords included in the text description information of the category. In this way, the keywords associated with each candidate text-image generation model can be determined in advance.
[0058] After determining the target text-image generation model corresponding to the text description information of each category, the text description information indicating the category can also be associated with the target text-image generation model, so as to determine the object category associated with each candidate text-image generation model, and use the text indicating the object category as the keyword associated with the target text-image generation model.
[0059] For example, candidate text and image generation model 1 has the highest evaluation score for text description information including transportation tools. Then, the keywords associated with candidate text and image generation model 1 can include different transportation tool names, such as bicycles, trains, cars, airplanes, etc. The keywords associated with the candidate text and image generation model can also include transportation tools, that is, transportation tools can be directly used as keywords associated with candidate text and image generation model 1.
[0060] In other words, in the present disclosure, the text keyword or the associated object category associated with each candidate text-image generation model can be determined in advance based on the evaluation scores of images generated by different candidate text-image generation models for different categories of text description information.
[0061] Based on this, another specific implementation of step S220 may include: determining a target text-image generation model corresponding to the object category represented by the candidate keyword from the multiple candidate text-image generation models according to the object categories associated with the multiple candidate text-image generation models.
[0062] For example, after determining the target keyword in the text description information in step S210, the object category represented by the target keyword can be determined. For example, if the target keyword is a bicycle, then the object category represented by it is determined to be a means of transportation; if the target keyword is a little girl, then the object category represented by it is determined to be a real person; if the target keyword is a stream, then the object category represented by it is determined to be a landscape, etc., and then the target object category represented by the target keyword is matched with the object category associated with each candidate text-image generation model. According to the candidate text-image generation model associated with the successfully matched object category, the target text-image generation model corresponding to the target keyword is determined, that is, the target text-image generation model corresponding to the object category represented by the candidate keyword in the text description information.
[0063] In an exemplary embodiment, the multiple candidate text-image generation models include multiple models of a first model, a second model, a third model, and a fourth model; wherein the first model includes a text-image similarity model and a diffusion model, the second model includes a text semantic similarity model and a text-image similarity model, the third model includes a diffusion model, and the fourth model includes an autoregressive model; the first model determines a reference image from a candidate image library corresponding to the text description information according to the text-image similarity model, and generates an image corresponding to the text description information based on the reference image and the text description information and based on the diffusion model; the second model determines a target candidate image from a candidate image library corresponding to the text description information according to the text semantic similarity model, and determines an image corresponding to the text description information from the target candidate image according to the text-image similarity model; the third model is used to input the text description information into the diffusion model to obtain an image corresponding to the text description information; the fourth model is used to input the text description information into the autoregressive model to obtain an image corresponding to the text description information.
[0064] For example, the model for generating an image from text in the present disclosure may include multiple candidate text-image generation model branches. Figure 3 As shown, the first branch can be determined based on the image-text similarity model and the diffusion model, the second branch can be determined based on the text semantic similarity model and the image-text similarity model, the third branch can be determined based on the diffusion model, and the fourth branch can be determined based on the autoregressive model.
[0065] For example, Figure 4A schematic diagram showing a training process of a picture-text similarity model in an exemplary embodiment of the present disclosure is shown. The picture-text similarity model is mainly used to learn and evaluate the similarity between an input text and an input image.
[0066] like Figure 4 As shown, the image-text similarity model may include a text encoder and an image encoder, which may batch-input image-text sample pairs, wherein the text and image in each image-text sample pair are matched, and the text in each image-text sample pair is not matched with the image in other image-text sample pairs. The text encoder may encode the text in the image-text sample pair to obtain a text vector of the text, such as Figure 4 From T1 to Tn in , the image encoder can encode the image in the image-text sample pair to obtain an image vector of the image, such as Figure 4 From I1 to In in the figure, the text vectors and image vectors of the same batch are optimized using the contrastive learning loss function to make the matching text vectors and image vectors as close as possible in the high-dimensional space, such as making Figure 4 The gaps between I1 and T1, I2 and T2, ..., and In and Tn in the diagonal positions of 41 in are as small as possible, so that the mismatched text vectors and image vectors are as far away as possible in the high-dimensional space, such as making Figure 4 The gap between the text vectors and the image vectors in 41 except the diagonal positions is as large as possible, so that the image-text similarity model finally trained can measure the similarity between the input text and the input image.
[0067] Among them, the text encoder and image encoder in the image-text similarity model can be selected according to their own needs, such as the text encoder can be a Bert (Bidirectional Encoder Representations from Transformers, bidirectional encoding representation based on transformer) model, etc., and the image encoder can be a vit (Vision Transformer, visual encoder), etc. In addition, the image-text similarity model in the present disclosure can also be obtained through other training technologies or methods, such as the Encoder+memory queue (encoder+memory queue), Blip (Bootstrapping Language-Image Pre-training, natural language image pre-training model) method, etc. to obtain the image-text similarity model, and this exemplary embodiment does not make any special limitations on this.
[0068] Exemplarily, for a text semantic similarity model, it can be used to evaluate the similarity between two input texts. During the training process, a deep learning Dropout (a regularization technology) technique can be used to generate training samples. Specifically, two text vectors generated by the same text description information through different Dropouts are positive sample pairs, and text vectors generated by different text description information through different Dropouts are negative sample pairs.
[0069] like Figure 5 As shown in the figure, the two text vectors generated by different Dropout for the text "Two dogs playing" are embed1 and embed2, and the two text vectors generated by different Dropout for the text "A cat in the grass" are embed3 and embed4. Then embed1 and embed2 are positive sample pairs, embed3 and embed4 are another positive sample pair, embed1 and embed3 are a negative sample pair, embed1 and embed4, embed2 and embed3, and embed2 and embed4 are also negative sample pairs.
[0070] For example, the Bert model can be used as a text encoder, and the text vectors of the positive and negative sample pairs are subjected to similarity loss and dissimilarity loss calculations to train a text semantic similarity model. For example, the input text can be segmented, and the latent vector corresponding to the segmentation can be determined according to the serial index of the segmentation in the latent vector table corresponding to the Bert model. The latent vector of the segmentation is input into the Bert model, i.e., multiple Transformer Blocks, and high-dimensional feature extraction is performed to obtain the word vector of each segmentation. The word vector of each segmentation is then passed through an average pooling layer to obtain the text vector representation of the input text. The training loss function of the text semantic similarity model is constructed using contrastive learning technology. Specifically, it can be shown as formula (1):
[0071]
[0072] In formula (1), represents a positive sample pair, Represents negative sample pairs, that is, the numerator of the training loss function of the text semantic similarity model is the similarity between two positive samples, and the denominator is the similarity between the positive sample and other negative samples in the same batch. t is the temperature value. t is a hyperparameter that can soften the label and solve the noise problem of the data itself. Its value can be a constant, which is used to adjust the degree of similarity measurement.
[0073] In the present disclosure, the text semantic similarity model can also be obtained by other means, such as DSSM (Deep Structure Semantic Model), SimBert (an improved version of the Bert model), etc., and this exemplary embodiment does not make any special limitations on this.
[0074] Exemplarily, when the plurality of candidate text-image generation models include the fourth model described above, the fourth model includes an autoregressive model with a transformer as a framework, Figure 6 A flowchart of a training method for a fourth model in an exemplary embodiment of the present disclosure is shown. Figure 6 , the method may include steps S610 to S630. Wherein:
[0075] In step S610, a text image sample pair is obtained, a text vector sample of the text in the text image sample pair is obtained through the encoder in the transformer, and a latent vector sample of the image in the text image sample pair is obtained through the encoder of the variational autoencoding method.
[0076] As mentioned above, the fourth model in the present disclosure, i.e., the autoregressive model, is based on the transformer, i.e., the Transformer architecture, and includes a Transformer Encoder (encoder in the transformer) and a Transformer Decoder (decoder in the transformer). Matched text and images can be obtained and used as text-image sample pairs. The text in the text-image sample pair is first input into the text encoder to encode the text, and then the encoded text is converted into a high-order vector through the Transformer Encoder to obtain a text vector sample. For the image in the text-image sample pair, the image can be converted into a corresponding latent vector through an encoder of a VAE (Variational Autoencoder) method, and used as a latent vector sample of the image.
[0077] In step S620, based on the cross attention between the text vector sample and the vector sequence of the image in the text image sample pair input by the decoder in the transformer, the latent vector prediction value of the image in the text image sample pair is obtained according to the decoder in the transformer.
[0078] For example, for each image sample pair, the image can be sliced and serialized first, and then the slice sequence can be feature extracted to obtain the image embedding vector sequence, which is used as the input of the decoder in the transformer. At the same time, the text vector sample is input into the TransformerDecoder (decoder in the transformer) through the cross-attention mechanism, and the latent vector prediction value of the image is obtained based on the cross-attention cyclic decoding between the text vector sample and the image embedding vector sequence.
[0079] In step S630, a training loss function value is determined according to the latent vector sample and the latent vector prediction value to train and obtain the fourth model.
[0080] For example, the training loss function of the fourth model can be determined based on the cross entropy loss between the latent vector samples of the image generated in step S610 and the latent vector prediction values of the image predicted in step S620, and training is performed with the optimization goal of reducing the value of the training loss function to obtain the fourth model.
[0081] Exemplarily, a specific implementation of step S630 may include: determining a training loss function value based on the latent vector sample and the latent vector prediction value, and when the training loss function value is less than a preset value, obtaining a fourth model to be tuned according to the training result; obtaining a text image sample pair, and obtaining a latent vector prediction value of the image in the text image sample pair based on the fourth model to be tuned; decoding the latent vector prediction value through a decoder of a variational autoencoding method to obtain a restored image; calculating a fourth similarity between the text in the text image sample pair and the restored image according to a text-image similarity model; adjusting the training loss function value based on the similarity to train the fourth model to be tuned, and obtaining the fourth model according to the training result of the fourth model to be tuned.
[0082] For example, for the fourth model, it can be trained through two stages of models. The main process of the first stage is to use a text encoder to encode the text in the input text image sample pair, and then convert the encoded text into a high-order vector through TransformerEncoder. For the image in the input text image sample pair, the latent vector of the image can be obtained through an encoder of a VAE-like method, and the latent vector is used as the latent vector label of the image. Then, based on the cross-attention between the vector sequence of the image and the high-order vector of the text, a Transformer Decoder is used to learn and restore the latent vector corresponding to the image, that is, the latent vector obtained by the Transformer Decoder is the latent vector prediction value of the image, and the Transformer Encoder and Transformer Decoder are trained based on the cross entropy loss between the latent vector prediction value and the latent vector label. When the value of the cross entropy loss is less than the first preset value or the number of training iterations reaches the second preset value, the first stage training stops, and the model obtained by the first stage training is tested. When the performance evaluation index of the test, such as accuracy, meets the requirements, the model obtained by the first stage training is determined to be the fourth model to be tuned, and the first stage training ends.
[0083] The second stage of training can use the above-mentioned image-text similarity model to perform reinforcement learning fine-tuning on the model to be tuned obtained from the first stage of training, thereby obtaining the final fourth model. The second stage of training can refer to Figure 7 As shown in the figure, the input text is first segmented, and then the segmented encoding is obtained through the text encoder, and then the segmented encoding is input into the Transformer Encoder to obtain the text vector sample of the text, and the text vector sample is input into the Transformer Decoder to perform cross-attention calculation with the vector sequence of the image sample corresponding to the input text, and the latent vector prediction value of the image is obtained by cyclic decoding. The latent vector prediction value of the image is then restored through the VQGAN model to obtain the generated image, and then the similarity between the input text and the image generated after the latent vector prediction value is restored through the VQGAN (Vector Quantized Generative Adversarial Networks) model is calculated based on the above-mentioned image-text similarity model.
[0084] When the similarity between the two is greater than a certain threshold, a positive feedback is given to the training loss function of the fourth model. When the similarity between the two is less than the threshold, a negative feedback is given to the training loss function of the fourth model (i.e., the cross entropy loss between the latent vector label of the image and the predicted value of the latent vector of the image). Based on the idea of reinforcement learning, the parameters of the fourth model to be tuned are optimized. When the value of the training loss function is less than the preset value or the number of training iterations meets the requirements, the second stage of training is stopped. Then, the model trained in the second stage is tested. When the performance evaluation indicators of the test, such as accuracy, meet the requirements, the second stage of training ends, and the model trained in the second stage is determined to be the final fourth model, that is, the final autoregressive model for generating images from text.
[0085] In the present disclosure, the autoregressive model can also use the Transformer model of GPT (Gererate Pre-Training Model) or Unilm (Unified Language Model) architecture, such as Cogview (Mastering Text-to-Image Generation via Transformers), Ernie-VilG (cross-modal bidirectional generation model), etc. This exemplary embodiment does not specifically limit this.
[0086] Exemplarily, in the case where the multiple candidate text-image generation models include the first model and / or the third model, the method for determining the diffusion model may include: obtaining a text image sample pair, adding T steps of random noise to the image in the text image sample pair to obtain the image to be denoised; determining a text vector corresponding to the text in the text image sample pair, and based on the cross-attention between the text vector and the image to be denoised at each step, performing T-step denoising on the reference image to be denoised to obtain a predicted image after T-step denoising; determining a training loss based on the loss between the predicted image and the image in the text image sample pair to train an initial diffusion model to obtain the diffusion model.
[0087] For example, Figure 8 A schematic diagram showing a training process of a diffusion model in an exemplary embodiment of the present disclosure is shown. Figure 8For the diffusion model, it is mainly divided into forward denoising and reverse denoising processes. The forward denoising process is based on adding random noise to the original image at each time step in T time steps. The reverse denoising process is just the opposite. The Unet (UConvolutional Networks for Biomedical Image Segmentation) model can be used to predict the random noise added in the forward process, and then restore the original image after T steps. When performing T-step denoising, the input text can be converted into a vector through a text encoder as a condition and the image denoising features of each step are cross-attention calculated to restore the noisy image according to the semantics of the text.
[0088] like Figure 8 q(X t |X t- 1) represents the forward denoising process, that is, the denoised image X in the previous step t- 1, continue to add noise to get the next step of the noise image X t , Figure 8 p0(X t- 1|X t ) indicates that in the denoising process, the image X after denoising in the previous step t Based on this, denoising is performed to obtain the denoised image X in the next step. t- 1. The cross entropy loss between the restored image and the original image obtained after T-step restoration is used as the training loss of the Unet model. When the loss between the two is less than the preset value, the training can be stopped to obtain a diffusion model for text image generation.
[0089] In the present disclosure, the diffusion model may also use models based on other technical frameworks, such as DALLE2 (Hierarchical Text-Conditional Image Generation with CLIP Latents, a hierarchical CLIP feature-based model for generating images from text), Imagen (text-to-image diffusion model), etc. This exemplary embodiment does not specifically limit this.
[0090] In an exemplary embodiment, for any candidate text-image generation model in the present disclosure, when training, large-scale text-image data crawled on the Internet can be used for pre-training to obtain the candidate text-image generation model to be optimized; then, the candidate text-image generation model to be optimized is fine-tuned using text-image data in a specific task field according to the specific task to obtain the final candidate text-image generation model. Taking the downstream specific task of displaying the corresponding products in the form of pictures according to the search text entered by the user in the e-commerce field as an example, the parameters of the candidate text-image generation model to be optimized can be fine-tuned according to the text-image data in the e-commerce field to obtain the candidate text-image generation model for the e-commerce field, thereby further ensuring the accuracy of the generated image.
[0091] Continue to refer Figure 2 In step S230, an image corresponding to the text description information is generated based on the target text-image generation model.
[0092] As mentioned above, when the target text-image generation model is the first model, the first model determines a reference image from a candidate image library corresponding to the text description information according to a text-image similarity model, and generates an image corresponding to the text description information based on the reference image and the text description information based on the diffusion model.
[0093] For example, Fig. 9 A schematic flow chart of a method for generating an image corresponding to text description information according to a first model in an exemplary embodiment of the present disclosure is shown. Fig. 9 , the method may include steps S910 to S950. Wherein:
[0094] In step S910, a first similarity between the text description information and each candidate image in a candidate image library corresponding to the text description information is calculated according to a picture-text similarity model.
[0095] For example, the candidate image library corresponding to the text description information may include an image library composed of reference candidate images pre-configured for keywords with greater weights in the text description information, and may also include an image library composed of reference candidate images pre-configured for the field to which the text description information belongs. The similarity between the text description information of the image to be generated and each candidate image in the candidate image library corresponding to the text description information may be calculated based on the above-mentioned trained image-text similarity model.
[0096] In step S920, a reference image is determined based on the candidate image with the greatest first similarity.
[0097] For example, the first similarities may be sorted, and then the candidate images in the candidate image library with the largest first similarity are used as reference images.
[0098] In step S930, T steps of random noise are added to the reference image to obtain a reference image to be denoised.
[0099] Wherein, T is a positive integer. For example, T steps of random noise may be added to the reference image to obtain a reference image to be denoised.
[0100] In step S940, a text vector corresponding to the text description information is determined so that the diffusion model performs T-step denoising on the reference image to be denoised based on the cross attention between the text vector and the image to be denoised at each step.
[0101] In step S950, based on the result of T-step denoising, an image corresponding to the text description information is generated.
[0102] For example, a text vector corresponding to the text description information of the image to be generated can be obtained through a text encoder. Then, according to the cross attention between the text vector and the image to be denoised at each step, a T-step denoising process is performed on the reference image to be denoised generated in step S930 based on the diffusion model obtained by the above training, so as to obtain an image corresponding to the text description information according to the image after T-step denoising.
[0103] Through the above steps S910 to S950, in the process of generating the text image, the accuracy of the generated image can be improved because the determined reference image is referred to.
[0104] As mentioned above, when the target text-image generation model is the second model, the second model determines the target candidate image from the candidate image library corresponding to the text description information according to the text semantic similarity model, and determines the image corresponding to the text description information from the target candidate image according to the image-text similarity model.
[0105] For example, Fig.10 A flow chart of a method for generating an image corresponding to text description information according to a second model in an exemplary embodiment of the present disclosure is shown. Fig.10 , the method may include steps S1010 to S1040. Wherein: in step S1010, according to the text semantic similarity model, the second similarity between the text description information and the text description information of each candidate image in the candidate image library corresponding to the text description information is calculated; in step S1020, the candidate image whose second similarity is greater than the first preset value or whose similarity is ranked in the top N is selected as the target candidate image; in step S1030, according to the image-text similarity model, the third similarity between the target candidate image and the text description information is calculated; in step S1040, based on the target candidate image with the largest third similarity, the image corresponding to the text description information is determined.
[0106] For example, each candidate image in the candidate image library can be configured with corresponding text description information, and the similarity between the text description information in step S210 and the text description information configured for each candidate image in the candidate image library can be calculated by the text semantic similarity model obtained through the above training. Then, the candidate images whose similarity is greater than a preset value or whose similarity is ranked in the top N are selected as target candidate images. Then, based on the image-text similarity model obtained through the above training, the similarity between the text description information in step S210 and each target candidate image is calculated respectively, and then the target candidate image with the largest similarity is selected as the image corresponding to the text description information in step S210.
[0107] As mentioned above, when the target text-image generation model is the third model, the third model is used to input the text description information into the diffusion model to obtain the image corresponding to the text description information. Exemplarily, the third model can generate the image corresponding to the text description information in the following manner: generate a random noise, and determine the random noise as the noise after T-step noise addition; determine the text vector corresponding to the text description information, so that the diffusion model performs T-step denoising on the random noise based on the cross attention between the text vector and the noise at each step to generate the image corresponding to the text description information.
[0108] For example, for the diffusion model obtained through training, when performing text image generation, in the case of a candidate image library, an image corresponding to the text description can be generated based on the text description and the reference image, such as the process of generating an image corresponding to the text description information shown in the above steps S910 to S950. In the absence of a candidate image library, an image can also be generated directly based on the text description. For example, a random Gaussian noise can be generated, and the noise can be used as the noise after T-step denoising of the original image, and then the generated random Gaussian noise can be denoised for T steps based on the cross attention between the text vector corresponding to the text description information and the noise at each step according to the diffusion model, thereby generating an image corresponding to the text description information.
[0109] Exemplarily, when the target text-image generation model is an autoregressive model, the text description information of the image to be generated can be directly input into the autoregressive model, and the latent vector of the image is obtained through the encoder and decoder of the transformer. Then, the above-mentioned VQGAN model is used to convert the latent vector into an image, thereby obtaining the image corresponding to the text description information.
[0110] In the present disclosure, a set of text-image generation solutions is constructed by combining the advantages of multiple models. One line is to directly use the autoregressive model to generate the image corresponding to the input text description information, and one line is to use the diffusion model to generate the image according to the text; one line is to first use the image-text similarity model to obtain the reference image according to the input text, and then use the diffusion model to generate the image corresponding to the input text according to the input text and the reference image; one line is to first match the target candidate image from the candidate image library according to the text semantic similarity model, and then use the image-text similarity model to perform similarity judgment, filter out the target candidate images with low similarity, and thus obtain the final generated image. In actual use, for different fields, the line with the highest accuracy in generating images for the field is used to generate the image corresponding to the text in the field, thereby improving the quality of the generated image.
[0111] Furthermore, in the present disclosure, due to the integration of text semantic similarity models and other multimodal technologies, by using multimodal retrieval and matching filtering modes, the weaknesses of simple generation models can be compensated to avoid generating some images with lower quality and poor effect.
[0112] The method disclosed in the present invention achieved a joint first place (FID=9.82) in the e-commerce text-to-image generation task of the Chinese Large-Scale Multimodal Evaluation Benchmark MUGE (Multimodal Understanding and Generation Evaluation Benchmark), and achieved the first place (FID=10.812) in the preliminary round of the multimodal technology innovation competition-text-based image generation task of the first "Xingzhi Cup" National Artificial Intelligence Application Innovation Competition hosted by the Ministry of Industry and Information Technology, where FID is an evaluation indicator specifically used to evaluate text-to-image tasks.
[0113] Fig.11 and Fig.12 , respectively, show the results of images generated based on text description information according to the method in the present disclosure. Specifically, when the text description information is "Winter Thickened Mid-Length Loose Hooded Sweater Korean Version Gray Women", the generated images are as follows: Fig.11 As shown in FIG. 1 , when the text description information is “Spring new casual sports pants knitted fleece men’s trousers”, the generated image is as follows: Fig.12 shown.
[0114] The present invention evaluates the scores of images generated for texts with different keywords by using multiple candidate text-image generation models. It can determine, from the multiple candidate text-image generation models, a target text-image generation model to be used when generating images for texts including different keywords. This allows the advantages of different models to be combined based on the keywords in the text description information to generate images corresponding to the text description information, thereby improving the accuracy of images generated based on the text description information.
[0115] It should be noted that the above figures are only schematic illustrations of the processes included in the method according to the exemplary embodiments of the present disclosure, and are not intended to be limiting. It is easy to understand that the processes shown in the above figures do not indicate or limit the time sequence of these processes. In addition, it is also easy to understand that these processes can be performed synchronously or asynchronously, for example, in multiple modules.
[0116] For further reference, Fig.13 As shown, in the implementation of this example, a device for generating an image from text is also provided, and the device 1300 for generating an image from text may include a candidate keyword acquisition module 1310, a target text-image generation model determination module 1320, and an image generation module 1330. The candidate keyword acquisition module 1320 is configured to acquire candidate keywords in the text description information; the target text-image generation model determination module 1320 is configured to determine the target text-image generation model corresponding to the candidate keyword from multiple candidate text-image generation models according to the keywords associated with the multiple candidate text-image generation models; the image generation module 1330 is configured to generate an image corresponding to the text description information based on the target text-image generation model; wherein, the target text-image generation models corresponding to different keywords are selected in advance according to the evaluation scores of the images generated by the multiple candidate text-image generation models for different keyword texts, so as to determine the keywords associated with each candidate text-image generation model.
[0117] In an exemplary embodiment, based on the aforementioned embodiments, the candidate keyword acquisition module 1310 can be specifically configured as follows: obtaining the candidate keywords in the text description information and the weight of each candidate keyword; determining the target keyword based on the candidate keyword with the largest weight; based on this, the target text-image generation model determination module 1320 can be specifically configured as follows: determining the target text-image generation model corresponding to the target keyword from multiple candidate text-image generation models based on the keywords associated with multiple candidate text-image generation models.
[0118] In an exemplary implementation, based on the aforementioned embodiment, the target text-image generation model determination module 1320 may also be specifically configured as: according to the object categories associated with the multiple candidate text-image generation models, determining the target text-image generation model corresponding to the object category represented by the candidate keyword from the multiple candidate text-image generation models.
[0119] In an exemplary embodiment, based on the aforementioned embodiments, the multiple candidate text-image generation models include multiple models of a first model, a second model, a third model, and a fourth model; wherein the first model includes a text-image similarity model and a diffusion model, the second model includes a text semantic similarity model and a text-image similarity model, the third model includes a diffusion model, and the fourth model includes an autoregressive model; the first model determines a reference image from a candidate image library corresponding to the text description information according to the text-image similarity model, and generates an image corresponding to the text description information based on the reference image and the text description information based on the diffusion model; the second model determines a target candidate image from a candidate image library corresponding to the text description information according to the text semantic similarity model, and determines an image corresponding to the text description information from the target candidate image according to the text-image similarity model; the third model is used to input the text description information into the diffusion model to obtain an image corresponding to the text description information; the fourth model is used to input the text description information into the autoregressive model to obtain an image corresponding to the text description information.
[0120] In an exemplary embodiment, based on the aforementioned embodiment, when the multiple candidate text-image generation models include the first model, the first model determines a reference image from a candidate image library corresponding to the text description information according to a text-image similarity model, and generates an image corresponding to the text description information based on the reference image and the text description information based on the diffusion model, including: calculating a first similarity between the text description information and each candidate image in the candidate image library corresponding to the text description information according to the text-image similarity model; determining a reference image based on the candidate image with the largest first similarity; adding T steps of random noise to the reference image to obtain a reference image to be denoised, wherein T is a positive integer; determining a text vector corresponding to the text description information, so that the diffusion model performs T-step denoising on the reference image to be denoised based on the cross-attention between the text vector and the image to be denoised at each step; and generating an image corresponding to the text description information based on the result after T steps of denoising.
[0121] In an exemplary embodiment, based on the aforementioned embodiment, when the multiple candidate text-image generation models include the second model, the second model determines the target candidate image from the candidate image library corresponding to the text description information according to the text semantic similarity model, and determines the image corresponding to the text description information from the target candidate image according to the image-text similarity model, including: calculating the second similarity between the text description information and the text description information of each candidate image in the candidate image library corresponding to the text description information according to the text semantic similarity model; selecting the candidate image whose second similarity is greater than a first preset value or whose similarity is ranked in the top N as the target candidate image; calculating the third similarity between the target candidate image and the text description information according to the image-text similarity model; and determining the image corresponding to the text description information based on the target candidate image with the largest third similarity.
[0122] In an exemplary embodiment, based on the aforementioned embodiment, when the multiple candidate text-image generation models include the fourth model, the fourth model includes an autoregressive model with a transformer as a framework, and the determination method of the fourth model includes: obtaining a text-image sample pair, obtaining a text vector sample of the text in the text-image sample pair through an encoder in the transformer, and obtaining a latent vector sample of the image in the text-image sample pair through an encoder of a variational autoencoding method; based on the cross-attention between the text vector sample and the vector sequence of the image in the text-image sample pair input by the decoder in the transformer, obtaining a latent vector prediction value of the image in the text-image sample pair according to the decoder in the transformer; determining a training loss function value according to the latent vector sample and the latent vector prediction value to train to obtain the fourth model.
[0123] In an exemplary embodiment, based on the aforementioned embodiment, the training loss function value is determined according to the latent vector sample and the latent vector prediction value to train the fourth model, including: determining the training loss function value according to the latent vector sample and the latent vector prediction value, and when the training loss function value is less than a preset value, obtaining the fourth model to be tuned according to the training result; obtaining a text image sample pair, and obtaining the latent vector prediction value of the image in the text image sample pair based on the fourth model to be tuned; decoding the latent vector prediction value by a decoder of a variational autoencoding method to obtain a restored image; calculating the fourth similarity between the text in the text image sample pair and the restored image according to a picture-text similarity model; adjusting the training loss function value based on the similarity to train the fourth model to be tuned, and obtaining the fourth model according to the training result of the fourth model to be tuned.
[0124] In an exemplary embodiment, based on the aforementioned embodiment, when the multiple candidate text-image generation models include the first model and / or the third model, the method for determining the diffusion model includes: obtaining a text image sample pair, adding T steps of random noise to the image in the text image sample pair to obtain the image to be denoised; determining a text vector corresponding to the text in the text image sample pair, and based on the cross-attention between the text vector and the image to be denoised at each step, performing T-step denoising on the reference image to be denoised to obtain a predicted image after T-step denoising; determining a training loss based on the loss between the predicted image and the image in the text image sample pair to train an initial diffusion model to obtain the diffusion model.
[0125] In an exemplary embodiment, based on the aforementioned embodiment, when the multiple candidate text-image generation models include the third model, the third model is used to input text description information into a diffusion model to obtain an image corresponding to the text description information, including: generating a random noise, and determining the random noise as the noise after T-step noise addition; determining the text vector corresponding to the text description information, so that the diffusion model performs T-step denoising on the random noise based on the cross-attention between the text vector and the noise at each step to generate an image corresponding to the text description information.
[0126] The specific details of each module in the above device have been described in detail in the implementation method of the method part. The undisclosed details can be found in the implementation method of the method part, so they will not be repeated here.
[0127] The exemplary embodiments of the present disclosure also provide an electronic device for executing the method of generating an image from text, and the electronic device may be the above-mentioned terminal 110. Generally, the electronic device may include a processor and a memory, the memory is used to store executable instructions of the processor, and the processor is configured to execute the above-mentioned method of generating an image from text by executing the executable instructions.
[0128] The memory may also be used to store the above-mentioned multiple candidate text-image generation models, and the processor may be configured to obtain an image corresponding to the input text description information according to the stored candidate text-image generation models via executable instructions.
[0129] Below Fig.14 The mobile terminal 1400 in FIG. 1 is taken as an example to exemplify the structure of the electronic device. It should be understood by those skilled in the art that, in addition to the components specifically used for mobile purposes, Fig.14 The construction in can also be applied to fixed type equipment.
[0130] like Fig.14As shown, the mobile terminal 1400 may specifically include: a processor 1401, a memory 1402, a bus 1403, a mobile communication module 1404, an antenna 1, a wireless communication module 1405, an antenna 2, a display screen 1406, a camera module 1407, an audio module 1408, a power module 1409 and a sensor module 1410.
[0131] The processor 1401 may include one or more processing units, for example, the processor 1401 may include an AP (Application Processor), a modem processor, a GPU (Graphics Processing Unit), an ISP (Image Signal Processor), a controller, an encoder, a decoder, a DSP (Digital Signal Processor), a baseband processor and / or an NPU (Neural-Network Processing Unit), etc. For example, in the present disclosure, the model training process can be accelerated by a GPU.
[0132] The processor 1401 may be connected to the memory 1402 or other components via a bus 1403 .
[0133] The memory 1402 may be used to store computer executable program codes, which include instructions. The processor 1401 executes various functional applications and data processing of the mobile terminal 1400 by running the instructions stored in the memory 1402. The memory 1402 may also store application data, such as images, videos and other files, and the memory 1402 may also store the first model, the second model, the third model and the fourth model mentioned above.
[0134] The communication function of the mobile terminal 1400 can be implemented by the mobile communication module 1404, antenna 1, wireless communication module 1405, antenna 2, modulation and demodulation processor and baseband processor. Antenna 1 and antenna 2 are used to transmit and receive electromagnetic wave signals. The mobile communication module 1404 can provide 2G, 3G, 4G, 5G and other mobile communication solutions applied to the mobile terminal 1400. The wireless communication module 1405 can provide wireless communication solutions such as wireless LAN, Bluetooth, near field communication, etc. applied to the mobile terminal 1400.
[0135] The display screen 1406 is used to implement display functions, such as displaying a user interface, displaying images and videos generated according to the text-to-image method disclosed in the present invention, etc. The camera module 1407 is used to implement shooting functions, such as shooting images and videos, etc. The audio module 1408 is used to implement audio functions, such as playing audio, collecting voice, etc. The power module 1409 is used to implement power management functions, such as charging the battery, powering the device, monitoring the battery status, etc. The sensor module 1410 may include a depth sensor 14101, a pressure sensor 14102, a gyroscope sensor 14103, an air pressure sensor 14104, etc., to implement corresponding sensing detection functions.
[0136] It will be appreciated by those skilled in the art that various aspects of the present disclosure may be implemented as systems, methods or program products. Therefore, various aspects of the present disclosure may be specifically implemented in the following forms, namely: complete hardware implementation, complete software implementation (including firmware, microcode, etc.), or a combination of hardware and software implementations, which may be collectively referred to herein as "circuits", "modules" or "systems".
[0137] The exemplary embodiments of the present disclosure also provide a computer-readable storage medium on which a program product capable of implementing the above-mentioned method of the present specification is stored. In some possible implementations, various aspects of the present disclosure can also be implemented in the form of a program product, which includes program code. When the program product is run on a terminal device, the program code is used to enable the terminal device to execute the steps according to various exemplary embodiments of the present disclosure described in the above-mentioned "Exemplary Method" section of the present specification, for example, it can execute Figure 2 Any one or more steps in .
[0138] The computer-readable medium shown in the present disclosure may be a computer-readable signal medium or a computer-readable storage medium or any combination of the above two. The computer-readable storage medium may be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device or device, or any combination of the above. More specific examples of computer-readable storage media may include, but are not limited to, an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above.
[0139] In the present disclosure, a computer-readable storage medium may be any tangible medium containing or storing a program that may be used by or in combination with an instruction execution system, apparatus, or device. In the present disclosure, a computer-readable signal medium may include a data signal propagated in a baseband or as part of a carrier wave, which carries a computer-readable program code. Such propagated data signals may take a variety of forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination of the above. A computer-readable signal medium may also be any computer-readable medium other than a computer-readable storage medium, which may send, propagate, or transmit a program for use by or in combination with an instruction execution system, apparatus, or device. The program code contained on the computer-readable medium may be transmitted using any suitable medium, including but not limited to: wireless, wire, optical cable, RF, etc., or any suitable combination of the above.
[0140] In addition, program code for performing the operations of the present disclosure may be written in any combination of one or more programming languages, including object-oriented programming languages such as Java, C++, etc., and conventional procedural programming languages such as "C" or similar programming languages. The program code may be executed entirely on the user computing device, partially on the user device, as a separate software package, partially on the user computing device and partially on a remote computing device, or entirely on a remote computing device or server. In cases involving a remote computing device, the remote computing device may be connected to the user computing device through any type of network, including a local area network (LAN) or a wide area network (WAN), or may be connected to an external computing device (e.g., through the Internet using an Internet service provider).
[0141] Those skilled in the art will readily appreciate other embodiments of the present disclosure after considering the specification and practicing the invention disclosed herein. This application is intended to cover any variations, uses, or adaptations of the present disclosure that follow the general principles of the present disclosure and include common knowledge or customary technical means in the art that are not disclosed in the present disclosure. The specification and examples are to be considered as exemplary only, and the true scope and spirit of the present disclosure are indicated by the claims.
[0142] It should be understood that the present disclosure is not limited to the exact structures that have been described above and shown in the drawings, and that various modifications and changes may be made without departing from the scope thereof. The scope of the present disclosure is limited only by the appended claims.
Claims
1. A method for generating an image from text, characterized in that: include: Obtain candidate keywords in text description information; According to the keywords associated with the multiple candidate text-image generation models, determining the target text-image generation model corresponding to the candidate keywords from the multiple candidate text-image generation models; Generate an image corresponding to the text description information based on the target text-image generation model; Wherein, target text-image generation models corresponding to different keywords are selected in advance according to evaluation scores of images generated by a plurality of candidate text-image generation models for different keyword texts, so as to determine the keywords associated with each candidate text-image generation model.
2. The method for generating an image from text according to claim 1, characterized in that: The step of obtaining candidate keywords in the text description information includes: Obtain candidate keywords and the weight of each candidate keyword in the text description information; Determine the target keyword according to the candidate keyword with the largest weight; The step of determining a target text-image generation model corresponding to the candidate keyword from the plurality of candidate text-image generation models according to the keywords associated with the plurality of candidate text-image generation models comprises: According to the keywords associated with the plurality of candidate text-image generation models, a target text-image generation model corresponding to the target keyword is determined from the plurality of candidate text-image generation models.
3. The method for generating an image from text according to claim 1, characterized in that: The step of determining a target text-image generation model corresponding to the candidate keyword from the plurality of candidate text-image generation models according to the keywords associated with the plurality of candidate text-image generation models comprises: According to the object categories associated with the multiple candidate text-image generation models, a target text-image generation model corresponding to the object category represented by the candidate keyword is determined from the multiple candidate text-image generation models.
4. The method for generating an image from text according to claim 1, characterized in that: The multiple candidate text-image generation models include multiple models selected from the first model, the second model, the third model, and the fourth model; wherein the first model includes a text-image similarity model and a diffusion model, the second model includes a text semantic similarity model and a text-image similarity model, the third model includes a diffusion model, and the fourth model includes an autoregressive model; the first model determines a reference image from a candidate image library corresponding to the text description information according to the text-image similarity model, and generates an image corresponding to the text description information based on the reference image and the text description information and the diffusion model; the second model determines a target candidate image from a candidate image library corresponding to the text description information according to the text semantic similarity model, and determines an image corresponding to the text description information from the target candidate image according to the text-image similarity model; the third model is used to input the text description information into the diffusion model to obtain an image corresponding to the text description information; the fourth model is used to input the text description information into the autoregressive model to obtain an image corresponding to the text description information.
5. The method for generating an image from text according to claim 4, characterized in that: In a case where the plurality of candidate text-image generation models include the first model, the first model determines a reference image from a candidate image library corresponding to the text description information according to a text-image similarity model, and generates an image corresponding to the text description information based on the diffusion model according to the reference image and the text description information, including: Calculating a first similarity between the text description information and each candidate image in a candidate image library corresponding to the text description information according to a picture-text similarity model; Determining a reference image based on the candidate image with the greatest first similarity; Adding T steps of random noise to the reference image to obtain a reference image to be denoised, where T is a positive integer; Determine a text vector corresponding to the text description information, so that the diffusion model performs T-step denoising on the reference image to be denoised based on the cross attention between the text vector and the image to be denoised at each step; Based on the result after T-step denoising, an image corresponding to the text description information is generated.
6. The method for generating an image from text according to claim 4, characterized in that: In the case where the multiple candidate text-image generation models include the second model, the second model determines a target candidate image from a candidate image library corresponding to the text description information according to a text semantic similarity model, and determines an image corresponding to the text description information from the target candidate images according to the image-text similarity model, including: Calculating, according to a text semantic similarity model, a second similarity between the text description information and the text description information of each candidate image in a candidate image library corresponding to the text description information; Selecting the candidate image whose second similarity is greater than the first preset value or whose similarity is ranked in the top N as the target candidate image; Calculating a third similarity between the target candidate image and the text description information according to the image-text similarity model; Based on the target candidate image with the largest third similarity, an image corresponding to the text description information is determined.
7. The method for generating an image from text according to claim 4, characterized in that: In the case where the plurality of candidate text-image generation models include the fourth model, the fourth model includes an autoregressive model with a transformer as a framework, and the determination method of the fourth model includes: Obtain a text image sample pair, obtain a text vector sample of the text in the text image sample pair through an encoder in the transformer, and obtain a latent vector sample of the image in the text image sample pair through an encoder of a variational autoencoding method; Based on the cross attention between the text vector sample and the vector sequence of the image in the text image sample pair input by the decoder in the transformer, obtain the latent vector prediction value of the image in the text image sample pair according to the decoder in the transformer; A training loss function value is determined according to the latent vector sample and the latent vector prediction value to train and obtain the fourth model.
8. The method for generating an image from text according to claim 7, characterized in that: The determining of a training loss function value according to the latent vector sample and the latent vector prediction value to train the fourth model includes: Determine a training loss function value according to the latent vector sample and the latent vector prediction value, and when the training loss function value is less than a preset value, obtain a fourth model to be tuned according to the training result; Acquire a text image sample pair, and obtain a latent vector prediction value of an image in the text image sample pair based on the fourth model to be tuned; Decoding the latent vector prediction value by a decoder of a variational autoencoding method to obtain a restored image; Calculating a fourth similarity between the text in the text image sample pair and the restored image according to the image-text similarity model; The training loss function value is adjusted based on the similarity to train the fourth model to be optimized, and the fourth model is obtained according to the training result of the fourth model to be optimized.
9. The method for generating an image from text according to claim 4, characterized in that: In the case where the multiple candidate text-image generation models include the first model and / or the third model, the manner of determining the diffusion model includes: Obtaining a text image sample pair, and adding T steps of random noise to an image in the text image sample pair to obtain an image to be denoised; Determine a text vector corresponding to the text in the text image sample pair, and perform T-step denoising on the reference image to be denoised based on the cross attention between the text vector and the image to be denoised at each step, so as to obtain a predicted image after T-step denoising; A training loss is determined based on the loss between the predicted image and the image in the text image sample pair to train an initial diffusion model to obtain the diffusion model.
10. The method for generating an image from text according to claim 4, characterized in that: In the case where the plurality of candidate text-image generation models include the third model, the third model is used to input the text description information into a diffusion model to obtain an image corresponding to the text description information, including: Generate a random noise, and determine the random noise as the noise after T-step noise addition; A text vector corresponding to the text description information is determined so that the diffusion model performs T-step denoising on the random noise based on the cross attention between the text vector and the noise at each step to generate an image corresponding to the text description information.
11. A device for generating an image from text, characterized in that: include: A candidate keyword acquisition module is configured to acquire candidate keywords from the text description information; A target text-image generation model determination module is configured to determine a target text-image generation model corresponding to the candidate keyword from among the multiple candidate text-image generation models according to the keywords associated with the multiple candidate text-image generation models; An image generation module is configured to generate an image corresponding to the text description information based on the target text-image generation model; Wherein, target text-image generation models corresponding to different keywords are selected in advance according to evaluation scores of images generated by a plurality of candidate text-image generation models for different keyword texts, so as to determine the keywords associated with each candidate text-image generation model.
12. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the method according to any one of claims 1 to 10 is implemented.
13. An electronic device, characterized in that: include: one or more processors; as well as A memory for storing one or more programs, which, when executed by the one or more processors, enables the one or more processors to implement the method according to any one of claims 1 to 10.
Citation Information
Cited By
Picture generation method and device based on noise reduction stream, electronic equipment and storage medium
CN119228672A
Text-driven knitted product image generation and editing method and device
CN120198548A
Text-driven Knitted Product Image Generation and Editing Method and Device
CN120198548B
Knitted product image generation method and device based on text adjustment and visual feedback
CN120219553A
Method for generating image, method for training text-to-image model, and computing device
WO2026055855A1
