Single sample font generation method based on conditional diffusion model and decoupling guidance

By using the conditional diffusion model and the decoupled guidance method in single-sample font generation, the style and content features are extracted and decoupled sampling is performed, which solves the problems of font image generation quality and stability in the existing technology, and achieves high quality and Relevant font image generation.

CN118537437APending Publication Date: 2024-08-23NANJING UNIV OF AERONAUTICS & ASTRONAUTICS +1
View PDF 0 Cites 3 Cited by

Patent Information

Application Number
CN202410490064.8
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-04-23
Publication Date
2024-08-23

AI Technical Summary

Technical Problem

Existing single-sample font generation methods have problems such as missing strokes and difficulty in retaining style details when generating font images with various combinations of styles and content. Moreover, the training instability of the GAN architecture and the inability to generate font images with unseen content have limitations. Build quality.

Method used

Using a method based on conditional diffusion model and decoupling guidance, the style and content features are extracted by freezing the pre-trained encoder, and the style-content decoupling guidance sampling strategy is used to generate font images to ensure that the generated results are consistent with the reference image and target characters. Strong correlation.

Benefits of technology

It achieves a more stable training process and higher-quality font image generation, can generate font images with any combination of styles and content, and ensures a strong correlation between input conditions and output font images, with good versatility and scalability. .

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118537437A
    Figure CN118537437A
Patent Text Reader

Abstract

The invention discloses a single sample font generation method based on a conditional diffusion model and decoupling guidance. The method comprises the following steps: 1, constructing a font generation framework, collecting fonts, and making a data set as a style image and a content image; 2, pre-training the content encoder on the data set; 3, a pre-trained content encoder extracts content features of the content image, and a style encoder extracts style features of the style image; 4, the content features and the style features are combined and then input into a conditional diffusion model; 5, freezing parameters of the trained content encoder and style encoder, and training a condition diffusion model; 6, judging whether the model completes training of all font images or not and whether the number of iterations is completed or not; and 7, sampling the trained model, and generating an image with a specified style and specified content. According to the method, the conditional diffusion model is applied to a single sample font generation task, a style and content decoupling normal form is followed, and a font image with any style and content combination can be generated.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The invention relates to the field of image generation, and mainly to a single sample font generation method based on a conditional diffusion model and decoupling guidance. Background Art

[0002] Font generation is an image generation task that aims to generate a completely new font library using a limited number of reference images. In traditional font design, it takes tedious work by professional designers to create new font styles. However, the emergence of few-sample font generation technology enables us to generate diverse font images in a more efficient way. Font generation technology has broad application prospects in the fields of font design, advertising design, brand identity, etc. It can help designers quickly generate a variety of unique font styles, saving time and labor costs. In addition, font generation technology can also promote the innovation and diversity of font design, providing font designers with more creative possibilities.

[0003] In order to generate font images of all styles and content combinations, most few-shot font generation methods are based on the paradigm of style-content decoupling. According to the representation method of style features, existing methods can be roughly divided into two categories: global style feature representation based and component / local feature representation based. Methods using global feature representation usually model the font style as global statistical features from the reference image. In order to utilize character-specific prior knowledge, component / local feature-based font generation methods usually decompose the entire image into multiple parts or components and extract style information from local regions. These methods achieve control over the font generation process by learning the relationship between the style and content of the font.

[0004] In order to reduce the dependence on components, MX-Font (Park, S., Chun, S., Cha, J., Lee, B., Shim, H.: Multiple heads are better than one: Few-shot font generation with multiple localized experts. In: ICCV, 2021) uses a multi-head encoder to implicitly extract different local concepts in a weakly supervised manner. XMP-Font (Liu, W., Liu, F., Ding, F., He, Q., Yi, Z.: Xmp-font: self-supervised cross-modality pre-training for few-shot font generation. In: CVPR, 2022) introduces a Transformer-based cross-modality encoder to capture local and global style features. CG-GAN (Kong, Y., Luo, C., Ma, W., Zhu, Q., Zhu, S., Yuan, N., Jin, L.: Look closer to supervise better: one-shot font generation via component-based discriminator. In: CVPR, 2022) uses component-level discriminators to supervise the generator at a finer level. However, these methods still require component-level labels. FS-Font (Tang, L., Cai, Y., Liu, J., Hong, Z., Gong, M., Fan, M., Han, J., Liu, J., Ding, E., Wang, J.: Few-shot font generation by learning fine-grained local styles. In: CVPR, 2022) learns the spatial correspondence between content and reference glyphs and extracts fine-grained local styles from the reference. However, this method requires the reference set to be carefully selected to cover as many specific components as possible. In addition, DG-Font (Xie, Y., Chen, X., Sun, L., Lu, Y.: Dg-font: Deformable generative networks for unsupervised font generation. In: CVPR, 2021) uses deformable convolutional networks instead of traditional convolutional networks to learn the spatial transformation from source fonts to target fonts to achieve unsupervised learning.CF-Font (Wang, C., Zhou, M., Ge, T., Jiang, Y., Bao, H., Xu, W.: Cf-font: Content fusion for few-shot font generation. In: CVPR, 2023) is an extension of DG-Font. It designs a content fusion module that uses fused content features to reduce the gap between the source font and the target font. However, these methods still have problems such as missing strokes and difficulty in preserving style details.

[0005] Almost all the methods mentioned above are based on the GAN architecture, and GAN may face the problem of unstable training due to its adversarial nature. In order to further improve the quality of image generation, Diff-Font (He, H., Chen, X., Wang, C., Liu, J., Du, B., Tao, D., Qiao, Y.: Diff-font: Diffusion model for robust one-shot font generation. 2022) introduced the diffusion model into single-shot font generation. However, this method represents the character content through predefined tokens, which makes it impossible to generate font images with unseen content, which is a big limitation in the font generation task. Summary of the invention

[0006] Purpose of the invention: In view of the problems existing in the above-mentioned background technology, the present invention provides a single-sample font generation method based on a conditional diffusion model and decoupling guidance. In order to generate font images of various styles and content combinations, the style features of the style image and the content features of the content image are respectively extracted as the guiding conditions of the diffusion model. During training, the pre-trained encoder is frozen to reduce the number of parameters of the model and speed up the convergence of the model. During inference, a sampling strategy based on style-content decoupling guidance is used to allow the generated font image to show a strong correlation with the reference image and the target character.

[0007] Technical solution: To achieve the above purpose, the technical solution adopted by the present invention is:

[0008] A single-sample font generation method based on a conditional diffusion model and decoupling guidance comprises the following steps:

[0009] Step S1, constructing a font generation framework, collecting fonts and making a data set, and dividing the data set into a training set and a test set; the font images in the data set with the Song style are used as content images, and the remaining font images in the data set are used as style images;

[0010] The font generation framework includes a conditional encoder module and a conditional diffusion model module, wherein the conditional encoder module includes a pre-trained style encoder E s and initialize the content encoder E' c , the conditional diffusion model module includes a denoising network

[0011] Step S2: Use the initialized content encoder E' c Train on the training set to obtain the pre-trained content encoder E c ;

[0012] Step S3: Use the pre-trained content encoder E c Extract content features of content images c , using the pre-trained style encoder E s Extract style features s ;

[0013] Step S4: extract the content features e c and style features s Connecting them on the channel, and then inputting the conditional diffusion model to generate the conditional guided diffusion model;

[0014] Step S5: Use the pre-trained content encoder E c and the pre-trained style encoder E s The parameters of are frozen, and the conditional diffusion model is used for training on the training set;

[0015] Step S6, determining whether the conditional diffusion model has completed the training of all font images in the training set and whether all iterations have been completed;

[0016] Step S7: Sampling the trained conditional diffusion model, and using the style-content decoupling guided sampling strategy according to the input style image and content image to generate a font image of the specified style and content.

[0017] Preferably, in step S1, the three fully connected layers of the VGG11 network structure are replaced with one linear layer, and then the replaced VGG11 network structure is used as the pre-trained style encoder E s The backbone network of the ResNet18 network structure is replaced by a linear layer, and the replaced ResNet18 network structure is used as the initial content encoder E' c The backbone network of the two backbone networks is initialized using Kaiming initialization; the denoising network in the conditional diffusion model is The UNet network structure is used. The UNet network structure includes an encoding layer network and a decoding layer network. Both the encoding layer network and the decoding layer network contain four residual blocks.

[0018] Preferably, the implementation process of step S2 is:

[0019] Step S2.1, randomly input a font image in the training set as an anchor image, select a font image with the same content but different style as the font image as a positive sample image, and select a font image with the same style but different content as the font image as a negative sample image;

[0020] Step S2.2: Input the selected anchor image, positive sample image and negative sample image into the initialized content encoder E' c Perform feature extraction, and then calculate the distance from the anchor point to the positive sample and the anchor point to the negative sample respectively:

[0021]

[0022]

[0023] Where a, p and n represent the anchor image, positive sample image and negative sample image respectively, d(a,p) represents the distance from the anchor point to the positive sample, and d(a,n) represents the distance from the anchor point to the negative sample. represents the l2 distance;

[0024] Step S2.3: Calculate the triplet loss function to update the initialized content encoder E' c , so that the distance from the anchor point to the positive sample decreases, and the distance from the anchor point to the negative sample increases;

[0025] L triplet =max(d(a,p)-d(a,n)+margin,0)

[0026] Among them, L triplet Represents the triplet loss function, margin represents the interval distance, which is a constant greater than 0.

[0027] Preferably, the implementation process of extracting content features and style features in step S3 is:

[0028] Step S3.1: Use the pre-trained content encoder E c For the input content image I c Extract content features:

[0029] e c =Proj(flatten(E c (I c )))

[0030] Where flatten represents the flattening operation, Proj represents the projection operation, and e c Represents the extracted content features;

[0031] Step S3.2: Use the pre-trained style encoder E s For the input style image I s Extract style features:

[0032] e s =Proj(flatten(E s (I s )))

[0033] where e s Represents the extracted style features.

[0034] Preferably, the mean square error loss function L used to train the conditional diffusion model in step S5 is mse for:

[0035]

[0036] Where E represents the expectation of all values ​​of l2, ∈ represents random noise that follows a standard normal distribution, t represents the time step, and x t represents a noisy image, x' t Indicates that x t and content image I c The result after connecting on the channel;

[0037] ∈ θ (x t ,t,e s ,e c ,I c ) represents the denoising network in the conditional diffusion model According to the input style features e s , content features c and content image I c Predicted noise;

[0038] ∈ θ (x' t ,t,e s ,e c ) means to convert x t and content image I c After concatenation, the denoising network in the conditional diffusion model According to the input style features e s , content features c Predicted noise;

[0039] Preferably, in step S7, the implementation process of using the style-content decoupling to guide the sampling strategy according to the input style image and content image is as follows:

[0040] ∈ dis =∈ uncond +w s ∈ style +w c ∈ content

[0041]

[0042]

[0043]

[0044] where w s represents the style guidance coefficient, w c represents the content guidance coefficient, represents an all-zero matrix, ∈ uncond It is a denoising network The predicted unconditional noise, ∈ style is the prediction noise guided by style features, ∈ content is the prediction noise guided by content features, ∈ dis represents the decoupled guided prediction noise used for the final sampling, Indicates that x t and content image I c After connection, the denoising network According to the input style features e s The predicted noise, Indicates that x t and content image I c After connection, the denoising network According to the input content features c Predicted noise.

[0045] Beneficial effects:

[0046] (1) The present invention uses the conditional diffusion model for the single-sample font generation task, which has a more stable training process and higher quality generated images compared to the GAN-based font generation method. The present invention uses two different encoders to extract style features and content features respectively, and realizes the generation of font images with any combination of style and content.

[0047] (2) During the sampling process, the present invention proposes a sampling method based on style-content decoupling guidance, which effectively aligns the style and characters of the generated image with the reference image and the content image, and also ensures a strong correlation between the input conditions and the output font image.

[0048] (3) The present invention effectively decouples style and content, and can be further applied to cross-language font generation tasks, such as generating Korean or Japanese character images with the font style based on an input Chinese font image. Therefore, the present invention has good versatility and extensibility. BRIEF DESCRIPTION OF THE DRAWINGS

[0049] Figure 1 It is a flow chart of a single sample font generation method based on a conditional diffusion model and decoupling guidance provided by the present invention;

[0050] Figure 2 It is an algorithm framework diagram of a single sample font generation method based on a conditional diffusion model and decoupling guidance provided by the present invention. DETAILED DESCRIPTION

[0051] The present invention is further described below in conjunction with the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, rather than all 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.

[0052] The present invention provides a single sample font generation method based on conditional diffusion model and decoupling guidance. The specific principle is as follows: Figure 1 As shown, the following steps are included:

[0053] Step S1, construct an initial font generation framework, collect fonts and create a data set, and divide the data set into a training set and a test set; the font image with Song style in the data set is used as the content image, and the remaining fonts in the data set are used as the style image; the font generation framework includes two modules, a conditional encoder module and a conditional diffusion model module, and the conditional encoder module includes a pre-trained style encoder E s and initialize the content encoder E' c , the conditional diffusion model module includes a denoising network

[0054] Specifically, the pre-trained encoder E s The backbone network is taken from the classic VGG network model; the initial content encoder E' c The backbone network is taken from the ResNet network structure, and the network weights are initialized using Kaiming initialization; the denoising network in the conditional diffusion model The UNet network structure is composed of an encoding layer network and a decoding layer network, where the encoding layer and the decoding layer each contain four residual blocks. Specifically, refer to Figure 2 .

[0055] Step S2: Use the initialized content encoder E' c Train on the training set to obtain the pre-trained content encoder E c , the trained content encoder E c Ability to ignore the differences in the styles of input images and focus more on their content.

[0056] Step S2.1, randomly input a font image in the training set as an anchor, select a font image with the same content but different style as the image as its positive sample, and select a font image with the same style but different content as the image as its negative sample;

[0057] Step S2.2: Input the selected anchor image, positive sample image and negative sample image into the content encoder for feature extraction, and then calculate the distance from the anchor point to the positive sample and the distance from the anchor point to the negative sample respectively:

[0058]

[0059]

[0060] Where a, p and n represent the anchor image, positive sample image and negative sample image respectively, d(a,p) represents the distance from the anchor point to the positive sample, and d(a,n) represents the distance from the anchor point to the negative sample. represents the l2 distance;

[0061] Step S2.3: Use the distance calculation triplet loss function obtained above to update the content encoder E c , so that the distance from the anchor point to the positive sample decreases and the distance from the anchor point to the negative sample increases.

[0062] L triplet =max(d(a,p)-d(a,n)+margin,0)

[0063] Among them, L triplet Represents the triplet loss function, margin represents the interval distance, which is a constant greater than 0.

[0064] Step S3: Use the pre-trained content encoder E c Extract content features of content images c , using the pre-trained style encoder E s Extract style features s .

[0065] Step S3.1: Use the pre-trained content encoder E c For the input content image I c Extract content features:

[0066] e c =Proj(flatten(E c (I c )))

[0067] Where flatten represents the flattening operation, which converts the input multi-dimensional tensor into a one-dimensional vector. Proj represents the projection operation, which maps the input data to a low-dimensional space. c Represents the extracted content features;

[0068] Step S3.2: Use the pre-trained style encoder E s For the input style image I s Extract style features:

[0069] e s =Proj(flatten(E s (I s )))

[0070] Where flatten represents the flattening operation, Proj represents the projection operation, and e s Represents the extracted style features.

[0071] Step S4: extract the content features e c and style features s They are connected on the channel and then input into the conditional diffusion model to generate the conditional guided diffusion model.

[0072] Step S5: Use the pre-trained content encoder E c and the pre-trained style encoder E s The parameters of are frozen and the conditional diffusion model is used for training on the training set.

[0073] Specifically, the mean square error loss function L used to train the conditional diffusion model is mse for:

[0074]

[0075] Where ∈ represents random noise that follows a standard normal distribution, ∈ θ Represents the denoising network in the conditional diffusion model The noise predicted based on the input conditions, t represents the time step, x t represents a noisy image, x' t Indicates that x t and content image I c The result after connecting on the channel.

[0076] Step S6: Determine whether the conditional diffusion model has completed the training of all font images in the training set and whether all iterations have been completed.

[0077] Step S7: Sampling the trained conditional diffusion model, and using the style-content decoupling guided sampling strategy according to the input style image and content image to generate a font image of the specified style and content.

[0078] Specifically, the implementation process of sampling using the style-content decoupling guided sampling strategy is as follows:

[0079] ∈ dis =∈ uncond +w s ∈ style +w c ∈ content

[0080]

[0081]

[0082]

[0083] where w s represents the style guidance coefficient, w c represents the content guidance coefficient, represents an all-zero matrix, ∈ uncond It is a denoising network The predicted unconditional noise, ∈ style is the prediction noise guided by style features, ∈ content is the prediction noise guided by content features, ∈ dis represents the decoupled guided prediction noise used for the final sampling.

[0084] The above is only a preferred embodiment of the present invention. It should be pointed out that for ordinary technicians in this technical field, several improvements and modifications can be made without departing from the principle of the present invention. These improvements and modifications should also be regarded as the scope of protection of the present invention.

Claims

1. A single-sample font generation method based on conditional diffusion model and decoupling guidance, characterized in that: The following steps are involved: Step S1, constructing a font generation framework, collecting fonts and making a data set, and dividing the data set into a training set and a test set; the font images in the data set with the Song style are used as content images, and the remaining font images in the data set are used as style images; The font generation framework includes a conditional encoder module and a conditional diffusion model module, wherein the conditional encoder module includes a pre-trained style encoder E s and initialize the content encoder E' c , the conditional diffusion model module includes a denoising network Step S2: Use the initialized content encoder e' c Train on the training set to obtain the pre-trained content encoder E c ; Step S3: Use the pre-trained content encoder E c Extract content features of content images c , using the pre-trained style encoder E s Extract style features s ; Step S4: extract the content features e c and style features s Connecting them on the channel, and then inputting the conditional diffusion model to generate the conditional guided diffusion model; Step S5: Use the pre-trained content encoder E c and the pre-trained style encoder E s The parameters of are frozen, and the conditional diffusion model is used for training on the training set; Step S6, determining whether the conditional diffusion model has completed the training of all font images in the training set and whether all iterations have been completed; Step S7: Sampling the trained conditional diffusion model, and using the style-content decoupling guided sampling strategy according to the input style image and content image to generate a font image of the specified style and content.

2. The single-sample font generation method based on conditional diffusion model and decoupling guidance according to claim 1, characterized in that: In step S1, the three fully connected layers of the VGG11 network structure are replaced with one linear layer, and the replaced VGG11 network structure is used as the pre-trained style encoder E s backbone network; The fully connected layer of the ResNet18 network structure is replaced with a linear layer, and then the replaced ResNet18 network is used as the initial content encoder E' c The backbone network of the two backbone networks is initialized using Kaiming initialization; the denoising network in the conditional diffusion model is The UNet network structure is used. The UNet network structure includes an encoding layer network and a decoding layer network. Both the encoding layer network and the decoding layer network contain four residual blocks.

3. The single-sample font generation method based on conditional diffusion model and decoupling guidance according to claim 1, characterized in that: The implementation process of step S2 is: Step S2.1, randomly input a font image in the training set as an anchor image, select a font image with the same content but different style as the font image as a positive sample image, and select a font image with the same style but different content as the font image as a negative sample image; Step S2.2: Input the selected anchor image, positive sample image and negative sample image into the initialized content encoder E' c Perform feature extraction, and then calculate the distance from the anchor point to the positive sample and the distance from the anchor point to the negative sample respectively: Where a, p and n represent the anchor image, positive sample image and negative sample image respectively, d(a,p) represents the distance from the anchor point to the positive sample, and d(a,n) represents the distance from the anchor point to the negative sample. represents the l2 distance; Step S2.3: Calculate the triplet loss function to update the initialized content encoder E' c , so that the distance from the anchor point to the positive sample decreases, and the distance from the anchor point to the negative sample increases; L triplet =max(d(a,p)-d(a,n)+margin,0) Among them, L triplet Represents the triplet loss function, margin represents the interval distance, which is a constant greater than 0.

4. The single-sample font generation method based on conditional diffusion model and decoupling guidance according to claim 1, characterized in that: The implementation process of extracting content features and style features in step S3 is as follows: Step S3.1: Use the pre-trained content encoder E c For the input content image I c Extract content features: e c =Proj(flat(E c (IN c ))) Among them, e c Represents the extracted content features, flatten represents the flattening operation, and Proj represents the projection operation; Step S3.2: Use the pre-trained style encoder E s For the input style image I s Extract style features: e s =Proj(flat(E s (IN s ))) where e s Represents the extracted style features.

5. The single-sample font generation method based on conditional diffusion model and decoupling guidance according to claim 1, characterized in that: The mean square error loss function L used to train the conditional diffusion model in step S5 is mse for: Where E represents the expectation of all values ​​of l2, ∈ represents random noise that follows a standard normal distribution, t represents the time step, and x t represents a noisy image, x' t Indicates that x t and content image I c The result after connecting on the channel; ∈ θ (x t ,t,e s ,e c ,I c ) represents the denoising network in the conditional diffusion model According to the input style features e s , content features c and content image I c Predicted noise; ∈ θ (x' t ,t,e s ,e c ) means to convert x t and content image I c After concatenation, the denoising network in the conditional diffusion model According to the input style features e s , content features c Predicted noise.

6. The single-sample font generation method based on conditional diffusion model and decoupling guidance according to claim 5, characterized in that: In step S7, the implementation process of using the style-content decoupling to guide the sampling strategy according to the input style image and content image is as follows: ∈ dis =∈ uncond +in s ∈ style +in c ∈ content where w s represents the style guidance coefficient, w c represents the content guidance coefficient, represents an all-zero matrix, ∈ uncond It is a denoising network The predicted unconditional noise, ∈ style is the prediction noise guided by style features, ∈ content is the prediction noise guided by content features, ∈ dis represents the decoupled guided prediction noise used for the final sampling; Indicates that x t and content image I c After connection, the denoising network According to the input style features e s The predicted noise, Indicates that x t and content image I c After connection, the denoising network According to the input content features c Predicted noise.

Citation Information

Cited By

  • Single-sample handwritten character copying method based on diffusion model

    CN118762103A

  • Method and system for quickly generating few-sample Chinese fonts based on diffusion model

    CN119692304A

  • Multi-category single-sample image generation method and system

    CN120563319A