Figure graph model, model training method and device, image generation method and device and electronic equipment
By combining the public text encoder network and the user preference text encoder network with the diffusion model, the problem of random output styles of the Vincentian graph model is solved, user customization of image styles is realized, and the pertinence and aesthetics of image generation are improved.
Patent Information
- Application Number
- CN202410809420.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-06-21
- Publication Date
- 2024-09-17
AI Technical Summary
When the existing Vincentian graph model does not specify a style, the image style output is relatively random, making it difficult to meet the specific needs of users.
The public text encoder network and the user preference text encoder network are combined with the diffusion model to generate images that conform to the user's preferred style through noise prediction processing and decoding processing.
This ensures that the generated image style meets user needs and improves the pertinence and beauty of image generation.
Smart Images

Figure CN118657845A
Abstract
Description
Technical Field
[0001] The present application belongs to the field of artificial intelligence technology, and specifically relates to a text-generated graph model, model training, image generation method, device and electronic equipment. Background Art
[0002] At present, artificial intelligence (AI) has been widely used in the multimedia field. For example, the Vincent image algorithm in the field of AI painting has been widely used in the fields of wallpaper, avatar, game, animation design, etc., greatly improving the efficiency of image creation and design. However, in the related technology, when using the model to generate images, for the instructions input by the user, if there is no specified style, the style of the image output by the model is relatively random, and it is difficult to obtain an image with the image style required by the user. Summary of the invention
[0003] The purpose of the embodiments of the present application is to provide a text-generated graph model, model training, image generation method, device and electronic device, which can achieve the style of the image output by the text-generated graph model to be the image style required by the user.
[0004] In a first aspect, an embodiment of the present application provides a cultural graph model, including:
[0005] A common text encoder network, used to convert image description information into a common text feature vector, wherein the image description information is used to describe the image content contained in the image generated by the text-generated graph model;
[0006] A user preference text encoder network, configured to output a user preference text feature vector based on the common text feature vector, wherein the user preference text feature vector is used to indicate image content contained in the image generated by the text-generated graph model and a painting style corresponding to the image content; the user preference text encoder network is connected to the common text encoder network;
[0007] A diffusion model is used to perform noise prediction processing on the common text feature vector and the user preference text feature vector to obtain a first prediction noise, wherein the first prediction noise is used to perform denoising processing on the user preference text feature vector; the diffusion model is connected to the common text encoder network and the user preference text encoder network respectively;
[0008] The image decoder is used to decode the user preference text feature vector after denoising and output an image.
[0009] In a second aspect, a model training method is provided for training the Wensheng graph model as described in the first aspect, the method comprising:
[0010] Acquire at least one training sample, each training sample including image description information, an image sample and a painting style sample, wherein the training sample is obtained based on user preference information;
[0011] The initial model is trained by using the at least one training sample to obtain a text-based graph model; the text-based graph model is used to generate M images corresponding to the user preference information according to the image description information, where M is an integer greater than 1.
[0012] In a third aspect, an image generation method is provided, comprising:
[0013] Inputting image description information into a common text encoder network of the text-generated graph model as described in the first aspect to obtain a common text feature vector, wherein the image description information is used to indicate image content contained in an image generated by the text-generated graph model;
[0014] Input the common text feature vector into the user preference text encoder network of the text-generated graph model, and output a user preference text feature vector; wherein the user preference text feature vector is used to indicate the image content contained in the image generated by the text-generated graph model and the painting style corresponding to the image content;
[0015] De-noising the user preference text feature vector by using the diffusion model of the text graph model to obtain the user preference text feature vector after de-noising;
[0016] The denoised user preference text feature vector is decoded by the image decoder of the text-generated graph model to obtain an image.
[0017] In a fourth aspect, an embodiment of the present application provides a model training device for training the viz graph model as described in the first aspect, comprising:
[0018] A first acquisition module is used to acquire at least one training sample, each training sample includes image description information, an image sample and a painting style sample, and the training sample is obtained based on user preference information;
[0019] A training module is used to perform model training on the initial model through the at least one training sample to obtain a Wensheng graph model; the Wensheng graph model is used to generate M images corresponding to the user preference information according to the image description information, where M is an integer greater than 1.
[0020] In a fifth aspect, an image generating device is provided, comprising:
[0021] A second acquisition module, configured to input image description information into a common text encoder network of the text-generated graph model as described in the first aspect to obtain a common text feature vector, wherein the image description information is used to indicate image content contained in an image generated by the text-generated graph model;
[0022] A third acquisition module is used to input the common text feature vector into the user preference text encoder network of the Wensheng graph model, and output a user preference text feature vector; wherein the user preference text feature vector is used to indicate the image content contained in the image generated by the Wensheng graph model and the painting style corresponding to the image content;
[0023] A fourth acquisition module is used to perform denoising on the user preference text feature vector through a diffusion model of the text graph model to obtain a denoised user preference text feature vector;
[0024] The fifth acquisition module is used to decode the user preference text feature vector after denoising through the image decoder of the text graph model to obtain an image.
[0025] In a sixth aspect, an embodiment of the present application provides an electronic device, comprising a processor and a memory, wherein the memory stores programs or instructions that can be run on the processor, and when the programs or instructions are executed by the processor, the steps of the method described in the second aspect are implemented.
[0026] In the seventh aspect, an embodiment of the present application provides an electronic device, which includes a processor and a memory, wherein the memory stores programs or instructions that can be run on the processor, and when the program or instructions are executed by the processor, the steps of the method described in the third aspect are implemented.
[0027] In an eighth aspect, an embodiment of the present application provides a readable storage medium, on which a program or instruction is stored. When the program or instruction is executed by a processor, the steps of the method described in the second aspect or the third aspect are implemented.
[0028] In the ninth aspect, an embodiment of the present application provides a chip, comprising a processor and a communication interface, wherein the communication interface is coupled to the processor, and the processor is used to run programs or instructions to implement the method described in the second aspect or the third aspect.
[0029] In the tenth aspect, an embodiment of the present application provides a computer program product, which is stored in a storage medium and is executed by at least one processor to implement the method described in the second aspect or the third aspect.
[0030] In an embodiment of the present application, the training samples of the text graph model are obtained based on user preference information. The user preference text encoder network in the text graph model can learn the user preference information, so that the text graph model obtained based on the training samples can generate an image style corresponding to the user preference information, thereby ensuring that the image style output by the text graph model is the image style required by the user. BRIEF DESCRIPTION OF THE DRAWINGS
[0031] Figure 1 is a schematic diagram of the structure of a Wensheng graph model provided in some embodiments of the present application;
[0032] Figure 2 is a schematic diagram of a common text encoder provided by some embodiments of the present application;
[0033] Figure 3 is a schematic diagram of an image decoder provided in some embodiments of the present application;
[0034] Figure 4 is a schematic diagram of an image encoder provided by some embodiments of the present application;
[0035] Figure 5 is a schematic diagram of a user preference text encoder provided by some embodiments of the present application;
[0036] Figure 6 is a flowchart of a model training method provided by some embodiments of the present application;
[0037] Figure 7 is a schematic diagram of a data flywheel based on user preferences provided by some embodiments of the present application;
[0038] Figure 8 is a schematic diagram of inputting a drawing instruction to a Wensheng graph model provided by some embodiments of the present application;
[0039] Fig. 9 is a schematic diagram of generating an image based on a Wensheng graph model provided by some embodiments of the present application;
[0040] Fig.10 is a schematic diagram of a training process of a user preference text encoder network provided by some embodiments of the present application;
[0041] Fig.11 is a schematic diagram of a first diffusion model provided by some embodiments of the present application;
[0042] Fig.12 is a schematic diagram of a training process of a first diffusion model or a second diffusion model provided in some embodiments of the present application;
[0043] Fig.13 is a schematic diagram of an image generation method provided by some embodiments of the present application;
[0044] Fig.14 is a schematic diagram of generating an image based on a Wensheng graph model provided by some embodiments of the present application;
[0045] Fig.15 is a schematic diagram of a module of a model training device provided in some embodiments of the present application;
[0046] Fig.16 is a module schematic diagram of an image generating device provided by some embodiments of the present application;
[0047] Fig.17 is a structural block diagram of an electronic device provided by some embodiments of the present application;
[0048] Fig.18 This is a structural block diagram of an electronic device provided in some embodiments of the present application. DETAILED DESCRIPTION
[0049] The following will be combined with the drawings in the embodiments of the present application to clearly describe the technical solutions in the embodiments of the present application. Obviously, the described embodiments are part of the embodiments of the present application, rather than all the embodiments. All other embodiments obtained by ordinary technicians in this field based on the embodiments in the present application belong to the scope of protection of this application.
[0050] The terms "first", "second", etc. in the specification and claims of the present application are used to distinguish similar objects, and are not used to describe a specific order or sequence. It should be understood that the data used in this way can be interchangeable under appropriate circumstances, so that the embodiments of the present application can be implemented in an order other than those illustrated or described here, and the objects distinguished by "first", "second", etc. are generally of one type, and the number of objects is not limited. For example, the first object can be one or more. In addition, "and / or" in the specification and claims represents at least one of the connected objects, and the character " / " generally indicates that the objects associated with each other are in an "or" relationship.
[0051] The following, in conjunction with the accompanying drawings, describes in detail the text graph model, model training method, and image generation method provided in the embodiments of the present application through specific embodiments and their application scenarios.
[0052] It should be noted that the model training method and image generation method provided in the embodiments of the present application can be executed by electronic devices such as mobile phones, tablet computers, laptops, PDAs, and vehicle-mounted electronic devices. In some embodiments of the present application, the model training method and image generation method provided in the embodiments of the present application are illustrated by taking the electronic device as the execution subject to execute the model training method and image generation method.
[0053] like Figure 1 As shown, the embodiment of the present application provides a cultural graph model, including:
[0054] (1) A common text encoder network, used to convert image description information into a common text feature vector, wherein the image description information is used to describe the image content contained in the image generated by the text-generated graph model.
[0055] The above image description information may also be described as a drawing instruction. For example, the image description information may be to draw a female character.
[0056] The common text encoder network converts the image description information into a common text feature vector, so that the text feature vector can interact with the image feature vector in the future to achieve the purpose of text-controlled image generation. Since the text feature vector extracted based on the image description information in the common text encoder network has no style preference, the text feature vector output by the common text encoder network is called a common text feature vector.
[0057] Optionally, a network structure of a common text encoder network is as follows Figure 2 As shown in the figure, it includes: a tokenizer module and 12 self-attention modules (Transformer Block). Each self-attention module includes a self-attention (SelfAttention) operator, a vector addition operator (Add), a normalization operator (Norm) and a forward feedback operator (Feed Forward). QKV is the three input vectors of the attention mechanism, which represent the query (Query), key (Key) and value (Value) respectively. In the self-attention (SelfAttention) mechanism, these three vectors come from the same input mapping; in the cross-attention (CrossAttention) mechanism, Query is mapped as an independent input, and Key and Value come from the same input mapping.
[0058] Specifically, the image description information first passes through the Tokenizer module, which is used to convert the text into a numerical vector with a dimension of [128, 768], where 128 represents the maximum number of character tokens and 768 is the representation vector of each character. The [128, 768]-dimensional numerical vector is then input into the self-attention module for self-attention calculation to obtain a [128, 768]-dimensional vector, which is recorded as the text encoder vector (TEV), i.e., the above-mentioned common text feature vector.
[0059] (2) a user preference text encoder network, which is used to output a user preference text feature vector based on the common text feature vector, wherein the user preference text feature vector is used to indicate the image content contained in the image generated by the text-generated graph model and the painting style corresponding to the image content; the user preference text encoder network is connected to the common text encoder network.
[0060] The user preference text encoder network is mainly used to convert the common text feature vector into a user preference text feature vector with user style preference, so as to facilitate the subsequent interaction with the image feature vector and realize the generation of images with style preference.
[0061] (3) a diffusion model, used to perform noise prediction processing on the common text feature vector and the user preference text feature vector to obtain a first prediction noise, wherein the first prediction noise is used to perform denoising processing on the user preference text feature vector; the diffusion model is connected to the common text encoder network and the user preference text encoder network respectively.
[0062] Optionally, the diffusion model can implement Figure 1 One-stage noise prediction processing and two-stage noise prediction processing.
[0063] Among them, the first-stage noise prediction processing includes performing noise prediction processing on the common text feature vector to obtain a second predicted noise, and the second predicted noise is used to denoise the common text feature vector. The second-stage noise prediction processing includes performing noise prediction processing on the user preference text feature vector based on the denoised common text feature vector to obtain a first predicted noise.
[0064] (4) An image decoder is used to decode the user preference text feature vector after denoising and output an image.
[0065] The image decoder is used to convert the user preference text feature vector into an image, thereby realizing image generation.
[0066] Optionally, the structure of the image decoder is as follows Figure 3 The figure shows three deconvolution layers: deconvolution layer 1 (DeconvBlock1), deconvolution layer 2, and deconvolution layer 3. The image reconstruction feature LatentB (dimension [32, 64, 64]) undergoes a series of deconvolution operations and finally generates a picture of [3, 512, 512]. The calculation process of DeconvBlock1, DeconvBlock2, and DeconvBlock3 is the same, except that the deconvolution kernel, step size, and number of channels are different. Here, DeconvBlock2 is used as an example to explain the calculation process:
[0067] (1): The image [32, 64, 64] output by DeconvBlock1 is first calculated by the deconvolution layer Deconv2_1 to obtain a [16, 128, 128] feature matrix. The deconvolution kernel size is 3x3, the step size is 2, and the number of output channels is 16;
[0068] (2): The feature matrix of [16,128,128] dimensions is still a feature matrix of [16,128,128] dimensions after the Relu2_1 layer;
[0069] (3): Conv2_2, Relu2_2, Conv2_3, Relu2_3 are the usual convolution and Relu operations. The dimension of the final output feature matrix of DeconvBlock2 is [16, 128, 128].
[0070] Optionally, the Wensheng graph model of the embodiment of the present application also includes an encoder, which is used to encode the image into an image feature vector, and the subsequent image decoder is used to decode the image feature vector into an image, which is the inverse process of the process performed by the image encoder.
[0071] The image encoder is described below.
[0072] like Figure 4 As shown in the figure, the three-dimensional representation matrix [3,512,512] of the image first undergoes a series of convolutional neural network (CNN) convolution operations to become the image feature vector LatentA of [32,64,64] dimensions. The calculation process of convolution module 1 (ConvBlock1), convolution module 2 (ConvBlock2) and convolution module 3 (ConvBlock3) is the same, except that the step size of the convolution kernel is different. Here we take ConvBlock1 as an example to explain the calculation process:
[0073] (1): The image [3,512,512] first passes through the convolution layer Conv1_1 to calculate the [8,256,256] feature matrix. The convolution kernel size is 3x3, the stride is 2, and the number of output channels is 8;
[0074] (2): The feature matrix of [8,256,256] dimensions is still the feature matrix of [8,256,256] dimensions after the Relu1_1 layer;
[0075] (3): Conv1_2 and Relu1_2 repeat the process of Step1 and Step2, except that the convolution step size of Conv1_2 is changed to 1, which ensures that the dimension of the output feature matrix remains [8, 256, 256].
[0076] In the text-generated graph model of the embodiment of the present application, the user preference text encoder network can learn user preference information. By training the text-generated graph model with training samples containing user preference information, the text-generated graph model can generate an image style corresponding to the user preference information, thereby ensuring that the image style output by the text-generated graph model can meet the user's preference.
[0077] Optionally, the user preference text encoder network comprises:
[0078] N self-attention modules, each of which is used to generate a text feature vector based on a common text feature vector and a corresponding painting style; wherein each self-attention module corresponds to a painting style, and N is an integer greater than 1;
[0079] A gating network, used to output a gating weight corresponding to each of the self-attention modules, wherein the gating weight is used to indicate the probability that the user selects the painting style corresponding to the self-attention module; wherein the gating network is connected to each of the N self-attention modules respectively;
[0080] The processing module is used to determine the text feature vector generated by the self-attention module with the largest gate weight as the user preferred text feature vector.
[0081] As an optional implementation, the network structure of the user preference text encoder network is as follows: Figure 5 As shown in FIG. 1 , it includes a preset number of expert networks (Expert) and gate networks (Gate-Network), each of which includes a self-attention module (OneTransformerBlock). The preset number can be represented by N. The architecture of each expert network is similar to Figure 4 Here, Expert only stacks one self-attention module (12 self-attention modules are stacked in the common text feature vector encoder network), so the vector dimension remains unchanged, still [128,768].
[0082] The above gating network consists of N feedforward operators, and each FeedForward will go through a layer of Sigmoid to calculate a gating weight g. i (i=1,2,…,N), used to indicate the probability of selecting this style. The processor is based on the gating weight g 1 ,g 2 …,g N Select the style with the highest score, assuming it is style k (1≤k≤N), then the feature vector output by Expertk is used as the user preference text feature vector, denoted as StyleTextEmbedding.
[0083] The user preference text encoder network is capable of learning user preference information, and the gating network calculates the probability of selecting each painting style based on the learned user preference information. The processor determines the text feature vector generated by the self-attention module with the highest probability as the user preference text feature vector, thereby obtaining a text feature vector with user preference information, namely the user preference text feature vector, so as to facilitate subsequent interaction with the image feature vector and realize the generation of images with style preferences.
[0084] Optionally, the diffusion model includes:
[0085] A first diffusion model, the first diffusion model is connected to the common text encoder network and is used to perform noise prediction processing on the common text feature vector to obtain a second predicted noise, and the second predicted noise is used to perform denoising processing on the common text feature vector;
[0086] The second diffusion model, the second diffusion module is used to perform noise prediction processing on the user preference text feature vector based on the common text feature vector after denoising to obtain a first predicted noise.
[0087] The first diffusion model is used to implement a first-stage noise prediction process, and the second diffusion model is used to implement a second-stage noise prediction process.
[0088] The purpose of using two-stage text control to generate image features is because: the first stage uses a common text feature vector, and this process is used to achieve alignment between text and image content generation. The second stage uses text features of user style preferences, and this process is used to further generate image features of the corresponding style from the image features of the first stage to achieve alignment of text and image styles. Through these two core steps, it is possible to achieve alignment in both image content and image style. For example, if the image content is a female figure, the image style is an ink painting.
[0089] In the text-generated graph model of the embodiment of the present application, the user preference text encoder network can learn user preference information. By training the text-generated graph model with training samples containing user preference information, the text-generated graph model can generate an image style corresponding to the user preference information, thereby ensuring that the image style output by the text-generated graph model can meet the user's preference. Through two-stage noise prediction processing, the aesthetics of the image can be improved while ensuring the consistency of the image and text.
[0090] like Figure 6 As shown, the embodiment of the present application also provides a model training method for training the above-mentioned Wensheng graph model, comprising:
[0091] Step 601: Obtain at least one training sample, each training sample including image description information, an image sample and a painting style sample, and the training sample is obtained based on user preference information.
[0092] In the embodiment of the present application, the training samples can be obtained according to the images output by the context image model within a preset time and the images selected by the user from the images output by the model. For example, the preset time can be one month.
[0093] Step 602: The initial model is trained by using the at least one training sample to obtain a text-based graph model; the text-based graph model is used to generate M images corresponding to the user preference information according to the image description information, where M is an integer greater than 1.
[0094] Optionally, the initial model is a model that generates M images based on image description information, and the image styles of the M images are image styles randomly selected by the model from preset image styles.
[0095] For example, the Wensheng graph model is used to generate M images corresponding to a target painting style according to a painting instruction, where the target painting style is a painting style corresponding to user preference information.
[0096] For example, Figure 7 As shown, the initial model generates an image based on the user's drawing instructions, the user makes a preference selection among the generated images, and then the user's behavior data is recorded and recovered. The behavior data is the user's behavior of selecting images among the images output by the model. Then, the model is iteratively trained based on the user's behavior data to produce a trained text image model, and the text image service is updated based on the produced model, so that the style of the image generated by the text image model can be closer to the image style required by the user.
[0097] The model training method of the embodiment of the present application uses training samples obtained based on user preference information to train the initial model, so that the user preference text encoder network in the text-based graph model can learn the user preference information, so that the text-based graph model obtained based on the training samples can generate an image style corresponding to the user preference information, thereby ensuring that the image style output by the text-based graph model can meet the user's preference.
[0098] Optionally, obtaining at least one training sample includes:
[0099] Get the image description information entered by the user;
[0100] Input the image description information into the Wensheng graph model and output M images, each image corresponds to a painting style, and different images correspond to different painting styles;
[0101] Using an image selected by a user from the M images as an image sample, and using a painting style corresponding to the image selected by the user as a painting style sample;
[0102] The training sample is obtained according to the image description information, the image sample and the painting style sample.
[0103] Optionally, the above image description information is referred to as a drawing instruction, which is used to indicate a target object generated by the text image model, and the target object may be a person, an animal, or a landscape. Figure 8 As shown, the user inputs a drawing instruction according to prompt information 801, and the prompt information 801 is "input drawing instruction". The drawing instruction 802 input by the user is "draw a female character". It is assumed that the drawing styles supported by the Wensheng graph model include 20 candidate styles as shown in Table 1, such as Fig. 9 As shown, the Vincent graph model randomly outputs images of four painting styles based on the painting instruction. For example, the four painting style images are ink painting style image 901, watercolor painting style image 902, oil painting style image 903, and photographic style image 904.
[0104] A selection button is displayed below each painting style image generated by the Wensheng graph model for users to select an image of that painting style, such as Fig. 9 As shown, two buttons, "Paint the same style" and "Download", are provided under the image of each painting style. Whether the user clicks "Paint the same style" or "Download", it means that the user has selected the image of the corresponding painting style. For example, if the user clicks the "Paint the same style" button under the image of the ink painting, 4 ink paintings of the same style will be generated. Assuming that the user clicks the download button, the corresponding picture is directly downloaded to the mobile phone album. Based on the user's above selection operation, a training sample <a female figure, ink painting, corresponding ink painting female figure image> is obtained, and the training sample is a triple data. By recycling the training samples in the above target time period, the training samples of the Wensheng graph model are obtained.
[0105] Table 1
[0106] Style ID Style Name 1 Ink Painting 2 Watercolor 3 painting 4 Crayon Drawing 5 Pencil drawing 6 Children's drawings 7 Sketch 8 Abstract Painting 9 mural 10 illustration 11 traditional Chinese painting 12 Impressionism 13 Digital Art Painting 14 2D Animation 15 3D Animation 16 Cartoon 17 game 18 Photography 19 Cyberpunk 20 Low Poly
[0107] In an embodiment of the present application, a training sample is obtained based on an image output by a text-generated image model within a preset time and an image selected by a user from among the images output by the model, so that the training sample is a training sample that can reflect the user's preference selection, and then the text-generated image model is subsequently trained by the training sample containing the user's preference information, so that the text-generated image model can generate an image style corresponding to the user's preference information, thereby ensuring that the image style output by the text-generated image model can meet the user's preference.
[0108] Optionally, the performing model training on the initial model by using the at least one training sample to obtain the Wensheng graph model includes:
[0109] At least one network parameter of a user preference text encoder network in the text graph model is updated according to the image description information, the painting style sample and the first loss function in the training sample.
[0110] At least one network parameter of the first diffusion model in the text graph model is updated according to the image description information in the training sample and the second loss function.
[0111] At least one network parameter of the second diffusion model in the Vincent graph model is updated according to the image description information in the training samples, the painting style samples, the image samples and the third loss function.
[0112] According to the trained user preference text encoder network, the first diffusion model and the second diffusion model, a text graph model is obtained.
[0113] The training process in the embodiment of the present application mainly includes the training process of the user preference text encoder network, the first diffusion model and the second diffusion model. By training the user preference text encoder network, the first diffusion model and the second diffusion model, the output model can be optimized in the direction of user preference.
[0114] Optionally, updating at least one network parameter of a user preference text encoder network in the text graph model according to the image description information, the painting style sample and the first loss function in the training sample includes:
[0115] Determine, according to the image description information and the painting style sample, a selection probability of each painting style selected by the user from N painting styles, wherein the selection probability of a first painting style is 1, and the selection probability of a second painting style is 0, the first painting style is a painting style corresponding to the painting style sample, and the second painting style is a painting style other than the first painting style among the N painting styles;
[0116] At least one network parameter of the user preference text encoder network in the text graph model is updated according to the selection probability, the gating weights corresponding to the N self-attention modules in the user preference text encoder network, and the first loss function.
[0117] Assume that the first loss function is recorded as L1, such as Fig.10 As shown, the process includes:
[0118] (1): For the gate weight value g i Normalized by softmax, the normalized gating weight p is obtainedi , as shown in formula (1);
[0119] (2):y i (i=1,2…,N) represents the style selected by the user. When the user selects style i (such as ink painting style), the corresponding y i =1; the corresponding y of other styles is 0;
[0120] Step 3: g i and i And calculate the cross entropy loss (CrossEntropyLoss), that is, L1, as shown in formula (2).
[0121]
[0122] Assume N = 3, and the user selects the second style, y 2 =1,g 2 =0.6;y 1 =0,g 1 =0.2,y 3 =0,g 3 =0.2, then based on the above formula (1), we can get: Based on formula (2), we can get:
[0123] Here, based on the image description information and the painting style samples, the probability of the user selecting each of the N painting styles is determined, and according to the selection probability, the gating weights corresponding to the N self-attention modules in the user preference text encoder network and the first loss function, at least one network parameter of the user preference text encoder network in the text graph model is updated, so that the user preference text encoder network can learn the user's preference, and then subsequently enable the text graph model to generate an image style corresponding to the user preference information, thereby ensuring that the image style output by the text graph model can meet the user's preference.
[0124] Optionally, updating at least one network parameter of the first diffusion model in the cultural graph model according to the image description information in the training sample and the second loss function includes:
[0125] Inputting the image description information into a common text encoder network and outputting a common text feature vector;
[0126] Inputting the image corresponding to the image description information into the image encoder of the Wensheng graph model, and outputting a first image feature vector;
[0127] Inputting the first image feature vector with the first random noise added thereto and the common text feature vector into the first diffusion model, and outputting a third predicted noise;
[0128] At least one network parameter of a first diffusion model in the Vincent graph model is updated according to the third prediction noise, the first random noise and the second loss function.
[0129] In the above training process, random noise is added to the image features, and then the random noise is predicted by the first diffusion model, so as to achieve the de-noising and denoising of the image features. In the process of image feature denoising, the text feature vector is introduced to interact with the noisy image feature vector to achieve the prediction of noise, thereby realizing the image generation process with text as the control condition. The structure of the first diffusion model is as follows Fig.11 As shown:
[0130] (1) Construction process of text condition vector (TCV):
[0131] (1.1) According to the common text feature vector CTE (Common Text Embedding), after a linear mapping layer (Project), a text encoding vector (Text Project Vector, TPV) with a dimension of [320,768] is obtained;
[0132] (1.2) Initialize a time embedding layer Embedding with a dimension of [320, 1280], and then pass it through a linear mapping layer Project to obtain a time mapping Embedding with a dimension of [320, 768];
[0133] (1.3) Add the text encoding vector TPV and the time mapping Embedding to obtain the text conditional control vector TCV, with a dimension of [320,768];
[0134] (2) Image Project Vector (IPV) Construction Process:
[0135] (2.1) Add a random Gaussian noise matrix NoiseA to the image feature vector LatentA through the AddNoise operation to obtain the image latent matrix NoiseLatentA after noise addition;
[0136] Here, LatentA is the first image feature vector, and the first random noise is NoiseA.
[0137] (2.2) Perform the convolution operation of Conv on NoiseLatentA to obtain a matrix of dimension [320, 64, 64]. The convolution kernel size corresponding to this matrix is 3x3, the step size is 1, and the number of output channels is 320). The matrix is reshaped to obtain an image project vector (IPV) of dimension [320, 64x64].
[0138] (3) Diffusion module (DiTBlock) calculation process based on Transformer architecture: The entire calculation process is composed of several DiTBlock stacks. The following is a DiTBlock, that is, Fig.11 The small picture on the right of DiTBlock explains:
[0139] (3.1) CrossAttention module, which uses the image encoding mapping vector IPV as the query and the text condition control vector TCV as the key and value to calculate the cross attention mechanism. The meanings of Add, Norm, and FeedForward are the same as those of the operators described above and will not be repeated here.
[0140] (3.2): Repeat the process of (3.1), use the output of (3.1) as the new query, and keep the Key and Value the same as Step 1, and repeat this process. After several DiTBlocks, the calculation process of the first diffusion model is completed;
[0141] (4) Construction process of image reconstruction feature LatentA:
[0142] (4.1) After a series of DiTBlock outputs, the vector dimension is [320, 64, 64]. After a layer of convolution Conv_out layer is calculated, a vector of dimension [32, 64, 64] is obtained, which is recorded as the image prediction noise matrix PredNoiseA. PredNoiseA is the third prediction noise.
[0143] (4.2) Subtract the image prediction noise matrix PredNoiseA from the image feature vector NoiseLatentA to obtain the final image reconstruction feature LatentB (i.e. LatentB = NoiseLatentA-PredNoiseA), with a dimension of [32, 64, 64], which is used as output.
[0144] like Fig.12As shown in the figure, the output result of the first-stage noise prediction network is PredNoiseA. The random noise matrix NoiseA and PredNoiseA added at the beginning are used to construct the MSE loss function, which is recorded as L2. This L2 is the second loss function. By training this loss function, the network parameters of the first diffusion model can be adjusted by backpropagation, so that the output PredNoiseA of the first diffusion model can approximate the random noise matrix NoiseA. Finally, the formula LatentB = NoisedLatentA-PredNoiseA is obtained.
[0145] By training the first diffusion model, the purpose of controlling the generation of images through common text feature vectors can be achieved. Since the first diffusion model training process uses common text feature vectors, the trained first diffusion model can achieve consistency between text content and image content.
[0146] Optionally, updating at least one network parameter of the second diffusion model in the Vincent graph model according to the image description information in the training sample, the painting style sample, the image sample and the third loss function includes:
[0147] Inputting the image description information into a common text encoder network and outputting a common text feature vector;
[0148] Inputting the common text feature vector and the painting style sample into a user preference text encoder network, and outputting a user preference text feature vector;
[0149] The image sample is input into the image encoder in the Wensheng graph model, and a second image feature vector is output; the second image feature vector may correspond to Figure 1 LatentA in;
[0150] Inputting the second image feature vector and the common text feature vector added with the second random noise into the first diffusion model, and outputting a fourth predicted noise; the fourth predicted noise may correspond to PredNoiseA;
[0151] Based on the fourth predicted noise, the second image feature vector with the second random noise is denoised to obtain a third image feature vector; the third image feature vector may correspond to Figure 1 LatentB in;
[0152] The third image feature vector with the third random noise added and the user preference text feature vector are input into the second diffusion model to output the fifth prediction noise; the third random noise corresponds to Figure 1 NoiseB in the image, the third image feature vector with the third random noise added corresponds to Figure 1Noise LatentB in; the fifth predicted noise corresponds to Figure 1 PredNoiseB in.
[0153] At least one network parameter of a second diffusion model in the Vincent graph model is updated according to the second random noise, the fifth prediction noise and the third loss function.
[0154] In some embodiments of the present application, the training process of the second diffusion model is similar to the training process of the first diffusion model, except that the control condition is changed from the common text feature vector to the user preference text feature vector. The training process of the first diffusion model can be described as a one-stage noise prediction process, and the training process of the second diffusion model can be described as a two-stage noise prediction process. The two-stage noise prediction process is as follows:
[0155] (1) Fig.11 The common text feature vector (CommonTextEmbedding) in is changed to the user preference text feature vector (StyleTextEmbedding), such as Figure 1 As shown, that is to say, the text feature vector encoded by the user preference text encoder network is used as the control condition of the two-stage diffusion model and input into the two-stage diffusion model.
[0156] (2) Fig.11 The input LatentA in is changed to LatentB, the random noise matrix NoiseA is changed to NoiseB, NoiseLatentA is changed to NoiseLatentB, the predicted noise matrix PredNoiseA is changed to PredNoiseB, and the final output LatentB is changed to LatentC, such as Figure 1 As shown;
[0157] (3) Fig.11 15 DiTBLocks are stacked in the network. The two-stage diffusion model does not require so many network layers, so it is replaced by 5 layers of DiTBlock stacked.
[0158] Reference Fig.12 , the output of the two-stage noise prediction network is PredNoiseB, and the MSE loss function is constructed using the random noise matrix NoiseB and PredNoiseB added at the beginning, denoted as L3. By training this loss function, the network parameters of the second diffusion model can be adjusted by backpropagation, so that the output PredNoiseB of the second diffusion model can approximate the random noise matrix NoiseB, and finally LatentC = NoisedLatentB-PredNoiseB is obtained by the formula.
[0159] By training the second diffusion model, the purpose of controlling the generation of images through the user preferred text feature vector can be achieved. Since the second diffusion model training process adopts the user preferred text feature vector, the trained second diffusion model can achieve consistency between the text content and the image painting style.
[0160] By training the first diffusion model and the second diffusion model, the image output by the model can be made consistent with the common text feature vector in terms of content, and consistent with the user preference text feature vector in terms of painting style.
[0161] In order to better understand the above training process, the entire network structure is explained as follows.
[0162] The image encoder in the Wensheng graph model is used to convert the real image into an image feature vector; the image decoder in the Wensheng graph model is used to convert the image feature vector into the real image. These two processes are mutually inverse processes, and they realize the conversion between the real image and the image feature vector. Since the real image is a matrix of size [3,512,512], and the image feature vector is a matrix of size [32,64,64], it can be seen from the calculation of the number of elements of these two matrices that the image feature vector matrix is smaller than the real image matrix. Therefore, in order to realize text-controlled image generation, it is only necessary to perform it in the image feature space, treat the image feature vector as a real image, and then after the text controls the generation of the image feature vector, the image feature vector can be converted into a real image through the image decoder, which can save the amount of calculation. The process of realizing text-controlled generation of image features is the first-stage noise prediction and the second-stage noise prediction.
[0163] The entire model training process in the embodiment of the present application is described below.
[0164] Assume that the training data set is S, which is a training set composed of triple data such as <a female figure, ink painting, and the corresponding image of the female figure in the ink painting>. During the training process, the above reasoning process will be performed on each triple data in the training set S, and then the three loss functions mentioned above will be used to derive the network parameters, and then back propagation will be implemented to complete the update of the network parameters. When each sample in the training set S is trained, the training is terminated, and a version of the text-based graph model is produced.
[0165] Exemplarily, the specific training process is as follows:
[0166] First, based on the loss function L1, the user preference text encoder is trained using user preference data such as <a female figure, ink painting> until the training set S is traversed. By training the user preference text encoder network, the user preference text features are extracted.
[0167] Then, based on the loss function L2, the first diffusion model is trained using a picture such as <a female character, a picture of four styles of a female character randomly selected> until the training set S is traversed. By training a one-stage noise prediction model, namely the first diffusion model, the common text features are learned to control the generation of image content, thereby generating the network parameters of the first diffusion model, which can be described as model parameters or network weights.
[0168] Next, based on the loss function L3, a two-stage noise prediction model, i.e., the second diffusion model, is trained using a sentence such as <a female figure, ink painting, and the corresponding image of the female figure in the ink painting> until the training set S is traversed. By training the two-stage noise prediction model, the user's preferred text features are learned to control the generation of image style, thereby generating the network parameters of the second diffusion model.
[0169] Finally, the overall loss function L=a*L1+b*L2+c*L3 composed of three loss functions is end-to-end jointly trained for the user preference text encoder, the first diffusion model, and the second diffusion model, where a+b+c=1, a, b, c are hyperparameters that can be set during training, such as a=b=c=1 / 3, where the network weights of the three parts of the public text encoder, image encoder, and image decoder are frozen and not trained, thereby achieving full-link text-image training until the training set S is traversed. This process is mainly used to achieve end-to-end training, thereby connecting the three trained network structures above to form a complete network structure.
[0170] like Fig.13 As shown, the embodiment of the present application also provides an image generation method, including:
[0171] Step 1301: inputting image description information into the common text encoder network of the above-mentioned text-generated graph model to obtain a common text feature vector, wherein the image description information is used to indicate the image content contained in the image generated by the text-generated graph model.
[0172] The above image description information may also be described as a drawing instruction. For example, the image description information may be to draw a female character.
[0173] Step 1302: Input the common text feature vector into the user preference text encoder network of the text-generated graph model, and output a user preference text feature vector; wherein the user preference text feature vector is used to indicate the image content contained in the image generated by the text-generated graph model and the painting style corresponding to the image content.
[0174] Step 1303: De-noising the user preference text feature vector using the diffusion model of the text graph model to obtain the de-noised user preference text feature vector.
[0175] Step 1304: The denoised user preference text feature vector is decoded by the image decoder of the text graph model to obtain an image.
[0176] In the embodiment of the present application, since the text-generated image model is trained based on user preference information, after the image description information is input into the text-generated image model, the image style corresponding to the user preference information can be obtained, thereby ensuring that the image style output by the text-generated image model can meet the user's preference.
[0177] Optionally, the user preference text feature vector is denoised by using a diffusion model of the text graph model to obtain a denoised user preference text feature vector, including:
[0178] Input the common text feature vector into the first diffusion model and output the second prediction noise;
[0179] According to the second predicted noise, the common text feature vector is subjected to denoising processing to obtain a first text feature vector;
[0180] Inputting the first text feature vector and the user preference text feature vector added with the fourth random noise into the second diffusion model, and outputting the first prediction noise;
[0181] The user preference text feature vector is denoised according to the first predicted noise to obtain a denoised user preference text feature vector.
[0182] The specific working principles of the first diffusion model and the second diffusion model have been described in detail in the above embodiments and will not be repeated here.
[0183] After completing the above training process, a new Wenshengtu model can be generated, and then the Wenshengtu system service can be updated. Then, based on the new Wenshengtu model and user instructions, images are generated. Compared with the previous Wenshengtu service, the Wenshengtu model trained with user preferences can automatically calculate the top 4 styles according to user instructions, and then generate 4 pictures of the corresponding styles and push them to users. The calculation method of the top 4 styles is as follows:
[0184] Based on the above-mentioned gating network, the four largest gating weights g_a, g_b, g_c, and g_d are calculated. The gating weights are calculated by Sigmoid, and the corresponding four styles are used as the final styles to generate the corresponding images. The style of the pictures generated in this way is user-preferred and no longer a random style. For example, if the user inputs "draw a female figure", the gating network calculates the 20 style scores shown in Table 2 below, and selects the four styles with the highest scores: photography, 3D animation, ink painting, and illustration. Then the interface is displayed as follows: Fig.14 As shown, Fig.14 Displayed in the figure are a photographic-style image 1401 , a 3D anime-style image 1402 , an ink painting-style image 1403 , and an illustration-style image 1404 .
[0185] in,
[0186]
[0187] The calculation formula corresponding to sigmoid is as follows:
[0188]
[0189] Among them, w j are the network model parameters used for training and learning.
[0190] Table 2
[0191] Style ID Style Name Style Score 1 Ink Painting 0.88 2 Watercolor 0.71 3 painting 0.12 4 Crayon Drawing 0.06 5 Pencil drawing 0.65 6 Children's drawings 0.01 7 Sketch 0.72 8 Abstract Painting 0.21 9 mural 0.13 10 illustration 0.85 11 traditional Chinese painting 0.76 12 Impressionism 0.23 13 Digital Art Painting 0.21 14 2D Animation 0.74 15 3D Animation 0.93 16 Cartoon 0.55 17 game 0.42 18 Photography 0.96 19 Cyberpunk 0.81 20 Low Poly 0.11
[0192] Based on the above process, refer to Figure 7 The design is continuously trained and iterated. This process is repeated to form a data flywheel-driven Wensheng graph optimization solution.
[0193] It should be noted that the training method of the above-mentioned Vincent graph model in the embodiment of the present application can also be applied to Vincent video model or Vincent audio model, etc.
[0194] The model training method provided in the embodiment of the present application can be executed by a model training device. In the embodiment of the present application, the model training device executing the model training method is taken as an example to illustrate the model training device provided in the embodiment of the present application.
[0195] like Fig.15 As shown, the embodiment of the present application further provides a model training device 1500 for training the above-mentioned Wensheng graph model, the device comprising:
[0196] A first acquisition module 1501 is used to acquire at least one training sample, each training sample includes image description information, an image sample and a painting style sample, and the training sample is obtained based on user preference information;
[0197] The training module 1502 is used to perform model training on the initial model through the at least one training sample to obtain a text image model; the text image model is used to generate M images corresponding to the user preference information according to the image description information, where M is an integer greater than 1.
[0198] Optionally, the first acquisition module is specifically used to:
[0199] Get the image description information entered by the user;
[0200] Input the image description information into the Wensheng graph model and output M images, each image corresponds to a painting style, and different images correspond to different painting styles;
[0201] Using an image selected by a user from the M images as an image sample, and using a painting style corresponding to the image selected by the user as a painting style sample;
[0202] The training sample is obtained according to the image description information, the image sample and the painting style sample.
[0203] Optionally, the training module is specifically used for:
[0204] According to the image description information, the painting style sample and the first loss function in the training sample, updating at least one network parameter of the user preference text encoder network in the text graph model;
[0205] According to the image description information in the training sample and the second loss function, updating at least one network parameter of the first diffusion model in the Wensheng graph model;
[0206] updating at least one network parameter of a second diffusion model in the Vincent graph model according to the image description information in the training sample, the painting style sample, the image sample and the third loss function;
[0207] According to the trained user preference text encoder network, the first diffusion model and the second diffusion model, a text graph model is obtained.
[0208] Optionally, the training module is specifically used for:
[0209] Determine, according to the image description information and the painting style sample, a selection probability of each painting style selected by the user from N painting styles, wherein the selection probability of a first painting style is 1, and the selection probability of a second painting style is 0, the first painting style is a painting style corresponding to the painting style sample, and the second painting style is a painting style other than the first painting style among the N painting styles;
[0210] At least one network parameter of the user preference text encoder network in the text graph model is updated according to the selection probability, the gating weights corresponding to the N self-attention modules in the user preference text encoder network, and the first loss function.
[0211] Optionally, the training module is specifically used for:
[0212] Inputting the image description information into a common text encoder network and outputting a common text feature vector;
[0213] Inputting the image corresponding to the image description information into the image encoder of the Wensheng graph model, and outputting a first image feature vector;
[0214] Inputting the first image feature vector with the first random noise added thereto and the common text feature vector into the first diffusion model, and outputting a third predicted noise;
[0215] At least one network parameter of a first diffusion model in the Vincent graph model is updated according to the third prediction noise, the first random noise and the second loss function.
[0216] Optionally, the training module is specifically used for:
[0217] Inputting the image description information into a common text encoder network and outputting a common text feature vector;
[0218] Inputting the common text feature vector and the painting style sample into a user preference text encoder network, and outputting a user preference text feature vector;
[0219] Input the image sample into an image encoder in the Vincent graph model, and output a second image feature vector;
[0220] Inputting the second image feature vector and the common text feature vector added with the second random noise into the first diffusion model, and outputting a fourth predicted noise;
[0221] Based on the fourth predicted noise, denoising the second image feature vector with the second random noise added thereto to obtain a third image feature vector;
[0222] Inputting the third image feature vector with third random noise added thereto and the user preference text feature vector into the second diffusion model, and outputting fifth predicted noise;
[0223] At least one network parameter of a second diffusion model in the Vincent graph model is updated according to the second random noise, the fifth prediction noise and the third loss function.
[0224] In an embodiment of the present application, the initial model is trained using training samples obtained based on user preference information, so that the user preference text encoder network in the text graph model can learn the user preference information, so that the text graph model obtained based on the training samples can generate an image style corresponding to the user preference information, thereby ensuring that the image style output by the text graph model can meet the user's preference.
[0225] The image generation method provided in the embodiment of the present application can be executed by an image generation device. In the embodiment of the present application, the image generation device provided in the embodiment of the present application is described by taking the image generation method executed by the image generation device as an example.
[0226] like Fig.16 As shown, the embodiment of the present application provides an image generating device 1600, including:
[0227] The second acquisition module 1601 is used to input the image description information into the common text encoder network of the Wensheng graph model to obtain a common text feature vector, wherein the image description information is used to indicate the image content contained in the image generated by the Wensheng graph model;
[0228] The third acquisition module 1602 is used to input the common text feature vector into the user preference text encoder network of the Wensheng graph model, and output the user preference text feature vector; wherein the user preference text feature vector is used to indicate the image content contained in the image generated by the Wensheng graph model and the painting style corresponding to the image content;
[0229] The fourth acquisition module 1603 is used to perform denoising on the user preference text feature vector by using the diffusion model of the text graph model to obtain the user preference text feature vector after denoising;
[0230] The fifth acquisition module 1604 is used to decode the denoised user preference text feature vector through the image decoder of the text graph model to obtain an image.
[0231] Optionally, the fourth acquisition module is specifically used for:
[0232] Input the common text feature vector into the first diffusion model and output the second prediction noise;
[0233] According to the second predicted noise, the common text feature vector is subjected to denoising processing to obtain a first text feature vector;
[0234] Inputting the first text feature vector and the user preference text feature vector added with the fourth random noise into the second diffusion model, and outputting the first prediction noise;
[0235] The user preference text feature vector is denoised according to the first predicted noise to obtain a denoised user preference text feature vector.
[0236] In the embodiment of the present application, since the text-generated image model is trained based on user preference information, after the image description information is input into the text-generated image model, the image style corresponding to the user preference information can be obtained, thereby ensuring that the image style output by the text-generated image model can meet the user's preference.
[0237] The model training device and the image generation device in the embodiment of the present application can be electronic devices, or components in electronic devices, such as integrated circuits or chips. The electronic device can be a terminal, or other devices other than a terminal. Exemplarily, the electronic device can be a mobile phone, a tablet computer, a laptop computer, a PDA, a vehicle-mounted electronic device, a mobile Internet device (Mobile Internet Device, MID), an augmented reality (augmented reality, AR) / virtual reality (virtual reality, VR) device, a robot, a wearable device, an ultra-mobile personal computer (ultra-mobile personal computer, UMPC), a netbook or a personal digital assistant (personal digital assistant, PDA), etc., and can also be a server, a network attached storage (Network Attached Storage, NAS), a personal computer (personal computer, PC), a television (television, TV), a teller machine or a self-service machine, etc., which is not specifically limited in the embodiment of the present application.
[0238] The model training device and the image generation device in the embodiment of the present application may be a device having an operating system. The operating system may be an Android operating system, an IOS operating system, or other possible operating systems, which are not specifically limited in the embodiment of the present application.
[0239] The model training device provided in the embodiment of the present application can achieve Figures 6 to 12 To avoid repetition, the various processes implemented by the method embodiment are not described here.
[0240] The image generation device provided in the embodiment of the present application can achieve Fig.13 To avoid repetition, the various processes implemented by the method embodiment are not described here.
[0241] Alternatively, if Fig.17As shown, an embodiment of the present application also provides an electronic device 1700, including a processor 1701 and a memory 1702, wherein the memory 1702 stores programs or instructions that can be executed on the processor 1701, and when the program or instructions are executed by the processor 1701, the various steps of the above-mentioned model training method or image generation method embodiment are implemented, and the same technical effect can be achieved. To avoid repetition, they are not repeated here.
[0242] It should be noted that the electronic devices in the embodiments of the present application include the mobile electronic devices and non-mobile electronic devices mentioned above.
[0243] Fig.18 A schematic diagram of the hardware structure of an electronic device to implement an embodiment of the present application.
[0244] The electronic device 1800 includes but is not limited to: a radio frequency unit 1801, a network module 1802, an audio output unit 1803, an input unit 1804, a sensor 1805, a display unit 1806, a user input unit 1807, an interface unit 1808, a memory 1809, and a processor 1810 and other components.
[0245] Those skilled in the art will appreciate that the electronic device 1800 may also include a power source (such as a battery) for supplying power to each component, and the power source may be logically connected to the processor 1810 through a power management system, thereby implementing functions such as managing charging, discharging, and power consumption management through the power management system. Fig.18 The electronic device structure shown in the figure does not constitute a limitation on the electronic device. The electronic device may include more or fewer components than shown in the figure, or combine certain components, or arrange the components differently, which will not be described in detail here.
[0246] Among them, the processor 1810 is used to obtain at least one training sample, each training sample includes image description information, an image sample and a painting style sample, and the training sample is obtained based on user preference information; the initial model is trained through the at least one training sample to obtain a Vincent graph model; the Vincent graph model is used to generate M images corresponding to the user preference information according to the image description information, where M is an integer greater than 1.
[0247] In an embodiment of the present application, the initial model is trained using training samples obtained based on user preference information, so that the user preference text encoder network in the text graph model can learn the user preference information, so that the text graph model obtained based on the training samples can generate an image style corresponding to the user preference information, thereby ensuring that the image style output by the text graph model can meet the user's preference.
[0248] Optionally, the processor 1810 is further configured to:
[0249] Get the image description information entered by the user;
[0250] Input the image description information into the Wensheng graph model and output M images, each image corresponds to a painting style, and different images correspond to different painting styles;
[0251] Using an image selected by a user from the M images as an image sample, and using a painting style corresponding to the image selected by the user as a painting style sample;
[0252] The training sample is obtained according to the image description information, the image sample and the painting style sample.
[0253] Optionally, the processor 1810 is further configured to:
[0254] According to the image description information, the painting style sample and the first loss function in the training sample, updating at least one network parameter of the user preference text encoder network in the text graph model;
[0255] According to the image description information in the training sample and the second loss function, updating at least one network parameter of the first diffusion model in the Wensheng graph model;
[0256] updating at least one network parameter of a second diffusion model in the Vincent graph model according to the image description information in the training sample, the painting style sample, the image sample and the third loss function;
[0257] According to the trained user preference text encoder network, the first diffusion model and the second diffusion model, a text graph model is obtained.
[0258] Optionally, the processor 1810 is further configured to:
[0259] Determine, according to the image description information and the painting style sample, a selection probability of each painting style selected by the user from N painting styles, wherein the selection probability of a first painting style is 1, and the selection probability of a second painting style is 0, the first painting style is a painting style corresponding to the painting style sample, and the second painting style is a painting style other than the first painting style among the N painting styles;
[0260] At least one network parameter of the user preference text encoder network in the text graph model is updated according to the selection probability, the gating weights corresponding to the N self-attention modules in the user preference text encoder network, and the first loss function.
[0261] Optionally, the processor 1810 is further configured to:
[0262] Inputting the image description information into a common text encoder network and outputting a common text feature vector;
[0263] Inputting the image corresponding to the image description information into the image encoder of the Wensheng graph model, and outputting a first image feature vector;
[0264] Inputting the first image feature vector with the first random noise added thereto and the common text feature vector into the first diffusion model, and outputting a third predicted noise;
[0265] At least one network parameter of a first diffusion model in the Vincent graph model is updated according to the third prediction noise, the first random noise and the second loss function.
[0266] Optionally, the processor 1810 is further configured to:
[0267] Inputting the image description information into a common text encoder network and outputting a common text feature vector;
[0268] Inputting the common text feature vector and the painting style sample into a user preference text encoder network, and outputting a user preference text feature vector;
[0269] Input the image sample into an image encoder in the Vincent graph model, and output a second image feature vector;
[0270] Inputting the second image feature vector and the common text feature vector added with the second random noise into the first diffusion model, and outputting a fourth predicted noise;
[0271] Based on the fourth predicted noise, denoising the second image feature vector with the second random noise added thereto to obtain a third image feature vector;
[0272] Inputting the third image feature vector with third random noise added thereto and the user preference text feature vector into the second diffusion model, and outputting fifth predicted noise;
[0273] At least one network parameter of a second diffusion model in the Vincent graph model is updated according to the second random noise, the fifth prediction noise and the third loss function.
[0274] The processor 1810 is used to input the image description information into the common text encoder network of the above-mentioned Wensheng graph model to obtain a common text feature vector, wherein the image description information is used to indicate the image content contained in the image generated by the Wensheng graph model;
[0275] Input the common text feature vector into the user preference text encoder network of the text-generated graph model, and output a user preference text feature vector; wherein the user preference text feature vector is used to indicate the image content contained in the image generated by the text-generated graph model and the painting style corresponding to the image content;
[0276] De-noising the user preference text feature vector by using the diffusion model of the text graph model to obtain the user preference text feature vector after de-noising;
[0277] The denoised user preference text feature vector is decoded by the image decoder of the text-generated graph model to obtain an image.
[0278] Optionally, the processor 1810 is further configured to: input the common text feature vector into the first diffusion model, and output a second predicted noise;
[0279] According to the second predicted noise, the common text feature vector is subjected to denoising processing to obtain a first text feature vector;
[0280] Inputting the first text feature vector and the user preference text feature vector added with the fourth random noise into the second diffusion model, and outputting the first prediction noise;
[0281] The user preference text feature vector is denoised according to the first predicted noise to obtain a denoised user preference text feature vector.
[0282] It should be understood that in the embodiment of the present application, the input unit 1804 may include a graphics processor (Graphics Processing Unit, GPU) 18041 and a microphone 18042, and the graphics processor 18041 processes the image data of the static picture or video obtained by the image capture device (such as a camera) in the video capture mode or the image capture mode. The display unit 1806 may include a display panel 18061, and the display panel 18061 may be configured in the form of a liquid crystal display, an organic light emitting diode, etc. The user input unit 1807 includes a touch panel 18071 and at least one of other input devices 18072. The touch panel 18071 is also called a touch screen. The touch panel 18071 may include two parts: a touch detection device and a touch controller. Other input devices 18072 may include, but are not limited to, a physical keyboard, function keys (such as volume control keys, switch keys, etc.), a trackball, a mouse, and a joystick, which will not be repeated here.
[0283] The memory 1809 can be used to store software programs and various data. The memory 1809 may mainly include a first storage area for storing programs or instructions and a second storage area for storing data, wherein the first storage area may store an operating system, an application program or instructions required for at least one function (such as a sound playback function, an image playback function, etc.), etc. In addition, the memory 1809 may include a volatile memory or a non-volatile memory, or the memory 1809 may include both volatile and non-volatile memories. Among them, the non-volatile memory may be a read-only memory (ROM), a programmable read-only memory (PROM), an erasable programmable read-only memory (EPROM), an electrically erasable programmable read-only memory (EEPROM), or a flash memory. The volatile memory may be a random access memory (RAM), a static random access memory (SRAM), a dynamic random access memory (DRAM), a synchronous dynamic random access memory (SDRAM), a double data rate synchronous dynamic random access memory (DDRSDRAM), an enhanced synchronous dynamic random access memory (ESDRAM), a synchronous link dynamic random access memory (SLDRAM) and a direct memory bus random access memory (DRRAM). The memory 1809 in the embodiment of the present application includes but is not limited to these and any other suitable types of memory.
[0284] The processor 1810 may include one or more processing units; optionally, the processor 1810 integrates an application processor and a modem processor, wherein the application processor mainly processes operations related to an operating system, a user interface, and application programs, and the modem processor mainly processes wireless communication signals, such as a baseband processor. It is understandable that the modem processor may not be integrated into the processor 1810.
[0285] An embodiment of the present application also provides a readable storage medium, on which a program or instruction is stored. When the program or instruction is executed by a processor, each process of the above-mentioned model training method or image generation method embodiment is implemented, and the same technical effect can be achieved. To avoid repetition, it will not be repeated here.
[0286] The processor is the processor in the electronic device described in the above embodiment. The readable storage medium includes a computer readable storage medium, such as a computer read-only memory ROM, a random access memory RAM, a magnetic disk or an optical disk.
[0287] An embodiment of the present application further provides a chip, which includes a processor and a communication interface, wherein the communication interface is coupled to the processor, and the processor is used to run programs or instructions to implement the various processes of the above-mentioned model training method or image generation method embodiment, and can achieve the same technical effect. To avoid repetition, it will not be repeated here.
[0288] It should be understood that the chip mentioned in the embodiments of the present application can also be called a system-level chip, a system chip, a chip system or a system-on-chip chip, etc.
[0289] An embodiment of the present application provides a computer program product, which is stored in a storage medium. The program product is executed by at least one processor to implement the various processes of the above-mentioned model training method or image generation method embodiment, and can achieve the same technical effect. To avoid repetition, it will not be repeated here.
[0290] It should be noted that, in this article, the terms "comprise", "include" or any other variant thereof are intended to cover non-exclusive inclusion, so that the process, method, article or device including a series of elements includes not only those elements, but also includes other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, the elements defined by the sentence "comprise one..." do not exclude the presence of other identical elements in the process, method, article or device including the element. In addition, it should be pointed out that the scope of the methods and devices in the embodiments of the present application is not limited to performing functions in the order shown or discussed, and may also include performing functions in a substantially simultaneous manner or in reverse order according to the functions involved, for example, the described method may be performed in an order different from that described, and various steps may also be added, omitted, or combined. In addition, the features described with reference to certain examples may be combined in other examples.
[0291] Through the description of the above implementation methods, those skilled in the art can clearly understand that the above-mentioned embodiment methods can be implemented by means of software plus a necessary general hardware platform, and of course by hardware, but in many cases the former is a better implementation method. Based on such an understanding, the technical solution of the present application, or the part that contributes to the prior art, can be embodied in the form of a computer software product, which is stored in a storage medium (such as ROM / RAM, a disk, or an optical disk), and includes a number of instructions for a terminal (which can be a mobile phone, a computer, a server, or a network device, etc.) to execute the methods described in each embodiment of the present application.
[0292] The embodiments of the present application are described above in conjunction with the accompanying drawings, but the present application is not limited to the above-mentioned specific implementation methods. The above-mentioned specific implementation methods are merely illustrative and not restrictive. Under the guidance of the present application, ordinary technicians in this field can also make many forms without departing from the purpose of the present application and the scope of protection of the claims, all of which are within the protection of the present application.
Claims
1. A Wensheng graph model, characterized in that: include: A common text encoder network, used to convert image description information into a common text feature vector, wherein the image description information is used to describe the image content contained in the image generated by the text-generated graph model; A user preference text encoder network, configured to output a user preference text feature vector based on the common text feature vector, wherein the user preference text feature vector is used to indicate image content contained in the image generated by the text graph model and a painting style corresponding to the image content; the user preference text encoder network is connected to the common text encoder network; A diffusion model is used to perform noise prediction processing on the common text feature vector and the user preference text feature vector to obtain a first prediction noise, wherein the first prediction noise is used to perform denoising processing on the user preference text feature vector; the diffusion model is connected to the common text encoder network and the user preference text encoder network respectively; The image decoder is used to decode the user preference text feature vector after denoising and output an image.
2. The cultural graph model according to claim 1, characterized in that: The user preference text encoder network comprises: N self-attention modules, each of which is used to generate a text feature vector based on a common text feature vector and a corresponding painting style; wherein each self-attention module corresponds to a painting style, and N is an integer greater than 1; A gating network, used to output a gating weight corresponding to each of the self-attention modules, wherein the gating weight is used to indicate the probability that the user selects the painting style corresponding to the self-attention module; wherein the gating network is connected to each of the N self-attention modules respectively; The processing module is used to determine the text feature vector generated by the self-attention module with the largest gate weight as the user preferred text feature vector.
3. The cultural graph model according to claim 1, characterized in that: The diffusion model includes: A first diffusion model, the first diffusion model is connected to the common text encoder network and is used to perform noise prediction processing on the common text feature vector to obtain a second predicted noise, and the second predicted noise is used to perform denoising processing on the common text feature vector; The second diffusion model, the second diffusion module is used to perform noise prediction processing on the user preference text feature vector based on the common text feature vector after denoising to obtain a first predicted noise.
4. A model training method for training the Vincent graph model according to any one of claims 1 to 3, characterized in that: include: Acquire at least one training sample, each training sample including image description information, an image sample and a painting style sample, wherein the training sample is obtained based on user preference information; The initial model is trained by using the at least one training sample to obtain a text-based graph model; the text-based graph model is used to generate M images corresponding to the user preference information according to the image description information, where M is an integer greater than 1.
5. The method according to claim 4, characterized in that The obtaining of at least one training sample comprises: Get the image description information entered by the user; Input the image description information into the Wensheng graph model and output M images, each image corresponds to a painting style, and different images correspond to different painting styles; Using an image selected by a user from the M images as an image sample, and using a painting style corresponding to the image selected by the user as a painting style sample; The training sample is obtained according to the image description information, the image sample and the painting style sample.
6. The method according to claim 4, characterized in that The step of training the initial model by using the at least one training sample to obtain a Wensheng graph model includes: According to the image description information, the painting style sample and the first loss function in the training sample, updating at least one network parameter of the user preference text encoder network in the text graph model; According to the image description information in the training sample and the second loss function, updating at least one network parameter of the first diffusion model in the Wensheng graph model; updating at least one network parameter of a second diffusion model in the Vincent graph model according to the image description information in the training sample, the painting style sample, the image sample and the third loss function; According to the trained user preference text encoder network, the first diffusion model and the second diffusion model, a text graph model is obtained.
7. The method according to claim 6, characterized in that According to the image description information, the painting style sample and the first loss function in the training sample, updating at least one network parameter of the user preference text encoder network in the text graph model includes: Determine, according to the image description information and the painting style sample, a selection probability of each painting style selected by the user from N painting styles, wherein the selection probability of a first painting style is 1, and the selection probability of a second painting style is 0, the first painting style is a painting style corresponding to the painting style sample, and the second painting style is a painting style other than the first painting style among the N painting styles; At least one network parameter of the user preference text encoder network in the text graph model is updated according to the selection probability, the gating weights corresponding to the N self-attention modules in the user preference text encoder network, and the first loss function.
8. The method according to claim 6, characterized in that The updating of at least one network parameter of the first diffusion model in the Wensheng graph model according to the image description information in the training sample and the second loss function includes: Inputting the image description information into a common text encoder network and outputting a common text feature vector; Inputting the image corresponding to the image description information into the image encoder of the Wensheng graph model, and outputting a first image feature vector; Inputting the first image feature vector with the first random noise added thereto and the common text feature vector into the first diffusion model, and outputting a third predicted noise; At least one network parameter of a first diffusion model in the Vincent graph model is updated according to the third prediction noise, the first random noise and the second loss function.
9. The method according to claim 6, characterized in that The updating of at least one network parameter of the second diffusion model in the Vincent graph model according to the image description information in the training sample, the painting style sample, the image sample and the third loss function comprises: Inputting the image description information into a common text encoder network and outputting a common text feature vector; Inputting the common text feature vector and the painting style sample into a user preference text encoder network, and outputting a user preference text feature vector; Input the image sample into an image encoder in the Vincent graph model, and output a second image feature vector; Inputting the second image feature vector and the common text feature vector added with the second random noise into the first diffusion model, and outputting a fourth predicted noise; Based on the fourth predicted noise, denoising the second image feature vector with the second random noise added thereto to obtain a third image feature vector; Inputting the third image feature vector with third random noise added thereto and the user preference text feature vector into the second diffusion model, and outputting fifth predicted noise; At least one network parameter of a second diffusion model in the Vincent graph model is updated according to the second random noise, the fifth prediction noise and the third loss function.
10. An image generation method, characterized in that: include: Inputting image description information into a common text encoder network of the text-generated graph model according to any one of claims 1 to 3 to obtain a common text feature vector, wherein the image description information is used to indicate image content contained in an image generated by the text-generated graph model; Input the common text feature vector into the user preference text encoder network of the text-generated graph model, and output a user preference text feature vector; wherein the user preference text feature vector is used to indicate the image content contained in the image generated by the text-generated graph model and the painting style corresponding to the image content; De-noising the user preference text feature vector by using the diffusion model of the text graph model to obtain the user preference text feature vector after de-noising; The denoised user preference text feature vector is decoded by the image decoder of the text-generated graph model to obtain an image.
11. The method according to claim 10, characterized in that The user preference text feature vector is subjected to denoising by using the diffusion model of the text graph model to obtain the user preference text feature vector after denoising, including: Input the common text feature vector into the first diffusion model and output the second prediction noise; According to the second predicted noise, the common text feature vector is subjected to denoising processing to obtain a first text feature vector; Inputting the first text feature vector and the user preference text feature vector added with the fourth random noise into the second diffusion model, and outputting the first prediction noise; The user preference text feature vector is denoised according to the first predicted noise to obtain a denoised user preference text feature vector.
12. A model training device for training the Vincent graph model according to any one of claims 1 to 3, characterized in that: include: A first acquisition module is used to acquire at least one training sample, each training sample includes image description information, an image sample and a painting style sample, and the training sample is obtained based on user preference information; A training module is used to perform model training on the initial model through the at least one training sample to obtain a Wensheng graph model; the Wensheng graph model is used to generate M images corresponding to the user preference information according to the image description information, where M is an integer greater than 1.
13. The device according to claim 12, characterized in that The first acquisition module is specifically used for: Get the image description information entered by the user; Input the image description information into the Wensheng graph model and output M images, each image corresponds to a painting style, and different images correspond to different painting styles; Using an image selected by a user from the M images as an image sample, and using a painting style corresponding to the image selected by the user as a painting style sample; The training sample is obtained according to the image description information, the image sample and the painting style sample.
14. The device according to claim 12, characterized in that The training module is specifically used for: According to the image description information, the painting style sample and the first loss function in the training sample, updating at least one network parameter of the user preference text encoder network in the text graph model; According to the image description information in the training sample and the second loss function, updating at least one network parameter of the first diffusion model in the Wensheng graph model; updating at least one network parameter of a second diffusion model in the Vincent graph model according to the image description information in the training sample, the painting style sample, the image sample and the third loss function; According to the trained user preference text encoder network, the first diffusion model and the second diffusion model, a text graph model is obtained.
15. The device according to claim 14, characterized in that The training module is specifically used for: Determine, according to the image description information and the painting style sample, a selection probability of each painting style selected by the user from N painting styles, wherein the selection probability of a first painting style is 1, and the selection probability of a second painting style is 0, the first painting style is a painting style corresponding to the painting style sample, and the second painting style is a painting style other than the first painting style among the N painting styles; At least one network parameter of the user preference text encoder network in the text graph model is updated according to the selection probability, the gating weights corresponding to the N self-attention modules in the user preference text encoder network, and the first loss function.
16. The device according to claim 14, characterized in that The training module is specifically used for: Inputting the image description information into a common text encoder network and outputting a common text feature vector; Inputting the image corresponding to the image description information into the image encoder of the Wensheng graph model, and outputting a first image feature vector; Inputting the first image feature vector with the first random noise added thereto and the common text feature vector into the first diffusion model, and outputting a third predicted noise; At least one network parameter of a first diffusion model in the Vincent graph model is updated according to the third prediction noise, the first random noise and the second loss function.
17. The device according to claim 14, characterized in that The training module is specifically used for: Inputting the image description information into a common text encoder network and outputting a common text feature vector; Inputting the common text feature vector and the painting style sample into a user preference text encoder network, and outputting a user preference text feature vector; Input the image sample into an image encoder in the Vincent graph model, and output a second image feature vector; Inputting the second image feature vector and the common text feature vector added with the second random noise into the first diffusion model, and outputting a fourth predicted noise; Based on the fourth predicted noise, denoising the second image feature vector with the second random noise added thereto to obtain a third image feature vector; Inputting the third image feature vector with third random noise added thereto and the user preference text feature vector into the second diffusion model, and outputting fifth predicted noise; At least one network parameter of a second diffusion model in the Vincent graph model is updated according to the second random noise, the fifth prediction noise and the third loss function.
18. An image generating device, characterized in that: include: A second acquisition module, configured to input image description information into a common text encoder network of the text-generated graph model according to any one of claims 1 to 3 to obtain a common text feature vector, wherein the image description information is used to indicate image content contained in an image generated by the text-generated graph model; A third acquisition module is used to input the common text feature vector into the user preference text encoder network of the Wensheng graph model, and output a user preference text feature vector; wherein the user preference text feature vector is used to indicate the image content contained in the image generated by the Wensheng graph model and the painting style corresponding to the image content; A fourth acquisition module is used to perform denoising on the user preference text feature vector through a diffusion model of the text graph model to obtain a denoised user preference text feature vector; The fifth acquisition module is used to decode the user preference text feature vector after denoising through the image decoder of the text graph model to obtain an image.
19. The device according to claim 18, characterized in that The fourth acquisition module is specifically used for: Input the common text feature vector into the first diffusion model and output the second prediction noise; According to the second predicted noise, the common text feature vector is subjected to denoising processing to obtain a first text feature vector; Inputting the first text feature vector with the fourth random noise added and the user preference text feature vector into the second diffusion model, and outputting the first prediction noise; The user preference text feature vector is denoised according to the first predicted noise to obtain a denoised user preference text feature vector.
20. An electronic device, characterized in that: It includes a processor and a memory, wherein the memory stores programs or instructions that can be run on the processor, and when the programs or instructions are executed by the processor, the steps of the model training method as described in any one of claims 1 to 9 are implemented.
21. An electronic device, characterized in that: The method comprises a processor and a memory, wherein the memory stores a program or instruction that can be run on the processor, and when the program or instruction is executed by the processor, the steps of the image generating method according to any one of claims 10 to 11 are implemented.
Citation Information
Cited By
Interactive icon automatic generation system based on artificial intelligence
CN120672895A
Text-to-image model, model training method and apparatus, image generation method and apparatus, and electronic device
WO2025261282A1
