Image editing method, device, equipment and storage medium

By obtaining the face and description embedding vectors, combined with the image editing model and character modeling module, the problem of low authenticity of the text generation image diffusion model in generating complex detailed information is solved, and high-fidelity customized character image editing is achieved. Improved editing efficiency and effects.

CN118135062BActive Publication Date: 2024-08-30INT DIGITAL ECONOMY ACAD +1
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202410573616.1
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-05-10
Publication Date
2024-08-30
Estimated Expiration
2044-05-10

AI Technical Summary

Technical Problem

Existing text generation image diffusion models have low realism when generating images with complex detailed information, and are difficult to capture the identity characteristics of customized characters.

Method used

By receiving the image to be edited, the reference face image and description information, the face embedding vector and description embedding vector are obtained, and the image editing model is used for editing. Combined with the character modeling module and the description denoising module, it generates information with the same identity and consistent description character portrait.

Benefits of technology

It improves the character identity fidelity of the generated customized characters, decouples identity information and description information, enhances the perception of images to be edited, realizes zero-sample reasoning, and improves the efficiency and effect of image editing.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118135062B
    Figure CN118135062B
Patent Text Reader

Abstract

The present application discloses an image editing method, apparatus, device and storage medium, the method comprising receiving an image to be edited, a reference face image and description information input by a user; obtaining a face embedding vector corresponding to the reference face image and a description embedding vector corresponding to the description information; and determining an edited image corresponding to the image to be edited using a preset image editing model according to the face embedding vector, the description embedding vector and the image to be edited. The embodiment of the present application uses the face embedding vector as a condition to use the face embedding vector as identity information, and then introduces the identity information into the image editing model, which can accurately capture the detailed face features in the input reference face image, thereby improving the identity fidelity of the generated customized portrait.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

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

[0002] Image editing has always been a hot topic in the field of computer vision. Image editing can be achieved through the text-to-image diffusion model, which has achieved good results in content authenticity and diversity. However, since it is difficult to provide detailed information about customized image content through text information, such as character identity information, the text-to-image diffusion model can only generate objects with simple categories and attributes in the image to be edited, and there will be a problem of low authenticity when it comes to objects with complex detailed information (such as customized characters).

[0003] Therefore the prior art still needs to be improved and enhanced. Summary of the invention

[0004] The technical problem to be solved by the present application is to provide an image editing method, device, equipment and storage medium in view of the deficiencies in the prior art.

[0005] In order to solve the above technical problems, the first aspect of the present application provides an image editing method, wherein the image editing method specifically includes:

[0006] Receive the image to be edited, the reference face image and description information input by the user;

[0007] Obtaining a face embedding vector corresponding to the reference face image and a description embedding vector corresponding to the description information;

[0008] According to the face embedding vector, the description embedding vector and the image to be edited, an edited image corresponding to the image to be edited is determined using a preset image editing model.

[0009] The image editing method, wherein the step of obtaining the face embedding vector corresponding to the reference face image and the description embedding vector corresponding to the description information, specifically comprises:

[0010] Inputting the description information into a preset text encoder, and outputting a description embedding vector corresponding to the description information through the text encoder;

[0011] The reference face image is input into a preset image encoder, an image feature vector is outputted through the image encoder, and the image feature vector is input into a linear mapping layer, and the image feature vector is mapped into a face embedding vector through the linear mapping layer.

[0012] The image editing method, wherein the image editing model includes a character modeling module and a description denoising module, and the method of determining an edited image corresponding to the image to be edited by using a preset image editing model according to the face embedding vector, the description embedding vector and the image to be edited, specifically includes:

[0013] Determine a description attention map and a spatial attention map based on the description embedding vector and the noisy hidden code corresponding to the image to be edited by using the description denoising module;

[0014] Utilizing the character modeling module, an image attention map is determined based on the face embedding vector and the spatial attention map, and an edited image corresponding to the image to be edited is determined based on the image attention map and the description attention map.

[0015] The image editing method, wherein the base uses the description denoising module to determine the description attention map and the spatial attention map based on the description embedding vector and the noisy hidden code corresponding to the image to be edited, specifically includes:

[0016] Determine a spatial attention map of the noisy hidden code corresponding to the image to be edited by using the spatial self-attention mechanism in the description denoising module;

[0017] The description mutual attention mechanism in the description denoising module is utilized to determine the description attention map of the noisy latent code based on the spatial attention map and the description embedding vector.

[0018] The image editing method, wherein the method utilizes the description mutual attention mechanism in the description denoising module to determine the description attention map of the noisy hidden code based on the spatial attention map and the description embedding vector, specifically includes:

[0019] constructing a description value feature and a description key feature based on the description embedding vector, and constructing a description query feature based on the spatial attention map;

[0020] Based on the description query feature, the description value feature and the description key feature, a description attention map of the noisy hidden code is determined using a description mutual attention mechanism in the description denoising module.

[0021] The image editing method, wherein the step of using the character modeling module to determine the image attention map based on the face embedding vector and the spatial attention map, specifically comprises:

[0022] Determine a portrait attention map based on the spatial attention map using a portrait self-attention mechanism in the character modeling module;

[0023] By utilizing the image mutual attention mechanism in the character modeling module, based on the portrait attention map, the spatial attention map and the face embedding vector, an image attention map with noisy hidden code corresponding to the image to be edited is determined.

[0024] The image editing method, wherein the image mutual attention mechanism in the character modeling module is used to determine the image attention map corresponding to the noisy hidden code corresponding to the image to be edited based on the portrait attention map, the spatial attention map and the face embedding vector, specifically comprising:

[0025] Using the character modeling module to fuse the spatial attention map and the portrait attention map to obtain an intermediate attention map;

[0026] Constructing a graph value feature and a graph key feature based on the face embedding vector, and constructing a graph query feature based on the intermediate attention graph;

[0027] Based on the graph query feature, the graph value feature and the graph key feature, an image attention map with noisy hidden code corresponding to the image to be edited is determined by utilizing the image mutual attention mechanism in the character modeling module.

[0028] The image editing method, wherein before determining the description attention map and the spatial attention map based on the description embedding vector and the noisy hidden code corresponding to the image to be edited by using the description denoising module, the method further comprises:

[0029] Diffusion processing is performed on the image to be edited to obtain a noisy hidden code corresponding to the image to be edited.

[0030] The image editing method, wherein determining the edited image corresponding to the image to be edited based on the image attention map and the description attention map, specifically includes:

[0031] Determine a denoising feature map based on the image attention map and the description attention map;

[0032] The denoising feature map is decoded to obtain an edited image corresponding to the image to be edited.

[0033] The image editing method, wherein the method further comprises:

[0034] Receiving editing area information corresponding to the image to be edited, and generating a position mask based on the editing area information, wherein the position mask is used to reflect the area to be edited in the image to be edited;

[0035] The image to be edited is updated based on the position mask and the image to be edited.

[0036] A second aspect of the present application provides an image editing device, wherein the image editing device specifically comprises:

[0037] A receiving module, used for receiving an image to be edited, a reference face image and description information input by a user;

[0038] An acquisition module, used to acquire a face embedding vector corresponding to the reference face image and a description embedding vector corresponding to the description information;

[0039] An execution module is used to determine an edited image corresponding to the image to be edited using a preset image editing model according to the face embedding vector, the description embedding vector and the image to be edited.

[0040] A third aspect of the present application provides a computer-readable storage medium, which stores one or more programs. The one or more programs can be executed by one or more processors to implement the steps in any of the image editing methods described above.

[0041] A fourth aspect of the present application provides a terminal device, comprising: a processor and a memory;

[0042] The memory stores a computer-readable program executable by the processor;

[0043] When the processor executes the computer-readable program, the steps in any of the above-mentioned image editing methods are implemented.

[0044] Beneficial effects:

[0045] (1) By taking the face embedding vector as a condition, the face embedding vector can be used as identity information. Then, the identity information is introduced into the image editing model, which can accurately capture the detailed facial features in the input reference face image and improve the identity fidelity of the generated customized character.

[0046] (2) By taking the face embedding vector and the description embedding vector in parallel as conditions, on the one hand, the decoupling of identity information and description information is achieved, which effectively improves the problem of mutual attention leakage of identity information; on the other hand, the portrait appearance is better controlled while ensuring the consistency of identity information.

[0047] (3) By introducing portrait attention, the perception ability of known information in the edited image is increased, thereby enabling better interaction between people.

[0048] (4) By treating the portrait modeling module as a plug-and-play, the portrait modeling module can be inserted into the pre-trained Wenshengtu diffusion model, and image editing can be performed directly by inserting the pre-trained Wenshengtu diffusion model into the portrait modeling module, thus achieving zero-shot reasoning without the need for additional training. BRIEF DESCRIPTION OF THE DRAWINGS

[0049] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the drawings required for use in the description of the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work.

[0050] Figure 1 A flowchart of an image editing method provided in an embodiment of the present application.

[0051] Figure 2 A principle flow chart of an implementation method of the image editing method provided in an embodiment of the present application.

[0052] Figure 3 Schematic flowchart of the training process for the preset image editing model.

[0053] Figure 4 A structural principle diagram of the image editing device provided in an embodiment of the present application.

[0054] Figure 5 A schematic diagram of the structure of a terminal device provided in an embodiment of the present application. DETAILED DESCRIPTION

[0055] The embodiments of the present application provide an image editing method, device, equipment and storage medium. To make the purpose, technical solution and effect of the present application clearer and more specific, the present application is further described in detail with reference to the accompanying drawings and examples. It should be understood that the specific embodiments described herein are only used to explain the present application and are not used to limit the present application.

[0056] It will be understood by those skilled in the art that, unless expressly stated, the singular forms "one", "said", and "the" used herein may also include plural forms. It should be further understood that the term "comprising" used in the specification of the present application refers to the presence of the features, integers, steps, operations, elements and / or components, but does not exclude the presence or addition of one or more other features, integers, steps, operations, elements, components and / or groups thereof. It should be understood that when we refer to an element as being "connected" or "coupled" to another element, it may be directly connected or coupled to the other element, or there may be an intermediate element. In addition, the "connection" or "coupling" used herein may include wireless connection or wireless coupling. The term "and / or" used herein includes all or any unit and all combinations of one or more associated listed items.

[0057] It will be understood by those skilled in the art that, unless otherwise defined, all terms (including technical and scientific terms) used herein have the same meaning as those generally understood by those skilled in the art to which this application belongs. It should also be understood that terms such as those defined in general dictionaries should be understood to have meanings consistent with those in the context of the prior art, and will not be interpreted with idealized or overly formal meanings unless specifically defined as here.

[0058] It should be understood that the sequence numbers and sizes of the steps in this embodiment do not mean the order of execution. The execution order of each process is determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiment of the present application.

[0059] After research, it was found that image editing has always been a hot topic in the field of computer vision. Image editing can be achieved through the text-to-image diffusion model, which has achieved good results in content authenticity and diversity. However, since it is difficult to provide detailed information about customized image content through text information, such as character identity feature information, the text-to-image diffusion model can only generate objects with simple categories and attributes in the image to be edited, and there will be a problem of low authenticity when it comes to objects with complex detailed information (such as customized characters, etc.).

[0060] To this end, some studies have adopted the method of inserting the image subject in the example image into the specified area of ​​the image to be edited to perform image editing. For example, Paint-by-Example proposed a local image editing method based on a diffusion model, which achieves example-based image editing by replacing the text conditions of the original diffusion model with image conditions. AnyDoor uses a detail extractor that aims to maintain texture details but allows diversified local changes, which can more realistically generate the main objects in the reference face image in the specified area of ​​the image to be edited; Unipaint fine-tunes each reference face image at test time. Among them, the methods adopted by Paint-by-Example and AnyDoor are to achieve example-based editing by replacing the text encoder of the stable diffusion model with an image encoder, which can encode the rough information of the reference face image, but cannot process the detailed information such as the identity of the person. Unipaint's method requires each reference face image and the image to be edited to be fine-tuned for several minutes to make the model fit the information of the reference face image, which requires a lot of computing resources and time consumption, and is difficult to use in an actual production environment.

[0061] In order to solve the above problems, in an embodiment of the present application, an image to be edited, a reference face image and description information input by a user are received; a face embedding vector corresponding to the reference face image and a description embedding vector corresponding to the description information are obtained; and an edited image corresponding to the image to be edited is determined using a preset image editing model based on the face embedding vector, the description embedding vector and the image to be edited. The embodiment of the present application uses the face embedding vector as a condition, uses the face embedding vector as identity information, and then introduces the identity information into the image editing model, which can accurately capture the detailed facial features in the input reference face image, thereby improving the identity fidelity of the generated customized character.

[0062] The application content is further explained below through the description of embodiments in conjunction with the accompanying drawings.

[0063] The present embodiment provides an image editing method, which can be executed by any electronic device with data processing capabilities. For example, the electronic device can be implemented as a terminal device or a server. The terminal device can be a desktop terminal or a mobile terminal, and the mobile terminal can specifically be any portable device such as a mobile phone, a tablet computer, a laptop computer, a vehicle-mounted terminal, etc. The server can be an independent physical server, or a server cluster or distributed system composed of multiple physical servers, or an artificial intelligence platform or cloud server that provides cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, and big data services.

[0064] like Figure 1 and Figure 2 As shown, the image editing method provided in this embodiment specifically includes:

[0065] S10: receiving an image to be edited, a reference face image and description information input by a user.

[0066] Specifically, the image to be edited can be a captured image or a downloaded image, etc., and the reference facial image and description information are used as conditional information corresponding to the image to be edited, wherein the reference facial image is used to determine the identity information of the customized character portrait generated in the image to be edited; the description information is used to determine the information of the character appearance of the customized character portrait generated in the image to be edited, and the image to be edited is edited according to the reference facial image and the description information, so that a character portrait with the same identity as the reference facial image and with a character appearance that conforms to the description information is generated in the image to be edited.

[0067] The description information may be a description of the appearance of the character, such as the character's clothing, accessories, hairstyle, character posture, etc., and accordingly, the description information may be a description in text form, a description in voice form, or a description in other forms. For example, the description information is a lady wearing a rainbow scarf, or the description information is arms folded in front of the chest, etc. The posture description information may also include information for describing the posture, such as a human posture key point sequence, a body skeleton diagram, etc., wherein the human posture key point sequence may be determined by a control network (ControlNet).

[0068] It should be noted that when custom editing is performed on the image to be edited, a customized portrait can be generated in a specified area of ​​the image to be edited. That is, after obtaining the image to be edited, the area to be edited corresponding to the image to be edited can be obtained first, and then a portrait of a person with the same identity as the reference face image and a person appearance that conforms to the description information is generated in the area to be edited. Based on this, in a specific implementation, the method further includes:

[0069] Receiving editing area information corresponding to the image to be edited, and generating a position mask based on the editing area information;

[0070] The image to be edited is updated based on the position mask and the image to be edited.

[0071] Specifically, the editing area information is used to reflect the area to be edited in the image to be edited, and the area to be edited can be any area in the image to be edited, so that the user can generate a character portrait in any area in the image to be edited by setting the editing area information, for example, the entire image area of ​​the image to be edited is used as the area to be edited, or the left half of the image to be edited is used as the area to be edited, or the right half of the image to be edited is used as the area to be edited, etc. The editing area information can be directly input by the user, or can be determined according to the selection operation performed by the user in the editing image.

[0072] The position mask is used to reflect the area to be edited in the image to be edited, that is, the image area in the image to be edited for generating the portrait of the person can be determined according to the position mask. The image size of the position mask can be the same as the image size of the image to be edited, and in the position mask, the pixel value of each pixel in the mask area corresponding to the area to be edited is set to 1, and the pixel value of each pixel in the non-mask area is set to 0. Of course, in practical applications, the pixel value of each pixel in the mask area can also be set to 0, and the pixel value of each pixel in the non-mask area can be set to 1, or other two different pixel values ​​can be used to distinguish between the mask area and the non-mask area. No specific limitation is made here, and the subsequent description is only based on the example that the pixel value of each pixel in the mask area is set to 1, and the pixel value of each pixel in the non-mask area is set to 0.

[0073] Further, after obtaining the position mask, the position mask is spliced ​​with the image to be edited according to the channel to update the image to be edited; or, the area to be edited corresponding to the mask area is first selected in the image to be edited, and then the pixel value of the area to be edited is set to 1 to update the image to be edited; or, the area to be edited corresponding to the mask area is first selected in the image to be edited, and then the pixel value of the area to be edited is set to 1, and then the image to be edited is spliced ​​with the position mask according to the channel to update the image to be edited, etc. In an embodiment of the present application, the process of updating the image to be edited based on the position mask and the image to be edited is to first select the area to be edited corresponding to the mask area in the image to be edited, and then set the pixel value of the area to be edited to 1, and then splice it with the position mask according to the channel to update the image to be edited.

[0074] S20. Obtain a face embedding vector corresponding to the reference face image and a description embedding vector corresponding to the description information.

[0075] Specifically, the reference face image includes a target portrait, and the description information includes appearance information, that is, it is necessary to generate a portrait of a person whose identity information is the same as the target portrait in the reference face image and whose appearance conforms to the description information in the to-be-edited region of the to-be-edited image. Therefore, after obtaining the reference face image and the description information, feature extraction can be performed on the target portrait in the reference face image, and feature extraction can be performed on the description information, so that the to-be-edited image can be edited based on the feature vector of the target portrait and the feature vector of the description information, so as to realize image editing.

[0076] In one implementation, the acquiring of the face embedding vector corresponding to the reference face image and the description embedding vector corresponding to the description information specifically includes:

[0077] Inputting the description information into a preset text encoder, and outputting a description embedding vector corresponding to the description information through the text encoder;

[0078] The reference face image is input into a preset image encoder, an image feature vector is outputted through the image encoder, and the image feature vector is input into a linear mapping layer, and the image feature vector is mapped into a face embedding vector through the linear mapping layer.

[0079] Specifically, the text encoder and the image encoder can be the text encoder and the image encoder in the CLIP (Contrastive Language-Image Pre-training) visual model, or the text encoder or the image encoder in other models with visual extraction capabilities, etc., and no specific limitation is made here. The description information is encoded by the text encoder to obtain the description embedding vector, and the reference face image is encoded by the image encoder to obtain the image feature vector.

[0080] The linear mapping layer is used to map the image feature vector to a face embedding vector, and the linear mapping layer can be a multi-layer perceptron (MLP) or other models with key point extraction capabilities. In addition, the face embedding vector includes the face key points of the face image in the reference face image, and each face key point in the face embedding vector is used as an identity marker to control the identity consistency between the customized portrait formed in the edited image and the target portrait.

[0081] For example: Assuming that the text encoder and image encoder are the text encoder and image encoder in CLIP, and the linear mapping layer is MLP, the process of obtaining the description embedding vector and the face embedding vector can be expressed as:

[0082] ;

[0083] in, represents the face embedding vector, represents the description embedding vector, represents a linear mapping layer, represents the CLIP image encoder, represents the CLIP text encoder, represents the reference face image, Indicates description information.

[0084] S30. Determine an edited image corresponding to the image to be edited by using a preset image editing model according to the face embedding vector, the description embedding vector and the image to be edited.

[0085] Specifically, the preset image editing model is used to denoise the noisy hidden code corresponding to the image to be edited based on the face embedding vector and the description embedding vector, so that the image editing model denoises the noisy hidden code corresponding to the image to be edited and generates an edited image corresponding to the image to be edited based on the face embedding vector and the description embedding vector, wherein the edited image generates a person portrait with the same identity as the reference face image and a person appearance that conforms to the description information in the image area corresponding to the area to be edited.

[0086] Exemplarily, the image editing model can be implemented by introducing a character modeling module into a pre-trained Vincent graph diffusion model, or directly using a conditionally stable diffusion model, etc. In an embodiment of the present application, the image editing model is implemented by introducing a character modeling module into a pre-trained Vincent graph diffusion model, that is, by inserting a character modeling module into a pre-trained Vincent graph diffusion model, not only can the face embedding vector used as identity information be introduced into the Vincent graph diffusion model, but also the face embedding vector used as identity information and the description embedding vector used as text information can be decoupled, so that a portrait of a person with high identity consistency can be generated, and the problem of mutual attention leakage of identity information can be effectively improved. At the same time, the embodiment of the present application forms an image editing model by introducing a character modeling module into a pre-trained Vincent graph diffusion model, and can directly use the image editing model to denoise the noisy hidden code corresponding to the image to be edited, without the need to train the image editing image, thereby achieving zero-sample reasoning without the need for additional training.

[0087] Of course, in practical applications, in order to improve the image editing effect, after obtaining the image editing model, the image editing model can also be fine-tuned. In the process of fine-tuning the image editing model, based on the reference face image The image editing model is fine-tuned by the corresponding face embedding vector, the text embedding vector corresponding to the description information TX, the noisy hidden code corresponding to the image to be edited, the position mask, the non-editing area mask determined based on the position mask, and the image to be edited. Among them, the non-editing area mask determined based on the position mask can be obtained by subtracting the all-1 matrix from the position mask, that is, the non-editing area mask , represents a matrix of all 1s, Represents the position mask, and when training the image editing model, the non-editing area mask can be first and the image to be edited Perform pixel multiplication to get the intermediate image , and then concatenate the noisy hidden code, position mask and intermediate image by channel.

[0088] When fine-tuning the image editing model, a loss function that supports mixed training of image and text data can be used to effectively utilize the face embedding vector for reflecting identity information determined based on the reference face image and the text embedding vector for reflecting the representation of the person's appearance determined based on the description information TX. The loss function can be expressed as:

[0089] ;

[0090] in, express It conforms to the Gaussian distribution. represents randomly sampled Gaussian noise, represents the uniform distribution of time step t, represents the image editing model, represents the position mask, Indicates the non-editing area mask, Represents the edited image. Represents dot product, intermediate image ; Represents the reference face image The corresponding face embedding vector, Indicates description information The corresponding description embedding vector, Indicates noisy hidden code.

[0091] At the same time, if Figure 3 As shown, during training, we can first sample a current time step t from the range of [0,1000], and then determine Finally, the image editing model is reversely learned through the loss function so that the image editing model can make the noisy hidden code An edited image is gradually generated through multi-step denoising. When the image editing model is reversely learned through a loss function, the loss function can be performed in a self-supervised manner, that is, a target portrait is selected from the image to be edited as a reference face image, and then the image area where the target portrait is located is used as the area to be edited, so that the image to be edited can be used as the edited image for reverse learning. The process of selecting a target portrait from the image to be edited can be implemented through an existing portrait recognition model, or can be implemented using an existing target detection algorithm, and no specific restrictions are made here.

[0092] In addition, it should be noted that when training the image editing model, the loss function can also be determined in other ways. For example, the Classifier-free Guidance sampling strategy can be used, and its calculation method can be:

[0093] ;

[0094] in, represents the noisy hidden code, Indicates description information. represents the reference face image, represents the time step, represents the image editing model, represents the loss function, is the bootstrap weight parameter.

[0095] In a specific implementation, the image editing model includes a character modeling module and a description denoising module, and the determining, based on the face embedding vector, the description embedding vector and the image to be edited, the edited image corresponding to the image to be edited using the preset image editing model specifically includes:

[0096] S31, using the description denoising module, based on the description embedding vector and the noisy hidden code corresponding to the image to be edited, determining a description attention map and a spatial attention map;

[0097] S32. Utilizing the character modeling module, determine an image attention map based on the face embedding vector and the spatial attention map, and determine an edited image corresponding to the image to be edited based on the image attention map and the description attention map.

[0098] Specifically, in step S31, the noisy hidden code is obtained by adding noise to the area to be edited in the image to be edited, for example, the noisy hidden code of the image to be edited is obtained by performing forward diffusion processing on the image to be edited, wherein, when the image to be edited is subjected to forward diffusion processing, the area to be edited in the image to be edited can be subjected to diffusion processing, so that a portrait of a person having the same identity as the reference face image and having a person appearance that conforms to the description information can be generated in the area to be edited through the image editing model. Accordingly, before determining the description attention map and the spatial attention map using the description denoising module based on the description embedding vector and the noisy hidden code corresponding to the image to be edited, the method further includes performing diffusion processing on the image to be edited to obtain the noisy hidden code corresponding to the image to be edited.

[0099] It should be noted that when editing the entire image to be edited, the noisy hidden code can be directly used as the input item of the image editing model; when editing a partial image area of ​​the image to be edited, after obtaining the noisy hidden code, the position mask and the noisy hidden code of the edited area of ​​the image to be edited can be used to update the noisy hidden code, wherein the updating process of the noisy hidden code can refer to the updating process of the image to be edited. In a typical implementation, the mask of the non-edited area can be used. and the image to be edited Perform pixel multiplication to get the intermediate image , and then update the noisy hidden code by splicing the noisy hidden code, the position mask and the intermediate image in a channel-by-channel manner.

[0100] The description denoising module is used to denoise the noisy hidden code based on the description embedding vector, wherein the description denoising module can be configured with a spatial attention mechanism and a description mutual attention mechanism, and the noisy hidden code is denoised by the spatial attention mechanism and the description mutual attention mechanism. Accordingly, in one implementation, the description denoising module is used to determine the description attention map and the spatial attention map based on the description embedding vector and the noisy hidden code corresponding to the image to be edited, specifically including:

[0101] S311, using the spatial self-attention mechanism in the description denoising module, determining a spatial attention map of the noisy hidden code corresponding to the image to be edited;

[0102] S312. Determine a description attention map of the noisy hidden code based on the spatial attention map and the description embedding vector by utilizing the description mutual attention mechanism in the description denoising module.

[0103] Specifically, the spatial self-attention mechanism is used to learn the noisy latent code in space, and the spatial attention map is used to reflect the spatial information of the noisy latent code. The description mutual attention mechanism is used to interactively learn the description embedding vector and the spatial attention map, and the description attention map is used to reflect the description information carried by the description embedding vector. That is, the description denoising module may include a spatial self-attention unit and a description mutual attention unit, the spatial self-attention unit is configured with a self-attention mechanism, and the description mutual attention unit is configured with a mutual attention mechanism. Among them, the input item of the spatial self-attention unit is the noisy latent code, and the output item is the spatial attention map, that is, the spatial self-attention unit is used to self-learn on the noisy latent code through the self-attention mechanism to obtain the spatial attention map. The input item of the description mutual attention unit is the description embedding vector and the spatial attention map, and the output item is the description attention map, that is, the description mutual attention unit is used to perform mutual learning between the description embedding vector and the spatial attention map through the mutual attention mechanism to obtain the description attention map.

[0104] It can be seen that when determining the spatial attention map, the noisy hidden code is projected by the preset spatial query projection matrix, spatial value projection matrix and spatial key projection matrix to obtain the spatial query features, spatial value features and spatial key features, and then the spatial query features, spatial value features and spatial key features are self-attentionally learned through the self-attention mechanism to obtain the spatial attention map. In other words, the noisy hidden code can be directly input into the spatial self-attention unit, and then the spatial attention map is output through the spatial self-attention unit.

[0105] When determining the description attention map using the description mutual attention mechanism, the description query feature can be constructed based on the spatial attention map, the description value feature and the description key feature can be constructed based on the description embedding vector, and then the description query feature, the description value feature and the description key feature can be subjected to mutual attention learning through the mutual attention mechanism to obtain the description attention map. Based on this, in a specific implementation, the description mutual attention mechanism in the description denoising module is used to determine the description attention map of the noisy hidden code based on the spatial attention map and the description embedding vector, specifically including:

[0106] constructing a description value feature and a description key feature based on the description embedding vector, and constructing a description query feature based on the spatial attention map;

[0107] Based on the description query feature, the description value feature and the description key feature, a description attention map of the noisy hidden code is determined using a description mutual attention mechanism in the description denoising module.

[0108] Specifically, the description query feature is obtained by projecting the spatial attention map using the description query projection matrix, and the description value feature and the description key feature are obtained by projecting the description embedding vector using the description value projection matrix and the description key projection matrix respectively. The determination process of the description attention map can be expressed as:

[0109] , , ;

[0110] ;

[0111] in, represents the description attention map, represents the spatial attention map, It represents the description of query features. represents the description query projection matrix, Describes key features. represents the description embedding vector, represents the description key projection matrix, Represents the descriptive value feature, represents the description value projection matrix, represents the feature dimension, which is a scaling factor. represents the transpose operation of the matrix, Represents the description of the mutual attention mechanism.

[0112] Further, in step S32, the character modeling module is used to interactively learn the spatial attention map and the face embedding vector, wherein the character modeling module can directly construct the query feature based on the spatial attention map, or can first determine the portrait attention map based on the spatial attention map, and then construct the query feature based on the spatial attention map and the portrait attention map, etc. In the embodiment of the present application, the character modeling module adopts a method of first determining the portrait attention map based on the spatial attention map, and then constructing the query feature based on the spatial attention map and the portrait attention map, so that the portrait attention learning can be added on the basis of the spatial attention learning, and the perception of the context information by the self-attention unit can be enhanced, thereby improving the perception of the context information by the denoising network, and then improving the denoising effect.

[0113] Based on this, in a specific implementation, the determining of the image attention map based on the face embedding vector and the spatial attention map by using the character modeling module specifically includes:

[0114] Determine a portrait attention map based on the spatial attention map using a portrait self-attention mechanism in the character modeling module;

[0115] By utilizing the image mutual attention mechanism in the character modeling module, based on the portrait attention map, the spatial attention map and the face embedding vector, an image attention map with noisy hidden code corresponding to the image to be edited is determined.

[0116] Specifically, the portrait self-attention mechanism is used to perform self-attention learning on the spatial attention map, and the portrait attention map is used to reflect the context information of the noisy latent code. The image mutual attention mechanism is used to interactively learn the face embedding vector, the portrait attention map and the spatial attention map, and the image attention map is used to reflect the identity information carried by the portrait embedding vector. That is, the character modeling module may include a portrait self-attention unit and an image mutual attention unit (referred to as an identity adapter), the portrait self-attention unit is configured with a self-attention mechanism, and the identity adapter is configured with a mutual attention mechanism. Among them, the input item of the portrait self-attention unit is the spatial attention map, and the output item is the portrait attention map, that is, the portrait self-attention unit is used to perform self-learning on the spatial attention map through the self-attention mechanism to obtain the portrait attention map. The input items of the identity adapter are the portrait embedding vector, the spatial attention map and the portrait attention map, and the output item is the image attention map, that is, the identity adapter is used to perform mutual learning between the portrait embedding vector, the spatial attention map and the portrait attention map through the mutual attention mechanism to obtain the image attention map.

[0117] When determining the portrait attention map through the portrait self-attention mechanism, it can be implemented through a trained Transformer network. That is, the portrait self-attention unit included in the portrait construction module can adopt a trained Transformer network, and the portrait attention map can be determined through the trained Transformer network. In other words, the spatial attention map can be input into the trained Transformer network, and the portrait attention map can be output through the trained Transformer network. Among them, the process of determining the portrait attention map through the trained Transformer network can be expressed as:

[0118] , , ;

[0119] ;

[0120] in, represents the portrait query feature, represents the portrait key feature, represents the portrait value feature, represents the portrait query projection matrix, represents the portrait key projection matrix, represents the portrait value projection matrix, represents the spatial attention map, represents the portrait self-attention mechanism, Represents a portrait attention map.

[0121] When determining the image attention map through the image mutual attention mechanism, the spatial attention map and the portrait attention map can be fused first to obtain an intermediate attention map, and then mutual attention learning is performed between the portrait embedding vector and the intermediate attention map. Based on this, in one implementation, the image mutual attention mechanism in the character modeling module is used to determine the image attention map corresponding to the noisy hidden code corresponding to the image to be edited based on the portrait attention map, the spatial attention map and the face embedding vector, specifically including:

[0122] Using the character modeling module to fuse the spatial attention map and the portrait attention map to obtain an intermediate attention map;

[0123] Constructing a graph value feature and a graph key feature based on the face embedding vector, and constructing a graph query feature based on the intermediate attention graph;

[0124] Based on the graph query feature, the graph value feature and the graph key feature, an image attention map with noisy hidden code corresponding to the image to be edited is determined by utilizing the image mutual attention mechanism in the character modeling module.

[0125] Specifically, the intermediate attention map is obtained by fusing the spatial attention map and the portrait attention map, wherein the fusion method can be to add the spatial attention map and the portrait attention map. Correspondingly, the determination process of the intermediate attention map can be expressed as:

[0126] ;

[0127] in, represents the intermediate attention map, represents the spatial attention map, Represents a portrait attention map.

[0128] Of course, in practical applications, other fusion methods can also be used to determine the intermediate attention map, for example, channel splicing, etc., and there is no specific restriction here.

[0129] After obtaining the intermediate attention map, the intermediate attention map and the portrait embedding vector can be learned through the identity adapter in the portrait modeling module. The identity adapter is configured with a mutual attention mechanism. The process of determining the image attention map by the identity adapter can be expressed as:

[0130] , , ;

[0131] ;

[0132] in, represents the image query feature, represents the intermediate attention map, represents the image key feature, represents the image value feature, represents the image query projection matrix, represents the image key projection matrix, represents the image value projection matrix, represents the face embedding vector, Represents an image attention map.

[0133] Furthermore, after obtaining the image attention map and the description attention map, the image attention map and the description attention map can be fused to determine the fusion feature, where the fusion feature can be expressed as:

[0134] ;

[0135] in, represents the fusion feature, represents the mapping matrix corresponding to the attention map, Represents the mapping matrix corresponding to the image attention map.

[0136] Of course, in practical applications, after obtaining the fused features, the fused features can be directly used as denoising feature maps, or the module unit composed of the portrait modeling module and the description denoising module can be used as a network unit of the image editing model, denoted as HEM, and the image editing model can include multiple cascaded HEMs. After determining the fused features through one of the multiple cascaded HEMs, the fused features can be used as the input features of the next HEM of the HEM, and then the next HEM determines the fused features based on the input features, and so on, until the last HEM, so that multiple self-attention and mutual attention learning are performed through multiple cascaded network units, the denoising effect of the image editing model can be improved, wherein the input item of the frontmost network unit is a noisy hidden code. In addition, it should be noted that multiple self-attention and mutual attention learning can also be achieved by looping multiple times.

[0137] After obtaining the fusion feature, a denoising feature map can be determined based on the fusion feature, and then an edited image corresponding to the image to be edited can be determined based on the denoising feature map. Based on this, determining the edited image corresponding to the image to be edited based on the image attention map and the description attention map specifically includes:

[0138] Determine a denoising feature map based on the image attention map and the description attention map;

[0139] The denoising feature map is decoded to obtain an edited image corresponding to the image to be edited.

[0140] Specifically, the denoised feature map is obtained by denoising the noisy hidden code, wherein the denoised feature map can be obtained by subtracting the noise term determined by the network unit HEM from the noisy hidden code. That is to say, when determining the denoised feature map based on the image attention map and the description attention map, the noise term can be determined based on the image attention map and the description attention map, and then the denoised feature map is determined based on the noise term and the noisy hidden code.

[0141] It should be noted that after determining the denoising feature map based on the image attention map and the description attention map, the edited image can be determined directly based on the denoising feature map, or the denoising feature map can be used as a noisy hidden code to re-execute the above-mentioned determination of the image attention map and the description attention map using the character modeling module and the description denoising module, and the determination of the denoising feature map based on the image attention map and the description attention map. Wherein, each execution corresponds to a time step, and the end condition of the re-execution can be to execute T time steps. Of course, in practical applications, the image editing model can include T cascaded denoising networks, the network structures of the T cascaded denoising networks are the same, and the input items of the denoising network located in the front are the noisy hidden code, the face embedding vector and the description embedding vector. The denoising feature map output by the previous denoising network in the two adjacent denoising networks is used as the noisy hidden code corresponding to the next denoising network, and the denoising feature map output by the last denoising network is used to determine the edited image corresponding to the image to be edited.

[0142] It can be understood that the image editing model may include a denoising network or multiple cascaded denoising networks, wherein when the image editing model includes a denoising network, the denoising network may be executed cyclically T times, and T may be a positive integer greater than or equal to 1. In addition, the denoising network may include a network unit HEM or multiple cascaded network units HEM, the network unit HEM includes a portrait modeling module and a description denoising module, wherein when the denoising network includes a network unit HEM, the network unit HEM may be executed a preset number of times, which is pre-set and may be a positive integer greater than or equal to 1.

[0143] In order to more clearly illustrate the process of determining the denoising feature map, assume that a total of T time steps are executed. Take the example to explain the process of determining the denoising feature map. The process of determining the denoising feature map can be expressed as:

[0144] ;

[0145] ;

[0146] ;

[0147] ;

[0148] in, Represents the time step The denoising feature map of represents the denoising parameter coefficient, , , represents the time step in the diffusion process The diffusion parameter, and Both represent the time step in the diffusion process The diffusion parameter, represents the network unit including the portrait modeling module and the description denoising module, express The input features of Indicates time steps, represents the denoising network, represents the noise term, represents randomly sampled Gaussian noise, Indicates the feature code of the image to be edited. Represents a noisy hidden code, through obtained by diffusion treatment.

[0149] After determining the denoising feature map, the denoising feature map can be decoded by a decoder to obtain an edited image frame corresponding to the image frame. Specifically, the edited image frame It can be expressed as:

[0150] ;

[0151] in, represents the VAE decoder, Represents the edited image frame, Represents the denoised feature map.

[0152] In summary, the present embodiment provides an image editing method, the method comprising obtaining an image to be edited, a reference face image and description information; receiving the image to be edited, the reference face image and description information input by a user; obtaining a face embedding vector corresponding to the reference face image and a description embedding vector corresponding to the description information; and determining the edited image corresponding to the image to be edited using a preset image editing model according to the face embedding vector, the description embedding vector and the image to be edited. The present application embodiment can generate a portrait of a person at any desired position, and naturally interact with the reference face image and description information, while ensuring the identity similarity and consistency of the generated portrait with the reference face image and the description information. In addition, the present application constructs a portrait modeling module of an identity adapter and a portrait attention unit in a text-to-image extension model, decouples the face embedding vector and the description embedding vector through the identity adapter in the character modeling module, and enhances the perception of known information in the image to be edited through the portrait attention unit in the character modeling module, thereby achieving a more harmonious interaction between people in a group photo scene, so that the scene can be more accurate and the adaptation scene is richer.

[0153] In addition, in order to further illustrate the editing effect of the embodiment of the present application, the following is verified from CLIP-H, face similarity Face Sim, FID, QS, IQA, editing time Time and memory consumption Memory, and the verification results are shown in Table 1. Among them, CLIP-H is used to measure the possibility of generating a person in a specified area, face similarity is used to measure the identity similarity between the generated person and the reference face image, FID is used to evaluate the difference between the distribution of the generated image and the distribution of the real image, QS can evaluate the quality of the generated image through the pre-trained model, and IQA is based on CLIP to evaluate the authenticity and naturalness of the generated image. The editing efficiency of the model is evaluated by editing time and memory usage.

[0154] Table 1 Verification results

[0155]

[0156] Based on the above image editing method, this embodiment provides an image editing device, such as Figure 4 As shown, the image editing device specifically includes:

[0157] The receiving module 100 is used to receive the image to be edited, the reference face image and the description information input by the user;

[0158] An acquisition module 200 is used to acquire a face embedding vector corresponding to the reference face image and a description embedding vector corresponding to the description information;

[0159] The execution module 300 is used to determine an edited image corresponding to the image to be edited by using a preset image editing model according to the face embedding vector, the description embedding vector and the image to be edited.

[0160] Based on the above-mentioned image editing method, this embodiment provides a computer-readable storage medium, which stores one or more programs. The one or more programs can be executed by one or more processors to implement the steps in the image editing method described in the above-mentioned embodiment.

[0161] Based on the above image editing method, the present application also provides a terminal device, such as Figure 5 As shown, it includes at least one processor 20; a display screen 21; and a memory 22, and may also include a communications interface 23 and a bus 24. The processor 20, the display screen 21, the memory 22, and the communications interface 23 may communicate with each other through the bus 24. The display screen 21 is configured to display a preset user guide interface in the initial setting mode. The communications interface 23 may transmit information. The processor 20 may call the logic instructions in the memory 22 to execute the method in the above embodiment.

[0162] In addition, the logic instructions in the memory 22 can be implemented in the form of software functional units and can be stored in a computer-readable storage medium when sold or used as an independent product.

[0163] The memory 22 is a computer-readable storage medium that can be configured to store software programs, computer executable programs, such as program instructions or modules corresponding to the methods in the embodiments of the present disclosure. The processor 20 executes functional applications and data processing by running the software programs, instructions or modules stored in the memory 22, that is, implementing the methods in the above embodiments.

[0164] The memory 22 may include a program storage area and a data storage area, wherein the program storage area may store an operating system and at least one application required for a function; the data storage area may store data created according to the use of the terminal device, etc. In addition, the memory 22 may include a high-speed random access memory and may also include a non-volatile memory. For example, a variety of media that can store program codes, such as a USB flash drive, a mobile hard disk, a read-only memory (ROM), a random access memory (RAM), a disk or an optical disk, may also be a transient storage medium.

[0165] In addition, the specific process of loading and executing the multiple instruction processors in the above-mentioned storage medium and the terminal device has been described in detail in the above-mentioned method, and will not be described one by one here.

[0166] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present application, rather than to limit it. Although the present application 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 make equivalent replacements for some of the technical features therein. However, these modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present application.

Claims

1. An image editing method, characterized in that: The image editing method specifically comprises: Receiving an image to be edited, a reference face image and description information input by a user, wherein the reference face image is used to determine the identity information of the customized character portrait generated in the image to be edited; the description information is used to determine the appearance information of the customized character portrait generated in the image to be edited; Obtaining a face embedding vector corresponding to the reference face image and a description embedding vector corresponding to the description information; According to the face embedding vector, the description embedding vector and the image to be edited, an edited image corresponding to the image to be edited is determined using a preset image editing model.

2. The image editing method according to claim 1, characterized in that: The acquiring the face embedding vector corresponding to the reference face image and the description embedding vector corresponding to the description information specifically includes: Inputting the description information into a preset text encoder, and outputting a description embedding vector corresponding to the description information through the text encoder; The reference face image is input into a preset image encoder, an image feature vector is outputted through the image encoder, and the image feature vector is input into a linear mapping layer, and the image feature vector is mapped into a face embedding vector through the linear mapping layer.

3. The image editing method according to claim 1, characterized in that: The image editing model includes a character modeling module and a description denoising module. The method of determining an edited image corresponding to the image to be edited by using a preset image editing model according to the face embedding vector, the description embedding vector and the image to be edited specifically includes: Determine a description attention map and a spatial attention map based on the description embedding vector and the noisy hidden code corresponding to the image to be edited by using the description denoising module; Utilizing the character modeling module, an image attention map is determined based on the face embedding vector and the spatial attention map, and an edited image corresponding to the image to be edited is determined based on the image attention map and the description attention map.

4. The image editing method according to claim 3, characterized in that: The method of using the description denoising module to determine a description attention map and a spatial attention map based on the description embedding vector and the noisy hidden code corresponding to the image to be edited specifically includes: Determine a spatial attention map of the noisy hidden code corresponding to the image to be edited by using the spatial self-attention mechanism in the description denoising module; The description mutual attention mechanism in the description denoising module is utilized to determine the description attention map of the noisy latent code based on the spatial attention map and the description embedding vector.

5. The image editing method according to claim 4, characterized in that: The using the description mutual attention mechanism in the description denoising module to determine the description attention map of the noisy hidden code based on the spatial attention map and the description embedding vector specifically includes: constructing a description value feature and a description key feature based on the description embedding vector, and constructing a description query feature based on the spatial attention map; Based on the description query feature, the description value feature and the description key feature, a description attention map of the noisy hidden code is determined using a description mutual attention mechanism in the description denoising module.

6. The image editing method according to claim 3, characterized in that: The method of using the character modeling module to determine the image attention map based on the face embedding vector and the spatial attention map specifically includes: Determine a portrait attention map based on the spatial attention map using a portrait self-attention mechanism in the character modeling module; By utilizing the image mutual attention mechanism in the character modeling module, based on the portrait attention map, the spatial attention map and the face embedding vector, an image attention map with noisy hidden code corresponding to the image to be edited is determined.

7. The image editing method according to claim 6, characterized in that: The method of utilizing the image mutual attention mechanism in the character modeling module to determine the image attention map corresponding to the noisy hidden code corresponding to the image to be edited based on the portrait attention map, the spatial attention map, and the face embedding vector specifically includes: Using the character modeling module to fuse the spatial attention map and the portrait attention map to obtain an intermediate attention map; Constructing a graph value feature and a graph key feature based on the face embedding vector, and constructing a graph query feature based on the intermediate attention graph; Based on the graph query feature, the graph value feature and the graph key feature, an image attention map with noisy hidden code corresponding to the image to be edited is determined by utilizing the image mutual attention mechanism in the character modeling module.

8. The image editing method according to claim 3, characterized in that: Before determining the description attention map and the spatial attention map by using the description denoising module based on the description embedding vector and the noisy hidden code corresponding to the image to be edited, the method further includes: Diffusion processing is performed on the image to be edited to obtain a noisy hidden code corresponding to the image to be edited.

9. The image editing method according to claim 3, characterized in that: The determining the edited image corresponding to the image to be edited based on the image attention map and the description attention map specifically includes: Determine a denoising feature map based on the image attention map and the description attention map; The denoising feature map is decoded to obtain an edited image corresponding to the image to be edited.

10. The image editing method according to claim 1, characterized in that: The method further comprises: Receiving editing area information corresponding to the image to be edited, and generating a position mask based on the editing area information, wherein the position mask is used to reflect the area to be edited in the image to be edited; The image to be edited is updated based on the position mask and the image to be edited.

11. An image editing device, characterized in that: The image editing device specifically comprises: A receiving module, configured to receive an image to be edited, a reference face image and description information input by a user, wherein the reference face image is used to determine the identity information of the customized character portrait generated in the image to be edited; and the description information is used to determine the appearance information of the customized character portrait generated in the image to be edited; An acquisition module, used to acquire a face embedding vector corresponding to the reference face image and a description embedding vector corresponding to the description information; An execution module is used to determine an edited image corresponding to the image to be edited using a preset image editing model according to the face embedding vector, the description embedding vector and the image to be edited.

12. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores one or more programs, and the one or more programs can be executed by one or more processors to implement the steps in the image editing method according to any one of claims 1-10.

13. A terminal device, characterized in that: include: Processor and memory; The memory stores a computer-readable program executable by the processor; When the processor executes the computer-readable program, the steps in the image editing method according to any one of claims 1 to 10 are implemented.

Citation Information

Patent Citations

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

    CN116958326A

  • Method for editing face image through text, terminal and storage medium

    CN117576257A