Image generation model training method and device, image generation method and device, equipment and medium
By using the predicted weight values obtained by the target reward model and the difference between the generated image and the sample image, the parameters of the image generation model are adjusted, and the problem of poor training effect of the image generation model in the prior art is solved, and better image generation ability and stability are achieved.
Patent Information
- Application Number
- CN202311093180.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2023-08-28
- Publication Date
- 2025-02-28
AI Technical Summary
The prior art is difficult to train an image generation model with better image generation capabilities, resulting in unstable image quality.
By acquiring the image description and its corresponding sample images, the predicted weight value is obtained using the target reward model, and the parameters of the image generation model are adjusted based on the difference between the generated image and the predicted weight value, so as to focus on training with high-quality graphics and text pairs.
The image generation ability and stability of the image generation model are improved, ensuring that the generated image quality is more in line with human intentions.
Smart Images

Figure CN119540672A_ABST
Abstract
Description
Technical Field
[0001] The present disclosure relates to the field of computer technology, and in particular to training of an image generation model, an image generation method, a device, a equipment and a medium. Background Art
[0002] In the field of image generation, image description (also called text prompt) can be used to guide image generation. Specifically, the image description can be used to obtain an image corresponding to the image description through an image generation model based on content generation technology.
[0003] In the above process, in order to ensure the quality of the generated images, it is necessary to train an image generation model with better image generation capabilities. Therefore, how to provide an image generation model that is trained to have better image generation capabilities becomes an urgent problem to be solved. Summary of the invention
[0004] One or more embodiments of the present disclosure provide an image generation model training, image generation method, apparatus, device and medium to achieve training to obtain an image generation model with better image generation capability.
[0005] According to a first aspect, a method for training an image generation model is provided, comprising:
[0006] Obtaining a first image description and a first sample image corresponding thereto;
[0007] Using the first image description and the first sample image, a prediction weight value is obtained through a target reward model, wherein the prediction weight value is positively correlated with an image quality of the first sample image and / or is positively correlated with a matching degree between the first image description and the first sample image;
[0008] Using the first image description and a first image generation model, a first generated image is obtained;
[0009] Based on the difference between the first generated image and the first sample image and the prediction weight value, the parameters of the first image generation model are adjusted.
[0010] In an optional embodiment, the adjusting the parameters of the first image generation model includes: using a preset loss function to determine an intermediate prediction loss based on the difference between the first generated image and the first sample image; determining a first prediction loss based on the product of the intermediate prediction loss and the prediction weight value; and adjusting the parameters of the first image generation model with the goal of minimizing the first prediction loss. In this embodiment, the first prediction loss is determined based on the product of the intermediate prediction loss and the prediction weight value, so that in the process of training the first image generation model, more emphasis is placed on using image-text pairs with higher corresponding prediction weight values to determine the first prediction loss (increasing the proportion of image-text pairs with higher corresponding prediction weight values, that is, image-text pairs with good quality, in determining the first prediction loss), that is, more emphasis is placed on using image-text pairs with good quality to train the first image generation model, so as to better improve the image generation capability of the first image generation model and ensure the stability of its image generation capability.
[0011] In an optional embodiment, it also includes: obtaining a second image description and its corresponding second sample image; inputting the second image description into the first image generation model to obtain a second generated image; using the difference between the second sample image and the second generated image to determine a second prediction loss; adjusting the parameters of the first image generation model with the goal of minimizing the first prediction loss includes: adjusting the parameters of the first image generation model with the goal of minimizing the first prediction loss and the second prediction loss. In this embodiment, in the process of training the first image generation model, real images and their corresponding image descriptions are also added to train the first image generation model, which increases the diversity of data for training the first image generation model and better improves the image generation capability of the first image generation model.
[0012] In an optional embodiment, it also includes: obtaining the third image description and the third sample image corresponding thereto; obtaining the label weight value corresponding to the third image description and the third sample image, wherein the label weight value is positively correlated with the image quality of the third sample image, and / or is positively correlated with the matching degree between the third image description and the third sample image; obtaining an evaluation weight value through the reward model to be trained using the third image description and the third sample image; determining a third prediction loss using the evaluation weight value and the label weight value; adjusting the reward model to be trained with the goal of minimizing the third prediction loss to obtain a target reward model that meets the first preset convergence condition. In this embodiment, the reward model to be trained is trained using the third image description and the third sample image, as well as the label weight values corresponding thereto, to obtain a target reward model that meets the first convergence condition, which can achieve supervised training of the determination result of the reward model to be trained, maintain its accuracy, and improve the accuracy of the determination result of the reward model to be trained.
[0013] In an optional embodiment, the label weight value is determined based on at least one of the following information: the clarity score of the third sample image, the aesthetic score of the third sample image, and the matching value between the third sample image and the third image description. In this embodiment, the label weight value is determined by a number of information that can characterize the quality of the image and / or the quality of the image and its image description, i.e., the matching degree. To a certain extent, the label weight value can better characterize the human quality evaluation of the corresponding image and its image description, thereby improving the accuracy of the predicted weight value output by the target reward model, so that the predicted weight value is more adapted to human feedback.
[0014] In an optional embodiment, the first sample image is an image generated according to the first image description using a pre-trained second image generation model; the parameters of the second image generation model serve as the initial parameters of the first image generation model. In this embodiment, the quality of the image-text pair formed by the image generated according to the first image description and the corresponding first image description using the pre-trained second image generation model is relatively better, and using such image-text pairs to train the first image generation model helps to train a first image generation model that can generate images of better quality. And the initial parameters of the first image generation model are the parameters of the second image generation model, that is, the first image generation model is a pre-trained model, which can accelerate the convergence speed of the first image generation model in the present disclosure to a certain extent, and is more helpful to improve the image generation capability of the first image generation model.
[0015] According to a second aspect, there is provided an image generation method, comprising:
[0016] Get the description of the image to be processed;
[0017] The target image is obtained by using the image description to be processed and the image generation model obtained by training using the image generation model training method described in the first aspect.
[0018] According to a third aspect, a training device for an image generation model is provided, comprising:
[0019] A first acquisition module, configured to acquire a first image description and a first sample image corresponding thereto;
[0020] a first obtaining module configured to obtain a prediction weight value by using the first image description and the first sample image through a target reward model, wherein the prediction weight value is positively correlated with an image quality of the first sample image and / or is positively correlated with a matching degree between the first image description and the first sample image;
[0021] A second obtaining module is configured to obtain a first generated image by using the first image description through a first image generation model;
[0022] The first adjustment module is configured to adjust the parameters of the first image generation model based on the difference between the first generated image and the first sample image and the prediction weight value.
[0023] According to a fourth aspect, there is provided an image generating device, comprising:
[0024] A second acquisition module is configured to acquire a description of the image to be processed;
[0025] The third obtaining module is configured to obtain a target image by using the image description to be processed and the image generation model obtained by training using the image generation model training device described in the third aspect.
[0026] According to a fifth aspect, a computer-readable storage medium is provided, on which a computer program is stored. When the computer program is executed in a computer, the computer is caused to execute the method described in the first aspect or the second aspect.
[0027] According to a sixth aspect, an electronic device is provided, comprising a memory and a processor, wherein the memory stores executable code, and when the processor executes the executable code, the method described in the first aspect or the second aspect is implemented.
[0028] According to the training of the image generation model, the image generation method, the apparatus, the device and the medium provided by the embodiments of the present disclosure, after obtaining the first image description and the first sample image corresponding to it, the first image description and the first sample image are used to obtain a predicted weight value through a target reward model, wherein the predicted weight value is positively correlated with the image quality of the first sample image, and / or is positively correlated with the degree of match between the first image description and the first sample image, and the corresponding predicted weight value can characterize the quality of the first image description and the first sample image corresponding to it; the first image description is used to obtain a first generated image through a first image generation model, and based on the difference between the first generated image and the first sample image and the predicted weight value, the parameters of the first image generation model are adjusted to achieve the predicted weight value based on environmental feedback data, that is, the quality of the image-text pair, to adjust and train the first image generation model, which helps to train an image generation model with better image generation capability, so that the trained first image generation model can generate images with better quality. BRIEF DESCRIPTION OF THE DRAWINGS
[0029] In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the following briefly introduces the drawings required for describing the embodiments. Obviously, the drawings described below are only some embodiments of the present invention, and for ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work.
[0030] Figure 1 A schematic diagram of an implementation framework of an embodiment disclosed in the present disclosure;
[0031] Figure 2 A schematic diagram of a flow chart of a training method for an image generation model provided in an embodiment;
[0032] Figure 3 A schematic diagram of a flow chart of a training method for an image generation model provided in an embodiment;
[0033] Figure 4 A schematic diagram of a flow chart of an image generation method provided in an embodiment;
[0034] Figure 5 A schematic block diagram of a training device for an image generation model provided in an embodiment;
[0035] Figure 6 A schematic block diagram of an image generating device provided in an embodiment;
[0036] Figure 7 A schematic block diagram of an electronic device provided in an embodiment. DETAILED DESCRIPTION
[0037] The technical solution of the embodiments of the present disclosure will be described in detail below with reference to the accompanying drawings.
[0038] It is understandable that before using the technical solutions disclosed in the embodiments of the present disclosure, the types, scope of use, usage scenarios, etc. of the personal information involved in the present disclosure should be informed to the user and the user's authorization should be obtained in an appropriate manner in accordance with relevant laws and regulations.
[0039] For example, in response to receiving an active request from a user, a prompt message is sent to the user to clearly prompt the user that the operation requested to be performed will require obtaining and using the user's personal information. Thus, the user can autonomously choose whether to provide personal information to software or hardware such as an electronic device, application, server, or storage medium that performs the operation of the technical solution of the present disclosure according to the prompt message.
[0040] As an optional but non-limiting implementation, in response to receiving an active request from the user, the prompt information may be sent to the user in the form of a pop-up window, in which the prompt information may be presented in text form. In addition, the pop-up window may also carry a selection control for the user to choose "agree" or "disagree" to provide personal information to the electronic device.
[0041] It is understandable that the above notification and the process of obtaining user authorization are merely illustrative and do not constitute a limitation on the implementation of the present disclosure. Other methods that meet the relevant laws and regulations may also be applied to the implementation of the present disclosure.
[0042] The embodiments of the present disclosure disclose an image generation model training, image generation method, device, equipment and medium. The application scenarios and technical concepts of the method are first introduced as follows:
[0043] As mentioned above, in the field of image generation, in order to ensure the quality of the generated images, it is necessary to train an image generation model with better image generation capabilities. At present, the process of training an image generation model is generally as follows: obtaining a number of sample image-text pairs, each sample image-text pair includes a sample image and its corresponding image description, and then based on the first image description in any first sample image-text pair among the sample image-text pairs, obtaining a generated image corresponding to the first image description through an image generation model, and then using the difference between the generated image corresponding to the first image description and the sample image in the first sample image-text pair to which the first image description belongs to construct a prediction loss, and then adjusting the parameters of the image generation model with the goal of minimizing the prediction loss.
[0044] In the process of training the image generation model, the quality of each image-text pair in the sample image-text pairs (for example, the clarity of the image, the aesthetics of the image and / or the degree of match between the image and the image description in each image-text pair) is not taken into consideration, resulting in the image generation model obtained by training having an image generation capability that is not good enough and not stable enough.
[0045] In view of this, the embodiments of the present disclosure provide an image generation model training, image generation method, device, equipment and medium to achieve training to obtain an image generation model with better image generation capabilities, better improve the stability of the image generation capabilities of the image generation model, and thereby obtain images of better quality. Figure 1 A schematic diagram of an implementation scenario according to an embodiment disclosed in the present disclosure is shown. In the implementation scenario, an exemplary structure of a training system for fine-tuning an image generation model and an exemplary data processing flow of the training system are shown. The training system may include a first image generation model to be trained (i.e., to be fine-tuned), and a target reward model for determining feedback data (i.e., current environmental feedback, i.e., reward score) for fine-tuning the first image generation model.
[0046] In one implementation, the first image generation model may be a model pre-trained based on a picture and text dataset (hereinafter referred to as the first picture and text dataset for clarity of description), and has the ability to generate a corresponding image based on an input image description. The first picture and text dataset includes a plurality of picture and text pairs, wherein any picture and text pair (referred to as the first picture and text pair) includes an image and its corresponding image description. The image description may also be referred to as a text prompt, i.e., a text prompt used to generate an image.
[0047] The target reward model is pre-trained based on any image-text pair in the image-text data set (hereinafter referred to as the second image-text data set for clarity) and the label weight value corresponding to the image-text pair. The target reward model is used to output the predicted weight value corresponding to the image-text pair based on the input image-text pair. The label weight value can characterize the quality of the corresponding image-text pair. The quality of the image-text pair can be characterized from the following angles but not limited to the following angles: the image quality of the image in the image-text pair and / or the matching degree between the image and the image description in the image-text pair. Among them, the image quality can be determined from the clarity of the image and / or the aesthetics of the image.
[0048] Among them, the higher the clarity of the image in the picture-text pair (i.e., the higher the clarity score), the better the beauty of the image (i.e., the higher the aesthetic score), the better the image quality of the image. The better the image quality of the image in the picture-text pair, and the stronger the match between the image and the image description in the picture-text pair (i.e., the higher the match value), the better the quality of the picture-text pair. It can be understood that the better the quality of the picture-text pair used to train the first image generation model, the better the image generation ability of the first image generation model can be improved. In one implementation, the larger the label weight value, the better the quality of the corresponding picture-text pair.
[0049] In one implementation, the second image-text data set and the subsequent training data set may include the same image-text pairs, or may include different image-text pairs.
[0050] The model training process is introduced below. In the model training process, a training data set for training the first image generation model is obtained. The training data set includes a number of sample image-text pairs. Any sample image-text pair includes an image description and its corresponding sample image. It can be understood that in the training process, the processing process of any pair of sample images and texts is similar. The model training process is described below by taking the processing process of any pair of first sample image-text pairs (including the first image description and its corresponding first sample image) as an example.
[0051] From a training data set, a first image description and its corresponding first sample image are obtained, that is, a first sample image-text pair is obtained; the first image description and the first sample image are processed by a target reward model, that is, the target reward model is used to obtain a prediction weight value that can characterize the quality of the image-text pair of the first image description and the first sample image, wherein the prediction weight value is positively correlated with the quality of the image-text pair of the first image description and the first sample image, and the quality of the image-text pair of the first image description and the first sample image can be determined by the image quality of the first sample image, and / or the matching degree between the first image description and the first sample image.
[0052] Next, the first image description is used to obtain a first generated image through a first image generation model, that is, the first image description is input into the first image generation model, and the first image generation model processes the first image description to obtain a first generated image; then, based on the difference between the first generated image and the first sample image and the prediction weight value, the parameters of the first image generation model are adjusted. In one implementation, if Figure 1As shown, the difference between the first generated image and the first sample image can be determined based on the first generated image and the first sample image (for example, the Euclidean distance between the first generated image and the first sample image is used to characterize the difference between the first generated image and the first sample image). In another implementation, the probability of the first image generation model obtaining the first sample image for the first image description based on the first image description in the process of generating the first generated image by the first image generation model (i.e., the subsequent p(x1|z1)) can be obtained, and the probability can characterize the difference between the first generated image and the first sample image, wherein the greater the probability of the first image generation model obtaining the first sample image for the first image description, the smaller the difference between the first generated image and the first sample image.
[0053] In the above process, quality assessment is performed on the first image description and the first sample image based on the target reward model to obtain corresponding prediction weight values, wherein the prediction weight values can characterize the quality of the image-text pair of the first image description and the first sample image. The parameters of the first image generation model are adjusted in combination with the prediction weight values as well as the first image description and the first sample image. This can be achieved by training the first image generation model based on offline reinforcement learning in combination with the prediction weight values output by the environmental feedback data, i.e., the target reward model, so as to improve the image generation capability of the first image generation model.
[0054] Furthermore, in combination with the environmental feedback data, i.e. the predicted weight value, during the model training process, it is possible to focus more on using the training data, i.e., the image-text pairs, which have better quality representations of the corresponding predicted weight values, to train the first image generation model, so that the trained image generation model has better image generation capabilities and better stability of the image generation capabilities. And to a certain extent, it is ensured that the quality of the images generated by the trained first image generation model is more in line with environmental expectations (i.e., human intentions).
[0055] In the following, in conjunction with specific embodiments, the training method, apparatus, device and medium of the image generation model, and the image generation method, apparatus, device and medium provided by the present disclosure are described in detail.
[0056] Figure 2 The flowchart of the training method of the image generation model in one embodiment of the present disclosure is shown. The method can be implemented by a target program. The target program can be installed in an electronic device, and the electronic device can be implemented by any device, equipment, platform, device cluster, etc. with computing and processing capabilities. Figure 2 As shown, the method includes the following steps S210-S240:
[0057] In step S210, a first image description and its corresponding first sample image are obtained.
[0058] In one implementation, the preset data storage space corresponding to the target program may pre-store a training data set for training the first image generation model, and the training data set may include a plurality of image-text pairs, referred to as first image-text pairs, and any first image-text pair includes an image description and its corresponding sample image. In this step, the target program may obtain any first image description and its corresponding first sample image from the training data set stored in the preset data storage space, that is, obtain any pair of first image-text pairs in the training data set.
[0059] It can be understood that in the embodiments of the present disclosure, a pair of first image-text pairs in the training data set (for example, a first image description and its corresponding first sample image) is taken as an example to illustrate the processing process of each pair of first image-text pairs in the training data set, that is, the training process of the first image generation model. Using each pair of first image-text pairs in the training data set, the first image generation model can be trained based on a similar process.
[0060] In one implementation, the first sample image may be an image generated by a pre-trained second image generation model according to the first image description. The quality of the image-text pair formed by the sample image and the image description is relatively good. Using the image-text pair with relatively good quality to train the first image generation model can facilitate the training of a first image generation model with relatively good image generation capability. In one implementation, the target program can also construct the aforementioned training data set, wherein the construction process includes: obtaining a number of image descriptions A (for example, obtaining image descriptions from a public data set that can provide a large number of image-text pairs), and then inputting the image descriptions A into the second image generation model respectively to obtain images corresponding to the image descriptions A, i.e., sample images. For each image description A, the image description A and its corresponding sample image are determined as a pair of first image-text pairs to construct the training data set.
[0061] In one implementation, the parameters of the second image generation model serve as the initial parameters of the first image generation model that needs to be trained, that is, the initial values of the parameters of the first image generation model are the same as the values of the parameters of the second image generation model.
[0062] For a clear layout, the following first introduces the pre-training process of the second image generation model (or the process of training the first image generation model).
[0063] The process includes: first obtaining an image generation model that needs to be pre-trained (which may be referred to as an image generation model to be trained), and obtaining a text-image dataset S (such as the aforementioned first text-image dataset) for pre-training the image generation model to be trained, wherein the text-image dataset S may include multiple text-image pairs, and a text-image pair includes an image description X and its corresponding image T. In one case, the text-image dataset S may be obtained from a public dataset that can provide a large number of text-image pairs or a specified artificially created dataset. The artificially created dataset includes a number of collected images and the image descriptions corresponding to each image that are artificially added to the image.
[0064] In one case, the image description may also be referred to as a text prompt, that is, a text prompt used to generate an image.
[0065] Then, according to the image description X in any image-text pair M in the image-text dataset S, the corresponding generated image T' is obtained through the image generation model to be trained, that is, the image description X is input into the image generation model to be trained, and the image description X is processed by the image generation model to be trained to generate the corresponding generated image T'; the difference between the image T in the aforementioned image-text pair M and the generated image T' is used to determine the loss corresponding to the image generation model to be trained, which is called the first generation loss. In one case, a preset loss function (such as a cross entropy loss function, an MSE (Mean Square Error) loss function, etc.) can be used to determine the first generation loss based on the difference between the image T and the generated image T', wherein the greater the difference between the image T and the generated image T', the greater the first generation loss.
[0066] Afterwards, the parameters of the image generation model are adjusted to minimize the first generation loss, i.e., to reduce the difference between the image in the image-text pair and the corresponding generated image, until the image generation model reaches a specified convergence condition, and a pre-trained image generation model is obtained, i.e., a second image generation model is obtained, i.e., an initial first image generation model in the training system is obtained. The specified convergence condition may include, but is not limited to, the number of parameter adjustments is not less than a first adjustment threshold, the training time exceeds a preset time, or the calculated first generation loss is less than a first loss threshold.
[0067] Let's review the above process. The above embodiment is explained by taking a pair of image-text pairs (i.e., a pair of image description X and its corresponding image T) as a sample. In another embodiment, the above process can also be performed on a batch of samples, i.e., multiple pairs of image-text pairs, to obtain the generated images corresponding to the image descriptions in each pair of image-text pairs, and then determine the first generation loss based on the generated images corresponding to the image descriptions in each pair of image-text pairs and the images in the pair of image-text pairs, and adjust the parameters of the image generation model with the goal of minimizing the first generation loss. In this embodiment, the first generation loss is determined for a batch of samples, and then the parameters of the image generation model are adjusted. This can reduce the number of parameter adjustments to the image generation model and make it easier to implement the above process.
[0068] In one implementation, the first image generation model and the second image generation model may be image generation models based on a Diffusion Model (diffusion model).
[0069] In one implementation, the aforementioned training data set may also be used as training data for the target reward model, that is, the training data set and the aforementioned second image-text data set may include the same image-text pairs, or may include different image-text pairs.
[0070] After the target program obtains the first image description and the first sample image corresponding thereto, in step S220, the first image description and the first sample image are used to obtain a predicted weight value through a target reward model, wherein the predicted weight value is positively correlated with the image quality of the first sample image and / or is positively correlated with the degree of match between the first image description and the first sample image. In one implementation, the target reward model may be pre-stored in a preset data storage space corresponding to the target program, and accordingly, the target program may obtain the target reward model from the preset data storage space.
[0071] In one embodiment, the target reward model may be a model pre-trained based on any image-text pair in an image-text dataset (i.e., the aforementioned second image-text dataset) and the label weight value corresponding to the image-text pair. Wherein, any image-text pair in the second image-text dataset includes an image description and its corresponding image. For the sake of clarity, any image-text pair in the second image-text dataset is referred to as a second image-text pair, any image description in the second image-text pair is referred to as a third image description, and any image in the second image-text pair in the second image-text dataset is referred to as a third sample image.
[0072] In one implementation, the third sample image may be an image generated by the aforementioned pre-trained second image generation model according to the corresponding third image description.
[0073] The label weight value y can be the weight value annotated by the annotator or a specific program for each second image-text pair in the second image-text data set. The label weight value y can characterize the quality of the corresponding second image-text pair, wherein the better the quality of the second image-text pair, the larger the corresponding label weight value y. In one case, the value range of the label weight value y can be [0, 1] (i.e., the value range is 0 to 1). Correspondingly, the value range of the prediction weight value can be [0, 1] (i.e., the value range is 0 to 1).
[0074] The quality of each second image-text pair can be determined by the image quality of the third image description contained therein, and / or the degree of match between the third image description contained therein and the third sample image. The better the image quality of the third image description contained in the second image-text pair, the higher the degree of match between the third image description contained in the second image-text pair and the third sample image, which can indicate that the quality of the second image-text pair is better. Accordingly, the label weight value corresponding to the second image-text pair is positively correlated with the image quality of the third sample image contained in the second image-text pair, and / or is positively correlated with the degree of match between the third image description contained in the second image-text pair and the third sample image.
[0075] In one implementation, the image quality may be determined by the clarity of the image and / or the aesthetics of the image, wherein the higher the clarity of the image and the better the aesthetics of the image, the better the image quality of the image.
[0076] Accordingly, the label weight value y can be determined based on at least one of the following information: the clarity score of the third sample image (which can characterize the clarity of the third sample image, wherein the larger the clarity score, the higher the clarity), the aesthetic score of the third sample image (which can characterize the aesthetics of the image, wherein the larger the aesthetic score, the better the aesthetics of the image), and the matching value between the third sample image and its corresponding third image description (which can characterize the matching degree, i.e., the correlation degree, between the third sample image and its corresponding third image description, wherein the larger the matching value, the stronger the matching degree). It can be understood that the above information is only an exemplary example of reference information for determining the label weight value corresponding to the second image-text pair, and the disclosed embodiment can also use other information that can characterize the image quality of the image to determine the label weight value corresponding to the image-text pair.
[0077] By using the above information to determine the label weight value, to a certain extent, the label weight value can better represent the human quality evaluation of the corresponding image and its image description, thereby improving the accuracy of the predicted weight value output by the target reward model and making the predicted weight value more adapted to human intentions.
[0078] In another implementation, the disclosed embodiment may also provide a training process of a target reward model. For a clear layout, the training process of the target reward model is introduced below, wherein the training process of the target reward model includes the following steps 11-15: In step 11, a third image description and its corresponding third image description are obtained. In this step, the target program may obtain the third image description and its corresponding third sample image from the aforementioned second image and text data set (or the aforementioned training data set); or, the target program may obtain the image description from the aforementioned public data set or artificially created data set as the third image description, and then obtain the third sample image corresponding to the third image description through the aforementioned pre-trained second image generation model according to the third image description.
[0079] Then, in step 12, the label weight value corresponding to the third image description and the third sample image is obtained. As mentioned above, the label weight value may be a weight value annotated by an annotator or a specific program for the third image description and its corresponding third sample image, which may characterize the quality of the image-text pair composed of the corresponding third image description and its corresponding third sample image. Specifically, the label weight value is positively correlated with the image quality of the third sample image, and / or is positively correlated with the matching degree between the third image description and the third sample image.
[0080] Then in step 13, the third image description and the third sample image are used to obtain an evaluation weight value through the reward model to be trained. In this step, the target program inputs the third image description and the third sample image into the reward model to be trained, and encodes the third image description and the third sample image respectively using the reward model to be trained to obtain the text representation corresponding to the third image description and the image representation corresponding to the third sample image. After that, the reward model to be trained is used to determine the evaluation weight value corresponding to the third image description and the third sample image based on the text representation corresponding to the third image description and the image representation corresponding to the third sample image. Among them, the evaluation weight value can represent the quality evaluated by the reward model to be trained for the third image description and the third sample image.
[0081] In one implementation, the reward model to be trained may include an image encoder, a text encoder, and an MLP (Multilayer Perceptron) layer. Accordingly, the target program may input the third sample image into the image encoder to obtain an image representation corresponding to the third sample image, input the third image description into the text encoder to obtain a text representation corresponding to the third image description, and then input the image representation corresponding to the third sample image and the text representation corresponding to the third image description into the MLP layer to obtain an evaluation weight value corresponding to the third image description and the third sample image.
[0082] In one case, the target program may also input the third sample image and its corresponding third image description into a pre-trained CLIP (Contrastive Language-Image Pre-Training) model to obtain an image representation corresponding to the third sample image and a text representation corresponding to the third image description, and then input the image representation corresponding to the third sample image and the text representation corresponding to the third image description into the aforementioned MLP layer to obtain an evaluation weight value corresponding to the third image description and the third sample image.
[0083] After obtaining the evaluation weight value, in step 14, the third prediction loss is determined using the evaluation weight value and the label weight value. In this step, the third prediction loss can be determined using the evaluation weight value and the label weight value according to the specified loss function. The greater the difference between the evaluation weight value and the label weight value, the greater the third prediction loss. In one implementation, the specified loss function can be an MSE (mean square error) loss function, wherein the third prediction loss It can be expressed by the following formula (1): in, represents the parameters to be adjusted of the reward model to be trained, a represents the third sample image, b represents the third image description, y represents the label weight value corresponding to the third sample image and the third image description, It represents the evaluation weight value determined by the reward model to be trained for the input third sample image and the third image description, and E can represent the calculated expected value.
[0084] Then in step 15, with the goal of minimizing the third prediction loss, the reward model to be trained is adjusted to obtain a target reward model that meets the first convergence condition. In this step, the target program determines the model parameter gradient of the reward model to be trained based on the third prediction loss using the back propagation algorithm; determines the updated model parameters of the reward model to be trained (i.e., the updated values of the model parameters of the reward model to be trained) using the determined model parameter gradient and the current model parameters of the reward model to be trained (i.e., the current values of the model parameters of the reward model to be trained); and then adjusts the model parameters of the reward model to be trained based on the updated model parameters. Among them, the determination of the model parameter gradient of the reward model to be trained is obtained with the goal of minimizing the third prediction loss. Minimizing the third prediction loss can achieve supervised training of the determination results of the reward model to be trained, maintain its accuracy, and improve the accuracy of the determination results of the reward model to be trained.
[0085] The above steps 11 to 15 are a model iterative training process for the reward model to be trained. In order to train a better reward model to be trained, the above process can be iterated multiple times. That is, after step 15, based on the updated model parameters of the reward model to be trained, return to step 11.
[0086] The stopping condition of the above-mentioned model iterative training process, i.e., the first convergence condition, may include: the number of iterative training times reaches a preset threshold, or the iterative training duration reaches a preset duration, or the third prediction loss is less than a set loss threshold, etc.
[0087] After the target program obtains the target reward model, the first image description and the first sample image are used to obtain the predicted weight value through the target reward model, that is, the first sample image and the first image description are input into the target reward model, and the first sample image and the first image description are processed by the target reward model to obtain the predicted weight value corresponding to the first sample image and the first image description. Among them, the predicted weight value can characterize the quality of the image-text pair of the first sample image and the first image description, that is, the predicted weight value is positively correlated with the image quality of the first sample image, and / or, is positively correlated with the matching degree between the first image description and the first sample image.
[0088] Then in step S230, the first image description is used to generate a first generated image through the first image generation model.
[0089] It can be understood that, when the current training process is the first training process based on the training system (i.e., the first training of the first image generation model based on the training system), the first image generation model is the image generation model obtained by the aforementioned pre-training, and its parameters are the same as the parameters of the aforementioned second image generation model. When the current training process is a non-first training process based on the training system for the image generation model (e.g., the Nth training of the first image generation model based on the training system, where N is greater than 1), the parameters of the first image generation model are the parameters adjusted by the previous training process of the current training process (e.g., the N-1th training process of the first image generation model based on the training system).
[0090] In this step, the target program may input the acquired first image description into the first image generation model, and process the first image description using the first image generation model to obtain a first generated image corresponding to the first image description.
[0091] It should be noted that Figure 2 An exemplary process of training an image generation model is shown. Figure 2 The process shown does not limit the order in which the steps are to be performed. Figure 2In the illustrated process, step S230 is executed after step S220. In another case, step S230 may also be executed before step S220, or step S230 and step S220 may be executed in parallel.
[0092] After the target program obtains the first generated image and the predicted weight value, in step S240, the parameters of the first image generation model are adjusted based on the difference between the first generated image and the first sample image and the predicted weight value. In this step, the target program can determine the first prediction loss based on the difference between the first generated image and the first sample image and the predicted weight value, and then adjust the parameters of the first image generation model with the goal of minimizing the first prediction loss.
[0093] Specifically, in one embodiment, step S240 may include the following steps 21-23:
[0094] In step 21, a preset loss function is used to determine an intermediate prediction loss according to the difference between the first generated image and the first sample image. In one implementation, the preset loss function may be a cross entropy loss function. In this step, the target program may determine the intermediate prediction loss according to the difference between the first generated image and the first sample image based on the cross entropy loss function. In one implementation, the intermediate prediction loss may be expressed by the following formula (2): l(θ)=E (x1,z1)~D1 [-logp(x1|z1)](2); wherein l(θ) represents the intermediate prediction loss, θ represents the parameters to be adjusted involved in the first image generation model, x1 represents the first sample image, z1 represents the first image description, p(x1|z1) represents the probability that the first generated image obtained by the first image generation model for the first image description is the same as the first sample image, that is, the probability that the first image generation model obtains the first sample image for the first image description, and the probability can be obtained in the process of the first image generation model generating the first generated image based on the first image description. The p(x1|z1) can represent the difference between the first generated image and the first sample image, wherein the larger the p(x1|z1), the smaller the difference between the first generated image and the first sample image; D1 represents the aforementioned training data set, and E represents the calculated expected value.
[0095] In another implementation, the preset loss function may also be an MSE (mean square error) loss function, and the MSE loss function may be used to determine the intermediate prediction loss according to the difference between the first generated image and the first sample image, wherein the intermediate prediction loss is positively correlated with the difference between the first generated image and the first sample image.
[0096] Then, in step 22, a first prediction loss is determined based on the product of the intermediate prediction loss and the prediction weight value. In this step, the target program may first calculate the product of the intermediate prediction loss and the prediction weight value, and then determine the first prediction loss based on the product. In one implementation, the first prediction loss may be represented by the following formula (3):
[0097] Among them, L1(θ) represents the first prediction loss, represents the aforementioned predicted weight value, that is, the predicted weight value determined by the target reward model for the first sample image and the first image description.
[0098] It can be understood that in the process of training the first image generation model, the greater the probability that the first generated image obtained by inputting the first image description into the first image generation model is the same as the first sample image, the smaller the image difference between the first generated image and the first sample image, and the smaller the first prediction loss. In the process of training the first image generation model, the smaller the first prediction loss is, the better the image generation ability of the first image generation model is characterized. Accordingly, in step 23, the parameters of the first image generation model are adjusted with the goal of minimizing the first prediction loss.
[0099] In this step, the target program determines the adjustment gradient of the parameters of the first image generation model based on the first prediction loss using the back propagation algorithm: then determines the updated parameters of the first image generation model (i.e., the updated values of the parameters) using the determined adjustment gradient and the current parameters of the first image generation model (i.e., the current values of the parameters); and adjusts the parameters of the first image generation model based on the updated parameters. The parameter gradient of the first image generation model is determined with the goal of minimizing the first prediction loss. Minimizing the first prediction loss can achieve supervision of the generation results of the first image generation model and improve the quality of the images it generates.
[0100] In this embodiment, the first image generation model is trained in combination with the predicted weight value that can characterize the quality of the image-text pair of the first sample image and the first image description (for example, the image quality of the first sample image, and / or the matching degree between the first image description and the first sample image). The first image generation model is trained based on an offline reinforcement learning method in combination with the predicted weight value output by the target reward model for the first sample image and the first image description as training data, so as to improve the image generation capability of the first image generation model.
[0101] Moreover, in combination with the environmental feedback data, i.e. the prediction weight value, it is possible to achieve that in the model training process, more emphasis is placed on using the training data, i.e., the image-text pairs, with the corresponding prediction weight value to determine the first prediction loss, i.e., more emphasis is placed on using the image-text pairs with good quality to train the first image generation model, so as to achieve better improvement of the image generation capability of the first image generation model and ensure the stability of its image generation capability. And to a certain extent, it is ensured that the quality of the image generated by the trained first image generation model is more in line with environmental expectations (i.e., human intentions).
[0102] The above steps S210 to S240 are a model iterative training process for the first image generation model. In order to train a first image generation model with better image generation capability, the above process can be iterated multiple times. That is, after step S240, based on the updated parameters of the first image generation model, return to step S210 until the stop condition of the model iterative training process is reached, and the trained first image generation model is obtained.
[0103] The stopping conditions of the model iterative training process of the first image generation model may include: the number of iterative training times reaches a preset number threshold, or the iterative training duration reaches a preset duration, or the first prediction loss is less than a set threshold, etc.
[0104] Let's review the training process of the aforementioned first image generation model. The above embodiment is explained by taking a pair of image-text pairs (i.e., a pair of first image descriptions and their corresponding first sample images) as an example. In another embodiment, the above model training process can also be performed for a batch of samples, i.e., multiple pairs of image-text pairs, to obtain the prediction weight values corresponding to each pair of image-text pairs and the first generated image corresponding to the image description in each pair of image-text pairs, and then based on the prediction weight values corresponding to each pair of image-text pairs, the first generated image corresponding to the image description in each pair of image-text pairs, and the difference between the sample images, determine the first prediction loss, and adjust the parameters of the first image generation model to be trained with the goal of minimizing the first prediction loss. In this embodiment, the first prediction loss is determined for a batch of samples, and then the parameters of the first image generation model are adjusted. This can reduce the number of parameter adjustments to the first image generation model and make it easier to implement the training process.
[0105] In yet another embodiment, in order to better improve the image generation capability of the first image generation model, as Figure 3 As shown, the method may further include the following steps S310-S390:
[0106] In step S310, a first image description and a first sample image corresponding thereto are obtained. The implementation process of step S310 can be found in Figure 2 Step S210 in the illustrated process is not described in detail here.
[0107] In step S320, the first image description and the first sample image are used to obtain a predicted weight value through the target reward model. The predicted weight value is positively correlated with the image quality of the first sample image and / or is positively correlated with the matching degree between the first image description and the first sample image. The implementation process of step S320 can be found in Figure 2 The implementation process of step S220 in the illustrated process will not be described in detail here.
[0108] In step S330, the first image description is used to generate a first generated image through the first image generation model. The implementation process of step S330 can be found in Figure 2 The implementation process of step S230 in the illustrated flow is not described in detail here.
[0109] In step S340, the preset loss function is used to determine the intermediate prediction loss according to the difference between the first generated image and the first sample image. The implementation process of step S320 can refer to the implementation process of the aforementioned step 21, which will not be described in detail here.
[0110] In step S350, the first prediction loss is determined based on the product of the intermediate prediction loss and the prediction weight value. The implementation process of step S320 can refer to the implementation process of the aforementioned step 22, which will not be described in detail here.
[0111] In step S360, a second image description and a corresponding second sample image are obtained. In one implementation, the second image description and the corresponding second sample image may be obtained from the aforementioned public data set that can provide a large number of image-text pairs or artificially produced data (such as the aforementioned image-text data set S). Compared with the aforementioned generated image generated by the second image generation model according to the image description, the second sample image corresponding to the second image description is a real image, which can carry more diverse image data.
[0112] Then, in step S370, the second generated image is obtained by using the first image generation model using the second image description. The process of obtaining the second generated image can refer to the process of obtaining the first generated image, which will not be described in detail here.
[0113] In step S380, the second prediction loss is determined by using the difference between the second sample image and the second generated image. In this step, the target program can determine the second prediction loss based on the preset loss function and using the difference between the second sample image and the second generated image, wherein the greater the difference between the second sample image and the second generated image, the greater the second prediction loss.
[0114] In one implementation, the preset loss function may be a cross entropy loss function. The second prediction loss L2(θ) may be expressed by the following formula (4): L2(θ)=E (x2,z2)~D2 [-log p(x2|z2)](4); D2 represents the data set to which the second image description and its corresponding second sample image belong (for example, the aforementioned image and text data set S); x2 represents the aforementioned second sample image, z2 represents the aforementioned second image description, and p(x2|z2) represents the probability that the second generated image obtained by the first image generation model for the second image description is the same as the second sample image, that is, the probability of obtaining the second sample image through the first image generation model according to the second image description, which can be obtained in the process of generating the second generated image by the first image generation model for the second image description. Among them, the larger the p(x2|z2), the smaller the difference between the second sample image and the second generated image, and the smaller the second prediction loss, and E represents the calculated expected value.
[0115] In another implementation, the preset loss function can also be an MSE (mean square error) loss function. The MSE loss function is used to utilize the difference between the second sample image and the second generated image to determine the second prediction loss, wherein the second prediction loss is positively correlated with the difference between the second sample image and the second generated image.
[0116] Next, in step S390, the parameters of the first image generation model are adjusted with the goal of minimizing the first prediction loss and the second prediction loss.
[0117] In this step, the target program can first determine the total prediction loss based on the first prediction loss and the second prediction loss, and then adjust the parameters of the first image generation model with the goal of minimizing the total prediction loss, wherein the total prediction loss is positively correlated with the first prediction loss and the second prediction loss, respectively. In one case, the total prediction loss L(θ) can be expressed by the following formula (5): L(θ) = φL1(θ) + βL2(θ)(5); wherein φ is a weight value corresponding to the preset first prediction loss, and β is a weight value corresponding to the preset second prediction loss.
[0118] It can be understood that the images in the image-text pairs in the aforementioned training data set are generated images using the second image generation model for the corresponding input image descriptions. Relative to this type of generated images, the third sample image corresponding to the second image description is a real image. In this implementation, in the process of training the first image generation model, real images and their corresponding image descriptions are also added to train the first image generation model, which increases the diversity of data for training the first image generation model and can better improve the image generation capability of the first image generation model.
[0119] Corresponding to the above method embodiment, the present disclosure provides an image generation method, which can be implemented by a first program. The first program can be the same physical program as the aforementioned target program, or can be a different physical program from the aforementioned target program. Figure 4 As shown, the method may include the following steps S410-S420:
[0120] In step S410, the image description to be processed is obtained. In one implementation, the image description to be processed may be any image description input by the user when there is a need to generate an image using the image description (for example, when generating corresponding illustrations for novels, news, etc.), and accordingly, the first program may obtain the image description input by the user as the image description to be processed.
[0121] In step S420, the target image is obtained by using the image description to be processed and training the image generation model obtained by the training method of the image generation model, that is, the first image generation model trained as described above. The process of obtaining the target image can refer to the process of obtaining the first generated image as described above, and will not be described in detail here.
[0122] In the above process, the trained first image generation model can be used to process the description of the image to be processed to obtain a target image with better quality, thereby improving the user experience.
[0123] The foregoing describes specific embodiments of the present disclosure, and other embodiments are within the scope of the appended claims. In some cases, the actions or steps recorded in the claims may be performed in an order different from that in the embodiments, and the desired results may still be achieved. In addition, the processes depicted in the accompanying drawings do not necessarily have to be performed in the specific order or sequential order shown to achieve the desired results. In some embodiments, multitasking and parallel processing are also possible, or may be advantageous.
[0124] Corresponding to the above method embodiment, the present disclosure provides an image generation model training device 500, whose schematic block diagram is as follows: Figure 5 As shown, it is used to execute Figure 2 or Figure 3 The method shown, the device 500 includes:
[0125] A first acquisition module 510, configured to acquire a first image description and a first sample image corresponding thereto;
[0126] A first obtaining module 520 is configured to obtain a prediction weight value by using the first image description and the first sample image through a target reward model, wherein the prediction weight value is positively correlated with the image quality of the first sample image and / or is positively correlated with the matching degree between the first image description and the first sample image;
[0127] A second obtaining module 530 is configured to obtain a first generated image by using the first image description through a first image generation model;
[0128] The first adjustment module 540 is configured to adjust the parameters of the first image generation model based on the difference between the first generated image and the first sample image and the prediction weight value.
[0129] In an optional embodiment, the first adjustment module 540 includes: a first determination unit (not shown in the figure), configured to use a preset loss function to determine the intermediate prediction loss according to the difference between the first generated image and the first sample image; a second determination unit (not shown in the figure), configured to determine the first prediction loss based on the product of the intermediate prediction loss and the prediction weight value; an adjustment unit (not shown in the figure), configured to adjust the parameters of the first image generation model with the goal of minimizing the first prediction loss.
[0130] In an optional implementation, it also includes:
[0131] A third acquisition module (not shown in the figure), configured to acquire a second image description and a second sample image corresponding thereto;
[0132] a fourth obtaining module (not shown in the figure), configured to obtain a second generated image by using the second image description and the first image generation model;
[0133] A first determination module (not shown in the figure), configured to determine a second prediction loss by using a difference between the second sample image and the second generated image;
[0134] The adjustment unit is specifically configured to adjust the parameters of the first image generation model with the goal of minimizing the first prediction loss and the second prediction loss.
[0135] In an optional implementation, the invention further includes: a fourth acquisition module (not shown in the figure), configured to acquire the third image description and the corresponding third sample image;
[0136] a fifth acquisition module (not shown in the figure), configured to acquire the label weight value corresponding to the third image description and the third sample image, wherein the label weight value is positively correlated with the image quality of the third sample image and / or is positively correlated with the matching degree between the third image description and the third sample image;
[0137] a fifth obtaining module (not shown in the figure), configured to obtain an evaluation weight value by using the third image description and the third sample image through a reward model to be trained;
[0138] A second determination module (not shown in the figure) is configured to determine a third prediction loss using the evaluation weight value and the label weight value;
[0139] The second adjustment module (not shown in the figure) is configured to adjust the reward model to be trained with the goal of minimizing the third prediction loss to obtain a target reward model that meets the first preset convergence condition.
[0140] In an optional implementation, the tag weight value is determined based on at least one of the following information: a clarity score of the third sample image, an aesthetic score of the third sample image, and a matching value between the third sample image and the third image description.
[0141] In an optional implementation, the first sample image is an image generated according to the first image description using a pre-trained second image generation model; parameters of the second image generation model serve as initial parameters of the first image generation model.
[0142] Corresponding to the above method embodiment, the present disclosure embodiment provides an image generating device 600, whose schematic block diagram is as follows: Figure 6 As shown, it is used to execute Figure 4 The method shown, the device 600 includes:
[0143] A second acquisition module 610 is configured to acquire a description of an image to be processed;
[0144] The third obtaining module 620 is configured to obtain a target image by using the image description to be processed and the image generation model obtained by training using the aforementioned image generation model training device.
[0145] The above device embodiments correspond to the method embodiments. For specific descriptions, please refer to the description of the method embodiments, which will not be repeated here. The device embodiments are obtained based on the corresponding method embodiments and have the same technical effects as the corresponding method embodiments. For specific descriptions, please refer to the corresponding method embodiments.
[0146] The present disclosure provides an electronic device, including a memory and a processor, wherein the memory stores an executable code, and when the processor executes the executable code, the following is implemented: Figure 2 , Figure 3 or Figure 4 The method shown below. Figure 7 , which shows a schematic structural diagram of an electronic device suitable for implementing an embodiment of the present disclosure. Figure 7 The electronic device shown is only an example and should not bring any limitation to the functions and scope of use of the embodiments of the present disclosure.
[0147] like Figure 7 As shown, the electronic device may include a processing device (e.g., a central processing unit, a graphics processing unit, etc.) 701, which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM) 702 or a program loaded from a storage device 708 into a random access memory (RAM) 703. In RAM 703, various programs and data required for the operation of the electronic device are also stored. The processing device 701, ROM 702, and RAM 703 are connected to each other via a bus 704. An input / output (I / O) interface 705 is also connected to the bus 704.
[0148] Typically, the following devices may be connected to the I / O interface 705: input devices 706 including, for example, a touch screen, a touch pad, a keyboard, a mouse, etc.; output devices 707 including, for example, a liquid crystal display (LCD), a speaker, a vibrator, etc.; storage devices 708 including, for example, a magnetic tape, a hard disk, etc.; and communication devices 709. The communication devices 709 may allow the electronic device to communicate with other devices wirelessly or by wire to exchange data. Figure 7 An electronic device having various devices is shown, but it should be understood that it is not required to implement or possess all the devices shown. More or fewer devices may be implemented or possessed instead. Figure 7 Each block shown in the figure may represent one device, or may represent multiple devices as required.
[0149] In particular, according to an embodiment of the present disclosure, the process described above with reference to the flowchart can be implemented as a computer software program. For example, an embodiment of the present disclosure includes a computer program product, which includes a computer program carried on a computer-readable medium, and the computer program includes a program code for executing the method shown in the flowchart. In such an embodiment, the computer program can be downloaded and installed from a network through a communication device 709, or installed from a storage device 708, or installed from a ROM 702. When the computer program is executed by the processing device 701, the above-mentioned functions defined in the method of the embodiment of the present disclosure are executed.
[0150] The present disclosure also provides a computer-readable storage medium having a computer program stored thereon. When the computer program is executed in a computer, the computer is caused to execute the following steps provided in the present disclosure: Figure 2 , Figure 3 or Figure 4 The method flow is shown.
[0151] It should be noted that the computer-readable medium described in the embodiments of the present disclosure may be a computer-readable signal medium or a computer-readable storage medium or any combination of the above two. The computer-readable storage medium may be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device or device, or any combination of the above. More specific examples of computer-readable storage media may include, but are not limited to: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above. In the embodiments of the present disclosure, the computer-readable storage medium may be any tangible medium containing or storing a program, which may be used by or in combination with an instruction execution system, device or device. In the embodiments of the present disclosure, the computer-readable signal medium may include a data signal propagated in a baseband or as part of a carrier wave, in which a computer-readable program code is carried. This propagated data signal may take a variety of forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination of the above. The computer readable signal medium may also be any computer readable medium other than a computer readable storage medium, which may send, propagate or transmit a program for use by or in conjunction with an instruction execution system, apparatus or device. The program code contained on the computer readable medium may be transmitted using any suitable medium, including but not limited to: wires, optical cables, RF (Radio Frequency), etc., or any suitable combination of the above.
[0152] The computer-readable medium may be included in the electronic device; or it may exist independently without being installed in the electronic device. The computer-readable medium carries one or more programs. When the one or more programs are executed by the electronic device, the electronic device: obtains a first image description and a first sample image corresponding to the first image; obtains a predicted weight value by using the first image description and the first sample image through a target reward model, wherein the predicted weight value is positively correlated with the image quality of the first sample image and / or is positively correlated with the matching degree between the first image description and the first sample image; obtains a first generated image by using the first image description through a first image generation model; adjusts the parameters of the first image generation model based on the difference between the first generated image and the first sample image and the predicted weight value. Alternatively, the electronic device: obtains a description of the image to be processed; obtains a target image by using the image generation model trained by using the image generation model training method described above using the image description to be processed.
[0153] Computer program code for performing the operations of the disclosed embodiments may be written in one or more programming languages or a combination thereof, including object-oriented programming languages such as Java, Smalltalk, C++, and conventional procedural programming languages such as "C" or similar programming languages. The program code may be executed entirely on the user's computer, partially on the user's computer, as a separate software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In cases involving a remote computer, the remote computer may be connected to the user's computer via any type of network, including a local area network (LAN) or a wide area network (WAN), or may be connected to an external computer (e.g., via the Internet using an Internet service provider).
[0154] Each embodiment in the present disclosure is described in a progressive manner, and the same or similar parts between the embodiments can be referred to each other, and each embodiment focuses on the differences from other embodiments. In particular, for the storage medium and computing device embodiments, since they are basically similar to the method embodiments, the description is relatively simple, and the relevant parts can be referred to the partial description of the method embodiments.
[0155] Those skilled in the art should be aware that in one or more of the above examples, the functions described in the embodiments of the present invention may be implemented using hardware, software, firmware, or any combination thereof. When implemented using software, these functions may be stored in a computer-readable medium or transmitted as one or more instructions or codes on a computer-readable medium.
[0156] The specific implementation methods described above further describe the purpose, technical solutions and beneficial effects of the embodiments of the present invention in detail. It should be understood that the above description is only a specific implementation method of the embodiments of the present invention and is not intended to limit the scope of protection of the present invention. Any modification, equivalent replacement, improvement, etc. made on the basis of the technical solution of the present invention shall be included in the scope of protection of the present invention.
Claims
1. A training method for an image generation model, comprising: Obtaining a first image description and a first sample image corresponding thereto; Using the first image description and the first sample image, a prediction weight value is obtained through a target reward model, wherein the prediction weight value is positively correlated with an image quality of the first sample image and / or is positively correlated with a matching degree between the first image description and the first sample image; Using the first image description and a first image generation model, a first generated image is obtained; Based on the difference between the first generated image and the first sample image and the prediction weight value, the parameters of the first image generation model are adjusted.
2. The method of claim 1, wherein: The adjusting the parameters of the first image generation model comprises: Determining an intermediate prediction loss according to a difference between the first generated image and the first sample image using a preset loss function; Determining a first prediction loss based on a product of the intermediate prediction loss and the prediction weight value; The parameters of the first image generation model are adjusted with the goal of minimizing the first prediction loss.
3. The method of claim 2, further comprising: Obtaining a second image description and a second sample image corresponding to the second image description; Using the second image description and the first image generation model, a second generated image is obtained; determining a second prediction loss using a difference between the second sample image and the second generated image; The step of adjusting the parameters of the first image generation model with the goal of minimizing the first prediction loss includes: The parameters of the first image generation model are adjusted with the goal of minimizing the first prediction loss and the second prediction loss.
4. The method of claim 1, further comprising: Obtaining the third image description and its corresponding third sample image; Acquire a label weight value corresponding to the third image description and the third sample image, wherein the label weight value is positively correlated with the image quality of the third sample image and / or is positively correlated with the matching degree between the third image description and the third sample image; Using the third image description and the third sample image, through the reward model to be trained, to obtain an evaluation weight value; Determining a third prediction loss using the evaluation weight value and the label weight value; With the goal of minimizing the third prediction loss, the reward model to be trained is adjusted to obtain a target reward model that meets a first preset convergence condition.
5. The method according to any one of claims 1 to 4, wherein: The tag weight value is determined based on at least one of the following information: a clarity score of the third sample image, an aesthetic score of the third sample image, and a matching value between the third sample image and the third image description.
6. The method according to any one of claims 1 to 4, wherein: The first sample image is an image generated according to the first image description using a pre-trained second image generation model; the parameters of the second image generation model serve as initial parameters of the first image generation model.
7. A method for generating an image, comprising: Get the description of the image to be processed; The target image is obtained by using the image description to be processed and training the image generation model obtained by using the image generation model training method described in any one of claims 1 to 6.
8. A training device for an image generation model, comprising: A first acquisition module, configured to acquire a first image description and a first sample image corresponding thereto; a first obtaining module configured to obtain a prediction weight value by using the first image description and the first sample image through a target reward model, wherein the prediction weight value is positively correlated with an image quality of the first sample image and / or is positively correlated with a matching degree between the first image description and the first sample image; A second obtaining module is configured to obtain a first generated image by using the first image description through a first image generation model; The first adjustment module is configured to adjust the parameters of the first image generation model based on the difference between the first generated image and the first sample image and the prediction weight value.
9. An image generating device, comprising: A second acquisition module is configured to acquire a description of the image to be processed; The third obtaining module is configured to obtain a target image by using the image description to be processed and the image generation model obtained by training using the image generation model training device according to claim 8.
10. An electronic device comprising a memory and a processor, wherein: The memory stores executable codes, and when the processor executes the executable codes, the method according to any one of claims 1 to 7 is implemented.
11. A computer-readable storage medium having a computer program stored thereon, which, when executed in a computer, causes the computer to execute the method according to any one of claims 1 to 7.