Image generation method, device, program product and storage medium

By using the preset background color and the guide image of the subject and the prompt text of the target object description, input to the pre-training model to generate an image with a specific background color, which solves the problems of low generated image quality and high training cost in the existing technology. , achieving low-cost and efficient image generation.

CN118154727BActive Publication Date: 2024-09-20ZHEJIANG NIAOCHAO SUPPLY CHAIN MANAGEMENT CO LTD
View PDF 6 Cites 0 Cited by

Patent Information

Application Number
CN202410581609.6
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-05-10
Publication Date
2024-09-20
Estimated Expiration
2044-05-10

AI Technical Summary

Technical Problem

The existing technology is difficult to generate images with specific background colors at low cost, and the quality of the generated images is not high. Especially in application scenarios that require a white background, the performance of the matting model is insufficient and the training cost is high.

Method used

By obtaining a guidance image with a preset background color and a preset subject, as well as a prompt text containing target object description information, input it into the pre-trained image generation model to generate the target image so that it has a preset background color, contains the target object, and Position matching in the image.

Benefits of technology

It achieves low-cost, high-quality generation of images with specific background colors, avoids special training and manual review of image generation models, and improves generation efficiency and diversity.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118154727B
    Figure CN118154727B
Patent Text Reader

Abstract

The present disclosure provides an image generation method, device, program product and storage medium, the image generation method may include: obtaining a guide image, the guide image includes: an image with a preset background color and containing a preset subject; obtaining a prompt text, the prompt text containing at least one target description information of a target object to be generated; inputting the guide image and the prompt text into a pre-trained image generation model, so that the image generation model generates a target image based on the guide image and the prompt text, wherein the target image has the preset background color, contains a target object matching the target description information, and the position of the target object in the target image matches the position of the preset subject in the guide image. This embodiment can generate a high-quality target image.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present disclosure relates to the technical field of machine learning, and in particular to an image generation method, device, program product, and storage medium. Background Art

[0002] With the development of image processing and machine learning technologies, image generation models can now generate high-quality images based on the prompt text and original image (if any) entered by the user. In some application scenarios, users want the images generated by the model to have a specified background color. Therefore, how to generate images with a specific background color at a low cost has become a technical problem that needs to be solved urgently. Summary of the invention

[0003] To overcome the problems existing in the related art, the present disclosure provides an image generation method, device, program product and storage medium.

[0004] According to a first aspect of an embodiment of this specification, there is provided an image generation method, the method comprising:

[0005] Acquire a guide image, wherein the guide image includes: an image having a preset background color and including a preset subject;

[0006] Acquire a prompt text, wherein the prompt text includes at least one target description information of a target object to be generated;

[0007] The guide image and the prompt text are input into a pre-trained image generation model so that the image generation model generates a target image based on the guide image and the prompt text, wherein the target image has the preset background color, contains a target object matching the target description information, and the position of the target object in the target image matches the position of the preset subject in the guide image.

[0008] According to a second aspect of an embodiment of this specification, there is provided an image generation method, the method comprising:

[0009] Obtaining description information input by the user and sending it to a server, wherein the server is used to execute the steps of the method described in the first aspect;

[0010] Get the target image returned by the server and display it.

[0011] According to a third aspect of an embodiment of this specification, a computer device is provided, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein when the processor executes the computer program, the steps of the method embodiment described in the first aspect are implemented.

[0012] According to a fourth aspect of the embodiments of this specification, a computer-readable storage medium is provided, on which a computer program is stored. When the computer program is executed by a processor, the steps of the method embodiments described in the first or second aspect are implemented.

[0013] According to a fifth aspect of the embodiments of this specification, a computer program product is provided, including a computer program, which, when executed by a processor, implements the steps of the method embodiments described in the first or second aspect above.

[0014] The technical solutions provided by the embodiments of this specification may have the following beneficial effects:

[0015] In an embodiment of the present specification, a guide image can be obtained, and the guide image includes: an image with a preset background color and containing a preset subject; the obtained prompt text contains at least one target description information of the target object to be generated; therefore, the guide image and the prompt text are input into an image generation model based on pre-training, so that the image generation model can generate a target image based on the guide image and the prompt text, wherein the target image has a preset background color, contains a target object matching the target description information, and the position of the target object in the target image matches the position of the preset subject in the guide image. Therefore, this embodiment does not need to train the image generation model for a specific background color, and can enable the model to generate a high-quality target image.

[0016] It is to be understood that the foregoing general description and the following detailed description are exemplary and explanatory only and are not restrictive of the present disclosure. BRIEF DESCRIPTION OF THE DRAWINGS

[0017] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the specification and, together with the description, serve to explain the principles of the disclosure.

[0018] Figure 1 is a flowchart of an image generating method according to an exemplary embodiment of the present specification.

[0019] Figure 2A It is an application scenario diagram of an image generation method shown in this specification according to an exemplary embodiment.

[0020] Figure 2B It is a schematic diagram of an image containing Gaussian spots according to an exemplary embodiment of the present specification.

[0021] Figure 2C It is a schematic diagram of an image generating method shown in this specification according to an exemplary embodiment.

[0022] Figure 2DIt is a schematic diagram of training and reasoning of an image generation model shown in this specification according to an exemplary embodiment.

[0023] Figure 2E It is a schematic diagram of an image generated by an image generation model under multiple different noise intensities according to an exemplary embodiment of this specification.

[0024] Figure 3A It is a schematic diagram of an image generation result shown in this specification according to an exemplary embodiment.

[0025] Figure 3B It is a schematic diagram of an image generated by using a white image as a guide according to an exemplary embodiment of the present specification.

[0026] Figure 3C It is a schematic diagram of an image generated by using a white image as a guide according to an exemplary embodiment of the present specification.

[0027] Figure 3D It is a schematic diagram of an image generated by using another image as a guide according to an exemplary embodiment of the present specification.

[0028] Figure 4 It is a schematic diagram of generating an image according to an exemplary embodiment of the present specification.

[0029] Figure 5 is a flowchart of another image generating method according to an exemplary embodiment of the present specification.

[0030] Figure 6 It is a hardware structure diagram of a computer device where an image generating device is located according to an exemplary embodiment of this specification. DETAILED DESCRIPTION

[0031] Exemplary embodiments will be described in detail herein, examples of which are shown in the accompanying drawings. When the following description refers to the drawings, unless otherwise indicated, the same numbers in different drawings represent the same or similar elements. The implementations described in the following exemplary embodiments do not represent all implementations consistent with this specification. Instead, they are merely examples of devices and methods consistent with some aspects of this specification as detailed in the appended claims.

[0032] The terms used in this specification are for the purpose of describing specific embodiments only and are not intended to limit this specification. The singular forms "a", "the" and "the" used in this specification and the appended claims are also intended to include plural forms unless the context clearly indicates otherwise. It should also be understood that the term "and / or" used herein refers to and includes any or all possible combinations of one or more associated listed items.

[0033] It should be understood that although the terms first, second, third, etc. may be used in this specification to describe various information, this information should not be limited to these terms. These terms are only used to distinguish the same type of information from each other. For example, without departing from the scope of this specification, the first information may also be referred to as the second information, and similarly, the second information may also be referred to as the first information. Depending on the context, the word "if" as used herein may be interpreted as "at the time of" or "when" or "in response to determining".

[0034] The user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, stored data, displayed data, etc.) involved in this disclosure are all information and data authorized by the user or fully authorized by all parties, and the collection, use and processing of relevant data must comply with the relevant laws, regulations and standards of relevant countries and regions, and provide corresponding operation entrances for users to choose to authorize or refuse.

[0035] In some specific scenarios, users have some specific requirements for the images generated by the image generation model. For example, in some application scenarios, users want the generated images to have a specific background color.

[0036] Taking local life and other application scenarios as an example, the platform can provide store services for merchants, and merchants can manage their online stores in the platform. For example, merchants can display a variety of different products in their online stores. Merchants can show users the characteristics and advantages of products by uploading product photos, adding descriptions and specifications and other information. Among them, in order to better display the products, product images with specific background colors can be used, for example, product images with white backgrounds, that is, white background product images. Of course, in other application scenarios, users may also want to generate images with other background colors.

[0037] To let the image generation model generate images with a specific background color, we can use two approaches, still taking the white background product image as an example:

[0038] Idea 1: After the product image is generated by the image generation model, the image is cut out by the cutout model, and then the cutout image is merged into the white image to obtain the white-background product image. The disadvantage of this solution is that the output of the white-background product image is heavily dependent on the performance of the cutout model. However, the performance of the current cutout model in the industry needs to be improved, which will have a significant impact on the output efficiency and easily cause problems such as edge burrs and missing of the main cutout part.

[0039] Idea 2: Perform special training on white background image generation on the pre-trained base model. For example, strategies such as noise offset can be used to alleviate the problem that the image generation model cannot produce high-contrast images. However, this solution requires a high training cost to iterate the base model, and it may not guarantee that the model can stably output white background images.

[0040] Based on this, the present embodiment provides an image generation method, which can realize the generation of a specific background color image at a low cost, and the generated target image has a high quality. Next, the present embodiment is described in detail.

[0041] like Figure 1 As shown, Figure 1 is a flowchart of an image generation method according to an exemplary embodiment of the present specification, comprising the following steps:

[0042] In step 102, a guidance image is acquired.

[0043] The guiding image is an image with a preset background color and including a preset subject.

[0044] In step 104, the prompt text is obtained.

[0045] The prompt text includes at least one target description information of the target object to be generated.

[0046] In step 106, the guide image and the prompt text are input into a pre-trained image generation model, so that the image generation model generates a target image based on the guide image and the prompt text.

[0047] The target image is an image having the preset background color, including a target object matching the target description information, and a position of the target object in the image matching a position of the preset subject in the guide image.

[0048] The image generation method of this embodiment can be run in a computer device, including but not limited to a server, a cloud server, a server cluster, a tablet computer, a personal digital assistant, a laptop computer, or a desktop computer. The image generation method embodiment can be applied to a client or a server, and this embodiment does not limit this.

[0049] The method of this embodiment can be applied to a variety of application scenarios. Figure 2A Shown is a schematic diagram of an application scenario shown in this specification according to an exemplary embodiment, including a platform, merchants and users. Among them, the platform has built a server and provides users with a client, through which users can use the services provided by the platform; different from the client for users, the platform also provides the store with a client for merchants, through which merchants can use the merchant services provided by the platform, such as store management services. Merchants can manage their online store information through the platform, including store name, address, contact information, etc.; it can also include product display services, merchants can display their own products on the platform, and display product features and advantages to users by uploading product photos, adding descriptions and specifications, etc. In actual applications, it can also include order management services or delivery services, etc., which are not elaborated in this embodiment. As an example, the model involved in the image generation method of this embodiment can be deployed in the server, for example, it can be deployed in Figure 2A In the server connected to the merchant's client, the merchant's client can receive user input and send it to the server, and the server runs the image generation method of this embodiment and sends the result to the client. In other examples, the model involved in the image generation method of this embodiment can also be deployed in the merchant's client, and this embodiment does not impose any restrictions on this. Of course, it can also be applied to other scenarios, and this embodiment does not impose any restrictions on this.

[0050] The specific structure of the image generation model of this embodiment can be constructed by itself as needed, and the solution of this embodiment can be used to improve the existing pre-trained image generation model as needed. Optionally, the image generation model can include the following types of models: Generative Adversarial Network GAN model, flow-based generation model or diffusion model, etc., which is not limited in this embodiment.

[0051] Taking the stable diffusion model as an example, the existing stable diffusion model can include the Cliptext encoder (text encoder of the Clip model) as a text feature extraction layer and the generation network U-net. The output of the Clip text encoder is directly connected to the U-net. The U-net uses its internal encoder to compress the image representation, and then performs a diffusion operation on the latent representation space (Latentspace), that is, denoising the output of the forward diffusion backward to obtain the latent representation Latent, and finally using the decoder to restore the image.

[0052] In actual applications, the background color set in this embodiment can be flexibly configured according to the actual application scenario, such as white, black, red, etc., which is not limited in this embodiment.

[0053] The preset subject in this embodiment can be configured according to actual needs. In some examples, the preset subject can provide the model with the position information of the target object in the target image to be generated. Optionally, the preset subject can also provide the model with information such as the shape of the target object in the target image to be generated.

[0054] As an example, the preset subject included in the guide image includes: a subject with a preset shape, so that the overall shape of the target object in the target image matches the overall shape of the preset subject. If the target object to be generated is a container for a certain dish, the preset subject can be a subject related to the overall shape of the container for a certain dish, such as a sphere or a sphere-like subject. It is not limited here that the overall shape of the preset subject and the target object to be generated must be the same, as long as the two are different but related. As another example, if the target object to be generated is a tower-shaped building, etc., the preset subject can be a tower-like subject; if the target object to be generated is a person, the preset subject can be a subject that can reflect the outline of the person (which can be the outline of the whole body, half body or face, etc.), and so on.

[0055] Optionally, the color of the preset subject in the guide image can be customized as needed. The color of the preset subject is different from the background color in the guide image, and the two can have a high contrast ratio. According to the requirements for the background color of the target image, a color with a large difference in contrast ratio from the background color of the target image can be determined as the color of the preset subject. The preset subject occupies a certain area in the guide image. The preset subject is composed of multiple pixels, and the color values ​​between the pixels can be different, such as different grayscales.

[0056] As an example, the image generation model includes: a diffusion model; the color of the preset subject in the guide image gradually fades from the central area of ​​the subject to the outside of the subject. Optionally, the grayscale value may gradually decrease from the central area of ​​the preset subject to the outer area of ​​the preset subject, so that the positional relationship between the central area and the outer area of ​​the target object can be provided to the model. That is, the preset subject may be a subject whose color gradually fades from the central area of ​​the subject to the outside, for example, the preset subject may be a sphere whose color gradually fades from the center position to the outside.

[0057] For step 104, there are many ways to obtain the prompt text; for example, in actual applications, an interactive interface can be provided to obtain the prompt text input by the user, and the specific type of the interactive interface is not limited in this embodiment. Alternatively, the execution subject of this embodiment can generate the prompt text based on the user's input. The prompt text can be used to guide the image generation model to generate output of a specific type, theme or format.

[0058] According to the actual application scenario, the target object can be various. For example, the target object in the image can be various commodities, such as dishes, food, daily necessities, etc., or can be a person or other various animals, etc., which is not limited in this embodiment.

[0059] As an example, the prompt text may include a variety of descriptive information of the target object, which may be attribute information of the target object, and may also include task information of the target object that the model is required to generate, such as the perspective of the target object in the target image. Taking dishes as an example, it may include information such as dish name, raw material information, taste information, ingredients information, cooking method information, and may also include perspective information, raw and cooked food information labels or container information, and so on. After obtaining these descriptive information, it is also possible to generate a task prompt text and input it into a pre-trained language model so that the language model outputs the above prompt text according to the task prompt text; wherein, the task prompt text is used to instruct the language model to convert these descriptive information into natural sentences as an expert or the like.

[0060] As an example, the task prompt text can include the role information of "food expert", which can indicate the role that the language model needs to play and activate the professional ability of the model. The task prompt text can also include the task information of "polishing food attribute information and image attribute information and converting them into natural sentences", which can provide a clear task definition to the language model so that it can perform the task correctly. The task prompt text can be specifically as follows: "If you are a gourmet, please polish the following food information into a sentence: {product name, category name, raw material, method, taste, utensils or perspective}".

[0061] Based on this, the guide image and the prompt text are input into the image generation model based on pre-training, so that the image generation model generates a target image based on the guide image and the prompt text, wherein the target image has the preset background color, contains a target object matching the target description information, and the position of the target object in the target image matches the position of the preset subject in the guide image. Therefore, in this embodiment, there is no need to train the image generation model for a specific background color, nor is there any need for manual review to obtain a high-quality seed image, so the implementation cost of this embodiment is low, and the model can generate a high-quality target image.

[0062] In some examples, the image may include a noise-based diffusion model, which is trained by gradually adding noise that satisfies a preset probability distribution to image samples; the preset subject contained in the guide image includes: spots generated using a function corresponding to the preset probability distribution.

[0063] In this embodiment, it is considered that the diffusion model is a deep generative model based on two stages, including a forward diffusion stage and a backward diffusion stage. In the forward diffusion stage, noise is gradually added to the original data until a completely randomly distributed noise is obtained, that is, the input data is gradually disturbed by the noise. In the backward diffusion stage, starting from the random noise finally obtained in the forward diffusion stage, the noise is gradually removed until the data is generated. The noise adding process of the diffusion model is a destruction of the original data. The noise used by the diffusion model can be noise that meets the preset probability distribution, for example, it can include Gaussian noise, etc.

[0064] Based on this, in order to align with the diffusion model training process, the preset subject contained in the guide image of this embodiment includes: spots generated by a function corresponding to the preset probability distribution, so that the color information of the preset subject contained in the guide image is consistent with the noise added by the diffusion model during the training stage.

[0065] In some examples, the noise added by the diffusion model may be noise based on Gaussian distribution, and the guide image may include: an image having a preset background color and containing Gaussian spots.

[0066] As an example, a Gaussian blob contained in an image can be generated by a Gaussian function. A Gaussian function is a probability density function in the form of a normal distribution. Optionally, generating a target image based on a Gaussian function can be to create an image, in which the color of all pixels in the image can be a preset background color, such as a completely white image; parameters such as the center position, size, or intensity of the Gaussian blob can be determined, and at a specified position, the intensity value is calculated at each pixel of the image according to the Gaussian function to generate one or more Gaussian blobs of preset colors; this step can be repeated to generate multiple blobs, and the new blobs can be superimposed on the image to obtain a guide image.

[0067] As an example, the guide image may include: an image with a white background and containing black Gaussian spots, so that the image generation model can be guided to generate a high-contrast target image, that is, an image with a white background.

[0068] In practical applications, the position of the preset subject in the guide image can be configured as needed. For example, the preset subject can be located at the upper left or lower right side of the image, etc.; as an example, it can be located in the middle area of ​​the guide image, so that the target object in the target image generated by the image generation model is located in the middle area of ​​the image.

[0069] In some examples, the noise-based diffusion model may also include other input parameters, such as noise control parameters. In practical applications, the noise control parameter value may be set as needed to control the process of adding noise to the input image by the model. Usually, based on the training principle of the diffusion model, the input noise control parameter is consistent with the training process of the diffusion model. In this embodiment, the step of inputting the guide image and the prompt text into the pre-trained image generation model so that the image generation model generates the target image based on the guide image and the prompt text may include:

[0070] The guide image, the prompt text and the preset noise control parameter value are input into an image generation model based on pre-training, so that the image generation model adds noise to the guide image according to the preset noise control parameter value to obtain a noise image that retains the image information in the guide image, and generates a target image based on the noise image and the prompt text.

[0071] In this embodiment, through the preset noise control parameter value, the image generation model can prevent the guidance image from being converted into a full-noise image when adding noise to the guidance image, but instead retain some image information in the guidance image so that the generated target image can match the image information in the guidance image, thereby generating a high-quality target image based on the guidance image.

[0072] In some examples, the preset noise control parameter value includes: a preset number of noise adding steps; the preset number of noise adding steps is less than the number of steps that the image generation model adds noise to the image sample during the training process. For example, the step of inputting the guide image and the prompt text into the image generation model based on pre-training so that the image generation model generates a target image based on the guide image and the prompt text may include: inputting the guide image, the prompt text and the preset number of noise adding steps into the image generation model based on pre-training so that the image generation model adds noise to the guide image according to the number of noise adding steps and generates a target image based on the prompt text; wherein the preset number of noise adding steps is less than the number of steps that the image generation model adds noise to the image sample during the training process.

[0073] In practical applications, the noise-based diffusion model may have a variety of input parameters, such as the number of noise adding steps. When the diffusion model is used to generate the target image of this embodiment, the preset number of noise adding steps may be less than the number of steps that the model adds noise to the image samples during the training process. For example, the preset number of noise adding steps may be close to the number of steps that the model adds noise to the image samples during the training process. As an example, some diffusion models implement pure noise conversion by adding noise to the original image for 1000 steps. The preset number of noise adding steps may be close to 1000 steps, such as a custom value such as 980 steps, and the difference between the two is less than a preset threshold. In this way, when the image generation model adds noise to the guide image, it will not convert the guide image into a full noise image, but will retain some image information in the guide image so that the generated target image can match the image information in the guide image.

[0074] In some examples, the preset noise control parameter value includes: a preset noise intensity; the preset noise intensity is lower than the intensity of noise added to the image sample by the image generation model during the training process. For example, the step of inputting the guide image and the prompt text into the image generation model based on pre-training so that the image generation model generates a target image based on the guide image and the prompt text may include: inputting the guide image, the prompt text and the preset noise intensity into the image generation model based on pre-training so that the image generation model adds noise to the guide image according to the noise intensity and generates a target image based on the prompt text; wherein the preset noise intensity is lower than the intensity of noise added to the image sample by the image generation model during the training process.

[0075] In practical applications, the input parameters of the noise-based diffusion model may also include noise intensity. When the target image of this embodiment is generated using the diffusion model, the preset noise intensity may be less than the intensity of the noise added to the image sample by the model during the training process. For example, the preset noise intensity may be close to the intensity of the noise added to the image sample by the model during the training process. As an example, some diffusion models achieve pure noise conversion by adding noise to the original image, that is, the noise intensity is 1, and the preset noise intensity may be close to 1, such as a custom value of 0.98, and the difference between the two is less than a preset threshold. In this way, when the image generation model adds noise to the guide image, it will not convert the guide image into a full noise image, but retain some image information in the guide image so that the generated target image can match the image information in the guide image.

[0076] In practical applications, the number of noise addition steps and the noise intensity can also be used simultaneously to control the diffusion model to add noise to the guidance image. Instead of converting the guidance image into a full-noise image, some image information in the guidance image is retained so that the generated target image can match the image information in the guidance image.

[0077] The scheme of this embodiment can be applied to a variety of scenarios, and the following is an example of generating product images. Taking some application scenarios as an example, the gallery of some platforms needs to spend a lot of money to purchase images, and can also be automatically generated using image generation models, but the images generated by existing image generation models cannot meet the needs. For example, it is difficult for the model to automatically generate images with white backgrounds, and it can only rely on the cutout model for post-processing, and the cutout results are obtained by white background images, which also brings 50% of the raw image results, which seriously restricts the raw image efficiency of AIGC (production AI, AI Generated Content). Therefore, in some schemes, high-quality seed images will be manually reviewed, and the seed images are white-background images that meet the requirements, and then the seed images are input into the model to allow the model to generate images based on the seed images. However, this method also requires a certain cost, and even the seed images that have been reviewed by people will produce low-quality AIGC images. In addition, some unpopular dishes may not have seed images, so these unpopular dish images cannot be obtained.

[0078] In addition, the white-background dish images generated by the model may have other defects such as poor layout or incomplete dishes in the image. In some solutions, ControlNet is usually used to control the layout of the image, and line drawings and depth maps are extracted from high-quality seed images as guide images. The disadvantage is that the quality of the seed image directly determines the final generated result, so the seed image needs to be manually reviewed and controlled. While ControlNet realizes layout and completeness control, it also limits the diversity of the model. The AIGC model cannot produce more diverse image results. For example, if the seed image is an oblique view, it is difficult to produce a flat view or a top view after being supported by ControlNet.

[0079] In this embodiment, taking the diffusion model as an example, the training of the diffusion model is to achieve pure noise conversion by denoising the original image for 1000 steps, but in reality, prior information will still be introduced; and in the text-generated image process, pure noise is used as the starting point for denoising, which is inconsistent; therefore, based on the purpose of generating white background images, this embodiment is based on the training idea of ​​the diffusion model, and the image generation process can be aligned with the training process. By means of image-generated image, the guide image is denoised to a level close to 100%, and then the text-generated image is used during denoising to provide guidance for the model with a white background.

[0080] As an example, the reasoning process of the diffusion model starts with a Gaussian noise image ε with the same size as the latent representation laten of the image. In contrast, this embodiment introduces a guide image so that when the model starts reasoning, it also obtains the object position information and white background information given in the guide image on the basis of Gaussian noise. As an example, a white background image with black Gaussian spots can be constructed as follows:

[0081] Construct an H×W grayscale image I, where H and W are the height and width of the guidance image input to the model, respectively, and the value range can be [0, 1]. Taking the input image of the model as an image with equal height and width as an example, for a given pixel (x, y) in the image, the I value can be calculated using the following Gaussian function:

[0082]

[0083] Among them, σ is a hyperparameter that controls the width of the Gaussian spot, S=H=W; such an image looks like a black ball that slowly fades away from the center of the white image to the edge of the image. Figure 2B The following is a schematic diagram of an image containing Gaussian spots. Figure 2B A sphere is shown with color values ​​fading away from the center of the sphere.

[0084] Among them, the size of the preset subject in the guide image can be set as needed. After determining the size of the guide image, it is possible to determine the area of ​​the guide image occupied by the preset subject, such as the middle area, etc., and then it can be determined that the pixel points in the image need to be calculated using the above-mentioned Gaussian function to obtain pixel values. The above embodiment is illustrated by taking the height and width of the guide image as an example. In actual applications, the height and width of the guide image may also be unequal, and may also be implemented using the above embodiment. For example, an image of height and width is first generated and an image containing the preset subject is generated using the above embodiment, and then the generated image is adjusted to the required height and width to obtain the guide image. Of course, other adjustments may also be made based on the above embodiment, and this embodiment does not limit this.

[0085] like Figure 2C , which is a schematic diagram of an embodiment of an image generation method according to an exemplary embodiment of the present specification. The prompt text Prompt in the figure takes "pickled fish, high definition, 4K" as an example. The prompt text can be encoded by a text encoder (Text Encoder) in the image generation model to obtain a text embedding vector Text Embedding; Figure 2B The guide image shown in can be encoded by the encoder Encoder in the image generation model to obtain the latent representation Zt in the latent space. Then the latent representation of the image and the text embedding vector can be processed by the generation network Unet such as denoising to obtain the latent representation Z0 of the generated target image in the latent space. The decoder Decod then converts it into the target image based on the latent representation Z0 of the target image.

[0086] The number of noise adding steps and / or noise intensity of the model can also be set. For example, the number of steps for model training is 1000, and the present embodiment can be set to 980 steps. Therefore, the model can add noise in the latent space based on the guide image and the number of noise adding steps, and then perform a denoising process to generate a high-quality white background image.

[0087] For example, Figure 2D and Figure 2E As shown, Figure 2D It is shown in the figure that the image generation model adds noise to the image sample for 1000 steps during the training phase. After 1000 steps, the input image is finally denoised to a full noise image. After the image generation model is trained, in the inference phase, it usually takes 30 to 50 steps to infer the image. As shown in 2D, Figure 2B After the guide image in 27 steps of denoising and the noise intensity of 0.9, the obtained noise image can retain the information of Gaussian spots in the guide image. Then the model denoises the noise image based on the information of Gaussian spots in the guide image, so as to obtain a high-quality target image.

[0088] As shown in 2E, it is a schematic diagram of the images generated by the image generation model under various noise intensities in the experiment. Figure 2E It can be seen that when the intensity is low, the model fails to generate high-quality target images well; when the noise intensity is close to but still less than 1, the model can generate high-quality target images.

[0089] In order to improve the performance of the model in some sub-fields, in some examples, some LoRA (Low-Rank Adaptation of Large Language Models) branch networks corresponding to the target objects are designed in this embodiment. LoRA was originally applied to the field of natural language for fine-tuning large language models. Since the number of parameters of large models exceeds 100 billion and the training cost is too high, LoRA adopts a method of only training low-rank matrices (low rank matrices), and injecting the parameters of the LoRA model into the SD model when using it, thereby changing the generation style of the diffusion model, etc. It can be expressed by the data formula W=W0+BA, where W0 is the parameter (Weights) of the initial diffusion model, BA is the low-rank matrix, that is, the parameter of the LoRA model, and W represents the final diffusion model parameter after being affected by the LoRA model. The BA matrix is ​​the training target of the LoRA model. The LoRA model can fine-tune the Cliptext encoder (text encoder of the Clip model) as the text feature extraction layer in the diffusion model and some network layers in Unet, such as the linear layer of CrossAttention. The whole process is a linear relationship, which can be considered as a model with a completely new effect obtained by superimposing the original diffusion model on the LoRA model.

[0090] In practical applications, image samples of a certain type of target object can be prepared in advance, and the diffusion model can be used as the base model and connected to the LoRA branch network. Based on the image samples of a type of target object, the LoRA branch network can be used for training so that the trained LoRA branch network can learn the association between the target objects of this category and the corresponding images, thereby controlling the diffusion model to generate a target image that matches this category.

[0091] In practical applications, the model can also be fine-tuned using image samples of target objects of multiple specific categories. Each category can correspond to a LoRA branch network, that is, the base model can be connected to multiple LoRA branch networks; wherein, the number of specific categories can be configured as needed, and specific specific categories can include objects of specific categories that are not involved in the training of the diffusion model. The specific configuration can be based on the actual application scenario, and this embodiment does not limit this. Taking n specific categories as an example, for any category ni in the n categories, a corresponding training data set is set, in which the training samples are the training samples and description samples of the target objects of category ni. The number of training data sets can be small. As an example, dozens of data can be used. In practical applications, it can be configured as needed. When training the LoRA branch network corresponding to category ni, the diffusion model and the LoRA branch networks corresponding to other categories do not participate in the training, and the parameters can be frozen. In this way, the trained LoRA branch network can learn the association between the description information of the category and the image, thereby controlling the diffusion model to generate an image matching the category. In this embodiment, each LoRA branch network can act on the text feature extraction layer in the diffusion model and the query (key) and value (value) layers in the U-Net network respectively.

[0092] Optionally, in the model inference stage, the LoRA branch network corresponding to the category information can be selected in the trained model according to the category information of the target object in the prompt text. Other LoRA branch networks are not selected and are in a non-working state. The diffusion model and the LoRA branch network corresponding to the target category generate the corresponding food image based on the text features of the input prompt text and the guide image.

[0093] like Figure 3A FIG. 1 is a schematic diagram of an image generation result according to an exemplary embodiment of the present specification. In this embodiment, a white-bottom pickled fish image is generated as an example. The guide image is as follows: Figure 2B As shown in the figure, the prompt text is "scyu, fish in soursoup, chilli, a big bowl on black marble table, steaming" as an example. The description information contained in the prompt text is explained in English. According to actual needs, the prompt text can also be in other languages. The noise intensity is controlled to 0.98, and the generated target image can be Figure 3A As shown in , the output of the model can be images from multiple different perspectives.

[0094] like Figure 3BAs shown, this is an image generated by using a white image as a guide during the experiment. This method can also achieve white background generation control, but the layout is prone to unreasonable problems, such as incomplete dishes contained in the image.

[0095] like Figure 3C As shown in the example of this specification, the Gaussian spot is located at the upper left side of the image. Under this guidance, the image output by the model is as follows Figure 3D As shown in , the model can generate a target image with matching position based on the upper left position of the Gaussian spot in the guide image, such as Figure 3D In the two target images shown in , the two bowls of noodles in the target images are both located on the upper left side, thus verifying the effectiveness of the solution of this embodiment.

[0096] As can be seen from the above embodiments, this embodiment proposes an image generation method based on the image generation process of the image generation model and a specific background color image combined with a guide image. This method can realize the generation of a specific background color image and control the generation layout, so that the image generation process can be separated from the seed image limitation, which greatly increases the diversity of the image generation results. For example, the generation of an accurate white background image can be achieved based on a white background image of Gaussian spots.

[0097] At present, the control efficiency of the image containing a specific background color in this embodiment is relatively high. In addition, high computing power is not required for model training. By guiding the position and size of the Gaussian spots in the image, the control of the generated subject can be achieved, ensuring the integrity of the subject and accurately controlling the layout position. It is better than the existing Controlnet method, retains the diversity of the raw image results, does not require seed image reliance, greatly reduces the cost of raw images, and improves the efficiency of raw images.

[0098] The method of this embodiment can be applied to a variety of scenarios, such as scenes such as dish images. In other examples, the acquisition of the prompt text may include:

[0099] In response to receiving dish description information of a dish to be configured by the merchant obtained from the store configuration page and sent by the merchant client, generating a prompt text including the dish description information;

[0100] The method may further comprise:

[0101] The target image generated by the image generation model is configured in the store configuration page.

[0102] In this embodiment, it can be applied to the scenario where merchants configure store merchandise. When merchants use the merchant client, the merchant client provides a store configuration page, which can include a configuration function for dishes. Users can enter the dish description information of the dishes to be configured. This embodiment can generate prompt text, and after obtaining the guide image, input the guide image and prompt text into the image generation model, obtain the target image generated by the image generation model and configure it in the store configuration page, so that merchants do not need to shoot and configure the dish images themselves.

[0103] like Figure 4 Shown is a schematic diagram of an image generation shown in this specification according to an exemplary embodiment. The image generation model of this embodiment can be deployed on a user-side device or a physical device deployed on the server side; this embodiment does not limit this. The user interface shows a text input box corresponding to "Please enter the name of the dish" for the user to enter the name of the dish. The figure takes the user entering "Sauerkraut Fish" as an example; a prompt text is generated based on the user's input. After the server performs the above processing, the guide image and prompt text are input into the image generation model. The image generation model can generate a target image based on the input data.

[0104] like Figure 5 FIG. 1 is a flowchart of another image generation method according to an exemplary embodiment of the present specification, and the method may include:

[0105] In step 502, the description information input by the user is obtained and sent to a server, and the server is used to execute the steps of the above-mentioned image generation method embodiment.

[0106] In step 504, the target image returned by the server is obtained and displayed.

[0107] The model involved in the image generation method of this embodiment can be deployed in the server, for example, Figure 1 In the server connected to the merchant's client, the merchant's client can receive the user's input and send it to the server, and the server runs the image generation method of this embodiment and sends the result to the client. In other examples, the model involved in the image generation method of this embodiment can also be deployed in the merchant's client, and this embodiment does not impose any limitation on this.

[0108] This embodiment can be applied to the client, and the client can also obtain the food image automatically generated by the server and configure it in the merchant's store, so that the merchant can reduce the configuration of product images in the store. The specific implementation process of this embodiment can refer to the above embodiment, and will not be repeated here.

[0109] Corresponding to the above-mentioned embodiments of the image generating method, this specification also provides embodiments of an image generating device and a terminal to which the device is applied.

[0110] The embodiments of the image generation device of this specification can be applied to computer devices, such as servers or terminal devices. The device embodiments can be implemented by software, hardware, or a combination of software and hardware. Taking software implementation as an example, as a device in a logical sense, it is formed by the processor of the file processing in which it is located reading the corresponding computer program instructions in the non-volatile memory into the memory and running them. From the hardware level, if Figure 6 The figure is a hardware structure diagram of the computer device where the image generating device of this manual is located, except Figure 6 In addition to the processor, memory, network interface, and non-volatile memory shown, the computer device where the image generating apparatus is located in the embodiment may also include other hardware, usually according to the actual function of the computer device, which will not be described in detail.

[0111] As an example, an image generating device may include:

[0112] The image acquisition module is used to: acquire a guide image, wherein the guide image includes: an image having a preset background color and containing a preset subject;

[0113] A text acquisition module, used to: acquire a prompt text, wherein the prompt text includes at least one target description information of a target object to be generated;

[0114] An image generation module is used to: input the guide image and the prompt text into an image generation model based on pre-training, so that the image generation model generates a target image based on the guide image and the prompt text, wherein the target image has the preset background color, contains a target object matching the target description information, and the position of the target object contained in the target image matches the position of the preset subject in the guide image.

[0115] In some examples, the preset subject included in the guide image includes: a subject having a preset shape, so that the overall shape of the target object in the target image matches the overall shape of the preset subject.

[0116] In some examples, the image generation model includes: a diffusion model; the color of the preset subject in the guide image gradually fades from the central area of ​​the subject toward the outside of the subject.

[0117] In some examples, the image generation model includes a noise-based diffusion model, which is trained by gradually adding noise that satisfies a preset probability distribution to image samples;

[0118] The preset subject included in the guide image includes: a spot generated by using a function corresponding to the preset probability distribution.

[0119] In some examples, the predetermined probability distribution includes a Gaussian distribution;

[0120] The guide image includes: an image with a preset background color and containing Gaussian spots.

[0121] In some examples, the guide image includes an image having a white background and containing black Gaussian spots.

[0122] In some examples, the preset subject is located in a middle area of ​​the guide image, so that the target object in the target image generated by the image generation model is located in the middle area of ​​the image.

[0123] In some examples, the step of inputting the guide image and the prompt text into a pre-trained image generation model so that the image generation model generates a target image based on the guide image and the prompt text includes:

[0124] The guide image, the prompt text and the preset number of noise adding steps are input into a pre-trained image generation model, so that the image generation model adds noise to the guide image according to the number of noise adding steps, and generates a target image based on the prompt text; wherein the preset number of noise adding steps is less than the number of steps in which the image generation model adds noise to image samples during the training process.

[0125] In some examples, the step of inputting the guide image and the prompt text into a pre-trained image generation model so that the image generation model generates a target image based on the guide image and the prompt text includes:

[0126] The guide image, the prompt text and the preset noise intensity are input into a pre-trained image generation model, so that the image generation model adds noise to the guide image according to the noise intensity and generates a target image based on the prompt text; wherein the preset noise intensity is lower than the intensity with which the image generation model adds noise to image samples during training.

[0127] In some examples, the prompt text includes one or more dish description information of the dish, the preset background color is white, and the target image includes: a dish image with a white background.

[0128] In some examples, obtaining the prompt text includes:

[0129] In response to receiving dish description information of a dish to be configured by the merchant obtained from the store configuration page and sent by the merchant client, generating a prompt text including the dish description information;

[0130] The method further comprises:

[0131] The target image generated by the image generation model is configured in the store configuration page.

[0132] As an example, an image generating device may include:

[0133] The acquisition module is used to: acquire the description information input by the user and send it to the server, and the server is used to execute the steps of the above-mentioned image generation method embodiment.

[0134] The display module is used to obtain and display the target image returned by the server.

[0135] The implementation process of the functions and effects of each module in the above-mentioned image generating device is specifically described in the implementation process of the corresponding steps in the above-mentioned image generating method, which will not be repeated here.

[0136] Accordingly, an embodiment of the present specification also provides a computer program product, including a computer program, which implements the steps of the aforementioned image generation method embodiment when executed by a processor.

[0137] Accordingly, an embodiment of the present specification also provides a computer device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the steps of the method embodiment when executing the program.

[0138] Accordingly, an embodiment of the present specification further provides a computer-readable storage medium on which a computer program is stored. When the computer program is executed by a processor, the steps of the embodiment of the image generating method are implemented.

[0139] For the device embodiment, since it basically corresponds to the method embodiment, the relevant parts can refer to the partial description of the method embodiment. The device embodiment described above is only schematic, wherein the modules described as separate components may or may not be physically separated, and the components displayed as modules may or may not be physical modules, that is, they may be located in one place, or they may be distributed on multiple network modules. Some or all of the modules may be selected according to actual needs to achieve the purpose of the scheme of this specification. A person of ordinary skill in the art can understand and implement it without paying creative labor.

[0140] The above embodiments can be applied to one or more computer devices, where the computer device is a device that can automatically perform numerical calculations and / or information processing according to pre-set or stored instructions. The hardware of the computer device includes but is not limited to a microprocessor, an application specific integrated circuit (ASIC), a field-programmable gate array (FPGA), a digital signal processor (DSP), an embedded device, etc.

[0141] The computer device may be any electronic product that can perform human-computer interaction with a user, such as a personal computer, a tablet computer, a smart phone, a personal digital assistant (PDA), a game console, an interactive network television (IPTV), a smart wearable device, etc.

[0142] The computer device may also include a network device and / or a user device, wherein the network device includes, but is not limited to, a single network server, a server group consisting of multiple network servers, or a cloud consisting of a large number of hosts or network servers based on cloud computing.

[0143] The network where the computer device is located includes but is not limited to the Internet, a wide area network, a metropolitan area network, a local area network, a virtual private network (VPN), etc.

[0144] The above is a description of a specific embodiment of the specification. Other embodiments are within the scope of the appended claims. In some cases, the actions or steps recorded in the claims can be performed in an order different from that in the embodiments and still achieve the desired results. In addition, the processes depicted in the drawings do not necessarily require the specific order or continuous order shown to achieve the desired results. In some embodiments, multitasking and parallel processing are also possible or may be advantageous.

[0145] The step division of the above methods is only for clear description. When implemented, they can be combined into one step or some steps can be split and decomposed into multiple steps. As long as they include the same logical relationship, they are all within the protection scope of this patent; adding insignificant modifications to the algorithm or process or introducing insignificant designs without changing the core design of the algorithm and process are all within the protection scope of this application.

[0146] Although this specification includes many specific implementation details, these should not be interpreted as limiting the scope of any invention or the scope of protection claimed, but are mainly used to describe the features of the specific embodiments of specific inventions. Certain features described in multiple embodiments in this specification may also be implemented in combination in a single embodiment. On the other hand, the various features described in a single embodiment may also be implemented separately in multiple embodiments or in any suitable sub-combination. In addition, although features may work in certain combinations as described above and even initially claim protection, one or more features from the claimed combination may be removed from the combination in some cases, and the claimed combination may point to a sub-combination or a variation of a sub-combination.

[0147] The description of "specific examples" or "some examples" means that the specific features, structures, materials or characteristics described in conjunction with the embodiment or example are included in at least one embodiment or example of this specification. In this specification, the schematic representation of the above terms does not necessarily refer to the same embodiment or example. Moreover, the specific features, structures, materials or characteristics described can be combined in any one or more embodiments or examples in a suitable manner.

[0148] Those skilled in the art will readily appreciate other embodiments of the specification after considering the specification and practicing the invention claimed herein. The specification is intended to cover any variations, uses or adaptations of the specification that follow the general principles of the specification and include common knowledge or customary techniques in the art that are not claimed in the specification. The specification and examples are to be considered exemplary only, and the true scope and spirit of the specification are indicated by the following claims.

[0149] It should be understood that the present description is not limited to the precise structures that have been described above and shown in the drawings, and that various modifications and changes may be made without departing from the scope thereof. The scope of the present description is limited only by the appended claims.

[0150] The above description is only a preferred embodiment of this specification and is not intended to limit this specification. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and principles of this specification should be included in the scope of protection of this specification.

Claims

1. A method for generating an image, the method comprising: Acquire a prompt text, wherein the prompt text includes at least one target description information of a target object to be generated; The preset guide image and the prompt text are input into a pre-trained image generation model, so that the image generation model adds noise to the guide image based on preset noise control parameters, obtains a non-full noise image that retains the image information of the guide image, and then generates a target image in combination with the prompt text; wherein, The training process of the image generation model includes: gradually adding noise that satisfies a preset probability distribution to image samples, and after obtaining a full-noise image, gradually removing noise from the full-noise image to generate an image; The guide image is obtained by generating a pure color image based on a preset color and then generating spots at a specified position of the pure color image based on a function corresponding to the preset probability distribution; The background color of the target image is the preset color, the target image includes a target object matching the target description information, and a position of the target object in the target image matches a position of the spot in the guide image.

2. The method according to claim 1, wherein the image generation model comprises: Diffusion model; The color of the spot in the guide image gradually fades from the central area of ​​the spot to the outer area of ​​the spot.

3. The method according to claim 2, wherein the preset probability distribution comprises a Gaussian distribution; The spots in the guide image include: Gaussian speckle.

4. The method according to claim 3, wherein the guiding image comprises: An image with a white background containing black Gaussian spots.

5. According to the method of claim 1, the spot is located in the middle area of ​​the guide image, so that the target object in the target image generated by the image generation model is located in the middle area of ​​the image.

6. The method according to claim 1, wherein the preset noise control parameters include: Preset number of noise adding steps; The preset number of noise adding steps is less than the number of steps of adding noise to image samples during the training process of the image generation model; and / or, The preset noise control parameters include: preset noise intensity; The preset noise intensity is lower than the intensity of noise added to image samples by the image generation model during training.

7. The method according to claim 1, wherein the prompt text includes one or more dish description information of the dish, the preset color is white, and the target image includes: Image of dish on white background.

8. The method according to claim 1, wherein obtaining the prompt text comprises: In response to receiving dish description information of a dish to be configured by the merchant obtained from the store configuration page and sent by the merchant client, generating a prompt text including the dish description information; The method further comprises: The target image generated by the image generation model is configured in the store configuration page.

9. A method for generating an image, the method comprising: Obtaining description information input by the user and sending it to a server, wherein the server is used to execute the steps of any method described in claims 1 to 8; Get the target image returned by the server and display it.

10. A computer device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein: When the processor executes the computer program, the steps of the method according to any one of claims 1 to 9 are implemented.

11. A computer-readable storage medium having a computer program stored thereon, wherein the computer program, when executed by a processor, implements the steps of any one of the methods of claims 1 to 9.

12. A computer program product, comprising a computer program, wherein when the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 9 are implemented.

Citation Information

Patent Citations

  • Image generation and diffusion model training method, electronic equipment and storage medium

    CN116450873A

  • Generation method and device of stylized image generation model, equipment and storage medium

    CN116740204A

  • Image generation method and device, electronic equipment and storage medium

    CN116797684A

  • Image generation method and device, electronic equipment, storage medium and program product

    CN117437317A

  • Image generation method and device, equipment and storage medium

    CN117710530A