A multi-attribute image editing method, device and electronic device based on command chain

By constructing SFT data sets and using large language models to decompose multi-attribute instructions, combined with super-resolution models, the shortcomings of multi-attribute image editing in the existing technology are solved, and highly consistent multi-attribute image editing effects are achieved.

CN117475037BActive Publication Date: 2024-08-27BEIJING ACAD OF ARTIFICIAL INTELLLIGENCE
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202311705594.1
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2023-12-13
Publication Date
2024-08-27
Estimated Expiration
2043-12-13

AI Technical Summary

Technical Problem

The existing technology has shortcomings in image multi-attribute editing and cannot effectively understand and process complex instructions containing multiple attribute changes, resulting in the editing model being unable to complete related editing work.

Method used

By constructing a supervised fine-tuning training data set SFT, a large language model is used to decompose multi-attribute instructions into single-attribute instruction chains, and then gradually execute single-attribute instructions for image editing. It is combined with a super-resolution model to complete image details and improve the reliability of the editing model. control and consistency.

Benefits of technology

It effectively solves the image editing problem of multi-attribute instructions, improves the consistency of the edited image and instructions and the controllability of the editing process, alleviates the text editing model's lack of understanding of complex instructions, and improves the continuous editability of images. .

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN117475037B
    Figure CN117475037B
Patent Text Reader

Abstract

The present invention discloses a multi-attribute image editing method, device and electronic device based on instruction chain, belonging to the field of artificial intelligence technology. The method comprises: constructing a supervised fine tuning training (Supervised Fine Tuning, SFT) data set, the SFT data set comprises multi-attribute instructions and corresponding single-attribute instruction chains; using the multi-attribute instructions and corresponding single-attribute instruction chains in the SFT data set to fine-tune the pre-trained large language model to obtain a trained large language model; using the trained large language model to decompose a multi-attribute instruction to be edited into a single-attribute instruction chain to be edited; for the image to be edited, using the editing model to gradually execute each single-attribute instruction in the single-attribute instruction chain to be edited, to obtain the edited image. The technical solution of the present invention can effectively solve the image editing problem of multi-attribute instructions, so that the edited image has a high consistency with the multi-attribute instructions.
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 a multi-attribute image editing method, device and electronic equipment based on an instruction chain. Background Art

[0002] There are already some excellent works in the field of face editing and general image editing. For example, based on CLIP, many works focus on using CLIP embeddings to guide the editing process (Avrahami, Lischinski, and Fried, 2022; Crowson et al., 2022; Kim, Kwon, and Ye, 2022; Kwon and Ye, 2022; Patashnik et al., 2021; Bar-Tal et al., 2022). Recently, pre-trained text-to-image diffusion models have greatly promoted the development of image editing. By using cross-attention control, Prompt2Prompt (Hertz et al., 2023) can perform local and global editing by modifying words in the original prompt. Null Text Inversion (Mokady et al., 2023) optimizes the back-diffusion trajectory of the input image and can perform real image editing through Prompt2Prompt. By optimizing the text embedding aligned with the input image, Imagic (Kawar et al., 2023) generates different images for editing by interpolating with the target description. ChatFace (Yue et al., 2023) develops an interactive system that can operate efficiently in a diffuse semantic latent space by combining the zero-shot reasoning capabilities of large language models. InstructPix2Pix (Brooks, Holynski, and Efros, 2023) uses synthetic text generated by fine-tuned GPT-3 and images generated by Prompt2Prompt to edit real images in an instruction-guided manner. MagicBrush (Zhang et al., 2023) further builds a large-scale, manually annotated dataset for instruction-guided real image editing and fine-tunes InstructPix2Pix.

[0003] At present, these works have achieved great success in single-attribute image editing, but these solutions still have obvious shortcomings in multi-attribute image editing. For example, for the following multi-attribute editing scenario: the input includes an image and a multi-attribute complex instruction such as "help me change this painting to a green background and replace the puppy with a kitten", the instruction includes two attribute changes, "background change" and "animal change", and the current technical solution cannot effectively understand and process such multi-attribute complex instructions, resulting in the editing model being unable to effectively complete the relevant editing work. Summary of the invention

[0004] In order to solve the problems existing in the prior art, the present invention provides the following technical solutions.

[0005] The present invention provides a multi-attribute image editing method based on command chain, comprising:

[0006] Constructing a supervised fine tuning training SFT (Supervised Fine Tuning) dataset, wherein the SFT dataset includes multi-attribute instructions and corresponding single-attribute instruction chains;

[0007] Fine-tune the pre-trained large language model using the multi-attribute instructions and the corresponding single-attribute instruction chains in the SFT data set to obtain a trained large language model;

[0008] Using the trained large language model, a multi-attribute instruction to be edited is decomposed into a chain of single-attribute instructions to be edited;

[0009] For the image to be edited, the editing model is used to gradually execute each single attribute instruction in the single attribute instruction chain to be edited to obtain the edited image.

[0010] Preferably, constructing the SFT data set includes:

[0011] Set multiple instruction templates for each attribute, and generate corresponding single-attribute instructions based on each instruction template;

[0012] Generate a multi-attribute instruction and a corresponding single-attribute instruction chain according to multiple single-attribute instructions;

[0013] All generated multi-attribute instructions and corresponding single-attribute instruction chains constitute the SFT data set.

[0014] Preferably, generating corresponding single-attribute instructions based on each instruction template includes: calling the API of OpenAI GPT4, using the format of: "Help me to rewrite the sentence: [input]", where "input" is the instruction template.

[0015] Preferably, generating a multi-attribute instruction and a corresponding single-attribute instruction chain according to multiple single-attribute instructions includes: calling the API of OpenAI GPT4, using the format of: "Help me to combine these instructionsinto one instruction:[intrsuction1,instruction2,...]", wherein "intrsuction1,instruction2,..." are all single-attribute instructions.

[0016] Preferably, the fine-tuning of the pre-trained large language model using the multi-attribute instructions and the corresponding single-attribute instruction chains in the SFT data set comprises:

[0017] The multi-attribute instructions in the SFT data set are used as the input of the pre-trained large language model, and the single-attribute instruction chain in the SFT data set is used as the output of the pre-trained large language model to train the pre-trained large language model.

[0018] Preferably, the decomposing a multi-attribute instruction to be edited into a single-attribute instruction chain to be edited by using a trained large language model comprises: setting an instruction decomposition prompt template, wherein the instruction decomposition prompt template is used to guide the large language model to decompose the multi-attribute instruction and specify the output format of the single-attribute instruction chain.

[0019] Preferably, the instruction decomposition prompt template includes a first prompt text, a second prompt text and a third prompt text, wherein the first prompt text is used to prompt the trained large language model for the multi-attribute instruction decomposition task to be completed; the second prompt text is used to provide the trained large language model with a specific multi-attribute instruction decomposition case, as well as input and output content and corresponding formats; the third prompt text is used to embed the multi-attribute instruction to be processed into the instruction decomposition prompt template.

[0020] Preferably, the editing model is obtained by fine-tuning pre-constructed training data, and the training data is constructed using the following method:

[0021] Get a dataset of original images;

[0022] Using the image description generator to obtain the original text description corresponding to the original image;

[0023] Obtaining latent variables and corresponding Gaussian noise based on the original text description;

[0024] Converting the original text description into a target text description using handwritten instructions;

[0025] Generate a preliminary target image using the original text description, latent variables and corresponding Gaussian noise, and target text description;

[0026] The following formula is used to align and correct the non-target area using the instance segmentation mask of each original image to obtain the final target image:

[0027] F out =F in ×(1-I mask )+F p2p ×I mask ,

[0028] Among them, F in is the original image, I mask is the segmentation mask corresponding to the target area, F out is the final target image, F p2p is the preliminary target image;

[0029] The original image, the final target image and the handwritten instructions constitute the training data.

[0030] Preferably, the converting the original text description into the target text description by using handwritten instructions comprises: using instruction templates set for attributes when constructing the SFT data set, and converting the original text description into the target text description through a large language model.

[0031] Preferably, for the image to be edited, using the editing model to gradually execute each single attribute instruction in the single attribute instruction chain to be edited, and obtaining the edited image comprises:

[0032] In each step of executing a single attribute instruction using the editing model, the image to be edited in the step is first input into the super-resolution model, then the image output by the super-resolution model is input into the editing model, and finally the editing model is used to execute the single attribute instruction for editing.

[0033] A second aspect of the present invention provides a multi-attribute image editing device based on a command chain, comprising:

[0034] An SFT data set construction module, used to construct an SFT data set, wherein the SFT data set includes multi-attribute instructions and corresponding single-attribute instruction chains;

[0035] A large language model fine-tuning module, used to fine-tune the pre-trained large language model using the multi-attribute instructions and the corresponding single-attribute instruction chains in the SFT data set to obtain a trained large language model;

[0036] An instruction decomposition module is used to decompose a multi-attribute instruction to be edited into a single-attribute instruction chain to be edited using a trained large language model;

[0037] The image editing module is used to use the editing model to gradually execute each single attribute instruction in the single attribute instruction chain to be edited to obtain the edited image.

[0038] The present invention also provides a memory storing a plurality of instructions, wherein the instructions are used to implement the multi-attribute image editing method based on instruction chain as described in the first aspect.

[0039] The present invention also provides an electronic device, comprising a processor and a memory connected to the processor, wherein the memory stores a plurality of instructions, and the instructions can be loaded and executed by the processor so that the processor can execute the multi-attribute image editing method based on the instruction chain as described in the first aspect.

[0040] The beneficial effects of the present invention are as follows: the present invention provides a multi-attribute image editing method, device and electronic device based on instruction chain, which alleviates the problem that the text-based image editing model cannot understand complex instructions by decomposing and processing multi-attribute complex instructions using LLM; by fine-tuning the image editing model, the controllability of the image editing model for single-attribute editing tasks is improved; a simple image super-resolution model is used to perform super-resolution processing on the input image data, which completes the detailed information of the input image and improves the continuous editability of the image. The technical solution provided by the present invention can effectively solve the image editing problem of multi-attribute instructions, so that the edited image has a high consistency with the multi-attribute instructions. BRIEF DESCRIPTION OF THE DRAWINGS

[0041] Figure 1 It is a flowchart of the multi-attribute image editing method based on command chain according to the present invention;

[0042] Figure 2 This is an example display diagram of the instruction decomposition prompt template of the present invention;

[0043] Figure 3 A schematic diagram of the process of constructing training data according to the present invention;

[0044] Figure 4 A flowchart of a specific example implementation process of the multi-attribute image editing method based on command chain according to the present invention;

[0045] Figure 5 It is a functional structure diagram of the multi-attribute image editing device based on command chain described in the present invention. DETAILED DESCRIPTION

[0046] In order to better understand the above technical solution, the above technical solution will be described in detail below in conjunction with the accompanying drawings and specific implementation methods.

[0047] The method provided by the present invention can be implemented in the following terminal environment, and the terminal may include one or more of the following components: a processor, a memory, and a display screen. The memory stores at least one instruction, and the instruction is loaded and executed by the processor to implement the method described in the following embodiment.

[0048] The processor may include one or more processing cores. The processor uses various interfaces and lines to connect various parts of the entire terminal, and executes various functions of the terminal and processes data by running or executing instructions, programs, code sets or instruction sets stored in the memory, and calling data stored in the memory.

[0049] The memory may include random access memory (RAM) or read-only memory (ROM). The memory may be used to store instructions, programs, codes, code sets or instructions.

[0050] The display screen is used to display the user interface of each application.

[0051] In addition, those skilled in the art can understand that the structure of the above terminal does not constitute a limitation on the terminal, and the terminal may include more or fewer components, or combine certain components, or arrange the components differently. For example, the terminal also includes components such as a radio frequency circuit, an input unit, a sensor, an audio circuit, and a power supply, which will not be described in detail here.

[0052] The terms involved in the present invention are explained as follows:

[0053] Multi-Attribute Instruction: An instruction that includes changes to multiple attributes at the same time. For example, the instruction "Help me change the background of this painting to a green one and replace the puppy with a kitten" includes the editing of two attributes: background change and animal change. This instruction can be considered a "multi-attribute instruction".

[0054] Single-Attribute Instruction: An instruction that only contains one attribute change. For example, the instruction "Help me change the puppy in the picture into a kitten" only contains the edit of the animal's attribute. This instruction can be considered a "single-attribute instruction".

[0055] SR: Super-resolution model, such as ESRGAN.

[0056] Editor: Image editor, such as InstructPix2Pix, etc.

[0057] LLM: Large language model, such as LLama, ChatGPT, etc.

[0058] Embodiment 1

[0059] like Figure 1 As shown, an embodiment of the present invention provides a multi-attribute image editing method based on a command chain, comprising:

[0060] S101, constructing an SFT data set, wherein the SFT data set includes multi-attribute instructions and corresponding single-attribute instruction chains;

[0061] S102, fine-tuning the pre-trained large language model using the multi-attribute instructions and the corresponding single-attribute instruction chains in the SFT data set to obtain a trained large language model;

[0062] S103, using the trained large language model to decompose a multi-attribute instruction to be edited into a single-attribute instruction chain to be edited;

[0063] S104, for the image to be edited, using the editing model, gradually executing each single attribute instruction in the single attribute instruction chain to be edited to obtain the edited image.

[0064] The purpose of the present invention is to solve the image editing problem of multi-attribute instructions, so that the image editing model can effectively understand and accurately execute the input multi-attribute instructions, ensuring the consistency of the final editing result with the instructions and the controllability of the editing process.

[0065] In order to achieve the above object, the present invention utilizes the powerful language understanding ability of the large language model (LLM) to decompose a multi-attribute instruction into a single-attribute instruction chain consisting of multiple single-attribute instructions. Then, by using the image editing model, each single-attribute instruction in the single-attribute instruction chain is gradually executed to obtain an edited image.

[0066] In the present invention, it is necessary to fine-tune the pre-trained large language model to obtain a trained large language model, and use the trained large language model to decompose a multi-attribute instruction to be edited into a single-attribute instruction chain to be edited. The pre-trained large language model is fine-tuned in the SFT data set. In the present invention, the SFT data set is first constructed, including multi-attribute instructions and corresponding single-attribute instruction chains. The construction of the SFT data set can be implemented by the following steps:

[0067] Set multiple instruction templates for each attribute, and generate corresponding single-attribute instructions based on each instruction template;

[0068] Generate a multi-attribute instruction and a corresponding single-attribute instruction chain according to multiple single-attribute instructions;

[0069] All generated multi-attribute instructions and corresponding single-attribute instruction chains constitute the SFT data set.

[0070] The generating of corresponding single-attribute instructions based on each instruction template includes: calling the API of OpenAI GPT4, using the format of: "Help me to rewrite the sentence: [input]", where "input" is the instruction template.

[0071] The generating a multi-attribute instruction and a corresponding single-attribute instruction chain according to a plurality of single-attribute instructions includes: calling the API of OpenAI GPT4, and the format adopted is: "Help me to combine these instructions into oneinstruction:[intrsuction1,instruction2,...]", wherein "intrsuction1,instruction2,..." are all single-attribute instructions.

[0072] Specifically, the present invention uses OpenAI's GPT4 to construct multiple multi-attribute instructions that support multiple attribute combinations of "hair, eyes, skin, gender, age, animation, expression, beard and glasses". The number of attributes in each multi-attribute instruction can be 2-6, and the number of instructions for each attribute combination is 500. The detailed construction method is described as follows:

[0073] Step 1: Generate single-attribute instructions: First, set 20 handwritten instruction templates for each attribute, such as "change the hair color to red"; then call OpenAI's GPT4API (Application Programming Interface), the format is: "Help me to rewrite the sentence: [input]", where input is the handwritten instruction template, and generate single-attribute instructions. For example, for the handwritten instruction template "change the hair color to red", call OpenAI's GPT4 API, and the generated single-attribute instruction is "Alter the hair to red color".

[0074] Step 2: Combine multiple single-attribute instructions into one multi-attribute instruction. The specific implementation method can be to call the GPT4 interface. The format is: "Help me to combine these instructions into one instruction: [intrsuction1, instruction2, ...]", where intrsuction1, instruction2, ... represent multiple single-attribute instructions. For example, "intrsuction1" is "Make the person into a woman", "instruction2" is "Make him wear glasses", and the generated multi-attribute instruction is "Turn the person to female and withglasses", and the corresponding single-attribute instruction chain is ["Make the person into awoman", "Make him wearglasses"]. Among them, the single-attribute instruction chain is composed of multiple single-attribute instructions. The composition rule is that multiple single-attribute instructions in a single-attribute instruction chain cannot edit repeated attributes. For example, two commands that edit hair at the same time, such as "change the haircolor to red" and "make the man with black hair", cannot appear at the same time.

[0075] In the present invention, examples of generated multi-attribute instructions and corresponding single-attribute instruction chains may be as follows:

[0076] 1.Multi-attribute instructions of two attribute combinations and corresponding single-attribute instruction chains.

[0077] {'combine_instructions':['Transform the boy into a younger and fresher female version of themselves.','Turn the boy into a youthful and rejuvenated girl.',"Change the boy's gender and make the girl appear younger and fresher."],'step_instructions':["Convert the boy's gender to female.",'Turn the girl into a younger and fresher version of herself.']}.

[0078] 2. Multi-attribute instructions of three attribute combinations and corresponding single-attribute instruction chains.

[0079] {'combine_instructions':['Transform the boy into an older version ofhimself with maroon gray hair and olive skin.','Turn the boy into an elderwith maroon gray hair and olive skin.','Make the boy look older with maroon gray hair and olive skin tone.'],'step_instructions':['Turn the boy into anelder version of his former self.','change for a olive skin color for theboy.',"Turn the boy's hair into a maroon gray color."]}.

[0080] 3.Multi-attribute instructions of four attribute combinations and corresponding single-attribute instruction chains.

[0081] {'combine_instructions':['Give the individual an aged female with brown skin tone and a smiling face.','Transform the person into a brown-skinned,older female with a beaming smile.','Turn the individual into asmiling,mature female with brown complexion.'],'step_instructions':['Give the individual a female person.','Make the girl appear more aged.','Create abrown skin tone for the girl.','Make the girl's face light up with asmile.']}.

[0082] In one embodiment of the present invention, the fine-tuning of the pre-trained large language model using the multi-attribute instructions and the corresponding single-attribute instruction chains in the SFT data set may include: using the multi-attribute instructions in the SFT data set as the input of the pre-trained large language model, using the single-attribute instruction chains in the SFT data set as the output of the pre-trained large language model, and training the pre-trained large language model.

[0083] In a preferred embodiment of the present invention, the decomposing a multi-attribute instruction to be edited into a single-attribute instruction chain to be edited using a trained large language model includes: setting an instruction decomposition prompt template, wherein the instruction decomposition prompt template is used to guide the large language model to decompose the multi-attribute instruction and specify the output format of the single-attribute instruction chain.

[0084] The instruction decomposition prompt template includes a first prompt text, a second prompt text and a third prompt text. The first prompt text is used to prompt the trained large language model to complete the multi-attribute instruction decomposition task; the second prompt text is used to provide the trained large language model with a specific multi-attribute instruction decomposition case, as well as the input and output content and the corresponding format; the third prompt text is used to embed the multi-attribute instruction to be processed into the instruction decomposition prompt template. The instruction decomposition prompt template example provided by the present invention can be as follows: Figure 2 shown. Figure 2In the example above, the first paragraph “Give you an example of instruction decomposition” indicates that the large language model needs to complete the instruction decomposition work; the second paragraph “

[0085] Input:Turn the person to female and with glasses

[0086] Output:The instruction involves two attribute changes,

[0087] gender and glasses.Then decompose it.

[0088] The result is:

[0089] Step1,Make the person into a woman;

[0090] Step2,Make him wear glasses.”

[0091] It prompts a specific instruction decomposition case of the language model, clarifies the decomposition input and output as well as the corresponding format; the third paragraph of text "Decompose [Muti-Attribute Instruction] step by step according to the above format:" embeds the multi-attribute instruction to be processed into the instruction decomposition prompt template.

[0092] At present, the existing editing model of single attribute instruction has the problem of insufficient controllability. Modification of a certain attribute will cause changes in other attributes, resulting in cumulative editing errors. In order to solve this problem, the present invention proposes the following solution: first construct high-quality training data, then use the constructed training data to fine-tune the existing editing model, and finally use the fine-tuned editing model to execute single attribute instruction to perform image editing. The training data can be constructed by the following method:

[0093] Get a dataset of original images;

[0094] Using the image description generator to obtain the original text description corresponding to the original image;

[0095] Obtaining latent variables and corresponding Gaussian noise based on the original text description;

[0096] Converting the original text description into a target text description using handwritten instructions;

[0097] Generate a preliminary target image using the original text description, latent variables and corresponding Gaussian noise, and target text description;

[0098] The following formula is used to align and correct the non-target area using the instance segmentation mask of each original image to obtain the final target image:

[0099] F out =F in ×(1-I mask )+F p2p ×I mask ,

[0100] Among them, F in is the original image, I mask is the segmentation mask corresponding to the target area, F out is the final target image, F p2p is the preliminary target image;

[0101] The original image, the final target image and the handwritten instructions constitute the training data.

[0102] Specifically, the training data construction process can be as follows Figure 3 As shown. Figure 3 The external models and tools used in the article are introduced as follows:

[0103] BLIP2: The model and code can be found in the github repository (https: / / github.com / huggingface / blog / blob / main / blip-2.md). The specific usage process is to input an image and get a text description of the image, i.e., a caption.

[0104] Prompt2Prompt: The specific model and code can be found in the github repository (https: / / github.com / google / prompt-to-prompt), which can perform local and global editing by modifying the words in the original prompt.

[0105] Inverse model: For the specific model and method, please refer to the paper titled "Null-text Inversion for Editing Real Images using Guided Diffusion Models". The code can be found in the github repository (https: / / null-text-inversion.github.io / ). Given an input image and text description, optimize the inverse diffusion trajectory of the input image to obtain the Gaussian noise corresponding to this image and the latent variables in the generation process.

[0106] InstructPix2Pix: The specific model and code can be found in the github repository (https: / / github.com / timothybrooks / instruct-pix2pix), which uses synthetic text generated by fine-tuned GPT-3 and images generated by Prompt2Prompt to edit real images in an instruction-guided manner.

[0107] Figure 3 In the training data construction process, the overall process can include the following steps:

[0108] In the first step, given an input image, we first use an image description generator (Captioner) such as BLIP2 to obtain a text description (caption) of the input image. Figure 3 For the input image shown in , we get the corresponding text description: "a woman with red hair smiling at the carema".

[0109] In the second step, based on the text description obtained in the first step, the method in the Inverse model work is used to obtain latent variables (latents) based on this text description and the corresponding Gaussian noise (noise)

[0110] In the third step, the handwritten instructions generated during the construction of the multi-attribute instruction decomposition SFT dataset are used to convert the text description generated in the first step into the text description of the target image (targetcaption) by prompting the large language model (LLM): "a man with red hair smiling at the carema". The specific input of the large language model is: "Give you the original caption[caption],and the edit instruction[Manualinstruction],generate the target caption". Among them, the caption in "[caption]" is the text description of the original image generated in the first step: "a woman with red hair smiling at the carema"; the Manual instruction in [Manual instruction] is the handwritten instruction: "change the woman toman"; and the target caption is "a man with red hair smiling at the camera".

[0111] In the fourth step, the text description (caption) generated in the first step, the latent variables (latents) and corresponding Gaussian noise (noise) generated in the second step, and the text description (target caption) of the target image generated in the third step are used to generate a preliminary target image with the help of the Prompt2Prompt solution.

[0112] In the fifth step, the non-target area is aligned and corrected (mask refine) using the instance segmentation mask of each original image using the following formula:

[0113] F out =F in ×(1-I mask )+F p2p ×I mask ,,

[0114] Among them, F in is the original image, I mask is the segmentation mask corresponding to the target area, F out is the final target image, i.e. output, F p2p is the initial target image.

[0115] In this way, an input image (Input), an output image (Output) and a manual instruction (Manual Instruction) can be obtained to form a training sample. In the embodiment of the present invention, a total of 180,000 training samples of training data are constructed, supporting common instructions of nine attributes: hair, eyes, skin, gender, age, animation, expression, beard and glasses. The specific distribution is shown in the following table:

[0116]

[0117] In the present invention, the generated training data can be used to fine-tune the existing editing model. For the specific process and detailed introduction, please refer to InstructPix2Pix ( https: / / arxiv.org / pdf / 1905.09998.pdf ).

[0118] Since the editability of an image decays with the increase of the number of edits, the editing model cannot modify an image multiple times. The present invention introduces an image super-resolution model (such as ESRGAN) to alleviate this problem. Among them, ESRGAN inputs a low-resolution image and can output a high-resolution image. In the setting, the resolution can be increased by 4 times. The model and code of ESRGAN can be seen in the github repository: https: / / github.com / xinntao / ESRGAN.

[0119] Specifically, if Figure 4 As shown, during the continuous editing process, before the image is input into the editing model, a super-resolution model is added to supplement the image detail information, thereby reducing the loss of image detail information during the continuous editing process, maintaining the editability of the image, avoiding inconsistencies between the editing process and instructions, and outputting low-quality images, collapse, artifacts, and the like.

[0120] In one embodiment of the present invention, the image to be edited, using the editing model to gradually execute each single attribute instruction in the single attribute instruction chain to be edited, to obtain the edited image comprises:

[0121] In each step of executing a single attribute instruction using the editing model, the image to be edited in the step is first input into the super-resolution model, then the image output by the super-resolution model is input into the editing model, and finally the editing model is used to execute the single attribute instruction for editing.

[0122] like Figure 4 As shown, a complete embodiment of the present invention includes:

[0123] Input a face image to be edited and a multi-attribute editing instruction, i.e., "Alter the girl to have black hair, pink skin, and be in a Disney cartoon art style." The multi-attribute editing instruction is injected into Figure 2 The instruction decomposition prompt template described above obtains the input of the large language model:

[0124] Give you an example of instruction decomposition

[0125] Input:Turn the person to female and with glasses

[0126] Output:The instruction involves two attribute changes,

[0127] gender and glasses.Then decompose it.

[0128] The result is:

[0129] Step1,Make the person into a woman;

[0130] Step2,Make him wear glasses.”

[0131] Decompose[Alter the girl to have black hair,pink skin,and be in aDisney cartoon art style.]step by step according to the above format.

[0132] Through the processing of the large language model, the output instruction decomposition result is obtained [Turn the hair color to black, Alter the skin color to pink, Make her Disney cartoon style]. After obtaining a series of single-attribute editing instructions, the image editing model (Editor) is called in sequence from left to right in the instruction decomposition chain to execute all single-attribute instructions. Note that the face image needs to be super-resolved using the super-resolution model (SR) before entering the image editing model. The final output result is the editing result of the multi-attribute editing instruction.

[0133] The multi-attribute image editing method based on instruction chain provided by the present invention has the following beneficial effects compared with the prior art: the technical solution provided by the present invention can effectively solve the image editing problem of multi-attribute instructions, so that the edited image has a high consistency with the multi-attribute instructions. The solution provided by the present invention mainly achieves this effect from the following three aspects: 1. By utilizing the powerful instruction decomposition capability of LLM to decompose and process multi-attribute complex instructions, the problem that the text-based image editing model cannot understand complex instructions is alleviated; 2. By constructing high-quality image editing training data to fine-tune the existing image editing model, the controllability of the existing image editing model for single-attribute editing tasks is improved; 3. Using a simple image super-resolution model to perform super-resolution processing on the input image data, the detailed information of the input image is completed, and the continuous editability of the image is improved. In addition, the technical solution provided by the present invention can also utilize the existing model acceleration technology to improve the speed of large language model instruction decomposition and the speed of single-step editing of the image editing model, thereby improving the overall rate of the technical solution; it can also explore the combination order of single-attribute instruction chains after the decomposition of multi-attribute instructions, and explore what kind of combination logic can make the final editing effect the best.

[0134] Embodiment 2

[0135] like Figure 5 As shown, another aspect of the present invention also includes a functional module architecture that is completely consistent with the aforementioned method flow, that is, the embodiment of the present invention also provides a multi-attribute image editing device based on a command chain, including:

[0136] An SFT data set construction module 501 is used to construct an SFT data set, wherein the SFT data set includes multi-attribute instructions and corresponding single-attribute instruction chains;

[0137] A large language model fine-tuning module 502 is used to fine-tune the pre-trained large language model using the multi-attribute instructions and the corresponding single-attribute instruction chains in the SFT data set to obtain a trained large language model;

[0138] The instruction decomposition module 503 is used to decompose a multi-attribute instruction to be edited into a single-attribute instruction chain to be edited by using the trained large language model;

[0139] The image editing module 504 is used to use the editing model to gradually execute each single attribute instruction in the single attribute instruction chain to be edited for the image to be edited, so as to obtain the edited image.

[0140] The device can be implemented by the multi-attribute image editing method based on command chain provided in the above-mentioned embodiment 1. The specific implementation method can be found in the description of embodiment 1, which will not be repeated here.

[0141] The present invention also provides a memory storing a plurality of instructions, wherein the instructions are used to implement the multi-attribute image editing method based on instruction chain as described in the first embodiment.

[0142] The present invention also provides an electronic device, comprising a processor and a memory connected to the processor, wherein the memory stores a plurality of instructions, and the instructions can be loaded and executed by the processor so that the processor can execute the multi-attribute image editing method based on instruction chain as described in Example 1.

[0143] Although preferred embodiments of the present invention have been described, additional changes and modifications may be made to these embodiments by those skilled in the art once the basic inventive concepts are known. Therefore, the appended claims are intended to be interpreted as including the preferred embodiments and all changes and modifications that fall within the scope of the present invention. Obviously, those skilled in the art may make various changes and modifications to the present invention without departing from the spirit and scope of the present invention. Thus, if these modifications and variations of the present invention fall within the scope of the claims of the present invention and their equivalents, the present invention is also intended to include these modifications and variations.

Claims

1. A multi-attribute image editing method based on command chain, characterized in that: include: Constructing an SFT data set, wherein the SFT data set includes multi-attribute instructions and corresponding single-attribute instruction chains; Fine-tune the pre-trained large language model using the multi-attribute instructions and the corresponding single-attribute instruction chains in the SFT data set to obtain a trained large language model; Decomposing a multi-attribute instruction to be edited into a single-attribute instruction chain to be edited by using a trained large language model, including: setting an instruction decomposition prompt template, wherein the instruction decomposition prompt template is used to guide the large language model to decompose the multi-attribute instruction and specify an output format of the single-attribute instruction chain; For the image to be edited, the editing model is used to gradually execute each single attribute instruction in the single attribute instruction chain to be edited to obtain the edited image.

2. The multi-attribute image editing method based on command chaining as claimed in claim 1, characterized in that: The constructing of the SFT data set comprises: Set multiple instruction templates for each attribute, and generate corresponding single-attribute instructions based on each instruction template; Generate a multi-attribute instruction and a corresponding single-attribute instruction chain according to multiple single-attribute instructions; All generated multi-attribute instructions and corresponding single-attribute instruction chains constitute the SFT data set.

3. The multi-attribute image editing method based on command chaining as claimed in claim 2, characterized in that: The generating of corresponding single-attribute instructions based on each instruction template includes: calling the API of OpenAI GPT4, using the format of "Help meto rewrite the sentence: [input]", where "input" is the instruction template.

4. The multi-attribute image editing method based on command chaining as claimed in claim 2, characterized in that: The generating a multi-attribute instruction and a corresponding single-attribute instruction chain according to a plurality of single-attribute instructions includes: calling the API of OpenAI GPT4, and the format adopted is: "Help me to combine these instructions into one instruction:[intrsuction1, instruction2, ...]", wherein "intrsuction1, instruction2, ..." are all single-attribute instructions.

5. The multi-attribute image editing method based on command chaining as claimed in claim 1, characterized in that: The fine-tuning of the pre-trained large language model using the multi-attribute instructions and the corresponding single-attribute instruction chains in the SFT data set includes: The multi-attribute instructions in the SFT data set are used as the input of the pre-trained large language model, and the single-attribute instruction chain in the SFT data set is used as the output of the pre-trained large language model to train the pre-trained large language model.

6. The multi-attribute image editing method based on command chaining as claimed in claim 1, characterized in that: The instruction decomposition prompt template includes a first prompt text, a second prompt text and a third prompt text. The first prompt text is used to prompt the trained large language model to complete a multi-attribute instruction decomposition task; the second prompt text is used to provide the trained large language model with a specific multi-attribute instruction decomposition case, as well as input and output content and corresponding formats; the third prompt text is used to embed the multi-attribute instruction to be processed into the instruction decomposition prompt template.

7. The multi-attribute image editing method based on command chaining as claimed in claim 1, characterized in that: The editing model is obtained by fine-tuning pre-constructed training data, and the training data is constructed using the following method: Get a dataset of original images; Using the image description generator to obtain the original text description corresponding to the original image; Obtaining latent variables and corresponding Gaussian noise based on the original text description; Converting the original text description into a target text description using handwritten instructions; Generate a preliminary target image using the original text description, latent variables and corresponding Gaussian noise, and target text description; The following formula is used to align and correct the non-target area using the instance segmentation mask of each original image to obtain the final target image: , in, is the original image, is the segmentation mask corresponding to the target area, is the final target image, is the preliminary target image; The original image, the final target image and the handwritten instructions constitute the training data.

8. The multi-attribute image editing method based on command chaining as claimed in claim 7, characterized in that: The converting the original text description into a target text description by using handwritten instructions includes: using an instruction template set for an attribute when constructing an SFT data set, and converting the original text description into a target text description through a large language model.

9. The multi-attribute image editing method based on command chaining as claimed in claim 1, characterized in that: The image to be edited is executed step by step using the editing model to execute each single attribute instruction in the single attribute instruction chain to be edited, and the edited image is obtained. In each step of executing a single attribute instruction using the editing model, the image to be edited in the step is first input into the super-resolution model, then the image output by the super-resolution model is input into the editing model, and finally the editing model is used to execute the single attribute instruction for editing.

10. A multi-attribute image editing device based on command chain, characterized in that: include: An SFT data set construction module, used to construct an SFT data set, wherein the SFT data set includes multi-attribute instructions and corresponding single-attribute instruction chains; A large language model fine-tuning module, used to fine-tune the pre-trained large language model using the multi-attribute instructions and the corresponding single-attribute instruction chains in the SFT data set to obtain a trained large language model; The instruction decomposition module is used to decompose a multi-attribute instruction to be edited into a single-attribute instruction chain to be edited by using a trained large language model, including: setting an instruction decomposition prompt template, wherein the instruction decomposition prompt template is used to guide the large language model to decompose the multi-attribute instruction and specify the output format of the single-attribute instruction chain; The image editing module is used to use the editing model to gradually execute each single attribute instruction in the single attribute instruction chain to be edited for the image to be edited, so as to obtain the edited image.

11. A memory, characterized in that: A plurality of instructions are stored, and the instructions are loaded and executed by a processor to implement the multi-attribute image editing method based on instruction chain as described in any one of claims 1-9.

12. An electronic device, characterized in that: It includes a processor and a memory connected to the processor, wherein the memory stores multiple instructions, and the instructions can be loaded and executed by the processor so that the processor can execute the multi-attribute image editing method based on instruction chain as described in any one of claims 1-9.