Picture generation method, electronic equipment and medium
By generating concept rendering vectors and target text, the problem of style migration after image generation in the Vincentian graph model is solved, efficient custom style modification and semantic retention are achieved, and resource consumption of network fine-tuning is avoided.
Patent Information
- Application Number
- CN202410885843.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-03
- Publication Date
- 2024-10-08
- Estimated Expiration
- 2044-07-03
AI Technical Summary
There is a one-to-one relationship between pictures and text generated by the existing Vincentian graph model. It is difficult for users to re-create or customize the style of the generated pictures, and the existing method requires time-consuming fine-tuning of the entire network to preserve the user's original Text entity.
By obtaining the encoding vector of the original text and the opposite concept, the concept rendering vector is generated and combined with the original text vector to form the target text vector, maximizing the cosine similarity to generate the optimal target text, input the original text and target text to the Vincent diagram model to Generate original and target images.
It realizes the automatic generation of target images without prior knowledge, retains the semantic features of the original image to the greatest extent, improves the generation efficiency, and avoids the time and resource consumption of network fine-tuning.
Smart Images

Figure BDA0004926027780000031 
Figure FDA0004926027760000011 
Figure HDA0004926027800000011
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of machine learning, and in particular to a picture generation method, electronic equipment, and medium. Background Art
[0002] Text-generated graph models (such as Stablediffusion) have attracted widespread attention due to their excellent generation capabilities. Text-generated graph models can create amazing works of art based on the text input by users. The scope of application includes scene design, animation creation, 3D scene generation, etc. However, since the generated images and texts are in a one-to-one relationship, it is difficult for users to re-create their generated images or transfer the style of images with a custom style after generating them. Therefore, how to allow users to complete custom style modifications to their own creations has become a problem to be solved.
[0003] Existing works (such as diffusion inversion or Dreambooth) can achieve user-defined style modification, however, they need to fine-tune the entire network to preserve the entities in the user's original text for reuse in the style transfer task. But this fine-tuning is time-consuming and consumes additional training resources. Summary of the invention
[0004] In view of the deficiencies in the prior art, the embodiments of the present invention provide a method for generating an image, an electronic device, and a medium.
[0005] In a first aspect, an embodiment of the present invention provides a method for generating an image, the method comprising the following steps:
[0006] Obtaining an original text, a first concept, and a second concept having a meaning opposite to the first concept; encoding the original text, the first concept, and the second concept to obtain an original text vector, a first concept vector, and a second concept vector;
[0007] Subtracting the first concept vector from the second concept vector to obtain a concept rendering vector; adding the scaled concept rendering vector to the original text vector to obtain a rendering text vector;
[0008] Splice the learnable prefix before the original text to obtain the target text; encode the target text to obtain the target text vector;
[0009] By maximizing the cosine similarity between the rendered text vector and the target text vector, the optimal target text closest to the rendered text is obtained;
[0010] The original text and the optimal target text are respectively input into the text-generated graph model to obtain the original image and the target image.
[0011] In a second aspect, an embodiment of the present invention provides an electronic device, comprising a memory and a processor, wherein the memory is coupled to the processor; wherein the memory is used to store program data, and the processor is used to execute the program data to implement the above-mentioned image generation method.
[0012] In a third aspect, an embodiment of the present invention provides a computer-readable storage medium having a computer program stored thereon, wherein the program implements the above-mentioned image generation method when executed by a processor.
[0013] In a fourth aspect, an embodiment of the present invention provides a computer program product, including a computer program / instruction, which implements the above-mentioned image generation method when executed by a processor.
[0014] Compared with the prior art, the present invention has the following beneficial effects:
[0015] The present invention provides a method for generating an image, which generates an original image and a target image by inputting the original text and the optimal target text obtained after concept rendering into a text-generated graph model. The method of the present invention can also automatically generate the target image without any prior knowledge. The image generated by the present invention retains the semantic features of the original image to the greatest extent and improves the generation efficiency. BRIEF DESCRIPTION OF THE DRAWINGS
[0016] In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the accompanying drawings required for use in the description of the embodiments will be briefly introduced below. Obviously, the accompanying drawings in the following description are only some embodiments of the present invention. For ordinary technicians in this field, other accompanying drawings can be obtained based on these accompanying drawings without paying creative labor.
[0017] Figure 1 A schematic diagram of a process for generating an image according to an embodiment of the present invention;
[0018] Figure 2 A schematic diagram of the structure of a method for generating an image provided by an embodiment of the present invention;
[0019] Figure 3 An example diagram of generating a picture provided by an embodiment of the present invention;
[0020] Figure 4 A schematic diagram of an electronic device provided by an embodiment of the present invention. DETAILED DESCRIPTION
[0021] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0022] It should be noted that, in the absence of conflict, the features in the following embodiments and implementations may be combined with each other.
[0023] like Figure 1 and Figure 2 As shown, an embodiment of the present invention provides a method for generating an image, and the method specifically includes the following steps:
[0024] Step S1, obtaining an original text, a first concept, and a second concept having the opposite meaning to the first concept; encoding the original text, the first concept, and the second concept to obtain an original text vector, a first concept vector, and a second concept vector.
[0025] Furthermore, in this example, the original text is defined as a sentence with a length of L, denoted by p t =[p 1 , p 2 , ..., p L ].
[0026] For example, assuming that the first concept representing the concept of "female" r + The first concept is "woman", and the second concept r is "man".
[0027] Furthermore, given an encoder f(·), the original text, the first concept, and the second concept are encoded to obtain the original text vector f(p t ), the first concept vector f(r + ), the second concept vector f(r - ).
[0028] Step S2: subtract the first concept vector from the second concept vector to obtain a concept rendering vector; and add the scaled concept rendering vector to the original text vector to obtain a rendering text vector.
[0029] Furthermore, in the vector space, the analogy relationship between vectors can be expressed as the add-subtract feature between words with similar meanings, such as f('Queen')-f('woman')+f('man')=f('king'). In this example, the first concept vector and the second concept vector are subtracted by using the analogy feature of the vector space to obtain the concept rendering vector r, which is expressed as follows:
[0030] r = f(r + )-f(r - )
[0031] The concept rendering vector is scaled and added to the original text vector to obtain the rendered text vector, which is expressed as follows:
[0032] f(p r )=f(p t )+λ·r
[0033] In the formula, f(p r ) represents the rendered text vector, and λ represents the scaling factor.
[0034] It should be noted that this example uses the analogy characteristics of the vector space to conceptually render the high-dimensional representation of the original text, thereby achieving semantic migration from the original text to the target concept.
[0035] Step S3, concatenating a learnable prefix in front of the original text to obtain a target text; encoding the target text to obtain a target text vector.
[0036] Specifically, for each original text pt, a learnable prefix k is added to it in the text space, denoted as [v 1 ,..,v i , .., v k ]; where i represents the i-th position, i∈k, v i ∈V, V is a predefined vocabulary. For example, in the text space of CLIP, V is a vocabulary of length 49408.
[0037] Furthermore, the expression of the target text pa is as follows:
[0038] p a =[v 1 , .., v i , .., v k , p 1 ,,..,p L ]
[0039] Encode the target text and obtain the target text vector f(p a ).
[0040] Step S4, obtaining the optimal target text that is closest to the rendered text by maximizing the cosine similarity between the rendered text vector and the target text vector.
[0041] Specifically, the cosine similarity between the rendered text vector and the target text vector is defined as the learning objective, and the learnable target text is optimized by maximizing the cosine similarity of the two vectors. The learning objective is:
[0042]
[0043] Furthermore, the step S4 further includes:
[0044] For each learnable word v i The gradient is set, and the learnable prefix k in the target text is updated by gradient descent through PGD (Project Gradient Descent), and a search is performed in the discrete text space to optimize the optimal target text pa that meets the learning objectives.
[0045] Step S5, inputting the original text and the optimal target text into the text-generated graph model respectively to obtain the original image and the target image.
[0046] Specifically, the original text pt and the optimal target text pa are input into the stable diffusion model respectively, and the stable diffusion model is represented as M(·), and the original image M(p t ) and the target image M(p a ). The original picture M(p t ) and the target image M(p a ) are semantically similar. The image M(p a ) contains specific concepts.
[0047] Example 1
[0048] Figure 3 (A) in is the first example of the generated image. Figure 3 In (A), the original text is "A photo of a chocolate cake", and the concept is "strawberry". After concept rendering, the optimal target text is "gergeous strawafantastic A photo of a chocolate cake". The original text and the optimal target are respectively input into the text graph model to obtain the original picture of chocolate cake and the target picture of chocolate cake with strawberries.
[0049] Figure 3 (B) in is the first example of the generated image. Figure 3In (B), the original text is "Aphotoofaking" and the concept is "woman". After concept rendering, the optimal target text is "glumeryfemalasex A photo of a king". The original text and the optimal target are respectively input into the Wensheng graph model to obtain the original photo of the king and the target picture of the king with female characteristics.
[0050] like Figure 4 As shown, an embodiment of the present application provides an electronic device, which includes a memory 101 for storing one or more programs and a processor 102. When the one or more programs are executed by the processor 102, any method in the first aspect described above is implemented.
[0051] The memory 101, the processor 102 and the communication interface 103 are directly or indirectly electrically connected to each other to achieve data transmission or interaction. For example, these elements can be electrically connected to each other through one or more communication buses or signal lines. The memory 101 can be used to store software programs and modules, and the processor 102 executes various functional applications and data processing by executing the software programs and modules stored in the memory 101. The communication interface 103 can be used to communicate signaling or data with other node devices.
[0052] Among them, the memory 101 can be, but is not limited to, a random access memory 101 (Random Access Memory, RAM), a read only memory 101 (Read Only Memory, ROM), a programmable read-only memory 101 (Programmable Read-Only Memory, PROM), an erasable read-only memory 101 (Erasable Programmable Read-Only Memory, EPROM), an electrically erasable read-only memory 101 (Electric Erasable Programmable Read-Only Memory, EEPROM), etc.
[0053] The processor 102 may be an integrated circuit chip with signal processing capability. The processor 102 may be a general-purpose processor 102, including a central processing unit 102 (CPU), a network processor 102 (NP), etc.; it may also be a digital signal processor 102 (DSP), an application-specific integrated circuit (ASIC), a field-programmable gate array (FPGA), or other programmable logic devices, discrete gate or transistor logic devices, or discrete hardware components.
[0054] In the embodiments provided in the present application, it should be understood that the disclosed method and system can also be implemented in other ways. The method and system embodiments described above are merely schematic. For example, the flowcharts and block diagrams in the accompanying drawings show the possible architecture, functions and operations of the method and system, method and computer program product according to multiple embodiments of the present application. In this regard, each box in the flowchart or block diagram can represent a module, a program segment or a part of a code, and the module, a program segment or a part of a code contains one or more executable instructions for implementing a specified logical function. It should also be noted that in some alternative implementations, the functions marked in the box can also occur in a different order from the order marked in the accompanying drawings. For example, two consecutive boxes can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each box in the block diagram and / or the flowchart, and the combination of boxes in the block diagram and / or the flowchart can be implemented with a dedicated hardware-based system that performs a specified function or action, or can be implemented with a combination of dedicated hardware and computer instructions.
[0055] In addition, the functional modules in the various embodiments of the present application may be integrated together to form an independent part, or each module may exist separately, or two or more modules may be integrated to form an independent part.
[0056] On the other hand, an embodiment of the present application provides a computer-readable storage medium on which a computer program is stored, and when the computer program is executed by the processor 102, a method as in any one of the first aspects described above is implemented. If the function is implemented in the form of a software function module and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on such an understanding, the technical solution of the present application is essentially or the part that contributes to the prior art or the part of the technical solution can be embodied in the form of a software product, and the computer software product is stored in a storage medium, including a number of instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the method described in each embodiment of the present application. The aforementioned storage medium includes: a U disk, a mobile hard disk, a read-only memory 101 (ROM, Read-Only Memory), a random access memory 101 (RAM, RandomAccess Memory), a disk or an optical disk, and other media that can store program codes.
[0057] Those skilled in the art will readily appreciate other embodiments of the present application after considering the description and practicing the contents disclosed herein. The present application is intended to cover any variations, uses or adaptations of the present application, which follow the general principles of the present application and include common knowledge or customary technical means in the art that are not disclosed in the present application. The description and examples are intended to be exemplary only.
[0058] It should be understood that the present application is not limited to the exact construction that has been described above and shown in the drawings, and that various modifications and changes may be made without departing from the scope thereof.
Claims
1. A method for generating an image, It is characterized in that The method comprises the following steps: Obtaining an original text, a first concept, and a second concept having a meaning opposite to the first concept; encoding the original text, the first concept, and the second concept to obtain an original text vector, a first concept vector, and a second concept vector; Subtracting the first concept vector from the second concept vector to obtain a concept rendering vector; adding the scaled concept rendering vector to the original text vector to obtain a rendering text vector; Splice the learnable prefix before the original text to obtain the target text; encode the target text to obtain the target text vector; By maximizing the cosine similarity between the rendered text vector and the target text vector, the optimal target text closest to the rendered text is obtained; The original text and the optimal target text are respectively input into the text-generated graph model to obtain the original image and the target image.
2. A method for generating an image according to claim 1, It is characterized in that The concept rendering vector is scaled and added to the original text vector to obtain the rendered text vector including: f(p r )=f(p r )+λ·r In the formula, f(p r ) represents the rendered text vector, f(p t ) represents the original text vector, , = λ represents the scaling ratio, and r represents the concept rendering vector.
3. A method for generating an image according to claim 1, It is characterized in that The learnable prefix is concatenated before the original text, and the target text includes: The learnable prefix k is denoted as [v 1 , ..., v i , ..., v k ]; where i represents the i-th position, i∈k, v i ∈V, V is a predefined vocabulary; The target text is obtained by concatenating the learnable prefix in front of the original text; the expression is as follows: p a =[in 1 ,in i ,..,in k ,p 1 ,,..,p L ] In the formula, p a represents the target text, p t =[p 1 , p 2 , ..., p L ] represents the original text, and L represents the length of the original text.
4. A method for generating an image according to claim 1, It is characterized in that By maximizing the cosine similarity between the rendered text vector and the target text vector, the optimal target text closest to the rendered text is obtained: The cosine similarity between the rendered text vector and the target text vector is defined as the learning objective. By maximizing the cosine similarity of the two vectors, the learnable target text is optimized. The learning objective is: In the formula, f(p r ) represents the rendered text vector, f(p a ) represents the target text vector.
5. A method for generating an image according to claim 3, It is characterized in that The process of obtaining the optimal target text closest to the rendered text also includes: For each learnable word v in the learnable prefix k i Set the gradient and perform gradient descent update on the learnable prefix k in the target text to optimize the optimal target text p that maximizes the cosine similarity between the rendered text vector and the target text vector. a .
6. An electronic device comprising a memory and a processor, It is characterized in that The memory is coupled to the processor; wherein the memory is used to store program data, and the processor is used to execute the program data to implement the image generation method described in any one of claims 1-5 above.
7. A computer-readable storage medium having a computer program stored thereon, It is characterized in that When the program is executed by a processor, the image generation method as described in any one of claims 1 to 5 is implemented.
8. A computer program product comprising a computer program / instructions, It is characterized in that When the computer program / instruction is executed by a processor, the image generation method described in any one of claims 1-5 is implemented.
Citation Information
Patent Citations
Teaching text comparison method, device, electronic equipment and medium
CN110489549A
Image generation method and device, computer equipment and storage medium
CN116433825A
Signaling concept drift during knowledge base population
US20210174216A1
