A method of dynamic image editing based on diffusion model
By adopting a two-stage design of editing effect initialization and sequence frame smoothing in the diffusion model, the problem of difficulty in balancing single editing intensity and consistency in image editing is solved, and efficient and smooth dynamic editing effects are achieved.
Patent Information
- Application Number
- CN202411080271.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-08-08
- Publication Date
- 2024-10-01
- Estimated Expiration
- 2044-08-08
AI Technical Summary
Image editing methods based on the diffusion model can only generate results with a single editing intensity, making it difficult to predict the editing effect, and it is difficult for existing models to take into account both editing effect and image consistency.
A two-stage design is adopted: editing effect initialization and sequence frame smoothing. Edit frame feature tensors with different editing strengths are obtained through linear interpolation, and self-attention and prediction noise are interpolated to ensure the coherence and visual effects of dynamic editing sequences.
It realizes the one-time generation of dynamic editing sequences with different editing intensities, improves the efficiency and effect of image editing, maintains the structure and background of the initial image, and reduces computational overhead and the generation of irrelevant components.
Smart Images

Figure CN118608660B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of image editing, and in particular to a method for dynamic image editing based on a diffusion model. Background Art
[0002] Image generation and editing are very important tasks in the field of computer vision. The diffusion model has very powerful capabilities in the field of image generation. It maps the image space to the feature space of the autoencoder, and then maps the feature space to the normal distribution of random noise through several steps of Markov chain. During inference, a clear image can be obtained by denoising the normal noise step by step through diffusion. However, the image editing method based on the diffusion model can only generate a single editing result, and a single generation is difficult to meet user needs.
[0003] Unet (U-type neural network) is the core structure of the diffusion model. At present, the advanced image editing models based on the diffusion model, such as Prompt2Prompt (editing model based on prompting), MasaCtrl (editing model based on mutual self-attention control), and PnP (Plug-and-Play, plug-and-play editing model based on diffusion features) generally use DDIMInversion (denoising implicit diffusion model inversion) to obtain the initial noise containing the original image information, and then operate the feature tensor in the Unet upsampling process or the Attention map in the attention module to complete the editing operation, such as style transfer and local replacement. However, it is difficult to know in advance the effect of this editing operation applied to the input image. In order to obtain results with different editing strengths, Fatezero (video editing model based on fused attention) can be used to copy the initial image and edit it as a video, or DDIM Inversion can be used to generate an image with editing effects first, and then interpolate frame by frame in the noise space. The current image interpolation model DiffInterp (image interpolation based on diffusion model), image transformation model Warp&Blend (transformation model based on image distortion), and Diffmorpher (image transformation based on diffusion model) can generate intermediate sequences after obtaining the editing results, but these three models all rely on the existing target image for interpolation, and it is difficult for the intermediate results to have a good linear transformation and maintain the structure of the original image. The Clip-Score (image text comparison training score) of a single frame in the dynamic editing sequence is measured, and then the difference between adjacent frames is calculated. The variance of the difference is used as the performance indicator, the path variance (ClipPath Variance, CPV) of the image text comparison training score, to measure the smoothness of the change of the sequence frame. The performance of DiffInterp / WarpBlend / Diffmorpher for local editing on the DirectInversion (diffusion model direct inversion) dataset is 4.11 / 1.42 / 1.24 (the lower the better). These methods require both the initial image and the edited target image as input, while our method only needs to input the initial image. After being initialized by the effect of the first stage, it is interpolated in the noise space, and then the sequence frame smoothing of the second stage is used to enhance the spatiotemporal consistency between frames. It can generate coherently changing dynamically edited sequence frames at one time, achieving an excellent performance of 1.03 on the same dataset. Summary of the invention
[0004] The technical problem to be solved by the present invention is that the diffusion model has limitations when performing image editing. It can only give results of a single editing intensity, and its editing effect cannot be roughly judged before the model is run. It can only repeatedly generate results that may not be satisfactory by adjusting hyperparameters, and this process is very time-consuming. To obtain editing results of intermediate intensity, it can also be obtained by interpolation between the initial image and the target result, but it is difficult for existing models to simultaneously take into account good editing effects and image consistency. Therefore, the present invention aims to propose a new architecture Generative Dynamics for text-guided image Translation (GDT), which adopts a two-stage design of editing effect initialization and sequence frame smoothing to simultaneously generate dynamic editing sequences of different intensities and smoothly changing, solve the problem that the diffusion model can only generate a single editing intensity of the image, and smooth these sequence frames by interpolating self-attention and prediction noise. Through these contributions, the present invention aims to improve the image editing effect of the diffusion model and generate user-satisfactory results more quickly.
[0005] The technical solution adopted by the present invention is as follows:
[0006] A method for dynamic image editing based on a diffusion model, characterized in that the method for dynamic image editing based on a diffusion model includes two stages: initialization of editing effect and smoothing of sequence frames;
[0007] The editing effect initialization refers to: using a pre-trained diffusion model-based image editing model, embedding the editing effect into the initial potential noise after noise addition, and obtaining the editing frame feature tensor with different editing strengths through linear interpolation;
[0008] The sequence frame smoothing includes two parts: interpolating self-attention and interpolating prediction noise;
[0009] The self-attention is interpolated: first, different frames are extracted to generate self-attention features, and the self-attention features include three types: Q, K, and V; then, K and V are interpolated, so that the final generated dynamic editing sequence frame can achieve better visual effects without losing the original structure;
[0010] The predicted noise is interpolated to adjust the denoising direction of images with different editing intensities in the potential noise space, so that the images with different editing intensities are consistent with their own editing degrees, and the generation of transparent ghosts is reduced.
[0011] The specific process of editing effect initialization is as follows:
[0012] (1.1) The initial image is encoded by the autoencoder VAE, which encodes the image from the RGB color space to a smaller latent feature space;
[0013] (1.2) After obtaining the feature tensor of the latent feature space, the encoded result is denoised to obtain the initial latent noise containing the initial image information, and the original frame feature tensor corresponding to the time step d is saved; the time step d is selected based on experience.
[0014] (1.3) After obtaining the initial potential noise, denoising is started. During the denoising process, it is necessary to determine whether the current time step size is greater than the value d set in step (1.2). If it is greater than d, a feature tensor embedded with the editing effect is generated using an image editing model based on a diffusion model until the time step size is no longer greater than d;
[0015] (1.4) When the time step reaches d, the feature tensor embedded with the editing effect and the original frame feature tensor corresponding to the time step d saved in step (1.2) are used to perform linear interpolation in the latent feature space, and latent noise tensors with different editing strengths are obtained according to different interpolation coefficients;
[0016] (1.5) The latent noise tensors with different editing intensities obtained after processing in step (1.4) are adjusted so that the images with different editing intensities are consistent with the initial images in color and tone, thereby obtaining the editing frame feature tensors with different editing intensities that have completed the initialization of the editing effect.
[0017] The specific process of sequence frame smoothing is as follows:
[0018] Determine whether the time step after the editing effect initialization is greater than 0. If it is greater than 0, perform the second stage of denoising. The second stage of denoising first interpolates the self-attention and then the predicted noise. After that, when the time step reaches 0, use the autoencoder VAE to decode the edit frame feature tensors of different editing intensities, and restore them from a smaller potential feature space to the RGB image space to obtain the final output dynamic editing sequence frame.
[0019] The interpolation of self-attention is performed in Unet, and the process is:
[0020] (2.1) First, the original frame feature tensor and the edited frame feature tensors with different editing strengths are grouped and normalized and 1×1 convolved to map them to three features Q, K, and V, which represent query, key value, and value item, respectively. K and V features are extracted, and then linear interpolation operations are used on K and V features according to the coefficients of the editing strength to inject the information of the initial image into the edited frame feature tensors with different editing strengths.
[0021] (2.2) Calculate self-attention, perform hierarchical normalization, and use cross-attention to introduce text prompts used for image editing; the result of cross-attention is hierarchically normalized, and then the feed-forward layer uses a linear transformation to map the data to a high dimension and then reduce it to a low dimension, and finally undergoes a 1×1 convolution to obtain the edited frame feature tensor after self-attention interpolation.
[0022] The process of interpolating the predicted noise is as follows: inputting the original frame feature tensor and the edited frame feature tensor with different editing strengths into Unet, and outputting the predicted noise of the original frame and the predicted noise of the edited frame with different editing strengths respectively; after obtaining the output of the two predicted noises and before denoising to the next time step, linear interpolation is performed to complete different corrections in the denoising direction, and then denoising to obtain the edited frame feature tensors with different editing strengths for the next time step; by interpolating the predicted noise, the dynamic editing sequence frames outputted finally can have better image quality and smoother visual changes.
[0023] The diffusion model-based image editing model is PnP, Prompt2Prompt or MasaCtrl.
[0024] Compared with the prior art, the present invention has the following beneficial effects:
[0025] 1. The image dynamic editing method based on the diffusion model provided by the present invention constructs a two-stage editing method that decomposes the original single-stage denoising process of the diffusion model into editing effect initialization and sequence frame smoothing, which can generate dynamic editing sequence frames with different editing intensities at one time.
[0026] 2. The image dynamic editing method based on the diffusion model provided by the present invention provides a dynamic editing framework that can be applied to different diffusion models of image editing. In the editing effect initialization stage, only a single frame image needs to be processed, which improves the efficiency of generating image frames, and in the sequence frame smoothing stage, the information fusion between different frames is increased by interpolating self-attention and prediction noise, so that the output result is not only smooth and coherent in visual effect, but also maintains the structure and background of the initial image.
[0027] 3. The self-attention mechanism is to calculate the correlation between the image itself and itself. In the video editing model Fatezero, the spatiotemporal attention mechanism is used to improve the smoothness between video frames and reduce motion blur and incoherence in the video. However, its solution is to superimpose the attention maps of different frames and then perform calculations, which not only brings a large amount of computational overhead, but also makes the editing strength of different frames converge. The self-attention interpolation method adopted by the GDT of the present invention is to inject the self-attention map of the initial image into other frames by interpolation, which will not bring additional computational burden and will not weaken the editing strength of the dynamic editing sequence frames.
[0028] 4. The noise predicted by Unet represents a direction of image denoising. Therefore, for the denoising of the initial image, the direction from the normal space to the initial image is obtained, while for the denoising of the target image, the direction from the normal space to the target image is obtained. By interpolating these two noises, the denoising direction of the image corresponding to different editing intensities can be obtained. Using self-attention and interpolation of predicted noise at the same time in the denoising process at a later time step can reduce the irrelevant components generated in the dynamic editing sequence frames while maintaining most of the structural features of the initial image, and achieve better visual effects. Based on the above reasons, the present invention can be widely promoted in the field of image editing of diffusion models. BRIEF DESCRIPTION OF THE DRAWINGS
[0029] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative labor.
[0030] Figure 1 It is the overall framework diagram of the present invention.
[0031] Figure 2 A diagram of a self-attention interpolation structure provided in an embodiment of the present invention.
[0032] Figure 3 A diagram of a prediction noise interpolation architecture provided by an embodiment of the present invention DETAILED DESCRIPTION
[0033] It should be noted that, in the absence of conflict, the embodiments of the present invention and the features in the embodiments can be combined with each other. The present invention will be described in detail below with reference to the accompanying drawings and in combination with the embodiments.
[0034] Example 1
[0035] In this embodiment, the GDT model proposed in the present invention is implemented based on the pre-trained Stable Diffusion-v1.5 (stable diffusion model version 1.5), and no parameters need to be fine-tuned during the inference process. The diffusion model inference process is set to 50 time steps. We divide the denoising step containing 50 time steps into a 35-step editing effect initialization stage and the remaining 15-step sequence frame smoothing stage. For the editing effect initialization, we use PnP for image editing. The generated dynamic editing sequence frame length is set to 6, and the resolution is 512×512. All experiments were conducted on an NVIDIA A800 GPU.
[0036] In order to solve the problem that the diffusion model can only output a single editing result at a time when editing images based on the wording in this article, the present invention splits the originally fixed single-stage denoising into two different stages: editing effect initialization and sequence frame smoothing. To obtain multiple images with different editing degrees using traditional methods, you can adjust hyperparameters to generate them frame by frame, or copy the initial image to edit it in the form of a video. The former cannot achieve information interaction between frames, and the serial output will consume more time, while the latter places higher requirements on video memory capacity. Our two-stage denoising method only needs to process a single frame in the editing effect initialization stage of the earlier denoising time step, and obtains the editing frame feature tensors of different editing intensities through interpolation and adjustment of potential noise, which are input into the second stage for inter-frame smoothing at a later time step, greatly improving the editing efficiency.
[0037] like Figure 1 As shown, the specific process of initializing the editing effect is as follows:
[0038] (1.1) The initial image is encoded by the autoencoder VAE, encoding the image from the RGB color space (3, 512, 512) to the latent feature space of (4, 64, 64);
[0039] (1.2) After obtaining the feature tensor of the latent feature space, use DDIM Inversion to add noise to the encoded result, obtain the initial latent noise containing the initial image information, and save the original frame feature tensor corresponding to the time step d;
[0040] (1.3) After obtaining the initial potential noise, we start to denoise it. The total number of denoising time steps is 50. When the time step is greater than the set value d (d=15 in this experiment), the first stage of editing effect initialization is performed. During the denoising process, it is necessary to determine whether the current time step size is greater than the value d set in step (1.2). When it is greater than d, the image editing model PnP based on the diffusion model is used to generate a feature tensor embedded with the editing effect until the time step size is no longer greater than d.
[0041] (1.4) When the time step reaches d, use the feature tensor embedded with the editing effect and the original frame feature tensor corresponding to the time step d saved in the DDIMInversion process in step (1.2) to perform linear interpolation in the latent feature space, and obtain latent noise tensors with different editing strengths according to different interpolation coefficients;
[0042] (1.5) Use AdaIN (adaptive instance normalization) to adjust the latent noise tensors with different editing intensities obtained after processing in step (1.4) so that the images with different editing intensities are consistent with the initial images in color and tone, and obtain the edited frame feature tensors with different editing intensities that have completed the initialization of the editing effect.
[0043] Determine whether the time step after the editing effect is initialized is greater than 0. If it is greater than 0, perform the second stage of denoising. The second stage of denoising first interpolates the self-attention, then interpolates the predicted noise, and then uses the autoencoder VAE to decode the edit frame feature tensors of different editing intensities when the time step reaches 0, and restores them from the smaller (4, 64, 64) potential feature space to the (3, 512, 512) RGB image space to obtain the final output dynamic editing sequence frame. The specific process of the sequence frame smoothing is as follows:
[0044] like Figure 2 As shown, the interpolation of self-attention is performed in Unet, and the process is:
[0045] (2.1) First, the original frame feature tensor and the edited frame feature tensors with different editing strengths are grouped and normalized and 1×1 convolved to map them to three features Q, K, and V, which represent query, key value, and value item, respectively. K and V features are extracted, and then linear interpolation operations are used on K and V features according to the coefficients of the editing strength to inject the information of the initial image into the edited frame feature tensors with different editing strengths.
[0046] (2.2) Calculate self-attention, perform hierarchical normalization, and use cross-attention to introduce text prompts used for image editing; the result of cross-attention is hierarchically normalized, and then the feed-forward layer uses a linear transformation to map the data to a high dimension and then reduce it to a low dimension, and finally undergoes a 1×1 convolution to obtain the edited frame feature tensor after self-attention interpolation.
[0047] like Figure 3 As shown, the process of interpolating the predicted noise is as follows: the original frame feature tensor and the edited frame feature tensor with different editing strengths are input into Unet, and the predicted noise of the original frame and the predicted noise of the edited frame with different editing strengths are output respectively; after obtaining the output of the two predicted noises and before denoising to the next time step, linear interpolation is performed to complete different corrections in the denoising direction, and then denoising is performed to obtain the edited frame feature tensors with different editing strengths for the next time step; by interpolating the predicted noise, the dynamic editing sequence frames outputted in the end can have better image quality and smoother visual changes.
[0048] For the attention mechanism in the diffusion model, cross attention is to calculate the relationship between the image modality and the text modality, so that the image denoising process can be guided by the text prompt and obtain the editing result that meets the target effect. The self-attention mechanism is to calculate the relationship between the image and itself, so the self-attention interpolation of different images can effectively perceive the information between frames. After the predicted noise is interpolated, the denoising direction of images with different editing degrees is optimized, so that they can each be denoised to a clear image of the corresponding editing intensity, improving the visual quality and smoothness of changes. Following the dataset used by DirectInversion before, our GDT model is evaluated using the variance indicator of the Clip-Score difference between adjacent frames, and then compared with other models on this basis. The editing tasks are divided into two categories: style transfer acting on the entire image and target editing acting on a local area. The style transfer task is also subdivided into three types: style, genre, and artist. For the 700 images in the dataset, each image is equipped with a corresponding text description, as well as three transfer styles and a local editing text prompt.
[0049] For the three image interpolation methods DiffInterp / Warp&Blend / Diffmorpher, both the initial image and the target image are required. We use the edited result obtained by DDIM Inversion as the target image. DiffInterp first adds random noise to the two input images, and then performs iterative denoising during the interpolation process to continuously generate intermediate frames, and uses the Clip model to filter the output results with higher scores. Although DiffInterp avoids the large amount of time loss caused by frame-by-frame denoising, there is no information interaction between frames during the denoising process, so the generated sequence frames change very drastically, and many irrelevant components that reduce the image quality will be generated. The performance of style transfer in the three categories of style / genre / artist and local editing, which is a total of four tasks, is 2.45 / 2.56 / 2.68 / 4.11 respectively. Warp&Blend uses feature matching to align the feature points of the two images first, and then realizes the dynamic transformation of the image according to the position mapping of the feature points. Although the change is relatively smooth, the visual quality of the intermediate result is very poor, and the performance is 1.02 / 1.07 / 0.71 / 1.42. Compared with DiffInterp, Diffmorpher uses the trainable parameter Lora to obtain the semantic information of the starting image and the target image in addition to interpolating in the feature space of the diffusion model. The interpolation of Lora is used to improve the spatiotemporal consistency of the intermediate results and increase the information fusion between frames. However, the trainable parameters bring additional computational overhead, and the effect of this method is subject to the quality of the given target image. The performance is 0.83 / 0.78 / 0.34 / 1.14. In contrast, our GDT model adopts a two-stage denoising method, using AdaIN to adjust the feature tensor to maintain the uniformity of the tone, and then combines efficient self-attention and predicted noise interpolation to smooth the intermediate frames. The whole process does not require any parameter training. Compared with the above methods, the GDT model only requires the initial image as input, so the quality of the generated sequence does not depend on the target image, and the performance is 0.65 / 0.64 / 0.25 / 1.03.
[0050] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit it. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or replace some or all of the technical features therein with equivalents. However, these modifications or replacements do not cause the essence of the corresponding technical solutions to deviate from the scope of the technical solutions of the embodiments of the present invention.
Claims
1. A method for dynamic image editing based on a diffusion model, characterized in that: The image dynamic editing method based on diffusion model includes two stages: editing effect initialization and sequence frame smoothing; The specific process of initializing the editing effect is as follows: (1.1) The initial image is encoded by the autoencoder VAE, which encodes the image from the RGB color space to a smaller latent feature space; (1.2) After obtaining the feature tensor of the latent feature space, add noise to the encoded result to obtain the initial latent noise containing the initial image information, and save the original frame feature tensor corresponding to the time step d; (1.3) After obtaining the initial potential noise, denoising is started. During the denoising process, it is necessary to determine whether the current time step size is greater than the value d set in step (1.2). If it is greater than d, a feature tensor embedded with the editing effect is generated using an image editing model based on a diffusion model until the time step size is no longer greater than d; (1.4) When the time step reaches d, the feature tensor embedded with the editing effect and the original frame feature tensor corresponding to the time step d saved in step (1.2) are used to perform linear interpolation in the latent feature space, and latent noise tensors with different editing strengths are obtained according to different interpolation coefficients; (1.5) adjusting the latent noise tensors with different editing intensities obtained after processing in step (1.4) so that the images with different editing intensities are consistent with the initial images in color and tone, thereby obtaining edited frame feature tensors with different editing intensities that have completed the initialization of the editing effect; The specific process of sequence frame smoothing is as follows: Determine whether the time step after the editing effect initialization is greater than 0. If it is greater than 0, perform the second stage of denoising. The second stage of denoising first interpolates the self-attention and then the predicted noise. After that, when the time step reaches 0, use the autoencoder VAE to decode the edit frame feature tensors of different editing intensities, and restore them from a smaller potential feature space to the RGB image space to obtain the final output dynamic editing sequence frame.
2. The method for dynamic image editing based on diffusion model according to claim 1, characterized in that: The interpolation of self-attention is performed in Unet, and the process is: (2.1) First, the original frame feature tensor and the edited frame feature tensors with different editing strengths are grouped and normalized and 1×1 convolved to map them to three features Q, K, and V, which represent query, key value, and value item, respectively. K and V features are extracted, and then linear interpolation operations are used on K and V features according to the coefficients of the editing strength to inject the information of the initial image into the edited frame feature tensors with different editing strengths. (2.2) Calculate self-attention, perform hierarchical normalization, and use cross-attention to introduce text prompts used for image editing; the result of cross-attention is hierarchically normalized, and then the feed-forward layer uses a linear transformation to map the data to a high dimension and then reduce it to a low dimension, and finally undergoes a 1×1 convolution to obtain the edited frame feature tensor after self-attention interpolation.
3. The method for dynamic image editing based on diffusion model according to claim 1, characterized in that: The process of interpolating the predicted noise is as follows: inputting the original frame feature tensor and the edited frame feature tensor with different editing strengths into Unet, and outputting the predicted noise of the original frame and the predicted noise of the edited frame with different editing strengths respectively; after obtaining the output of the two predicted noises and before denoising to the next time step, linear interpolation is performed to complete different corrections in the denoising direction, and then denoising to obtain the edited frame feature tensors with different editing strengths for the next time step; by interpolating the predicted noise, the dynamic editing sequence frames outputted finally can have better image quality and smoother visual changes.
4. The method for dynamic image editing based on diffusion model according to claim 1, characterized in that: The diffusion model-based image editing model is PnP, Prompt2Prompt or MasaCtrl.
