Image generation method and apparatus, electronic device, storage medium, and program product
By fusing the semantic features and detailed hierarchical information of image generation prompts, the problem of insufficient edge and texture delineation in diffusion generation models during image generation is solved, thereby improving the quality of image generation.
Patent Information
- Application Number
- CN202611330951.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-08-28
- Publication Date
- 2026-11-20
AI Technical Summary
Diffusion-based generative models are prone to insufficient edge and texture delineation during image generation, resulting in poor image quality.
By obtaining the semantic features and detailed hierarchical information of the image generation prompts, the image generation method is fused together to generate an image that meets the requirements, combined with the initial image.
It improves the quality of image generation, especially in terms of detail and structural realism.
Smart Images

Figure CN123141602A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of computer technology, and in particular to an image generation method, apparatus, electronic device, storage medium, and program product. Background Technology
[0002] In recent years, diffusion generative models have been widely used in the field of image generation due to their excellent probabilistic modeling capabilities and high image generation fidelity.
[0003] During training, the diffusion generation model learns the reverse denoising process by gradually adding noise to the image, and then learns the mapping process from noise to image. Based on this, when the diffusion generation model is used to generate an image, it directly predicts the complete image from random noise.
[0004] Although the above methods can generate natural-looking images, the diffusion generation model generates images by mapping noise to an image in a single way, which can lead to insufficient ability to depict edges and textures in the image during the generation process, resulting in poor image quality. Summary of the Invention
[0005] The purpose of this application is to provide an image generation method, apparatus, electronic device, storage medium, and program product to improve the quality of generated images. The specific technical solution is as follows:
[0006] In a first aspect, embodiments of this application provide an image generation method, comprising: obtaining an image generation prompt word and an initial image; obtaining semantic features of descriptive units in the image generation prompt word and determining detail level information of the descriptive units, wherein the detail level information characterizes the degree of description of detail information in the image by the descriptive units; fusing the obtained semantic features and the determined detail level information to obtain a first fusion feature; and generating an image described by the image generation prompt word based on the initial image and the first fusion feature.
[0007] Secondly, embodiments of this application provide an image generation apparatus, which may include:
[0008] The acquisition module is used to obtain image generation prompts and the initial image.
[0009] The first processing module is used to obtain the semantic features of the descriptive units in the image generation prompts and determine the detail level information of the descriptive units, wherein the detail level information represents the degree to which the descriptive units describe the detail information in the image.
[0010] The second processing module is used to fuse the obtained semantic features and the determined detailed level information to obtain the first fused feature.
[0011] The generation module is used to generate an image with prompt words based on the initial image and the first fusion feature.
[0012] Thirdly, embodiments of this application provide an electronic device, including: a processor, a communication interface, a memory, and a communication bus, wherein...
[0013] The processor, communication interface, and memory communicate with each other through a communication bus;
[0014] Memory, used to store computer programs;
[0015] When a processor executes a program stored in memory, it implements the image generation method of the first aspect or any possible implementation thereof.
[0016] Fourthly, embodiments of this application provide a computer-readable storage medium storing a computer program, which, when executed by a processor, implements the image generation method in the first aspect or any possible implementation thereof.
[0017] Fifthly, embodiments of this application provide a computer program product containing instructions that, when run on a computer, cause the computer to execute the image generation method in the first aspect or any possible implementation thereof.
[0018] When generating an image using the scheme provided in this application, image generation prompts are used as guidance to generate an image that meets the requirements based on an initial image. After obtaining the image generation prompts, not only are the semantic features of the descriptive units in the prompts further obtained, but also the detail level information of the descriptive units. This detail level information represents the degree to which the descriptive units describe the details in the image. Thus, when generating an image based on the initial image, the image can be characterized not only semantically from the perspective of the descriptive units, but also by combining the degree of detail description reflected in the detail level information to characterize the content described by the descriptive units, thereby improving the quality of the generated image.
[0019] Of course, implementing any product or method of this application does not necessarily require achieving all of the advantages described above at the same time. Attached Figure Description
[0020] To more clearly illustrate the technical solutions in the embodiments of this application or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of this application. For those skilled in the art, other embodiments can be obtained based on these drawings.
[0021] Figure 1 This is a flowchart illustrating an image generation method provided in an embodiment of this application.
[0022] Figure 2 This is a schematic diagram of a cross-attention mechanism provided in an embodiment of this application.
[0023] Figure 3 This is a schematic diagram of a process for obtaining a first fusion feature, provided as an embodiment of this application.
[0024] Figure 4 This is a schematic diagram of an MLP architecture provided in an embodiment of this application.
[0025] Figure 5 This is a schematic diagram of a network architecture for obtaining a first fusion feature, provided as an embodiment of this application.
[0026] Figure 6 This is a schematic diagram of a process for obtaining a second enhanced feature, provided as an embodiment of this application.
[0027] Figure 7 This is a schematic diagram of a network architecture logic for obtaining a second enhanced feature, provided as an embodiment of this application.
[0028] Figure 8 This is a schematic diagram of another network architecture logic for obtaining the second enhanced feature, provided as an embodiment of this application.
[0029] Figure 9 This is a schematic flowchart of another image generation method provided in an embodiment of this application.
[0030] Figure 10 This is a schematic diagram of a network architecture logic for obtaining a second fusion feature, provided as an embodiment of this application.
[0031] Figure 11 This is a schematic diagram of a process for obtaining a second fusion feature, provided as an embodiment of this application.
[0032] Figure 12 This is a schematic diagram of another network architecture logic for obtaining the second fusion feature, provided as an embodiment of this application.
[0033] Figure 13 This is a schematic diagram of a process for obtaining a third fusion feature, provided as an embodiment of this application.
[0034] Figure 14 This is a schematic diagram of a network architecture logic for obtaining a third fusion feature, provided as an embodiment of this application.
[0035] Figure 15 This is a schematic diagram illustrating the effect of generating an image according to an embodiment of this application.
[0036] Figure 16 This is a schematic diagram illustrating another effect of generating an image, provided as an embodiment of this application.
[0037] Figure 17 This is a schematic diagram of the structure of an image generation device provided in an embodiment of this application.
[0038] Figure 18 This is a schematic diagram of the structure of an electronic device provided in an embodiment of this application. Detailed Implementation
[0039] The technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, and not all embodiments. Based on the embodiments of this application, all other embodiments obtained by those skilled in the art based on this application are within the scope of protection of this application.
[0040] The image generation method provided in this application can be applied to an image generation device. The following embodiments of this application will use an image generation device as the execution subject to illustrate the technical solution of this application. Of course, the image generation method provided in this application can also be applied to other devices, such as electronic devices, etc., which will not be described in detail here.
[0041] Combination Figure 1 The method includes: Step S101: obtaining image generation prompts and an initial image; Step S102: obtaining the semantic features of the descriptive units in the image generation prompts and determining the detail level information of the descriptive units, wherein the detail level information represents the degree to which the descriptive units describe the details in the image; Step S103: fusing the obtained semantic features and the determined detail level information to obtain a first fusion feature; Step S104: generating the image described by the image generation prompts based on the initial image and the first fusion feature. After obtaining the image generation prompts, not only are the semantic features of the descriptive units in the image generation prompts further obtained, but also the detail level information of the descriptive units is obtained. This detail level information represents the degree to which the descriptive units describe the details in the image. Thus, when generating an image based on the initial image, the image generation prompts serve as a guide, enabling not only the semantic characterization of the image from the descriptive units but also the characterization of the content described by the descriptive units by combining the degree of detail description reflected by the detail level information. This generates an image that meets the requirements based on the initial image, thereby improving the quality of the generated image.
[0042] Optionally, the image generation prompt in step S101 above can be input by the user or obtained based on the user's input information.
[0043] For example, a user can input an image generation prompt, and the image generation device can obtain the image generation prompt by receiving the input prompt.
[0044] Alternatively, the user can input other information that indicates image generation prompts, such as file information that contains (or records) image generation prompts. The image generation device can obtain the image generation prompts by parsing the file information that indicates the image generation prompts.
[0045] Optionally, the initial image in step S101 above can also be input by the user or obtained based on the user's input information.
[0046] For example, a user can directly input an initial image, and the image generation device acquires the initial image by receiving the initial image input by the user.
[0047] Alternatively, the user input can be other information that indicates the initial image, such as image indication information that indicates the storage location of the initial image, based on which the image generation device retrieves the initial image at the corresponding storage location. Another example is that the user input can be document information containing the initial image.
[0048] Optionally, the description unit in step S102 above can be understood as a feature definition unit of the image generation prompt words for the final generated image. This description unit can be obtained by segmenting the image generation prompt words according to different dimensions.
[0049] The categorization dimensions can be set according to actual usage needs, such as word level, phrase level, or sentence level.
[0050] For example, word-level segmentation can refer to dividing the different words included in the image-generated prompts into different descriptive units based on the semantics of the image-generated prompts.
[0051] As an example, the initial image input by the user could be a sky background image, and the image generation prompt could be "Add a young woman with fair skin and blue eyes to the image." In this scenario, the descriptive units could be "fair skin," "blue eyes," "young woman," etc., as in the example above.
[0052] Phrase-level segmentation can refer to dividing the content segmented by each segmentation punctuation mark in the image generation prompt into different descriptive units based on the segmentation punctuation marks (such as commas, semicolons, etc.) used to represent the meaning of sentence segmentation in the image generation prompt.
[0053] As an example, the image-generated prompt is "A girl in a red dress is standing in a golden wheat field, with distant mountain ranges and a few white clouds in the sky." In this scenario, the descriptive units could be "a girl in a red dress," "standing in a golden wheat field," "distant mountain ranges," and "a few white clouds in the sky."
[0054] Sentence-level segmentation can refer to dividing the content segmented by different ending punctuation marks (such as periods) in the image generation prompt words into a descriptive unit.
[0055] As an example, the image-generated prompt is "An orange cat wearing an astronaut helmet is floating in space. The lighting and shadows in the image are very soft, presenting a cinematic quality." In this scenario, the description unit could be "An orange cat wearing an astronaut helmet is floating in space" or "The lighting and shadows in the image are very soft, presenting a cinematic quality."
[0056] The semantic features of the description unit can be the feature information that the image generation device can process based on the description unit, such as the semantic feature vector obtained based on the description unit.
[0057] As an example, a description unit can be transformed into a semantic feature through an encoder.
[0058] Optionally, the type and number of levels of this detailed hierarchical information can also be flexibly configured.
[0059] As an example, the type of this level of detail information can be binary encoded, such as 0 corresponding to the first level of detail information, 1 corresponding to the second level of detail information, and so on.
[0060] As another example, the number of levels of this detail level information can be 2. For instance, the detail level information can be divided into high-frequency information and low-frequency information. High-frequency information can be understood as detail-level features, such as features used to define textures (e.g., features of a person's pupils). Low-frequency information can be understood as theme-level features, such as features used to define outlines, backgrounds, etc.
[0061] Optionally, more levels can be set according to actual usage needs. For example, detailed level information can also include intermediate frequency information located between high-frequency and low-frequency information.
[0062] Optionally, in step S103 above, when fusing semantic features and detail-level information, the corresponding detail-level information can be fused with the semantic features of the description unit based on the detail-level information corresponding to different description units, thereby obtaining the first fused feature. That is, for each description unit, the detail-level information of the description unit is fused with the semantic features of the description unit to obtain the fused feature of the description unit, and the fused features of each description unit of the image-generated prompt word are concatenated to obtain the first fused feature.
[0063] As an example, taking the aforementioned descriptive units including "fair skin," "blue eyes," and "young woman" as examples, the semantic features of "fair skin" and "blue eyes" can both correspond to high-frequency information at the detail level. The semantic feature of "young woman" can correspond to low-frequency information at the detail level. Therefore, the semantic features of "fair skin" can be fused with the detail level information of "fair skin," the semantic features of "blue eyes" can be fused with the detail level information of "blue eyes," and the semantic features of "young woman" can be fused with the detail level information of "young woman," thus obtaining the first fused feature with the image generation prompt "Add a young woman with fair skin and blue eyes to the image."
[0064] Optionally, in step S104 above, the first fusion feature obtained by fusing semantic features and detail-level information can be mapped to generate key features (Key, K) and value features (Value, V) respectively; the image feature tensor obtained by encoding the initial image is used as the query feature (Query, Q). The three sets of features Q, K, and V are respectively input into the frequency division cross-attention module, the correlation matrix between the query feature Q and the key feature K is calculated and divided by the dimension scaling factor (\sqrt{d_k}\), and normalized by the normalized exponential function (Softmax) to obtain the attention weight matrix. Then, the value feature V is weighted and aggregated using this weight matrix to obtain the cross-modal fusion feature tensor; the cross-modal fusion feature tensor is sent to the subsequent decoding network to generate the target image that meets the prompt word requirements.
[0065] Combination Figure 2 , where x1 can be a feature of the initial image, such as the image feature tensor of the initial image (that is, x1 is the image feature tensor of the initial image), and x2 is the first fusion feature.
[0066] Combine image features with the query weight matrix W q The transpose matrix W T q Multiply to obtain the query matrix Q; combine the first fused feature with the key weight matrix W. k The transpose matrix W Tk Multiply to obtain the key matrix K; combine the first fused feature with the value weight matrix W. v The transpose matrix W T v Multiplying them together yields the value matrix V (Value).
[0067] Transpose Q and K into the transpose matrix (K) T Perform matrix multiplication to obtain the similarity matrix QK. T The similarity matrix is transformed using the Softmax function to obtain the attention matrix A.
[0068] Multiply the attention matrix A by V to obtain the cross-modal fusion feature tensor Z, and generate an image based on this cross-modal fusion feature tensor Z.
[0069] Optionally, the output result Z can be formalized as shown in Formula 1.
[0070] Formula 1
[0071] Where Attention(Q, K, V) is the fusion feature tensor Z obtained from the first fusion feature and the initial image, softmax() represents the softmax function, Q is the query matrix, and K is the input matrix. T Let d be the transpose of the key matrix K. k Let k be the dimension of the key matrix k, and V be the value matrix.
[0072] In some implementations, see Figure 3 Step S103 above: fusing the obtained semantic features and the determined detail level information to obtain a first fused feature, including: Step S201: concatenating the obtained semantic features and the determined detail level information to obtain a concatenated feature; Step S202: extracting features from the concatenated feature to obtain a first hidden feature; Step S203: using the obtained semantic features to enhance the first hidden feature to obtain a first enhanced feature; Step S204: performing attention transformation on the first enhanced feature to obtain a second enhanced feature after feature enhancement based on the first enhanced feature; Step S205: extracting features from the second enhanced feature to obtain a second hidden feature; Step S206: using the second enhanced feature to enhance the second hidden feature to obtain a first fused feature. In this way, the final fused feature can be obtained by performing feature enhancement multiple times, so as to achieve phased feature enhancement guidance, improve the accuracy of the generated first fused feature in representing the relationship between semantic features and detailed hierarchical information, thereby improving the accuracy of the image generated based on the first fused feature, significantly improving the detail depiction and structural realism of high-precision image generation, and improving the image generation efficiency and stability of image generation in complex scenes.
[0073] Optionally, in step S201 above, before concatenating semantic features and detailed level information, the feature distribution range of semantic features and / or detailed level information can be adjusted, such as mapping semantics to a specific range, and / or mapping detailed level information to a feature range. This stabilizes the numerical feature distribution of semantic features and / or detailed level information, preventing excessively large amplitudes in a particular branch feature from affecting the accuracy of the first fused feature.
[0074] As an example, semantic features can be normalized to adjust their feature distribution range, and / or detailed-level information can be normalized to adjust its feature distribution range. For instance, normalization transformations can adjust the feature distribution ranges of semantic features and / or detailed-level information. In network architecture, this normalization transformation can be achieved through a normalization layer, also known as layer normalization, layer normalization, or normalization layer.
[0075] Optionally, the splicing method for semantic features and detail level information in step S201 above can include a variety of methods, such as splicing semantic features and detail level information through feature splicing (cat, also known as concatenate).
[0076] As an example, semantic features and detailed hierarchical information can be concatenated in a dimension to obtain concatenated features. For instance, semantic features of dimension d_model and detailed hierarchical information of dimension d_model can be concatenated to form concatenated features of dimension 2d_model.
[0077] For example, both semantic features and detail-level information are two-dimensional feature vectors of size m×n. When concatenating semantic features and detail-level information, semantic features and detail-level information can be concatenated in the row dimension ([m] dimension), that is, semantic features and detail-level information are stacked one on top of the other to obtain concatenated features of dimension 2m×n.
[0078] Alternatively, semantic features and detail-level information can be concatenated in the column dimension ([n] dimension), that is, semantic features and detail-level information can be concatenated left and right to obtain concatenated features with a dimension of m×2n.
[0079] Optionally, in step S202 above, the features of the spliced features can be extracted using a multilayer perceptron (MLP) to obtain the first hidden feature. For example, the spliced features with a dimension of 2d_model are input into the MLP, and through the non-linear transformation of the MLP, the first hidden feature with a dimension of d_model is obtained, realizing the fusion of semantic features and detailed hierarchical information, such as establishing the association between the semantic feature of "fair skin" and high-frequency information.
[0080] The structure of an MLP can be as follows: Figure 4 As shown, the MLP can include a three-layer structure, namely an input layer, a hidden layer, and an output layer.
[0081] The input layer is used to receive raw data (such as the splicing features mentioned above) and transmit the data to the inner layers (hidden layers).
[0082] The hidden layer is located between the input layer and the output layer. It consists of multiple stacked hidden units. The hidden units are used to extract features through weighted summation and activation functions. The features extracted by the hidden layer can be combined by the output layer to obtain the final feature extraction result.
[0083] The output layer may include a perceptron, which receives the output of the hidden layer and combines it to obtain the final feature extraction result (such as the first hidden feature).
[0084] Optionally, the structure of an MLP can vary depending on the specific application scenario, for example... Figure 4 The structure of MLP is illustrated using a single hidden layer as an example. However, depending on the actual usage requirements and other conditions, the hidden layer can also be a structure with more layers.
[0085] Optionally, in step S203 above, the semantic features and the first hidden features can be residually connected to achieve feature enhancement of the first hidden features and obtain the first enhanced features.
[0086] Residual connection can be understood as adding two feature vectors element by element. For example, if the semantic feature is vector x, and the first hidden feature obtained from the semantic feature is F(x), then when feature enhancement is performed through residual connection, the first enhanced feature Output can be understood as Output = x + F(x).
[0087] Optionally, in conjunction with the above description of dimensional changes to semantic features, when dimensional changes are performed on semantic features, the semantic features used for feature enhancement of the first hidden feature in step S203 can be the dimensionally changed semantic features, so as to avoid the impact on the accuracy of feature enhancement due to the inconsistency between the dimensions of the semantic features and the first hidden features.
[0088] In one example, combined with the processing method of adjusting the feature distribution interval of the semantic features mentioned above, if the distribution interval of the semantic features has been corrected, then in step S203 above, the semantic features with the adjusted distribution interval can be used to enhance the first hidden feature, so that the semantic features used for feature enhancement match the data distribution and numerical range of the first hidden feature, thereby improving the stability and accuracy of feature enhancement.
[0089] Optionally, in step S204 above, in the network architecture, attention transformation of the first enhanced feature can be achieved through an attention layer.
[0090] Optionally, in step S204 above, feature enhancement of the transformed features can be achieved by residual connection based on the first enhanced feature. For example, residual connection can be performed between the first enhanced feature and the transformed features to achieve feature enhancement of the transformed features.
[0091] Optionally, in step S205 above, the extraction method of the second enhanced feature can include a variety of methods, such as extracting the features of the second enhanced feature through MLP. For the extraction method of MLP, please refer to the relevant description of MLP above, which will not be repeated here.
[0092] Optionally, before extracting the features of the second enhanced feature, the feature distribution range of the second enhanced feature can be adjusted, such as mapping the second enhanced feature to a specific range, in order to stabilize the numerical feature distribution of the second enhanced feature and avoid the excessive increase of a certain branch feature of the second enhanced feature, which would affect the accuracy of subsequent feature extraction.
[0093] As an example, the feature distribution range of the second enhanced feature can be adjusted by normalizing the second enhanced feature. For example, in the network architecture, the feature distribution range of the second enhanced feature can be adjusted by layer normalization.
[0094] Optionally, in step S206 above, a residual connection can be performed on the second enhanced feature and the second hidden feature to enhance the second hidden feature, thereby obtaining the first fused feature. Regarding the implementation of the residual connection, please refer to the relevant description of the residual connection in step S203 above, which will not be repeated here.
[0095] Optionally, in conjunction with the above description of adjusting the feature distribution range of the second enhanced feature, when adjusting the feature distribution range of the second enhanced feature, the second enhanced feature used to enhance the second hidden feature in step S206 can be the second enhanced feature before adjusting the feature distribution range, so as to maximize the preservation of the feature distribution of the second enhanced feature and improve the accuracy of feature enhancement.
[0096] Optionally, implement Figure 3 One possible network architecture logic of the method described is as follows: Figure 5 As shown, the logic includes: concatenating semantic features and detail-level information to obtain concatenated features; inputting the concatenated features into an MLP to extract features from the concatenated features, obtaining a first hidden feature; performing a residual connection between the semantic features and the first hidden feature to enhance the features of the first hidden feature, obtaining a first enhanced feature; performing attention transformation and feature enhancement on the first enhanced feature to obtain a second enhanced feature; inputting the second enhanced feature into an MLP to extract features from the second enhanced feature, obtaining a second hidden feature; and performing a residual connection between the second hidden feature and the second enhanced feature to enhance the features of the second enhanced feature, obtaining a first fused feature.
[0097] Optionally, combined Figure 5 Before concatenating semantic features and detailed hierarchical information, the feature distribution intervals of semantic features and detailed hierarchical information can be adjusted separately through layer normalization. In this scenario, the semantic features used for the subsequent residual connection with the first hidden feature can be the semantic features before the feature distribution interval adjustment.
[0098] Optionally, such as Figure 5 As shown, before extracting the features of the second enhanced feature, the feature distribution range of the second enhanced feature can be adjusted through layer normalization. In this scenario, the second enhanced feature used for the subsequent residual connection with the second hidden feature can be the second enhanced feature before the feature distribution range adjustment.
[0099] In some implementations, see Figure 6Step S204 above: Performing attention transformation on the first enhanced feature to obtain a second enhanced feature after feature enhancement based on the transformed feature of the first enhanced feature, includes: Step S301: Performing at least one cascaded attention and enhancement process on the first enhanced feature; Step S302: Using the output feature of the last cascaded attention and enhancement process as the second enhanced feature, wherein each attention and enhancement process includes the following steps: Step S3011: Performing self-attention transformation on the input feature to obtain attention weight features, wherein in the first attention and enhancement process, the input feature is the first enhanced feature, and in subsequent attention and enhancement processes, the input feature is the output feature of the previous attention and enhancement process; Step S3012: Using the input feature to enhance the attention weight features to obtain intermediate enhanced features; Step S3013: Extracting features from the intermediate enhanced features to obtain intermediate hidden features; Step S3014: Using the intermediate enhanced features to enhance the intermediate hidden features to obtain output features. Thus, the second enhanced feature can be obtained from the first enhanced feature through at least one cascaded attention and enhancement process. Since each attention and enhancement process applies attention changes and feature enhancements to the input features, semantic features and detail-level information can be deeply fused and bound through this at least one cascaded attention and enhancement process. This strengthens the association between semantic features and detail-level information, enabling the second enhanced feature to accurately describe the relationship between semantic features and detail-level information. This improves the accuracy of generating descriptions of different descriptive units in subsequent image generation processes and enhances the overall accuracy of image generation.
[0100] Optionally, the number of times the attention and enhancement processes are cascaded at least once in step S301 can be set according to actual usage requirements.
[0101] Optionally, in step S3011 above, before performing self-attention transformation on the input features, the feature distribution range of the input features can be adjusted, such as mapping the input features to a specific range, in order to stabilize the numerical feature distribution of the input features and avoid the excessive increase of a certain branch feature of the input features, which would affect the accuracy of the subsequent self-attention transformation.
[0102] As an example, the input features can be normalized to adjust the feature distribution range of the input features, such as by using layer normalization.
[0103] Optionally, in step S3012 above, feature enhancement of the attention weight features can be achieved through residual connections. For example, residual connections can be performed between the attention weight features and the input features to obtain intermediate enhanced features. Regarding the implementation of residual connections, please refer to the relevant description of residual connections in step S203 above; it will not be repeated here.
[0104] Optionally, in step S3013 above, feature extraction of intermediate enhanced features can be achieved through a feedforward network.
[0105] Optionally, the implementation architecture of the feedforward network can be configured according to actual usage requirements. For example, the feedforward network can be an MLP, and the composition architecture of an MLP can be found in the above-mentioned section. Figure 4 The relevant content will not be repeated here.
[0106] Optionally, in step S3013, before extracting intermediate enhancement features, the feature distribution range of the intermediate enhancement features can be adjusted, such as mapping the intermediate enhancement features to a specific range, in order to stabilize the numerical feature distribution of the intermediate enhancement features and avoid the excessive increase of a certain branch feature of the intermediate enhancement features, which would affect the accuracy of subsequent feature extraction.
[0107] As an example, the feature distribution range of intermediate enhanced features can be adjusted by normalizing the intermediate enhanced features, such as by adjusting the feature distribution range of intermediate enhanced features through layer normalization.
[0108] Optionally, in step S3014 above, feature enhancement of intermediate hidden features can be achieved through residual connections. For example, residual connections can be performed between intermediate hidden features to obtain output features. Regarding the implementation of residual connections, please refer to the relevant description of residual connections in step S203 above; it will not be repeated here.
[0109] Optionally, implement Figure 6 One possible network architecture logic of the method described is as follows: Figure 7 As shown, the logic includes: the input features undergo self-attention transformation to obtain attention weight features; the input features and attention weight features are connected by a residual connection to enhance the features of the attention weight features, resulting in intermediate enhanced features; the intermediate enhanced features are input into a feedforward network to extract features from the intermediate enhanced features, resulting in intermediate hidden features; the intermediate enhanced features and intermediate hidden features are connected by a residual connection to enhance the features of the intermediate hidden features, resulting in output features.
[0110] Optionally, such as Figure 7As shown, before performing self-attention transformation on the input features, the feature distribution range of the input features can be adjusted through layer normalization. In this scenario, the input features used for the subsequent residual connection with the attention weight features can be the input features before the feature distribution range adjustment.
[0111] Optionally, such as Figure 7 As shown, before extracting the intermediate enhanced features, the feature distribution range of the intermediate enhanced features can be adjusted through layer normalization. In this scenario, the intermediate enhanced features used for subsequent residual connections with the intermediate hidden features can be the intermediate enhanced features before feature distribution range adjustment.
[0112] Alternatively, each attention and enhancement process can be implemented using a transformer block, for example, Figure 7 The network architecture logic shown can be implemented using transformer blocks. In other words, N transformations can be achieved using N transformer blocks. Figure 6 or Figure 7 The attention and enhancement processes are shown.
[0113] Combination Figure 7 , Figure 8 An implementation using two-stage cascaded attention and enhancement processing as an example is shown. Figure 6 The diagram illustrates the network architecture logic of the method shown. (Combined with...) Figure 8 The input feature (first enhanced feature) undergoes a first self-attention transformation to obtain the first attention weight feature; the input feature and the first attention weight feature are connected by a residual connection to enhance the first attention weight feature, resulting in the first intermediate enhanced feature; the first intermediate enhanced feature is input into a feedforward network to extract features from the first intermediate enhanced feature, resulting in the first intermediate hidden feature; the first intermediate enhanced feature and the first intermediate hidden feature are connected by a residual connection to enhance the first intermediate hidden feature, resulting in the output feature of the first attention transformation and enhancement processing.
[0114] The output features of the first attention and feature enhancement are used as the input features of the second attention and enhancement processing. After the second self-attention transformation, the second attention weight features are obtained. The input features and the second attention weight features are connected by a residual to enhance the features of the second attention weight features, resulting in the second intermediate enhanced features. The second intermediate enhanced features are then input into a feedforward network to extract features from the second intermediate enhanced features, resulting in the second intermediate hidden features. Finally, the second intermediate enhanced features and the second intermediate hidden features are connected by a residual to enhance the features of the second intermediate hidden features, resulting in the output features of the second attention transformation and enhancement processing.
[0115] If the number of cascaded attention and enhancement processes in step S301 above includes more than one, such as 3 times, 5 times, etc., the relationship between two adjacent cascaded attention and enhancement processes in multiple cascaded attention and enhancement processes can be referred to the above. Figure 8 The contents shown will not be illustrated with examples here.
[0116] In some implementations, step S3011 above—performing a self-attention transformation on the input features to obtain attention weight features—includes: step S401: updating the weights of the attention heads assigned to the levels described by the detailed level information based on the features in the input features associated with detailed level information; step S402: performing a self-attention transformation on the input features based on the updated weights to obtain attention weight features. In this way, attention transformation can be performed on corresponding features by using different attention head weights according to the different levels described by the detailed level information of the features in the input features. For example, the weights of different attention heads can focus on the self-attention transformation of features at different levels, thereby specifically fitting the self-attention change characteristics of different features and improving the accuracy of the self-attention transformation.
[0117] As an example, the attention head in step S401 above can include multiple attention heads, and different attention heads correspond to different levels of detail information. Depending on the different levels of detail information corresponding to the feature, the attention head corresponding to the feature will also be different.
[0118] For example, the attention head corresponding to detail level information 1 (such as high-frequency level) can be attention head A, which is used to determine the attention weights corresponding to high-frequency semantic features; the attention head corresponding to detail level information 2 (such as low-frequency level) can be attention head B, which is used to determine the attention weights corresponding to low-frequency semantic features.
[0119] In some implementations, see Figure 9Step S104 above: Based on the initial image and the first fusion feature, an image describing the image generation prompt is generated, including: Step S501: Extracting image features from the initial image; Step S502: Fusing the image features and the determined detail level information to obtain the second fusion feature; Step S503: Generating the image describing the image generation prompt based on the first and second fusion features. Thus, when generating an image using the second fusion feature, since the second fusion feature already embeds multi-scale hierarchical prior information (i.e., detail level information) corresponding to the fused image features, during the image generation stage, different frequency components in the latent space can be precisely controlled according to this detail level information. For example, the processing of image contour features can be strengthened in the low-frequency stage, and the processing of local texture detail features can be strengthened in the high-frequency stage, so as to achieve multi-dimensional hierarchical adaptive adjustment of the image, improving feature modulation accuracy and image generation quality.
[0120] Optionally, in step S501 above, the image features of the initial image can be obtained through a convolutional layer. For example, the initial image (such as the image feature tensor of the initial image) can be input into a first convolutional layer, which can be a two-dimensional convolutional layer (Conv2). When the first convolutional layer is a two-dimensional convolutional layer, the first layer of the first convolutional layer is used to extract shallow image features, and the second layer of the first convolutional layer is used to extract deep image features, so as to extract the image features of the initial image through the first convolutional layer. The image features extracted by the first convolutional layer can also be understood as the primary features of the initial image.
[0121] Optionally, in step S501 above, before extracting the image features of the initial image, the feature distribution range of the initial image can be adjusted, such as mapping the initial image (e.g., the image feature tensor of the initial image) to a specific range, in order to stabilize the feature distribution of the initial image and avoid excessive changes in some features of the initial image, which would affect the accuracy of feature fusion.
[0122] As an example, the feature distribution range of the initial image can be adjusted by normalizing the initial image, such as by using a normalization layer.
[0123] Optionally, in step S501 above, before extracting the features of the initial image, a nonlinear activation can be applied to the initial image to enhance the feature representation of the initial image.
[0124] Optionally, in step S502 above, before fusing image features and detail level information, nonlinear activation can be applied to the detail level information. Applying nonlinear activation to the detail level information allows the learning of the level's scale rules to be more flexible, the parameters to be more stable, and the fit with image features to be higher. Ultimately, the effect of layered control of the image's contours and textures is more accurate, thereby achieving precise mapping and transformation of the detail level information and improving the accuracy of fusing image features and detail level information.
[0125] Optionally, in step S502 above, before fusing image features and detail level information, the image features and detail level information can be mapped to the same dimension, such as mapping the image features and detail level information to the second dimension respectively, so as to achieve dimensional alignment of image features and detail level information, avoid the problem of dimension mismatch in the subsequent fusion process, and thus improve the accuracy of the second fused feature.
[0126] As an example, dimensional alignment between image features and detail-level information can be achieved through linear transformations. For instance, a linear transformation can be applied to image features, mapping their dimension to a second dimension. Similarly, a linear transformation can be applied to detail-level information, mapping its dimension to the same second dimension. The size of this second dimension can be set according to actual usage requirements; it can be a standard data dimension that the image generation model can handle, or it can be another dimension predefined by the image generation model.
[0127] Optionally, in step S503 above, the method of generating the image description of the image prompt based on the first fusion feature and the second fusion feature can refer to the above-mentioned implementation method of generating the image description of the image prompt based on the first fusion feature and the initial image. For example, the image can be generated based on the first fusion feature and the second fusion feature through a cross-attention mechanism, which will not be elaborated here.
[0128] Optionally, a possible network architecture logic for obtaining the second fusion feature can be as follows: Figure 10 As shown, the logic includes:
[0129] The initial image is processed through the first convolutional layer to extract features, resulting in image features. The image features are then fused with detail-level information to output the second fused features.
[0130] Optionally, such as Figure 10 As shown, before extracting features from the initial image, the feature distribution range of the initial image can be adjusted by layer normalization.
[0131] Optionally, such as Figure 10As shown, before extracting features from the initial image, nonlinear activation functions can be used to nonlinearly activate the features of the initial image. For example, after performing layer normalization on the feature distribution range of the initial image, the adjusted feature distribution range of the initial image can be nonlinearly activated using a nonlinearity function. The nonlinearly activated features are then input into the first convolutional layer to extract image features.
[0132] Optionally, such as Figure 10 As shown, before fusing the image features and detail level information of the initial image, nonlinear activation of the detail level information can be achieved through a nonlinear activation function.
[0133] In some implementations, see Figure 11 Step S502 above: fusing image features and determined detail level information to obtain a second fused feature, including: Step S601: fusing image features and determined detail level information to obtain a third fused feature; Step S602: extracting features from the third fused feature to obtain a third hidden feature; Step S603: using the initial image to enhance the third hidden feature to obtain the second fused feature. Thus, by determining the second fused feature through fusion, feature extraction, and feature enhancement, a deeper binding between image features and detail level information can be achieved, improving the correlation between image features and detail level information in the second fused feature. This ensures that when generating an image based on the second fused feature, the second fused feature can accurately represent the correlation between detail level information and image features, improving the accuracy of image generation based on the second fused feature.
[0134] Optionally, in step S601 above, fusion can be achieved by splicing image features and detail level information to obtain a second fused feature.
[0135] Optionally, in step S601 above, the image features can also be processed through detail level information, such as scaling and offsetting the image features, to achieve the fusion of detail level information and image features.
[0136] Optionally, in step S602 above, the features of the third fusion feature can be obtained through a convolutional layer. For example, the third fusion feature can be input into the second convolutional layer (Conv2) to extract the features of the third fusion feature and obtain the third hidden feature.
[0137] Optionally, in step S602 above, before extracting the features of the third fusion feature, a nonlinear activation can be applied to the third fusion feature. As an example, nonlinear activation of the third fusion feature can be achieved using nonlinearity.
[0138] Optionally, in step S602 above, before extracting the third fusion feature, the third fusion feature can also be subjected to random dropout processing to suppress overfitting during the training process.
[0139] As an example, the third fusion feature can be randomly deactivated after nonlinear activation. Alternatively, this random deactivation can be implemented simultaneously with the nonlinear activation, such as by using a nonlinear activation function coupled with random deactivation functionality.
[0140] Optionally, in step S603 above, feature enhancement of the third hidden feature can be achieved through residual connections. For example, a second fused feature can be obtained by performing a residual connection between the initial image and the third hidden feature. Regarding the implementation method of residual connections, please refer to the relevant description of residual connections in step S203 above, which will not be repeated here.
[0141] In residual connections, the features of the initial image (such as the image feature tensor of the initial image) can be added element-wise with the third hidden features to obtain the second fused features.
[0142] Optionally, in step S603 above, the magnitude of the second fused feature can be adjusted according to actual usage requirements. For example, the magnitude of the feature obtained after residual connection can be adjusted according to the output scaling factor, and the feature with the adjusted magnitude can be used as the final second fused feature. For instance, the feature obtained after residual connection can be divided by the output scaling factor to obtain the second fused feature.
[0143] Optionally, in combination with the above Figure 10 ,accomplish Figure 11 One possible network architecture logic of the method described is as follows: Figure 12 As shown, the logic includes: fusing image features and detail-level information to obtain a third fused feature; inputting the third fused feature into a second convolutional layer, extracting features from the third fused feature through the second convolutional layer to obtain a third hidden feature; and performing a residual connection between the initial image and the third hidden feature to enhance the features of the third hidden feature and obtain a second fused feature.
[0144] Optionally, such as Figure 12 As shown, before extracting the features of the third fusion feature, the third fusion feature can also be nonlinearly activated using a nonlinear activation function.
[0145] In some implementations, see Figure 13The above step S601: fusing image features and determined detail level information to obtain a third fused feature includes: step S701: fusing image features and determined detail level information to obtain a fourth fused feature; step S702: determining feature fusion components based on detail level information, wherein the feature fusion components include scaling components and / or offset components; step S703: fusing the feature fusion components and the fourth fused feature to obtain a third fused feature.
[0146] Optionally, in step S701 above, the image features and detail level information can be added element by element to obtain the fourth fused feature.
[0147] Optionally, in step S702 above, the detailed level information can be segmented to obtain feature fusion components.
[0148] As an example, detailed hierarchical information can be segmented along the channel dimension (such as along the channel dimension of model feature processing) into scaling components and / or offset components, thereby obtaining feature fusion components.
[0149] Optionally, in step S703 above, before fusing the feature fusion component and the fourth fusion feature, the feature fusion component and the fourth fusion feature can be aligned to the same dimension to improve the accuracy of fusion.
[0150] There are several ways to fuse the feature fusion component and the fourth fusion feature. For example, the fourth fusion feature can be scaled based on the scaling component included in the feature fusion component, and / or the fourth fusion feature can be translated based on the translation component included in the feature fusion component to obtain the third fusion feature.
[0151] Optionally, in step S703 above, before fusing the fusion component of the fusion feature and the fourth fusion feature, the feature distribution range of the fourth fusion feature can be adjusted, such as mapping the fourth fusion feature to a specific range, in order to stabilize the feature distribution of the fourth fusion feature and avoid excessive changes in some features of the fourth fusion feature, which could affect the accuracy of subsequent processing such as feature fusion.
[0152] As an example, the feature distribution range of the fourth fusion feature can be adjusted by normalizing the fourth fusion feature, just as the feature distribution range of the third fusion feature can be adjusted by layer normalization.
[0153] Optionally, implement Figure 13 One possible network architecture logic of the method described is as follows: Figure 14As shown, the logic includes: fusing image features and detail level information to obtain a fourth fused feature; determining feature fusion components based on detail level information, which may include a scaling component S and / or an offset component T; fusing the feature fusion components and the fourth fused feature, such as offsetting the fourth fused feature based on the offset component and / or scaling the fourth fused feature table based on the scaling component, to obtain a third fused feature.
[0154] Optionally, such as Figure 14 As shown, before fusing the feature fusion components and the fourth fusion feature, the feature distribution range of the fourth fusion feature can be adjusted by norm.
[0155] In some implementations, step S102 above, determining the detail level information of the description unit, includes: step S801: obtaining the detail level determined based on the degree of description of detail information in the image by the description unit; step S802: determining the representation information of the detail level from the pre-generated representation information of each optional detail level, thus obtaining the detail level information; wherein, the representation information of each optional detail level is generated in the following manner: step S901: determining the maximum total number of levels; step S902: determining a continuous integer sequence based on the maximum total number of levels, as the level index sequence of the optional detail levels; step S903: mapping each index in the level index sequence to a level embedding vector of the prediction dimension, thus obtaining the representation information of each optional detail level. In this way, the detail level information can be determined based on the continuous level embedding vectors, ensuring that the detail level information also contains level semantics, thereby ensuring that subsequent semantic features can be accurately fused with the detail level information, improving the accuracy of the first fused feature.
[0156] Optionally, in step S801 above, the degree of description of detailed information by the description unit can be determined by semantic analysis of the description unit, thereby obtaining the detail level of the description unit.
[0157] Optionally, by combining steps S801 and S802, the detail level information corresponding to each description unit can be determined based on the detail level and the representation information of the detail level.
[0158] As an example, if the detail level corresponding to description unit A is 1 (or high frequency), then the representation information of detail level 1 (or high frequency) can be taken from the identification information of optional detail levels as the detail level information of description unit A.
[0159] The following section describes in detail how the representation information for each optional detail level is generated.
[0160] Optionally, in step S901 above, the method for obtaining the maximum total number of levels can include various methods, such as different methods for obtaining the maximum total number of levels depending on the model architecture and the actual application scenario.
[0161] As an example, the maximum total number of levels can be obtained from sample data. For instance, a batch of sample data can be obtained, the detailed levels corresponding to each sample data can be counted, and the maximum level among them can be taken as the maximum total number of levels. In this way, the maximum total number of levels can be obtained by reasoning from the sample data.
[0162] As another example, the image generation method provided in this application embodiment can be applied to image generation models, such as embedding it into feature processing stages of the image generation model. In this scenario, the maximum total number of levels can be obtained from the upstream input features of the image generation model, such as from the feature tensor input to the previous layer of the image generation model. For example, the image generation method provided in this application embodiment can be embedded in the feature processing stage of the image generation model. In this scenario, the maximum total number of levels can be determined by the multi-level feature tensor output by the previous stage of the model (i.e., the processing stage before feature extraction).
[0163] A multi-level feature tensor can be understood as the output result obtained by the previous operation layer of the image generation model through computation on the initial image and / or image generation prompt words.
[0164] As another example, the image generation method provided in this application embodiment can be applied to image generation models, such as in feature processing steps embedded in the image generation model. In this scenario, the maximum total number of layers can be obtained from the configuration parameters of the image generation model. For example, the maximum total number of layers can be understood as the hyperparameters of the model. During the image generation process, the maximum total number of layers can be determined through the parameter configuration of the image generation model.
[0165] Optionally, in step S902 above, the image generating device can generate a level index sequence based on the maximum total number of levels. The type of the level index sequence can be set according to actual usage requirements. For example, the level index sequence can be a continuous integer level index sequence. For instance, if the maximum total number of levels is num_levels, then the generated level index sequence includes multiple indices from 0 to num_levels-1.
[0166] Optionally, the computing hardware devices for the hierarchical index sequence can be aligned with the computing hardware devices for the multi-level feature tensors output by the model. This ensures that the computing hardware devices corresponding to the hierarchical index sequence are consistent with the computer hardware devices corresponding to the multi-level feature tensors. This avoids errors in subsequent image generation processes due to inconsistencies between the computing hardware devices corresponding to the hierarchical index sequence and the computer hardware devices corresponding to the multi-level feature tensors (also known as hardware device heterogeneity), which could lead to errors in subsequent tensor operations.
[0167] The computing hardware device for the hierarchical index sequence can be understood as the hardware device for storing the hierarchical index sequence, such as storing the hierarchical index sequence using a CPU, GPU, or NPU.
[0168] The hardware devices for computing multi-level feature tensors can be understood as hardware devices for storing multi-level feature tensors, such as CPUs, GPUs, or NPUs that store multi-level feature tensors.
[0169] Optionally, the data type of the hierarchical index sequence can be aligned with the data type of the multi-level feature tensor. This ensures that the data type of the hierarchical index sequence is suppressed by the data type of the multi-level feature tensor, so as to avoid errors in subsequent image generation due to the inconsistency between the data type of the hierarchical index sequence and the data type of the multi-level feature tensor, such as errors in tensor operations.
[0170] Optionally, in step S903 above, each index in the hierarchical index sequence can be mapped to a hierarchical embedding vector of the prediction dimension by embedding a neural network layer. For example, the dimension of the generated hierarchical embedding vector can be (num_levels, level_emb_channels), where num_levels is the total number of levels, and level_emb_channels can be a preset dimension of the embedding vector. The value of level_emb_channels can be set according to actual usage requirements, such as the specific model architecture, the task type of the image generation task, and the currently available computing resources.
[0171] The hierarchical embedding vector can be understood as a continuous vector. For example, the hierarchical embedding vector can be a high-dimensional continuous vector obtained by index mapping based on the hierarchical index sequence, so that the detailed hierarchical information obtained from the hierarchical embedding vector can be aligned with the semantic feature vector.
[0172] Optionally, the aforementioned embedding neural network layer, also known as the Embedding Layer, can be a learnable embedding neural network layer. Through training, it can learn the mapping relationship between the discrete index values of the hierarchical index sequence and the hierarchical embedding vector, thereby improving the accuracy of mapping each index in the hierarchical index sequence to the hierarchical embedding vector.
[0173] As an example, the neural network layer may include a one-hot code and a lookup matrix, which can map any index in the hierarchical index sequence to a hierarchical embedding vector of the prediction dimension.
[0174] For example, any index in the level index sequence is used as input, and the index is converted into a one-hot vector by a one-hot encoder; the one-hot vector is fused with the lookup matrix to obtain the level embedding vector corresponding to the index, also known as the level embedded code.
[0175] For example, a matrix multiplication operation can be performed between a one-hot vector and a lookup matrix, and the result can be used as a hierarchical embedding vector.
[0176] In this way, through the above process, we can obtain the hierarchical embedding vectors corresponding to the hierarchical index sequences, so as to obtain the representation information of each optional detail level.
[0177] In some implementations, step S103 above—fusing the obtained semantic features and the determined level-of-detail information to obtain a first fused feature—includes: step S901: mapping the obtained semantic features and the determined level-of-detail information to a first dimension respectively; step S902: fusing the semantic features mapped to the first dimension and the level-of-detail information mapped to the first dimension to obtain the first fused feature. This is to avoid errors in the fusion of semantic features and level-of-detail information due to inconsistencies in feature dimensions, thereby improving the accuracy of the first fused feature.
[0178] As an example, dimensional alignment between semantic features and detailed information can be achieved through linear transformations. For instance, semantic features can be linearly transformed to expand their dimension to the first dimension. Similarly, detailed information can be linearly transformed to expand its dimension to the first dimension. The size of this first dimension can be set according to actual usage requirements; for example, the first dimension can be a standard data dimension that the image generation model can process.
[0179] Optionally, in conjunction with the above regarding Figure 3 as well as Figure 5 Related descriptions, such as Figure 5 As shown above, in the above Figure 5 In the illustrated process, the dimensions of semantic features and detailed hierarchical information can be adjusted separately through dimension mapping, such as mapping them both to the first dimension. In this scenario, the semantic features used for subsequent residual connections with the first hidden feature can be the dimension-adjusted semantic features.
[0180] See Figure 15 , Figure 15 Image A in the example is an image generated using the method provided in this application, based on an initial image and an image generation prompt. Compared to image B, generated using other methods with the same initial image and image generation prompt, image A generated in this application achieves better display effects in features such as the texture, direction, and density transition of hair in the eyebrow area, and also effectively enhances higher-frequency feature information such as the subtle texture of the forehead skin. Furthermore, low-frequency structural features such as the background outline behind the portrait remain stable without significant sharpening distortion. In contrast, image B, due to the lack of hierarchical control during the generation process, suffers from insufficient control over the texture information of high-frequency features such as hair, and fails to balance skin detail enhancement with low-frequency background processing, resulting in artifacts and texture blurring in the eyebrow area.
[0181] See Figure 16 ,exist Figure 16 In the image, the left, middle, and right images are obtained by fusing different levels of detail information from the same image, such as... Figure 16 The image on the left was generated to preserve low-frequency components. Although the final image shows the macroscopic structural relationship between the task and the background, high-frequency details such as eyebrow texture and the weave of the knitted hat were smoothed and blurred.
[0182] The middle image is generated using the mid-frequency component. Compared to the left image, the edge clarity of different details is improved, such as the edges of eyebrows and woven hats, which are clearer. However, the texture of individual features is still relatively rough.
[0183] The image on the right is generated based on high-frequency components. By combining the two images, it can be seen that by fusing high-frequency components during the image generation process, the texture of the eyebrows (such as the shape of a single hair), the weave of the knitted hat, and the texture of the skin can be accurately reproduced. The sharpness and realism of the image are significantly improved compared to the images on the left and in the middle.
[0184] Combination Figure 16 The comparison of image generation effects after fusing different feature components is shown in this application embodiment. By binding detailed hierarchical information with semantic features, accurate extraction and feature fusion of image features at different frequencies can be achieved. For example, in the image generation process, the first fusion feature (and the second fusion feature) in this application embodiment can be used to achieve hierarchical modeling and collaborative optimization of information at different levels (such as low-frequency structure, mid-frequency contour, and high-frequency details). This enables refined and hierarchical control of image generation, effectively suppressing or even avoiding problems such as loss of detail, artifacts, or over-sharpening caused by processing images with a single frequency band, thereby improving the fidelity and visual realism of the generated image and enhancing the accuracy of the generated image.
[0185] This application also provides an image generation apparatus, see [link to relevant documentation]. Figure 17 The image generating apparatus may include:
[0186] The acquisition module 1701 is used to obtain the image generation prompt and the initial image.
[0187] The first processing module 1702 is used to obtain the semantic features of the descriptive units in the image generation prompts and determine the detail level information of the descriptive units, wherein the detail level information represents the degree to which the descriptive units describe the detail information in the image.
[0188] The second processing module 1703 is used to fuse the obtained semantic features and the determined detailed level information to obtain the first fused feature.
[0189] The generation module 1704 is used to generate an image with prompt word description based on the initial image and the first fusion feature.
[0190] In one possible implementation, the second processing module 1703 includes: a feature concatenation unit for concatenating the obtained semantic features and the determined detail level information to obtain concatenated features; a first feature extraction unit for extracting features from the concatenated features to obtain a first hidden feature; a first feature enhancement unit for enhancing the first hidden feature using the obtained semantic features to obtain a first enhanced feature; an attention transformation unit for performing attention transformation on the first enhanced feature to obtain a second enhanced feature after enhancing the transformed feature based on the first enhanced feature; a second feature extraction unit for extracting features from the second enhanced feature to obtain a second hidden feature; and a second feature enhancement unit for enhancing the second hidden feature using the second enhanced feature to obtain a first fused feature.
[0191] In one possible implementation, the attention transformation unit is specifically used to perform at least one cascaded attention and enhancement process on the first enhanced feature, and to use the output feature of the last cascaded attention and enhancement process as the second enhanced feature. Each attention and enhancement process includes the following steps: performing a self-attention transformation on the input feature to obtain attention weight features, wherein in the first attention and enhancement process, the input feature is the first enhanced feature, and in subsequent attention and enhancement processes, the input feature is the output feature of the previous attention and enhancement process; using the input feature to enhance the attention weight features to obtain intermediate enhanced features; extracting features from the intermediate enhanced features to obtain intermediate hidden features; and using the intermediate enhanced features to enhance the intermediate hidden features to obtain output features.
[0192] In one possible implementation, the attention transformation unit is specifically used to obtain attention weight features in the following manner: based on the features in the input features that are associated with the details level information, the weights of the attention heads to which the details level information is described are updated; based on the updated weights, the input features are subjected to self-attention transformation to obtain attention weight features.
[0193] In one possible implementation, the generation module 1704 includes: a third feature extraction unit for extracting image features from the initial image; a feature fusion unit for fusing the image features and the determined detail level information to obtain a second fused feature; and a generation unit for generating an image with a prompt word description based on the first fused feature and the second fused feature.
[0194] In one possible implementation, the feature fusion unit includes: a feature fusion subunit for fusing image features and determined detail level information to obtain a third fused feature; a feature extraction subunit for extracting features from the third fused feature to obtain a third hidden feature; and a feature enhancement subunit for enhancing the third hidden feature using the initial image to obtain a second fused feature.
[0195] In one possible implementation, the feature fusion subunit is specifically used to fuse image features and determined detail level information to obtain a fourth fused feature; determine feature fusion components based on detail level information, wherein the feature fusion components include scaling components and / or offset components; and fuse the feature fusion components and the fourth fused feature to obtain a third fused feature.
[0196] In one possible implementation, the first processing module 1702 is specifically used to obtain the detail level determined based on the degree of description of detail information in the image by the description unit; determine the representation information of the detail level from the pre-generated representation information of each optional detail level to obtain the detail level information; wherein, the representation information of each optional detail level is generated in the following manner: determine the maximum total number of levels; determine a continuous integer sequence based on the maximum total number of levels as the level index sequence of the optional detail levels; map each index in the level index sequence to a level embedding vector of the prediction dimension to obtain the representation information of each optional detail level.
[0197] In one possible implementation, the second processing module 1703 is specifically used to map the obtained semantic features and the determined detail level information to the first dimension respectively; and to fuse the semantic features mapped to the first dimension and the detail level information mapped to the first dimension to obtain the first fused feature.
[0198] This application also provides an electronic device, such as... Figure 18As shown, it includes a processor 1801, a communication interface 1802, a memory 1803, and a communication bus 1804, wherein the processor 1801, the communication interface 1802, and the memory 1803 communicate with each other through the communication bus 1804.
[0199] Memory 1803 is used to store computer programs;
[0200] The processor 1801, when executing the program stored in the memory 1803, implements the image generation method described in the above method embodiments.
[0201] The communication bus mentioned in the above electronic devices can be a Peripheral Component Interconnect (PCI) bus or an Extended Industry Standard Architecture (EISA) bus, etc. This communication bus can be divided into address bus, data bus, control bus, etc. For ease of illustration, only one thick line is used to represent it in the diagram, but this does not mean that there is only one bus or one type of bus.
[0202] The communication interface is used for communication between the aforementioned electronic devices and other devices.
[0203] The memory may include random access memory (RAM) or non-volatile memory (NVM), such as at least one disk storage device. Optionally, the memory may also be at least one storage device located remotely from the aforementioned processor.
[0204] The processors mentioned above can be general-purpose processors, including central processing units (CPUs), network processors (NPs), etc.; they can also be digital signal processors (DSPs), application-specific integrated circuits (ASICs), field-programmable gate arrays (FPGAs), or other programmable logic devices, discrete gate or transistor logic devices, or discrete hardware components.
[0205] In another embodiment provided in this application, a computer-readable storage medium is also provided, which stores a computer program that, when executed by a processor, implements the steps of any of the above-described image generation methods.
[0206] In another embodiment provided in this application, a computer program product containing instructions is also provided, which, when run on a computer, causes the computer to execute any of the image generation methods described above.
[0207] In the above embodiments, implementation can be achieved entirely or partially through software, hardware, firmware, or any combination thereof. When implemented using software, it can be implemented entirely or partially in the form of a computer program product. The computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, all or part of the processes or functions described in the embodiments of this application are generated. The computer can be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device. The computer instructions can be stored in a computer-readable storage medium or transmitted from one computer-readable storage medium to another. For example, the computer instructions can be transmitted from one website, computer, server, or data center to another website, computer, server, or data center via wired (e.g., coaxial cable, fiber optic, digital subscriber line (DSL)) or wireless (e.g., infrared, wireless, microwave, etc.) means. The computer-readable storage medium can be any available medium that a computer can access or a data storage device such as a server or data center that integrates one or more available media. The available medium can be a magnetic medium (e.g., floppy disk, hard disk, magnetic tape), an optical medium (e.g., DVD), or a semiconductor medium (e.g., solid state disk (SSD)).
[0208] It should be noted that, in this document, relational terms such as "first" and "second" are used only to distinguish one entity or operation from another, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Furthermore, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Without further limitations, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes said element.
[0209] The various embodiments in this specification are described in a related manner. Similar or identical parts between embodiments can be referred to mutually. Each embodiment focuses on describing the differences from other embodiments. In particular, the apparatus embodiments are basically similar to the method embodiments, so the description is relatively simple; relevant parts can be referred to the descriptions of the method embodiments.
[0210] The above description is merely a preferred embodiment of this application and is not intended to limit the scope of protection of this application. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of this application are included within the scope of protection of this application.
Claims
1. An image generation method, characterized in that, include: Obtain image generation prompts and the initial image; Obtain the semantic features of the descriptive units in the image generation prompts, and determine the detail level information of the descriptive units, wherein the detail level information characterizes the degree to which the descriptive units describe the detail information in the image; The obtained semantic features and the determined detailed hierarchical information are fused to obtain the first fused feature; Based on the initial image, and based on the first fusion feature, an image with a prompt description is generated.
2. The method according to claim 1, characterized in that, The process of fusing the obtained semantic features and the determined level of detail information to obtain the first fused feature includes: The obtained semantic features and the determined detailed hierarchical information are combined to obtain the combined features; Extract the features from the spliced features to obtain the first hidden feature; The first hidden feature is enhanced using the obtained semantic features to obtain the first enhanced feature; The first enhanced feature is subjected to attention transformation to obtain a second enhanced feature after feature enhancement based on the transformed feature and the first enhanced feature. Extract the features of the second enhanced feature to obtain the second hidden feature; The second enhanced feature is used to enhance the second hidden feature to obtain the first fused feature.
3. The method according to claim 2, characterized in that, The step of performing attention transformation on the first enhanced feature to obtain a second enhanced feature after feature enhancement based on the transformed feature of the first enhanced feature includes: The first enhanced feature is subjected to at least one cascaded attention and enhancement process, and the output feature of the last cascaded attention and enhancement process is used as the second enhanced feature. Each attention and enhancement process includes the following steps: The input features are subjected to self-attention transformation to obtain attention weight features. In the first attention and enhancement process, the input features are the first enhancement features. In non-first attention and enhancement processes, the input features are the output features of the previous attention and enhancement process. The attention weight features are enhanced using the input features to obtain intermediate enhanced features; Extract the features of the intermediate enhanced features to obtain the intermediate hidden features; The intermediate enhanced features are used to enhance the intermediate hidden features to obtain the output features.
4. The method according to claim 3, characterized in that, The process of performing a self-attention transformation on the input features to obtain attention weight features includes: Based on the features in the input features that are associated with the level of detail information, update the weights of the attention heads to which the level of detail information is assigned. Based on the updated weights, the input features are subjected to self-attention transformation to obtain attention weight features.
5. The method according to claim 1, characterized in that, The step of generating an image with prompt word descriptions based on the initial image and the first fusion feature includes: Extract image features from the initial image; The image features and the determined detail level information are fused to obtain a second fused feature; Based on the first fusion feature and the second fusion feature, an image with a prompt word description is generated.
6. The method according to claim 5, characterized in that, The process of fusing the image features and the determined level of detail information to obtain a second fused feature includes: The image features and the determined level of detail information are fused to obtain a third fused feature; Extract the features of the third fusion feature to obtain the third hidden feature; The third hidden feature is enhanced using the initial image to obtain the second fused feature.
7. The method according to claim 6, characterized in that, The process of fusing the image features and the determined level of detail information to obtain a third fused feature includes: The image features and the determined detail level information are fused to obtain the fourth fused feature; The feature fusion components are determined based on the detailed level information, wherein the feature fusion components include scaling components and / or offset components; The feature fusion component and the fourth fusion feature are fused to obtain the third fusion feature.
8. The method according to any one of claims 1 to 7, characterized in that, Determining the detailed level information of the description unit includes: Obtain the detail level determined based on the degree of description of detail information in the image by the description unit; The detail level information is obtained by determining the representation information of the detail level from the pre-generated representation information of each optional detail level; The representation information for each optional detail level is generated in the following manner: Determine the maximum total number of levels; based on the maximum total number of levels, determine a continuous integer sequence as the level index sequence for the optional detail levels; map each index in the level index sequence to a level embedding vector of the prediction dimension to obtain the representation information of each optional detail level.
9. The method according to claim 1, characterized in that, The process of fusing the obtained semantic features and the determined level of detail information to obtain the first fused feature includes: The obtained semantic features and the determined detailed hierarchical information are respectively mapped to the first dimension; The semantic features mapped to the first dimension and the detailed hierarchical information mapped to the first dimension are fused to obtain the first fused feature.
10. An image generation apparatus, characterized in that, include: The acquisition module is used to obtain image generation prompts and the initial image; The first processing module is used to obtain the semantic features of the descriptive units in the image generation prompts and determine the detail level information of the descriptive units, wherein the detail level information represents the degree to which the descriptive units describe the detail information in the image; The second processing module is used to fuse the obtained semantic features and the determined detailed level information to obtain the first fused feature; The generation module is used to generate an image with a prompt word description based on the initial image and the first fusion feature.
11. The apparatus according to claim 10, characterized in that, The second processing module includes: The feature splicing unit is used to splice the obtained semantic features and the determined detailed level information to obtain spliced features; The first feature extraction unit is used to extract the features of the spliced features to obtain the first hidden feature; The first feature enhancement unit is used to enhance the first hidden feature using the obtained semantic features to obtain the first enhanced feature; An attention transformation unit is used to perform attention transformation on the first enhanced feature to obtain a second enhanced feature after feature enhancement of the transformed feature based on the first enhanced feature; The second feature extraction unit is used to extract the features of the second enhanced feature to obtain the second hidden feature; The second feature enhancement unit is used to enhance the second hidden feature using the second enhanced feature to obtain the first fused feature.
12. The apparatus according to claim 11, characterized in that, The attention transformation unit is specifically used to perform at least one cascaded attention and enhancement process on the first enhanced feature, and take the output feature of the last cascaded attention and enhancement process as the second enhanced feature. Each attention and enhancement process includes the following steps: The input features are subjected to self-attention transformation to obtain attention weight features. In the first attention and enhancement process, the input features are the first enhancement features. In non-first attention and enhancement processes, the input features are the output features of the previous attention and enhancement process. The attention weight features are enhanced using the input features to obtain intermediate enhanced features; Extract the features of the intermediate enhanced features to obtain the intermediate hidden features; The intermediate enhanced features are used to enhance the intermediate hidden features to obtain the output features.
13. An electronic device, characterized in that, It includes a processor, a communication interface, a memory, and a communication bus, wherein the processor, the communication interface, and the memory communicate with each other through the communication bus; Memory, used to store computer programs; A processor, when executing a program stored in memory, implements the method according to any one of claims 1 to 9.
14. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores a computer program that, when executed by a processor, implements the method described in any one of claims 1 to 9.
15. A computer program product containing instructions, characterized in that, When the computer program product is run on a computer, it causes the computer to perform the method according to any one of claims 1 to 9.
