Multi-instance controllable image generation method based on cross attention redistribution

By introducing patch-oriented and region-oriented cross-attention loss into the Vincentian graph model, the diffusion model is guided to generate multi-instance images, which solves the problem of semantic inconsistency in multi-instance image generation in the existing technology and improves the accuracy and application of image generation. Effect.

CN118628611AActive Publication Date: 2024-09-10HANGZHOU DIANZI UNIV

Patent Information

Application Number
CN202410772782.4
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-06-17
Publication Date
2024-09-10
Estimated Expiration
2044-06-17

AI Technical Summary

Technical Problem

Existing Vincentian graph models have problems such as missing entities, attribute exchanges, attribute leaks, and spatial layout errors in multi-instance image generation tasks. It is difficult to generate images that are semantically consistent with text prompts, and model fine-tuning requires a lot of resources.

Method used

Adopt a multi-instance controllable image generation method based on cross-attention redistribution, utilize a pre-trained large language model to generate precise layouts of multi-instance text cues, and guide diffusion through patch-oriented cross-attention and region-oriented cross-attention loss The denoising process of the model produces images that match multi-instance text.

Benefits of technology

It improves the controllability of the generated model and the consistency of images and conditional text, reduces entity missing, attribute exchange, attribute leakage and spatial layout errors, and improves the application effect of image editing and personalized generation.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118628611A
    Figure CN118628611A
Patent Text Reader

Abstract

The invention discloses a multi-instance controllable image generation method based on cross attention redistribution. The method comprises the following steps: firstly, constructing a ChatGPT code prompt chain CoC; and then, using a code prompt chain in ChatGPT to generate a layout required in a multi-instance text prompt generation task. Then, a cross attention map is obtained in each time step of the diffusion model, and two guide losses are obtained based on layout information; and finally, modifying prediction noise on the current time step by using loss guidance, and finally obtaining a generated multi-instance controllable image from a noise image subjected to iterative optimization through a decoder. The problems of entity missing, attribute exchange, attribute leakage, spatial layout errors and the like are relieved, more accurate and high-quality image generation and modification are achieved in the fields of image editing, personalized generation, virtual fitting and the like, and services better meeting personalized requirements are provided for users.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention belongs to the technical field of image generation, and in particular relates to a multi-instance controllable image generation method based on cross-attention reallocation. Background Art

[0002] As a key component in the field of AIGC (artificial intelligence generated content), controllable image generation technology has brought broad application prospects to multiple industries with its ability to precisely manipulate models to generate unprecedented images. Text-to-Image Generation is one of the core research directions in the field of controllable image generation, which can transform the delicate emotions and rich imaginations described in text into vivid visual images. Especially after the emergence of the diffusion model, due to its outstanding performance in generating high-quality and diverse results, a series of large text-to-image models based on the diffusion model have been spawned, such as Imagen, DALL·E 2, and Stable Diffusion (SD). Among them, the SD model is the most classic and advanced open source model at present. After extensive training on billions of text-image pairs, it has shown significant performance improvements.

[0003] Although the large-scale text graph model based on the diffusion model has achieved remarkable results in single-instance image generation, when dealing with multi-instance text prompts with complex layouts and rich attributes, there is a significant misalignment between the semantics of the images generated by the existing text graph model and the text prompts, and there are problems such as missing entities, attribute interchange, attribute leakage, and spatial layout errors. The specific problems are as follows:

[0004] (1) Entity Missing: Some objects are ignored in the generated images.

[0005] (2) Attribute exchange: The attributes of two or more objects are exchanged with each other.

[0006] (3) Property leakage: The property of one object is incorrectly bound to another object.

[0007] (4) Spatial layout errors: There are errors in the spatial relationship or layout in the generated image.

[0008] In the direction of multi-instance image generation tasks, existing research methods are mainly divided into two categories, based on non-training methods and based on model fine-tuning methods. Based on the non-training method, the cross-attention map is modified in each step of the denoising process through certain additional conditions, such as layout, mask, etc., or the loss obtained from the cross-attention map is used to guide the denoising direction towards a direction that is more consistent with the text information. Based on the model fine-tuning method, the original model (such as the SD model) is fine-tuned through some new training data to alleviate the prior loss of the original model during training, or the controllability of the model is enhanced through additional trainable modules. However, the existing research technologies cannot solve the multi-instance generation task well, and fine-tuning the model also requires a larger resource overhead.

[0009] Therefore, in order to further enhance the ability of the generative model, it is necessary to conduct in-depth research to improve the controllability of the diffusion model in multi-instance generation tasks, enhance the consistency between the generated images and conditional texts, and alleviate the occurrence of entity missing, attribute interchange, attribute leakage, spatial layout errors, etc. This will promote the widespread application of AIGC technology in various fields and bring more excellent and accurate results to application scenarios such as image editing, personalized generation, and virtual fitting. Summary of the invention

[0010] To solve the above problems, the present invention provides a method for generating multi-instance controllable images based on cross-attention reallocation, which utilizes a pre-trained large language model (LLM) to generate an accurate layout that conforms to multi-instance text prompts, and uses the cross-attention layer-based loss obtained by the layout information to guide the denoising direction of the diffusion model, and generates images that match the multi-instance text prompts through iterative denoising of the diffusion model.

[0011] A multi-instance controllable image generation method based on cross attention reallocation, the steps of which are as follows:

[0012] Step (1) Build the ChatGPT code prompt chain (Chain-of-Code, CoC).

[0013] Step (2) uses the constructed code prompt chain in ChatGPT to generate a layout that meets the requirements of the task under the condition of multiple instance text prompts.

[0014] Step (3) obtains the cross-attention map in each time step of the diffusion model. At the same time, based on the layout information, two guided losses are obtained: Patch-Oriented Cross-Attention (PCA) loss and Region-Oriented Cross-Attention (RCA) loss.

[0015] Step (4) uses the loss obtained in step (3) to guide the modification of the predicted noise at the current time step, and the iteratively optimized noise image is finally passed through the decoder to obtain the generated multi-instance controllable image.

[0016] The construction of the ChatGPT code hint chain described in step (1) is to predict the accurate layout from multi-instance text hints using LLM. Code Chain (CoC) is an effective extension of Chain of Thoughts (CoT) to enhance the code-driven reasoning of LLM. Its core concept is to encourage LLMs to construct semantic subtasks in the program as flexible pseudocode. Then, at runtime, these pseudocode segments can be explicitly recognized and processed by the code interpreter and LMulator (LLM's code simulator). In the implementation, before predicting the layout, pseudocode and comments related to layout generation are manually provided to LLM. This step aims to illustrate the rules and principles underlying layout generation. Next, LMulator can execute the code according to the guidance of the annotations to predict the layout.

[0017] The CoC hints for layout prediction include three basic components: task instructions, reasoning code, and context examples. Specifically, the code hint chain can be decomposed into the following specific steps:

[0018] Step 1: Use LLM to parse objects based on the input multi-instance text prompts.

[0019] Step 2: Determine the number of objects indicated by the multi-instance text prompt.

[0020] Step 3: Generate a location description for each object. First, the spatial relationship between the objects described in the image is analyzed based on multiple instance text cues. If not explicitly stated, the most likely scenario is inferred. Then, the region where each object is located in the image is specified, such as left, right, top left, etc., to achieve maximum specificity.

[0021] Step 4: Create a layout. Based on the number and location description of the objects, generate a coherent layout for each object in the image. The layout format should be (x1, y1, x2, y2), where (x1, y1) represents the upper left corner coordinates and (x2, y2) represents the lower right corner coordinates.

[0022] In the code hint chain, each step described above will give some corresponding examples to assist ChatGPT in generating and returning content that better meets the required standards, which will be beneficial for the next step.

[0023] In step (2), ChatGPT uses the code hint chain obtained in step (1) to gradually decompose the layout generation task into four progressive subtasks according to the logic of CoC. Each step uses the generation result obtained in the previous step, and finally obtains a layout that is precisely aligned with the multi-instance text hint. At the same time, the content is returned through ChatGPT in this process to determine the combination of entities and their modifiers that need to be paid attention to in the generation process. In this process, the generated layout is defined as a bounding box, each of which corresponds to a text phrase that describes its content. For example, in the phrase "red dog", the "dog" and "red" tokens share the same layout (bounding box).

[0024] Obtaining a cross-attention map at each time step of the diffusion model as described in step (3) is the use of the present invention on a publicly available SD model. The SD model differs from previous diffusion models in that it operates in the latent space of an autoencoder. The encoder ε(·) is trained to convert the image x into a latent space encoding z = ε(x). The decoder D(·) learns to reconstruct the image from the latent code, with the goal of D(ε(x)) ≈ x. Then, a conditional diffusion model ∈ is trained in the latent space. θ (·), Generate latent text embedding τ using CLIP text encoder according to the given multi-instance text prompt P θ (P). During the training of the diffusion model, the mean square reconstruction loss is used:

[0025]

[0026] Among them, ∈ comes from the standard normal distribution N(0,1), t is the time step, z t is the latent variable at time t, τ θ (·) is the pre-trained CLIP text encoder. During inference, the random Gaussian noise z t The iterative denoising is z0, and the final image obtained through the decoder is x′=D(z0).

[0027] In this process, text information is integrated into the image synthesis process, and the text embedding feature f p From the pre-trained CLIP text encoder In which N k Indicates the number of markers, N e Indicates the embedding dimension. Keyword value Sum By p Generated by the projection layer. Given a set of queries Computed from a feature map of resolution h×w, the cross-attention map is defined as:

[0028]

[0029] Among them, N q = h×w and d represents the output dimensions of the key and query value. At the denoising time step t, by reshaping and indexing A, we get A i ∈[0,1] h′×w′ , represents the cross attention map between a topic i and each spatial position in the feature map. In the present invention, an attention map with a dimension of 16×16 is used. The attention map in this dimension has been proven to contain the richest semantic information.

[0030] After obtaining the original cross-attention map, it must pass through a Gaussian smoothing function before the next step can be performed. Since the Gaussian smoothing filter is very effective for noise that obeys the normal distribution, it is often used to eliminate Gaussian noise in the image. At the same time, before performing image processing tasks such as edge detection and feature extraction, it is usually necessary to smooth the image to reduce the impact of noise on subsequent processing. The Gaussian smoothing operation is a two-dimensional convolution operation used to "blur" the image, which can effectively remove high-frequency noise and improve the signal-to-noise ratio of the image. At the same time, since Gaussian smoothing can retain the edge information of the image, it will not cause the edge of the image to be blurred. Gaussian smoothing is similar to a mean filter (if 3×3, all are added together to take the mean, which becomes the pixel value of the middle point), but it uses different kernels to represent the shape of the Gaussian hump. The two-dimensional Gaussian smoothing function can be expressed as:

[0031]

[0032] Therefore, the attention map for loss calculation must go through the following function:

[0033] A←Gaussian Smoothing(A) (4)

[0034] Subsequently, two guided losses are proposed on the layout obtained by step (2) and the attention map A after Gaussian smoothing: patch-oriented cross attention (PCA) loss and region-oriented cross attention (RCA) loss, so that the loss can be used in step (4) to modify the noise predicted at each time step in the denoising process. For the role of each loss, specifically, the PCA loss promotes the assignment of at least one image patch to each token in the layout, while also emphasizing the high activation values ​​of the image patches of all tokens in the attention prompt. In addition, as a complement, the RCA loss focuses on improving the average attention within the layout to increase the probability of generating objects in the region. At the same time, both PCA and RCA losses address the different importance of nouns and modifiers by distinguishing the loss words between nouns and modifiers.

[0035] Patch-Oriented Cross-Attention (PCA) Loss: The PCA loss serves the dual purpose of encouraging at least one image patch to be assigned to each token in a layout while emphasizing boosting the activation values ​​of image patches of all tokens in the attention prompt. This emphasis is crucial as low attention values ​​in these regions may lead to multi-instance generation challenges such as object omission or attribute leakage. When examining a specific text prompt like “two black dogs”, both the label “dog” and the label “black” are associated with multiple (two) layouts. Therefore, the PCA loss first identifies the patch with the highest attention value in the respective layout of each token. Second, the minimum attention value is selected from the extracted patches with the highest attention. Finally, the sum of these minimum attention values ​​for all tokens is calculated. For tokens associated with only one layout, the minimum attention value obtained after performing the maximum calculation operation is directly added to the summation formula. In addition, during the optimization process, the PCA loss distinguishes between loss terms for nouns and modifiers.

[0036] The PCA loss tailored for nouns is mainly used to ensure the generation of objects and is defined as follows:

[0037]

[0038] Among them G n Indicated by k n The set of noun tokens, B i Represents the label i∈G n , The associated layout of time t represents the cross attention map of token i, Indicates B i Here, max computes the attention map The maximum patch attention value within the layout q.

[0039] The PCA loss tailored for modifiers is used to optimize object-related properties and is defined as follows:

[0040]

[0041] Among them G m Indicated by k m A set of modifier tags, B j Denotes a token j∈G m , The relevant layout of , represents the cross-attention map of token j at time t, Indicates B j Here, max computes the attention map The maximum patch attention value within the layout q.

[0042] Region-guided Cross-Attention (RCA) Loss: When some topic tokens in their related layouts show low initial values ​​in the highest attention patch in the original attention map, PCA loss may fail to improve the attention value, resulting in problems such as object omission. To address this limitation, RCA loss is proposed to improve the average attention within the layout. This improvement aims to increase the possibility of generating objects within the region during denoising and alleviate the object omission problem. Similarly, RCA loss distinguishes the loss words of nouns and modifiers during the optimization process.

[0043] The RCA loss tailored for nouns is mainly used to enhance object generation and is defined as follows:

[0044]

[0045] Here, mean calculates the average attention value within layout q, The other symbols are consistent with equation (5).

[0046] The RCA loss tailored for modifiers is used to improve object-related properties and is defined as follows:

[0047]

[0048] Here, mean calculates the average attention value within layout q, The other symbols are consistent with equation (6).

[0049] The loss obtained in step (3) described in step (4) guides the modification of the prediction noise at a certain interval of time steps in the sampling process. Specifically, based on PCA and RCA losses, in the optimization process, the two noun losses are first minimized to optimize the noise sample z t , object generation is prioritized in the early denoising stage. When the two noun losses cannot meet the threshold condition, the noise sample z is optimized by minimizing the two modifier losses. t , the purpose is to refine the attributes related to the object. If the modifier loss also fails to meet the threshold condition, it reverts to minimizing the noun loss to optimize the noise, and alternates between the two as needed. The calculation formula is as follows:

[0050]

[0051] Where a represents the step size for controlling the optimization effect during the denoising process, is defined as:

[0052]

[0053] in for The threshold value, is the threshold of is the threshold of is the threshold of. The observation results show that the attention regions of noun markers are relatively concentrated, while those of modifier markers are relatively dispersed. Therefore, a higher threshold is assigned to the noun loss and a lower threshold is assigned to the modifier loss. To prevent the degradation of image quality due to the continuous optimization strategy during the entire denoising process, the update of the noise sample z t is restricted to the first t' steps, where t' < t and t' represents the number of steps using the noun and modifier losses.

[0054] Advantages of the present invention:

[0055] In the present invention, aiming at some problems existing in the currently widely used SD model in multi-instance generation tasks, such as body missing, entity leakage, attribute confusion, attribute leakage, spatial layout error, interaction relationship error, etc., a new training-free method is proposed to improve text-to-image synthesis. The present invention utilizes the code-chain prompting technology in large language models to directly generate object layouts from the given multi-instance text prompts. Subsequently, two key components are introduced: patch-oriented cross-attention (PCA) loss and region-oriented cross-attention (RCA) loss. These two losses are based on the generated layouts and adjust the noise predicted by the SD model during the sampling process, thereby enhancing the text-image consistency between the generated pictures and the conditional text and alleviating the occurrence of problems such as entity missing, attribute swapping, attribute leakage, spatial layout error, etc.

[0056] Currently, many downstream tasks in the text-to-image direction related to various application scenarios such as image editing, personalized generation, virtual fitting, etc. rely on the original generation ability of the SD model. Therefore, by improving the ability of the SD model in multi-instance generation, the application effects of downstream tasks such as image editing and personalized generation are effectively improved, making the generated or modified images more in line with semantic conditions. Therefore, this invention has important application value and potential economic value. Through the present invention, more accurate and high-quality image generation and modification can be achieved in the fields of image editing, personalized generation, and virtual fitting, providing services that better meet the personalized needs of users. The application prospect of this technology is broad and is expected to be widely applied in industries such as film, game, painting, and virtual reality, bringing more business opportunities and competitive advantages to related enterprises. Brief Description of the Drawings

[0057] Figure 1 is a schematic diagram of the specific process of the method of the present invention;

[0058] Figure 2It is a case demonstration of ChatGPT using CoC code prompt chain in the method of the present invention;

[0059] Figure 3 is the latent variable z at a single time step in the present invention t The process of performing loss-guided optimization. DETAILED DESCRIPTION

[0060] The present invention will be further described below in conjunction with the accompanying drawings and actual cases.

[0061] This paper provides a method for multi-instance controllable image generation based on cross-attention redistribution. The method is divided into two stages: first, a pre-trained large language model (LLM) is used to generate a layout, and second, a novel loss function is proposed to redistribute cross-attention on the SD model based on the generated layout. Experiments are carried out on the T2I-CompBench dataset, and good results are achieved in both qualitative and quantitative experiments.

[0062] like Figure 1 As shown, a method for multi-instance controllable generation capability based on cross-attention improved diffusion model, the steps are as follows:

[0063] Step (1): The user enters a multi-instance text prompt, such as "a man on the right of a wallet".

[0064] Step (2): Construct the code hint chain (CoC) required for ChatGPT to generate layout tasks.

[0065] ChatGPT is a language generation model based on the Transformer model. It learns the probability distribution of language by pre-training a large-scale corpus, and then can generate continuous text related to the input. However, the generation results of ChatGPT may have some problems, such as grammatical errors, incoherence, or failure to meet specific contextual requirements. By building a ChatGPT prompt code chain, additional instructions or information can be introduced into the generation process to guide the model to generate text of a specific type or style. These prompt codes can help the model better understand the task requirements, generate appropriate content, or meet the needs of users.

[0066] The CoC code prompt chain contains three parts: task instructions, reasoning code, and context examples. By using the code chain prompt technology in a large language model, it is possible to generate an accurate description of the object layout directly from multi-instance text prompts.

[0067] Step (3): ChatGPT uses the CoC code prompt chain to generate an accurate layout corresponding to the multi-instance text prompt input by the user. This method can prompt the generated content of ChatGPT to generate an accurate layout that meets the requirements of the multi-instance generation task. Under the above text prompt, the answer returned by ChatGPT using the CoC prompt contains two parts: first, a description of all entities is given, including the quantity information implied by the entity in the given text prompt and an analytical description of where its layout information should be located in the image, as shown in the result ritual2 given by the above text prompt "a man on the right of a wallet"; then, specific entity layout information is given on a canvas of size 256×256, such as LayoutDictionary:{"man-0":(135,35,180,240),"wallet-0":(35,70,120,110)}.

[0068] At the same time, in this process, ChatGPT returns content to determine the entities and their modifier combinations that need to be paid attention to during the generation process. For example, in the text prompt "a man on the left of a wallet", the entity objects that need to be paid attention to are "man" and "wallet"; if the objects that need to be paid attention to in the text prompt "a blue boat and a brown cat" are "blue boat" and "brown cat". This information is used as an index to obtain the corresponding cross-attention map and the corresponding combination of parts of speech, which plays a vital role in the next step of loss calculation.

[0069] By guiding the ChatGPT model to generate object layouts that match multi-instance text prompts, we can better control the generation process and ensure that the generated images meet the expected requirements.

[0070] Step (4): At each time step of the diffusion model, obtain the cross-attention map.

[0071]

[0072] The cross attention maps used in the following steps are all passed through the Gaussian smoothing function, as shown in the formula:

[0073] A←Gaussian Smoothing(A) (2)

[0074] Step (5): Based on the layout information, two key guided losses are calculated: Patch-Oriented Cross-Attention (PCA) loss and Region-Oriented Cross-Attention (RCA) loss. The specific calculation method is as follows: Figure 3 As shown in the blue area. These losses can adjust the noise predicted by the diffusion model at each time step according to the generated layout information, thereby enhancing the consistency between the generated image and the conditional text. Specifically:

[0075] Patch-Oriented Cross-Attention (PCA) Loss: The PCA loss serves the dual purpose of encouraging at least one image patch to be assigned to each token in a layout while emphasizing boosting the activation values ​​of image patches of all tokens in the attention prompt. This emphasis is crucial as low attention values ​​in these regions may lead to challenges in multi-instance generation such as object omission or attribute leakage. When examining a specific text prompt like “two black dogs”, both the label “dog” and the label “black” are associated with multiple (two) layouts. Therefore, the PCA loss first identifies the patch with the highest attention value in the respective layout of each token. Then, the minimum attention value is selected from the extracted patches with the maximum attention. Finally, the sum of these minimum attention values ​​for all tokens is calculated. For tokens associated with only one layout, the minimum attention value obtained after performing the maximum calculation operation is directly added to the summation formula. In addition, during the optimization process, the PCA loss distinguishes between loss terms for nouns and modifiers.

[0076] The PCA loss tailored for nouns is mainly used to ensure the generation of objects and is defined as follows:

[0077]

[0078] Among them G n Indicated by k n The set of noun tokens, B i Represents the label i∈G n , The associated layout of time t represents the cross attention map of token i, Indicates B i Here, max computes the attention map The maximum patch attention value within the layout q.

[0079] The PCA loss tailored for modifiers is used to optimize object-related properties and is defined as follows:

[0080]

[0081] Among them G m Indicated by k m A set of modifier tags, B j Denotes a token j∈G m , The relevant layout of , represents the cross-attention map of token j at time t, Indicates B j Here, max computes the attention map The maximum patch attention value within the layout q.

[0082] Region-guided Cross-Attention (RCA) Loss: When some topic tokens in their related layouts show low initial values ​​in the highest attention patch in the original attention map, PCA loss may fail to improve the attention value, resulting in problems such as object omission. To address this limitation, RCA loss is proposed to improve the average attention within the layout. This improvement aims to increase the possibility of generating objects within the region during denoising and alleviate the object omission problem. Similarly, RCA loss distinguishes the loss words of nouns and modifiers during the optimization process.

[0083] The RCA loss tailored for nouns is mainly used to enhance object generation and is defined as follows:

[0084]

[0085] Here, mean calculates the average attention value within layout q, The other symbols are consistent with equation (3).

[0086] The RCA loss tailored for modifiers is used to improve object-related properties and is defined as follows:

[0087]

[0088] Here, mean calculates the average attention value within layout q, The other symbols are consistent with equation (5).

[0089] Step (6): Since PCA loss and RCA loss have different losses according to different parts of speech, how to organize the final guided loss requires threshold judgment of the losses of different parts of speech. The final loss combination is shown in the formula:

[0090]

[0091] In this process, different thresholds are set for different parts of speech at different time steps, where the noun threshold is higher than the modifier threshold. The larger the time step, the higher the threshold. The reason for setting this threshold is that some existing research and experimental results show that the attention area of ​​noun markers is relatively concentrated, while the attention area of ​​modifier markers is relatively scattered. At the same time, the SD model mainly generates the structure of the image in the early stage of denoising, and is mainly used to increase and optimize the details of the image in the later stage. Therefore, a higher threshold is assigned to the noun loss and a lower threshold is assigned to the modifier loss. At the same time, the thresholds of these losses grow faster in the first few time steps and slower thereafter in order to maintain the position of the previously generated image structure and reduce changes. This progressive update strategy can prevent z t becomes inconsistent with the dataset distribution while promoting more accurate generation.

[0092] Step (7): Using the loss guidance obtained in step (6), modify the prediction noise at the current time step. In this process, the threshold of the current time step is first determined, that is:

[0093] t <t′ (8)

[0094] The constraint on the time step used for loss optimization is to prevent image quality degradation due to continuous optimization strategies throughout the denoising process.

[0095]

[0096] Step (8): After optimizing the prediction noise at the current time step, determine whether the current time step is in the iterative optimization time step, that is, whether t exists in the iterative optimization time step set {0, 5, 10, 20, 30}.

[0097] When t∈{0,5,10,20,30}, determine whether the maximum number of iterative optimization times is reached at this time step. If not, change through formula (10) and return to step (4).

[0098]

[0099] when Or t∈{0,5,10,20,30} and the maximum number of iterative optimizations is reached at this time step, then iterative denoising is performed until the final latent variable z0 is obtained. Finally, the final generated image is obtained through the decoder D(·) Right now:

[0100]

[0101] At the end of the method, the test was conducted on the T2I-CompBench dataset, which includes three categories of tasks: attribute binding, spatial relations, and complex text. These three categories are further divided into six small tasks. Among them, the attribute stick relationship includes color, texture, and shape attribute binding, the spatial relationship includes spatial layout relations and action interaction relations, and finally the complex text is to detect the generation ability in long texts. Very good qualitative and quantitative experimental results were achieved in this dataset. By adjusting the noise during the generation process, the present invention can reduce the occurrence of problems such as entity missing, attribute interchange, attribute leakage, and spatial layout errors, so that the generated image is more in line with the expected requirements.

Claims

1. A multi-instance controllable image generation method based on cross attention reallocation, characterized in that: The steps are as follows: Step 1. Build the ChatGPT code prompt chain CoC; Step 2: Use the code prompt chain in ChatGPT to generate the layout required in the layout generation task under the given multi-instance text prompt; Step 3: Obtain a cross-attention map at each time step of the diffusion model, and obtain two guided losses based on the layout information; Step 4: Use the loss to guide the modification of the predicted noise at the current time step, iterate the optimized noise image, and finally obtain the generated multi-instance controllable image through the decoder.

2. The method for generating multi-instance controllable images based on cross attention reallocation according to claim 1, characterized in that: The code hint chain CoC hint includes task instructions, reasoning code and context examples. The specific implementation process is as follows: Step 1.1, using the large language model LLM to parse the object according to the input multi-instance text prompt; Step 1.2, determining the number of objects indicated by the multi-instance text prompt; Step 1.3, generate a location description for each object: analyze the spatial relationship between the objects described in the image based on the multi-instance text prompts, and then specify the area where each object is located in the image; Step 1.

4. Generate a coherent layout for each object in the image based on the number and location description of the objects. The layout format should be (x1, y1, x2, y2), where (x1, y1) represents the upper left corner coordinate and (x2, y2) represents the lower right corner coordinate.

3. The method for generating multi-instance controllable images based on cross attention reallocation according to claim 2, characterized in that: The specific implementation process of step 2 is as follows: using the code prompt chain in ChatGPT, the layout generation task is gradually decomposed into four progressive subtasks according to the logic of CoC, each step uses the generation result obtained in the previous step, and finally obtains a layout aligned with the multi-instance text prompts; at the same time, in this process, the content is returned through ChatGPT to determine the combination of entities and their modifiers that are concerned in the generation process.

4. The method for generating multi-instance controllable images based on cross attention reallocation according to claim 3, characterized in that: In the process of generating the layout required in the task, the generated layout is defined as bounding boxes, each bounding box corresponds to a text phrase describing its content.

5. The method for generating multi-instance controllable images based on cross attention reallocation according to claim 4, characterized in that: The specific process of obtaining the cross attention map is as follows: The cross-attention map obtained at each time step of the diffusion model is used on the public SD model; the SD model operates in the latent space of an autoencoder; the encoder ε(·) is trained to convert the image x to the latent space code z = ε(x); the decoder D(·) learns to reconstruct the image from the latent code, with the goal of achieving D(ε(x)) ≈ x; then the conditional diffusion model ∈ is trained in the latent space θ (·), Generate latent text embedding τ using CLIP text encoder according to the given multi-instance text prompt P θ (P); During the training of the diffusion model, the mean square reconstruction loss is used: Among them, ∈ comes from the standard normal distribution N(0,1), t is the time step, z t is the latent variable at time t, τ θ (·) is the pre-trained CLIP text encoder; during inference, the random Gaussian noise z t Iterative denoising is z0, and the final image obtained by the decoder is x′=D(z0); In this process, text information is integrated into the image synthesis process, and the text embedding feature f p From the pre-trained CLIP text encoder In the k Indicates the number of markers, N e Indicates the embedding dimension; keyword value Sum By p Generated through the projection layer; given a set of queries Computed from a feature map of resolution h×w, the cross-attention map is defined as: N q = h×w and d represents the output dimensions of the key and query value. At the denoising time step t, by reshaping and indexing A, we get A i ∈[0,1] h′×w′ , represents the cross attention map between a topic i and each spatial position in the feature map; After obtaining the original cross attention map, it passes through the Gaussian smoothing function, and then proceeds to the next step. The attention map of the row loss calculation passes through the following function: A←Gaussian Smoothing(A).

6. The method for generating multi-instance controllable images based on cross attention reallocation according to claim 5, characterized in that: The specific process of obtaining the two guided losses is as follows: Two guided losses are proposed on the layout obtained in step 2 and the attention map A after Gaussian smoothing function: patch-oriented cross-attention PCA loss and region-oriented cross-attention RCA loss; The patch-oriented cross-attention PCA loss: first identify the patch with the highest attention value in the respective layout of each token; second select the minimum attention value from the extracted highest attention patches; finally calculate the sum of these minimum attention values ​​for all tokens; For tokens associated with only one layout, the minimum attention value obtained after performing the maximum calculation operation is directly added to the summation formula; The PCA loss customized for nouns is used to ensure object generation and is defined as follows: Among them G n Indicated by k n The set of noun tokens, B i Represents the label i∈G n , The associated layout of time t represents the cross attention map of token i, Indicates B i The binary mask of the qth layout in , max computes the attention map The maximum patch attention value within the layout q; The PCA loss customized for modifiers is used to optimize the object-related attributes and is defined as follows: Among them G m Indicated by k m A set of modifier tags, B j Denotes a token j∈G m , The relevant layout of , represents the cross-attention map of token j at time t, Indicates B j The binary mask of the qth layout in , max computes the attention map The maximum patch attention value within the layout q; The region-guided cross-attention RCA loss: The RCA loss distinguishes the loss words of nouns and modifiers during the optimization process; The RCA loss customized for nouns is used to enhance object generation and is defined as follows: mean calculates the average attention value within layout q; The RCA loss tailored for modifiers is used to improve object-related properties and is defined as follows:

7. The method for generating multi-instance controllable images based on cross attention reallocation according to any one of claims 1 to 6, characterized in that: The specific implementation process of step 4 is as follows: Based on PCA and RCA losses, in the optimization process, the two noun losses are first minimized to optimize the noise sample z t , object generation is prioritized in the early denoising stage; when the two noun losses cannot meet the threshold condition, the noise sample z is optimized by minimizing the two modifier losses t , if the modifier loss also cannot meet the threshold condition, it returns to minimizing the noun loss to optimize the noise, and alternates between the two. The calculation formula is as follows: Among them, α represents the step size of controlling the optimization influence in the denoising process, is defined as: wherein is 's threshold, is 's threshold, is 's threshold, is 's threshold, and the update of the noise sample z t is limited to the first t' steps, where t' < t and t' represents the number of steps using the noun and modifier losses.

Citation Information

Patent Citations

  • Fundus blood vessel segmentation method based on branch attention and multi-model fusion

    CN111047613A

  • Cross-media cross retrieval method based on attention mechanism and modal dependence

    CN113792167A

  • Cross-domain pedestrian re-identification method based on attention guidance and multi-scale label generation

    CN114092964A

Cited By

  • Multifunctional image generation method convenient to interact

    CN119444912A

  • An interactive and convenient multifunctional image generation method

    CN119444912B

  • Text-guided zero-sample transparent layer and layered image generation method

    CN120070638A

  • Interior design appearance migration method and system based on diffusion model target perception

    CN120107058A

  • Question solving method and system based on chain reasoning and program reasoning fusion

    CN120146180A