Image editing method, image editing device and storage medium

The face consistency is optimized through the target diffusion model and fusion module, and the mask image is fused in the initial image generation module, which solves the problems of face consistency and naturalness of graphic restoration in image editing, and improves the prediction accuracy of the model.

CN118799447APending Publication Date: 2024-10-18CHINA MOBILE COMM LTD RES INST +1
View PDF 0 Cites 1 Cited by

Patent Information

Application Number
CN202410302507.6
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-03-15
Publication Date
2024-10-18

AI Technical Summary

Technical Problem

Existing image editing models have problems in face consistency and naturalness of graphic restoration, resulting in poor prediction accuracy. Especially when editing hairstyles and repairing clothing with complex textures, the similarity of faces and expressions change, and unnatural filling of gaps occurs. Color blocks appear.

Method used

Using the target diffusion model, combined with the fusion module and the target image generation module, the face consistency is optimized by fusing the feature map and mask map of the image to be predicted, and the repair module is used in the initial image generation module to combine the random mask and the training image The weight map fusion improves the naturalness of image restoration.

Benefits of technology

While ensuring the consistency of the face, it achieves more natural image restoration and improves the prediction accuracy of the model, especially the image editing effect in complex clothing and hairstyle editing scenarios.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118799447A_ABST
    Figure CN118799447A_ABST
Patent Text Reader

Abstract

The embodiment of the invention provides an image editing method, an image editing device and a storage medium, and the method comprises the steps: inputting a to-be-predicted image to a target diffusion model through the image editing device, and obtaining a first target image corresponding to the to-be-predicted image; wherein the target diffusion model comprises a fusion module and a target image generation module, and the fusion module is used for performing fusion processing on a first feature map corresponding to the to-be-predicted image and a second feature map corresponding to the to-be-predicted image; the target diffusion model is obtained by training an initial image generation module based on a training image set; and the initial image generation module comprises a restoration module, and the restoration module is used for carrying out fusion processing on the random mask and an initial weight map corresponding to a second target image in the training image set, so that the prediction accuracy of the model can be improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of artificial intelligence technology, and in particular to an image editing method, an image editing device and a storage medium. Background Art

[0002] Text-driven image generation generates images through text prompts, while text-driven image editing uses text prompts to modify the content of the input image. In other words, image editing adds a process of image input and reconstruction of the original image on the basis of text-driven images. The editing content can be global, such as stylizing the image, modifying the weather and season, etc.; it can also be local, such as face editing, clothing editing, hair editing and background editing. The main methods in the field of image editing are Generative Adversarial Network (GAN) and Latent Diffusion Model (LDM).

[0003] However, the above models have the following shortcomings in the field of image editing: (1) Face consistency problem. During the image editing process, when the edited object changes, other parts often change as well. In particular, during the hairstyle editing process, the similarity and expression of the face are also prone to change; (2) Image restoration unnatural problem. For example, in scenarios such as changing long hair to short hair or removing bangs, the corresponding part of the original image needs to be filled. However, there is currently no optimization for this problem, and the filled part is often unnatural. In particular, clothes with complex textures will have obvious irregular and unnatural color blocks. In summary, the above models have problems with face consistency and unnatural image restoration when performing image editing, which leads to poor prediction accuracy of the model. Summary of the invention

[0004] The embodiments of the present application provide an image editing method, an image editing device, and a storage medium, which can solve the problem of facial consistency and the problem of unnatural graphics restoration, thereby improving the prediction accuracy of the model.

[0005] The technical solution of the embodiment of the present application is implemented as follows:

[0006] In a first aspect, an embodiment of the present application provides an image editing method, the method comprising:

[0007] Inputting the image to be predicted into the target diffusion model to obtain a first target image corresponding to the image to be predicted; wherein the target diffusion model includes a fusion module and a target image generation module, and the fusion module is used to fuse the first feature map corresponding to the image to be predicted and the second feature map corresponding to the image to be predicted;

[0008] The target diffusion model is obtained by training an initial image generation module based on a training image set; the initial image generation module includes a repair module, which is used to fuse the random mask and the initial weight map corresponding to the second target image in the training image set.

[0009] In a second aspect, an embodiment of the present application provides an image editing device, the image editing device comprising: an input unit;

[0010] The input unit is used to input the image to be predicted into the target diffusion model to obtain a first target image corresponding to the image to be predicted; wherein the target diffusion model includes a fusion module and a target image generation module, and the fusion module is used to fuse the first feature map corresponding to the image to be predicted and the second feature map corresponding to the image to be predicted;

[0011] The target diffusion model is obtained by training an initial image generation module based on a training image set; the initial image generation module includes a repair module, which is used to fuse the random mask and the initial weight map corresponding to the second target image in the training image set.

[0012] In a third aspect, an embodiment of the present application provides an image editing device, the image editing device comprising: a processor and a memory; wherein:

[0013] The memory is used to store a computer program that can be run on the processor;

[0014] The processor is used to execute the image editing method as described above when running the computer program.

[0015] In a fourth aspect, an embodiment of the present application provides a computer-readable storage medium, characterized in that a computer program code is stored on the storage medium, and when the computer program code is executed by a computer, the image editing method as described above is implemented.

[0016] In a fifth aspect, an embodiment of the present application provides a computer program product, including a computer program, characterized in that when the computer program is executed by a processor, it implements the image editing method as described above.

[0017] An embodiment of the present application provides an image editing method, an image editing device and a storage medium, the method comprising: the image editing device inputs an image to be predicted into a target diffusion model to obtain a first target image corresponding to the image to be predicted; wherein the target diffusion model comprises a fusion module and a target image generation module, the fusion module is used to fuse a first feature map corresponding to the image to be predicted and a second feature map corresponding to the image to be predicted; the target diffusion model is obtained by training an initial image generation module based on a training image set; the initial image generation module comprises a repair module, the repair module is used to fuse a random mask and an initial weight map corresponding to the second target image in the training image set. That is to say, the target diffusion model may include a fusion module and a target image generation module, and the fusion module can be used to fuse the first feature map corresponding to the predicted image and the second feature map corresponding to the predicted image, so as to optimize the facial consistency before and after the predicted image is edited, and the target diffusion model is obtained by training the initial image generation module based on the training image set; and the repair module in the initial image generation module can be used to fuse the random mask and the initial weight map corresponding to the second target image in the training image set, so as to make the image repair more natural, that is, when the image editing device of the present application edits the predicted image based on the target diffusion model, it can ensure the facial consistency before and after the image editing, and can perform image repair more naturally, thereby improving the prediction accuracy of the model. BRIEF DESCRIPTION OF THE DRAWINGS

[0018] Figure 1 A schematic diagram of an image editing method proposed in an embodiment of the present application;

[0019] Figure 2 A schematic diagram of the model training proposed in the embodiment of the present application;

[0020] Figure 3 A schematic diagram of the process of determining an initial weight map proposed in an embodiment of the present application;

[0021] Figure 4 A schematic diagram of the face fusion module process proposed in the embodiment of the present application;

[0022] Figure 5 A schematic diagram of the training phase flow proposed in the embodiment of the present application;

[0023] Figure 6 A schematic diagram of the sampling phase process proposed in the embodiment of the present application;

[0024] Figure 7 A schematic diagram of the flow of a clothing repair module proposed in an embodiment of the present application;

[0025] Figure 8 The structure diagram of the image editing device proposed in the embodiment of the present application is as follows: Figure 1 ;

[0026] Fig. 9 The structure diagram of the image editing device proposed in the embodiment of the present application is as follows: Figure 2 . DETAILED DESCRIPTION

[0027] The following will be combined with the accompanying drawings in the embodiments of the present application to clearly and completely describe the technical solutions in the embodiments of the present application. It is understood that the specific embodiments described herein are only used to explain the related applications, rather than to limit the applications. It should also be noted that, for ease of description, only the parts related to the related applications are shown in the accompanying drawings.

[0028] Text-driven image generation generates images through text prompts, while text-driven image editing modifies the content of the input image through text prompts. In other words, image editing adds an image input and a process of reconstructing the original image on the basis of the text image. The content of the editing can be global, such as stylizing the image, modifying the weather and season, etc.; it can also be local, such as face editing, clothing editing, hair editing and background editing. The main methods in the field of image editing are Generative Adversarial Network (GAN) and Latent Diffusion Model (LDM). GAN has achieved good results in the field of face editing, but due to the richer diversity of components such as hair, clothing, and background, GAN cannot generate satisfactory results. LDM has made great progress in diversity and can generate more realistic images containing faces, hair, clothing, background, etc.

[0029] When editing a real image, GAN generally calculates the direction vector of the attribute to be edited first, then converts the original image into a latent space embedding, moves the latent space embedding of the original image according to the direction vector of the attribute, and then inputs the moved latent space embedding into the generator, and finally the edited image is obtained. However, in GAN, reconstructing the original image is a relatively difficult task, and the reconstructed image will have a large consistency loss. LDM's image reconstruction capability is better than GAN. In the latest method, the reconstructed image and the original image can maintain the consistency at the naked eye level.

[0030] The editing process of LDM generally uses methods such as scoring functions, modifying the embedding of prompt words, and modifying the weight map of the cross attention module. Among them, modifying the weight map of the cross attention module has the best effect. This method can keep other areas basically unchanged while modifying the properties of the specified area. However, since hair shows strong diversity and often has a large overlapping area with parts such as faces and clothing, when editing hair, it is easy to cause changes in parts such as faces and clothing. In addition, when encountering scenes such as image restoration that require changing long hair to short hair, unnatural color blocks are often generated in the long hair area of ​​the original image, resulting in a significant decrease in the quality of the generated image.

[0031] However, the above models have the following shortcomings in the field of image editing: (1) Face consistency problem. During the image editing process, when the edited object changes, other parts often change as well. In particular, during the hairstyle editing process, the similarity and expression of the face are also prone to change; (2) Image restoration unnatural problem. For example, in scenarios such as changing long hair to short hair or removing bangs, the corresponding part of the original image needs to be filled. However, there is currently no optimization for this problem, and the filled part is often unnatural. In particular, clothes with complex textures will have obvious irregular and unnatural color blocks. In summary, the above models have problems with face consistency and unnatural image restoration when performing image editing, which leads to poor prediction accuracy of the model.

[0032] In order to solve the problem of face consistency and unnatural graphic restoration when the above-mentioned model is used for image editing, thereby resulting in poor prediction accuracy of the model, an embodiment of the present application provides an image editing method, an image editing device and a storage medium, the method comprising: the image editing device inputs the image to be predicted into a target diffusion model to obtain a first target image corresponding to the image to be predicted; wherein the target diffusion model comprises a fusion module and a target image generation module, the fusion module is used to fuse the first feature map corresponding to the image to be predicted and the second feature map corresponding to the image to be predicted; the target diffusion model is obtained by training the initial image generation module based on the training image set; the initial image generation module comprises a repair module, the repair module is used to fuse the random mask and the initial weight map corresponding to the second target image in the training image set. That is to say, the target diffusion model may include a fusion module and a target image generation module, and the fusion module can be used to fuse the first feature map corresponding to the predicted image and the second feature map corresponding to the predicted image, so as to optimize the facial consistency before and after the predicted image is edited, and the target diffusion model is obtained by training the initial image generation module based on the training image set; and the repair module in the initial image generation module can be used to fuse the random mask and the initial weight map corresponding to the second target image in the training image set, so as to make the image repair more natural, that is, when the image editing device of the present application edits the predicted image based on the target diffusion model, it can ensure the facial consistency before and after the image editing, and can perform image repair more naturally, thereby improving the prediction accuracy of the model.

[0033] The technical solutions in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application.

[0034] Embodiment 1

[0035] The present application embodiment provides an image editing method, Figure 1 This is a schematic diagram of the image editing method proposed in the embodiment of the present application, such as Figure 1 As shown, the image editing method may include the following steps:

[0036] Step 101: input an image to be predicted into a target diffusion model to obtain a first target image corresponding to the image to be predicted.

[0037] In an embodiment of the present application, the image editing device may input the image to be predicted into a target diffusion model to obtain a first target image corresponding to the image to be predicted.

[0038] It should be noted that, in the embodiments of the present application, the target diffusion model may include a fusion module and a target image generation module, and the present application does not specifically limit the type and number of modules included in the target diffusion model.

[0039] It should be noted that, in the embodiment of the present application, the fusion module can be used to fuse the first feature map corresponding to the image to be predicted and the second feature map corresponding to the image to be predicted.

[0040] It should be noted that, in the embodiment of the present application, the first feature map corresponding to the image to be predicted may be a feature map generated by a target image generation module.

[0041] It should be noted that, in the embodiment of the present application, the second feature map corresponding to the image to be predicted may be a feature map of the original image with a step length of t-1 and superimposed noise.

[0042] It should be noted that, in the embodiment of the present application, before inputting the image to be predicted into the target diffusion model to obtain the first target image corresponding to the image to be predicted, the image editing device may first train the initial image generation module to obtain the target diffusion model.

[0043] It should be noted that, in the embodiments of the present application, the target diffusion model can be obtained by training the initial image generation module based on the training image set and the low-rank adapter.

[0044] For example, in the embodiments of the present application, Figure 2 This is a schematic diagram of the model training proposed in the embodiment of the present application, such as Figure 2 As shown, the initial image generation module includes a Unet network structure, and the Unet network structure includes a repair module. When the image editing device trains the initial image generation module, the parameters of the initial image generation module can be fixed first, and the initial image generation module can be trained using a low-rank adapter (Low-Rank Adaptation, Lora). After the training is completed, the parameters obtained by Lora can be updated to the initial image generation module, so that the target diffusion model can be obtained.

[0045] It should be noted that, in an embodiment of the present application, the initial image generation module may include a repair module, which can be used to fuse the initial weight map corresponding to the random mask and the second target image in the training image set. The present application does not specifically limit the number and type of modules included in the initial image generation module.

[0046] It should be noted that, in the embodiments of the present application, the training image set may be a set of images with clothes, and the present application does not specifically limit the number of training image sets.

[0047] It should be noted that, in the embodiments of the present application, the second target image may be part or all of the images in the training image set, and the present application does not specifically limit the number of the second target images.

[0048] It should be noted that, in the embodiment of the present application, the initial weight map may be determined based on the target key vector corresponding to the target prompt word and the query vector corresponding to the second target image.

[0049] It should be noted that, in the embodiment of the present application, the target prompt word is determined based on a preset search strategy; the target prompt word is the prompt word corresponding to the second target image.

[0050] For example, in an embodiment of the present application, the image editing device can obtain the target prompt word (token) of "clothing" and the index value idx corresponding to the target prompt word through a preset search strategy. For example, a girl in a red coat, coat representing clothing is the sixth token, that is, idx=6.

[0051] For example, in the embodiments of the present application, Figure 3 This is a schematic diagram of the process of determining the initial weight map proposed in the embodiment of the present application, such as Figure 3 As shown, assuming that the target key vector corresponding to the target prompt word is K P , the query vector corresponding to the second target image is Then, when the image editing device determines the initial weight map based on the target key vector corresponding to the target prompt word and the query vector corresponding to the second target image, it can be calculated by the following formula (1).

[0052]

[0053] Among them, M t represents the initial weight graph, represents the query vector corresponding to the second target image, K P Represents the target key vector corresponding to the target prompt word.

[0054] It should be noted that in an embodiment of the present application, the target weight map corresponding to the initial weight map is obtained by fusing the target mask and the initial weight map corresponding to the second target image; the target mask is determined based on the random mask and the clothing mask corresponding to the second target image; the target value vector corresponding to the target weight map and the target prompt word is used to determine the third target image.

[0055] It should be noted that, in the embodiments of the present application, the clothing mask corresponding to the second target image can be obtained based on a segmentation model, and the present application does not specifically limit the type of the segmentation model.

[0056] Illustratively, in an embodiment of the present application, when determining the target mask, the image editing device may multiply the random mask and the clothing mask corresponding to the second target image bit by bit to obtain the target mask.

[0057] Exemplarily, in an embodiment of the present application, the image editing device can obtain a target weight map based on the fusion of the target mask and the initial weight map corresponding to the second target image. As shown in the following formula (2), the target weight map can be obtained by multiplying the target mask and the initial weight map corresponding to the second target image.

[0058]

[0059] Among them, M t,idx represents the initial weight graph, represents the target mask, represents the target weight map.

[0060] That is to say, in an embodiment of the present application, the image editing device can randomly set the initial weight map corresponding to the clothing prompt word to zero based on the target mask, thereby improving the clothing generation capability and making the image restoration more natural.

[0061] It should be noted that, in the embodiment of the present application, the image editing device may convert the initial weight map M into t The weight graph M of the idxth t,idx Replace with So we can get a new target weight map

[0062] It should be noted that, in the embodiment of the present application, after obtaining the target weight map, the image editing device can determine the third target image based on the target weight map and the target value vector corresponding to the target prompt word.

[0063] Exemplarily, in an embodiment of the present application, when the image editing device determines the third target image based on the target weight map and the target value vector corresponding to the target prompt word, it can be obtained by the following formula (3).

[0064]

[0065] in, represents the target weight map, V P represents the target value vector corresponding to the target prompt word, Represents the third target image.

[0066] It should be noted that, in an embodiment of the present application, the image editing device can first train the initial image generation module to obtain a target diffusion model. The initial image generation module may include a repair module. The repair module can be used to fuse the random mask and the initial weight map corresponding to the second target image in the training image set, that is, the target mask can be determined based on the random mask and the clothing mask corresponding to the second target image, and then the initial weight map corresponding to the clothing prompt word can be randomly set to zero based on the target mask, thereby improving the clothing generation capability and making the image repair more natural.

[0067] Furthermore, in an embodiment of the present application, when the image editing device inputs the image to be predicted into the target diffusion model to obtain a first target image corresponding to the image to be predicted, the image to be predicted can be input into a target image generation module to obtain a first feature map corresponding to the image to be predicted; then the first feature map and the second feature map corresponding to the image to be predicted can be input into a fusion module to obtain the first target image.

[0068] It should be noted that, in an embodiment of the present application, the image editing device can determine a preset fusion strategy based on the diffusion time step corresponding to the target diffusion model; and then can fuse the first feature map and the second feature map based on the preset fusion strategy to obtain a first target image.

[0069] It should be noted that, in an embodiment of the present application, the preset fusion strategy may be a face fusion strategy, which may be a face fusion strategy based on a progressive step size. For example, the image editing device may gradually increase the mask strength from 0 to 1, and then adjust the starting point of the mask strength according to the time step of the diffusion process T, thereby adaptively maintaining the structural features of the target image while effectively balancing the relationship between the structural features of the hairstyle and the consistency of the face.

[0070] It should be noted that in an embodiment of the present application, when the image editing device fuses the first feature map and the second feature map based on a preset fusion strategy to obtain the first target image, it can determine the third feature map corresponding to the image to be predicted based on the preset fusion strategy; and then, the first feature map and the second feature map can be fused based on the third feature map to obtain the first target image.

[0071] It should be noted that in an embodiment of the present application, when the image editing device determines the third feature map corresponding to the image to be predicted based on a preset fusion strategy, it can determine the facial semantic mask corresponding to the image to be predicted based on the segmentation model; then the third feature map can be determined based on the facial semantic mask and the preset fusion strategy.

[0072] Exemplarily, in an embodiment of the present application, when the image editing device determines the third feature map based on the face semantic mask and the preset fusion strategy, the third feature map can be obtained by the following formula (4).

[0073]

[0074] Among them, mask f represents the semantic mask of the face, T represents the total time step of diffusion, Indicates the starting point of the mask intensity, FM t represents the third feature map.

[0075] It should be noted that, in the embodiment of the present application, after determining the third feature map, the image editing device can fuse the first feature map and the second feature map based on the third feature map to obtain the first target image. As shown in the following formula (5), the image editing device can use the third feature map FM t The first feature map Z t-1 and the second feature map Z t-1,targ Perform fusion processing to obtain the first target image

[0076]

[0077] Among them, Z t-1 Represents the first feature map, FM t represents the third feature map, Z t-1,targ Represents the second feature map.

[0078] For example, in the embodiments of the present application, Figure 4 This is a schematic diagram of the face fusion module process proposed in the embodiment of the present application, such as Figure 4 As shown, assuming that the image to be predicted is Z t , input the image into the image generation module (target image generation module) to obtain the first feature map Z corresponding to the image to be predicted t-1 , then the third feature map FM can be used t The first feature map Z t-1 and the second feature map Z t-1,targ Perform fusion processing to obtain the final result, that is, the first target image

[0079] That is to say, in an embodiment of the present application, the image editing device can fuse the generated intermediate result (first feature map) and the face area (second feature map) of the original image through the face semantic mask during the sampling process to improve the face consistency.

[0080] To summarize, before the image editing device inputs the image to be predicted into the target diffusion model to obtain the first target image corresponding to the image to be predicted, the initial image generation module can be trained to obtain the target diffusion model, so that the trained target diffusion model can improve the generation capability of clothing and make the image restoration more natural. Then, the image to be predicted can be input into the target image generation module to obtain the first feature map corresponding to the image to be predicted; then the first feature map and the second feature map corresponding to the image to be predicted can be input into the fusion module to obtain the first target image, that is, the image editing device can fuse the generated intermediate result (first feature map) and the face area (second feature map) of the original image through the face semantic mask during the sampling process to improve the face consistency.

[0081] An embodiment of the present application provides an image editing method, which includes: an image editing device inputs an image to be predicted into a target diffusion model to obtain a first target image corresponding to the image to be predicted; wherein the target diffusion model includes a fusion module and a target image generation module, and the fusion module is used to fuse a first feature map corresponding to the image to be predicted and a second feature map corresponding to the image to be predicted; the target diffusion model is obtained by training an initial image generation module based on a training image set; the initial image generation module includes a repair module, and the repair module is used to fuse a random mask and an initial weight map corresponding to the second target image in the training image set. That is to say, the target diffusion model may include a fusion module and a target image generation module, and the fusion module can be used to fuse the first feature map corresponding to the predicted image and the second feature map corresponding to the predicted image, so as to optimize the facial consistency before and after the predicted image is edited, and the target diffusion model is obtained by training the initial image generation module based on the training image set; and the repair module in the initial image generation module can be used to fuse the random mask and the initial weight map corresponding to the second target image in the training image set, so as to make the image repair more natural, that is, when the image editing device of the present application edits the predicted image based on the target diffusion model, it can ensure the facial consistency before and after the image editing, and can perform image repair more naturally, thereby improving the prediction accuracy of the model.

[0082] Embodiment 2

[0083] Based on the above embodiments, another embodiment of the present application provides a text-driven hairstyle editing method (image editing method), in which the present application adds a clothing repair module (repair module) and a face fusion module (fusion module) to the latent diffusion model (LDM) model; wherein the LDM model includes an image generation module, the image generation module includes a repair module, the clothing repair module (repair module) is used in the training stage, and the face fusion module (fusion module) is used in the sampling stage. In the clothing repair module, the present application proposes an algorithm for adding a random mask to the weight map of the cross attention based on LDM, which fuses the weight map of the cross attention (initial weight map) and the random mask, and randomly resets the weights of some clothing to zero to improve the generation ability of clothing. In the face fusion module, the present application proposes a progressive face fusion method, which fuses the intermediate result (first feature map) and the original face area (second feature map) based on the face segmentation mask and the sampling step size to optimize the face consistency before and after image editing. The two modules are introduced in detail below.

[0084] It should be noted that, in the embodiments of the present application, Figure 5 The following is a flow chart of the training phase proposed in the embodiment of the present application, as shown in FIG. Figure 5 As shown, during the training phase, the image editing device can train the image generation module (initial image generation module) based on the original image (training image set) and the reconstruction loss function to obtain the target diffusion model (target LDM model). Figure 6 The following is a flow chart of the sampling phase proposed in the embodiment of the present application, as shown in FIG. Figure 6 As shown, in the sampling stage, the image editing device can input the original image (image to be predicted) into the target diffusion model to obtain the target image (first target image). The target diffusion model includes a fusion module (face fusion module) and an image generation module (target image generation module). The fusion module is used to fuse the first feature map corresponding to the image to be predicted and the second feature map corresponding to the image to be predicted.

[0085] It should be noted that in the embodiments of this application, due to the weak structure of clothing and relatively complex texture, in scenes that require image restoration, such as when a hairstyle changes from long to short or when bangs are removed, the filling effect of clothing often has problems such as texture distortion and unnatural splicing. This application proposes a clothing restoration method to improve the generation capability of clothing areas, which mainly acts on the training stage of the model. Figure 2As shown, the image editing device can first collect 5,000 images with clothes and obtain labels and clothing mask images; then, the cross attention module (crossattention) in the Unet structure can be replaced with a clothing repair module (repair module); finally, the image editing device can fix the parameters of the pre-trained model and use the low-rank adapter (Low-Rank Adaptation, Lora) to train the model (initial image generation module). After the training is completed, the parameters obtained by Lora are updated to the pre-trained model; wherein the initial image generation module includes a Unet network structure, and the Unet network structure can include a clothing repair module (repair module).

[0086] It should be noted that, in the embodiments of the present application, Figure 7 This is a schematic diagram of the clothing repair module process proposed in the embodiment of the present application, such as Figure 7 As shown, first, the image editing device can obtain the index value idx corresponding to the "clothing" prompt word (token) through the search strategy (preset search strategy). For example, a girl in a red coat, coat representing clothing is the sixth token, that is, idx = 6; in the tth round of denoising, cross attention can be used to make the image Z t Feature map and the features of the token; specifically, the query of the image (the query vector corresponding to the second target image) and the key value (Key) K of the token P (target key vector corresponding to the target prompt word) is multiplied to obtain the weight map (initial weight map corresponding to the second target image) M t , as shown in the above formula (1), the image editing device can then generate the randomly generated mask mask t,r (Random mask) and clothing mask c (Clothing mask corresponding to the second target image) bitwise multiplication, we get (Target mask) Then we can use the weight map M corresponding to the clothing token t,idx Randomly set to zero, as shown in the above formula (2), the target mask and the initial weight map corresponding to the second target image can be multiplied to obtain the target weight map; then, the image editing device can t The weight graph M of the idxth t,idx Replace with Get the new weight map (new target weight map) Finally, you can and the token value (Value) V P(target value vector corresponding to the target prompt word) to obtain the modified image feature map (Third target image).

[0087] That is to say, in an embodiment of the present application, the image editing device can randomly set the initial weight map corresponding to the clothing prompt word to zero based on the target mask, thereby improving the clothing generation capability and making the image restoration more natural.

[0088] It should be noted that, in an embodiment of the present application, the image editing device can first train the initial image generation module to obtain a target diffusion model. The initial image generation module may include a repair module. The repair module can be used to fuse the random mask and the initial weight map corresponding to the second target image in the training image set, that is, the target mask can be determined based on the random mask and the clothing mask corresponding to the second target image, and then the initial weight map corresponding to the clothing prompt word can be randomly set to zero based on the target mask, thereby improving the clothing generation capability and making the image repair more natural.

[0089] Furthermore, in an embodiment of the present application, when the image editing device inputs the image to be predicted into the target diffusion model to obtain a first target image corresponding to the image to be predicted, the image to be predicted can be input into a target image generation module to obtain a first feature map corresponding to the image to be predicted; then the first feature map and the second feature map corresponding to the image to be predicted can be input into a fusion module to obtain the first target image.

[0090] It should be noted that in the embodiments of the present application, the face fusion module (fusion module) is intended to optimize the problem of large changes in the face when editing a hairstyle. The present application can fuse the generated intermediate result (first feature map) and the face area (second feature map) of the original image through the face mask during the sampling process to improve the consistency of the face. At present, the noise image is generally mixed with the original image, but directly integrating the original image into the face area will cause the face area to be removed by noise, so the present application proposes a face fusion strategy based on progressive step size (preset fusion strategy). Specifically, the image editing device can gradually increase the mask strength from 0 to 1, and then adjust the starting point of the mask strength according to the time step of the diffusion process T. In this way, the structural features of the target image can be adaptively maintained, while effectively balancing the relationship between the structural features of the hairstyle and the consistency of the face.

[0091] It should be noted that, in the embodiment of the present application, the image editing device may first use a face parser to obtain a face semantic mask. f , the starting point of the mask intensity can then be adjusted according to the total time step T of the diffusion The starting point is the starting time step with a mask strength of 0, and the mask strength gradually increases from 0 to 1. As shown in the above formula (4); Next, in order to match the noise intensity of the target image and the intermediate result, the present application superimposes the image feature Z of the noise of the original image of the t-1 step in the image reconstruction process t-1,targ (Second feature map) is used as the fusion target map, using soft mask FM t (Third feature map) fuses the face area of ​​the intermediate result (first feature map) and the target map (second feature map), that is, Z t-1 Optimized for (First target image) The specific fusion process is shown in the above formula (5).

[0092] It should be noted that, in an embodiment of the present application, the preset fusion strategy may be a face fusion strategy, which may be a face fusion strategy based on a progressive step size. For example, the image editing device may gradually increase the mask strength from 0 to 1, and then adjust the starting point of the mask strength according to the time step of the diffusion process T, thereby adaptively maintaining the structural features of the target image while effectively balancing the relationship between the structural features of the hairstyle and the consistency of the face.

[0093] It should be noted that in an embodiment of the present application, when the image editing device fuses the first feature map and the second feature map based on a preset fusion strategy (face fusion strategy) to obtain a first target image, it can determine the third feature map corresponding to the image to be predicted based on the preset fusion strategy; and then, the first feature map and the second feature map can be fused based on the third feature map to obtain the first target image.

[0094] It should be noted that in an embodiment of the present application, when the image editing device determines the third feature map corresponding to the image to be predicted based on a preset fusion strategy, it can determine the facial semantic mask corresponding to the image to be predicted based on the segmentation model; then the third feature map can be determined based on the facial semantic mask and the preset fusion strategy.

[0095] Exemplarily, in an embodiment of the present application, when the image editing device determines the third feature map based on the face semantic mask and the preset fusion strategy, the third feature map can be obtained by the above formula (4).

[0096] It should be noted that, in the embodiment of the present application, after determining the third feature map, the image editing device can fuse the first feature map and the second feature map based on the third feature map to obtain the first target image. As shown in the above formula (5), the image editing device can use the third feature map FM t The first feature map Z t-1 and the second feature map Z t-1,targ Perform fusion processing to obtain the first target image

[0097] For example, in the embodiments of the present application, Figure 4 As shown, assuming that the image to be predicted is Z t , input the image into the image generation module (target image generation module) to obtain the first feature map Z corresponding to the image to be predicted t-1 , then the third feature map FM can be used t The first feature map Z t-1 and the second feature map Z t-1,targ Perform fusion processing to obtain the final result, that is, the first target image

[0098] That is to say, in an embodiment of the present application, the image editing device can fuse the generated intermediate result (first feature map) and the face area (second feature map) of the original image through the face semantic mask during the sampling process to improve the face consistency.

[0099] To summarize, before the image editing device inputs the image to be predicted into the target diffusion model to obtain the first target image corresponding to the image to be predicted, the initial image generation module can be trained to obtain the target diffusion model, so that the trained target diffusion model can improve the generation capability of clothing and make the image restoration more natural. Then, the image to be predicted can be input into the target image generation module to obtain the first feature map corresponding to the image to be predicted; then the first feature map and the second feature map corresponding to the image to be predicted can be input into the fusion module to obtain the first target image, that is, the image editing device can fuse the generated intermediate result (first feature map) and the face area (second feature map) of the original image through the face semantic mask during the sampling process to improve the face consistency.

[0100] An embodiment of the present application provides an image editing method, which includes: an image editing device inputs an image to be predicted into a target diffusion model to obtain a first target image corresponding to the image to be predicted; wherein the target diffusion model includes a fusion module and a target image generation module, and the fusion module is used to fuse a first feature map corresponding to the image to be predicted and a second feature map corresponding to the image to be predicted; the target diffusion model is obtained by training an initial image generation module based on a training image set; the initial image generation module includes a repair module, and the repair module is used to fuse a random mask and an initial weight map corresponding to the second target image in the training image set. That is to say, the target diffusion model may include a fusion module and a target image generation module, and the fusion module can be used to fuse the first feature map corresponding to the predicted image and the second feature map corresponding to the predicted image, so as to optimize the facial consistency before and after the predicted image is edited, and the target diffusion model is obtained by training the initial image generation module based on the training image set; and the repair module in the initial image generation module can be used to fuse the random mask and the initial weight map corresponding to the second target image in the training image set, so as to make the image repair more natural, that is, when the image editing device of the present application edits the predicted image based on the target diffusion model, it can ensure the facial consistency before and after the image editing, and can perform image repair more naturally, thereby improving the prediction accuracy of the model.

[0101] Embodiment 3

[0102] Based on the above embodiments, the present application provides an image editing device. Figure 8 Schematic diagram of the structure of the image editing device Figure 1 ,like Figure 8 As shown, the image editing device 10 includes: an input unit 11;

[0103] The input unit 11 is used to input the image to be predicted into the target diffusion model to obtain a first target image corresponding to the image to be predicted; wherein the target diffusion model includes a fusion module and a target image generation module, and the fusion module is used to fuse the first feature map corresponding to the image to be predicted and the second feature map corresponding to the image to be predicted;

[0104] The target diffusion model is obtained by training an initial image generation module based on a training image set; the initial image generation module includes a repair module, which is used to fuse the random mask and the initial weight map corresponding to the second target image in the training image set.

[0105] In the embodiments of the present application, further, Fig. 9 Schematic diagram of the structure of the image editing device Figure 2 ,like Fig. 9 As shown, the image editing device 10 proposed in the embodiment of the present application may also include a processor 12 and a memory 13 storing executable instructions of the processor 12. Further, the image editing device 10 may also include a communication interface 14 and a bus 15 for connecting the processor 12, the memory 13 and the communication interface 14.

[0106] In the embodiment of the present application, the processor 12 may be at least one of an Application Specific Integrated Circuit (ASIC), a Digital Signal Processor (DSP), a Digital Signal Processing Device (DSPD), a Programmable Logic Device (PLD), a Field Programmable Gate Array (FPGA), a Central Processing Unit (CPU), a controller, a microcontroller, and a microprocessor. It is understandable that for different devices, the electronic device used to implement the function of the processor may also be other, and the embodiment of the present application does not specifically limit it. The image editing device 10 may also include a memory 13, which may be connected to the processor 12, wherein the memory 13 is used to store executable program code, the program code includes computer operation instructions, and the memory 13 may include a high-speed RAM memory, and may also include a non-volatile memory, for example, at least two disk memories.

[0107] In the embodiment of the present application, the bus 15 is used to connect the communication interface 14, the processor 12 and the memory 13, and the mutual communication between these devices.

[0108] In the embodiment of the present application, the memory 13 is used to store instructions and data.

[0109] Furthermore, in an embodiment of the present application, the above-mentioned processor 12 is used to input the image to be predicted into the target diffusion model to obtain a first target image corresponding to the image to be predicted; wherein the target diffusion model includes a fusion module and a target image generation module, and the fusion module is used to fuse the first feature map corresponding to the image to be predicted and the second feature map corresponding to the image to be predicted; the target diffusion model is obtained by training the initial image generation module based on the training image set; the initial image generation module includes a repair module, and the repair module is used to fuse the random mask and the initial weight map corresponding to the second target image in the training image set.

[0110] In practical applications, the memory 13 may be a volatile memory, such as a random access memory (RAM); or a non-volatile memory, such as a read-only memory (ROM), a flash memory, a hard disk (HDD) or a solid-state drive (SSD); or a combination of the above types of memory, and provide instructions and data to the processor 12.

[0111] An embodiment of the present application provides an image editing device, which inputs an image to be predicted into a target diffusion model to obtain a first target image corresponding to the image to be predicted; wherein the target diffusion model includes a fusion module and a target image generation module, and the fusion module is used to fuse a first feature map corresponding to the image to be predicted and a second feature map corresponding to the image to be predicted; the target diffusion model is obtained by training an initial image generation module based on a training image set; the initial image generation module includes a repair module, and the repair module is used to fuse a random mask and an initial weight map corresponding to the second target image in the training image set. That is to say, the target diffusion model may include a fusion module and a target image generation module, and the fusion module can be used to fuse the first feature map corresponding to the predicted image and the second feature map corresponding to the predicted image, so as to optimize the facial consistency before and after the predicted image is edited, and the target diffusion model is obtained by training the initial image generation module based on the training image set; and the repair module in the initial image generation module can be used to fuse the random mask and the initial weight map corresponding to the second target image in the training image set, so as to make the image repair more natural, that is, when the image editing device of the present application edits the predicted image based on the target diffusion model, it can ensure the facial consistency before and after the image editing, and can perform image repair more naturally, thereby improving the prediction accuracy of the model.

[0112] An embodiment of the present application provides a computer-readable storage medium having a program stored thereon, and when the program is executed by a processor, the image editing method as described above is implemented.

[0113] Specifically, the program instructions corresponding to an image editing method in this embodiment can be stored in a storage medium such as a CD, a hard disk, a USB flash drive, etc. When the program instructions corresponding to an image editing method in the storage medium are read or executed by an electronic device, the following steps are included:

[0114] Inputting the image to be predicted into the target diffusion model to obtain a first target image corresponding to the image to be predicted; wherein the target diffusion model includes a fusion module and a target image generation module, and the fusion module is used to fuse the first feature map corresponding to the image to be predicted and the second feature map corresponding to the image to be predicted;

[0115] The target diffusion model is obtained by training an initial image generation module based on a training image set; the initial image generation module includes a repair module, which is used to fuse the random mask and the initial weight map corresponding to the second target image in the training image set.

[0116] Those skilled in the art will appreciate that the embodiments of the present application may be provided as methods, systems, or computer program products. Therefore, the present application may adopt the form of hardware embodiments, software embodiments, or embodiments in combination with software and hardware. Moreover, the present application may adopt the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage and optical storage, etc.) that contain computer-usable program code.

[0117] The present application is described with reference to implementation flowcharts and / or block diagrams of the methods, devices (systems), and computer program products according to the embodiments of the present application. It should be understood that each process and / or box in the flowchart and / or block diagram, as well as the combination of processes and / or boxes 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 device to generate a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the process in the flowchart. 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.

[0118] These computer program instructions may also be stored in a computer-readable memory that can direct a computer or other programmable data processing 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 is implemented in the implementation flow diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.

[0119] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operation steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing instructions for executing the steps in the flowchart. Figure 1 A process or multiple processes and / or boxes Figure 1 A step that specifies a function in one or more boxes.

[0120] The above description is only a preferred embodiment of the present application and is not intended to limit the protection scope of the present application.

Claims

1. An image editing method, characterized in that: The method comprises: Inputting the image to be predicted into the target diffusion model to obtain a first target image corresponding to the image to be predicted; wherein the target diffusion model includes a fusion module and a target image generation module, and the fusion module is used to fuse the first feature map corresponding to the image to be predicted and the second feature map corresponding to the image to be predicted; The target diffusion model is obtained by training an initial image generation module based on a training image set; the initial image generation module includes a repair module, which is used to fuse the random mask and the initial weight map corresponding to the second target image in the training image set.

2. The method according to claim 1, characterized in that The step of inputting the image to be predicted into the target diffusion model to obtain a first target image corresponding to the image to be predicted includes: Inputting the image to be predicted into the target image generation module to obtain a first feature map corresponding to the image to be predicted; The first feature map and the second feature map corresponding to the image to be predicted are input into the fusion module to obtain the first target image.

3. The method according to claim 2, characterized in that The method further comprises: Determining a preset fusion strategy based on the diffusion time step corresponding to the target diffusion model; The first feature map and the second feature map are fused based on the preset fusion strategy to obtain the first target image.

4. The method according to claim 3, characterized in that The fusing the first feature map and the second feature map based on the preset fusion strategy to obtain the first target image includes: Determine a third feature map corresponding to the image to be predicted based on the preset fusion strategy; The first feature map and the second feature map are fused based on the third feature map to obtain the first target image.

5. The method according to claim 4, characterized in that The determining, based on the preset fusion strategy, a third feature map corresponding to the image to be predicted includes: Determine a face semantic mask corresponding to the image to be predicted based on the segmentation model; The third feature map is determined based on the face semantic mask and the preset fusion strategy.

6. The method according to claim 1, characterized in that The target diffusion model is obtained by training the initial image generation module based on the training image set and the low-rank adapter.

7. The method according to claim 1, characterized in that The initial weight map is determined based on a target key vector corresponding to a target prompt word and a query vector corresponding to the second target image, and the target prompt word is determined based on a preset search strategy; The target prompt word is a prompt word corresponding to the second target image.

8. The method according to claim 7, characterized in that The target weight map corresponding to the initial weight map is obtained by fusing the target mask with the initial weight map corresponding to the second target image; The target mask is determined based on the random mask and a clothing mask corresponding to the second target image; The target weight map and the target value vector corresponding to the target prompt word are used to determine a third target image.

9. An image editing device, characterized in that: The image editing device comprises: an input unit; The input unit is used to input the image to be predicted into the target diffusion model to obtain a first target image corresponding to the image to be predicted; wherein the target diffusion model includes a fusion module and a target image generation module, and the fusion module is used to fuse the first feature map corresponding to the image to be predicted and the second feature map corresponding to the image to be predicted; The target diffusion model is obtained by training an initial image generation module based on a training image set; the initial image generation module includes a repair module, which is used to fuse the random mask and the initial weight map corresponding to the second target image in the training image set.

10. An image editing device, characterized in that: The image editing device comprises: a processor and a memory; wherein, The memory is used to store a computer program that can be run on the processor; The processor is configured to execute the method according to any one of claims 1 to 8 when running the computer program.

11. A computer-readable storage medium, characterized in that: The storage medium stores computer program codes, and when the computer program codes are executed by a computer, the method according to any one of claims 1 to 8 is executed.

12. A computer program product, comprising a computer program, characterized in that The computer program implements the method according to any one of claims 1 to 8 when executed by a processor.

Citation Information

Cited By

  • Image fusion method and device, equipment, storage medium and program product

    CN119515697A