Training method of image generation model, image generation method, device and equipment
By processing the initial sample image set and training the deep learning model, and using the masked sample image as a control condition for image generation, the problem of image splicing generated by the image extension method in the existing technology is unnatural and cannot be globally optimized, and improves Efficiency and accuracy of image generation.
Patent Information
- Application Number
- CN202410726029.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-06-05
- Publication Date
- 2024-08-30
AI Technical Summary
The images generated by existing image extension methods have problems such as unnatural splicing and inability to be globally optimized, resulting in poor accuracy and poor effect of the generated images.
By processing the initial sample image set, a first intermediate sample image set and a mask sample image are generated, and a deep learning model is used to train the image generation model, and the mask sample image is used as a control condition for image generation to achieve automated image extension. .
It improves the efficiency and accuracy of image generation, overcomes the problems of unnatural splicing and inability to be globally optimized, and ensures the naturalness and quality of the generated images.
Smart Images

Figure CN118570583A
Abstract
Description
Technical Field
[0001] The present disclosure relates to the fields of computer technology and image processing technology, and more specifically, to a training method for an image generation model, an image generation method and device, an electronic device, a computer-readable storage medium, and a computer program product. Background Art
[0002] With the development of computer technology, the demand for image extension is increasing day by day. Image extension can be understood as the generation task of image content completion, that is, by extending the edge or border of the original image, the original image can be better adapted to different display devices.
[0003] In the process of realizing the concept disclosed in the present invention, the inventors found that there are at least the following problems in the related art: since the generated image obtained by the current image extension method has the problem of unnatural splicing and cannot be globally optimized, it is impossible to effectively guarantee the accuracy and generation effect of the generated image. Summary of the invention
[0004] In view of this, the present disclosure provides a training method for an image generation model, an image generation method and device, an electronic device, a computer-readable storage medium, and a computer program product.
[0005] According to one aspect of the present disclosure, a method for training an image generation model is provided, comprising: processing an initial sample image set to obtain a first intermediate sample image set and a mask sample image, wherein each initial sample image in the initial sample image set corresponds to an actual generated image; processing the first intermediate sample image set according to the mask sample image to obtain a second intermediate sample image set, wherein the second intermediate sample image set includes a second intermediate sample image corresponding to each of the initial sample images; and training a deep learning model using the second intermediate sample image and the actual generated image of each of the initial sample images to obtain an image generation model.
[0006] According to an embodiment of the present disclosure, each of the above-mentioned initial sample images has a respective aspect ratio; the above-mentioned processing of the initial sample image set to obtain the first intermediate sample image set and the mask sample image includes: scaling each of the above-mentioned initial sample images according to the first preset value and the respective aspect ratio of each of the above-mentioned initial sample images to obtain the scaled sample image set; intercepting the above-mentioned scaled sample image set according to the above-mentioned first preset value to obtain the above-mentioned intercepted sample image set; randomly sampling the above-mentioned intercepted sample image set according to the second preset value to obtain the above-mentioned first intermediate sample image set; generating an initial mask sample image according to the above-mentioned first preset value; and randomly sampling the above-mentioned initial mask sample image according to the above-mentioned second preset value to obtain the above-mentioned mask sample image.
[0007] According to an embodiment of the present disclosure, the above-mentioned first intermediate sample image set includes a first intermediate sample image corresponding to each of the above-mentioned initial sample images; the above-mentioned processing of the above-mentioned first intermediate sample images according to the above-mentioned mask sample images to obtain the second intermediate sample image includes: performing format conversion processing on the above-mentioned first intermediate sample image and the above-mentioned mask sample image to obtain first intermediate sample image data and mask sample image data; using the above-mentioned mask sample image data as a control condition, processing the above-mentioned first intermediate sample image data to obtain a third intermediate sample image; and, generating the above-mentioned second intermediate sample image according to the above-mentioned initial sample image and the above-mentioned third intermediate sample image.
[0008] According to an embodiment of the present disclosure, the above-mentioned first intermediate sample image data is processed with the above-mentioned mask sample image data as a control condition to obtain the third intermediate sample image, including: performing feature extraction processing on the above-mentioned mask sample image data and the above-mentioned first intermediate sample image data respectively to obtain a mask sample feature map and a first intermediate sample feature map; performing feature fusion processing on the above-mentioned mask sample feature map and the above-mentioned first intermediate sample feature map to obtain a fused sample feature map; and, generating the above-mentioned third intermediate sample image according to the above-mentioned fused sample feature map.
[0009] According to an embodiment of the present disclosure, the above-mentioned use of the second intermediate sample image and the actual generated image of each of the above-mentioned initial sample images to train the deep learning model to obtain the image generation model includes: based on a preset loss function, obtaining a loss function value according to the second intermediate sample image and the actual generated image of each of the above-mentioned initial sample images; adjusting the model parameters of the above-mentioned deep learning model according to the above-mentioned loss function value until a predetermined end condition is met; and determining the deep learning model obtained when the above-mentioned predetermined end condition is met as the above-mentioned image generation model.
[0010] According to an embodiment of the present disclosure, the above-mentioned preset loss function includes a first sub-loss function and a second sub-loss function, the above-mentioned first sub-loss function is determined according to the image generation type, and the above-mentioned second sub-loss function is determined according to the generation loss function and the perceptual loss function; the above-mentioned loss function value is obtained based on the preset loss function according to the second intermediate sample image and the actual generated image of each of the above-mentioned initial sample images, including: for each of the above-mentioned initial sample images, based on the above-mentioned first sub-loss function and the above-mentioned second sub-loss function, according to the above-mentioned second intermediate sample image and the above-mentioned actual generated image, the first sub-loss function value and the second sub-loss function value are determined; according to the above-mentioned first sub-loss function value and the above-mentioned second sub-loss function value, the sub-loss function cumulative value is determined; and, according to the sub-loss function cumulative value of each of the above-mentioned initial sample images, the above-mentioned loss function value is determined.
[0011] According to an embodiment of the present disclosure, the above-mentioned method also includes repeatedly performing the following operations until the performance test result of the above-mentioned image generation model meets the predetermined performance condition: using the verification sample image set to test the model performance of the above-mentioned image generation model to obtain the above-mentioned performance test result, wherein the above-mentioned verification sample image set includes at least one verification sample image and a second intermediate verification sample image and an actual verification generated image corresponding to each of the above-mentioned verification sample images; in the case of determining that the above-mentioned performance test result does not meet the above-mentioned predetermined performance condition, adjusting the model hyperparameters corresponding to the above-mentioned image generation model; and, based on the adjusted model hyperparameters, retraining the above-mentioned deep learning model using the second intermediate verification sample image and the actual generated image of each of the above-mentioned initial sample images to obtain a new image generation model.
[0012] According to another aspect of the present disclosure, an image generation method is provided, including: obtaining an initial image and extended canvas information; processing the initial image according to the extended canvas information to obtain a first intermediate image and a mask image; inputting the first intermediate image and the mask image into an image generation model, and outputting a target generated image; wherein the image generation model is trained using an image generation model training method.
[0013] According to an embodiment of the present disclosure, the extended canvas information includes canvas size information, image position information and image scaling information; the processing of the initial image according to the extended canvas information to obtain the first intermediate image and the mask image includes: creating a target canvas and a first intermediate mask image according to the canvas size information; scaling the initial image according to the image scaling information to obtain the first processed image; pasting the first processed image to the target canvas according to the image position information to obtain the first intermediate image; performing pixel changes on the first intermediate mask image according to the image position information and the image scaling information to obtain the second intermediate mask image; and performing pixel inversion on the second intermediate mask image to obtain the mask image.
[0014] According to another aspect of the present disclosure, a training device for an image generation model is provided, comprising: a first processing module, used to process an initial sample image set to obtain a first intermediate sample image set and a mask sample image, wherein each initial sample image in the initial sample image set corresponds to an actual generated image; a second processing module, used to process the first intermediate sample image set according to the mask sample image to obtain a second intermediate sample image set, wherein the second intermediate sample image set includes a second intermediate sample image corresponding to each of the initial sample images; and a first training module, used to train a deep learning model using the second intermediate sample image and the actual generated image of each of the initial sample images to obtain an image generation model.
[0015] According to another aspect of the present disclosure, an image generating device is provided, including: an acquisition module for acquiring an initial image and extended canvas information; a third processing module for processing the initial image according to the extended canvas information to obtain a first intermediate image and a mask image; an input module for inputting the first intermediate image and the mask image into an image generating model, and outputting a target generated image; wherein the image generating model is trained using an image generating model training device.
[0016] According to another aspect of the present disclosure, an electronic device is provided, comprising: one or more processors; and a memory for storing one or more instructions, wherein when the one or more instructions are executed by the one or more processors, the one or more processors implement the method described in the present disclosure.
[0017] According to another aspect of the present disclosure, a computer-readable storage medium is provided, on which executable instructions are stored. When the executable instructions are executed by a processor, the processor implements the method described in the present disclosure.
[0018] According to another aspect of the present disclosure, a computer program product is provided. The computer program product includes computer executable instructions. When the computer executable instructions are executed, they are used to implement the method described in the present disclosure.
[0019] According to an embodiment of the present disclosure, a deep learning model is trained by processing an initial sample image set to obtain a second intermediate sample image set and an actual generated image, so that the obtained image generation model can use the mask sample image as a control condition to guide the automatic image generation of the initial sample image, and automatically achieve image extension of the initial sample image, thereby at least partially overcoming the technical problems that the generated images obtained by the current image extension method in the related art have unnatural splicing and cannot be globally optimized, which helps to subsequently control the image content of the generated image based on the mask image, thereby improving the efficiency and accuracy of image generation. BRIEF DESCRIPTION OF THE DRAWINGS
[0020] The above and other objects, features and advantages of the present disclosure will become more apparent through the following description of the embodiments of the present disclosure with reference to the accompanying drawings, in which:
[0021] Figure 1 The system architecture to which the image generation method and the training method of the image generation model according to the embodiments of the present disclosure can be applied is schematically shown;
[0022] Figure 2 A flowchart schematically illustrates a method for training an image generation model according to an embodiment of the present disclosure;
[0023] Figure 3 An example schematic diagram schematically shows a process of obtaining a second intermediate sample image according to an embodiment of the present disclosure;
[0024] Figure 4 An example schematic diagram schematically illustrates a training process of an image generation model according to an embodiment of the present disclosure;
[0025] Figure 5 The flowchart of the image generation method according to the embodiment of the present disclosure is schematically shown;
[0026] Figure 6 An example schematic diagram schematically shows a process of processing an initial image according to extended canvas information to obtain a first intermediate image and a mask image according to an embodiment of the present disclosure;
[0027] Figure 7 An example schematic diagram schematically shows an initial image and a target generated image according to an embodiment of the present disclosure;
[0028] Figure 8 A block diagram schematically shows a training device for an image generation model according to an embodiment of the present disclosure;
[0029] Fig. 9 A block diagram schematically shows an image generating device according to an embodiment of the present disclosure; and
[0030] Fig.10 A block diagram of an electronic device suitable for implementing an image generation method and a training method for an image generation model according to an embodiment of the present disclosure is schematically shown. DETAILED DESCRIPTION
[0031] Hereinafter, embodiments of the present disclosure will be described with reference to the accompanying drawings. However, it should be understood that these descriptions are exemplary only and are not intended to limit the scope of the present disclosure. In the following detailed description, for ease of explanation, many specific details are set forth to provide a comprehensive understanding of the embodiments of the present disclosure. However, it is apparent that one or more embodiments may also be implemented without these specific details. In addition, in the following description, descriptions of known structures and technologies are omitted to avoid unnecessary confusion of the concepts of the present disclosure.
[0032] The terms used herein are only for describing specific embodiments and are not intended to limit the present disclosure. The terms "comprise", "include", etc. used herein indicate the existence of the features, steps, operations and / or components, but do not exclude the existence or addition of one or more other features, steps, operations or components.
[0033] All terms (including technical and scientific terms) used herein have the meanings commonly understood by those skilled in the art, unless otherwise defined. It should be noted that the terms used herein should be interpreted as having a meaning consistent with the context of this specification, and should not be interpreted in an idealized or overly rigid manner.
[0034] When using expressions such as "at least one of A, B, and C, etc.", they should generally be interpreted according to the meaning of the expression commonly understood by those skilled in the art (for example, "a system having at least one of A, B, and C" should include but is not limited to a system having A alone, B alone, C alone, A and B, A and C, B and C, and / or A, B, C, etc.).
[0035] In the embodiments of the present disclosure, the collection, updating, analysis, processing, use, transmission, provision, disclosure, storage, etc. of the data involved (for example, including but not limited to user personal information) are in compliance with the provisions of relevant laws and regulations, are used for legitimate purposes, and do not violate public order and good morals. In particular, necessary measures are taken for user personal information to prevent illegal access to user personal information data and maintain the security of user personal information and network security.
[0036] In the embodiments of the present disclosure, the user's authorization or consent is obtained before obtaining or collecting the user's personal information.
[0037] For example, after collecting the initial images and / or initial sample images, your information may be desensitized using methods including de-identification or anonymization to protect the security of your information.
[0038] In one example, the original image may be processed by a preset generative model to obtain an extended generated image. The preset generative model may include at least one of the following: a variational autoencoder, a denoising diffusion probability model, and a generative adversarial model.
[0039] However, the method of generating extended generated images based on variational autoencoders has poor quality, rough details, and distortion. The method of generating extended generated images based on denoising diffusion probability models needs to rely on manual determination of text descriptions, and the reconstruction accuracy of image generation is not high enough. There is a significant color difference with the original image, resulting in obvious seams between the generated image and the original image. The method of generating extended generated images based on generative adversarial models has limited model capacity. Usually, a model can only cover the extension of one type of items, and the generated images are relatively simple and lack diversity.
[0040] In another example, the above-mentioned preset generation models can be combined to obtain a combined model, and the combined model can be used to generate the extended generated image. However, different models are independent of each other, and global optimization training for the combined model cannot be performed.
[0041] In summary, the image extension methods in the related art have problems such as unnatural splicing and inability to optimize globally, which results in the inability to effectively guarantee the accuracy and generation effect of the generated image after extension.
[0042] In order to at least partially solve the technical problems existing in the related art, the present disclosure provides a training method, an image generation method, a device and an apparatus for an image generation model, which can be applied to the fields of computer technology and image processing technology. The training method of the image generation model includes: processing an initial sample image set to obtain a first intermediate sample image set and a mask sample image, wherein each initial sample image in the initial sample image set corresponds to an actual generated image; processing the first intermediate sample image set according to the mask sample image to obtain a second intermediate sample image set, wherein the second intermediate sample image set includes a second intermediate sample image corresponding to each initial sample image; and using the second intermediate sample image and the actual generated image of each initial sample image, training a deep learning model to obtain an image generation model.
[0043] Figure 1The system architecture to which the image generation method and the training method of the image generation model according to the embodiment of the present disclosure can be applied is schematically shown. It should be noted that: Figure 1 What is shown is merely an example of a system architecture to which the embodiments of the present disclosure can be applied, in order to help those skilled in the art understand the technical content of the present disclosure, but it does not mean that the embodiments of the present disclosure cannot be used in other devices, systems, environments or scenarios.
[0044] like Figure 1 As shown, the system architecture 100 according to this embodiment may include a first terminal device 101, a second terminal device 102, a third terminal device 103, a network 104 and a server 105. The network 104 is used to provide a medium for a communication link between the first terminal device 101, the second terminal device 102, the third terminal device 103 and the server 105. The network 104 may include various connection types, such as wired, wireless communication links or optical fiber cables, etc.
[0045] The user may use at least one of the first terminal device 101, the second terminal device 102, and the third terminal device 103 to interact with the server 105 through the network 104 to receive or send messages, etc. Various communication client applications may be installed on the first terminal device 101, the second terminal device 102, and the third terminal device 103, such as shopping applications, web browser applications, search applications, instant messaging tools, email clients, social platform software, etc. (only as examples).
[0046] The first terminal device 101, the second terminal device 102, and the third terminal device 103 may be various electronic devices having display screens and supporting web browsing, including but not limited to smart phones, tablet computers, laptop computers, desktop computers, and the like.
[0047] The server 105 may be a server that provides various services, such as a background management server (only as an example) that provides support for websites browsed by users using the first terminal device 101, the second terminal device 102, and the third terminal device 103. The background management server may analyze and process the received data such as user requests, and feed back the processing results (such as web pages, information, or data obtained or generated according to user requests) to the terminal device.
[0048] It should be noted that the image generation method and the training method of the image generation model provided in the embodiment of the present disclosure can generally be executed by the server 105. Accordingly, the image generation device and the training device of the image generation model provided in the embodiment of the present disclosure can generally be set in the server 105. The image generation method and the training method of the image generation model provided in the embodiment of the present disclosure can also be executed by a server or server cluster that is different from the server 105 and can communicate with the first terminal device 101, the second terminal device 102, the third terminal device 103 and / or the server 105. Accordingly, the image generation device and the training device of the image generation model provided in the embodiment of the present disclosure can also be set in a server or server cluster that is different from the server 105 and can communicate with the first terminal device 101, the second terminal device 102, the third terminal device 103 and / or the server 105.
[0049] Alternatively, the image generation method and the image generation model training method provided in the embodiments of the present disclosure may also be executed by the first terminal device 101, the second terminal device 102 or the third terminal device 103, or may also be executed by other terminal devices different from the first terminal device 101, the second terminal device 102 or the third terminal device 103. Accordingly, the image generation device and the image generation model training device provided in the embodiments of the present disclosure may also be set in the first terminal device 101, the second terminal device 102 or the third terminal device 103, or may be set in other terminal devices different from the first terminal device 101, the second terminal device 102 or the third terminal device 103.
[0050] It should be understood that Figure 1 The number of terminal devices, networks and servers in the embodiment is only for illustration. Any number of terminal devices, networks and servers may be provided according to the implementation requirements.
[0051] It should be noted that the sequence numbers of the operations in the following method are only used as representations of the operations for the purpose of description, and should not be regarded as representing the execution order of the operations. Unless explicitly stated, the method does not need to be executed completely in the order shown.
[0052] Figure 2 A flowchart of a method for training an image generation model according to an embodiment of the present disclosure is schematically shown.
[0053] like Figure 2 As shown, the training method 200 of the image generation model includes operations S210 to S230.
[0054] In operation S210, the initial sample image set is processed to obtain a first intermediate sample image set and a mask sample image, wherein each initial sample image in the initial sample image set corresponds to an actually generated image.
[0055] In operation S220, the first intermediate sample image set is processed according to the mask sample image to obtain a second intermediate sample image set, wherein the second intermediate sample image set includes a second intermediate sample image corresponding to each initial sample image.
[0056] In operation S230, a deep learning model is trained using the second intermediate sample image and the actually generated image of each initial sample image to obtain an image generation model.
[0057] According to an embodiment of the present disclosure, before training the image generation model, an initial sample image set may be obtained. The initial sample image set may be a public data set or a private data set, such as laion-aesthetics / places-512, etc. In one example, the image to be generated may have an image generation type, and as many initial sample images corresponding to the image generation type as possible may be collected, and mixed with a large-scale public data set for training, thereby enhancing the generalization ability of the image generation model.
[0058] According to an embodiment of the present disclosure, the initial sample image set may include multiple initial sample images, and the image type of the initial sample image may be configured according to actual business needs, which is not limited here. For example, the image type may include at least one of the following: JPG (Joint Photographic Experts Group), TIFF (Tag Image File Format), PNG (Portable Network Graphics), PDF (Portable Document Format), GIF (Graphics Interchange Format), etc.
[0059] According to an embodiment of the present disclosure, each initial sample image may correspond to an actual generated image. The actual generated image may be used to characterize the extended image obtained after the initial sample image is processed by the image generation operation. For each initial sample image, the initial sample image may be processed to obtain a first intermediate sample image. In addition, a mask sample image may be generated according to the size of the initial sample image.
[0060] According to an embodiment of the present disclosure, the first intermediate sample image set may include first intermediate sample images corresponding to each of the multiple initial sample images. For each first intermediate sample image, the first intermediate sample image may be processed according to the mask sample image to obtain a second intermediate sample image. After obtaining the second intermediate sample image, a deep learning model may be trained based on a preset loss function according to the second intermediate sample image of each initial sample image and the actual generated image to obtain an image generation model.
[0061] The deep learning model can be configured according to actual business needs and is not limited here. For example, the deep learning model may include at least one of the following: Diffusion Model (DM), Denoising Diffusion Probabilistic Models (DDPMs), Score-based Generative Models (SGMs), Stochastic Differential Equations (Score SDEs) and Conditional Control Diffusion Model (i.e., ControlNet).
[0062] According to an embodiment of the present disclosure, a deep learning model is trained by processing an initial sample image set to obtain a second intermediate sample image set and an actual generated image, so that the obtained image generation model can use the mask sample image as a control condition to guide the automatic image generation of the initial sample image, and automatically achieve image extension of the initial image, thereby at least partially overcoming the technical problems that the generated images obtained by the current image extension method in the related art have unnatural splicing and cannot be globally optimized, which helps to subsequently control the image content of the generated image based on the mask image, thereby improving the efficiency and accuracy of image generation.
[0063] Reference below Figure 3 and Figure 4 , the training method 200 of the image generation model according to an embodiment of the present invention is further explained.
[0064] According to an embodiment of the present disclosure, operation S210 may include the following operations.
[0065] According to the first preset value and the aspect ratio of each initial sample image, each initial sample image is scaled to obtain a scaled sample image set. According to the first preset value, the scaled sample image set is intercepted to obtain a intercepted sample image set. According to the second preset value, the intercepted sample image set is randomly sampled to obtain a first intermediate sample image set. According to the first preset value, an initial mask sample image is generated. According to the second preset value, the initial mask sample image is randomly sampled to obtain a mask sample image.
[0066] According to an embodiment of the present disclosure, each initial sample image may have a respective aspect ratio.
[0067] According to an embodiment of the present disclosure, for each initial sample image, the initial sample image can be scaled according to the first preset value and the aspect ratio of the initial sample image, that is, the image scaling is performed while maintaining the aspect ratio of the initial sample image to obtain a scaled sample image. For example, the first preset value can be 512, so that the short side of the initial sample image is 512.
[0068] According to an embodiment of the present disclosure, for each scaled sample image, the scaled sample image set can be cropped according to a first preset value, that is, the long side of the initial sample image is randomly cropped to obtain a cropped sample image, thereby making the long side of the scaled sample image 512, that is, the long side and the short side of the cropped sample image are both 512, and the 512*512 cropped sample image can be marked as the extended true value image.
[0069] According to an embodiment of the present disclosure, an initial mask sample image can be generated according to a first preset value, that is, an initial mask sample image of size 512*512 with all pixel values of 255 is initialized. According to a second preset value, the initial mask sample image is randomly sampled so as to randomly sample a rectangular area on the initial mask sample image, and the rectangular area can be understood as a non-extended area. For example, the second preset value can be 64, and the initial mask sample image is randomly sampled based on the short side of the rectangular area being 64. In addition, it can also be required that the area of the rectangular area is greater than or equal to 128*128. In this case, according to setting the pixel values in the rectangular area on the initial mask sample image to 0, a mask sample image for guiding the image generation task is obtained.
[0070] According to an embodiment of the present disclosure, for each intercepted sample image, the same random sampling process can be performed on the intercepted sample image according to the above-mentioned random sampling process to obtain a first intermediate sample image, and the first intermediate sample image can be used as a canvas image.
[0071] According to an embodiment of the present disclosure, after obtaining the first intermediate sample image set and the mask sample image, the text descriptions of the above-mentioned images can be processed uniformly. For example, the text descriptions of the above-mentioned images can be uniformly described as "a photograph of a beautiful empty scene, highest quality settings".
[0072] According to the embodiments of the present disclosure, since the first intermediate sample image is obtained by scaling, cropping and randomly sampling the initial sample image, and the mask sample image is obtained by randomly sampling the initial mask sample image, it is possible to obtain a conditional control image for guiding the training of an image generation model for an image generation task, and the generation of the conditional control image is made as comprehensive as possible, which is conducive to improving the training effect of subsequent image generation models.
[0073] According to an embodiment of the present disclosure, operation S220 may include the following operations.
[0074] For each first intermediate sample image, the first intermediate sample image and the mask sample image are format converted to obtain first intermediate sample image data and mask sample image data. The mask sample image data is used as a control condition to process the first intermediate sample image data to obtain a third intermediate sample image. A second intermediate sample image is generated based on the initial sample image and the third intermediate sample image.
[0075] According to an embodiment of the present disclosure, a model inference tool may be used to call an image extension pipeline to load a Stablediffusion 1.5 native model and a preset deep learning model, and the first intermediate sample image and the mask sample image may be input into the native model and the preset deep learning model to obtain a second intermediate sample image. For example, the model inference tool may refer to diffusers.
[0076] According to an embodiment of the present disclosure, before the first intermediate sample image and the mask sample image are input into a preset deep learning model, the first intermediate sample image and the mask sample image may be format converted to obtain an image input format dedicated to the preset deep learning model, namely, the first intermediate sample image data and the mask sample image data. For example, the first intermediate sample image data and the mask sample image data may be floating point numbers, the data value of the mask sample image data may be [0, 1], and the data value of the outer extension area in the first intermediate sample image data is fixed to -1.
[0077] According to an embodiment of the present disclosure, taking the preset deep learning model as a conditional controlled diffusion model as an example, various calling parameters of the pipeline can be preset. For example, the text prompt (i.e., prompt) can be set to a preset field, the denoising intensity can be set to a third preset value, the influence of the text prompt on the image generation process (i.e., guidance_scale) can be set to a fourth preset value, and the weight of the conditional controlled diffusion model can be set to a fifth preset value. On this basis, the first intermediate sample image can be used as a guide image, the mask sample image can be used as a conditional control image, and the pipeline can be called to generate an extended third intermediate sample image.
[0078] According to an embodiment of the present disclosure, the preset field, the third preset value, the fourth preset value, and the fifth preset value can be configured according to actual business needs and are not limited here. For example, the preset field can be "photograph of a beautiful empty scene, highest quality settings", the third preset value can be 0.8, the fourth preset value can be d7.0, and the fifth preset value can be 1.
[0079] According to an embodiment of the present disclosure, after obtaining the extended third intermediate sample image, a second intermediate sample image can be generated according to the initial sample image and the third intermediate sample image. For example, the initial image can be pasted to the third intermediate sample image, i.e., extend.paste(image, (x, y)), thereby keeping the image of the non-extended area unchanged.
[0080] According to the embodiments of the present disclosure, by performing format conversion processing on the first intermediate sample image and the mask sample image, the image can be converted into the first intermediate sample image data and the mask sample image data that meet the data format required by the model. On this basis, by using the mask sample image data as a control condition, the first intermediate sample image is optimized and adjusted to obtain a third intermediate sample image, and the initial sample image and the third intermediate sample image are subjected to image processing and synthesis operations to obtain a second intermediate sample image, which is helpful to further optimize and integrate the image features and effects, thereby obtaining a second intermediate sample image that meets the requirements, and is conducive to improving the accuracy of the target generated image obtained subsequently.
[0081] According to an embodiment of the present disclosure, using the mask sample image data as a control condition, processing the first intermediate sample image data to obtain the third intermediate sample image may include the following operations.
[0082] The masked sample image data and the first intermediate sample image data are subjected to feature extraction processing respectively to obtain a masked sample feature map and a first intermediate sample feature map. The masked sample feature map and the first intermediate sample feature map are subjected to feature fusion processing to obtain a fused sample feature map. A third intermediate sample image is generated according to the fused sample feature map.
[0083] According to an embodiment of the present disclosure, the model structure of the deep learning model can be configured according to actual business needs, which is not limited here. For example, the deep learning model may include at least one model structure. The model structure may include at least one model substructure and the connection relationship between each model substructure. The model structure may be a structure obtained by connecting at least one model substructure based on the connection relationship between the model substructures. At least one model substructure included in the model structure may be a structure from at least one operation layer.
[0084] For example, the model structure may be a structure obtained by connecting at least one model substructure from at least one operation layer based on the connection relationship between the model substructures. For example, at least one operation layer may include at least one of the following: input layer, convolution layer, hidden layer, transcription layer, pooling layer, depooling layer, deconvolution layer, feedforward neural network layer, attention layer, residual layer, fully connected layer, batch normalization layer, linear embedding layer, and nonlinear layer.
[0085] In one example, the deep learning model may include an encoding-decoding network and a conditional control network. For example, the encoding-decoding network may include a first encoding subnetwork, a first intermediate subnetwork, and a first decoding subnetwork, and the conditional control network may include a second encoding subnetwork with the same number of layers as the first encoding subnetwork, a second intermediate subnetwork with the same number of layers as the first intermediate subnetwork, and a zero convolution network.
[0086] According to an embodiment of the present disclosure, the first encoding subnetwork may include a first input layer and a first hidden layer. The first encoding subnetwork may be used to encode the masked sample image data and the first intermediate sample image data. For example, the masked sample image data and the first intermediate sample image data may be encoded using the first input layer of the first encoding subnetwork to obtain masked sample image encoded data and first intermediate sample image encoded data. The masked sample image encoded data and the first intermediate sample image encoded data may be processed using the first hidden layer of the first encoding subnetwork to obtain masked sample image encoded vectors and first intermediate sample image encoded vectors.
[0087] According to an embodiment of the present disclosure, the first decoding subnetwork may include a second hidden layer and a first output layer. The first decoding subnetwork may be used to reconstruct the mask sample image coding vector and the first intermediate sample image coding vector. For example, the mask sample image coding vector and the first intermediate sample image coding vector may be decoded by the second hidden layer of the first decoding subnetwork, respectively, to obtain the mask sample image auxiliary decoding data and the first intermediate sample image auxiliary decoding data. The mask sample image auxiliary decoding data and the first intermediate sample image auxiliary decoding data are processed by the first output layer of the first decoding subnetwork, respectively, to obtain the mask sample feature map and the first intermediate sample feature map.
[0088] According to an embodiment of the present disclosure, after obtaining the mask sample feature map and the first intermediate sample feature map, the second encoding sub-network, the second intermediate sub-network and the zero convolution network can be used to perform feature fusion processing on the mask sample feature map and the first intermediate sample feature map to obtain a fused sample feature map. On this basis, the extended third intermediate sample image can be further obtained according to the fused sample feature map.
[0089] According to the embodiments of the present disclosure, since the mask sample feature map and the first intermediate sample feature map are obtained by performing feature extraction processing on the mask sample image data and the first intermediate sample image data respectively, key feature information in the image can be extracted. By performing feature fusion processing on the mask sample feature map and the first intermediate sample feature map, a fused feature map with better image feature expression ability can be obtained, which realizes in-depth mining and optimization of image feature information, is conducive to generating a third intermediate sample image with better image feature expression, and thus can improve the generation effect of the target generated image.
[0090] Figure 3 An example schematic diagram of a second intermediate sample image obtaining process according to an embodiment of the present disclosure is schematically shown.
[0091] like Figure 3 As shown in 300 , after obtaining the initial sample images 302 , since each initial sample image 302 has a width-to-height ratio 301 , the initial sample images 302 can be processed according to the width-to-height ratio 301 to obtain a first intermediate sample image 303 and a mask sample image 304 .
[0092] For the first intermediate sample image 303, the first intermediate sample image 303 may be subjected to format conversion processing to obtain first intermediate sample image data 305. The first intermediate sample image data 305 may be subjected to feature extraction processing to obtain a first intermediate sample feature map 306. For the mask sample image 304, the mask sample image 304 may be subjected to format conversion processing to obtain mask sample image data 307. The mask sample image data 307 may be subjected to feature extraction processing to obtain a mask sample feature map 308.
[0093] After obtaining the first intermediate sample feature map 306 and the mask sample feature map 308, feature fusion processing can be performed on the mask sample feature map 308 and the first intermediate sample feature map 306 to obtain a fused sample feature map 309. According to the fused sample feature map 309, a third intermediate sample image 310 is generated. On this basis, a second intermediate sample image 311 can be generated according to the initial sample image 302 and the third intermediate sample image 310.
[0094] According to an embodiment of the present disclosure, operation S230 may include the following operations.
[0095] Based on the preset loss function, a loss function value is obtained according to the second intermediate sample image and the actual generated image of each initial sample image. The model parameters of the deep learning model are adjusted according to the loss function value until a predetermined end condition is met. The deep learning model obtained when the predetermined end condition is met is determined as the image generation model.
[0096] According to an embodiment of the present disclosure, after obtaining the second intermediate sample image set, a loss function value can be obtained based on the second intermediate sample image and the actual generated image of each initial sample image based on a preset loss function. The preset loss function can be configured according to actual business needs and is not limited here.
[0097] For example, the loss function value can be obtained based on a preset loss function using the second intermediate sample image and the actual generated image of each initial sample image. The model parameters of the deep learning model can be adjusted according to the loss function value until the predetermined conditions are met. For example, the model parameters of the deep learning model can be adjusted according to the back propagation algorithm or the stochastic gradient descent algorithm until the predetermined conditions are met. The deep learning model obtained when the predetermined conditions are met is determined as the image generation model. The predetermined conditions may include at least one of the convergence of the loss function value and the maximum number of training rounds.
[0098] According to an embodiment of the present disclosure, since the loss function value is obtained based on the second intermediate sample image and the actual generated image of each initial sample image, the image generation model is obtained by training the deep learning model using the loss function value, and the image generation model can be used to process the initial image to obtain the target generated image, thereby improving the efficiency and accuracy of obtaining the target generated image.
[0099] According to an embodiment of the present disclosure, based on a preset loss function, obtaining a loss function value according to the second intermediate sample image and the actually generated image of each initial sample image may include the following operations.
[0100] For each initial sample image, based on the first sub-loss function and the second sub-loss function, the first sub-loss function value and the second sub-loss function value are determined according to the second intermediate sample image and the actual generated image. The sub-loss function cumulative value is determined according to the first sub-loss function value and the second sub-loss function value. The loss function value is determined according to the respective sub-loss function cumulative values of each initial sample image.
[0101] According to an embodiment of the present disclosure, the preset loss function may include a first sub-loss function and a second sub-loss function. The first sub-loss function may be determined according to the image generation type, for example, the first loss sub-function may include a stable diffusion loss function (Stable Diffusion Loss) and a conditional control loss function (i.e., ControlNet Loss). The second sub-loss function (i.e., Natural Loss) may be determined according to a generation loss function (i.e., Reconstruction Loss) and a perceptual loss function (i.e., Perceptual Loss).
[0102] According to an embodiment of the present disclosure, the second sub-loss function can be used to optimize the effect of the image generation task, that is, to quantify the naturalness of the splicing of the initial sample image and the second intermediate sample image, so as to optimize the constraint model to generate a more realistic and natural second intermediate sample image. The generation loss function can be used to constrain the 8 pixel width / height critical area at the boundary of the extended second intermediate sample image to be completely consistent with the image at the corresponding position on the actual generated image, and its purpose is to make the transition between the extended area and the non-extended area image smoother and more natural. The perceptual loss function can be used to constrain the regional image of the generated extended second intermediate sample image to have similar visual features to the image at the corresponding position of the actual generated image, that is, to make the extended second intermediate sample image and the actual generated image sufficiently similar.
[0103] According to an embodiment of the present disclosure, after obtaining the second intermediate sample image, the first sub-loss function value can be obtained based on the first loss sub-function, using the second intermediate sample image and the actual generated image. The second sub-loss function value can be obtained based on the second loss sub-function, using the second intermediate sample image and the actual generated image. On this basis, the loss function value can be determined according to the first sub-loss function value and the second sub-loss function value of each initial sample image, and the deep learning model can be trained using the loss function value to obtain an image generation model.
[0104] According to an embodiment of the present disclosure, by using a first sub-loss function and a second sub-loss function, and calculating the accumulated values of the sub-loss functions, the loss function value for each initial sample image is determined, and the weights and interactions of different sub-loss functions are fully considered, providing a more comprehensive loss function value, thereby helping to optimize the training and performance of the image generation model.
[0105] Figure 4 An example schematic diagram of the training process of the image generation model according to an embodiment of the present disclosure is schematically shown.
[0106] like Figure 4 As shown, in 400, the initial sample image set 401 can be processed to obtain a first intermediate sample image set 403 and a mask sample image 404. Each initial sample image in the initial sample image set 401 corresponds to an actual generated image 402. The first intermediate sample image set 403 and the mask sample image 404 can be input into a deep learning model 405 to obtain a second intermediate sample image set 406. The second intermediate sample image set 406 includes a second intermediate sample image corresponding to each initial sample image.
[0107] The preset loss function may include a first sub-loss function 4071 and a second sub-loss function 4072. For each initial sample image, based on the first sub-loss function 4071 and the second sub-loss function 4072, according to the second intermediate sample image set 406 and the actual generated image 402 corresponding to each initial sample image, the first sub-loss function value and the second sub-loss function value may be determined, and the loss function value 408 may be further determined.
[0108] The model parameters of the deep learning model 405 are adjusted according to the loss function value 408 until a predetermined end condition is met, and the deep learning model 405 obtained when the predetermined end condition is met is determined as the image generation model.
[0109] In the embodiments of the present disclosure, after completing all the processes in the training phase, a trained image generation model (i.e., outpaint ControlNet) can be obtained. The image generation model can be understood as an improved method based on the StableDiffusion and ControlNet frameworks. Through an end-to-end joint training method, it can solve the problem of difficult global optimization of image outpaint generation and achieve the goal of global optimization of the generation effect. The above end-to-end image generation model can be used for inference calculations in subsequent application processes to achieve the generation and processing of outpainted images.
[0110] According to an embodiment of the present disclosure, the training method 200 of the image generation model may further include repeatedly performing the following operations until the performance test result of the image generation model meets a predetermined performance condition.
[0111] The model performance of the image generation model is tested using a validation sample image set to obtain a performance test result, wherein the validation sample image set includes at least one validation sample image and a second intermediate validation sample image and an actual validation generated image corresponding to each validation sample image. When it is determined that the performance test result does not meet a predetermined performance condition, the model hyperparameter corresponding to the image generation model is adjusted. Based on the adjusted model hyperparameters, the deep learning model is retrained using the second intermediate validation sample image and the actual generated image of each initial sample image to obtain a new image generation model.
[0112] According to an embodiment of the present disclosure, the model hyperparameters may include at least one of the following: resolution (i.e., resolution), learning rate (i.e., learning_rate), batch size (i.e., batchsize), training rounds (num_train_epochs), and the number of layers of the deep learning model. In one example, the resolution may be set to 512, the learning rate may be set to 1e-5, the batch size may be set to 4, and the training rounds may be set to 80. The model hyperparameters corresponding to the image generation model may be adjusted using a model inference tool, for example, a verification calculation may be performed and a checkpoint of the model may be saved every 4,000 iterations. After the training is completed, the checkpoint of the model with the best effect on the verification set may be taken and determined as the image generation model.
[0113] According to an embodiment of the present disclosure, model performance can be characterized by a model performance evaluation value. The performance test result may include a model performance evaluation value. The model performance evaluation value may include at least one of the following: precision, recall, accuracy, error rate, and F-function value. The predetermined performance condition may refer to the model performance evaluation value being greater than or equal to a predetermined model performance evaluation threshold. The predetermined model performance evaluation threshold may be configured according to actual business needs and is not limited here.
[0114] According to an embodiment of the present disclosure, the model performance of the image generation model can be tested using a verification sample image set to obtain a performance test result. For example, the image generation model can be used to process the verification sample image set to obtain a prediction result. Based on the prediction result, the performance test result is determined, and then it is determined whether the performance test result meets the predetermined performance condition. In the case where it is determined that the performance test result meets the predetermined performance condition, the optimization operation for the verification sample image set is terminated. In the case where it is determined that the performance test result does not meet the predetermined performance condition, a new verification sample image set can be determined. The model performance of the image generation model is tested using the new verification sample image set to obtain a performance test result. Repeat the above operation until the performance test result meets the predetermined performance condition.
[0115] According to an embodiment of the present disclosure, the performance of the image generation model is tested by repeatedly using a validation sample image set to obtain a performance test result. When it is determined that the performance test result does not meet a predetermined performance condition, the model hyperparameters corresponding to the image generation model are adjusted until the performance test result of the image generation model meets the predetermined performance condition, thereby improving the accuracy of the image generation model in obtaining the generated image.
[0116] The above are merely exemplary embodiments, but are not limited thereto, and may also include other image generation model training methods known in the art, as long as they can improve the efficiency and accuracy of image generation.
[0117] Figure 5 The flowchart of the image generating method according to the embodiment of the present disclosure is schematically shown.
[0118] like Figure 5 As shown, the image generating method 500 includes operations S510 to S530.
[0119] In operation S510, an initial image and extended canvas information are acquired.
[0120] In operation S520, the initial image is processed according to the extended canvas information to obtain a first intermediate image and a mask image.
[0121] In operation S530, the first intermediate image and the mask image are input into an image generation model, and a target generated image is output. The image generation model is trained using a training method for an image generation model.
[0122] According to an embodiment of the present disclosure, the code for generating an image generation request can be pre-written into a script. In response to detecting an image generation operation initiated by a user, the client can run the script to generate an image generation request message based on the initial image (i.e., image) and extended canvas information (i.e., calibration) passed in by the user through the image generation operation. The above-mentioned initial image and extended canvas information can be used to define the layout form of the extended generated image. The client can send the image generation request message to the server, so that the server can process the initial image according to the extended canvas information in the image generation request message to obtain the generated image.
[0123] According to an embodiment of the present disclosure, the extended canvas information may be used to indicate the position from which the initial image needs to be extended, how many pixels need to be extended horizontally, how many pixels need to be extended vertically, etc. For example, the extended canvas information may include at least one of the following: canvas size information, image position information, and image scaling information.
[0124] According to an embodiment of the present disclosure, canvas size information can be used to characterize the size of the target canvas. For example, the canvas size information may include the width (i.e., width) and the height (i.e., height) of the target canvas. Image position information and image scaling information may be used to characterize the specific area where the initial image is to be placed on the target canvas. For example, the image position information may include the horizontal coordinate (i.e., x) and the vertical coordinate (i.e., y) of the upper left vertex of the initial image, and the image scaling information may include the width (i.e., w) and height (i.e., h) to which the initial image needs to be scaled. Thus, the extended canvas information may be defined as calibration (width, height, x, y, w, h).
[0125] According to an embodiment of the present disclosure, after obtaining an initial image and extended canvas information, the initial image can be processed according to the extended canvas information to obtain a first intermediate image. In addition, a mask image can also be generated according to the extended canvas information. In the case where the extended canvas information includes image size information, image scaling information, and image position information, for example, a target canvas and a first intermediate mask image can be created according to the image size information. On this basis, the initial image and the target canvas can be processed according to the image scaling information and the image position information to obtain a first intermediate image. Alternatively, the first intermediate mask image can be processed according to the image scaling information and the image position information to obtain a mask image. After obtaining the first intermediate image and the mask image, the above-mentioned first intermediate image and the mask image can be input into an image generation model to obtain a second intermediate image.
[0126] According to an embodiment of the present disclosure, after obtaining the second intermediate image, the second intermediate image may be further post-processed to generate a target generated image, thereby achieving one-step end-to-end generation of an extended target generated image. The specific post-processing operation may be configured according to actual business needs and is not limited here. For example, the post-processing operation may include at least one of the following: non-extended area recovery processing, gamma correction processing, tone mapping processing, and flooding processing.
[0127] According to the embodiments of the present disclosure, since the second intermediate image is obtained by processing the first intermediate image according to the mask image, and the first intermediate image and the mask image are obtained by processing the initial image according to the extended canvas information, it is possible to use the mask image as a control condition to guide the automatic image generation of the initial image, thereby at least partially overcoming the technical problems that the generated image obtained by the current image extension method in the related art has unnatural splicing and cannot be globally optimized, and by controlling the image content of the generated image based on the mask image, the accuracy and generation effect of the target generated image are improved.
[0128] Reference below Figure 6 and Figure 7 , the image generating method 500 according to the embodiment of the present invention is further described.
[0129] According to an embodiment of the present disclosure, operation S520 may include the following operations.
[0130] According to the canvas size information, a target canvas and a first intermediate mask image are created. According to the image scaling information, the initial image is scaled to obtain a first processed image. According to the image position information, the first processed image is pasted to the target canvas to obtain a first intermediate image. According to the image position information and the image scaling information, the first intermediate mask image is pixel-changed to obtain a second intermediate mask image. The second intermediate mask image is pixel-inverted to obtain a mask image.
[0131] According to an embodiment of the present disclosure, the extended canvas information may include canvas size information, image position information, and image scaling information.
[0132] According to an embodiment of the present disclosure, as described above, the extended canvas information can be defined as calibration (width, height, x, y, w, h). After obtaining the initial image and the extended canvas information, the target canvas can be created according to the width of the target canvas (i.e., width) and the height of the target canvas (i.e., height), i.e., canvas = Image.new ((width, height), 'RGB'). In addition, the first intermediate mask image of the target canvas can also be created according to the width of the target canvas (i.e., width) and the height of the target canvas (i.e., height), i.e., mask = np.zeros ((height, width), dtype = np.uint8).
[0133] According to an embodiment of the present disclosure, after obtaining the target canvas, the initial image can be scaled according to the width (i.e., w) and height (i.e., h) to which the initial image needs to be scaled, to obtain a first processed image, i.e., image=image.resize((w, h)). On this basis, the first processed image can be pasted to the target canvas according to the horizontal coordinate (i.e., x) and vertical coordinate (i.e., y) of the upper left vertex of the initial image, to obtain a first intermediate image, i.e., canvas.paste(image, (x, y)).
[0134] According to an embodiment of the present disclosure, after obtaining the first intermediate mask image, the first intermediate mask image can be pixel-changed according to the horizontal coordinate (i.e., x), the vertical coordinate (i.e., y) of the upper left vertex of the initial image, and the width (i.e., w) and height (i.e., h) to which the initial image needs to be scaled to obtain the second intermediate mask image, which is equivalent to the process of filling the mask image of the non-extended area on the target canvas with white, i.e., mask[y: y+h, x; x+w]=255. On this basis, the second intermediate mask image can be pixel-inverted to obtain a mask image, i.e., mask=np.invert(mask). Thus, the mask image can be used as a conditional control image for guiding image generation.
[0135] According to the embodiment of the present disclosure, since the first intermediate image is obtained by pasting the first processed image to the target canvas according to the image position information, the first processed image is obtained by scaling the initial image according to the image scaling information, and the target canvas and the first intermediate mask image are created according to the canvas size information, it is possible to obtain a first intermediate image that meets the size requirements, thereby ensuring that the proportion and position of the first intermediate image in the subsequent image generation process meet expectations. In addition, since the mask image is obtained by inverting the pixels of the second intermediate mask image, and the second intermediate mask image is obtained by changing the pixels of the first intermediate mask image according to the image position information and the image scaling information, it is possible to determine that the mask image matches the first intermediate image, thereby achieving refined control of the image content, which is conducive to ensuring the accuracy of the subsequent target generated image.
[0136] Figure 6 An example schematic diagram of a process of processing an initial image according to extended canvas information to obtain a first intermediate image and a mask image according to an embodiment of the present disclosure is schematically shown.
[0137] like Figure 6 As shown in 600, the extended canvas information 601 may include canvas size information 601_1, image position information 601_2, and image scaling information 601_6. According to the canvas size information 601_1, a target canvas 602 and a first intermediate mask image 603 may be created. According to the image scaling information 6016, the initial image 606 is scaled to obtain a first processed image 607. According to the image position information 6012, the first processed image 607 is pasted to the target canvas 602 to obtain a first intermediate image 608.
[0138] According to the image position information 6012 and the image scaling information 6016 , the first intermediate mask image 603 is pixel-changed to obtain the second intermediate mask image 604 . The second intermediate mask image 604 is pixel-inverted to obtain the mask image 605 .
[0139] Figure 7 An example schematic diagram of an initial image and a target generated image according to an embodiment of the present disclosure is schematically shown.
[0140] like Figure 7As shown in 700, taking the initial image 701 as an example, the initial image 701 can be processed according to the extended canvas information to obtain a target generated image 702 corresponding to the initial image 701. Taking the initial image 703 as an example, the initial image 703 can be processed according to the extended canvas information to obtain a target generated image 704 corresponding to the initial image 703. Taking the initial image 705 as an example, the initial image 705 can be processed according to the extended canvas information to obtain a target generated image 706 corresponding to the initial image 705.
[0141] The above are only exemplary embodiments, but are not limited thereto, and may also include other image generation methods known in the art, as long as they can improve the accuracy and generation effect of the target generated image.
[0142] Figure 8 A block diagram of a training device for an image generation model according to an embodiment of the present disclosure is schematically shown.
[0143] like Figure 8 As shown, the training device 800 for the image generation model may include a first processing module 810 , a second processing module 820 and a first training module 830 .
[0144] The first processing module 810 is used to process the initial sample image set to obtain a first intermediate sample image set and a mask sample image, wherein each initial sample image in the initial sample image set corresponds to an actually generated image.
[0145] The second processing module 820 is used to process the first intermediate sample image set according to the mask sample image to obtain a second intermediate sample image set, wherein the second intermediate sample image set includes a second intermediate sample image corresponding to each initial sample image.
[0146] The first training module 830 is used to train the deep learning model using the second intermediate sample image and the actual generated image of each initial sample image to obtain an image generation model.
[0147] According to an embodiment of the present disclosure, each initial sample image has a respective aspect ratio.
[0148] According to an embodiment of the present disclosure, the third processing module 810 may include a first scaling unit, a truncation unit, a first random sampling unit, a first generation unit, and a second random sampling unit.
[0149] The first scaling unit is used to scale each initial sample image according to a first preset value and the width-to-height ratio of each initial sample image to obtain a scaled sample image set.
[0150] The interception unit is used to intercept the scaled sample image set according to a first preset value to obtain a intercepted sample image set.
[0151] The first random sampling unit is used to randomly sample the intercepted sample image set according to the second preset value to obtain a first intermediate sample image set.
[0152] The first generating unit is used to generate an initial mask sample image according to a first preset value.
[0153] The second random sampling unit is used to randomly sample the initial mask sample image according to a second preset value to obtain a mask sample image.
[0154] According to an embodiment of the present disclosure, the first intermediate sample image set includes a first intermediate sample image corresponding to each of the initial sample images. The second processing module 820 may include a first processing unit, a second processing unit and a second generating unit.
[0155] The first processing unit is used to perform format conversion processing on the first intermediate sample image and the mask sample image to obtain first intermediate sample image data and mask sample image data.
[0156] The second processing unit is used to process the first intermediate sample image data by taking the mask sample image data as a control condition to obtain a third intermediate sample image.
[0157] The second generating unit is used to generate a second intermediate sample image according to the initial sample image and the third intermediate sample image.
[0158] According to an embodiment of the present disclosure, the second processing unit may include a feature extraction processing subunit, a feature fusion processing subunit and a generation subunit.
[0159] The feature extraction processing subunit is used to perform feature extraction processing on the mask sample image data and the first intermediate sample image data respectively to obtain a mask sample feature map and a first intermediate sample feature map.
[0160] The feature fusion processing subunit is used to perform feature fusion processing on the mask sample feature map and the first intermediate sample feature map to obtain a fused sample feature map.
[0161] The generating subunit is used to generate a third intermediate sample image according to the fused sample feature map.
[0162] According to an embodiment of the present disclosure, the first training module 830 may include an obtaining unit, an adjusting unit, and a determining unit.
[0163] The obtaining unit is used to obtain the loss function value based on the preset loss function according to the second intermediate sample image and the actually generated image of each initial sample image.
[0164] The adjustment unit is used to adjust the model parameters of the deep learning model according to the loss function value until a predetermined end condition is met.
[0165] A determination unit is used to determine the deep learning model obtained when a predetermined end condition is met as an image generation model.
[0166] According to an embodiment of the present disclosure, the preset loss function includes a first sub-loss function and a second sub-loss function, the first sub-loss function is determined according to the image generation type, and the second sub-loss function is determined according to the generation loss function and the perception loss function.
[0167] According to an embodiment of the present disclosure, the obtaining unit may include a first determining subunit, a second determining subunit, and a third determining subunit.
[0168] The first determination subunit is used to determine, for each initial sample image, a first sub-loss function value and a second sub-loss function value based on the first sub-loss function and the second sub-loss function according to the second intermediate sample image and the actually generated image.
[0169] The second determining subunit is used to determine the sub-loss function accumulated value according to the first sub-loss function value and the second sub-loss function value.
[0170] The third determination subunit is used to determine the loss function value according to the accumulated value of the sub-loss function of each initial sample image.
[0171] According to an embodiment of the present disclosure, the training device 800 for the image generation model may further include a testing module, an adjustment module and a second training module.
[0172] A testing module is used to test the model performance of the image generation model using a verification sample image set to obtain a performance test result, wherein the verification sample image set includes at least one verification sample image and a second intermediate verification sample image and an actual verification generated image corresponding to each verification sample image.
[0173] The adjustment module is used to adjust the model hyperparameters corresponding to the image generation model when it is determined that the performance test result does not meet the predetermined performance conditions.
[0174] The second training module is used to retrain the deep learning model based on the adjusted model hyperparameters using the second intermediate verification sample image and the actual generated image of each initial sample image to obtain a new image generation model.
[0175] Fig. 9 The block diagram schematically shows an image generating device according to an embodiment of the present disclosure.
[0176] like Fig. 9 As shown, the image generating device 900 may include an acquisition module 910 , a third processing module 920 and an input module 930 .
[0177] The acquisition module 910 is used to acquire the initial image and extended canvas information.
[0178] The third processing module 920 is used to process the initial image according to the extended canvas information to obtain a first intermediate image and a mask image.
[0179] The input module 930 is used to input the first intermediate image and the mask image into the image generation model and output the target generated image. The image generation model is trained using the training device of the image generation model.
[0180] According to an embodiment of the present disclosure, the extended canvas information includes canvas size information, image position information and image scaling information.
[0181] According to an embodiment of the present disclosure, the third processing module 920 may include a creating unit, a second scaling unit, a pasting unit, a pixel changing unit, and a pixel inverting unit.
[0182] The creation unit is used to create a target canvas and a first intermediate mask image according to the canvas size information.
[0183] The second scaling unit is used to scale the initial image according to the image scaling information to obtain a first processed image.
[0184] The pasting unit is used to paste the first processed image to the target canvas according to the image position information to obtain a first intermediate image.
[0185] The pixel changing unit is used to change the pixels of the first intermediate mask image according to the image position information and the image scaling information to obtain the second intermediate mask image.
[0186] A pixel inversion unit is used to invert the pixels of the second intermediate mask image to obtain a mask image. According to the embodiments of the present disclosure, any multiple of the modules, submodules, units, and subunits, or at least part of the functions of any multiple of them can be implemented in one module. According to the embodiments of the present disclosure, any one or more of the modules, submodules, units, and subunits can be split into multiple modules for implementation. According to the embodiments of the present disclosure, any one or more of the modules, submodules, units, and subunits can be at least partially implemented as a hardware circuit, such as a field programmable gate array (FPGA), a programmable logic array (PLA), a system on a chip, a system on a substrate, a system on a package, an application-specific integrated circuit (ASIC), or can be implemented by hardware or firmware in any other reasonable way of integrating or packaging the circuit, or in any one of the three implementation methods of software, hardware, and firmware, or in any appropriate combination of any of them. Alternatively, according to the embodiments of the present disclosure, one or more of the modules, submodules, units, and subunits can be at least partially implemented as a computer program module, and when the computer program module is run, the corresponding function can be performed.
[0187] For example, any multiple of the acquisition module 910, the third processing module 920, and the input module 930 can be combined in one module / unit / subunit for implementation, or any one of the modules / units / subunits can be split into multiple modules / units / subunits. Alternatively, at least part of the functions of one or more of these modules / units / subunits can be combined with at least part of the functions of other modules / units / subunits and implemented in one module / unit / subunit. According to an embodiment of the present disclosure, at least one of the acquisition module 910, the third processing module 920, and the input module 930 can be at least partially implemented as a hardware circuit, such as a field programmable gate array (FPGA), a programmable logic array (PLA), a system on a chip, a system on a substrate, a system on a package, an application specific integrated circuit (ASIC), or can be implemented by hardware or firmware such as any other reasonable way of integrating or packaging the circuit, or implemented in any one of the three implementation methods of software, hardware, and firmware or in a suitable combination of any of them. Alternatively, at least one of the acquisition module 910 , the third processing module 920 , and the input module 930 may be at least partially implemented as a computer program module, and when the computer program module is executed, a corresponding function may be performed.
[0188] It should be noted that the image generating device part in the embodiment of the present disclosure corresponds to the image generating method part in the embodiment of the present disclosure. The description of the image generating device part specifically refers to the image generating method part, which will not be repeated here.
[0189] For example, any multiple of the first processing module 810, the second processing module 820, and the first training module 830 can be combined in one module / unit / sub-unit for implementation, or any one of the modules / units / sub-units can be split into multiple modules / units / sub-units. Alternatively, at least part of the functions of one or more of these modules / units / sub-units can be combined with at least part of the functions of other modules / units / sub-units and implemented in one module / unit / sub-unit. According to an embodiment of the present disclosure, at least one of the first processing module 810, the second processing module 820, and the first training module 830 can be at least partially implemented as a hardware circuit, such as a field programmable gate array (FPGA), a programmable logic array (PLA), a system on a chip, a system on a substrate, a system on a package, an application specific integrated circuit (ASIC), or can be implemented by hardware or firmware such as any other reasonable way of integrating or packaging the circuit, or implemented in any one of the three implementation methods of software, hardware, and firmware, or in any appropriate combination of any of them. Alternatively, at least one of the first processing module 810, the second processing module 820 and the first training module 830 may be at least partially implemented as a computer program module, and when the computer program module is executed, the corresponding function may be performed.
[0190] It should be noted that the training device part of the image generation model in the embodiment of the present disclosure corresponds to the training method part of the image generation model in the embodiment of the present disclosure. The description of the training device part of the image generation model specifically refers to the training method part of the image generation model, which will not be repeated here.
[0191] Fig.10 A block diagram of an electronic device suitable for implementing an image generation method and a training method for an image generation model according to an embodiment of the present disclosure is schematically shown. Fig.10 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.
[0192] like Fig.10As shown, the computer electronic device 1000 according to the embodiment of the present disclosure includes a processor 1001, which can perform various appropriate actions and processes according to the program stored in the read-only memory (ROM) 1002 or the program loaded from the storage part 1009 to the random access memory (RAM) 1003. The processor 1001 may include, for example, a general-purpose microprocessor (such as a CPU), an instruction set processor and / or a related chipset and / or a special-purpose microprocessor (for example, an application-specific integrated circuit (ASIC)), etc. The processor 1001 may also include an onboard memory for caching purposes. The processor 1001 may include a single processing unit or multiple processing units for performing different actions of the method flow according to the embodiment of the present disclosure.
[0193] In RAM 1003, various programs and data required for the operation of electronic device 1000 are stored. Processor 1001, ROM 1002 and RAM 1003 are connected to each other via bus 1004. Processor 1001 performs various operations of the method flow according to the embodiment of the present disclosure by executing the program in ROM 1002 and / or RAM 1003. It should be noted that the program can also be stored in one or more memories other than ROM 1002 and RAM 1003. Processor 1001 can also perform various operations of the method flow according to the embodiment of the present disclosure by executing the program stored in the one or more memories.
[0194] According to an embodiment of the present disclosure, the electronic device 1000 may further include an input / output (I / O) interface 1005, which is also connected to the bus 1004. The electronic device 1000 may further include one or more of the following components connected to the input / output (I / O) interface 1005: an input portion 1006 including a keyboard, a mouse, etc.; an output portion 1007 including a cathode ray tube (CRT), a liquid crystal display (LCD), etc., and a speaker, etc.; a storage portion 1008 including a hard disk, etc.; and a communication portion 1009 including a network interface card such as a LAN card, a modem, etc. The communication portion 1009 performs communication processing via a network such as the Internet. A drive 1010 is also connected to the input / output (I / O) interface 1005 as needed. A removable medium 1011, such as a magnetic disk, an optical disk, a magneto-optical disk, a semiconductor memory, etc., is installed on the drive 1010 as needed, so that a computer program read therefrom is installed into the storage portion 1008 as needed.
[0195] According to an embodiment of the present disclosure, the method flow according to an embodiment of the present disclosure 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 storage medium, and the computer program contains a program code for executing the method shown in the flowchart. In such an embodiment, the computer program can be downloaded and installed from the network through the communication part 1009, and / or installed from the removable medium 1011. When the computer program is executed by the processor 1001, the above-mentioned functions defined in the system of the embodiment of the present disclosure are executed. According to an embodiment of the present disclosure, the system, equipment, device, module, unit, etc. described above can be implemented by a computer program module.
[0196] The present disclosure also provides a computer-readable storage medium, which may be included in the device / apparatus / system described in the above embodiments; or may exist independently without being assembled into the device / apparatus / system. The above computer-readable storage medium carries one or more programs, and when the above one or more programs are executed, the method according to the embodiment of the present disclosure is implemented.
[0197] According to an embodiment of the present disclosure, the computer-readable storage medium may be a non-volatile computer-readable storage medium. For example, it may include, but is not limited to: 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), a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination thereof. In the present disclosure, a computer-readable storage medium may be any tangible medium containing or storing a program that may be used by or in combination with an instruction execution system, apparatus, or device.
[0198] For example, according to an embodiment of the present disclosure, the computer-readable storage medium may include the ROM 1002 and / or the RAM 1003 described above and / or one or more memories other than the ROM 1002 and the RAM 1003 .
[0199] An embodiment of the present disclosure also includes a computer program product, which includes a computer program, which contains program code for executing the method provided by the embodiment of the present disclosure. When the computer program product runs on an electronic device, the program code is used to enable the electronic device to implement the image generation method and image generation model training method provided by the embodiment of the present disclosure.
[0200] When the computer program is executed by the processor 1001, the above functions defined in the system / device of the embodiment of the present disclosure are executed. According to the embodiment of the present disclosure, the system, device, module, unit, etc. described above can be implemented by a computer program module.
[0201] In one embodiment, the computer program may rely on tangible storage media such as optical storage devices, magnetic storage devices, etc. In another embodiment, the computer program may also be transmitted and distributed in the form of signals on a network medium, and downloaded and installed through the communication part 1009, and / or installed from the removable medium 1011. The program code contained in the computer program may be transmitted using any appropriate network medium, including but not limited to: wireless, wired, etc., or any suitable combination of the above.
[0202] According to an embodiment of the present disclosure, the program code for executing the computer program provided by the embodiment of the present disclosure can be written in any combination of one or more programming languages. Specifically, these computing programs can be implemented using high-level process and / or object-oriented programming languages, and / or assembly / machine languages. Programming languages include, but are not limited to, Java, C++, python, "C" language or similar programming languages. The program code can be executed entirely on the user computing device, partially on the user device, partially on the remote computing device, or entirely on the remote computing device or server. In the case of a remote computing device, the remote computing device can be connected to the user computing device through any type of network, including a local area network (LAN) or a wide area network (WAN), or can be connected to an external computing device (for example, using an Internet service provider to connect through the Internet).
[0203] The flowcharts and block diagrams in the accompanying drawings illustrate the possible architecture, functions and operations of the systems, methods and computer program products according to various embodiments of the present disclosure. In this regard, each box in the flowchart or block diagram may represent a module, a program segment, or a part of a code, and the above-mentioned module, program segment, or a part of the code contains one or more executable instructions for implementing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the box may also occur in an order different from that marked in the accompanying drawings. For example, two boxes represented in succession can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each box in the block diagram or flowchart, and the combination of boxes in the block diagram or flowchart, can be implemented with a dedicated hardware-based system that performs the specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions. It can be understood by those skilled in the art that the features recorded in the various embodiments and / or claims of the present disclosure can be combined and / or combined in a variety of ways, even if such a combination or combination is not explicitly recorded in the present disclosure. In particular, without departing from the spirit and teaching of the present disclosure, the features described in the various embodiments and / or claims of the present disclosure may be combined and / or combined in a variety of ways. All of these combinations and / or combinations fall within the scope of the present disclosure.
[0204] The embodiments of the present disclosure are described above. However, these embodiments are only for illustrative purposes and are not intended to limit the scope of the present disclosure. Although the embodiments are described above separately, this does not mean that the measures in the various embodiments cannot be used in combination to advantage. The scope of the present disclosure is defined by the attached claims and their equivalents. Without departing from the scope of the present disclosure, those skilled in the art may make a variety of substitutions and modifications, which should all fall within the scope of the present disclosure.
Claims
1. A training method for an image generation model, comprising: Processing the initial sample image set to obtain a first intermediate sample image set and a mask sample image, wherein each initial sample image in the initial sample image set corresponds to an actually generated image; Processing the first intermediate sample image set according to the mask sample image to obtain a second intermediate sample image set, wherein the second intermediate sample image set includes a second intermediate sample image corresponding to each of the initial sample images; and The second intermediate sample image and the actually generated image of each of the initial sample images are used to train a deep learning model to obtain an image generation model.
2. The method according to claim 1, wherein: Each of the initial sample images has a width-to-height ratio; The processing of the initial sample image set to obtain the first intermediate sample image set and the mask sample image comprises: Scaling each of the initial sample images according to the first preset value and the aspect ratio of each of the initial sample images to obtain a scaled sample image set; According to the first preset value, the scaled sample image set is intercepted to obtain the intercepted sample image set; According to a second preset value, randomly sampling the intercepted sample image set to obtain the first intermediate sample image set; generating an initial mask sample image according to the first preset value; and According to the second preset value, the initial mask sample image is randomly sampled to obtain the mask sample image.
3. The method according to claim 1 or 2, wherein: The first intermediate sample image set includes a first intermediate sample image corresponding to each of the initial sample images; The step of processing the first intermediate sample image set according to the mask sample image to obtain the second intermediate sample image set comprises: For each of the first intermediate sample images, Performing format conversion processing on the first intermediate sample image and the mask sample image to obtain first intermediate sample image data and mask sample image data; Using the mask sample image data as a control condition, processing the first intermediate sample image data to obtain a third intermediate sample image; and The second intermediate sample image is generated according to the initial sample image and the third intermediate sample image.
4. The method according to claim 3, wherein: The step of processing the first intermediate sample image data using the mask sample image data as a control condition to obtain a third intermediate sample image comprises: Performing feature extraction processing on the mask sample image data and the first intermediate sample image data respectively to obtain a mask sample feature map and a first intermediate sample feature map; Performing feature fusion processing on the masked sample feature map and the first intermediate sample feature map to obtain a fused sample feature map; and The third intermediate sample image is generated according to the fused sample feature map.
5. The method according to claim 1, wherein: The method of training the deep learning model by using the second intermediate sample image and the actually generated image of each of the initial sample images to obtain the image generation model comprises: Based on a preset loss function, a loss function value is obtained according to the second intermediate sample image and the actually generated image of each of the initial sample images; Adjusting the model parameters of the deep learning model according to the loss function value until a predetermined end condition is met; and The deep learning model obtained when the predetermined end condition is met is determined as the image generation model.
6. The method according to claim 5, wherein: The preset loss function includes a first sub-loss function and a second sub-loss function, the first sub-loss function is determined according to the image generation type, and the second sub-loss function is determined according to the generation loss function and the perception loss function; The step of obtaining the loss function value based on the preset loss function and according to the second intermediate sample image and the actually generated image of each of the initial sample images comprises: For each of the initial sample images, based on the first sub-loss function and the second sub-loss function, according to the second intermediate sample image and the actually generated image, determine a first sub-loss function value and a second sub-loss function value; Determine a sub-loss function accumulated value according to the first sub-loss function value and the second sub-loss function value; and The loss function value is determined according to the accumulated value of the sub-loss function of each of the initial sample images.
7. The method according to claim 1, further comprising repeatedly performing the following operations until the performance test result of the image generation model meets a predetermined performance condition: The model performance of the image generation model is tested using a validation sample image set to obtain the performance test result, wherein: The verification sample image set includes at least one verification sample image and a second intermediate verification sample image and an actual verification generated image corresponding to each of the verification sample images; In the case where it is determined that the performance test result does not meet the predetermined performance condition, adjusting a model hyperparameter corresponding to the image generation model; as well as Based on the adjusted model hyperparameters, the deep learning model is retrained using the second intermediate verification sample image and the actual verification generated image of each of the initial sample images to obtain a new image generation model.
8. A method for generating an image, comprising: Get the initial image and extended canvas information; Processing the initial image according to the extended canvas information to obtain a first intermediate image and a mask image; Inputting the first intermediate image and the mask image into an image generation model, and outputting a target generated image; Wherein, the image generation model is trained using the methods described in claims 1 to 7.
9. The method according to claim 8, wherein: The extended canvas information includes canvas size information, image position information and image scaling information; The step of processing the initial image according to the extended canvas information to obtain a first intermediate image and a mask image includes: Creating a target canvas and a first intermediate mask image according to the canvas size information; Scaling the initial image according to the image scaling information to obtain a first processed image; Pasting the first processed image to the target canvas according to the image position information to obtain the first intermediate image; According to the image position information and the image scaling information, pixels of the first intermediate mask image are changed to obtain a second intermediate mask image; and Pixels of the second intermediate mask image are inverted to obtain the mask image.
10. A training device for an image generation model, comprising: A first processing module is used to process the initial sample image set to obtain a first intermediate sample image set and a mask sample image, wherein each initial sample image in the initial sample image set corresponds to an actually generated image; A second processing module, configured to process the first intermediate sample image set according to the mask sample image to obtain a second intermediate sample image set, wherein the second intermediate sample image set includes a second intermediate sample image corresponding to each of the initial sample images; and The first training module is used to train a deep learning model using the second intermediate sample image and the actual generated image of each of the initial sample images to obtain an image generation model.
11. An image generating device, comprising: The acquisition module is used to obtain the initial image and extended canvas information; a third processing module, configured to process the initial image according to the extended canvas information to obtain a first intermediate image and a mask image; An input module, used for inputting the first intermediate image and the mask image into an image generation model, and outputting a target generated image; Wherein, the image generation model is trained using the device described in claim 10.
12. An electronic device comprising: one or more processors; a memory for storing one or more instructions, Wherein, when the one or more instructions are executed by the one or more processors, the one or more processors implement the method of any one of claims 1 to 7 or any one of claims 8 to 9.
13. A computer-readable storage medium having executable instructions stored thereon, wherein when the executable instructions are executed by a processor, the processor is enabled to implement the method of any one of claims 1 to 7 or any one of claims 8 to 9.
14. A computer program product, comprising computer executable instructions for implementing the method of any one of claims 1 to 7 or any one of claims 8 to 9 when the computer executable instructions are executed.
