Method for generating image, method for training text-to-image model, and computing device

The text-to-image model with self-attention and cross-attention modules effectively addresses the misalignment issue in existing systems, generating high-quality images efficiently by interacting flexibly with text embeddings and reducing computational demands.

WO2026055855A1PCT designated stage Publication Date: 2026-03-19HUAWEI TECH CO LTD
View PDF 5 Cites 0 Cited by

Patent Information

Authority / Receiving Office
WO · WO
Patent Type
Applications
Current Assignee / Owner
Filing Date
2024-09-11
Publication Date
2026-03-19

AI Technical Summary

Technical Problem

Existing text-to-image generative systems often fail to accurately reflect the intended visual content described by the input text, leading to misalignment and inefficiencies in computational demands.

Method used

A method involving a text-to-image model with self-attention, cross-attention, and feed-forward modules that flexibly interact with text embeddings, incorporating a cross-attention module to inject text embeddings into the model, and utilizing adaptive normalization and compression techniques to reduce model size and computational demands while maintaining image generation quality.

Benefits of technology

The proposed method generates images that closely align with the intended visual content described by the text, reduces model size and computational requirements, and enhances training efficiency by streamlining subtasks for improved image generation.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN2024118364_19032026_PF_FP_ABST
    Figure CN2024118364_19032026_PF_FP_ABST
Patent Text Reader

Abstract

The disclosure provides a method for generating an image, a method for training a text-to-image model, and a computing device. The method includes: obtaining a first text; and generating a first image according to the first text and a trained text- to-image model including a first self-attention module, a first cross-attention module, and a first feed-forward module. An input of the first self-attention module includes a first feature related to a random noise, and an output includes a first sequence representation; an input of the first cross-attention module includes a first text embedding and a second feature related to the first sequence representation, and an output includes a second sequence representation; and an input of the first feed-forward module includes a third feature related to the second sequence representation, and an output of the first feed-forward module includes a first image representation.The first image is generated the first image representation.
Need to check novelty before this filing date? Find Prior Art

Description

METHOD FOR GENERATING IMAGE, METHOD FOR TRAINING TEXT-TO-IMAGE MODEL, AND COMPUTING DEVICETECHNICAL FIELD

[0001] The present disclosure relates generally to machine learning, and specifically, to a method for generating an image, a method for training a text-to-image model, and a computing device.BACKGROUND

[0002] Recently, the advancement of text-to-image (T2I) generative systems has started a new era of photorealistic image synthesis, profoundly impacting numerous downstream applications, such as image editing, video generation, three dimensional (3D) assets creation, etc.

[0003] However, when a descriptive text is input into these systems for generating an image, the resulting image may not fully reflect the intended visual content described by the text.SUMMARY

[0004] The present disclosure provides a method for generating an image, a method for training a text-to-image model, and a computing device, to generate the image that reflects the intended visual content described by the text.

[0005] According to a first aspect, a method for generating an image may be provided. The method may be performed by a computing device or a module (such as a chip or a circuit) in the computing device. The method may include: obtaining a first text; and generating a first image according to the first text and a trained text-to-image model including a first self-attention module, a first cross-attention module, and a first feed-forward module. An input of the first self-attention module includes a first feature related to a random noise, and an output of the first self-attention module includes a first sequence representation. An input of the first cross-attention module includes a first text embedding converted from the first text, and a second feature related to the first sequence representation, and an output of the first cross-attention module includes a second sequence representation. An input of the first feed-forward module includes a third feature related to the second sequence representation, and an output of the first feed-forward module includes a first image representation.

[0006] According to the method in the first aspect, the trained text-to-image model may incorporate the cross-attention module to inject the text embedding into the entire model. The trained text-to-image model may flexibly interact with the text embedding. Therefore, the image outputted from the trained text-to-image model may be closely aligned with the text and reflect the intended visual content described by the text. Furthermore, since the trained text-to-image model flexibly interacts with the text embedding, the size of the text-to-image model may be reduced while the generation efficiency may be maintained. Thus, the number of parameters of the trained text-to-image model may be less, and the computational demands in both the training stage and the inference stage may be reduced while maintaining competitive image generation quality to the state-of-the-art image generators.

[0007] In a possible design, the input of the first self-attention module further includes a first condition for generating the first image.

[0008] The first condition may be used to generate the first image, which is another control condition. For example, the first condition may be depth information or depth representation, so that the first image may have the depth information; the first condition may be canny edge information, so that an outline of an object in the first image may be clearer; the first condition may be open-pose information, so that the first image may have richer content; or the first condition may be sketch or other art form information, so that a sketch image or other art form image may be generated. It should be understood that the first condition may not be limited to these examples and may also include other image feature information. The computing device may present some of the first conditions to the user, allowing the user to select the first condition to generate the first image,  and the implementations may also not be limited in the present disclosure. Thus, the image generated by the trained text-to-image under the text control and the first condition control may have the richer content.

[0009] In a possible design, the trained text-to-image model further includes a second self-attention module, a second cross-attention module, and a second feed-forward module, where: an input of the second self-attention module includes a fifth feature that is related to both a first condition for generating the first image and the first feature, and an output of the second self-attention module includes a third sequence representation; an input of the second cross-attention module includes the first text embedding and a sixth feature related to the third sequence representation, and an output of the second cross-attention module includes a fourth sequence representation; an input of the second feed-forward module includes a seventh feature related to the fourth sequence representation, and an output of the second feed-forward module includes a second image representation, and the first image is generated further based on an eighth feature related to the second image representation.

[0010] In this way, when the first condition is encoded, the trained text-to-image model may further incorporate the cross-attention module to inject the text embedding into the process of encoding the first condition. The trained text-to-image model may further flexibly interact with the text embedding. Therefore, the image outputted from the trained text-to-image model may further be closely aligned with the text and reflect the intended visual content described by the text. Also, the image generated by the trained text-to-image under the text control and the first condition control may have the richer content.

[0011] In a possible design, the method further includes: obtaining the first condition.

[0012] In a possible design, the second self-attention module includes a second compressor for compressing the first condition and the first feature.

[0013] In a possible design, the first self-attention module includes a first compressor for compressing the first feature.

[0014] The first or second compressor may provide a more simplified compression process and have the less computing resources, and further may allow the model to manage the computational challenges associated with high-resolution image generation, leading to a significant reduction in training and inference time.

[0015] In a possible design, the trained text-to-image model further includes a multilayer perceptron layer for generating an adaptive normalization parameter according to a current time, and the adaptive normalization parameter includes a first parameter, a second parameter, a third parameter, and a fourth parameter. The first feature includes a normalized representation related to the random noise, the second feature includes a normalized first sequence representation, the trained text-to-image model further includes at least one of a first linear layer or a second linear layer, the first linear layer is used to perform adaptive normalization on a representation related to the random noise according to the first parameter to obtain the first feature, and the second linear layer is used to perform adaptive normalization on the first sequence representation according to the second parameter to obtain the second feature. The third feature includes a normalized second sequence representation, the trained text-to-image model further includes at least one of a third linear layer or a fourth linear layer, the third linear layer is used to perform adaptive normalization on the second sequence representation according to the third parameter to obtain the third feature, and the fourth linear layer is used to perform adaptive normalization on the first image representation according to the fourth parameter to obtain the fourth feature.

[0016] In this way, the multilayer perceptron layer is global. Furthermore, the adaptive normalization parameter may be obtained based on the current time only. Thus, the number of parameters in the text-to-image model may be further reduced.

[0017] In a possible design, generating the first image according to the first text and the trained text-to-image model, includes: processing the first feature using the first self-attention module to obtain the first sequence representation; processing the first text embedding converted from the first text and the second feature related to the first sequence representation using the first cross-attention module to obtain the second sequence representation; processing the third feature related to the second sequence representation using the first feed-forward module to obtain the first image representation; and decoding the fourth feature related to the first image representation to generate the first image.

[0018] According to a second aspect, a method for training a text-to-image model may be provided. The method may be performed by a computing device or a module (such as a chip or a circuit) in the computing device.

[0019] The computing device for performing the method for training a text-to-image model may be the same as the computing device for performing the method for generating an image, or different from the computing device for performing the method for generating an image.

[0020] The method may include: obtaining a sample set including a text sample and an image sample; and training the text-to-image model using the sample set, according to a training condition including minimizing a difference between the image sample and a predicted image output by the text-to-image model, to obtain a trained text-to-image model, the text-to-image model including a first self-attention module, a first cross-attention module, and a first feed-forward module, where: an input of the first self-attention module includes a first training feature related to the image sample, and an output of the first self-attention module includes a first training sequence representation; an input of the first cross-attention module includes a text training embedding converted from the text sample and a second training feature related to the first training sequence representation, and an output of the first cross-attention module includes a second training sequence representation; and an input of the first feed-forward module includes a third training feature related to the second training sequence representation, and an output of the first feed-forward module includes a first training image representation, the predicted image is generated based on a fourth training feature related to the first training image representation.

[0021] In a possible design, the training condition further includes at least one of: maximizing an alignment degree between the predicted image and the text sample; or maximizing an aesthetic quality score of the predicted image.

[0022] The training the text-to-image model may be divided into three streamlined subtasks: (1) learning the pixel distribution of natural images, (2) learning text-image alignment, and (3) enhancing the aesthetic quality of images.

[0023] For the first subtask, the image sample may be a realistic image and include intricate pixel-level dependencies and pixel distribution. The training condition of this subtask is to minimize the difference between the image sample and the predicted image output by the text-to-image model. Therefore, the text-to-image model may learn the pixel distribution of natural images. In this subtask, the text-to-image model may be initialized with a low-cost class-condition model, significantly reducing the learning cost.

[0024] For the second subtask, the training condition of this subtask is to maximize an alignment degree between the predicted image and the text sample. In this subtask, the text-to-image model may learn text-image alignment. Precise alignment learning is required for understanding how to generate images that accurately match the text description. The alignment degree between the predicted image and the text sample may be obtained by a corresponding machine learning model. For example, the predicted image and the text sample may be inputted to such a machine learning model and the correlation degree between the predicted image and the text sample may be outputted.

[0025] For the third subtask, the training condition of this subtask is to maximize an aesthetic quality score of the predicted image. In this subtask, the text-to-image model may learn aesthetic quality of images. The aesthetic quality score may be obtained by a corresponding machine learning model. For example, the predicted image may be inputted to such a machine learning model and the aesthetic quality score may be outputted.

[0026] Thus, minimizing the difference between the image sample and the predicted image is initializing the text-to-image model, maximizing the alignment degree between the predicted image and the text sample is fine-tuning the text-to-image model, and maximizing the aesthetic quality score of the predicted image is further fine-tuning the text-to-image model. Compared with the conventional manner that entangles these three problems (the pixel distribution of natural images, text-image alignment, and the aesthetic quality of images) together and directly trains the text-to-image model from scratch using vast amount of data, resulting in inefficient training, the method in the embodiments of the present disclosure may boost the training efficiency and need less training data.

[0027] In a possible design, the input of the first self-attention module further includes a first condition for generating the predicted image.

[0028] In a possible design, the text-to-image model further includes a second self-attention module, a second cross-attention module, and a second feed-forward module, where: an input of the second self-attention module includes a fifth training feature that is related to both a first condition for generating the predicted image and the first training feature, and an  output of the second self-attention module includes a third training sequence representation; an input of the second cross-attention module includes the text training embedding and a sixth training feature related to the third training sequence representation, and an output of the second cross-attention module includes a fourth training sequence representation; and an input of the second feed-forward module includes a seventh training feature related to the fourth training sequence representation, and an output of the second feed-forward module includes a second training image representation, and the predicted image is generated further based on an eighth training feature related to the second training image representation.

[0029] In a possible design, the second self-attention module includes a second compressor for compressing the first condition and the first training feature.

[0030] In a possible design, the method further includes: obtaining the first condition.

[0031] In a possible design, the first self-attention module includes a first compressor for compressing the first training feature.

[0032] In a possible design, the text-to-image model further includes a multilayer perceptron layer for generating an adaptive normalization parameter according to a current time, and the adaptive normalization parameter includes a first parameter, a second parameter, a third parameter, and a fourth parameter. The first training feature includes a normalized representation related to the image sample, the second training feature includes a normalized first training sequence representation, the text-to-image model further includes at least one of a first linear layer or a second layer, the first linear layer is used to perform adaptive normalization on a representation related to the image sample according to the first parameter to obtain the first training feature, and the second linear layer is used to perform adaptive normalization on the first training sequence representation according to the second parameter to obtain the second training feature. The third training feature includes a normalized second training sequence representation, the text-to-image model further includes at least one of a third linear layer or a fourth linear layer, the third linear layer is used to perform adaptive normalization on the second training sequence representation according to the third parameter to obtain the third training feature, and the fourth linear layer is used to perform adaptive normalization on the third image representation according to the fourth parameter to obtain the fourth training feature.

[0033] In a possible design, the method further includes: obtaining the image sample; and inputting a prompt and the image sample into a vision-language model to obtain the text sample.

[0034] According to a third aspect, a computing device is provided and configured to perform the method or design in the first aspect, or the method or design in the second aspect.

[0035] According to a fourth aspect, a computing device is provided and includes a processor and a memory storing executable instructions which, when executed by the processor, cause the computing device to perform the method or design in the first aspect, or the method or design in the second aspect.

[0036] According to a fifth aspect, a computer-readable storage medium is provided. The computer-readable storage medium has instructions stored thereon, which when executed by a computing device, cause the computing device to perform the method or design in the first aspect, or the method or design in the second aspect.

[0037] According to a sixth aspect, a computer program product. The computer program product is for storing instructions which, when executed, cause a computing device to perform the method or design in the first aspect, or the method or design in the second aspect.

[0038] This disclosure encompasses various embodiments, including not only method embodiments, but also other embodiments such as apparatus embodiments and embodiments related to non-transitory computer readable storage media. Embodiments may incorporate, individually or in combinations, the features disclosed herein.BRIEF DESCRIPTION OF THE DRAWINGS

[0039] For a better understanding of the present disclosure, as well as other aspects and further features thereof, reference is made to the following description which is to be used in conjunction with the accompanying drawings, where:

[0040] FIG. 1 illustrates an example of a computing device that may be used to implement any of the methods described herein;

[0041] FIG. 2 illustrates a text-to-image model, in accordance with at least some non-limiting embodiments of the present disclosure;

[0042] FIG. 3 is a flowchart of a method performed by a processor of the computing device of FIG. 1 for training a text-to-image model, in accordance with at least some non-limiting embodiments of the present disclosure;

[0043] FIG. 4 illustrates an example architecture for training a text-to-image model, in accordance with at least some non-limiting embodiments of the present disclosure;

[0044] FIG. 5 illustrates another example architecture for training a text-to-image model, in accordance with at least some non-limiting embodiments of the present disclosure;

[0045] FIG. 6 illustrates yet another example architecture for training a text-to-image model, in accordance with at least some non-limiting embodiments of the present disclosure;

[0046] FIG. 7 illustrates an example architecture for implementing a base block in FIG. 4, 5, or 6, in accordance with at least some non-limiting embodiments of the present disclosure;

[0047] FIG. 8 is a flowchart of a method performed by a processor of the computing device of FIG. 1 for generating an image, in accordance with at least some non-limiting embodiments of the present disclosure;

[0048] FIG. 9 illustrates a text-to-image model for generating an image, in accordance with at least some non-limiting embodiments of the present disclosure.DETAILED DESCRIPTION

[0049] The examples and conditional language recited herein are principally intended to aid the reader in understanding the principles of the present disclosure and not to limit its scope to such specifically recited examples and conditions. It will be appreciated that a person skilled in the art may devise various arrangements which, although not explicitly described or illustrated herein, nonetheless embody the principles of the present disclosure and are included within its spirit and scope.

[0050] Moreover, all statements herein reciting principles, aspects, and implementations of the present disclosure, as well as specific examples thereof, are intended to encompass both structural and functional equivalents thereof, whether they are currently known or developed in the future. Thus, for example, it will be appreciated by a person skilled in the art that any block diagrams herein represent conceptual views of illustrative circuitry embodying the principles of the present disclosure. Similarly, it will be appreciated that any flowcharts, flow diagrams, state transition diagrams, pseudo-code, and the like represent various processes which may be substantially represented in computer-readable media and so executed by a computer or processor, whether or not such computer or processor is explicitly illustrated.

[0051] The functions of the various elements illustrated in the figures, including any functional block labeled as a "processor" , may be provided through the use of dedicated hardware as well as hardware capable of executing software in association with appropriate software. When provided by a processor, the functions may be provided by a single dedicated processor, by a single shared processor, or by a plurality of individual processors, some of which may be shared. In some embodiments of the present disclosure, the processor may be a general-purpose processor, such as a central processing unit (CPU) or a processor dedicated to a specific purpose, such as a digital signal processor (DSP) . Moreover, explicit use of the term a "processor" should not be construed to refer exclusively to hardware capable of executing software, and may implicitly include, without limitation, application specific integrated circuit (ASIC) , field programmable gate array (FPGA) , read-only memory (ROM) for storing software, random access memory (RAM) , and non-volatile storage. Other hardware, conventional and / or custom, may also be included.

[0052] Software modules, or simply modules which are implied to be software, may be represented herein as any combination of flowchart elements or other elements indicating performance of process steps and / or textual description. Such modules may be executed by hardware that is expressly or implicitly illustrated. Moreover, it should be understood that module may include for example, but without being limitative, computer program logic, computer program instructions, software, stack, firmware, hardware circuitry or a combination thereof which provides the required capabilities.

[0053] With these fundamentals in place, we will first introduce some technologies discussed in some non-limiting examples to illustrate various implementations of aspects of the present disclosure.

[0054] FIG. 1 illustrates a diagram of a computing device in accordance with at least some embodiments of the present disclosure.

[0055] In some embodiments, the computing device 100 may be implemented by any of a conventional personal computer, a computer dedicated to operating and / or monitoring systems related to a data center, a controller and / or an electronic device (such as, but not limited to, a mobile device, a tablet device, a server, a controller unit, a control device, a monitoring device etc. ) and / or any combination thereof appropriate to the relevant task at hand.

[0056] As shown in FIG. 1, the computing device 100 includes various hardware components including one or more single or multi-core processors collectively represented by a processor 110, a solid-state drive 120, a random-access memory 130 and an input / output interface 150.

[0057] The computing device 100 may be an “off the shelf” generic computer system. The computing device 100 may also be specifically dedicated to the implementation of the present disclosure. In some embodiments, the computing device 100 may also be distributed amongst multiple systems. As a person skilled in the art of the present disclosure may appreciate, multiple variations as to how the computing device 100 is implemented may be envisioned without departing from the scope of the present disclosure.

[0058] Communication between the various components of the computing device 100 may be enabled by one or more internal and / or external buses 160 (e.g. a peripheral component interconnect (PCI) bus, universal serial bus, institute of electrical and electronics engineers (IEEE) 1394 “Firewire” bus, small computer system interface (SCSI) bus, serial advanced technology attachment (Serial-ATA) bus, aeronautical radio incorporated (ARINC) bus, etc. ) , to which the various hardware components are electronically coupled.

[0059] The input / output interface 150 may allow enabling networking capabilities such as wire or wireless access. As an example, the input / output interface 150 may include a networking interface such as, but not limited to, a network port, a network socket, a network interface controller and the like. Multiple examples of how the networking interface may be implemented will become apparent to the person skilled in the art of the present disclosure. For example, but without being limitative, the networking interface may implement specific physical layer and data link layer standard such as Ethernet, Fibre Channel, Wi-Fi or Token Ring. The specific physical layer and the data link layer may provide a base for a full network protocol stack, allowing communication among small groups of computers on the same local area network (LAN) and large-scale network communications through routable protocols, such as Internet Protocol (IP) .

[0060] In some embodiments, the solid-state drive 120 stores program instructions suitable for being loaded into the random-access memory 130 and executed by the processor 110 for operating data centers based on a generated machine learning pipeline. For example, the program instructions may be part of a library or an application.

[0061] In some embodiments, the computing device 100 may be implemented as part of a cloud computing device. Broadly, a cloud computing device is a type of computing that relies on a network of remote servers hosted on the Internet, for example, to store, manage, and process data, rather than a local server or personal computer. This type of computing may allow users to access data and applications from remote locations, and provide a scalable, flexible, and cost-effective solution for data storage and computing. Cloud computing devices can be divided into three main categories: Infrastructure as a Service (IaaS) , Platform as a Service (PaaS) , and Software as a Service (SaaS) . In an IaaS environment, users can rent virtual servers, storage, and other computing resources from a third-party provider, for example. In a PaaS environment, users have access to a platform for developing, running, and managing applications without having to manage the underlying infrastructure. In a SaaS environment, users can access pre-built software applications that are hosted by a third-party provider, for example. In summary, cloud computing devices may offer a range of benefits, including cost savings, scalability, increased agility, and the ability to quickly deploy and manage applications.

[0062] The computing device 100 may implement artificial intelligence (AI) , such as a text-to-image model. The text-to-image model discussed herein may employ a diffusion transformer (DiT) architecture. The DiT architecture may integrate a  transformer into a diffusion model for generating an image according to a text. This integration leverages sequence modeling capabilities of the transformer and the generative power of the diffusion model. In detail, the transformer may capture a sequence of features of the text and inject these features into the entire diffusion model. Further, the transformer may also capture features of image latent representation. The features of image latent representation may also be combined into the diffusion model to contribute to generate the high-quality image. Consequently, the diffusion model may generate a high-quality image that is closely aligned with the text and reflects the intended visual content described by the text.

[0063] However, the text-to-image model using the DiT architecture often features complex architectures and a large number of parameters. With such complex architectures and large number of parameters, the sequence of features of the text may not be fully injected into the entire diffusion model, leading to the generated image that is not sufficiently aligned with the text and not fully reflect the intended visual content described by the text.

[0064] In view of this, a text-to-image model is proposed. For example, as illustrated in FIG. 2, the first model 210 may be the text-to-image model using the DiT architecture. The first model 210 may include a plurality of base blocks 211, 212, 213, and 214. It should be noted that the base blocks 211, 212, 213, and 214 in the first model 210 are examples only, and the number of the plurality of base blocks in the first model 210 may be 2, 6, 8, 10, 12, 14, or the like, which is not limited in the present disclosure.

[0065] The plurality of base blocks 211, 212, 213, and 214 may be linked tandemly. Information may be passed through these base blocks 211, 212, 213, and 214 to obtain the image, where through these base blocks 211, 212, 213, and 214, the noise may be progressively added under the control of the text, until the noise is completely corrupted, each step on the adding progressively is governed by a transition probability distribution, the inverse process of removing the noise may be learned, and data may be reconstructed to generate the image. Each of the plurality of base blocks 211, 212, and 213 may include a self-attention module, a cross-attention module, and a feed-forward module, where the cross-attention module is positioned between the self-attention module and the feed-forward module and is configured to receive the sequential feature of the text such as the text embedding and inject the sequential feature of the text into the corresponding base block. In FIG. 2, a text embedding may be injected into each of the base blocks 211, 212, 213, and 214. Therefore, the sequential feature of the text may be injected fully into the entire diffusion model, and the generated image is sufficiently aligned with the text and fully reflects the intended visual content described by the text.

[0066] It should be noted that the feature in the above description, and the embedding, the representation, or the like in the following description may be data in a numerical form, which may be processed by a machine learning model, such as a vector, a matrix, or the like.

[0067] In the following, a method for training the text-to-image model is described. With reference to FIG. 3, which illustrates a flowchart diagram of a method 300 for training a text-to-image model in accordance with at least some non-limiting embodiments of the present disclosure. The method 300 may be performed by the processor 110 of the computing device 100. As illustrated in FIG. 3, the method 300 may include steps 310 and 320.

[0068] In step 310, a sample set including a text sample and an image sample is obtained.

[0069] According to certain non-limiting embodiments of the present disclosure, the method 300 commences at step 310 with the processor 110 being configured to obtain the sample set including the text sample and the image sample.

[0070] In some examples, the processor 110 may be configured to obtain the image sample and input a prompt and the image sample into a vision-language model to obtain the text sample. For example, the processor 110 may be configured to access existing image samples and select the image sample from the existing image samples. The processor 110 may be further configured to obtain a prompt inputted by a user, which indicates to label the image, and input the prompt and the image sample into the vision-language model to obtain the text sample. The prompt may be, for example, "Describe this image and its style in a very detailed manner" . The vision-language model may be any existing vision-language model for labeling the image. Also, the vision-language model may be implemented in the computing device 100 or outside of the computing device 100. In this way, the richer text sample corresponding to the image sample may be obtained effectively and fast.

[0071] In step 320, the text-to-image model is trained using the sample set, according to a training condition including minimizing a difference between the image sample and a predicted image output by the text-to-image model, to obtain a trained text-to-image model.

[0072] According to certain non-limiting embodiments of the present disclosure, the method 300 commences at step 320 with the processor 110 being configured to train the text-to-image model using the sample set, according to a training condition of minimizing a difference between the image sample and a predicted image output by the text-to-image model, to obtain a trained text-to-image model.

[0073] In some examples, the processor 110 may be configured to: obtain a text training embedding converted from the text sample and a first training feature related to the image sample; input the text training embedding and the first training feature into the text-to-image model; receive a predicted image from the text-to-image model; obtain a trained text-to-image model when a difference between the image sample and the predicted image meets the training condition; and obtain another sample set and return to step 310.

[0074] The text-to-image model includes a first self-attention module, a first cross-attention module, and a first feed-forward module.

[0075] An input of the first self-attention module includes the first training feature, and an output of the first self-attention module includes a first training sequence representation. For example, the image sample may be encoded to obtain the representation of the image sample and the representation of the image sample is added with the random noise. The representation of the image sample added with the random noise may be used as the first training feature, or the representation of the image sample added with the random noise may be normalized and the normalized representation may be used as the first training feature.

[0076] An input of the first cross-attention module includes the text training embedding and a second training feature related to the first training sequence representation, and an output of the first cross-attention module includes a second training sequence representation. For example, the first training sequence representation may be used as the second training feature, or the first training sequence representation may be normalized, and the normalized first training sequence representation may be used as the second training feature.

[0077] An input of the first feed-forward module includes a third training feature related to the second training sequence representation, and an output of the first feed-forward module includes a first training image representation. For example, the second training sequence representation may be used as the third training feature, or the second training sequence representation may be normalized, and the normalized second training sequence representation may be used as the third training feature.

[0078] It should be noted that the first training feature related to the image sample may be encoded by the text-to-image model, under the control of the text sample, to obtain the first training image representation.

[0079] The predicted image is generated based on a fourth training feature related to the first training image representation. For example, the first training image representation may be used as the fourth training feature, or the first training image representation may be normalized, and the normalized first training image representation may be used as the fourth training feature. In detail, the fourth training feature may be decoded by the text-to-image model to obtain the predict image.

[0080] According to the method for training the text-to-image in the at least some non-limiting embodiments of the present disclosure, the text-to-image model is trained. The trained text-to-image model may incorporate the cross-attention module to inject the text embedding into the entire model. The trained text-to-image model may flexibly interact with the text embedding. Therefore, the image outputted from the trained text-to-image model may be closely aligned with the text and reflect the intended visual content described by the text. Furthermore, since the trained text-to-image model flexibly interacts with the text embedding, the size of the text-to-image model may be reduced while the generation efficiency may be maintained. Thus, the number of parameters of the trained text-to-image model may be less, and the computational demands in both the training stage and the inference stage may be reduced while maintaining competitive image generation quality to the state-of-the-art image generators.

[0081] According to certain non-limiting embodiments of the present disclosure, the training condition further includes at least one of: maximizing an alignment degree between the predicted image and the text sample; or maximizing an aesthetic quality score of the predicted image.

[0082] The training the text-to-image model may be divided into three streamlined subtasks: (1) learning the pixel distribution of natural images, (2) learning text-image alignment, and (3) enhancing the aesthetic quality of images.

[0083] For the first subtask, the image sample may be a realistic image and include intricate pixel-level dependencies and pixel distribution. The training condition of this subtask is to minimize the difference between the image sample and the predicted image output by the text-to-image model. Therefore, the text-to-image model may learn the pixel distribution of natural images. In this subtask, the text-to-image model may be initialized with a low-cost class-condition model, significantly reducing the learning cost.

[0084] For the second subtask, the training condition of this subtask is to maximize an alignment degree between the predicted image and the text sample. In this subtask, the text-to-image model may learn text-image alignment. Precise alignment learning is required for understanding how to generate images that accurately match the text description. The alignment degree between the predicted image and the text sample may be obtained by a corresponding machine learning model. For example, the predicted image and the text sample may be inputted to such a machine learning model and the correlation degree between the predicted image and the text sample may be outputted.

[0085] For the third subtask, the training condition of this subtask is to maximize an aesthetic quality score of the predicted image. In this subtask, the text-to-image model may learn aesthetic quality of images. The aesthetic quality score may be obtained by a corresponding machine learning model. For example, the predicted image may be inputted to such a machine learning model and the aesthetic quality score may be outputted.

[0086] According to the method for training the text-to-image in certain non-limiting embodiments of the present disclosure, minimizing the difference between the image sample and the predicted image is initializing the text-to-image model, maximizing the alignment degree between the predicted image and the text sample is fine-tuning the text-to-image model, and maximizing the aesthetic quality score of the predicted image is further fine-tuning the text-to-image model. Compared with the conventional manner that entangles these three problems (the pixel distribution of natural images, text-image alignment, and the aesthetic quality of images) together and directly trains the text-to-image model from scratch using vast amount of data, resulting in inefficient training, the method in the embodiments of the present disclosure may boost the training efficiency and need less training data.

[0087] According to certain non-limiting embodiments of the present disclosure, the input of the first self-attention module further includes a first condition for generating the predicted image.

[0088] The first condition may be used to generate the predicted image, which is another control condition. For example, the first condition may be depth information or depth representation, so that the generated image may have the depth information; the first condition may be canny edge information, so that an outline of an object in the generated image may be clearer; the first condition may be open-pose information, so that the generated image may have richer content; or the first condition may be sketch or other art form information, so that a sketch image or other art form image may be generated. It should be understood that the first condition may not be limited to these examples and may also include other image feature information. The computing device 100 may present some of the first conditions to the user, allowing the user to select the first condition to generate the generated image, and the implementations may also not be limited in the present disclosure.

[0089] According to the method for training the text-to-image in certain non-limiting embodiments of the present disclosure, the image generated by the trained text-to-image under the text control and the first condition control may have the richer content.

[0090] According to certain non-limiting embodiments of the present disclosure, the text-to-image model further includes a second self-attention module, a second cross-attention module, and a second feed-forward module. An input of the second self-attention module includes a fifth training feature that is related to both a first condition for generating the predicted image and the first training feature, and an output of the second self-attention module includes a third training sequence representation.  The first condition for generating the predicted image and the first training feature may be used as the fifth training feature, or the first condition for generating the predicted image and the first training feature may be both normalized to obtain the fifth training feature.

[0091] An input of the second cross-attention module includes the text training embedding and a sixth training feature related to the third training sequence representation, and an output of the second cross-attention module includes a fourth training sequence representation. The third training sequence representation may be used as the sixth training feature, or the third training sequence representation may be normalized, and the normalized third training sequence representation may be used as the sixth training feature.

[0092] An input of the second feed-forward module includes a seventh training feature related to the fourth training sequence representation, and an output of the second feed-forward module includes a second training image representation. The fourth training sequence representation may be used as the seventh training feature, or the fourth training sequence representation may be normalized, and the normalized fourth training sequence representation may be used as the seventh training feature.

[0093] The predicted image is generated based on the fourth training feature related to the first training image representation and an eighth training feature related to the second training image representation. The second training image representation may be used as the eighth training feature, or the second training image representation may be normalized, and the normalized second training image representation may be used as the eighth training feature.

[0094] The second self-attention module may be a copy of the first self-attention module, or a reduced copy of the first self-attention module, or an extended copy of the first self-attention module. The second cross-attention module may be a copy of the first cross-attention module, or a reduced copy of the first cross-attention module, or an extended copy of the first cross-attention module. The second feed-forward module may be a copy of the first feed-forward module, or a reduced copy of the first feed-forward module, or an extended copy of the first feed-forward.

[0095] According to the method for training the text-to-image in certain non-limiting embodiments of the present disclosure, when the first condition is encoded, the trained text-to-image model may further incorporate the cross-attention module to inject the text embedding into the process of encoding the first condition. The trained text-to-image model may further flexibly interact with the text embedding. Therefore, the image outputted from the trained text-to-image model may further be closely aligned with the text and reflect the intended visual content described by the text. Also, the image generated by the trained text-to-image under the text control and the first condition control may have the richer content.

[0096] According to certain non-limiting embodiments of the present disclosure, the second self-attention module includes a second compressor for compressing the first condition and the first training feature.

[0097] In detail, the first condition or the first training feature may be a matrix, which may be divided into patches, each of which is compressed, for example, a patch that is 2 units wide and 2 units tall is compressed into a patch that is 1 unit wide and 1 unit tall. The compressed first condition or the first training feature may be converted into matrixes Q, K, and V linearly. The Q, K, and V are processed by the second self-attention module to obtain the final output of the second self-attention module.

[0098] Alternatively, the first condition or the first training feature may be converted into matrixes Q, K, and V linearly. K and V may be compressed. Q and the compressed K and V are processed by the second self-attention module to obtain the final output of the second self-attention module.

[0099] Furthermore, the patch compressing may be replaced with the convolution manner for compressing.

[0100] The second compressor may provide a more simplified compression process and have the less computing resources, and further may allow the model to manage the computational challenges associated with high-resolution image generation, leading to a significant reduction in training and inference time.

[0101] According to certain non-limiting embodiments of the present disclosure, the method further includes: obtaining the first condition. The related description may refer to the above description about the first condition.

[0102] According to certain non-limiting embodiments of the present disclosure, the first self-attention module includes a first compressor for compressing the first training feature. The related description may refer to the above description about the second compressor. Also, the first training feature may also be a matrix.

[0103] According to certain non-limiting embodiments of the present disclosure, the text-to-image model further includes a multilayer perceptron layer (MLP) for generating an adaptive normalization parameter according to a current time, and the adaptive normalization parameter includes a first parameter, a second parameter, a third parameter, and a fourth parameter. The first training feature includes a normalized representation of the image sample added with the random noise. The second training feature includes a normalized first training sequence representation. The text-to-image model further includes at least one of a first linear layer or a second layer, the first linear layer is used to perform adaptive normalization on the representation of the image sample added with the random noise according to the first parameter to obtain the first training feature, and the second linear layer is used to perform adaptive normalization on the first training sequence representation according to the second parameter to obtain the second training feature. The third training feature includes a normalized second training sequence representation. The text-to-image model further includes at least one of a third linear layer or a fourth linear layer, the third linear layer is used to perform adaptive normalization on the second training sequence representation according to the third parameter to obtain the third training feature, and the fourth linear layer is used to perform adaptive normalization on the third image representation according to the fourth parameter to obtain the fourth training feature.

[0104] According to the method for training the text-to-image in certain non-limiting embodiments of the present disclosure, the MLP layer is global. Furthermore, the adaptive normalization parameter may be obtained based on the current time only. Thus, the number of parameters in the text-to-image model may be further reduced.

[0105] Furthermore, the MLP and the first to fourth linear layers may also be applied to the second self-attention module, the second cross-attention module, and the second feed-forward module, and the same content may not be repeated herein.

[0106] In the following, example architectures for training a text-to-image model may be described to understand the method 300.

[0107] With reference to FIG. 4, there is depicted a first example architecture 400 for training a text-to-image model, in accordance with at least some non-limiting embodiments of the present disclosure.

[0108] According to certain non-limiting embodiments of the present disclosure, the architecture 400 may include a text-to-image model represented by the first model 210. The first model 210 may be configured in the computing device 100. For example, the first model 210 may include a set of program instructions stored in the solid-state drive 120 and loaded into the random-access memory 130 and executed by the processor 110 for realizing the text-to-image process. An input of the first model 210 may include a first training feature 203, and a text training embedding which may be output from a text encoder 202 that is separated from the first model 210 or integrated into the first model 210, and an output of the first model 210 may include a predict image.

[0109] The text encoder 202 is configured to access a text sample 201. For example, the text sample 201 may be a text description of "a small cactus with a happy face in the Sahara desert" , etc. The text encoder 202 may be further configured to encode the text sample 201 to output the text training embedding. In some implementations, the text encoder 202 may be configured in the computing device 100, which may also include a set of program instructions stored in the solid-state drive 120 and loaded into the random-access memory 130 and executed by the processor 110 for realizing the text encoding. In other implementations, the text encoder 202 may be configured outside of the computing device 100. For example, the text encoder 202 may be configured in another computing device. The computing device 100 may access the text sample 201, send the text sample 201 to the another computing device, and receive the text training embedding from the another computing device via the input / output interface 150. Furthermore, any existing text encoder or future text encoder may be utilized, which is not limited herein. In FIG. 4, it is illustrated that the text encoder 202 is separated from the first model 210, and the text encoder 202 that is integrated into the first model 210 may be understood for a person skilled in the art with reference to FIG. 4.

[0110] When the text training embedding and the first training feature 203 are inputted into the first model 210, the base block 211 may be configured to receive the text training embedding and the first training feature 203, and perform encoding  based on the text training embedding and the first training feature 203 to obtain a first encoded result where the first encoded result may be an intermediate representation generated by the first model 210, and output the first encoded result to the following base block, such as the base block 212. The base block 212 may be configured to receive the first encoded result from the prior base block such as the base block 211 and the text training embedding, and perform encoding based on the text training embedding and the first encoded result to obtain a first training image representation, and output the first training image representation. When there is one base block for encoding, the first encoded result may be used as the first training image representation, and when there are more than two base blocks for encoding, the output of the last base block may be used as the first training image representation. The text training embedding may be inputted into each base block in the first model 210.

[0111] In the , the base block 213 may be configured to receive the text training embedding and the first training image representation, and perform decoding based on the text training embedding and the first training image representation, to output a first decoded result. The base block 214 may be configured to receive the text training embedding and the first decoded result, and perform decoding based on the text training embedding and the first decoded result to output the predict image. When there is one base block for decoding, the first decoded result may be used as the predict image, and when there are more than two base blocks for decoding, the output of the last base block may be used as the predict image.

[0112] It should be further noted that the number of the base blocks for encoding or decoding depends on the actual design and may refer to the above description.

[0113] The base blocks in the first model 210 have identical architectures and distinct parameters, or the base blocks in the first model 210 have distinct architectures and parameters, which depends on the actual design.

[0114] The details about the base blocks may be illustrated in FIG. 7. It should be understood that FIG. 7 illustrates the details about the base block 211, and other base blocks may be obtained and understood according to the principle illustrated in FIG. 7 and the connection relationship illustrated in FIG. 4.

[0115] According to certain non-limiting embodiments of the present disclosure, as illustrated in FIG. 7, the base block 211 may include a first self-attention module 2112, a first cross-attention module 2114, and a first feed-forward module 2116.

[0116] In FIG. 7, the image sample 208 may be inputted into the image encoder 209, and the image encoder 209 may output the image representation. The image representation may be added with the random noise to obtain a representation related to the image sample. The representation related to the image sample is inputted into the first linear layer 2111. The first linear layer 2111 is used to receive the representation related to the image sample and perform adaptive normalization on the representation related to the image sample according to the first parameter to obtain the normalized representation related to the image sample as the first training feature. The first training feature is inputted into a first compressor 21121 in the first self-attention module 2112 for compressing the first training feature. The first self-attention module 2112 may be configured to process based on the output of the first compressor 21121 to output a first training sequence representation.

[0117] The first training sequence representation may be inputted into the second linear layer 2113. The second linear layer 2113 is used to perform adaptive normalization on the first training sequence representation to obtain the normalized first training sequence representation as the second training feature related to the first training sequence representation.

[0118] The first cross-attention module 2114 may be configured to receive the text training embedding and the second training feature related to the first training sequence representation, and output a second training sequence representation.

[0119] When these is one base block for encoding, the second training sequence representation may be inputted into the third linear layer 2115. The third linear layer 2115 is used to perform adaptive normalization on the second training sequence representation to obtain the normalized second training sequence representation as the third training feature related to the second training sequence representation. The first feed-forward module 2116 may also include a compressor 21161 for compressing the third training feature. The first feed-forward module 2116 in this one base block may be configured to output the first training image representation. The first training image representation is inputted into the fourth linear layer 2117. The fourth linear layer 2117 is used to perform adaptive normalization on the first training image representation to obtain the normalized first training image representation as the fourth training feature related to the first training image representation.

[0120] When there are a plurality of base blocks for encoding, the first feed-forward module 2116 in the last base block may be configured to output the first training image representation. Accordingly, each of the plurality of base blocks may also include the linear layers and compressors.

[0121] When the first model 210 is configured to generate the image with a higher resolution, for example, from a resolution of approximately 1 kilopixel in horizontally to a resolution of approximately 4 kilopixel in horizontally, the first model 210 may handle a larger quantity of information. That is, when the image with the higher resolution is required, the size of the first training feature 203 may be increased. Therefore, the compressors may need to compress the first training feature 203. The compressing process may refer to the above description.

[0122] According to certain non-limiting embodiments of the present disclosure, the architecture 400 may further include a MLP layer 205 configured to obtain an adaptive normalization parameter according to a current time 204. The MLP layer 205 is global, that is, all base blocks in the first model 210 share the same adaptive normalization parameter. Furthermore, the adaptive normalization parameter may be obtained based on the current time only. Thus, the number of parameters in the first model 210 may be further reduced.

[0123] The adaptive normalization parameter may include a first parameter, a second parameter, a third parameter, and a fourth parameter.

[0124] For example, the adaptive normalization parameter, outputted by the MLP layer 205, may be denoted by a tuple of  where i represents the current time underlying the diffusion process,  and may be the first parameter and include scale and shift parameters,  may be the second parameter and includes a scale parameter,  and may be the third parameter and include scale and shift parameters, and may be the fourth parameter and includes a scale parameter. For a certain time i, the first linear layer is denoted by E represents a block-specific embedding and relates to the certain block. The second linear layer is denoted by The third linear layer is denoted by The fourth linear layer is denoted by That is, in this example, a block-specific MLP in the convention model is replaced with the global MLP layer and layer-specific embedding.

[0125] Furthermore, the first self-attention module 2112 may employ the residual structure, and the input of the first self-attention module 2112 may be added with the output of the first self-attention module 2112, and an added result may be inputted into the first cross-attention module 2114. Also, the first cross-attention module 2114 may employ the residual structure, and the input of the first cross-attention module 2114 may be added with the output of the first cross-attention module 2114, and an added result may be inputted into the first feed-forward module 2116. Furthermore, the first feed-forward module 2116 may employ the residual structure, and the input of the feed-forward module 2116 may be added with the output of the feed-forward module 2116.

[0126] With reference to FIG. 5, there is depicted another example architecture 500 for training a text-to-image model, in accordance with at least some non-limiting embodiments of the present disclosure.

[0127] According to certain non-limiting embodiments of the present disclosure, the architecture 500 may include a text-to-image model presented by a first model 210 and a second model 220. In other words, the first model 210 and the second model 220 together implement the functionality of the text-to-image model. The details about the first model 210 may refer to the corresponding description in the example architecture, which is not repeated herein.

[0128] According to certain non-limiting embodiments of the present disclosure, the second model 220 may also include a plurality of base blocks, such as base blocks 221 and 222.

[0129] For example, the second model 220 may be a copy of a portion of the first model 210. With reference to FIG. 5, the base block 221 is a copy of the base block 211, and the base block 222 is a copy of the base block 212. In this case, the base block 221 and the base block 211 may have the same structure and different parameters, and the base block 222 and the base block 212 may have the same structure and different parameters.

[0130] For another example, the second model 220 may be a reduced copy of a portion of the first model 210. With reference to FIG. 5, the base block 221 is a reduced copy of the base block 211, and the base block 222 is a reduced copy of the base block 212. In this case, the width or dimensionality of the base block 221 is less than that of the base block 211, such as the number of parameters in the base block 221 is less than the number of parameters in the base block 211; and the width or dimensionality of the base block 222 is less than that of the base block 212. Also, the second model 220 may be an expanded copy of a portion of the first model 210, and details will not be repeated.

[0131] When the second model 220 is the copy, the reduced copy, or the expanded copy, of the portion of the first model 210, it may ensure consistency and speed up the model establishment.

[0132] According to certain non-limiting embodiments of the present disclosure, an input of the second model 220 may include the first training feature 203 and the first condition. Alternatively, the input of the second model 220 may include the first training feature 203, the first condition, and the text training embedding. The text training embedding may be inputted into each of base blocks in the second model 220. An output of the second model 220 may include a second training image representation.

[0133] The first condition is inputted into a zero linear layer 208 and is outputted from the zero linear layer 208 and inputted into the base block 221. The zero linear layer 208 may refer to a type of layer in the text-to-image model where weights are all initialized to zero, or a layer that has no effect on the input due to having zero weights. The zero linear layer may be used for specific model designs or as part of an initialization strategy. Alternatively, first condition is inputted into the base block 221 directly.

[0134] The first condition and the first training feature 203 may be added and then inputted into the base block 221. The base block 221 may be configured to receive the text training embedding, the first condition, and the first training feature 203, and perform encoding based on the text training embedding, the first condition, and the first training feature 203 to obtain a second encoder result, and output the second encoded result to the following base block, such as the base block 222. The base block 221 may further be configured to output the second encoded result to the first model 210 via a zero linear layer 223. The first encoded result output from the base block 211 and the second encoded result output from the base block 221 may be added and then are inputted into the base block 212 for further processing.

[0135] The base block 222 may be configured to receive the second encoded result from the prior base block such as the base block 221 and the text training embedding, and perform encoding based on the text training embedding and the second encoded result to obtain a second training image representation, and output the second training image representation. The base block 222 may further be configured to output the second training image representation to the first model 210 via a zero linear layer 224. The first training image representation output from the base block 212 and the second training image representation output from the base block 222 may be added and then are inputted into the base block 213 for further processing to obtain the predict image.

[0136] In detail, the base block 221 or the base block 222 may include a second self-attention module, a second cross-attention module, and a second feed-forward module. The details about the second self-attention module, the second cross-attention module, and the second feed-forward module may refer to the first self-attention module, the first cross-attention module, and the first feed-forward module in FIG. 7, which are not repeated herein.

[0137] According to the certain non-limiting embodiments of the present disclosure, the second self-attention module includes a second compressor for compressing the first condition and the first training feature, which may refer to the first compressor and is not repeated herein.

[0138] With reference to FIG. 6, there is depicted yet another example architecture 600 for training a text-to-image model, in accordance with at least some non-limiting embodiments of the present disclosure.

[0139] According to certain non-limiting embodiments of the present disclosure, the architecture 600 may include the text-to-image model presented by the first model 210 and the second model 220. In other words, the first model 210 and the second model 220 together implement the functionality of the text-to-image model. The details about the first model 210 may refer to the corresponding description in the implementations illustrated in FIGS. 4 and 7, which is not repeated herein.

[0140] The different between the architecture 500 and the architecture 600 may be that in the architecture 500, the second model 220 may be connected into the first base blocks in the first model 210, but in the architecture 600, the second model 220 may be connected into the last base blocks in the first model 210 via skip-connections.

[0141] It should be noted that the MLP layer 205 may be applied to both the first model 210 and the second model 220 in the architecture 500 and the architecture 600.

[0142] It should be noted that the text-to-image model may include at least following applications.

[0143] In an example application, the computing device 100 may release the text-to-image model to the public to provide an online service for the public. The users may access the text-to-image model through a subscription, a webpage, or the like. In this case, the computing device 100 may be the general-purpose computing device, and the users may not need to know about the backend hardware and software architecture for realizing the first model 110 in the computing device 100. The users may simply call the service via a web page or an application programming interface (API) , or the like. Furthermore, other developers may also be allowed to integrate the first model 110 into their own applications or services via the API.

[0144] In an example application, the computing device 100 may be implemented as an end-user device, such as a smartphone or tablet. The user may install the text-to-image model in the end-user device and input the text into the end-user device. The end-user device may output and display the image via the installed text-to-image model to the user.

[0145] In an example application, the text-to-image model may be customized software packages for specific industries or fields. These customized software packages may be installed in the computing device 100. The computing device 100 may have specific hardware or may be integrated with an existing system, to install the customized software packages. The user in specific industries or fields may use the computing device 100 to realize the text-to-image function of the text-to-image model.

[0146] In an example application, the computing device 100 may be installed with programs such as design software, image editing software, or other related applications, and the text-to-image model may be used as a plugin or extension for these programs. The user may directly invoke the text-to-image model while using these programs.

[0147] In an example application, if the text-to-image model requires specific hardware support, the computing device 100 may be a proprietary hardware device that has the text-to-image model built-in, such as a personal digital assistant (PDA) or an in-vehicle mobile device.

[0148] In an example application, the computing device 100 may provide the cloud-based text-to-image model services using the text-to-image model, allowing users to access powerful computing resources over the Internet to generate high-quality images.

[0149] In an example application, the computing device 100 may offer, based on the text-to-image model, custom development services based on customer needs, which may include both software and hardware customization.

[0150] It should be noted that a person skilled in the art may apply the text-to-image model into other applications in a suitable manner while nonetheless remaining within the scope of the present disclosure. The above example applications are examples and may not limit the applications of the present disclosure.

[0151] It should be noted that the embodiments of the present disclosure is not limited to a specific implementation of the diffusion transformer architecture. Instead, the embodiments of the present disclosure may be applied to any suitable diffusion transformer architecture currently available or developed in the future. This includes any variants, modifications, or improvements of the diffusion transformer architecture, ensuring flexibility and adaptability in the applications of the present disclosure.

[0152] In the following, a method for generate an image using the above trained text-to-image model is described. With reference to FIG. 8, there is depicted a flowchart diagram of a method for generate an image in accordance with at least some non-limiting embodiments of the present disclosure. The method 800 may be performed by the processor 110 of the computing device 100, or the method 800 may be performed by a processor of another computing device. As illustrated in FIG. 8, the method 800 may include steps 810 and 820.

[0153] In step 810, a first text is obtained.

[0154] According to certain non-limiting embodiments of the present disclosure, the method 800 commences at step 810 with the processor 110 being configured to obtain the first text.

[0155] For example, the processor 110 may be configured to obtain the first text inputted by the user where the user may input the first text into the computing device 100 or obtain the first text from another computing device where the user may input the first text into the another computing device.

[0156] In step 820, a first image is generated according to the first text and a trained text-to-image model including a first self-attention module, a first cross-attention module, and a first feed-forward module.

[0157] According to certain non-limiting embodiments of the present disclosure, step 820 may include: converting the first text into the first text embedding and generating the first image according to the first text embedding and the trained text-to-image model. In detail, the processor 110 may be configured to input the first text into the text encoder and receive the first text embedding from the text encoder, and input the first text embedding into the trained text-to-image model, and receive the first image from the trained text-to-image model.

[0158] An input of the first self-attention module includes a first feature related to a random noise, and an output of the first self-attention module includes a first sequence representation. The first feature includes a representation related to the random noise or a normalized representation related to the random noise. When using the text-to-image model to generate the first image, the first feature may include the random noise, which may be preset or generated by the computing device 100. Alternatively, the first feature may include the representation that is converted from a preset image and added with the random noise. The preset image may be outputted by the user, and the user wants to change the preset image using the text-to-image model. Or, the preset image may be preset or generated by the computing device 100. The preset image may be converted by an image encoder to obtain the image representation, and the random noise may be added into the image representation to form the first feature. Furthermore, the first feature may be preset.

[0159] An input of the first cross-attention module includes a first text embedding converted from the first text, and a second feature related to the first sequence representation, and an output of the first cross-attention module includes a second sequence representation. The second feature may include the first sequence representation or a normalized first sequence representation.

[0160] An input of the first feed-forward module includes a third feature related to the second sequence representation, and an output of the first feed-forward module includes a first image representation. The third feature may include the second sequence representation or a normalized second sequence representation.

[0161] The first image is generated based on a fourth feature related to the first image representation.

[0162] According to certain non-limiting embodiments of the present disclosure, step 820 may include: processing the first feature using the first self-attention module to obtain the first sequence representation; processing the first text embedding converted from the first text and the second feature related to the first sequence representation using the first cross-attention module to obtain the second sequence representation; processing the third feature related to the second sequence representation using the first feed-forward module to obtain the first image representation; and decoding the fourth feature related to the first image representation to generate the first image.

[0163] For example, the processor 110 may be configured to process the first feature using the first self-attention module to obtain the first sequence representation. Furthermore, the processor 110 may be configured to process the first text embedding converted from the first text and the second feature related to the first sequence representation using the first cross-attention module to obtain the second sequence representation. In addition, the processor 110 may be configured to process the third feature related to the second sequence representation using the first feed-forward module to obtain the first image representation. The processor 110 may be configured to decode the fourth feature related to the first image representation to generate the first image.

[0164] For example, as illustrated in FIG. 9, the base block 211 may include the first self-attention module 2112, the first cross-attention module 2114, and the first feed-forward module 2116. Also, the base block 212 may include the first self-attention module 2122, the first cross-attention module 2124, and the first feed-forward module 2126; the base block 213 may include the first self-attention module 2132, the first cross-attention module 2134, and the first feed-forward module 2136;  and the base block 214 may include the first self-attention module 2142, the first cross-attention module 2144, and the first feed-forward module 2146. The details about first self-attention modules 2112, 2122, 2132, and 2142, first cross-attention module 2114, 2124, 2134, and 2144, and first feed-forward module 2116, 2126, 2136, and 2146 may refer to the related description in FIGS. 4 to 7.

[0165] The process of obtaining the first image representation and the process of decoding the first image representation to generate the first image may refer to the above first model 210.

[0166] According to certain non-limiting embodiments of the present disclosure, the input of the first self-attention module further includes a first condition for generating the first image.

[0167] According to certain non-limiting embodiments of the present disclosure, the trained text-to-image model further includes a second self-attention module, a second cross-attention module, and a second feed-forward module.

[0168] An input of the second self-attention module includes a fifth feature that is related to both a first condition for generating the first image and the first feature, and an output of the second self-attention module includes a third sequence representation. An input of the second cross-attention module includes the first text embedding and a sixth feature related to the third sequence representation, and an output of the second cross-attention module includes a fourth sequence representation. An input of the second feed-forward module includes a seventh feature related to the fourth sequence representation, and an output of the second feed-forward module includes a second image representation. The first image is generated further based on an eighth feature related to the second image representation.

[0169] For example, as illustrated in FIG. 9, the base block 221 may include the second self-attention module 2212, the second cross-attention module 2214, and the second feed-forward module 2216. Also, the base block 222 may include the second self-attention module 2222, the second cross-attention module 2224, and the second feed-forward module 2226. The details about second self-attention modules 2212 and 2222, second cross-attention module 2214 and 2224, and second feed-forward module 2216, and 2226 refer to the related description in FIGS. 4 to 7.

[0170] The process of obtaining the second image representation may refer to the description about the above second model 220. The process of generating the first image may also refer to the description about the above second model 220.

[0171] According to certain non-limiting embodiments of the present disclosure, the second self-attention module includes a second compressor for compressing the first condition and the first feature.

[0172] According to certain non-limiting embodiments of the present disclosure, the method 800 may include: obtaining the first condition. In detail, the processor 110 may be configured to obtain the first condition inputted by the user where the user may input the first condition into the computing device 100 or obtain the first condition from another computing device where the user may input the first condition into the another computing device.

[0173] According to certain non-limiting embodiments of the present disclosure, the first self-attention module includes a first compressor for compressing the first feature.

[0174] The second compressor, the first condition, and the first compressor may refer to the above description, which will not be repeated here.

[0175] According to certain non-limiting embodiments of the present disclosure, the trained text-to-image model further includes a multilayer perceptron layer for generating an adaptive normalization parameter according to a current time, and the adaptive normalization parameter includes a first parameter, a second parameter, a third parameter, and a fourth parameter.

[0176] The first feature may include a normalized representation related to the random noise. The second feature may include a normalized first sequence representation. The trained text-to-image model may further include at least one of a first linear layer or a second linear layer, the first linear layer is used to perform adaptive normalization on a representation related to the random noise according to the first parameter to obtain the first feature, and the second linear layer is used to perform adaptive normalization on the first sequence representation according to the second parameter to obtain the second feature.

[0177] The third feature may include a normalized second sequence representation. The trained text-to-image model may further include at least one of a third linear layer or a fourth linear layer, the third linear layer is used to perform adaptive normalization on the second sequence representation according to the third parameter to obtain the third feature, and the fourth  linear layer is used to perform adaptive normalization on the first image representation according to the fourth parameter to obtain the fourth feature.

[0178] Also, the adaptive normalization parameter may be applied in the second self-attention module, the second cross-attention module, and the second feed-forward module. For example, the fifth feature may include the normalization first condition and first feature. The sixth feature may include the normalization third sequence representation. The seventh feature may include the normalization fourth sequence representation. The eighth feature may include the normalization second image representation.

[0179] Some implementations of the present disclosure provide a computer-readable storage medium (e.g., a non-transitory computer-readable storage medium) . The computer-readable storage medium has stored thereon program instructions that, when run on a computing device, cause the computing device to execute one or more steps of the above methods.

[0180] For example, the computer-readable storage medium includes, but is not limited to, a magnetic storage device (e.g., a hard disk, a floppy disk or a magnetic tape) , an optical disk (e.g., a compact disk (CD) , or a DVD) , a smart card, and a flash memory device (e.g., an erasable programmable read-only memory (EPROM) , a card, a stick or a key driver) . Various computer-readable storage media described in the embodiments of the present disclosure may represent one or more devices and / or other machine-readable storage media, which are used for storing information. The term "computer-readable storage medium" may include, but is not limited to, wireless channels and various other media capable of storing, containing and / or carrying instructions and / or data.

[0181] Some implementations of the present disclosure further provide a computer program product. The computer program product includes program instructions carried on a non-transitory computer-readable storage medium. When executed on a computing device, the computer program instructions cause the computing device to perform one or more steps of the above methods.

[0182] Beneficial effects of the computer-readable storage medium and the computer program product are the same as the beneficial effects of the method for data transmission as described in some of the above embodiments, and details will not be repeated here.

[0183] In the present disclosure, the terms “a” or “an” are defined to mean “at least one” , that is, these terms do not exclude a plural number of items, unless stated otherwise.

[0184] In the present disclosure, unless stated otherwise, the terms “connected” and “coupled” , and derivatives and variants thereof, refer herein to any structural or functional connection or coupling, either direct or indirect, between two or more elements. For example, connection or coupling between the elements can be acoustical, mechanical, optical, electrical, thermal, logical, or any combinations thereof.

[0185] In the present disclosure, the expression “based on” is intended to mean “based at least partly on” , that is, this expression can mean “based solely on” or “based partially on” , and so should not be interpreted in a limited manner. More particularly, the expression “based on” could also be understood as meaning “depending on” , “representative of” , “indicative of” , “associated with” or similar expressions.

[0186] In the present disclosure, the terms “system” and “network” may be used interchangeably in different embodiments of this disclosure. “At least one” means one or more, and “aplurality of” means two or more. The term “and / or” describes an association relationship of associated objects, and indicates that three relationships may exist. For example, A and / or B may indicate the following three cases: Only A exists, both A and B exist, and only B exists, where A and B may be singular or plural. The character “ / ” indicates an “or” relationship between associated objects. “At least one of the following items (pieces) ” or a similar expression thereof indicates any combination of these items, including a single item (piece) or any combination of a plurality of items (pieces) . For example, “at least one of A, B, or C” includes: only A; only B; only C; A and B; A and C; B and C; or A, B, and C, and “at least one of A, B, and C” may also be understood as including: only A; only B; only C; A and B; A and C; B and C; or A, B, and C. In addition, unless otherwise specified, ordinal numbers such as “first” and “second” in embodiments of this disclosure are used to distinguish between a plurality of objects, and are not used to limit a sequence, a time sequence, priorities, or importance of the plurality of objects.

[0187] A person skilled in the art should understand that embodiments of this disclosure may be provided as a method, an apparatus (or system) , a computer-readable storage medium (e.g., a non-transitory computer-readable storage medium) , or a computer program product. Therefore, this disclosure may use a form of a hardware-only embodiment, a software-only embodiment, or an embodiment with a combination of software and hardware. Moreover, this disclosure may use a form of a computer program product that is implemented on one or more computer-usable storage media (including but not limited to a disk memory, an optical memory, and the like) that include computer-usable program code.

[0188] This disclosure is described with reference to the flowcharts and / or block diagrams of the method, the device (system) , and the computer program product according to this disclosure. It should be understood that computer program instructions may be used to implement each process and / or each block in the flowcharts and / or the block diagrams and a combination of a process and / or a block in the flowcharts and / or the block diagrams. The computer program instructions may be provided for a general-purpose computer, a dedicated computer, an embedded processor, or a processor of another programmable data processing device and enable a machine to execute the instructions. When executed by any computer or the processor of a programmable data processing device, the instructions cause the apparatus to implement specific functions as described in one or more procedures in the flowcharts and / or one or more blocks in the block diagrams. The computer program instructions may alternatively be stored in a computer-readable memory that can indicate a computer or another programmable data processing device to work in a specific manner, so that the instructions stored in the computer-readable memory generate an artifact that includes an instruction apparatus. The instruction apparatus implements a specific function in one or more procedures in the flowcharts and / or one or more blocks in the block diagrams.

[0189] The computer program instructions may alternatively be loaded onto a computer or another programmable data processing device, so that a series of operations and steps are performed on the computer or the another programmable device, so that computer-implemented processing is generated. Therefore, the instructions executed on the computer or on another programmable device provide steps for implementing specific functions as described in one or more procedures in the flowcharts and / or one or more blocks in the block diagrams.

[0190] Modifications and improvements to the above-described implementations of the present disclosure may become apparent to a person skilled in the art. The foregoing description is intended to be exemplary rather than limiting. The scope of the present disclosure is therefore intended to be limited solely by the scope of the appended claims.

Claims

1.A method for generating an image, the method comprising:obtaining a first text; andgenerating a first image according to the first text and a trained text-to-image model comprising a first self-attention module, a first cross-attention module, and a first feed-forward module, wherein:an input of the first self-attention module comprises a first feature related to a random noise, and an output of the first self-attention module comprises a first sequence representation;an input of the first cross-attention module comprises a first text embedding converted from the first text, and a second feature related to the first sequence representation, and an output of the first cross-attention module comprises a second sequence representation; andan input of the first feed-forward module comprises a third feature related to the second sequence representation, and an output of the first feed-forward module comprises a first image representation,wherein the first image is generated based on a fourth feature related to the first image representation.2.The method of claim 1, wherein the input of the first self-attention module further comprises a first condition for generating the first image.3.The method of claim 1, wherein the trained text-to-image model further comprises a second self-attention module, a second cross-attention module, and a second feed-forward module, wherein:an input of the second self-attention module comprises a fifth feature that is related to both a first condition for generating the first image and the first feature, and an output of the second self-attention module comprises a third sequence representation;an input of the second cross-attention module comprises the first text embedding and a sixth feature related to the third sequence representation, and an output of the second cross-attention module comprises a fourth sequence representation;an input of the second feed-forward module comprises a seventh feature related to the fourth sequence representation, and an output of the second feed-forward module comprises a second image representation,wherein the first image is generated further based on an eighth feature related to the second image representation.4.The method of claim 3, wherein the second self-attention module comprises a second compressor for compressing the first condition and the first feature.5.The method of any one of claims 2 to 4, further comprising:obtaining the first condition.6.The method of any one of claims 1 to 5, wherein the first self-attention module comprises a first compressor for compressing the first feature.7.The method of any one of claims 1 to 6, wherein the trained text-to-image model further comprises a multilayer perceptron layer for generating an adaptive normalization parameter according to a current time, and the adaptive normalization parameter comprises a first parameter, a second parameter, a third parameter, and a fourth parameter,wherein the first feature comprises a normalized representation related to the random noise, the second feature comprises a normalized first sequence representation, the trained text-to-image model further comprises at least one of a first linear layer or a second linear layer, the first linear layer is used to perform adaptive normalization on a representation related to the random noise according to the first parameter to obtain the first feature, and the second linear layer is used to perform adaptive normalization on the first sequence representation according to the second parameter to obtain the second feature,wherein the third feature comprises a normalized second sequence representation, the trained text-to-image model further comprises at least one of a third linear layer or a fourth linear layer, the third linear layer is used to perform adaptive normalization on the second sequence representation according to the third parameter to obtain the third feature, and the fourth linear layer is used to perform adaptive normalization on the first image representation according to the fourth parameter to obtain the fourth feature.8.The method of any one of claims 1 to 7, wherein generating the first image according to the first text and the trained text-to-image model, comprises:processing the first feature using the first self-attention module to obtain the first sequence representation;processing the first text embedding converted from the first text and the second feature related to the first sequence representation using the first cross-attention module to obtain the second sequence representation;processing the third feature related to the second sequence representation using the first feed-forward module to obtain the first image representation; anddecoding the fourth feature related to the first image representation to generate the first image.9.A method for training a text-to-image model, the method comprising:obtaining a sample set comprising a text sample and an image sample; andtraining the text-to-image model using the sample set, according to a training condition comprising minimizing a difference between the image sample and a predicted image output by the text-to-image model, to obtain a trained text-to-image model, the text-to-image model comprising a first self-attention module, a first cross-attention module, and a first feed-forward module, wherein:an input of the first self-attention module comprises a first training feature related to the image sample, and an output of the first self-attention module comprises a first training sequence representation;an input of the first cross-attention module comprises a text training embedding converted from the text sample and a second training feature related to the first training sequence representation, and an output of the first cross-attention module comprises a second training sequence representation; andan input of the first feed-forward module comprises a third training feature related to the second training sequence representation, and an output of the first feed-forward module comprises a first training image representation,wherein the predicted image is generated based on a fourth training feature related to the first training image representation.10.The method of claim 9, wherein the training condition further comprises at least one of:maximizing an alignment degree between the predicted image and the text sample; ormaximizing an aesthetic quality score of the predicted image.11.The method of claim 9 or 10, wherein the input of the first self-attention module further comprises a first condition for generating the predicted image.12.The method of claim 9 or 10, wherein the text-to-image model further comprises a second self-attention module, a second cross-attention module, and a second feed-forward module, wherein:an input of the second self-attention module comprises a fifth training feature that is related to both a first condition for generating the predicted image and the first training feature, and an output of the second self-attention module comprises a third training sequence representation;an input of the second cross-attention module comprises the text training embedding and a sixth training feature related to the third training sequence representation, and an output of the second cross-attention module comprises a fourth training sequence representation; andan input of the second feed-forward module comprises a seventh training feature related to the fourth training sequence representation, and an output of the second feed-forward module comprises a second training image representation,wherein the predicted image is generated further based on an eighth training feature related to the second training image representation.13.The method of claim 12, wherein the second self-attention module comprises a second compressor for compressing the first condition and the first training feature.14.The method of any one of claims 11 to 13, further comprising:obtaining the first condition.15.The method of any one of claims 9 to 14, wherein the first self-attention module comprises a first compressor for compressing the first training feature.16.The method of any one of claims 9 to 15, wherein the text-to-image model further comprises a multilayer perceptron layer for generating an adaptive normalization parameter according to a current time, and the adaptive normalization parameter comprises a first parameter, a second parameter, a third parameter, and a fourth parameter,wherein the first training feature comprises a normalized representation related to the image sample, the second training feature comprises a normalized first training sequence representation, the text-to-image model further comprises at least one of a first linear layer or a second layer, the first linear layer is used to perform adaptive normalization on a representation related to the image sample according to the first parameter to obtain the first training feature, and the second linear layer is used to perform adaptive normalization on the first training sequence representation according to the second parameter to obtain the second training feature,wherein the third training feature comprises a normalized second training sequence representation, the text-to-image model further comprises at least one of a third linear layer or a fourth linear layer, the third linear layer is used to perform adaptive normalization on the second training sequence representation according to the third parameter to obtain the third training feature, and the fourth linear layer is used to perform adaptive normalization on the third image representation according to the fourth parameter to obtain the fourth training feature.17.The method of any one of claims 9 to 16, further comprising:obtaining the image sample; andinputting a prompt and the image sample into a vision-language model to obtain the text sample.18.A computing device, configured to perform the method according to any one of claims 1 to 8, or the method according to any one of claims 9 to 17.19.A computing device, comprising a processor and a memory storing executable instructions which, when executed by the processor, cause the computing device to perform the method according to any one of claims 1 to 8 or the method according to any one of claims 9 to 17.20.A computer-readable storage medium having instructions stored thereon, which when executed by a computing device, cause the computing device to perform the method of any one of claims 1 to 8, or the method according to any one of claims 9 to 17.21.A computer program product, for storing instructions which, when executed, cause a computing device to perform the method of any one of claims 1 to 8, or the method according to any one of claims 9 to 17.

Citation Information

Patent Citations

  • Scene text recognition method and device based on diffusion model and readable medium

    CN117911997A

  • Data processing method, model training method, electronic device, computer storage medium and computer program product

    CN118469815A

  • Method and device for generating image from text, storage medium and electronic equipment

    CN118587303A

  • Utilizing visual and textual aspects of images with recommendation systems

    US20230206010A1

  • Machine learning diffusion model with image encoder trained for synthetic image generation

    US20240282016A1