Image generation method, noise prediction method for image generation and related equipment
By adjusting the module of the image generation model to give spatial perception capabilities, the problem of unreasonable object structure when the Diffusion model generates high-resolution images is solved, and high-resolution images with reasonable object structures and rich details are generated.
Patent Information
- Application Number
- CN202410635365.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-05-21
- Publication Date
- 2024-09-06
AI Technical Summary
When existing image generation models generate higher-resolution images, they are prone to unreasonable object structures, such as object duplication and overlap. This is mainly due to the lack of high-resolution image samples and the high training cost of the Diffusion model, resulting in the model being only suitable for Low resolution image generation.
By adjusting the modules in the image generation model and giving it spatial awareness, the model can adjust the feature size according to the resolution of the input image, thereby avoiding feature duplication and ensuring that the generated high-resolution image has a reasonable object structure. The specific method includes adjusting the module in the second model so that its output conforms to the feature size of the preset resolution, and using the collaborative work of the first model and the second model in the image generation process to iteratively generate the image to avoid unreasonable structure.
It effectively avoids the problem of unreasonable object structure in high-resolution images, ensures that the generated images have reasonable object structures and better image details, and improves the efficiency and quality of image generation.
Smart Images

Figure CN118608640A
Abstract
Description
Technical Field
[0001] The present application relates to the field of artificial intelligence, and in particular to an image generation method, a noise prediction method for image generation, and related equipment. Background Art
[0002] Image generation technology is an important branch of artificial intelligence, which can automatically create new image content from scratch.
[0003] However, since high-resolution image samples are not easy to obtain, image generation models such as the Diffusion model are mainly trained using fixed low-resolution image samples, resulting in unreasonable object structures in higher-resolution images generated by these models. Summary of the invention
[0004] In view of the above problems, the embodiments of the present application provide an image generation method, a noise prediction method for image generation, and related devices to overcome the above problems or at least partially solve the above problems.
[0005] In a first aspect of an embodiment of the present application, a method for generating an image is provided, the method comprising:
[0006] When the resolution of the first image is higher than the preset resolution, generate an image based on the first image using the first model and the second model to obtain a second image, wherein the resolution of the second image is not lower than the resolution of the first image;
[0007] Among them, the first model is obtained by adjusting the modules in the second model, and the output of the adjusted modules conforms to the feature size corresponding to the preset resolution; the second model is a pre-trained image generation model.
[0008] A second aspect of the embodiments of the present application provides a noise prediction method for image generation, the method comprising:
[0009] When the resolution of the noise image does not match the preset resolution, a fourth model is used to perform noise prediction on the noise image to obtain a prediction result, and the prediction result is used for fingerprint image generation or face image generation;
[0010] Among them, the fourth model is obtained by adjusting the module in the fifth model, and the output of the adjusted module conforms to the characteristic size corresponding to the preset resolution, the fifth model is a pre-trained model for noise prediction in fingerprint image generation, or the fifth model is a pre-trained model for noise prediction in face image generation.
[0011] According to a third aspect of the embodiments of the present application, an image generating device is provided, the device comprising:
[0012] An image generation module, configured to generate an image based on the first image using the first model and the second model to obtain a second image when the resolution of the first image is higher than a preset resolution, wherein the resolution of the second image is not lower than the resolution of the first image;
[0013] Among them, the first model is obtained by adjusting the modules in the second model, and the output of the adjusted modules conforms to the feature size corresponding to the preset resolution; the second model is a pre-trained image generation model.
[0014] According to a fourth aspect of the embodiments of the present application, a noise prediction device for image generation is provided, the device comprising:
[0015] A noise prediction module, used for, when the resolution of the noise image does not match the preset resolution, using the fourth model to perform noise prediction on the noise image to obtain a prediction result, wherein the prediction result is used for fingerprint image generation or face image generation;
[0016] The fourth model is obtained by adjusting the module in the fifth model, and the output of the adjusted module conforms to the characteristic size corresponding to the preset resolution, the fifth model is a pre-trained model for noise prediction in fingerprint image generation, or the fifth model is a pre-trained model for noise prediction in face image generation.
[0017] In a fifth aspect of the embodiments of the present application, an electronic device is provided, comprising a memory, a processor, and a computer program stored on the memory, wherein the processor executes the computer program to implement the image generation method as described in the first aspect disclosed in the embodiments of the present application, or to implement the noise prediction method for image generation as described in the second aspect disclosed in the embodiments of the present application.
[0018] In a sixth aspect of the embodiments of the present application, a computer-readable storage medium is provided, on which a computer program / instruction is stored. When the computer program / instruction is executed by a processor, the image generation method as described in the first aspect disclosed in the embodiments of the present application is implemented, or the noise prediction method for image generation as described in the second aspect disclosed in the embodiments of the present application is implemented.
[0019] In a seventh aspect of the embodiments of the present application, a computer program product is provided, comprising a computer program / instruction, which, when executed by a processor, implements the image generation method as described in the first aspect disclosed in the embodiments of the present application, or implements the noise prediction method for image generation as described in the second aspect disclosed in the embodiments of the present application.
[0020] The embodiments of the present application include the following advantages:
[0021] In this embodiment, the modules in the second model are adjusted to give it spatial perception ability, so that the adjusted first model can restore the feature size corresponding to the resolution of the first image to the feature size corresponding to the preset resolution during the process of extracting features from the first image, thereby ensuring that the first model will not have feature duplication when deeply modeling semantic information, thereby avoiding unreasonable object structures in the generated higher resolution images (i.e., images higher than the preset resolution). BRIEF DESCRIPTION OF THE DRAWINGS
[0022] In order to more clearly illustrate the technical solutions of the embodiments of the present application, the drawings required for use in the description of the embodiments of the present application will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative labor.
[0023] Figure 1 is a flowchart of the steps of an image generation method in an embodiment of the present application;
[0024] Figure 2 is a schematic diagram of an image generation process in an embodiment of the present application;
[0025] Figure 3 1 is a schematic diagram comparing a spatial perception U-Net, a progressive spatial perception U-Net and an original U-Net in an embodiment of the present application;
[0026] Figure 4 is a flowchart of the steps of noise prediction for image generation in an embodiment of the present application;
[0027] Figure 5 is a structural schematic diagram of an image generating device according to an embodiment of the present application;
[0028] Figure 6 is a structural schematic diagram of a noise prediction device for image generation according to an embodiment of the present application;
[0029] Figure 7 It is a structural schematic diagram of an electronic device in an embodiment of the present application. DETAILED DESCRIPTION
[0030] The following will be combined with the drawings in the embodiments of the present application to clearly and completely describe the technical solutions in the embodiments of the present application. Obviously, the described embodiments are part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application.
[0031] It should be understood that the references to "one embodiment" or "an embodiment" throughout the specification mean that the specific features, structures, or characteristics associated with the embodiment are included in at least one embodiment of the present application. Therefore, the references to "in one embodiment" or "in an embodiment" appearing throughout the specification do not necessarily refer to the same embodiment. In addition, these specific features, structures, or characteristics may be combined in any suitable manner in one or more embodiments.
[0032] In the various embodiments of the present application, it should be understood that the size of the serial numbers of the following processes does not mean the order of execution. The execution order of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiments of the present application.
[0033] Exemplary embodiments will be described in detail herein, examples of which are shown in the accompanying drawings. When the following description refers to the drawings, unless otherwise indicated, the same numbers in different drawings represent the same or similar elements. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with the present application. Instead, they are merely examples of devices and methods consistent with some aspects as detailed in the present application.
[0034] It should be noted that, in the absence of conflict, the embodiments and features in the embodiments of the present application may be combined with each other.
[0035] Image generation technology is an important branch of the field of artificial intelligence. It simulates human creativity through algorithms and can automatically create new image content from scratch. It has shown great potential and value in multiple industries.
[0036] In the biomedical field, through image generation technology, researchers can create images for disease model research, which is important for understanding the mechanism of disease occurrence and developing new treatments. In the field of astronomy, image generation technology can help scientists simulate various phenomena in the universe, so as to better explore the mysteries of the universe. In addition, image generation technology is also widely used in industrial design and artistic creation. Designers can use this technology to quickly generate images of multiple design solutions, thereby improving design efficiency and innovation capabilities.
[0037] It is understandable that the higher the image resolution, the clearer and more detailed the visual experience can be. Therefore, high-resolution images play an irreplaceable role in autonomous driving, industrial design, medical diagnosis, and cultural communication.
[0038] However, since high-resolution image samples are not easy to obtain, image generation models such as diffusion models are mainly trained using fixed low-resolution image samples, so that higher-resolution images generated by these models (such as images higher than the fixed low-resolution images) will have unreasonable object structures.
[0039] Taking the Diffusion model as an example, the working principle of the Diffusion model is similar to the diffusion phenomenon in the physical process. It gradually restores clear image content by gradually removing noise data. That is, it generates high-quality images by simulating the diffusion process. The implementation of this image generation process requires a large amount of training data and a complex neural network structure to support it.
[0040] However, due to the lack of a large number of high-resolution image samples and the fact that it takes a lot of time and cost to train the Diffusion model using high-resolution image samples, the current Diffusion model is only suitable for the generation of fixed low-resolution images. When it is applied to the generation of higher-resolution images, object structure problems such as unreasonable object duplication and overlap will occur.
[0041] Based on the above analysis, in view of the problem that higher-resolution images generated by current image generation models have unreasonable object structures, an embodiment of the present application provides an image generation scheme and a noise prediction scheme for image generation, which can enable higher-resolution images generated by image generation models such as Diffusion models to have reasonable object structures.
[0042] First, refer to Figure 1 As shown, a flowchart of a method for generating an image in an embodiment of the present application is shown. Figure 1 As shown, the image generation method includes the following steps:
[0043] Step S11: when the resolution of the first image is higher than the preset resolution, the first model and the second model are used to generate an image based on the first image to obtain a second image, and the resolution of the second image is not lower than the resolution of the first image.
[0044] Among them, the first model is obtained by adjusting the module in the second model, and the output of the adjusted module conforms to the feature size corresponding to the preset resolution; the second model is a pre-trained image generation model; the generated second image can contain any image content (such as fingerprints or faces, etc.).
[0045] In this embodiment, the first image can be input into the first model. After the first model preliminarily generates an image based on the first image, the preliminarily generated image is input into the second model, so that the second model can further generate an image based on the image with a reasonable object structure generated by the first model (mainly adding details and adjusting the preliminarily generated image), thereby avoiding unreasonable object structure problems such as duplication and overlap of objects in the final generated second image.
[0046] Alternatively, the first image may be input into the second model, and after the second model preliminarily generates an image based on the first image, the preliminarily generated image is input into the first model, so that the first model can further generate an image based on the image generated by the second model (mainly performing operations such as adjusting the object structure of the preliminarily generated image), thereby avoiding unreasonable object structure problems such as duplication and overlap of objects in the final generated second image.
[0047] It should be noted that in order to achieve the generation of higher resolution images (i.e., images higher than the preset resolution), the resolution of the images generated by the first model and the second model should not be lower than the resolution of the input image; the preset resolution should be the image resolution that the second model is suitable for processing. For example, the resolution of the image samples used by the second model obtained through training can be used as the preset resolution.
[0048] When the resolution of the first image is higher than the preset resolution, it means that the resolution of the first image is higher than the image resolution that the second model is suitable for processing. Since the parameter structure of the second model is fixed, when the second model processes the first image, the output feature size of each module within the model (that is, the size of the extracted features) will increase compared to the output feature size of each module within the model when the second model processes the preset resolution image. As a result, feature duplication may occur when the second model models semantic information based on the features extracted by the modules, which in turn leads to unreasonable object structure in the image generated by the second model.
[0049] To avoid the above problems, the present application adjusts the modules in the second model so that the obtained first model has spatial perception capability, that is, the ability to adjust the extracted feature size according to the resolution of the input image.
[0050] For example, when the second model processes an image with a preset resolution, the output feature size of its internal module B is 32*32; when the second model processes an image with a resolution of A1 (A1 is greater than the preset resolution), the output feature size of its internal module B is 128*128; when the second model (i.e., the first model) after module adjustment processes an image with a resolution of A1, the output feature size of its internal module B will conform to the feature size corresponding to the preset resolution, that is, the output feature size of the internal module B will be restored from 128*128 to 32*32.
[0051] The output characteristic size of the module in the second model may be adjusted by adjusting the parameters or structure of the module in the second model. For example, at least one of the following adjustments may be made to the module in the second model:
[0052] Adjusting the parameters of the module, for example, adjusting the parameters of the convolutional layer used for downsampling in the module to adjust the size of the features extracted by the module to other desired sizes;
[0053] A target operation layer is added to the module, and the target operation layer is used to adjust the feature size corresponding to the output of the module. For example, a pooling layer can be added to the module to map the size of the feature extracted by the module to other required sizes.
[0054] Optionally, to avoid introducing additional training steps (such as a retraining step when adjusting the module of the second model), you can choose to manually adjust the parameters of the module, and / or select an operation layer that does not require training as the target operation layer. For example, the target operation layer may include an adaptive pooling layer, which is used to adjust its own parameters according to the input feature size and a pre-set output feature size.
[0055] By adopting the technical solution of the embodiment of the present application, the modules in the second model are adjusted to give it spatial perception ability, so that the adjusted first model can restore the feature size corresponding to the resolution of the first image to the feature size corresponding to the preset resolution during the process of extracting features from the first image, thereby ensuring that the first model will not have feature duplication when deeply modeling semantic information, thereby avoiding unreasonable object structures in the generated higher resolution images (i.e., images higher than the preset resolution).
[0056] As a possible implementation manner, when the resolution of the first image is higher than the preset resolution, using the first model and the second model to generate an image based on the first image to obtain the second image includes:
[0057] When the resolution of the first image is higher than the preset resolution, inputting the first image into the first model to iterate and perform image generation for a first number of times to obtain a third image;
[0058] The third image is input into the second model to iterate and generate an image a second number of times to obtain the second image.
[0059] In specific implementation, the first execution number and the second execution number can be set based on experimental tests or experience. For example, the first execution number can be set to 50 and the second execution number can be set to 30, then the first model will iterate the input first image 50 times to generate the image to obtain the third image, and the second model will iterate the input third image 30 times to generate the image to obtain the second image.
[0060] In this embodiment, by setting the first execution number and the second execution number, the user can freely adjust the iterative execution times (ie, step length) of the first model and the second model according to actual needs, and the operation is more flexible.
[0061] Optionally, a relationship between the first execution number and the second execution number satisfies at least one of the following:
[0062] Item A-1: the second execution number is the difference between a preset total execution number and the first execution number, and the preset total execution number is the number of iterations required for image generation using the second model alone;
[0063] Item A-2: The second execution number is greater than the first execution number.
[0064] In this embodiment, for item A-1, by taking the number of iterations required for the second model to realize image generation alone as a reference upper limit (i.e., the preset total number of executions), such as taking the number of iterations when the second model generates an image with the same resolution as the second image and relatively complete image content based on the first image as a reference upper limit, and setting the first number of executions and the second number of executions, it is possible to avoid the situation where the total number of model executions is too large and affects the image generation efficiency while ensuring the quality of the generated image.
[0065] Regarding item A-2, by controlling the execution times of the first model to be greater than the execution times of the second model during the image generation process, the image generation efficiency can be ensured.
[0066] As a possible implementation manner, before adjusting the modules in the second model, the method further includes:
[0067] According to the position distance between each module in the second model and the input end of the second model, the module to be adjusted is selected from the modules.
[0068] In a specific implementation, a module selection range can be set according to the position distance between each module in the second model and the input end of the second model, such as selecting one or more modules within a range of four modules from the input end of the second model as the modules to be adjusted.
[0069] In this embodiment, considering the role of the module in the model, it is usually associated with the position distance between the module and the model input terminal. For example, the closer the position distance between the module and the input terminal of the second model, the greater its role (or influence) in the feature extraction part, that is, the shallow module of the model is mainly responsible for feature extraction; the farther the position distance between the module and the input terminal of the second model, the greater its role (or influence) in the semantic information modeling part, that is, the deep module of the model is mainly responsible for semantic information modeling. In order to avoid feature duplication during deep semantic modeling of the model, it is necessary to adjust the feature size output by the module that has a greater role in the feature extraction part.
[0070] The present application selects the modules that need to be adjusted based on the position distance between the modules in the second model and the input end of the second model, so as to find the modules that have a greater effect on the feature extraction part for adjustment, thereby effectively avoiding feature duplication during deep semantic modeling of the model.
[0071] As a possible implementation manner, before adjusting the modules in the second model, the method further includes:
[0072] Determining the number of modules to be adjusted according to a resolution difference between a resolution of the first image and the preset resolution;
[0073] The modules that need to be adjusted are selected from the modules according to the number of modules that need to be adjusted and the position distance between each module in the second model and the input end of the second model.
[0074] In specific implementation, the correlation between the resolution difference and the number of modules that need to be adjusted can be predetermined based on experimental tests or experience.
[0075] For example, the number of modules required to be adjusted for different resolution difference ranges may be determined in advance, and then the number of modules required to be adjusted may be determined according to the resolution difference range within which the resolution difference between the resolution of the first image and the preset resolution lies.
[0076] After determining the number of modules that need to be adjusted, a corresponding number of modules that play a greater role in the feature extraction part are selected as the modules that need to be adjusted based on the position distance between each module in the second model and the input end of the second model.
[0077] In this embodiment, taking into account factors such as the limited range of change of the adjustable characteristic size of a single module, or the excessive difference in the input and output characteristic sizes of a single module after adjustment may affect the details of the generated image, the present application determines the number of modules that need to be adjusted based on the resolution difference between the resolution of the first image and the preset resolution, so that even when the resolution difference between the resolution of the first image and the preset resolution is large (such as when generating an extremely high-resolution image), it can also be ensured that the generated image has a reasonable object structure and good image details.
[0078] As a possible implementation manner, selecting the modules to be adjusted from the modules according to the number of modules to be adjusted and the position distance between each module in the second model and the input end of the second model includes:
[0079] In the case that the number of modules to be adjusted is one, among the modules of the second model, the module that is closest to the input end of the second model is determined as the module to be adjusted;
[0080] When the number of modules to be adjusted is N, N modules are selected from the modules in order of position distance from near to far as the modules to be adjusted, where N is an integer greater than 1.
[0081] In a specific implementation, when the number of modules that need to be adjusted is one, the module in the second model that is closest to the input end of the second model, that is, the module that has the greatest role (or influence) in the feature extraction part, is determined as the module that needs to be adjusted, thereby ensuring that the output feature size change of the module can have as much influence as possible on the modeling process of the deep semantic information of the model, so that the generated image can have a reasonable object structure.
[0082] When the number of modules to be adjusted is N, select as many modules as possible that are closer to the input end of the second model in order of position distance from near to far, such as taking the first N modules as the modules to be adjusted, or taking any N modules among the first M (M is an integer greater than N) modules as the modules to be adjusted, etc. In this selection method, as many modules that play a greater role in the feature extraction part as possible can be selected as the modules to be adjusted, thereby ensuring that the output feature size change of each module can effectively affect the modeling process of the deep semantic information of the model, so that the generated image can have a reasonable object structure.
[0083] As a possible implementation manner, when the number of modules to be adjusted in the second model is N, adjusting the modules in the second model includes:
[0084] Adjusting the N modules that need to be adjusted in the second model so that the output of the adjusted target module meets the characteristic size corresponding to the preset resolution;
[0085] Among them, the difference between the input characteristic size and the output characteristic size of each of the N modules that need to be adjusted after adjustment is less than the set value, and the target module is: the module among the N modules that need to be adjusted that is farthest from the input end of the second model, and N is an integer greater than 1.
[0086] In specific implementation, the set values corresponding to the N modules can be set based on experimental tests or according to experience. The set values corresponding to the N modules can be the same or different.
[0087] By adjusting the N modules including the target module, the model can be endowed with the ability of progressive spatial perception, so that, on the premise of ensuring that the output feature size of the target module can be restored to the feature size corresponding to the preset resolution, the feature size change value of each of the N modules (i.e., the difference between the input feature size and the output feature size) is controlled below the set value corresponding to each of the N modules, thereby avoiding the loss of image details due to a sharp drop in the feature size of a single module.
[0088] As a possible implementation manner, the second model includes a pre-trained third model for noise prediction; and adjusting the modules in the second model includes:
[0089] The modules in the third model are adjusted.
[0090] In this embodiment, if the second model is an image generation model (i.e., a Diffusion model) that restores the image content by removing noise data from an input noise image, then the modules in the third model for noise prediction, such as U-Net, contained in the second model can be adjusted to ensure that the third model does not have feature duplication when deeply modeling semantic information, thereby obtaining the second model (i.e., the first model) after module adjustment.
[0091] When generating an image, a high-resolution noise image (i.e., the first image) can be input into the first model. The first model performs noise removal on the first image according to the noise prediction result output by the third model inside it, thereby generating an image with a reasonable object structure.
[0092] As a possible implementation manner, the third model includes U-Net; and adjusting the modules in the third model includes:
[0093] The modules in the downsampling path and the modules in the upsampling path in the U-Net are adjusted so that the output of the adjusted modules in the downsampling path conforms to the feature size corresponding to the preset resolution, and the output of the adjusted modules in the upsampling path conforms to the feature size corresponding to the resolution of the first image.
[0094] In a specific implementation, the structure and / or parameters of a module in the up- and down-sampling paths of the U-Net can be adjusted respectively to obtain a spatially aware U-Net. The spatially aware U-Net has spatially aware up- and down-sampling capabilities, and can map the feature size corresponding to the high-resolution noise image (i.e., the first image) to the feature size corresponding to the preset resolution through the adjusted module in the down-sampling path, and map the received feature size to the feature size corresponding to the high-resolution noise image through the adjusted module in the up-sampling path, thereby generating a high-resolution image with a reasonable object structure.
[0095] Alternatively, the structures and / or parameters of multiple modules in the up- and down-sampling paths of the U-Net may be adjusted respectively to obtain a progressive spatial perception U-Net. The progressive spatial perception U-Net also has spatial perception up- and down-sampling capabilities, and can progressively map the feature size corresponding to the high-resolution noise image (i.e., the first image) to the feature size corresponding to the preset resolution through the collaboration of the multiple modules adjusted in the down-sampling path, and map the received feature size to the feature size corresponding to the high-resolution noise image through the modules adjusted in the up-sampling path, thereby generating a high-resolution image with a reasonable object structure and good image details.
[0096] For example, refer to Figure 2Schematic diagram of the image generation process shown in FIG. 1 , a high-resolution noise image conforming to a standard normal distribution is randomly generated, and the high-resolution noise image is input into the first model as the first image. The first model and the spatial perception U-Net or progressive spatial perception U-Net inside the first model are executed a first number of times T 1 The noise prediction and removal operations are performed to obtain the third image.
[0097] The third image is input to the second model, and the second model and the original U-Net inside it (i.e., the U-Net without module adjustment) are executed for the second time (TT 1 ) can obtain a clear second image with a reasonable object structure. 1 It can be freely set according to actual needs, such as being set to 20; T represents the preset total number of executions, that is, the number of iterations (such as 50) for obtaining the second image using the second model.
[0098] Optionally, the modules in the upsampling and downsampling paths can be adjusted symmetrically according to the locations of the modules to maintain the structural symmetry of U-Net and avoid model errors. For example, the module closest to the model input in the downsampling path and the module closest to the model output in the upsampling path can be adjusted to maintain the structural symmetry of U-Net.
[0099] Taking the second model as a pre-trained diffusion model (such as Stable Diffusion V1.5) as an example, the above module adjustment process is illustrated. Figure 3 Schematic diagram showing the comparison between the spatial-aware U-Net, the progressive spatial-aware U-Net and the original U-Net.
[0100] In this example, the preset resolution is 512x512, and the resolution of the first image is 2048x2048; the third model included in the second model is U-Net, and the input end of U-Net is used to receive the input text description (Prompt), latent features (Latent) and step number t (Timestep), wherein the latent features can be obtained by encoding the first image (i.e., the noise image) through a variational autoencoder (VAE); the input end of U-Net is used to output the noise prediction result (which can be expressed as Noise Pred∈ θ), the second model performs multiple rounds of noise removal on the first image according to the noise prediction result iteratively output by U-Net, so as to gradually restore the clear image content, thereby realizing image generation; in U-Net, downsampling modules 1 to 4 (i.e., Down Block 1 to 4) constitute a downsampling path, and upsampling modules 1 to 4 (i.e., UP Block 1 to 4) constitute an upsampling path, and the upsampling path and the downsampling path are connected through an intermediate module (Mid Block).
[0101] like Figure 3 As shown, the original U-Net is the U-Net in the second model (i.e., the U-Net without module adjustment). After the latent feature t (Timestep t) of size 256x256 corresponding to the first image is input into Down Block1 of the original U-Net, the size of the feature output by Down Block1 to Down Block2 is 128x128, and the size of the feature output by Down Block2 to DownBlock3 is 128x128, that is, the size of the feature that each module in the original U-Net needs to process (i.e., received) is larger than the feature size that each module itself is suitable for processing (i.e., corresponding to the preset resolution), so that when the second model generates an image based on the noise prediction result of the output of the original U-Net, an image with an unreasonable object structure will be generated.
[0102] The spatially aware U-Net is obtained by adjusting the Down Block1 and UP Block1 in the original U-Net. The adjusted Down Block1 is endowed with spatially aware downsampling capability, which can map the feature size corresponding to the high-resolution image (i.e., the first image) to the feature size corresponding to the preset resolution, so as to ensure that there will be no feature duplication when U-Net models semantic information in depth; the adjusted UP Block1 is endowed with spatially aware upsampling capability, which can map the received feature size to the feature size (256x256) corresponding to the high-resolution image, so as to ensure that the output is a high-resolution image.
[0103] Specifically, after the above latent feature t (Timestep t) is input into Down Block1 of the spatial perception U-Net, the size of the feature output by Down Block1 to Down Block2 in the spatial perception U-Net is adjusted to the feature size (32x32) corresponding to the preset resolution compared to the size of the feature output by Down Block1 to Down Block2 in the original U-Net (128x128). This makes the size of the features received by Down Block2 and subsequent modules in the spatial perception U-Net conform to the feature size that is suitable for processing. However, since the feature size of Down Block1 in the spatial perception U-Net decreases sharply (i.e., from the input feature size of 256x256 to the output feature size of 32x32), image details may be lost.
[0104] The progressive spatial-aware U-Net is obtained by adjusting Down Block1, Down Block2, UPBlock1, and UP Block 2 in the original U-Net. The adjusted Down Block1 and Down Block2 are both endowed with spatial-aware downsampling capabilities, which can progressively map the feature size corresponding to the high-resolution image to the feature size corresponding to the preset resolution (that is, Down Block1 and Down Block2 are endowed with the ability to collaboratively implement progressive spatial-aware downsampling), so as to avoid the loss of image details due to a sharp drop in feature size in a single module; the upsampling path is symmetrically adjusted according to the module adjustment method of the downsampling path, that is, UP Block1 and UP Block 2 are selected to be adjusted to maintain the symmetry of the U-Net structure and avoid model errors.
[0105] Specifically, after the above latent feature t (Timestep t) is input into DownBlock1 of the progressive spatial-aware U-Net, Down Block1 smoothly reduces the size of the input feature from 256x256 to 64x64 and outputs it to DownBlock2 (corresponding to the above target module), and Down Block2 smoothly reduces the size of the input feature from 64x64 to 16x16 and outputs it to Down Block3. This ensures that the size of the features received by Down Block3 and subsequent modules will conform to the feature size that they are suitable for processing, and can avoid the situation where the feature size of Down Block1 and Down Block2 drops sharply, so that the generated image can have a reasonable object structure and good image details.
[0106] As a possible implementation manner, before using the first model and the second model to generate an image based on the first image to obtain the second image, the method further includes:
[0107] Evaluating the quality of images generated by the second model based on images of different resolutions;
[0108] The preset resolution is determined according to a quality assessment of the image generated by the second model.
[0109] In a specific implementation, images with different resolutions can be input into the second model respectively, and the quality of each image generated by the second model can be evaluated from aspects such as whether the object structure is reasonable or the degree of loss of image details.
[0110] Subsequently, the resolutions of the corresponding input images are sorted in order of quality assessment results from good to bad, and the average of the first a resolutions is taken as the preset resolution, where a is a positive integer.
[0111] In this embodiment, considering that the second model may be trained using image samples of different resolutions, the image resolution (ie, the preset resolution) applicable to the second model can be accurately found through quality assessment.
[0112] As a possible implementation manner, determining the preset resolution according to a quality evaluation of the image generated by the second model includes:
[0113] The image resolution based on which the image with the best quality assessment among the images generated by the second model is based is determined as the preset resolution.
[0114] In a specific implementation, the image resolution based on which the image with the best quality assessment is generated by the second model is determined as the preset resolution, so that the preset resolution can represent the image resolution that the second model is most suitable for processing. Subsequently, the image resolution can be used as a reference, and when the resolution of the input image is higher than the preset resolution, the first model and the second model are used to collaboratively generate the image, and when the resolution of the input image is not higher than the preset resolution, the second model is used to generate the image, thereby ensuring the quality of image generation at different resolutions.
[0115] Second, refer to Figure 4 As shown, a flowchart of the steps of noise prediction for image generation in an embodiment of the present application is shown, such as Figure 4 As shown, the noise prediction method includes the following steps:
[0116] Step S21: when the resolution of the noise image does not match the preset resolution, use the fourth model to perform noise prediction on the noise image to obtain a prediction result, and the prediction result is used for fingerprint image generation or face image generation.
[0117] Among them, the fourth model is obtained by adjusting the module in the fifth model, and the output of the adjusted module conforms to the characteristic size corresponding to the preset resolution, the fifth model is a pre-trained model for noise prediction in fingerprint image generation, or the fifth model is a pre-trained model for noise prediction in face image generation.
[0118] By adopting the technical solution of the embodiment of the present application, the modules in the fifth model are adjusted to give it spatial perception ability, so that the adjusted fourth model can restore the feature size corresponding to the resolution of the noise image to the feature size corresponding to the preset resolution during the process of extracting features from the noise image, thereby ensuring that the fourth model will not have feature duplication when deeply modeling semantic information, thereby avoiding the appearance of unreasonable object structures in the generated higher resolution images (i.e., images higher than the preset resolution).
[0119] As a possible implementation manner, before adjusting the modules in the fifth model, the method further includes:
[0120] According to the position distance between each module in the fifth model and the input end of the fifth model, the module to be adjusted is selected from the modules.
[0121] As a possible implementation manner, before adjusting the modules in the fifth model, the method further includes:
[0122] Determining the number of modules that need to be adjusted according to a resolution difference between the resolution of the noise image and the preset resolution;
[0123] The modules that need to be adjusted are selected from the modules according to the number of modules that need to be adjusted and the position distance between each module in the fifth model and the input end of the fifth model.
[0124] As a possible implementation manner, selecting the modules to be adjusted from the modules according to the number of modules to be adjusted and the position distance between each module in the fifth model and the input end of the fifth model includes:
[0125] In the case that the number of modules to be adjusted is one, among the modules of the fifth model, the module that is closest to the input end of the fifth model is determined as the module to be adjusted;
[0126] When the number of modules to be adjusted is N, N modules are selected from the modules in order of position distance from near to far as the modules to be adjusted, where N is an integer greater than 1.
[0127] As a possible implementation manner, when the number of modules to be adjusted in the fifth model is N, adjusting the modules in the fifth model includes:
[0128] Adjusting the N modules that need to be adjusted in the fifth model so that the output of the adjusted target module meets the characteristic size corresponding to the preset resolution;
[0129] Among them, after adjustment, the difference between the input characteristic size and the output characteristic size of each of the N modules that need to be adjusted is less than the set value, and the target module is: the module among the N modules that need to be adjusted that is farthest from the input end of the fifth model, and N is an integer greater than 1.
[0130] As a possible implementation, the fifth model includes U-Net; and adjusting the modules in the fifth model includes:
[0131] The modules in the downsampling path and the modules in the upsampling path in the U-Net are adjusted so that the output of the adjusted modules in the downsampling path conforms to the feature size corresponding to the preset resolution, and the output of the adjusted modules in the upsampling path conforms to the feature size corresponding to the resolution of the noise image.
[0132] As a possible implementation, at least one of the following adjustments is made to the modules in the fifth model:
[0133] adjusting parameters of the module;
[0134] A target operation layer is added to the module, and the target operation layer is used to adjust the characteristic size corresponding to the output of the module.
[0135] As a possible implementation, the target operation layer includes at least an adaptive pooling layer, and the adaptive pooling layer is used to adjust its own parameters according to an input feature size and a preset output feature size.
[0136] In this embodiment, the specific description of the fourth model and the fifth model can refer to the relevant embodiment of the third model mentioned above, and this embodiment can achieve the same effect as the image generation method embodiment described in the first aspect above. In order to avoid repetition, they are not repeated here.
[0137] It should be noted that, for the method embodiments, for the sake of simplicity, they are all expressed as a series of action combinations, but those skilled in the art should be aware that the embodiments of the present application are not limited by the described order of actions, because according to the embodiments of the present application, certain steps can be performed in other orders or simultaneously. Secondly, those skilled in the art should also be aware that the embodiments described in the specification are all preferred embodiments, and the actions involved are not necessarily required by the embodiments of the present application.
[0138] Figure 5 : is a structural schematic diagram of an image generating device according to an embodiment of the present application, the image generating device comprising:
[0139] An image generation module, configured to generate an image based on the first image using the first model and the second model to obtain a second image when the resolution of the first image is higher than a preset resolution, wherein the resolution of the second image is not lower than the resolution of the first image;
[0140] Among them, the first model is obtained by adjusting the modules in the second model, and the output of the adjusted modules conforms to the feature size corresponding to the preset resolution; the second model is a pre-trained image generation model.
[0141] Optionally, the device further comprises:
[0142] The first selection module is used to select the module that needs to be adjusted from the modules according to the position distance between each module in the second model and the input end of the second model.
[0143] Optionally, the device further comprises:
[0144] A first processing module, used for determining the number of modules to be adjusted according to a resolution difference between a resolution of the first image and the preset resolution;
[0145] The second selection module is used to select the modules that need to be adjusted from the modules according to the number of modules that need to be adjusted and the position distance between each module in the second model and the input end of the second model.
[0146] Optionally, the second selection module includes:
[0147] A first selection submodule is used for, when the number of modules to be adjusted is one, determining, among the modules of the second model, the module with the closest position distance to the input end of the second model as the module to be adjusted;
[0148] The second selection submodule is used to select N modules from the modules as the modules to be adjusted in the order of position distance from near to far when the number of modules to be adjusted is N, where N is an integer greater than 1.
[0149] Optionally, the second selection submodule includes:
[0150] A third selection submodule is used to adjust the N modules that need to be adjusted in the second model so that the output of the adjusted target module meets the characteristic size corresponding to the preset resolution;
[0151] Among them, the difference between the input characteristic size and the output characteristic size of each of the N modules that need to be adjusted after adjustment is less than the set value, and the target module is: the module among the N modules that need to be adjusted that is farthest from the input end of the second model, and N is an integer greater than 1.
[0152] Optionally, the image generation module includes:
[0153] A first generation submodule is used for inputting the first image into the first model to iterate and perform image generation for a first number of times to obtain a third image when the resolution of the first image is higher than a preset resolution;
[0154] The second generation submodule is used to input the third image into the second model to iterate and perform image generation a second number of times to obtain the second image.
[0155] Optionally, a relationship between the first execution number and the second execution number satisfies at least one of the following:
[0156] The second execution number is the difference between a preset total execution number and the first execution number, and the preset total execution number is the number of iterations required for image generation using the second model alone;
[0157] The second execution number is greater than the first execution number.
[0158] Optionally, the second model includes a pre-trained third model for noise prediction; the device further includes:
[0159] The first adjustment module is used to adjust the modules in the third model.
[0160] Optionally, the third model includes U-Net; and the first adjustment module includes:
[0161] The first adjustment submodule is used to adjust the modules in the downsampling path and the modules in the upsampling path in the U-Net so that the output of the adjusted modules in the downsampling path conforms to the feature size corresponding to the preset resolution, and the output of the adjusted modules in the upsampling path conforms to the feature size corresponding to the resolution of the first image.
[0162] Optionally, the device further comprises:
[0163] The second adjustment module is used to perform at least one of the following adjustments on the modules in the second model:
[0164] adjusting parameters of the module;
[0165] A target operation layer is added to the module, and the target operation layer is used to adjust the characteristic size corresponding to the output of the module.
[0166] Optionally, the target operation layer includes at least an adaptive pooling layer, and the adaptive pooling layer is used to adjust its own parameters according to an input feature size and a preset output feature size.
[0167] Optionally, the device further comprises:
[0168] A quality assessment module, used for assessing the quality of images generated by the second model based on images of different resolutions;
[0169] The second processing module is used to determine the preset resolution according to the quality evaluation of the image generated by the second model.
[0170] Optionally, the second processing module includes:
[0171] The first processing submodule is used to determine the image resolution based on the image with the best quality assessment among the images generated by the second model as the preset resolution.
[0172] Figure 6 : is a schematic diagram of the structure of a noise prediction device for image generation according to an embodiment of the present application, the noise prediction device for image generation comprises:
[0173] A noise prediction module, used for, when the resolution of the noise image does not match the preset resolution, using the fourth model to perform noise prediction on the noise image to obtain a prediction result, wherein the prediction result is used for fingerprint image generation or face image generation;
[0174] Among them, the fourth model is obtained by adjusting the module in the fifth model, and the output of the adjusted module conforms to the characteristic size corresponding to the preset resolution, the fifth model is a pre-trained model for noise prediction in fingerprint image generation, or the fifth model is a pre-trained model for noise prediction in face image generation.
[0175] Optionally, the device further comprises:
[0176] The third selection module is used to select the module that needs to be adjusted from the modules according to the position distance between each module in the fifth model and the input end of the fifth model.
[0177] Optionally, the device further comprises:
[0178] A third processing module, used for determining the number of modules to be adjusted according to the resolution difference between the resolution of the noise image and the preset resolution;
[0179] The fourth selection module is used to select the modules that need to be adjusted from the modules according to the number of modules that need to be adjusted and the position distance between each module in the fifth model and the input end of the fifth model.
[0180] Optionally, the fourth selection module includes:
[0181] a fourth selection submodule, configured to, when the number of modules to be adjusted is one, determine, among the modules of the fifth model, the module with the closest position distance to the input end of the fifth model as the module to be adjusted;
[0182] The fifth selection submodule is used to select N modules from the modules as the modules to be adjusted in the order of position distance from near to far when the number of modules to be adjusted is N, where N is an integer greater than 1.
[0183] Optionally, the fifth selection submodule includes:
[0184] A sixth selection submodule, used for adjusting the N modules that need to be adjusted in the fifth model, so that the output of the adjusted target module meets the characteristic size corresponding to the preset resolution;
[0185] Among them, after adjustment, the difference between the input characteristic size and the output characteristic size of each of the N modules that need to be adjusted is less than the set value, and the target module is: the module among the N modules that need to be adjusted that is farthest from the input end of the fifth model, and N is an integer greater than 1.
[0186] Optionally, the fifth model includes U-Net; and the device further includes:
[0187] The third adjustment module is used to adjust the modules in the downsampling path and the modules in the upsampling path in the U-Net so that the output of the adjusted module in the downsampling path conforms to the characteristic size corresponding to the preset resolution, and the output of the adjusted module in the upsampling path conforms to the characteristic size corresponding to the resolution of the noise image.
[0188] Optionally, the device further comprises:
[0189] The fourth adjustment module is used to perform at least one of the following adjustments on the modules in the fifth model:
[0190] adjusting parameters of the module;
[0191] A target operation layer is added to the module, and the target operation layer is used to adjust the characteristic size corresponding to the output of the module.
[0192] Optionally, the target operation layer includes at least an adaptive pooling layer, and the adaptive pooling layer is used to adjust its own parameters according to an input feature size and a preset output feature size.
[0193] It should be noted that the device embodiment is similar to the method embodiment, so the description is relatively simple, and the relevant parts can be referred to the method embodiment.
[0194] The present application also provides an electronic device, referring to Figure 7 , Figure 7 Schematic diagram of an electronic device proposed in an embodiment of the present application. Figure 7 As shown, the electronic device 100 includes: a memory 110 and a processor 120. The memory 110 and the processor 120 are connected via a bus communication. A computer program is stored in the memory 110. The computer program can be run on the processor 120 to implement the steps in the image generation method disclosed in the embodiment of the present application or the noise prediction method for image generation.
[0195] The embodiment of the present application also provides a computer-readable storage medium on which a computer program / instruction is stored. When the computer program / instruction is executed by a processor, the steps in the image generation method or the noise prediction method for image generation disclosed in the embodiment of the present application are implemented.
[0196] The embodiment of the present application also provides a computer program product, including a computer program / instruction, which, when executed by a processor, implements the steps in the image generation method or the noise prediction method for image generation disclosed in the embodiment of the present application.
[0197] The various embodiments in this specification are described in a progressive manner, and each embodiment focuses on the differences from other embodiments. The same or similar parts between the various embodiments can be referenced to each other.
[0198] Those skilled in the art will appreciate that the embodiments of the present application can be provided as methods, devices or computer program products. Therefore, the present application can adopt the form of a complete hardware embodiment, a complete software embodiment, or an embodiment in combination with software and hardware. Moreover, the present application can adopt the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.
[0199] The embodiments of the present application are described with reference to the flowcharts and / or block diagrams of the methods, apparatuses, electronic devices, and computer program products according to the embodiments of the present application. It should be understood that each process and / or block in the flowchart and / or block diagram, as well as the combination of the processes and / or blocks in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing terminal device to generate a machine, so that the instructions executed by the processor of the computer or other programmable data processing terminal device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.
[0200] These computer program instructions may also be stored in a computer-readable memory capable of directing a computer or other programmable data processing terminal device to operate in a specific manner, so that the instructions stored in the computer-readable memory produce a manufactured product including an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.
[0201] These computer program instructions can also be loaded onto a computer or other programmable data processing terminal device so that a series of operating steps are executed on the computer or other programmable terminal device to produce a computer-implemented process, thereby providing instructions for executing on the computer or other programmable terminal device to implement the process. Figure 1 A process or multiple processes and / or boxes Figure 1 The steps for the functions specified in one or more boxes.
[0202] Although the preferred embodiments of the present application have been described, those skilled in the art may make additional changes and modifications to these embodiments once they have learned the basic creative concept. Therefore, the appended claims are intended to be interpreted as including the preferred embodiments and all changes and modifications that fall within the scope of the embodiments of the present application.
[0203] Finally, it should be noted that, in this article, relational terms such as first and second, etc. are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or terminal device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or terminal device. In the absence of further restrictions, the elements defined by the sentence "including one..." do not exclude the existence of other identical elements in the process, method, article or terminal device including the elements.
[0204] The above is a detailed introduction to an image generation method, a noise prediction method for image generation and related equipment provided by the present application. Specific examples are used in this article to illustrate the principles and implementation methods of the present application. The description of the above embodiments is only used to help understand the method of the present application and its core idea. At the same time, for a person skilled in the art, according to the idea of the present application, there will be changes in the specific implementation method and application scope. In summary, the content of this specification should not be understood as a limitation on the present application.
Claims
1. An image generation method, characterized in that: The method comprises: When the resolution of the first image is higher than the preset resolution, generate an image based on the first image using the first model and the second model to obtain a second image, wherein the resolution of the second image is not lower than the resolution of the first image; Among them, the first model is obtained by adjusting the modules in the second model, and the output of the adjusted modules conforms to the feature size corresponding to the preset resolution; the second model is a pre-trained image generation model.
2. The method according to claim 1, characterized in that Before adjusting the modules in the second model, the method further includes: According to the position distance between each module in the second model and the input end of the second model, the module to be adjusted is selected from the modules.
3. The method according to claim 1, characterized in that: Before adjusting the modules in the second model, the method further includes: Determining the number of modules to be adjusted according to a resolution difference between a resolution of the first image and the preset resolution; The modules that need to be adjusted are selected from the modules according to the number of modules that need to be adjusted and the position distance between each module in the second model and the input end of the second model.
4. The method according to claim 3, characterized in that According to the number of modules to be adjusted and the position distance between each module in the second model and the input end of the second model, the modules to be adjusted are selected from the modules, including: In the case that the number of modules to be adjusted is one, among the modules of the second model, the module that is closest to the input end of the second model is determined as the module to be adjusted; When the number of modules to be adjusted is N, N modules are selected from the modules in order of position distance from near to far as the modules to be adjusted, where N is an integer greater than 1.
5. The method according to claim 1, characterized in that When the number of modules to be adjusted in the second model is N, adjusting the modules in the second model includes: Adjusting the N modules that need to be adjusted in the second model so that the output of the adjusted target module meets the characteristic size corresponding to the preset resolution; Among them, after adjustment, the difference between the input characteristic size and the output characteristic size of each of the N modules that need to be adjusted is less than the set value, and the target module is: the module among the N modules that need to be adjusted that is farthest from the input end of the second model, and N is an integer greater than 1.
6. The method according to claim 1, characterized in that When the resolution of the first image is higher than the preset resolution, generating an image based on the first image using the first model and the second model to obtain the second image includes: When the resolution of the first image is higher than the preset resolution, inputting the first image into the first model to iterate and perform image generation for a first number of times to obtain a third image; The third image is input into the second model to iteratively generate an image a second number of times to obtain the second image.
7. The method according to claim 6, characterized in that The relationship between the first execution number and the second execution number satisfies at least one of the following: The second execution number is the difference between a preset total execution number and the first execution number, and the preset total execution number is the number of iterations required for image generation using the second model alone; The second execution number is greater than the first execution number.
8. The method according to claim 1, characterized in that The second model includes a pre-trained third model for noise prediction; adjusting the modules in the second model includes: The modules in the third model are adjusted.
9. The method according to claim 8, characterized in that The third model includes U-Net; and adjusting the modules in the third model includes: The modules in the downsampling path and the modules in the upsampling path in the U-Net are adjusted so that the output of the adjusted modules in the downsampling path conforms to the feature size corresponding to the preset resolution, and the output of the adjusted modules in the upsampling path conforms to the feature size corresponding to the resolution of the first image.
10. The method according to any one of claims 1 to 9, characterized in that: Make at least one of the following adjustments to the modules in the second model: adjusting parameters of the module; A target operation layer is added to the module, and the target operation layer is used to adjust the characteristic size corresponding to the output of the module.
11. The method according to any one of claims 1 to 9, characterized in that: Before generating an image based on the first image using the first model and the second model to obtain the second image, the method further includes: Evaluating the quality of images generated by the second model based on images of different resolutions; The preset resolution is determined according to a quality assessment of the image generated by the second model.
12. A noise prediction method for image generation, characterized in that: The method comprises: When the resolution of the noise image does not match the preset resolution, a fourth model is used to perform noise prediction on the noise image to obtain a prediction result, and the prediction result is used for fingerprint image generation or face image generation; Among them, the fourth model is obtained by adjusting the module in the fifth model, and the output of the adjusted module conforms to the characteristic size corresponding to the preset resolution, the fifth model is a pre-trained model for noise prediction in fingerprint image generation, or the fifth model is a pre-trained model for noise prediction in face image generation.
13. An electronic device comprising a memory, a processor and a computer program stored in the memory, characterized in that: The processor executes the computer program to implement the image generation method according to any one of claims 1 to 11, or to implement the noise prediction method for image generation according to claim 12.
14. A computer-readable storage medium having a computer program / instruction stored thereon, characterized in that: When the computer program / instructions are executed by a processor, the image generation method according to any one of claims 1 to 11 is implemented, or the noise prediction method for image generation according to claim 12 is implemented.
15. A computer program product comprising a computer program / instructions, characterized in that When the computer program / instructions are executed by a processor, the image generation method according to any one of claims 1 to 11 is implemented, or the noise prediction method for image generation according to claim 12 is implemented.
