Small sample Chinese font generation method
By building a small sample Chinese font generation network, combining the generation network and the discriminant network, the problems of incomplete content and poor style consistency in the generation of Chinese fonts in the existing technology are solved, and Chinese fonts with consistent styles are generated in the small sample environment.
Patent Information
- Application Number
- CN202411958500.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-30
- Publication Date
- 2025-04-29
AI Technical Summary
The existing deep learning methods have problems such as incomplete content, poor style consistency and difficulty in extracting features from small samples in Chinese font generation, especially in the fields of digital restoration of ancient books.
A small sample Chinese font generation network is constructed, and a structure that connects the generation network and the discriminating network is adopted. The content characteristics of the source font and the style characteristics of the reference sample are extracted through the encoder, and a new font style is generated by combining the decoder. The content and style of the generated font is judged through the discriminating network to ensure the content integrity and style consistency of the generated font.
It effectively solves the problems of missing and adhesion of generated font strokes, and can generate Chinese fonts with similar styles to reference samples in a small sample learning environment, improving the generation effect of font details.
Smart Images

Figure CN119903813A_ABST
Abstract
Description
Technical Field
[0001] The invention belongs to the technical field of computer vision, and in particular relates to Chinese font generation. Background Art
[0002] Chinese characters carry the long history of the Chinese nation and record thousands of years of thought, art and culture. As an important form of visual expression of Chinese characters, Chinese fonts reflect the richness and variability of Chinese character forms. From neat and orderly official script and regular script, to elegant and elegant running script and cursive script, to printing fonts such as Fangsong and bold, each Chinese font contains unique aesthetic characteristics. With the development of the times, Chinese fonts are widely used in book publishing and advertising, artistic creation and personalized design, digital storage and restoration of ancient books and other fields.
[0003] In the early days, Chinese font design was completely dependent on the manual drawing of designers. The design process was time-consuming and cumbersome, and it was difficult to maintain a consistent style. With the development of computer technology, automated generation methods have emerged. Traditional Chinese font generation mostly uses the method of component splicing and reuse, breaking down Chinese characters into components, first building a component library, and then using the component library to splice new fonts. This method limits the diversity of fonts and is difficult to handle complex glyphs. In recent years, deep learning technology has been applied to Chinese font generation. This technology trains deep neural networks to allow computers to learn Chinese font samples and generate fonts with specific styles and structures. It can not only utilize existing sample resources, but also greatly improve generation efficiency.
[0004] The current mainstream deep learning method is based on image translation. It takes the source font and reference samples as input, learns content features and style features respectively, and then combines and decodes the two features to generate the target font. This method still has some shortcomings when generating fonts: (1) The content is not complete. The model needs to avoid problems such as missing strokes and adhesion to generate accurate and readable character content. (2) The style consistency is poor. In addition to the overall style harmony, the local style should also be consistent. The model should not rely on specific samples in the training data and should demonstrate generalization capabilities in unseen styles. (3) It is difficult to learn features from limited reference samples. In technical fields such as digital restoration of ancient books, samples are scarce due to damage, loss, etc. The model needs to enhance its learning ability to effectively extract features from a small number of reference samples. Summary of the invention
[0005] The technical problem to be solved by the present invention is to overcome the shortcomings of the above-mentioned prior art and provide a method for generating a small sample Chinese font with complete content and consistent style.
[0006] The technical solution adopted to solve the above technical problems consists of the following steps:
[0007] (1) Establishing a Chinese font dataset
[0008] 1) Collect Chinese font files and build character sets
[0009] 100 TrueType Chinese fonts that conform to the GB2312 standard were collected. The 6763 characters included in the standard constituted a complete character set, and 50 characters were randomly selected from the complete character set as a small sample character set.
[0010] 2) Divide the training set and test set
[0011] 94 Chinese fonts are used as training sets, and glyph images in the complete character set are extracted as source fonts and reference samples.
[0012] The remaining 6 Chinese fonts are used as test sets. The glyph images of the complete character set of one of the Chinese fonts are extracted as the source font, and the glyph images of small sample character sets of the other five Chinese fonts, namely, running script, regular script, running regular script, official script, and handwriting, are extracted as reference samples.
[0013] (2) Constructing a small sample Chinese font generation network
[0014] The small sample Chinese font generation network is composed of a generation network and a discriminant network in series.
[0015] The generation network is composed of an encoder and a decoder connected in series.
[0016] The encoder is composed of a convolution layer 1 and a downsampling layer 1, a downsampling layer 2, a multi-branch attention module 1, a multi-core void convolution module 1, a multi-branch attention module 2, a multi-core void convolution module 2, a downsampling layer 3, a multi-branch attention module 3, and a multi-core void convolution module 3, which are connected in series in sequence.
[0017] The decoder is composed of a convolutional layer 2 and a residual network layer 1, a residual network layer 2, a residual network layer 3, an efficient upsampling module 1, an efficient upsampling module 2, an efficient upsampling module 3, and a convolutional layer 3 connected in series in sequence.
[0018] The discriminant network is composed of a convolutional layer 4 and a downsampling layer 4, a downsampling layer 5, a downsampling layer 6, a multi-branch attention module 4, a downsampling layer 7, a downsampling layer 8, a multi-branch attention module 5, and an average pooling layer 1, which are connected in series in sequence, and the output end of the average pooling layer 1 is connected to the input end of the Embedding layer 1 and the Embedding layer 2.
[0019] (3) Training a small sample Chinese font generation network
[0020] 1) Construct loss function
[0021] The loss function includes the discriminant network loss function LD , generate network loss function L G .
[0022] Generate network loss function L G Including generating network hinge loss function Reconstruction loss function L rec , feature map loss function L fm as follows:
[0023]
[0024] Among them, λ rec represents the weight of the reconstruction loss function, λ rec The value range is (0,0.5), λ fm represents the weight of the feature map loss function, λ fm The value range is (0,1).
[0025] Construct the discriminant network loss function L as follows D :
[0026]
[0027] Among them, trg represents the real sample, gen represents the generated font, and y c Indicates content label, y s Represents the style label, D(trg,y c ) represents the probability of judging that the real sample content label is true, D(trg,y s ) represents the probability of judging the style label of the real sample to be true, D(gen,y c ) represents the probability of judging the generated font content label to be true, D(gen,y s ) represents the probability of judging the generated font style label to be true, and represents the expected value of the latter form;
[0028] The hinge loss function of the generated network is constructed as follows
[0029]
[0030] The reconstruction loss function L is constructed as follows: rec :
[0031]
[0032] Where i represents the pixel number, n pixel Indicates the total number of pixels of the real sample, trg i Represents the value of the i-th pixel of the true sample, gen iIndicates the value of the i-th pixel of the generated font, E (trg,gen) represents the expected value of the latter.
[0033] The feature map loss function L is constructed as follows fm :
[0034]
[0035] Among them, trg_fm represents the feature map of the real sample, gen_fm represents the feature map of the generated font, and n pixel_fm Indicates the total number of pixels of the real sample feature map, trg_fm i Represents the value of the i-th pixel in the real sample feature map, gen_fm i Indicates the value of the i-th pixel in the generated font feature map, E (trg_fm,gen_fm) represents the expected value of the latter.
[0036] 2) Training a small sample Chinese font generation network
[0037] The training set is input into the small sample Chinese font generation network for training. The training parameters are set as follows: batch size is 8, the learning rate of the generation network is 0.0002, the learning rate of the discriminant network is 0.001, and the optimizer is Adam. The training is performed until the loss function converges.
[0038] (4) Testing a small sample Chinese font generation network
[0039] The test set is input into the trained small sample Chinese font generation network, and five generated Chinese fonts, namely running script, regular script, semi-regular script, official script, and handwriting, are output.
[0040] In the step (2) of constructing a small sample Chinese font generation network of the present invention, the multi-branch attention module 1 is composed of a convolution layer 5, an average pooling layer 2, a Softmax activation layer 1, a horizontal pooling layer, a vertical pooling layer, a re-weighted layer 1, an average pooling layer 3, a Softmax activation layer 2, a re-weighted layer 2, a non-local attention module, an average pooling layer 4, and a Softmax activation layer 3; the convolution layer 5 is connected in series with the average pooling layer 2 and the Softmax activation layer 1 in sequence; the horizontal pooling layer is connected in parallel with the vertical pooling layer, and its output end is connected in series with the re-weighted layer 1, the average pooling layer 3, and the Softmax activation layer 2 in sequence; the non-local attention module is connected in series with the average pooling layer 4 and the Softmax activation layer 3 in sequence; the output ends of the Softmax activation layer 1, the Softmax activation layer 2, and the Softmax activation layer 3 are connected in series with the re-weighted layer 2.
[0041] The structure of the multi-branch attention module 2-multi-branch attention module 5 is the same as that of the multi-branch attention module 1.
[0042] The multi-core dilated convolution module 1 of the present invention is composed of a convolution layer 6, a channel attention module, a dilated convolution layer 1, a dilated convolution layer 2, a dilated convolution layer 3, a feature fusion layer, a conditional convolution layer, a self-attention module, and a gating layer; the convolution layer 6 is connected in series with the channel attention module; the dilated convolution layer 1 is connected in parallel with the dilated convolution layer 2 and the dilated convolution layer 3, and its output end is connected in series with the feature fusion layer, the conditional convolution layer, and the self-attention module in sequence; the output ends of the channel attention module and the self-attention module are connected to the gating layer.
[0043] The structures of the multi-core dilated convolution module 2 and the multi-core dilated convolution module 3 are the same as that of the multi-core dilated convolution module 1.
[0044] In step (2) of the present invention, a small sample Chinese font generation network is constructed. The convolution kernel size of the convolution layer 1 and the convolution layer 3 is 3×3, the step size is 1, and the padding is 1. The convolution kernel size of the convolution layer 2 is 1×1, the step size is 1, and the padding is 0. The convolution kernel size of the convolution layer 4 is 3×3, the step size is 2, and the padding is 1.
[0045] In step (2) of the present invention, in constructing a small sample Chinese font generation network, the convolution kernel size of the residual network layer 1 is 3×3, the step size is 1, and the padding is 1; the structures of the residual network layer 2 and the residual network layer 3 are the same as the structure of the residual network layer 1.
[0046] The convolution kernel size of the convolution layer 5 is 3×3, the step size is 1, and the padding is 1.
[0047] The convolution kernel size of the convolution layer 6 is 3×3, the step size is 1, and the padding is 1. The expansion rate of the dilated convolution layer 1 is 1, the convolution kernel size is 3×3, the step size is 1, and the padding is 1; the expansion rate of the dilated convolution layer 2 is 2, the convolution kernel size is 3×3, the step size is 1, and the padding is 2; the expansion rate of the dilated convolution layer 3 is 4, the convolution kernel size is 3×3, the step size is 1, and the padding is 4; the convolution kernel size of the conditional convolution layer is 3×3, the step size is 1, and the padding is 1.
[0048] In the step (3) of training a small sample Chinese font generation network of the present invention, in 1) constructing a loss function, the λ rec represents the weight of the reconstruction loss function, λ fm represents the weight of the feature map loss function, λ rec The best value is 0.25, fm The best value is 0.5.
[0049] The present invention uses an encoder to extract the content features of the source font and the style features of the reference sample, and uses a decoder to combine the content features of the source font with the style features of the reference sample to generate a new font style; the discriminant network simultaneously judges the content and style of the generated font, effectively ensuring the content integrity and style consistency of the generated font; a multi-branch attention module and a multi-core hole convolution module are introduced in the encoder to extract richer local features and semantic information; an efficient upsampling module is introduced in the decoder to significantly improve the generation effect of font details. Compared with the prior art, the present invention effectively solves the technical problems of missing and sticking strokes in the generated font, and can generate Chinese fonts with a style similar to that of the reference sample in a small sample learning environment, and can be used for small sample Chinese font generation. BRIEF DESCRIPTION OF THE DRAWINGS
[0050] Figure 1 It is a flow chart of embodiment 1 of the present invention.
[0051] Figure 2 It is a structural schematic diagram of a small sample Chinese font generation network of the present invention.
[0052] Figure 3 yes Figure 2 Schematic diagram of the encoder structure.
[0053] Figure 4 yes Figure 2 Schematic diagram of the decoder structure.
[0054] Figure 5 yes Figure 2 Schematic diagram of the structure of the discriminant network.
[0055] Figure 6 yes Figure 3 Schematic diagram of the structure of the multi-branch attention module 1.
[0056] Figure 7 yes Figure 3 Schematic diagram of the structure of the multi-core hole convolution module 1.
[0057] Figure 8 It is a visualization schematic diagram of generating 5 different Chinese fonts according to the present invention. DETAILED DESCRIPTION
[0058] The present invention will be further described in detail below in conjunction with the accompanying drawings and examples, but the present invention is not limited to the following embodiments.
[0059] Example 1
[0060] The method for generating a small sample Chinese font in this embodiment comprises the following steps (see Figure 1 ):
[0061] (1) Establishing a Chinese font dataset
[0062] 1) Collect Chinese font files and build character sets
[0063] 100 TrueType Chinese fonts that conform to the GB2312 standard were collected. The 6763 characters included in the standard constituted a complete character set, and 50 characters were randomly selected from the complete character set as a small sample character set.
[0064] 2) Divide the training set and test set
[0065] 94 Chinese fonts are used as training sets, and glyph images in the complete character set are extracted as source fonts and reference samples.
[0066] The remaining 6 Chinese fonts are used as test sets. The glyph images of the complete character set of one of the Chinese fonts are extracted as the source font, and the glyph images of small sample character sets of the other five Chinese fonts, namely, running script, regular script, running regular script, official script, and handwriting, are extracted as reference samples.
[0067] (2) Constructing a small sample Chinese font generation network
[0068] Figure 2 A schematic diagram of the structure of the small sample Chinese font generation network of this embodiment is given. Figure 2 In the embodiment, the small sample Chinese font generation network is composed of a generation network and a discrimination network connected in series.
[0069] The generation network of this embodiment is composed of an encoder and a decoder connected in series.
[0070] Figure 3 Given Figure 2 Schematic diagram of the encoder structure. Figure 3 In the embodiment, the encoder is composed of convolution layer 1 and downsampling layer 1, downsampling layer 2, multi-branch attention module 1, multi-core hole convolution module 1, multi-branch attention module 2, multi-core hole convolution module 2, downsampling layer 3, multi-branch attention module 3, and multi-core hole convolution module 3, which are connected in series in sequence. The convolution kernel size of convolution layer 1 of the embodiment is 3×3, the step size is 1, and the padding is 1. The embodiment adopts an encoder of this structure to extract the content features of the source font and the style features of the reference sample; introduces a multi-branch attention module and a multi-core hole convolution module to extract richer local features and semantic information, and enhances the encoder's understanding and expression capabilities of detail features.
[0071] Figure 4 Given Figure 2 Schematic diagram of the decoder structure. Figure 4In the decoder of the present embodiment, a convolution layer 2 and a residual network layer 1, a residual network layer 2, a residual network layer 3, an efficient upsampling module 1, an efficient upsampling module 2, an efficient upsampling module 3, and a convolution layer 3 are sequentially connected in series. The convolution kernel size of the convolution layer 2 of the present embodiment is 1×1, the step size is 1, and the padding is 0, and the convolution kernel size of the convolution layer 3 is 3×3, the step size is 1, and the padding is 1. The convolution kernel size of the residual network layer 1 of the present embodiment is 3×3, the step size is 1, and the padding is 1. The structure of the residual network layer 2 and the residual network layer 3 of the present embodiment is the same as that of the residual network layer 1. The present embodiment adopts a decoder of this structure, combines the content features of the source font and the style features of the reference sample and generates a new font, which not only retains the content characteristics of the source font, but also can flexibly integrate the style of the reference sample; the efficient upsampling module is a known module, and the present embodiment introduces an efficient upsampling module to improve the generation effect of font details and avoid blurring and distortion of the generated font.
[0072] Figure 5 Given Figure 2 Schematic diagram of the discriminant network. Figure 5 In the embodiment, the discriminant network is composed of a convolutional layer 4 and a downsampling layer 4, a downsampling layer 5, a downsampling layer 6, a multi-branch attention module 4, a downsampling layer 7, a downsampling layer 8, a multi-branch attention module 5, and an average pooling layer 1, which are connected in series in sequence, and the output end of the average pooling layer 1 is connected to the input end of the Embedding layer 1 and the Embedding layer 2. The convolution kernel size of the convolutional layer 4 of the embodiment is 3×3, the step size is 2, and the padding is 1. The embodiment introduces the Embedding layer 1 and the Embedding layer 2, embeds the character content and the font style, and discriminates the content and style of the generated font, which effectively ensures the content integrity and style consistency of the generated font.
[0073] Figure 6 Given Figure 3 Schematic diagram of the structure of the multi-branch attention module 1. Figure 6In the embodiment, the multi-branch attention module 1 is composed of a convolution layer 5 connected with an average pooling layer 2, a Softmax activation layer 1, a horizontal pooling layer, a vertical pooling layer, a re-weighted layer 1, an average pooling layer 3, a Softmax activation layer 2, a re-weighted layer 2, a non-local attention module, an average pooling layer 4, and a Softmax activation layer 3; the convolution layer 5 is connected in series with the average pooling layer 2 and the Softmax activation layer 1; the horizontal pooling layer is connected in parallel with the vertical pooling layer, and its output end is connected in series with the re-weighted layer 1, the average pooling layer 3, and the Softmax activation layer 2; the non-local attention module is connected in series with the average pooling layer 4 and the Softmax activation layer 3; the output ends of the Softmax activation layer 1, the Softmax activation layer 2, and the Softmax activation layer 3 are connected to the re-weighted layer 2. The convolution kernel size of the convolution layer 5 of the embodiment is 3×3, the step size is 1, and the padding is 1.
[0074] The structures of the multi-branch attention module 2-multi-branch attention module 5 of this embodiment are the same as the structure of the multi-branch attention module 1. This embodiment adopts a multi-branch attention module, which captures the features of long-distance dependencies and important areas through adaptive weighting of multi-branch feature maps.
[0075] Figure 7 Given Figure 3 Schematic diagram of the structure of the multi-core hole convolution module 1. Figure 7 In the embodiment, the multi-core dilated convolution module 1 is composed of a convolution layer 6, a channel attention module, a dilated convolution layer 1, a dilated convolution layer 2, a dilated convolution layer 3, a feature fusion layer, a conditional convolution layer, a self-attention module, and a gating layer; the convolution layer 6 is connected in series with the channel attention module; the dilated convolution layer 1 is connected in parallel with the dilated convolution layer 2 and the dilated convolution layer 3, and its output end is connected in series with the feature fusion layer, the conditional convolution layer, and the self-attention module in sequence; the output ends of the channel attention module and the self-attention module are connected to the gating layer. In this embodiment, the convolution kernel size of the convolution layer 6 is 3×3, the step size is 1, and the padding is 1. The expansion rate of the hole convolution layer 1 is 1, the convolution kernel size is 3×3, the step size is 1, and the padding is 1; the expansion rate of the hole convolution layer 2 is 2, the convolution kernel size is 3×3, the step size is 1, and the padding is 2; the expansion rate of the hole convolution layer 3 is 4, the convolution kernel size is 3×3, the step size is 1, and the padding is 4; the convolution kernel size of the conditional convolution layer is 3×3, the step size is 1, and the padding is 1.
[0076] The structures of the multi-core dilated convolution module 2 and the multi-core dilated convolution module 3 of this embodiment are the same as the structure of the multi-core dilated convolution module 1. This embodiment adopts a multi-core dilated convolution module, and retains the detailed information of the source font and the reference sample through multi-scale information processing and dynamic feature fusion.
[0077] (3) Training a small sample Chinese font generation network
[0078] 1) Construct loss function
[0079] The loss function includes the discriminant network loss function L D , generate network loss function L G .
[0080] Generate network loss function L G Including generating network hinge loss function Reconstruction loss function L rec , feature map loss function L fm as follows:
[0081]
[0082] Among them, λ rec represents the weight of the reconstruction loss function, λ rec The value range is (0, 0.5). rec The value is 0.25, λ fm represents the weight of the feature map loss function, λ fm The value range is (0,1). fm The value is 0.5.
[0083] Construct the discriminant network loss function L as follows D :
[0084]
[0085] Among them, trg represents the real sample, gen represents the generated font, and y c Indicates content label, y s Represents the style label, D(trg,y c ) represents the probability of judging that the real sample content label is true, D(trg,y s ) represents the probability of judging the style label of the real sample to be true, D(gen,y c ) represents the probability of judging the generated font content label to be true, D(gen,y s ) represents the probability of judging the generated font style label to be true, and represents the expected value of the latter.
[0086] The hinge loss function of the generated network is constructed as follows
[0087]
[0088] The reconstruction loss function L is constructed as follows: rec :
[0089]
[0090] Where i represents the pixel number, n pixel Indicates the total number of pixels of the real sample, trg i Represents the value of the i-th pixel of the true sample, gen i Indicates the value of the i-th pixel of the generated font, E (trg,gen) represents the expected value of the latter.
[0091] The feature map loss function L is constructed as follows fm :
[0092]
[0093] Among them, trg_fm represents the feature map of the real sample, gen_fm represents the feature map of the generated font, and n pixel_fm Indicates the total number of pixels of the real sample feature map, trg_fm i Represents the value of the i-th pixel in the real sample feature map, gen_fm i Indicates the value of the i-th pixel in the generated font feature map, E (trg_fm,gen_fm) represents the expected value of the latter.
[0094] 2) Training a small sample Chinese font generation network
[0095] The training set is input into the small sample Chinese font generation network for training. The training parameters are set as follows: batch size is 8, the learning rate of the generation network is 0.0002, the learning rate of the discriminant network is 0.001, and the optimizer is Adam. The training is performed until the loss function converges.
[0096] (4) Testing a small sample Chinese font generation network
[0097] The test set is input into the trained small sample Chinese font generation network, and five generated Chinese fonts, namely running script, regular script, semi-regular script, official script, and handwriting, are output.
[0098] Complete the small sample Chinese font generation method.
[0099] Example 2
[0100] The method for generating a small sample Chinese font in this embodiment comprises the following steps:
[0101] (1) Establishing a Chinese font dataset
[0102] This step is the same as in Example 1.
[0103] (2) Constructing a small sample Chinese font generation network
[0104] This step is the same as in Example 1.
[0105] (3) Training a small sample Chinese font generation network
[0106] 1) Construct loss function
[0107] The loss function includes the discriminant network loss function L D , generate network loss function L G .
[0108] Generate network loss function L G Including generating network hinge loss function Reconstruction loss function L rec , feature map loss function L fm as follows:
[0109]
[0110] Among them, λ rec represents the weight of the reconstruction loss function, λ rec The value range is (0, 0.5). rec The value is 0.01, fm represents the weight of the feature map loss function, λ fm The value range is (0,1). fm The value is 0.01.
[0111] The other steps of this step are the same as those in Example 1.
[0112] The other steps are the same as those in Example 1.
[0113] Complete the small sample Chinese font generation method.
[0114] Example 3
[0115] The method for generating a small sample Chinese font in this embodiment comprises the following steps:
[0116] (1) Establishing a Chinese font dataset
[0117] This step is the same as in Example 1.
[0118] (2) Constructing a small sample Chinese font generation network
[0119] This step is the same as in Example 1.
[0120] (3) Training a small sample Chinese font generation network
[0121] 1) Construct loss function
[0122] The loss function includes the discriminant network loss function L D , generate network loss function L G .
[0123] Generate network loss function L G Including generating network hinge loss function Reconstruction loss function L rec , feature map loss function L fm as follows:
[0124]
[0125] Among them, λ rec represents the weight of the reconstruction loss function, λ rec The value range is (0, 0.5). rec The value is 0.49, fm represents the weight of the feature map loss function, λ fm The value range is (0,1). fm The value is 0.99.
[0126] The other steps of this step are the same as those in Example 1.
[0127] The other steps are the same as those in Example 1.
[0128] Complete the small sample Chinese font generation method.
[0129] In order to verify the beneficial effects of the present invention, a computer simulation experiment was carried out using the method of Example 1. The various simulation experiments are as follows:
[0130] 1. Simulation environment
[0131] The hardware conditions are: Ubuntu 20.04.5LTS, 1 NVIDIA RTX3090 GPU card.
[0132] The software platform is: Python language and Pytorch deep network framework.
[0133] 2. Simulation content and results
[0134] The computer simulation experiment was carried out using the method of Example 1, and the experimental results are shown in Figure 8 .Depend on Figure 8 It can be seen that the first line is the source font, the second line is the reference sample, and the third line is the generated font. The first to fifth columns are five kinds of Chinese fonts: running script, regular script, running regular script, official script, and handwriting. The generated Chinese font content is consistent with the source font, which reduces the common stroke missing and adhesion problems in the Chinese font generation process. In a small sample learning environment, the generated Chinese font is similar to the style of the reference sample.
Claims
1. A method for generating a small sample Chinese font, characterized in that It consists of the following steps: (1) Establishing a Chinese font dataset 1) Collect Chinese font files and build character sets Collect 100 TrueType Chinese fonts that conform to the GB2312 standard. The 6763 characters included in the standard form a complete character set. 50 characters are randomly selected from the complete character set as a small sample character set. 2) Divide the training set and test set 94 Chinese fonts were used as training sets, and glyph images in the complete character set were extracted as source fonts and reference samples; The remaining 6 Chinese fonts are used as test sets. The glyph images of the complete character set of one of the Chinese fonts are extracted as the source font. The glyph images of the small sample character set of the five Chinese fonts, namely, running script, regular script, running regular script, official script, and handwriting, are extracted as reference samples. (2) Constructing a small sample Chinese font generation network The small sample Chinese font generation network is composed of a generation network and a discriminant network in series; The generation network is composed of an encoder and a decoder connected in series; The encoder is composed of a convolution layer 1 and a downsampling layer 1, a downsampling layer 2, a multi-branch attention module 1, a multi-core hole convolution module 1, a multi-branch attention module 2, a multi-core hole convolution module 2, a downsampling layer 3, a multi-branch attention module 3, and a multi-core hole convolution module 3 connected in series in sequence; The decoder is composed of a convolutional layer 2 and a residual network layer 1, a residual network layer 2, a residual network layer 3, an efficient upsampling module 1, an efficient upsampling module 2, an efficient upsampling module 3, and a convolutional layer 3 connected in series in sequence; The discriminant network is composed of a convolutional layer 4 and a downsampling layer 4, a downsampling layer 5, a downsampling layer 6, a multi-branch attention module 4, a downsampling layer 7, a downsampling layer 8, a multi-branch attention module 5, and an average pooling layer 1, which are connected in series in sequence, and the output end of the average pooling layer 1 is connected to the input end of the Embedding layer 1 and the Embedding layer 2; (3) Training a small sample Chinese font generation network 1) Construct loss function The loss function includes the discriminant network loss function L D , generate network loss function L G ; Generate network loss function L G Including generating network hinge loss function Reconstruction loss function L rec , feature map loss function L fm as follows: Among them, λ rec represents the weight of the reconstruction loss function, λ rec The value range is (0,0.5), λ fm represents the weight of the feature map loss function, λ fm The value range is (0,1); Construct the discriminant network loss function L as follows D : Among them, trg represents the real sample, gen represents the generated font, and y c Indicates content label, y s Represents the style label, D(trg,y c ) represents the probability of judging that the real sample content label is true, D(trg,y s ) represents the probability of judging the style label of the real sample to be true, D(gen,y c ) represents the probability of judging the generated font content label to be true, D(gen,y s ) represents the probability of judging the generated font style label to be true, and represents the expected value of the latter form; The hinge loss function of the generated network is constructed as follows The reconstruction loss function L is constructed as follows: rec : Where i represents the pixel number, n pixel Indicates the total number of pixels of the real sample, trg i Represents the value of the i-th pixel of the true sample, gen i Indicates the value of the i-th pixel of the generated font, E (trg,gen) represents the expected value of the latter form; The feature map loss function L is constructed as follows fm : Among them, trg_fm represents the feature map of the real sample, gen_fm represents the feature map of the generated font, and n pixel_fm Indicates the total number of pixels of the real sample feature map, trg_fm i Represents the value of the i-th pixel in the real sample feature map, gen_fm i Indicates the value of the i-th pixel in the generated font feature map, E (trg_fm,gen_fm) represents the expected value of the latter form; 2) Training a small sample Chinese font generation network The training set is input into the small sample Chinese font generation network for training. The training parameters are set as follows: batch size is 8, the learning rate of the generation network is 0.0002, the learning rate of the discriminant network is 0.001, and the optimizer is Adam. The training is performed until the loss function converges. (4) Testing a small sample Chinese font generation network The test set is input into the trained small sample Chinese font generation network, and five generated Chinese fonts, namely running script, regular script, semi-regular script, official script, and handwriting, are output.
2. The method for generating a small sample Chinese font according to claim 1, characterized in that: In step (2) of constructing a small sample Chinese font generation network, the multi-branch attention module 1 is composed of a convolution layer 5, an average pooling layer 2, a Softmax activation layer 1, a horizontal pooling layer, a vertical pooling layer, a re-weighted layer 1, an average pooling layer 3, a Softmax activation layer 2, a re-weighted layer 2, a non-local attention module, an average pooling layer 4, and a Softmax activation layer 3; the convolution layer 5 is connected in series with the average pooling layer 2 and the Softmax activation layer 1; the horizontal pooling layer is connected in parallel with the vertical pooling layer, and its output end is connected in series with the re-weighted layer 1, the average pooling layer 3, and the Softmax activation layer 2; the non-local attention module is connected in series with the average pooling layer 4 and the Softmax activation layer 3; the output ends of the Softmax activation layer 1, the Softmax activation layer 2, and the Softmax activation layer 3 are connected in series with the re-weighted layer 2; The structure of the multi-branch attention module 2-multi-branch attention module 5 is the same as that of the multi-branch attention module 1.
3. The method for generating a small sample Chinese font according to claim 1, characterized in that: In step (2) of constructing a small sample Chinese font generation network, the multi-core dilated convolution module 1 is composed of a convolution layer 6, a channel attention module, a dilated convolution layer 1, a dilated convolution layer 2, a dilated convolution layer 3, a feature fusion layer, a conditional convolution layer, a self-attention module, and a gating layer; the convolution layer 6 is connected in series with the channel attention module; the dilated convolution layer 1 is connected in parallel with the dilated convolution layer 2 and the dilated convolution layer 3, and its output end is connected in series with the feature fusion layer, the conditional convolution layer, and the self-attention module in sequence; the output ends of the channel attention module and the self-attention module are connected to the gating layer; The structures of the multi-core dilated convolution module 2 and the multi-core dilated convolution module 3 are the same as that of the multi-core dilated convolution module 1.
4. The method for generating a small sample Chinese font according to claim 1, characterized in that: In step (2) of constructing a small sample Chinese font generation network, the convolution kernel size of the convolution layer 1 and the convolution layer 3 is 3×3, the step size is 1, and the padding is 1; the convolution kernel size of the convolution layer 2 is 1×1, the step size is 1, and the padding is 0; the convolution kernel size of the convolution layer 4 is 3×3, the step size is 2, and the padding is 1.
5. The method for generating a small sample Chinese font according to claim 1, characterized in that: In step (2) of constructing a small sample Chinese font generation network, the convolution kernel size of the residual network layer 1 is 3×3, the step size is 1, and the padding is 1; the structures of the residual network layer 2 and the residual network layer 3 are the same as the structure of the residual network layer 1.
6. The method for generating a small sample Chinese font according to claim 2, characterized in that: The convolution kernel size of the convolution layer 5 is 3×3, the step size is 1, and the padding is 1.
7. The method for generating a small sample Chinese font according to claim 3, characterized in that: The convolution kernel size of the convolution layer 6 is 3×3, the step size is 1, and the padding is 1. The expansion rate of the dilated convolution layer 1 is 1, the convolution kernel size is 3×3, the step size is 1, and the padding is 1; the expansion rate of the dilated convolution layer 2 is 2, the convolution kernel size is 3×3, the step size is 1, and the padding is 2; the expansion rate of the dilated convolution layer 3 is 4, the convolution kernel size is 3×3, the step size is 1, and the padding is 4; the convolution kernel size of the conditional convolution layer is 3×3, the step size is 1, and the padding is 1.
8. The method for generating a small sample Chinese font according to claim 1, characterized in that: In step (3) of training the small sample Chinese font generation network 1) constructing the loss function, the λ rec represents the weight of the reconstruction loss function, λ fm represents the weight of the feature map loss function, λ rec The value is 0.25, λ fm The value is 0.5.