Method and apparatus for generating image based on text, electronic device and storage medium

By constructing an entity-labeled image library and an end-to-end model, the problem of insufficient accuracy and controllability in image generation in existing technologies is solved, and personalized, high-quality images can be generated efficiently in open domains.

CN117252958BActive Publication Date: 2026-11-27GUANGDONG OPPO MOBILE TELECOMMUNICATIONS CORP LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202311378412.4
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2023-10-23
Publication Date
2026-11-27
Estimated Expiration
2043-10-23

AI Technical Summary

Technical Problem

Existing controllable text-to-image generation technologies are insufficient in terms of accuracy and controllability, especially in the generation of personalized images in open domains, and their reliance on limited public datasets leads to poor generation results.

Method used

An image library containing a large number of entity labels and images is constructed. An end-to-end model is used to search for target images corresponding to entity labels in the image library. The images corresponding to descriptive text are generated by combining entity location information. A cross-attention mechanism and U-net network are used to improve the accuracy and efficiency of image generation.

Benefits of technology

It achieves highly controllable, high-quality image generation from end to end, solves the problem of insufficient open domain data, and improves the accuracy and efficiency of image generation.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN117252958B_ABST
    Figure CN117252958B_ABST
Patent Text Reader

Abstract

Embodiments of the present application provide a method and device for generating an image based on text, electronic equipment and storage medium, which are related to the technical field of artificial intelligence drawing. By responding to the reception of a descriptive text, an entity label in the descriptive text and entity position information corresponding to the entity label are extracted, the entity label being used to describe an entity; a target image corresponding to the entity label is searched in an image library, each image in the image library corresponding to an entity label and including an entity described by the corresponding entity label; and an image corresponding to the descriptive text is generated according to the entity label, the entity position information corresponding to the entity label and the target image, thereby realizing the function of end-to-end text-based generation of highly controllable images and improving the efficiency and accuracy of text-based image generation.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of artificial intelligence drawing technology, and more specifically, to a method, apparatus, electronic device, and storage medium for generating images based on text. Background Technology

[0002] Artificial intelligence-based image generation technology includes image-based image generation technology and text-based image generation technology. Image-based image generation refers to generating a new image based on an original image input by the user; for example, generating an animated image based on a portrait image input by the user. Text-based image generation refers to the technology of generating images based on text input by the user; for example, generating an image corresponding to a text input by the user.

[0003] This application relates to text-based image generation technology in artificial intelligence drawing techniques. Text-based image generation technology can be applied to various scenarios, such as creating personalized wallpapers for mobile theme stores, creating creative image materials for Microsoft Office PowerPoint (PPT), creating image content in virtual spaces, and multimodal dialogue interaction systems. Summary of the Invention

[0004] This application provides a method, apparatus, electronic device, and storage medium for generating images based on text, so as to realize the function of generating highly controllable images based on text from end to end, thereby improving the efficiency and accuracy of generating images based on text.

[0005] In a first aspect, embodiments of this application provide a method for generating images based on text. The method includes: in response to receiving descriptive text, extracting entity markers and entity location information corresponding to the entity markers from the descriptive text, wherein the entity markers are used to describe entities; searching for a target image corresponding to the entity markers in an image library, wherein each image in the image library corresponds to an entity marker and includes the entity described by the corresponding entity marker; and generating an image corresponding to the descriptive text based on the entity markers, the entity location information corresponding to the entity markers, and the target image.

[0006] Secondly, embodiments of this application provide an apparatus for generating images based on text. The apparatus includes: a feature extraction module, configured to extract entity markers and corresponding entity location information from the descriptive text in response to receiving descriptive text, wherein the entity markers describe entities; an image search module, configured to search for a target image corresponding to the entity markers in an image library, wherein each image in the image library corresponds to an entity marker and includes the entity described by the corresponding entity marker; and an image generation module, configured to generate an image corresponding to the descriptive text based on the entity markers, the corresponding entity location information, and the target image.

[0007] Thirdly, embodiments of this application provide an electronic device, which includes a memory and a processor. The memory stores an application program that is used to execute the method provided in embodiments of this application when invoked by the processor.

[0008] Fourthly, embodiments of this application provide a computer-readable storage medium storing program code, which, when invoked by a processor, causes the processor to execute the method provided in embodiments of this application.

[0009] The method, apparatus, electronic device, and storage medium for generating images based on text provided in this application can achieve end-to-end functionality for generating highly controllable, high-quality images based on text. By constructing an image library containing a large number of entity markers and images (i.e., images containing entities described by entity markers), on the one hand, it can provide a large amount of entity image data for end-to-end text-based image generation, solving the problem of insufficient open-domain data leading to difficulty in handling personalized image generation in the open domain, and providing necessary data assurance for generating highly controllable, high-quality images guided by descriptive text. On the other hand, by searching for target images corresponding to entity markers in the image library, and generating images corresponding to descriptive text based on entity markers, their corresponding entity location information, and target images, it can ensure that the generated images are highly controllable and improve the accuracy of text-based image generation. At the same time, by searching the image library to determine the target images corresponding to entity markers instead of directly generating more difficult entity images, it can improve the efficiency and accuracy of text-based image generation. Attached Figure Description

[0010] To more clearly illustrate the technical solutions in the embodiments of this application, the accompanying drawings used in the description of the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of this application, and not all embodiments. Based on the embodiments of this application, all other embodiments and drawings obtained by those skilled in the art without creative effort are within the scope of protection of this application.

[0011] Figure 1 This is a training framework structure diagram of an end-to-end model provided in an embodiment of this application; Figure 2 This is a flowchart of generating an image based on text, provided in an embodiment of this application; Figure 3 This is a schematic diagram of a detection frame provided in an exemplary embodiment of this application; Figure 4 It is a grayscale image of the first image corresponding to the descriptive text provided in an exemplary embodiment of this application; Figure 5 It is a grayscale image of the second image corresponding to the descriptive text provided in an exemplary embodiment of this application; Figure 6 It is a grayscale image of a third image corresponding to the descriptive text provided in an exemplary embodiment of this application; Figure 7 It is a grayscale image of the fourth image corresponding to the descriptive text provided in an exemplary embodiment of this application; Figure 8 It is a grayscale image of the fifth image corresponding to the descriptive text provided in an exemplary embodiment of this application; Figure 9 It is a grayscale image of the sixth image corresponding to the descriptive text provided in an exemplary embodiment of this application; Figure 10 It is a grayscale image of the seventh image corresponding to the descriptive text provided in an exemplary embodiment of this application; Figure 11 It is a grayscale image of the eighth image corresponding to the descriptive text provided in an exemplary embodiment of this application; Figure 12 It is a grayscale image of the ninth image corresponding to the descriptive text provided in an exemplary embodiment of this application; Figure 13 It is a grayscale image of the tenth image corresponding to the descriptive text provided in an exemplary embodiment of this application; Figure 14 This is a partial flowchart of a method for generating images based on text, provided in another embodiment of this application; Figure 15 This is a flowchart of step S220 provided in an embodiment of this application; Figure 16 This is a flowchart of step S220 provided in an exemplary embodiment of this application; Figure 17 This is a flowchart of generating an image based on text, provided in another embodiment of this application; Figure 18This is a structural block diagram of an apparatus for generating images based on text, according to an embodiment of this application. Figure 19 This is a structural block diagram of an electronic device provided in an embodiment of this application. Detailed Implementation

[0012] To enable those skilled in the art to better understand the present application, the technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the accompanying drawings.

[0013] The main challenge of text-based image generation technology lies in generating high-quality images that incorporate semantic information from the text. Early methods typically relied on Generative Adversarial Networks (GANs), autoregressive models, and diffusion models to achieve text-based image generation. Among these, diffusion models offer greater stability during training compared to the other two models, do not depend on complex adversarial training processes, and can precisely control the quality and diversity of generated images during the diffusion process.

[0014] With advancements in research on diffusion models, large-scale text-guided diffusion models, such as DALLE-2, Imagen, and Stable diffusion, have been able to generate custom high-fidelity images with specified content, styles, and attributes by leveraging the semantics of text input. This demonstrates that text-based image generation technology has further evolved into controllable text-based image generation technology (referred to as controllable text-generated images). This means that text-based images can be generated that are highly aligned with the text description (often referred to as prompts in this field). High alignment refers to the ability to control the relevant attributes of the generated image, generate multiple entities, and control the logical relationships between multiple entities through text. Currently, controllable text-based image generation technology mainly includes the following four types: (1) Attention map-based approach: During the model's inference process, the text tokens (often called tokens in the field) controlling the text are continuously aligned with the attention map. All entity tokens (often called subject tokens in the field) in the text prompt are focused on and activated. Potential diffusion is performed iteratively until all entity tokens reach a predefined minimum attention value. Alternatively, a local control loss can be introduced during the inference process to correct the generation of intermediate layers in the model. The inventors found in their research that: In the model inference process, since the model relies on the weights saved during StableDiffusion training, changing the relevant strategies of the attention map is a "remedial" measure and cannot fundamentally change the model's training weights. The quality and controllability of the generated images are generally poor, and the accuracy and controllability of images generated from text are not high.

[0015] (2) Based on detection boxes (often referred to as bboxes in the art): Binding entity markers in text to detection box regions, and learning the corresponding binding concepts by adding an adapter (often referred to as an adapter in the art) to the U-net network. The inventors found in their research that the relevant strategies based on detection boxes have relatively coarse control granularity, the accuracy of text-based image generation is not high, and it is difficult to generate high-quality images for entities with complex edge details.

[0016] (3) Based on Large Language Model (LLM): This approach uses graphical representations to outline code snippets from text input and generates corresponding images based on these snippets. For example, Control-GPT uses GPT-4 to generate vector graphics (often referred to as TikZ in the field), and combines the generated sketches with text instructions to serve as a reference for the diffusion model to generate photorealistic images, guiding the final image generation. LayoutGPT transforms challenging language concepts (such as numbers and spatial relationships) into spatial layouts, thereby guiding the final image generation. The inventors found in their research that strategies based on large language models, such as Control-GPT's reliance on vector TikZ code generation, lead to uncontrollable errors in the generated results, resulting in low controllability of text-based image generation. LayoutGPT also relies on bounding boxes to control the generation of multi-attribute entities, resulting in limited control granularity and low accuracy in text-based image generation.

[0017] In other words, the controllability and accuracy of current controllable text-to-image generation technologies still have room for improvement. Furthermore, the inventors also discovered that current controllable text-to-image generation technologies typically use publicly available datasets in the field for image generation, such as COCO-stuff, Visual Genome, and Open Images. However, relying solely on these datasets is far from sufficient for personalized image generation in the open domain; that is, the currently known datasets are insufficient to support personalized image generation in the open domain.

[0018] Based on the above analysis, this application provides a method, apparatus, electronic device, and storage medium for generating images based on text. This enables end-to-end generation of highly controllable, high-quality images based on text. By constructing an image library containing a large number of entity markers and images (i.e., images containing entities described by entity markers), on the one hand, it provides a large amount of entity image data for end-to-end text-based image generation, solving the problem of insufficient open-domain data leading to difficulty in handling personalized image generation in the open domain. This provides necessary data assurance for generating highly controllable, high-quality images guided by descriptive text. On the other hand, by searching for target images corresponding to entity markers in the image library, and generating images corresponding to descriptive text based on entity markers, their corresponding entity location information, and target images, it ensures that the generated images are highly controllable, improving the accuracy of text-based image generation. Furthermore, by searching the image library to determine the target images corresponding to entity markers instead of directly generating more complex entity images, it improves the efficiency and accuracy of text-based image generation.

[0019] The text-based image generation method provided in this application can be applied to devices or electronic devices that generate images based on text. This method is implemented using an end-to-end model; that is, the user only needs to input descriptive text, and the end-to-end model can generate an image corresponding to the descriptive text. The method steps in the text-based image generation method represent the specific working process of the end-to-end model. The general structural framework of the end-to-end model will be described below.

[0020] First, it should be noted that although the accompanying drawings in some parts of this application show grayscale images, it should be understood that all images involved in the embodiments of this application, such as sample images, real images, images corresponding to descriptive text, etc., are actually color images.

[0021] See Figure 1 , Figure 1 This is a training framework structure diagram of an end-to-end model provided in an embodiment of this application. Figure 1 In the middle, locked parts represent the parts that need retraining, and unlocked parts represent the parts that need retraining. For example... Figure 1 As shown, during the training of the end-to-end model, sample images and descriptive text about the sample images serve as inputs to the end-to-end model. The LLM extracts entity markers and entity location information (including bounding box mask information) from the descriptive text. The image retrieval module searches for entity images corresponding to the entity markers, inputs the searched entity images into the image encoder, and inputs the entity location information into the sample image noise addition process. The image encoder encodes the entity images, outputting first embedding information (patch embedding) to the data receiving layer (fuser layer); and outputting second embedding information (cls embedding), which contains more image detail information than the first embedding information, to the text encoder. The text encoder is used to input the second embedding information into the embedding layer of the text encoder. When the text encoder encodes, it first encodes the descriptive text in the first layer, and then the subsequent layers encode based on the second embedding information, and outputs the third embedding information into the key (K) matrix and value (V) matrix of U-net. By using the second embedding information to replace the relevant information of the descriptive text stored in the original embedding layer, the weight learning of the text encoder can be retrained to improve the fidelity of the generated image and the generalization of the descriptive text.

[0022] Meanwhile, a noisy sample image is generated by a variational autoencoder (VAE). During the process of adding noise to the sample image, the detection box mask information output by the LLM model is spliced ​​in, which can enhance the local learning of the topic diffusion model within the detection box to increase image fidelity. The noisy sample image is then input into the convolutional layer of the U-net network, and the noisy detection box mask information (add bboxembedding) is input into the data receiving layer.

[0023] The data receiving layer converts the received information into data that the U-net network can receive and use. Based on the output information from the data receiving layer and the information in the K and V matrices, the U-net network uses a cross-attention map mechanism to generate images until the generated image is identical or nearly identical to the sample image. Training on that sample image is then complete. This model training process is repeated using other sample images until all sample images have been trained. Notably, the U-net network uses a cross-attention mechanism to support multi-entity learning, designing an attention map for each entity. This addresses the problem of entity confusion caused by multiple entities and attributes. For example, an image containing two people sitting side-by-side might be generated as an image containing two identical people sitting side-by-side, which differs from the user's desired image of two different people sitting side-by-side.

[0024] Once the end-to-end model is trained, it can include a text parsing module, an image retrieval module, and a subject diffusion model.

[0025] The text parsing module takes descriptive text as input and outputs entity tags extracted from the descriptive text, along with the corresponding entity positional relationships. The text parsing module may include an LLM (Local Level Management Model).

[0026] The image retrieval module connects to an external image library and is used to search for entity images corresponding to entity labels as target images based on entity labels and / or entity positional relationships, or to search for entity images corresponding to entity labels and having the same bounding box size as the entity positional relationships as target images.

[0027] The topic diffusion model generates an image corresponding to descriptive text based on entity labels, target images, and entity location information with mapping relationships. The model includes an image encoder, a text encoder, a data receiver layer, and a U-net network. The image encoder encodes the image and generates corresponding embedding information. The text encoder encodes the embedding information and / or descriptive text and generates corresponding embedding information. The data receiver layer receives the embedding information output by the text encoder and converts it into data usable by the U-net network. The key and value matrices of the U-net network store the embedding information output by the text encoder. The U-net network uses a cross-attention mechanism to generate an image corresponding to the descriptive text based on the received information, addressing the problem of inaccurate generated images due to loss caused by multiple entities.

[0028] See Figure 2 , Figure 2This is a flowchart illustrating image generation based on text, provided in one embodiment of this application. For example... Figure 2 As shown, the method for generating images based on text may include steps S110 to S130.

[0029] Step S110: In response to receiving descriptive text, extract entity markers and entity location information corresponding to the entity markers from the descriptive text. Entity markers are used to describe entities.

[0030] Descriptive text, also known as text description or, in this field, as prompts, is a coherent arrangement of words and phrases with complete and autonomous meaning, used to describe the image to be generated. The content of descriptive text can include, but is not limited to, entities, the number of entities, entity locations, and logical positional relationships between different entities. Entities typically refer to objects that exist in the real world, such as people, animals, plants, and trees. For example, the descriptive text "A dog is standing on a sheep, two trees are growing on the grass, and a bird is flying in the air" is an example, where "sheep," "dog," "tree," "grass," and "bird" are entities.

[0031] Entity tokens, often referred to as tokens in this field, are keywords extracted from descriptive text to describe entities. For example, keywords such as "sheep," "dog," "tree," "grassland," and "bird" in text are all entity tokens.

[0032] Entity positional relationships can include, but are not limited to, entity positions and logical positional relationships between entities. For example, "A is in front of B" can represent the logical positional relationship between entity A and entity B. In some embodiments, entity positional relationships can be represented using bounding boxes (bboxes). The entity described by the entity marker corresponding to the bounding box is usually located within the bounding box. The bounding box can be a rectangle, including four corner points, each corner point having an image coordinate (i.e., the coordinates of the corner point in the image). The position and size of the bounding box in the image can be represented using the image coordinates of the four corner points. Entity positional relationships can be determined comprehensively based on the image size, the positions of the entities in the descriptive text, and / or the logical positional relationships between entities. In some embodiments, if the descriptive text describes the required size of the generated image, the entity positional relationship can also be determined based on that size, the positions of the entities in the descriptive text, and / or the logical positional relationships between entities. In other embodiments, if the descriptive text does not describe the required size of the generated image, the entity positional relationship can be determined according to the default image size, the positions of the entities in the descriptive text, and / or the logical positional relationships between entities.

[0033] End-to-end models can be deployed in various applications or web pages. Users can input descriptive text into the end-to-end model via keyboard, touchscreen, or voice recognition device. In other words, the method of inputting descriptive text is determined by the actual platform on which the end-to-end model is deployed. For example, if the end-to-end model is deployed in a mobile application, users can input descriptive text by speaking into the phone or by typing on the phone's keyboard. Similarly, if the end-to-end model is deployed on a web page, users can input descriptive text into the web page via keyboard.

[0034] In some embodiments, if the descriptive text input by the user is used only to describe an image, then in response to the received descriptive text, the entity tags extracted from the descriptive text should be used only to describe entities belonging to an image and their positional relationships. The end-to-end model can then generate an image corresponding to the descriptive text based on the descriptive text.

[0035] In other embodiments, the descriptive text input by the user can be used to describe multiple images. The text description of each image can be distinguished using specific rules or tags. In response to the received descriptive text, the end-to-end model can extract multiple descriptive sub-texts from the descriptive text according to specific rules or tags. Each descriptive sub-text corresponds to an image and is used to describe the entities belonging to that image and the positional relationships of the entities. The end-to-end model generates the image corresponding to each descriptive sub-text at a time until all descriptive sub-texts have been generated.

[0036] NLP tools such as Spacy or LLM can be used to extract relevant noun entities from descriptive text, such as entity tags and entity counts. Considering that LLM can extract not only relevant noun entities but also the logical positional relationships between them, this embodiment uses an LLM model to extract entity tags and positional relationships from descriptive text to improve the accuracy of the generated image.

[0037] In some embodiments, the end-to-end model includes an LLM (Limited Linear Model), which can be used to extract entity tags and corresponding entity location information from descriptive text. In response to received descriptive text, the end-to-end model inputs the descriptive text into the LLM model, which can extract entity tags and corresponding entity location relationships from the descriptive text, and outputs the entity tags and entity location relationships.

[0038] In some embodiments, users can input custom rule text into the LLM model according to actual needs, pre-setting information such as the number and location of entities in the generated image, and then input descriptive text. The number of entities in the descriptive text is the same as the number of entities in the custom rule text. Both the custom rule text and the descriptive text need to conform to the language rules of the LLM model. It is understood that although some examples below use English descriptive text, the language of the descriptive text used in this application embodiment can include, but is not limited to, Chinese, English, Russian, and other languages. The specific language used to describe the descriptive text can be determined based on the languages ​​supported by the actual end-to-end model. Typically, end-to-end models support at least two languages, Chinese and English. For example, taking the 2DGPT artificial intelligence model as an example, the user-inputted custom rule text can be as follows: user: 2DGPT is designed to be able to assist with the 2d modeling tasks, 2DGPT is able to generate a 2d object layout using bounding box based on the query it receives, please use the following format: ``` object_description: ['a object description', 'a object description', 'a object description', 'a object description'] Coordinate points: [[0.1, 0.2, 0.5, 0.6], [0.3, 0.4, 0.5, 0.6], [0.5,0.6, 0.9, 0.9], [0.7, 0.8, 1, 1]] description: 'description of the whole scene' ``` Each Coordinate point is normalized and MUST be [0, 1]. In the scene, the point y more close to 1 more close to the ground. The object description should correspond one-to-one with the Coordinated point The size of the bounding box area should match the corresponding common object description size The four coordinate points described by each object description represent the x, y coordinates in the upper left corner of the bounding box, and the x, y coordinates in the lower right corner. The relative size of each object should follow the size scene in the world and attention should be paid to the positional relationship between the top, bottom, left, and right spatial relationship in the description.”。

[0039] Assume that the descriptive text input by the user is "A dog stands on top of a sheep, a tree grows on the grass and a bird is flying in the sky", the LLM model can output the following information: "object_description: ['a dog', 'a sheep', 'a tree', 'grass', 'a bird'] Coordinate points: [[0.1, 0.2, 0.5, 0.6], [0.3, 0.4, 0.5, 0.6], [0.5,0.6, 0.9, 0.9], [0.7, 0.8, 1, 1]] description: 'A dog stands on top of a sheep, a tree grows on thegrass, and a bird is flying in the sky'".

[0040] The keywords following "object_description" are entity tags, and the coordinates following "Coordinate points" represent the entity's positional relationships. For easier understanding, please refer to [link to relevant documentation]. Figure 3 , Figure 3 This is a schematic diagram of a detection frame provided in an exemplary embodiment of this application. Figure 3 As shown, detection boxes 1-4 represent the positional relationships of the four entities in the image.

[0041] Step S120: Search for the target image corresponding to the entity tag in the image library. Each image in the image library corresponds to an entity tag and includes the entity described by the corresponding entity tag.

[0042] The image library is pre-built and can be deployed in the cloud, other databases, or servers accessible to the end-to-end model. The image library stores a large number of entity tags and entity images. Each entity image corresponds to one entity tag and includes the entity described by that entity tag; that is, each entity image contains only one entity.

[0043] The image library has a search function. Entity tags are the search criteria for the image library, and entity images are the search results. That is, by inputting entity tags into the image library, you can search for entity images that correspond to the entity tags.

[0044] In some embodiments, to improve the overall efficiency of text-based image generation by increasing search speed, each entity marker in the image library can be assigned a corresponding entity image. After obtaining the entity markers output by the LLM, the image library can be searched for the entity image corresponding to the entity marker as the target image for that entity marker. In this embodiment, each entity marker corresponds to one target image.

[0045] In other embodiments, to improve the overall efficiency of text-based image generation by accelerating the fusion of entity positional relationships (e.g., detection boxes) and entity images (target images), each entity marker in the image library can be configured to correspond to multiple entity images, with the entities in these multiple images being identical. The only difference between the multiple entity images is their size, which can be determined based on the size of commonly used detection boxes. In this case, based on the entity marker and entity positional relationships, an entity image corresponding to the entity marker and with the same size as the detection box can be searched in the image library as the target image corresponding to that entity marker. This ensures that the target image and the detection box have the same size, improving the efficiency of fusing the detection box and the target image, thereby improving the overall efficiency of image generation. In this embodiment, each entity marker can have multiple target images.

[0046] In other embodiments, to enhance the diversity of text-based image generation, each entity tag in the image library can correspond to multiple entity images, and the entities in the multiple entity images are of the same type, differing only in their style (or action, or entity type within the same entity type). For example, if the entity type is "dog," the multiple entity images can include animated dogs, real-world dogs, sketch-style dogs, or oil painting-style dogs, depending on the entity's style. The multiple entity images can also include standing dogs, running dogs, lying dogs, or crouching dogs, depending on the entity's action. Furthermore, the multiple entity images can include pugs, Labrador Retrievers, Shiba Inus, etc., depending on the entity type within the same entity type. In this embodiment, each entity tag corresponds to multiple target images.

[0047] Step S130: Generate an image corresponding to the descriptive text based on the entity marker, the entity location information corresponding to the entity marker, and the target image corresponding to the entity marker.

[0048] The general topic diffusion model is a breakthrough technology for open-domain personalized image generation. It only requires a reference image and can generate new images without fine-tuning during testing. The topic diffusion model will significantly improve the efficiency and accuracy of image generation. To address the limitation of the general topic diffusion model, which can only accept images as input and generate images from images, this embodiment designs an end-to-end model, introducing a text parsing module (LLM) and an image retrieval module. The topic diffusion model includes an image encoder, a text encoder, a data receiving layer, and a U-net network. This allows the topic diffusion model in this embodiment to generate images based on text, thus overcoming the limitation of the general topic diffusion model, which can only generate images from images, and expanding the application scenarios of the topic diffusion model.

[0049] The target image can be input into an image encoder to obtain the first embedding information (pattern embedding) and the second embedding information (cls embedding) output by the image encoder. The second embedding information includes more detailed image information than the first embedding information. The second embedding information is input into the embedding layer of the text encoder to obtain the third embedding information output by the text encoder. The entity location information, the first embedding information, and the third embedding information are input into the U-net network to obtain the image generated by the U-net network corresponding to the descriptive text.

[0050] Specifically, entity location information and first embedding information can be input into a data receiving layer. This layer converts the format of the entity location information and first embedding information into a format that the U-net network can receive. Third embedding information is input into the key matrix (K matrix) and value matrix (V matrix) of the U-net network. Finally, an image corresponding to the descriptive text, generated by the U-net network using a cross-attention mechanism, is obtained. Since the U-net network cannot directly receive the first embedding information and entity location information, a new data receiving layer (e.g., a fuser layer) is added to the topic diffusion model. This allows the data receiving layer to receive the first embedding information and entity location information and convert the received information into data that the U-net network can receive and use.

[0051] It should be noted that the images corresponding to the descriptive text are usually multiple different images, and users can choose the image they want from among them. For example, assuming the descriptive text is "A dog stands on top of asheep, a tree grows on the grass and a bird is flying in the sky," the generated images corresponding to the descriptive text could include, for example,... Figure 4-13 The 10 different images shown are as follows: Figure 4-13 As shown, all 10 different images include entities from the descriptive text, and the logical positional relationships between different entities are the same in all images, with the positions of the same entities being roughly the same. The differences between the 10 different images lie in the specific actions, styles, colors, and types of entities within them.

[0052] Based on steps S110 to S130, the function of generating highly controllable high-quality images based on text can be realized end-to-end. By constructing an image library containing a large number of entity markers and images (i.e., images containing entities described by entity markers), on the one hand, a large amount of entity image data can be provided for end-to-end text-based image generation, solving the problem of insufficient open domain data leading to difficulty in handling personalized image generation in the open domain, and providing necessary data guarantee for generating highly controllable high-quality images guided by descriptive text. On the other hand, by searching for target images corresponding to entity markers in the image library, and generating images corresponding to descriptive text based on entity markers, their corresponding entity location information, and target images, the generated images can be ensured to be highly controllable, improving the accuracy of text-based image generation. At the same time, by searching the image library to determine the target images corresponding to entity markers instead of directly generating more difficult entity images, the efficiency and accuracy of text-based image generation can be improved.

[0053] In some embodiments, before step S120, or before the end-to-end model is trained, the method for generating images based on text may further include building an image library, see [link to relevant documentation]. Figure 14 , Figure 14 This is a partial flowchart of a method for generating images based on text, provided in another embodiment of this application, such as... Figure 14 As shown, constructing an image library may include the following steps S210 to S230.

[0054] Step S210: Obtain a sample image, which includes at least one entity.

[0055] To generate high-quality images, images with an aesthetic score greater than 5 can be selected as sample images. Sample images can be obtained from LAION-Aesthetics, an open-source dataset of 250 terabytes (TB) containing 5.6 billion images scraped from the Internet.

[0056] Step S220: Segment the sample image to obtain at least one segmented image and at least one entity label, each segmented image corresponding to an entity label and including the entity described by the entity label.

[0057] See Figure 15 , Figure 15 This is a flowchart of step S220 provided in an embodiment of this application. For example... Figure 15 As shown, step S220 may include steps S221 to S224.

[0058] Step S221: Generate descriptive text about the sample image based on the sample image.

[0059] Bootstrapping Language-Image Pretraining (BLIP) can be used to generate descriptive text about sample images. BLIP introduces a multimodal mixture of encoder-decoder (MED) structure, enabling effective multi-task pre-learning and transfer learning. It can effectively learn from sample images and generate descriptive text about them. In other words, by inputting a sample image into BLIP, one can obtain the descriptive text generated by BLIP.

[0060] Step S222: Extract entity labels and entity location information from the descriptive text about the sample image. There is a one-to-one mapping relationship between entity location information and entity labels.

[0061] Natural Language Processing (NLP) tools such as Spacy or LLM can be used to extract entity labels and entity location information from descriptive text about sample images. LLM models include, but are not limited to, ChatGPT and Llama2. Considering that LLM models can extract more logical relationships between entities compared to NLP tools like Spacy, this embodiment uses LLM to extract entity labels and entity location information to improve the accuracy of the generated images.

[0062] Step S223: Generate executable text based on the descriptive text about the sample image, the extracted entity markers, and the entity location information.

[0063] Step S224: Segment the sample image based on the executable text to obtain at least one segmented image and at least one entity label.

[0064] The Segment Anything Model (SAM) can be used to segment sample images based on executable text, yielding segmentation results that may include at least one mask. Based on the segmentation results, at least one segmented image (i.e., a single entity image) and at least one entity label can be separated from the sample image. Each segmented image corresponds to one entity label. The SAM mainly consists of three parts: an image encoder (for calculating image embeddings), a cue encoder (for calculating cue embeddings), and a mask decoder (for real-time mask prediction). When using SAM, the image embedding only needs to be extracted once and can be reused under different cues. Given an image embedding, the cue encoder and mask decoder can predict the mask within 50 milliseconds based on the cue.

[0065] Based on steps S221 to S224, this embodiment of the application constructs an automatic data annotation tool based on LAION-Aesthetics data and the BLIP, DINO, and SAM model frameworks, solving the problem of missing open-domain data. For example, see... Figure 16 , Figure 16 This is a flowchart of step S220 provided in an exemplary embodiment of this application. Figure 16 As shown, when a sample image is input into BLIP, BLIP can output descriptive text about the sample image, such as "arafed red sports car parked in front of a body of water," to LLM and DINO. LLM can then output entity markers and entity location information extracted from the descriptive text to DINO. DINO generates executable text based on the descriptive text, extracted entity markers, and entity location information. This executable text is then input into the SAM model. The SAM model segments the sample image based on the sample image and the executable text, resulting in the following: Figure 16 The structured segmentation result shown includes three masks.

[0066] Step S230: Construct an image library by using at least one entity tag as a search condition and at least one segmented image as a search result.

[0067] An index can be constructed using vector retrieval tools such as Faiss or ScaNN. This involves using at least one entity label as a search condition and at least one segmented image as the search result to build an image library. After constructing the image library, an end-to-end model's image search module can be connected to the library to search for images corresponding to the entity labels.

[0068] Based on steps S210 and S230, an image library containing a large number of entity tags and images (i.e., images of entities containing entity tags) can be constructed. This can provide a large amount of entity image data for end-to-end text-based image generation, solve the problem of insufficient open domain data leading to difficulty in handling personalized image generation in the open domain, and provide the necessary data guarantee for generating highly controllable, high-quality images guided by descriptive text.

[0069] See Figure 17 , Figure 17 This is a flowchart illustrating image generation based on text, provided in another embodiment of this application. For example... Figure 17 As shown, the method for generating images based on text may include steps S310 to S330.

[0070] Step S310: In response to receiving descriptive text, extract entity markers and corresponding detection boxes from the descriptive text. Entity markers are used to describe entities.

[0071] Step S320: For each entity marker, obtain an image with the same detection box size as the entity marker from the searched image corresponding to the entity marker, and use it as the final target image corresponding to the entity marker.

[0072] In this embodiment, when constructing the image library, multiple images corresponding to the same entity label can be stored. The sizes of the multiple images corresponding to the same entity label are different. The sizes of the multiple images corresponding to the same entity label can be determined according to the commonly used detection box sizes. For example, the commonly used detection box sizes are a first size, a second size, and a third size. Therefore, the image library can store three images corresponding to the same entity label, with the sizes of the three images being the first size, the second size, and the third size, respectively. This facilitates the direct search for entity segmentation images with the same detection box size during the image generation process, improving the speed of subsequent fusion of entity segmentation images and detection boxes, thereby significantly improving the efficiency of text-based image generation.

[0073] Step S330: Generate an image corresponding to the descriptive text based on the entity marker, the detection box corresponding to the entity marker, and the target image corresponding to the entity marker.

[0074] In addition to the technical effects of steps S110 to S130, steps S310 to S330 can also construct an image library based on the segmented images of the entity images and the actual labels. By searching for segmented images with the same size as the detection box, the final target image corresponding to the entity label can be obtained directly. This facilitates the subsequent fusion of entity segmented images and detection boxes, thereby significantly improving the efficiency of generating images based on text.

[0075] See Figure 18 , Figure 18 This is a structural block diagram of a text-based image generation device according to an embodiment of this application. The text-based image generation device 100 can be applied to electronic devices. The text-based image generation device 100 may include a feature extraction module 110, an image search module 120, and an image generation module 130.

[0076] The feature extraction module 110 is used to extract entity markers and corresponding entity location information from the received descriptive text in response to receiving the descriptive text. The entity markers are used to describe entities. The specific working process of the feature extraction module 110 can be found in steps S110 and S310.

[0077] The image search module 120 is used to search for target images corresponding to the entity markers in an image library. Each image in the image library corresponds to an entity marker and includes the entity described by the corresponding entity marker. The specific working process of the feature extraction module 110 can be found in steps S120 and S320.

[0078] The image generation module 130 is used to generate an image corresponding to the descriptive text based on the entity marker, the entity location information corresponding to the entity marker, and the target image. The specific working process of the image generation module 130 can be found in steps S130 and S330.

[0079] In some embodiments, the text-based image generation device 100 may further include an image library construction module. This module acquires sample images, each including at least one entity; segments the sample images to obtain at least one segmented image and at least one entity marker, each segmented image corresponding to an entity marker and including the entity described by that marker; and constructs the image library by using the at least one entity marker as a search condition and the at least one segmented image as the search result. The specific operation of the image library construction module can be found in steps S210 to S230.

[0080] In some embodiments, the text-based image generation apparatus 100 may further include a model training module for training a topic diffusion model based on a pre-built image library. The specific operation of the model training module can be found in the section on topic model training in step S130.

[0081] Those skilled in the art will clearly understand that the apparatus provided in the embodiments of this application can implement the methods provided in the embodiments of this application. The specific working process of the described apparatus and modules can be found in the corresponding processes of the methods in the embodiments of this application, and will not be repeated here.

[0082] In the embodiments provided in this application, the coupling, direct coupling, or communication connection between the modules shown or discussed may be indirect coupling or communication coupling through some interfaces, devices, or modules, and may be electrical, mechanical, or other forms. The embodiments of this application do not impose specific limitations on this.

[0083] Furthermore, the functional modules in the embodiments of this application can be integrated into one processing module, or each module can exist physically separately, or two or more modules can be integrated into one module. The integrated modules described above can be implemented in hardware or as software functional modules.

[0084] See Figure 19 , Figure 19 This is a structural block diagram of an electronic device provided in an embodiment of this application. The electronic device 200 may include a memory 210 and a processor 220. The memory 210 stores an application program that is configured to execute the method provided in the embodiment of this application when invoked by the processor 220.

[0085] Processor 220 may include one or more processing cores. Processor 220 uses various interfaces and lines to connect to various parts of the entire electronic device 200, and is used to run or execute instructions, programs, code sets or instruction sets stored in memory 210, as well as to call and run or execute data stored in memory 210, and perform various functions of electronic device 200 and process data.

[0086] The processor 220 can be implemented using at least one of the following hardware forms: Digital Signal Processing (DSP), Field-Programmable Gate Array (FPGA), and Programmable Logic Array (PLA). The processor 220 can integrate one or a combination of several of the following: Central Processing Unit (CPU), Graphics Processing Unit (GPU), and modem. The CPU primarily handles the operating system, user interface, and applications; the GPU is responsible for rendering and drawing the displayed content; and the modem handles wireless communication. It is understood that the modem can also be implemented separately as a communication chip, without being integrated into the processor 220.

[0087] The memory 210 may include random access memory (RAM) or read-only memory (ROM). The memory 210 can be used to store instructions, programs, code, code sets, or instruction sets. The memory 210 may include a program storage area and a data storage area. The program storage area may store instructions for implementing an operating system, instructions for implementing at least one function, instructions for implementing the various method embodiments described above, etc. The data storage area may store data created by the electronic device 200 during use.

[0088] This application embodiment also provides a computer-readable storage medium storing program code that is configured to execute the method provided in this application embodiment when invoked by a processor.

[0089] Computer-readable storage media can be electronic storage devices such as flash memory, electrically erasable programmable read-only memory (EEPROM), erasable programmable read-only memory (EPROM), hard disk, or ROM.

[0090] In some embodiments, the computer-readable storage medium includes a non-volatile computer-readable storage medium (Non-TCRSM). The computer-readable storage medium has storage space for program code that performs any of the method steps described above. This program code can be read from or written to one or more computer program products. The program code may be compressed in an appropriate form.

[0091] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of this application, and are not intended to limit them. Although this application has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some of the technical features. Such modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of this application.

Claims

1. A method for generating images based on text, characterized in that, include: In response to receiving descriptive text, entity markers and entity location information corresponding to the entity markers are extracted from the descriptive text, wherein the entity markers are used to describe entities; Search for the target image corresponding to the entity tag in the image library, where each image in the image library corresponds to an entity tag and includes the entity described by the corresponding entity tag; Based on the entity marker, the entity location information corresponding to the entity marker, and the target image, an image corresponding to the descriptive text is generated; The step of generating an image corresponding to the descriptive text based on the entity marker, the entity location information corresponding to the entity marker, and the target image includes: The target image is input into the image encoder of the topic diffusion model to obtain the first embedding information and the second embedding information output by the image encoder. The second embedding information includes more detailed image information than the first embedding information. The second embedding information is input into the text encoder of the topic diffusion model to obtain the third embedding information output by the text encoder; The entity location information and the first embedded information are input into the data receiving layer of the topic diffusion model. The data receiving layer is used to convert the format of the entity location information and the first embedded information into a format that the U-net network of the topic diffusion model can receive. The third embedded information is input into the key matrix and value matrix of the U-net network; Obtain the image corresponding to the descriptive text generated by the U-net network using a cross-attention mechanism.

2. The method according to claim 1, characterized in that, The entity location information includes a detection box. After searching the image library for the target image corresponding to the entity marker, the method further includes: For each entity marker, an image with the same bounding box size as the entity marker is obtained from the searched images corresponding to that entity marker, and this image is used as the final target image corresponding to that entity marker.

3. The method according to claim 1, characterized in that, Before searching for the target image corresponding to the entity marker in the image library, the method further includes: Acquire a sample image, wherein the sample image includes at least one entity; The sample image is segmented to obtain at least one segmented image and at least one entity label, each segmented image corresponding to an entity label and including the entity described by the entity label; The image library is constructed by using at least one entity tag as a search criterion and at least one segmented image as a search result.

4. The method according to claim 3, characterized in that, The segmentation of the sample image to obtain at least one segmented image and at least one entity label includes: Based on the sample image, generate descriptive text about the sample image; Entity markers and entity location information are extracted from the descriptive text about the sample images, and there is a one-to-one mapping relationship between the entity location information and the entity markers; Executable text is generated based on the descriptive text about the sample image, the extracted entity markers, and the entity location information; The sample image is segmented based on the executable text to obtain at least one segmented image and at least one entity label.

5. The method according to claim 1, characterized in that, The step of extracting entity markers and corresponding entity location information from the descriptive text includes: A large language model is used to extract entity markers and corresponding entity location information from the descriptive text.

6. An apparatus for generating images based on text, characterized in that, include: The feature extraction module is used to extract entity markers and entity location information corresponding to the entity markers from the descriptive text in response to receiving descriptive text, wherein the entity markers are used to describe entities; An image search module is used to search for a target image in an image library that corresponds to the entity tag, wherein each image in the image library corresponds to an entity tag and includes the entity described by the corresponding entity tag; An image generation module is used to generate an image corresponding to the descriptive text based on the entity marker, the entity location information corresponding to the entity marker, and the target image; The step of generating an image corresponding to the descriptive text based on the entity marker, the entity location information corresponding to the entity marker, and the target image includes: The target image is input into the image encoder of the topic diffusion model to obtain the first embedding information and the second embedding information output by the image encoder. The second embedding information includes more detailed image information than the first embedding information. The second embedding information is input into the text encoder of the topic diffusion model to obtain the third embedding information output by the text encoder; The entity location information and the first embedded information are input into the data receiving layer of the topic diffusion model. The data receiving layer is used to convert the format of the entity location information and the first embedded information into a format that the U-net network of the topic diffusion model can receive. The third embedded information is input into the key matrix and value matrix of the U-net network; Obtain the image corresponding to the descriptive text generated by the U-net network using a cross-attention mechanism.

7. An electronic device, characterized in that, include: A memory and a processor, wherein an application program is stored in the memory, the application program being used to perform the method as described in any one of claims 1-5 when invoked by the processor.

8. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores program code that, when invoked by a processor, executes the method as described in any one of claims 1-5.

Citation Information

Patent Citations

  • Image processing method and device, equipment and storage medium

    CN110211205A

  • Image description generation method and device, storage medium and electronic equipment

    CN115810068A