Chinese font style transfer method based on adaptive generative adversarial network
Through adaptive generative adversarial network technology, font content and style features are separated and integrated, which solves the problem of poor transfer effect between multiple fonts in the existing technology and achieves efficient and realistic font style transfer effect.
Patent Information
- Application Number
- CN202111429305.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-11-29
- Publication Date
- 2024-10-22
- Estimated Expiration
- 2041-11-29
AI Technical Summary
Existing font style transfer technology is difficult to achieve efficient and realistic style transfer between multiple fonts, and the existing technology has blurred edge details and low efficiency when migrating a single font.
Using a method based on adaptive generative adversarial networks, we separate font content and style features by training the encoder, build a style feature warehouse, and optimize the generator through adaptive weight vectors to integrate the content features of the font to be migrated and the style features of the target font. , generate target font samples.
It achieves efficient and realistic style transfer effects between multiple fonts, improves the authenticity and convenience of the transfer effect, and is suitable for the migration of multiple target fonts.
Smart Images

Figure CN114139495B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of font design, and in particular to a Chinese font style transfer method based on an adaptive generative adversarial network. Background Art
[0002] As a carrier of cultural heritage and information expression, fonts give people more implicit and euphemistic emotional expression and abstract aesthetics. Fonts have experienced the baptism and inheritance of history and culture, and have rich and beautiful font styles. Therefore, in today's rapidly developing digital age, fonts of different styles are widely used in graphic advertising, product packaging, trademarks, corporate logos, book cover layouts, web page interfaces and other related designs.
[0003] The design of font style is an extremely difficult task, and it is still considered to be the privilege of professional designers. Existing software systems do not have the creativity of professional designers. At present, most commercial font products are actually hand-designed according to specific requirements for certain glyph attributes, such as italics, serifs, cursive, width, angle, etc. Among them, the design of Chinese font style is particularly difficult. According to statistics, among Chinese characters, 1,000 commonly used Chinese characters can cover about 92% of written materials, 2,000 Chinese characters can cover more than 98%, and 3,000 characters can cover 99%. Therefore, at least about 2,800 individual Chinese characters need to be designed to meet the needs of actual use. Chinese font design artists have designed a variety of fonts for Chinese fonts, such as Kaiti, Songti, Fangzheng Fangsong, and Heiti. However, due to the wide variety of Chinese characters, complex radical structures, and different lengths, each character is composed of many radicals and strokes during design, which is first completed through geometric modeling and then manual operation, so the design process requires a lot of human resources.
[0004] Font style transfer is a specific application background of image style transfer. It has great research significance and commercial value in some font design and development applications. Currently, the conventional technical routes are mainly divided into the following two types.
[0005] 1. Using a CNN-based deep learning network, the idea is to use a baseline network in the image classification direction to extract font features, and use mean square error or absolute error loss to optimize the network. Its disadvantage is that it can only complete the migration function of a single font, and the edge details of the migrated font are relatively fuzzy. The advantage is that the technology is simple, convenient and efficient. Among them, the paper "Chinese Handwriting Generation by Neural Network Based Style Transformation" realizes the function of migrating printed fonts to Song fonts.
[0006] 2. Use the generative adversarial network (GAN) to achieve font style transfer. The paper "Chinese Typography Transfer" proposed an end-to-end deep learning algorithm for Chinese font transfer, using the fully convolutional network (FCN) as the transfer network to capture calligraphy style information from the target characters, and then reconstruct the output of the target font. The advantages of the generative adversarial network (GAN) are combined to assist in optimizing the parameters of the transfer network, thereby improving the effect and fidelity of single font style transfer. Another paper "DCFont: An End-To-End Deep Chinese Font Generation System" is mainly through the font feature reconstruction network and the font grid transfer network. The former uses the encoding and decoding framework built by the VGG16 network to achieve a small number of characters written by a given user to reconstruct and estimate the font features of all other characters; the latter uses the adversarial network to optimize the generator, converting the characters in the reference font style into the target handwriting style. Its main contribution is that the input of the decoding network in the generator is a fusion of the content and the target font feature style. Summary of the invention
[0007] The purpose of the present invention is to provide a Chinese font style transfer method based on an adaptive generative adversarial network with excellent transfer effect, and is suitable for style transfer between multiple fonts.
[0008] To achieve the above objectives, the technical solution adopted by the present invention is: a Chinese font style migration method based on an adaptive generative adversarial network, including a generator composed of an encoder and a decoder, including the following steps: S100, training an encoder capable of separating font content and style; S200, constructing a style feature warehouse of the trained font category based on the trained encoder; S300, constructing an adaptive generative adversarial network optimization training; S400, inputting the font sample to be migrated into the feature map generated by the trained encoder, inputting the migration target information into the style feature warehouse to generate a target font style feature map, and fusing the two feature maps and inputting them into the trained decoder to generate a target font sample.
[0009] Compared with the prior art, the present invention has the following technical effects: in the present invention, the encoder is firstly trained by the existing fonts, and the loss function during training is defined so that the encoder can output separated content and style features; then, the style features of the font are extracted from the trained encoder from the existing commonly used characters of the target font and saved; then, the other parameters of the generator are optimized according to the font to be migrated and its corresponding target font, and the construction of the network model is completed. When other characters of the target font are generated, the migration effect is very good because the characters are fused by the content features of the font to be migrated and the style features of the target font. BRIEF DESCRIPTION OF THE DRAWINGS
[0010] Figure 1 is the training flow chart of the encoder;
[0011] Figure 2 This is a schematic diagram of the font style feature warehouse construction process;
[0012] Figure 3 This is a flowchart for training the decoder. DETAILED DESCRIPTION
[0013] Combine the following Figures 1 to 3 , the present invention is further described in detail.
[0014] See also Figure 1-3 , a Chinese font style transfer method based on adaptive generative adversarial network, including a generator composed of an encoder and a decoder, including the following steps: S100, training an encoder capable of separating font content and style; S200, constructing a style feature warehouse of the trained font category according to the trained encoder; S300, constructing an adaptive generative adversarial network optimization training; S400, inputting the font sample to be transferred into the feature map generated by the trained encoder, inputting the transfer target information into the style feature warehouse to generate the target font style feature map, and merging the two feature maps and inputting them into the trained decoder to generate the target font sample. In the present invention, the encoder is firstly trained by the existing font, and the loss function is defined during training so that the encoder can output separated content and style features; then the style features of the font are extracted from the trained encoder from the existing common characters of the target font and saved; then, according to the font to be transferred and its corresponding target font, the other parameters of the generator are tuned, and the construction of the network model is completed. When generating other characters of the target font, the migration effect is very good because it is formed by the fusion of the content features of the font to be transferred and the style features of the target font.
[0015] In the above and below, the "to-be-migrated" font refers to the font before migration, and the "target font" refers to the font after migration. For example, if we need to generate a handwritten font B based on a known font A (such as Songti), then the font A here is the to-be-migrated font or the font before migration, and the generated font B is the target font or the font after migration. In addition, in the following, the font generated by A can be called pseudo B or the generated font B sample, etc.
[0016] See also Figure 1, further, the step S100 includes the following steps: S110, constructing the encoder and decoder framework and initializing the network parameters of the encoder and decoder; S120, dividing the output feature map of the encoder into a first feature map representing the font content and a second feature map representing the font style; S130, fusing the two feature maps and inputting them into the decoder, and calculating the reconstruction loss according to the output of the decoder; S140, reducing the dimension of the second feature map by multiple 1×1 convolutions and global average pooling operations to obtain a one-dimensional feature vector, performing softmax classification on the one-dimensional feature vector to obtain the probability distribution of font classification and calculating the font classification loss accordingly; S150, preparing data of multiple font types to form a first training set; S160, using the first training set to train the encoder and decoder, the loss function during training is composed of the reconstruction loss and the classification loss superimposed. Here, the backbone of the encoder can be composed of a VGG16 network. In order to enable the encoder to learn the maximum interval between style and content, we introduce another classification branch in the network optimization process. The reconstruction loss corresponds to unsupervised training, and the classification loss corresponds to supervised training. When training the encoder, the first training set can be composed of multiple fonts and multiple scripts, such as the common Songti, Kaiti, Lishu, and Heiti. At the same time, some Chinese characters with common radicals of the target font will also be prepared. The more font types the first training set contains, the more likely the trained encoder will be able to distinguish most font content and styles.
[0017] Since the differences between Chinese characters in different Chinese fonts are mainly manifested in the differences in the relative distances between the edge contours of common strokes and radicals, the strokes reflect the differences between local features, and the relative positions between radicals correspond to the differences in global features. Therefore, the abstract features of a certain font style can be linearly represented by a set of basis vectors of characters with common strokes and radicals in a high-dimensional data ball space. The purpose of constructing a feature space warehouse is to be able to better select and match such basis vectors during the style migration process, making the migration effect more realistic. To this end, we have to manually collect a set of Chinese characters with common radicals in each font. This set is not fixed, and different companies may use different sets. Generally, 200-300 characters are selected, which cover the vast majority of radicals. After collecting the set of Chinese characters, we construct a feature space warehouse of the corresponding style. The specific process is as follows: Figure 2 As shown, in the step S200, the Chinese characters of the common radicals of the target font are prepared and input into the trained encoder, and the multiple one-dimensional feature vectors outputted by the encoder are saved to obtain the font style feature warehouse, which has two dimensions, namely the sample set size and the one-dimensional feature vector representing the font style of each sample. The font style feature warehouse here is a two-dimensional matrix, which represents the style of a font, that is, the style feature of the target font.
[0018] See also Figure 3 , further, the step S300 includes the following steps: S310, inputting the Chinese characters of the common radicals of the font to be migrated into the trained encoder to obtain a first feature map representing the font content and a second feature map representing the font style; S320, introducing an adaptive weight vector and multiplying it with the two-dimensional matrix of the font style characteristics of the target font to obtain a one-dimensional feature vector representing the style of the target font, and upsampling the one-dimensional feature vector to obtain a third feature map representing the style of the target font; S330, fusing the first feature map, the second feature map and the third feature map obtained in step S310 and step S320 and inputting them into the decoder to generate a pseudo sample of the target font, and calculating the reconstruction loss of the generator based on the pseudo sample; S340, inputting the pseudo sample and the real sample of the target font into the discriminator, and calculating the adversarial loss based on the identification result; S350, preparing the Chinese characters of the common radicals of the font to be migrated and the target font to constitute a second training set; S360, fixing the network parameters of the encoder, and using the second training set to train the decoder and the adaptive weight vector, and the loss function during training is the superposition of the reconstruction loss and the adversarial loss. By setting an adaptive weight vector, the two-dimensional matrix stored in the font style feature warehouse can be used to generate the style features corresponding to the font, so as to facilitate the extraction of the style features of the target font. At the same time, by using the discriminator to distinguish between pseudo samples and real samples, adversarial loss can be introduced. Combined with the reconstruction loss of the generator itself, it is equivalent to using supervised training and unsupervised training here, ensuring that the trained network parameters are better.
[0019] After the above network parameter optimization is completed, font style migration can be conveniently performed. Furthermore, the step S400 includes the following steps: S410, inputting any Chinese character of the font to be migrated into the trained encoder to obtain a first feature map representing the font content and a second feature map representing the font style; S420, fusing the third feature map representing the target font style with the first feature map and the second feature map in step S410 and inputting them into the trained decoder to generate the corresponding Chinese characters in the target font.
[0020] The present invention is also applicable to the migration of multiple target fonts, and more preferably, in step S200, there are multiple target fonts, the font style feature warehouse has three dimensions and the third dimension is the font category; in step S300, the decoder network parameters and adaptive weight vectors corresponding to each target font are trained separately for each target font; in step S400, the decoder network parameters, upsampling parameters and adaptive weight vectors corresponding to the target font are selected when performing font style migration. When performing font style migration, you only need to select the parameters corresponding to the target font, which is very convenient to use.
[0021] Specifically, in step S120, the size of the first feature map is C1*W*H, and the size of the second feature map is C2*W*H. In step S130, the size of the two feature maps after fusion is (C1+C2)*W*H. The fusion here is a simple channel addition. Here, C1 can be equal to C2 or not. In step S160, the loss function after superposition is as follows:
[0022] ;
[0023] In the formula, and The two coefficients are the set coefficients, followed by the reconstruction loss and the classification loss.
[0024] Furthermore, in the step S140, the length of the one-dimensional feature vector is N, in the step S200, there are M Chinese characters with common radicals, and the font style feature warehouse is a matrix of size N*M; in the step S320, the adaptive weight vector is a matrix of size M*1, and the one-dimensional feature vector of length N is obtained by multiplying the font style feature warehouse and the adaptive weight vector. The upsampling is composed of multiple transposed convolutions, and the size of the third feature map obtained by upsampling is C2*W*H; in the step S330, the second feature map and the third feature map are first superimposed. When superimposing, the weight of the third feature map can be set larger, and the size of the superimposed feature map is still C2*W*H, and then the superimposed feature map and the first feature map are fused. The fusion here is the same as that in step S130, which is a simple channel addition.
[0025] Furthermore, the generator converts the input image x with the target label c into a target pseudo sample G(x,c), and the discriminator judges the pseudo sample and the real sample. Step S360 includes the following steps:
[0026] S361, first calculate the reconstruction loss according to the output of the decoder according to the following formula:
[0027]
[0028] In the formula, The loss is used to measure the difference between the pseudo samples generated by the generator and the real samples of the pseudo target samples, and its loss form is as follows:
[0029]
[0030] The font sample is black text on a white background, and condition A means that the background of the font area in the sample is the white background area;
[0031] S362. Calculate the adversarial loss according to the output of the discriminator using the following formula:
[0032]
[0033] In the formula, E(*) represents the expectation of the distribution function;
[0034] S363. Calculate the total loss of the discriminator and the generator according to the reconstruction loss and the adversarial loss using the following formula:
[0035]
[0036]
[0037] Among them, the total loss of the discriminator Used to train and optimize the network parameters of the discriminator and the total loss of the generator Used to train and optimize the network parameters of the decoder, adaptive weight vectors, and upsampled transposed convolutions.
[0038] The present invention also discloses a computer-readable storage medium, on which a computer program is stored, and when the computer program is executed by a processor, the aforementioned font style transfer method is implemented. The present invention also discloses an electronic device, including a memory, a processor, and a computer program stored in the memory, and when the processor executes the computer program, the aforementioned font style transfer method is implemented.
Claims
1. A Chinese font style transfer method based on adaptive generative adversarial network, Features: The generator includes an encoder and a decoder, and includes the following steps: S100, trains an encoder capable of separating font content and style; S200, constructing a style feature warehouse of the trained font category according to the trained encoder; S300, constructing an adaptive generative adversarial network optimization training, wherein the adaptive generative adversarial network is composed of a generator and a discriminator composed of the encoder and the decoder, and the adaptive generative adversarial network optimization training steps include: S310, inputting Chinese characters of common radicals of the font to be migrated into the trained encoder to obtain a first feature map representing the font content and a second feature map representing the font style; S320, introducing an adaptive weight vector and multiplying it with a two-dimensional matrix of font style features of a target font to obtain a one-dimensional feature vector representing the target font style, and upsampling the one-dimensional feature vector to obtain a third feature map representing the target font style; S330, fusing the first feature map, the second feature map, and the third feature map obtained in step S310 and step S320, and inputting the result into the decoder to generate a pseudo sample of the target font, and calculating the reconstruction loss of the generator according to the pseudo sample; S340, inputting the pseudo sample and the real sample of the target font into the discriminator, and calculating the adversarial loss according to the identification result; S350, preparing a second training set consisting of Chinese characters of common radicals of the font to be migrated and the target font; S360, fixing the network parameters of the encoder, and using the second training set to train the decoder and the adaptive weight vector, wherein the loss function during training is a superposition of the reconstruction loss and the adversarial loss; S400, input the font sample to be migrated into the feature map generated by the trained encoder, input the migration target information into the style feature warehouse to generate the target font style feature map, and fuse the two feature maps and input them into the trained decoder to generate the target font sample.
2. The Chinese font style transfer method based on adaptive generative adversarial network as claimed in claim 1, Features: The step S100 includes the following steps: S110, constructing the encoder and decoder framework and initializing the network parameters of the encoder and decoder; S120, dividing the output feature map of the encoder into a first feature map representing the font content and a second feature map representing the font style; S130, fusing the two feature maps and inputting them into the decoder, and calculating the reconstruction loss according to the output of the decoder; S140, performing dimensionality reduction and global average pooling operations on the second feature map to obtain a one-dimensional feature vector, performing softmax classification on the one-dimensional feature vector to obtain a probability distribution of font classification and calculating the font classification loss based on the probability distribution; S150, preparing data of multiple font types to form a first training set; S160, using the first training set to train the encoder and the decoder, the loss function during training being a superposition of the reconstruction loss and the classification loss.
3. The Chinese font style transfer method based on adaptive generative adversarial network as claimed in claim 2, Features: In the step S200, Chinese characters with common radicals in the target font are prepared and input into the trained encoder, and multiple one-dimensional feature vectors outputted by the encoder are saved to obtain a font style feature warehouse, which has two dimensions, namely, the sample set size and a one-dimensional feature vector representing the font style of each sample.
4. The Chinese font style transfer method based on adaptive generative adversarial network as claimed in claim 1, Features: The step S400 includes the following steps: S410, inputting any Chinese character of the font to be migrated into the trained encoder to obtain a first feature map representing the content of the font and a second feature map representing the style of the font; S420, fusing the third feature map representing the style of the target font with the first feature map and the second feature map in step S410, and inputting the resultant into the trained decoder to generate the corresponding Chinese characters in the target font.
5. The Chinese font style transfer method based on adaptive generative adversarial network as claimed in claim 1, Features: In the step S200, there are multiple target fonts, the font style feature warehouse has three dimensions and the third dimension is the font category; in step S300, each target font is trained separately to obtain the decoder network parameters and adaptive weight vector corresponding to each target font; in step S400, the decoder network parameters, upsampling parameters and adaptive weight vector corresponding to the target font are selected when performing font style migration.
6. The Chinese font style transfer method based on adaptive generative adversarial network as claimed in claim 2, Features: In the step S120, the size of the first feature map is C1*W*H, the size of the second feature map is C2*W*H, and in the step S130, the size of the two feature maps after fusion is (C1+C2)*W*H; in the step S160, the superimposed loss function is as follows: In the formula, α and β are the set coefficients, and the two coefficients are followed by the reconstruction loss and classification loss respectively.
7. The Chinese font style transfer method based on adaptive generative adversarial network as claimed in claim 2, Features: In the step S140, the length of the one-dimensional feature vector is N. In the step S200, there are M Chinese characters with common radicals, and the font style feature warehouse is a matrix of size N*M. In the step S320, the adaptive weight vector is a matrix of size M*1. The font style feature warehouse is multiplied by the adaptive weight vector to obtain a one-dimensional feature vector of length N. The upsampling is composed of multiple transposed convolutions, and the size of the third feature map obtained by upsampling is C2*W*H. In the step S330, the second feature map and the third feature map are first superimposed, and then the superimposed feature map and the first feature map are fused.
8. The Chinese font style transfer method based on adaptive generative adversarial network as claimed in claim 7, Features: The generator converts the input image x with the target label c into a target pseudo sample G(x,c), and the discriminator judges the pseudo sample and the real sample. Step S360 includes the following steps: S361, first calculate the reconstruction loss according to the output of the decoder according to the following formula: L rec =E x,c,c [||x-G(G(x,c),c’)|| |smooth_L1 ]; In the formula, smooth_L1 loss is used to measure the difference between the pseudo sample generated by the generator and the real sample of the pseudo target sample, and its loss form is as follows: The font sample is black text on a white background, and condition A means that the background of the font area in the sample is the white background area; S362. Calculate the adversarial loss according to the output of the discriminator using the following formula: L adv =E x [logD src (x)]+E x,c [log(1-D src (G(x,c)))]; In the formula, E(*) represents the expectation of the distribution function; S363. Calculate the total loss of the discriminator and the generator according to the reconstruction loss and the adversarial loss using the following formula: L D =-L adv ; L G =L adv +λ rec *L rec ; Among them, the total loss of the discriminator is L D Used to train and optimize the network parameters of the discriminator, the total loss L of the generator G Used to train and optimize the network parameters of the decoder, adaptive weight vectors, and upsampled transposed convolutions.
9. A computer-readable storage medium, Features: A computer program is stored thereon, and when the computer program is executed by a processor, the method according to any one of claims 1 to 8 is implemented.
10. An electronic device, Features: The method comprises a memory, a processor and a computer program stored in the memory, wherein when the processor executes the computer program, the method according to any one of claims 1 to 8 is implemented.
Citation Information
Patent Citations
Font style migration method based on conditional cycle consistency generative adversarial network
CN110503598A
Multi-domain image conversion method and system based on conditional generative adversarial network, and medium
CN110675316A
Character style migration method based on two-stage deep network
CN112307714A
Chinese calligraphy character image style migration method and system, and intelligent terminal
CN113393370A
Generating stylized-stroke images from source images utilizing style-transfer-neural networks with non-photorealistic-rendering
US20200151938A1
