Diversified personalized image generation method and system
Conditional vectors are generated by text and image encoders, and the image generator is optimized using the combination of penalty terms and multi-LoRA weights, which solves the limitations and subjective experience dependence of image generation in traditional technologies, and achieves high-quality diversified personalization. Image generation, reducing computational storage requirements.
Patent Information
- Application Number
- CN202410624186.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-05-20
- Publication Date
- 2024-09-27
AI Technical Summary
Traditional image generation technology is difficult to generate high-quality personalized images on any theme and style, and the generation process has limitations and cannot meet a variety of personalized needs. Moreover, the weighted weights rely on subjective experience, resulting in unsatisfactory quality of the generated results. and high computing and storage requirements.
By inputting text descriptions and reference images, using text encoders and image encoders to generate content representation vectors and style representation vectors, combined with adaptive merging of penalty terms and multiple LoRA weights, the network structure of the image generator is optimized to generate personalized target images. , reduce signal interference, and balance different design styles and elements.
It achieves high-quality diversified personalized image generation, reduces the impact of subjective experience, improves image generation quality, reduces computing and storage resource requirements, and improves reasoning efficiency.
Smart Images

Figure CN118710488A
Abstract
Description
Technical Field
[0001] The present invention relates to image generation means, belongs to the field of computer vision and machine learning, and in particular to a diversified personalized image generation method and system. Background Art
[0002] Image generation is the process of mapping and generating specific categories or labels. Traditional image generation technology can only generate images within the scope of a specific theme or a specific style. It is difficult to achieve the synthesis of any theme and style. There are certain limitations in the generation process and it cannot meet a variety of personalized needs. Although personalized image generation technology can achieve personalized generation of specific themes and specific styles, it often uses a weighted approach in the generation process, and the weighted values are mostly set based on subjective experience. Not only can it not maintain the multi-element characteristics of the generated image, the quality of the generated result is not ideal, and the generation process is relatively long, with high requirements for computing and storage. Therefore, there is an urgent need for a means to solve the above-mentioned defects in the existing technology to achieve high-quality image generation for multiple design elements. Summary of the invention
[0003] The purpose of the present invention is to overcome the above-mentioned defects and problems existing in the prior art and to provide a diversified personalized image generation method and system which can not only generate personalized images but also have good image generation quality.
[0004] To achieve the above objectives, the technical solution of the present invention is: a diversified personalized image generation method, comprising:
[0005] S1. Input text description and reference image; the text description is the content of the desired generated image, and the reference image is the style reference of the desired generated image;
[0006] S2, encoding the text description based on the text encoder to obtain a content representation vector, and encoding the reference image based on the image encoder to obtain a style representation vector;
[0007] S3, concatenating the content representation vector and the style representation vector to obtain a conditional vector;
[0008] S4. By introducing the penalty term and adaptively merging multiple LoRA weights, and optimizing the network structure of the image generator, the image generator is improved to obtain a multi-style image generator based on improved LoRA;
[0009] S5. A multi-style image generator based on the improved LoRA takes the conditional vector as input to generate personalized target images.
[0010] The step S4 specifically includes:
[0011] S41, collecting image data to form a large-scale image dataset, and then pre-training a base model of an image generator on the large-scale image dataset, so that the image generator learns a general image generation capability;
[0012] S42. For different target styles, collect image datasets of corresponding styles, and use LoRA technology to fine-tune the image datasets based on the base model to obtain several LoRA weights suitable for different target styles;
[0013] S43, merge the LoRA weights of all styles, and introduce a penalty term in the merging process to obtain a merged LoRA weight; the merged expression is as follows:
[0014] W=merge({W_i})+λ*penalty({W_i});
[0015] Where: W is the merged LoRA weight, Wi is the LoRA weight of different target styles, merge() is the merging operation of LoRA weights, penalty() is the penalty term, and λ is the balance factor.
[0016] In step S43, the step of merging the LoRA weights of all styles includes:
[0017] S431, design a weight adjustment matrix, and uniformly initialize the weights of each LoRA module in the weight adjustment matrix; the dimension of the weight adjustment matrix is (N, M), where N is the number of LoRA modules, and M is the number of parameters of each LoRA module;
[0018] S432, using the elements of the weight adjustment matrix as learnable parameters, automatically updating the optimized loss function through gradient descent, and obtaining an optimized weight adjustment matrix;
[0019] S433, based on the optimized weight adjustment matrix, perform LoRA weight merging; the expression of the merging is as follows:
[0020] W'=W+sum(A[i,:]*Li), i=1 to N;
[0021] Where: W′ is the merged LoRA weight adjustment matrix, W is the original weight adjustment matrix, Li is the weight matrix of the i-th LoRA module, and A[i,:] is the i-th row of the weight adjustment matrix A;
[0022] S434. Define a penalty item; the penalty item is as follows:
[0023] P = λ*||W′-W||_F^2;
[0024] Where: P is the penalty term, λ is the balance factor, ||||_F is the Frobenius norm of the weight adjustment matrix;
[0025] S435, adding the penalty term to the loss function, and minimizing the loss function; the loss function is as follows:
[0026] L = L_recon + P;
[0027] Where: L is the loss function, L_recon is the reconstruction loss of image generation, and P is the penalty term.
[0028] In the step S4, optimizing the network structure of the image generator means: adding an attention module after each upsampling layer of the decoder part of the image generator, introducing a discriminator to judge the authenticity of the output of the image generator, and then training and optimizing the image generator. During the training process, the discriminator and the image generator are optimized alternately. Finally, at the end of each training cycle, the quality of the generated personalized target image is evaluated, and the learning rates of the discriminator and the image generator are adjusted as needed.
[0029] The step S5 specifically includes:
[0030] S51, based on the reference image, identifying the style category to which the reference image belongs, and selecting a corresponding LoRA sub-weight from the merged LoRA weight;
[0031] S52, based on the base model and the LoRA sub-weight, with the conditional vector as input, generate a personalized target image; the generated expression is as follows:
[0032] O = G(Z; W_k);
[0033] Where: O is the generated personalized target image, G is the base model, Z is the conditional vector, and W_k is the LoRA sub-weight.
[0034] A diversified personalized image generation system, the system comprising:
[0035] A text and image input module, used to input text description and reference image; the text description is the content of the desired generated image, and the reference image is the style reference of the desired generated image;
[0036] A style representation module is used to encode the text description based on the text encoder to obtain a content representation vector, and to encode the reference image based on the image encoder to obtain a style representation vector;
[0037] A conditional vector module is used to concatenate the content representation vector and the style representation vector to obtain a conditional vector;
[0038] The image generator optimization module is used to improve the image generator by introducing a penalty term and adaptively merging multiple LoRA weights, while optimizing the network structure of the image generator, thereby obtaining a multi-style image generator based on improved LoRA;
[0039] The image generation module is used to generate personalized target images based on the multi-style image generator based on the improved LoRA, taking the conditional vector as input.
[0040] The image generator optimization module optimizes the image generator according to the following steps:
[0041] S41, collecting image data to form a large-scale image dataset, and then pre-training a base model of an image generator on the large-scale image dataset, so that the image generator learns a general image generation capability;
[0042] S42. For different target styles, collect image datasets of corresponding styles, and use LoRA technology to fine-tune the image datasets based on the base model to obtain several LoRA weights suitable for different target styles;
[0043] S43, merge the LoRA weights of all styles, and introduce a penalty term in the merging process to obtain a merged LoRA weight; the merged expression is as follows:
[0044] W=merge({W_i})+λ*penalty({W_i});
[0045] Where: W is the combined LoRA weight, W _ i is the LoRA weight of different target styles, merge() is the merging operation of LoRA weights, penalty() is the penalty term, and λ is the balance factor.
[0046] In step S43, the step of merging the LoRA weights of all styles includes:
[0047] S431, design a weight adjustment matrix, and uniformly initialize the weights of each LoRA module in the weight adjustment matrix; the dimension of the weight adjustment matrix is (N, M), where N is the number of LoRA modules, and M is the number of parameters of each LoRA module;
[0048] S432, using the elements of the weight adjustment matrix as learnable parameters, automatically updating the optimized loss function through gradient descent, and obtaining an optimized weight adjustment matrix;
[0049] S433, based on the optimized weight adjustment matrix, perform LoRA weight merging; the expression of the merging is as follows:
[0050] W'=W+sum(A[i,:]*Li), i=1 to N;
[0051] Where: W′ is the merged LoRA weight adjustment matrix, W is the original weight adjustment matrix, Li is the weight matrix of the i-th LoRA module, and A[i,:] is the i-th row of the weight adjustment matrix A;
[0052] S434. Define a penalty item; the penalty item is as follows:
[0053] P = λ*||W′-W||_F^2;
[0054] Where: P is the penalty term, λ is the balance factor, ||||_F is the Frobenius norm of the weight adjustment matrix;
[0055] S435, adding the penalty term to the loss function, and minimizing the loss function; the loss function is as follows:
[0056] L = L_recon + P;
[0057] Among them: L is the loss function, L_recon is the reconstruction loss of image generation, and P is the penalty top.
[0058] The image generator optimization module optimizes the network structure of the image generator in the following ways:
[0059] An attention module is added after each upsampling layer of the decoder part of the image generator, and a discriminator is introduced to judge the authenticity of the output of the image generator. The image generator is then trained and optimized. During the training process, the discriminator and the image generator are optimized alternately. Finally, at the end of each training cycle, the quality of the generated personalized target image is evaluated, and the learning rates of the discriminator and the image generator are adjusted as needed.
[0060] The image generation module generates an image according to the following steps:
[0061] S51, based on the reference image, identifying the style category to which the reference image belongs, and selecting a corresponding LoRA sub-weight from the merged LoRA weight;
[0062] S52, based on the base model and the LoRA sub-weight, with the conditional vector as input, generate a personalized target image; the generated expression is as follows:
[0063] O = G(Z; W_k);
[0064] Where: O is the generated personalized target image, G is the base model, Z is the conditional vector, and W_k is the LoRA sub-weight.
[0065] Compared with the prior art, the present invention has the following beneficial effects:
[0066] 1. In a diversified personalized image generation method and system of the present invention, the method first inputs a text description and a reference image, and then encodes the text description and the reference image based on a text encoder and an image encoder respectively to obtain a content representation vector and a style representation vector, and then splices the two into a conditional vector, and then introduces a penalty term and adaptively merges multiple LoRA weights, while optimizing the network structure of the image generator, improves the image generator, and uses the conditional vector as input to generate a personalized target image; in the application, this design synthesizes multiple LoRA weights and introduces a penalty term, so that in the image generation process, the signal interference between various contents and styles is reduced, and different design styles and elements are effectively balanced, and there is no need to manually adjust parameters or merge weights, thereby reducing the influence of subjective experience and improving the image generation quality. Therefore, the present invention not only realizes the generation of personalized images, but also has good image generation quality.
[0067] 2. In a diversified personalized image generation method and system of the present invention, through the processing and merging of multiple LoRAs, and integrating the training model, the network structure of the image generator is optimized, and the image generator is improved, so that the present invention can not only flexibly generate personalized images of various styles according to the style reference provided by the user, but also the merged LoRA weights have higher parameter efficiency, which can significantly improve the reasoning efficiency and reduce the demand for computing and storage resources. BRIEF DESCRIPTION OF THE DRAWINGS
[0068] Figure 1 It is a flow chart of the method steps of the present invention.
[0069] Figure 2 It is a schematic diagram of the network structure of the image generator in Example 1 of the present invention.
[0070] Figure 3 It is a schematic diagram of the system structure of the present invention.
[0071] Figure 4 It is a schematic diagram of the device structure in Example 3 of the present invention.
[0072] In the figure: text and image input module 1, style representation module 2, conditional vector module 3, image generator optimization module 4, image generation module 5, processor 6, memory 7, computer program code 71. DETAILED DESCRIPTION
[0073] The present invention is further described in detail below in conjunction with the accompanying drawings and specific implementation methods.
[0074] Embodiment 1:
[0075] See also Figure 1 , a diversified personalized image generation method, comprising:
[0076] S1. Input text description and reference image; the text description is the content of the desired generated image, and the reference image is the style reference of the desired generated image;
[0077] S2, encoding the text description based on the text encoder to obtain a content representation vector, and encoding the reference image based on the image encoder to obtain a style representation vector;
[0078] S3, concatenating the content representation vector and the style representation vector to obtain a conditional vector;
[0079] S4. By introducing the penalty term and adaptively merging multiple LoRA weights, and optimizing the network structure of the image generator, the image generator is improved to obtain a multi-style image generator based on improved LoRA;
[0080] In the personalized image generation process, the image generator plays a key role. In order to achieve diversified style generation capabilities, the image generator is fine-tuned based on the improved LoRA in this embodiment, as follows:
[0081] S41. Collect image data to form a large-scale image dataset, and then pre-train a base model of an image generator on the large-scale image dataset to enable the image generator to learn general image generation capabilities; the base model is preferably: Stable Diffusion XL.
[0082] S42. For different target styles, collect image datasets of corresponding styles, and use LoRA technology to fine-tune the image datasets based on the base model to obtain several LoRA weights suitable for different target styles;
[0083] For different target styles, such as oil painting, watercolor painting, cartoon painting, etc., images of corresponding styles are collected and image data sets are formed to provide a basis for personalized generation.
[0084] Fine-tuning in natural language processing and machine learning refers to further training a pre-trained basic model using data from a specific domain or task to adapt the model to the domain or task and improve the performance of the model in that scenario.
[0085] S43, merge the LoRA weights of all styles, and introduce a penalty term in the merging process to obtain a merged LoRA weight; the merged expression is as follows:
[0086] W=merge({W_i})+λ*penalty({W_i});
[0087] Where: W is the merged LoRA weight, Wi is the LoRA weight of different target styles, merge() is the merging operation of LoRA weights, penalty() is the penalty term, and λ is the balance factor.
[0088] Furthermore, in step S43, the step of merging the LoRA weights of all styles includes:
[0089] S431, design a weight adjustment matrix, and uniformly initialize the weights of each LoRA module in the weight adjustment matrix; the dimension of the weight adjustment matrix is (N, M), where N is the number of LoRA modules, and M is the number of parameters of each LoRA module;
[0090] S432, using the elements of the weight adjustment matrix as learnable parameters, automatically updating the optimized loss function through gradient descent, and obtaining an optimized weight adjustment matrix;
[0091] During the fine-tuning process, the model parameters are automatically updated through the gradient descent algorithm, with the goal of optimizing the loss function so that the model performs better on specific tasks. The loss function measures the gap between the model's prediction and the true label. By minimizing this gap, the model's prediction is closer to the true label. The gradient descent algorithm improves the performance of the model by calculating the gradient of the loss function with respect to the model parameters and adjusting the parameters in the opposite direction of the gradient, gradually reducing the loss function value. As training progresses, the loss function value continues to decrease, and the model's performance on specific tasks gradually improves until a satisfactory effect is achieved. This process can be seen as an adaptive process of the model on new tasks. By learning task-specific patterns and knowledge, the model gradually transforms from a general language model to a specialized model suitable for specific scenarios.
[0092] S433, based on the optimized weight adjustment matrix, perform LoRA weight merging; the expression of the merging is as follows:
[0093] W'=W+sum(A[i,:]*Li), i=1 to N;
[0094] Where: W′ is the merged LoRA weight adjustment matrix, W is the original weight adjustment matrix, Li is the weight matrix of the i-th LoRA module, and A[i,:] is the i-th row of the weight adjustment matrix A;
[0095] S434. Define a penalty item; the penalty item is as follows:
[0096] P = λ*||W′-W||_F^2;
[0097] Where: P is the penalty term, λ is the balance factor, ||||_F is the Frobenius norm of the weight adjustment matrix;
[0098] S435, adding the penalty term to the loss function, and minimizing the loss function; the loss function is as follows:
[0099] L = L_recon + P;
[0100] Where: L is the loss function, L_recon is the reconstruction loss of image generation, and P is the penalty term.
[0101] In the application, the penalty term is set to balance the interaction between the weight matrices of style and content to reduce the signal interference between them. Specifically, the penalty term is designed to reduce the similarity between multiple LoRA weights, for example: by minimizing the cosine similarity between them. Such a setting helps ensure that the generated image can reflect a specific style while retaining the characteristics of the original content.
[0102] For further information, see Figure 2 In step S4, optimizing the network structure of the image generator means: adding an attention module after each upsampling layer of the decoder part of the image generator, and introducing a discriminator to judge the authenticity of the output of the image generator, and then training and optimizing the image generator, and alternately optimizing the discriminator and the image generator during the training process, and finally evaluating the quality of generating personalized target images at the end of each training cycle, and adjusting the learning rates of the discriminator and the image generator as needed.
[0103] The means of adjusting the learning rate include: warmup, that is, using a smaller learning rate at the beginning of training, and then linearly increasing it to a preset value within a fixed number of steps, which helps to stabilize the training process at the beginning.
[0104] S5. A multi-style image generator based on the improved LoRA takes the conditional vector as input to generate personalized target images.
[0105] Further, it specifically includes:
[0106] S51, based on the reference image, identifying the style category to which the reference image belongs, and selecting a corresponding LoRA sub-weight from the merged LoRA weight;
[0107] S52, based on the base model and the LoRA sub-weight, with the conditional vector as input, generate a personalized target image; the generated expression is as follows:
[0108] O = G(Z; W_k);
[0109] Where: O is the generated personalized target image, G is the base model, Z is the conditional vector, and W_k is the LoRA sub-weight.
[0110] In application, the working process of the present invention is described by the following specific embodiments:
[0111] First, user Xiao Ming wants to generate an oil painting style painting with his beloved dog "Wangcai" as the protagonist. To this end, user Xiao Ming enters the following content:
[0112] The input text description is: A golden retriever wearing red clothes is running on the grass;
[0113] The input reference image is: a painting by Van Gogh;
[0114] Then, according to the input of user Xiao Ming, the following steps are performed:
[0115] 1. The text encoder encodes the text description "a golden retriever in red clothes running on the grass" to obtain a content representation vector; at the same time, the image encoder encodes the reference image "a Van Gogh oil painting" to obtain a style representation vector and recognize that the reference image belongs to the "oil painting" style;
[0116] 2. Concatenate the content representation vector and the style representation vector into a conditional vector;
[0117] 3. Select the sub-weight corresponding to the "oil painting" style from the merged LoRA weights, and use the base model and the sub-weight corresponding to the "oil painting" style to generate a personalized image based on the conditional vector;
[0118] 4. Post-process the generated personalized image, output the final oil painting style painting, and present it to user Xiao Ming.
[0119] In the end, user Xiao Ming got a painting with "Wangcai" as the protagonist, running on the grass. It was a personalized painting with distinctive oil painting style characteristics, which met the user's needs.
[0120] Embodiment 2:
[0121] See also Figure 3 , a diversified personalized image generation system, the system comprising:
[0122] A text and image input module 1, used to input text description and reference image; the text description is the content of the desired generated image, and the reference image is the style reference of the desired generated image;
[0123] The style representation module 2 is used to encode the text description based on the text encoder to obtain a content representation vector, and to encode the reference image based on the image encoder to obtain a style representation vector;
[0124] The conditional vector module 3 is used to concatenate the content representation vector and the style representation vector to obtain a conditional vector;
[0125] The image generator optimization module 4 is used to improve the image generator by introducing a penalty term and adaptively merging multiple LoRA weights, while optimizing the network structure of the image generator, thereby obtaining a multi-style image generator based on improved LoRA;
[0126] Further, the image generator optimization module 4 optimizes the image generator according to the following steps:
[0127] S41, collecting image data to form a large-scale image dataset, and then pre-training a base model of an image generator on the large-scale image dataset, so that the image generator learns a general image generation capability;
[0128] S42. For different target styles, collect image datasets of corresponding styles, and use LoRA technology to fine-tune the image datasets based on the base model to obtain several LoRA weights suitable for different target styles;
[0129] S43, merge the LoRA weights of all styles, and introduce a penalty term in the merging process to obtain a merged LoRA weight; the merged expression is as follows:
[0130] W=merge({W_i})+λ*penalty({W_i});
[0131] Where: W is the merged LoRA weight, Wi is the LoRA weight of different target styles, merge() is the merging operation of LoRA weights, penalty() is the penalty term, and λ is the balance factor.
[0132] Furthermore, in step S43, the step of merging the LoRA weights of all styles includes:
[0133] S431, design a weight adjustment matrix, and uniformly initialize the weights of each LoRA module in the weight adjustment matrix; the dimension of the weight adjustment matrix is (N, M), where N is the number of LoRA modules, and M is the number of parameters of each LoRA module;
[0134] S432, using the elements of the weight adjustment matrix as learnable parameters, automatically updating the optimized loss function through gradient descent, and obtaining an optimized weight adjustment matrix;
[0135] S433, based on the optimized weight adjustment matrix, perform LoRA weight merging; the expression of the merging is as follows:
[0136] W'=W+sum(A[i,:]*Li), i=1 to N;
[0137] Where: W′ is the merged LoRA weight adjustment matrix, W is the original weight adjustment matrix, Li is the weight matrix of the i-th LoRA module, and A[i,:] is the i-th row of the weight adjustment matrix A;
[0138] S434. Define a penalty item; the penalty item is as follows:
[0139] P = λ*||W′-W||_F^2;
[0140] Where: P is the penalty term, λ is the balance factor, ||||_F is the Frobenius norm of the weight adjustment matrix;
[0141] S435, adding the penalty term to the loss function, and minimizing the loss function; the loss function is as follows:
[0142] L = L_recon + P;
[0143] Where: L is the loss function, L_recon is the reconstruction loss of image generation, and P is the penalty term.
[0144] Furthermore, the image generator optimization module 4 optimizes the network structure of the image generator in the following manner:
[0145] An attention module is added after each upsampling layer of the decoder part of the image generator, and a discriminator is introduced to judge the authenticity of the output of the image generator. The image generator is then trained and optimized. During the training process, the discriminator and the image generator are optimized alternately. Finally, at the end of each training cycle, the quality of the generated personalized target image is evaluated, and the learning rates of the discriminator and the image generator are adjusted as needed.
[0146] The image generation module 5 is used to generate a personalized target image based on the multi-style image generator of the improved LoRA, taking the conditional vector as input.
[0147] Further, S51, based on the reference image, identifying the style category to which the reference image belongs, and selecting a corresponding LoRA sub-weight from the merged LoRA weight;
[0148] S52, based on the base model and the LoRA sub-weight, with the conditional vector as input, generate a personalized target image; the generated expression is as follows:
[0149] O = G(Z; W_k);
[0150] Where: O is the generated personalized target image, G is the base model, Z is the conditional vector, and W_k is the LoRA sub-weight.
[0151] Embodiment 3:
[0152] See also Figure 4 , a diversified personalized image generation device, the device comprising a processor 6 and a memory 7;
[0153] The memory 7 is used to store computer program code 71 and transmit the computer program code 71 to the processor 6;
[0154] The processor 6 is configured to execute the diversified personalized image generation method described in Embodiment 1 according to the instructions in the computer program code 71 .
[0155] This embodiment also includes a computer-readable storage medium, in which computer-executable instructions are stored. When the computer-executable instructions are executed on a computer, the diversified personalized image generation method described in Example 1 is implemented.
[0156] Generally speaking, the computer instructions for implementing the method of the present invention may be carried in any combination of one or more computer-readable storage media. Non-transitory computer-readable storage media may include any computer-readable media, except for the signal itself that is temporarily propagating.
[0157] The computer-readable storage medium may be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device or device, or any combination thereof. More specific examples of computer-readable storage media (a non-exhaustive list) include: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EKROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination thereof. In the present invention, a computer-readable storage medium may be any tangible medium containing or storing a program that may be used by or in conjunction with an instruction execution system, device, or device.
[0158] Computer program code for performing the operation of the present invention can be written in one or more programming languages or a combination thereof, including object-oriented programming languages such as Java, SMalltalk, C++, and conventional procedural programming languages such as "C" or similar programming languages, in particular, Python suitable for neural network computing and platform frameworks based on TensorFlow, PyTorch, etc. can be used. The program code can be executed entirely on the user's computer, partially on the user's computer, as an independent software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In the case of a remote computer, the remote computer can be connected to the user's computer or to an external computer (for example, using an Internet service provider to connect via the Internet) through any type of network, including a local area network (LAN) or a wide area network (WAN).
[0159] The above-mentioned device and non-temporary computer-readable storage medium can be found in the detailed description of a diversified personalized image generation method and its beneficial effects, which will not be repeated here.
[0160] Although the embodiments of the present invention have been shown and described above, it should be understood that the above embodiments are exemplary and should not be construed as limitations on the present invention. A person skilled in the art may change, modify, replace and vary the above embodiments within the scope of the present invention.
Claims
1. A diversified personalized image generation method, characterized in that: include: S1. Input text description and reference image; the text description is the content of the desired generated image, and the reference image is the style reference of the desired generated image; S2, encoding the text description based on the text encoder to obtain a content representation vector, and encoding the reference image based on the image encoder to obtain a style representation vector; S3, concatenating the content representation vector and the style representation vector to obtain a conditional vector; S4. By introducing the penalty term and adaptively merging multiple LoRA weights, and optimizing the network structure of the image generator, the image generator is improved to obtain a multi-style image generator based on improved LoRA; S5. A multi-style image generator based on the improved LoRA takes the conditional vector as input to generate personalized target images.
2. The method for generating a diversified personalized image according to claim 1, characterized in that: The step S4 specifically includes: S41, collecting image data to form a large-scale image dataset, and then pre-training a base model of an image generator on the large-scale image dataset, so that the image generator learns a general image generation capability; S42. For different target styles, collect image datasets of corresponding styles, and use LoRA technology to fine-tune the image datasets based on the base model to obtain several LoRA weights suitable for different target styles; S43, merge the LoRA weights of all styles, and introduce a penalty term in the merging process to obtain a merged LoRA weight; the merged expression is as follows: W=merge({W_i})+enter*penalty({W_i}); Where: W is the merged LoRA weight, Wi is the LoRA weight of different target styles, merge() is the merging operation of LoRA weights, penalty() is the penalty term, and λ is the balance factor.
3. The method for generating diversified personalized images according to claim 2, characterized in that: In step S43, the step of merging the LoRA weights of all styles includes: S431, design a weight adjustment matrix, and uniformly initialize the weights of each LoRA module in the weight adjustment matrix; the dimension of the weight adjustment matrix is (N, M), where N is the number of LoRA modules, and M is the number of parameters of each LoRA module; S432, using the elements of the weight adjustment matrix as learnable parameters, automatically updating the optimized loss function through gradient descent, and obtaining an optimized weight adjustment matrix; S433, based on the optimized weight adjustment matrix, perform LoRA weight merging; the expression of the merging is as follows: W'=W+sum(A[i,:]*Li),i=1to N; Where: W′ is the merged LoRA weight adjustment matrix, W is the original weight adjustment matrix, Li is the weight matrix of the i-th LoRA module, and A[i,:] is the i-th row of the weight adjustment matrix A; S434. Define a penalty item; the penalty item is as follows: P = λ*||W'-W||_F^2; Where: P is the penalty term, λ is the balance factor, ||||_F is the Frobenius norm of the weight adjustment matrix; S435, adding the penalty term to the loss function, and minimizing the loss function; the loss function is as follows: L = L_recon + P; Where: L is the loss function, L_recon is the reconstruction loss of image generation, and P is the penalty term.
4. The method for generating a diversified personalized image according to claim 1, characterized in that: In step S4, optimizing the network structure of the image generator means: adding an attention module after each upsampling layer of the decoder part of the image generator, introducing a discriminator to judge the authenticity of the output of the image generator, and then training and optimizing the image generator. During the training process, the discriminator and the image generator are optimized alternately. Finally, at the end of each training cycle, the quality of the generated personalized target image is evaluated, and the learning rates of the discriminator and the image generator are adjusted as needed.
5. The method for generating diversified personalized images according to claim 2, characterized in that: The step S5 specifically includes: S51, based on the reference image, identifying the style category to which the reference image belongs, and selecting a corresponding LoRA sub-weight from the merged LoRA weight; S52, based on the base model and the LoRA sub-weight, with the conditional vector as input, generate a personalized target image; the generated expression is as follows: O = G(Z; W_k); Where: O is the generated personalized target image, G is the base model, Z is the conditional vector, and W_k is the LoRA sub-weight.
6. A diversified personalized image generation system, characterized in that: The system comprises: A text and image input module (1) is used to input a text description and a reference image; the text description is the content of the image to be generated, and the reference image is the style reference of the image to be generated; A style representation module (2), used for encoding the text description based on a text encoder to obtain a content representation vector, and encoding the reference image based on an image encoder to obtain a style representation vector; A conditional vector module (3), used for concatenating the content representation vector and the style representation vector to obtain a conditional vector; An image generator optimization module (4) is used to improve the image generator by introducing a penalty term and adaptively combining multiple LoRA weights, while optimizing the network structure of the image generator, thereby obtaining a multi-style image generator based on improved LoRA; The image generation module (5) is used to generate a personalized target image based on the multi-style image generator of the improved LoRA, taking the conditional vector as input.
7. A diversified personalized image generation system according to claim 6, characterized in that: The image generator optimization module (4) optimizes the image generator according to the following steps: S41, collecting image data to form a large-scale image dataset, and then pre-training a base model of an image generator on the large-scale image dataset, so that the image generator learns a general image generation capability; S42. For different target styles, collect image datasets of corresponding styles, and use LoRA technology to fine-tune the image datasets based on the base model to obtain several LoRA weights suitable for different target styles; S43, merge the LoRA weights of all styles, and introduce a penalty term in the merging process to obtain a merged LoRA weight; the merged expression is as follows: W=merge({W_i})+λ*penalty({W_i}); Where: W is the merged LoRA weight, Wi is the LoRA weight of different target styles, merge() is the merging operation of LoRA weights, penalty() is the penalty term, and λ is the balance factor.
8. The diversified personalized image generation system according to claim 7, characterized in that: In step S43, the step of merging the LoRA weights of all styles includes: S431, design a weight adjustment matrix, and uniformly initialize the weights of each LoRA module in the weight adjustment matrix; the dimension of the weight adjustment matrix is (N, M), where N is the number of LoRA modules, and M is the number of parameters of each LoRA module; S432, using the elements of the weight adjustment matrix as learnable parameters, automatically updating the optimized loss function through gradient descent, and obtaining an optimized weight adjustment matrix; S433, based on the optimized weight adjustment matrix, perform LoRA weight merging; the expression of the merging is as follows: W'=W+sum(A[i,:]*Li),i=1to N; Where: W′ is the merged LoRA weight adjustment matrix, W is the original weight adjustment matrix, Li is the weight matrix of the i-th LoRA module, and A[i,:] is the i-th row of the weight adjustment matrix A; S434. Define a penalty item; the penalty item is as follows: P = λ*||W'-W||_F^2; Where: P is the penalty term, λ is the balance factor, ||||_F is the Frobenius norm of the weight adjustment matrix; S435, adding the penalty term to the loss function, and minimizing the loss function; the loss function is as follows: L = L_recon + P; Where: L is the loss function, L_recon is the reconstruction loss of image generation, and P is the penalty term.
9. The diversified personalized image generation system according to claim 6, characterized in that: The image generator optimization module (4) optimizes the network structure of the image generator in the following manner: An attention module is added after each upsampling layer of the decoder part of the image generator, and a discriminator is introduced to judge the authenticity of the output of the image generator. The image generator is then trained and optimized. During the training process, the discriminator and the image generator are optimized alternately. Finally, at the end of each training cycle, the quality of the generated personalized target image is evaluated, and the learning rates of the discriminator and the image generator are adjusted as needed.
10. The diversified personalized image generation system according to claim 7, characterized in that: The image generation module (5) generates an image according to the following steps: S51, based on the reference image, identifying the style category to which the reference image belongs, and selecting a corresponding LoRA sub-weight from the merged LoRA weight; S52, based on the base model and the LoRA sub-weight, with the conditional vector as input, generate a personalized target image; the generated expression is as follows: O = G(Z; W_k); Where: O is the generated personalized target image, G is the base model, Z is the conditional vector, and W_k is the LoRA sub-weight.
