Font generation method, font generation model training method, device and equipment
By acquiring text images of the target font and multiple base fonts, and determining and mixing style features and content features, the problem of inconsistent style in the generated text skeleton was solved, achieving a higher consistency in generation results.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- ZHEJIANG UNIV
- Filing Date
- 2022-12-23
- Publication Date
- 2026-04-24
AI Technical Summary
The existing technology has the problem that the skeleton style of the generated text is inconsistent with the skeleton style of the reference text.
By acquiring reference text of the target font and text images of target text from multiple base fonts, the style characteristics and multiple content characteristics of the target font are determined, and they are mixed to generate the target text corresponding to the target font.
This improved the consistency between the skeleton style of the generated text and the skeleton style of the reference text, thereby increasing the accuracy of the training results.
Smart Images

Figure CN116152368B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of computer technology, and in particular to a font generation method, a font generation model training method, apparatus, and device. Background Technology
[0002] In advertising creative production, web design and other scenarios, it is indispensable to use text to convey information, and different fonts will affect the overall visual effect or reading experience. In practical applications, fonts can be automatically generated as needed.
[0003] Typically, the font generation method used in automatic font generation is as follows: content features are obtained from the text image of the target text in a known font (e.g., KaiTi), and style features are obtained from the text image of a reference text for the target font. These two types of features are then combined and a decoder is used to generate the target text corresponding to the target font. However, this method suffers from the problem that the skeletal style of the generated text is inconsistent with the skeletal style of the reference text. Summary of the Invention
[0004] This application provides a font generation method, a font generation model training method, an apparatus, and a device to solve the problem in the prior art where the skeleton style of the generated text is inconsistent with the skeleton style of the reference text.
[0005] In a first aspect, embodiments of this application provide a font generation method, including:
[0006] Obtain text images of reference text for the target font, as well as text images of target text for multiple preset base fonts, where the skeleton styles of different base fonts are different;
[0007] Based on the text image of the reference text, the style features of the target font are determined, and based on the text image of the target text, multiple content features of the target text are obtained.
[0008] The style features and multiple content features of the target text are mixed to obtain the target text corresponding to the target font.
[0009] Secondly, embodiments of this application provide a font generation method, including:
[0010] Obtain the generation request sent by the terminal, the generation request being used to request the generation of the target text corresponding to the target font;
[0011] Upon receiving the generation request, the target text corresponding to the target font is obtained. The target text corresponding to the target font is obtained in the following way: based on the text image of the reference text of the target font, the style features of the target font are determined, and based on the text images of the target text of multiple preset base fonts, multiple content features of the target text are obtained, with different skeleton styles for different base fonts; the style features and the multiple content features of the target text are mixed to obtain the target text corresponding to the target font.
[0012] Send the target text corresponding to the target font to the terminal.
[0013] Thirdly, embodiments of this application provide a font generation method, including:
[0014] In response to a user's action, a generation request is sent to the server, the generation request being used to request the generation of the target text corresponding to the target font;
[0015] The target text corresponding to the target font sent by the server based on the generation request is obtained. The target text corresponding to the target font is obtained in the following way: based on the text image of the reference text of the target font, the style features of the target font are determined, and based on the text images of the target text of multiple preset base fonts, multiple content features of the target text are obtained, and the skeleton styles of different base fonts are different; the style features and the multiple content features of the target text are mixed to obtain the target text corresponding to the target font.
[0016] Output the target text corresponding to the target font.
[0017] Fourthly, embodiments of this application provide a method for training a font generation model, including:
[0018] A basic model is constructed, which is equipped with training parameters. The basic model is used to generate fonts based on text images of target characters in a known font.
[0019] Using the corresponding training samples, the training parameters of the base model are iteratively adjusted until the second preset requirement is met, thereby obtaining the trained base model;
[0020] The base model is adjusted to a model for font generation based on text images of target texts with multiple preset base fonts, resulting in a font generation model to be trained, wherein the skeleton styles of different base fonts are different;
[0021] Using the corresponding training samples, the training parameters of the font generation model are iteratively adjusted until the second preset requirement is met, thereby obtaining the trained font generation model.
[0022] Fifthly, embodiments of this application provide a font generation apparatus, comprising:
[0023] The acquisition module is used to acquire text images of reference text for the target font, as well as text images of target text for multiple preset base fonts, where the skeleton styles of different base fonts are different;
[0024] The feature module is used to determine the style features of the target font based on the text image of the reference text, and to obtain multiple content features of the target text based on the text image of the target text.
[0025] The mixing module is used to mix the style features and multiple content features of the target text to obtain the target text corresponding to the target font.
[0026] Sixthly, embodiments of this application provide a font generation apparatus, comprising:
[0027] The acquisition module is used to acquire the generation request sent by the terminal, wherein the generation request is used to request the generation of the target text corresponding to the target font;
[0028] The acquisition module is used to obtain the target text corresponding to the target font when the generation request is received. The target text corresponding to the target font is obtained in the following way: based on the text image of the reference text of the target font, the style features of the target font are determined, and based on the text images of the target text of multiple preset base fonts, multiple content features of the target text are obtained, with different skeleton styles of different base fonts; the style features and the multiple content features of the target text are mixed to obtain the target text corresponding to the target font.
[0029] The sending module is used to send the target text corresponding to the target font to the terminal.
[0030] Seventhly, embodiments of this application provide a font generation apparatus, comprising:
[0031] The sending module is used to send a generation request to the server in response to a user's operation. The generation request is used to request the generation of the target text corresponding to the target font.
[0032] The acquisition module is used to acquire the target text corresponding to the target font sent by the server based on the generation request; the target text corresponding to the target font is obtained in the following way: based on the text image of the reference text of the target font, the style features of the target font are determined, and based on the text images of the target text of multiple preset base fonts, multiple content features of the target text are obtained, the skeleton styles of different base fonts are different; the style features and the multiple content features of the target text are mixed and processed to obtain the target text corresponding to the target font;
[0033] The output module is used to output the target text corresponding to the target font.
[0034] Eighthly, embodiments of this application provide a training apparatus for a font generation model, comprising:
[0035] The building module is used to build a basic model, which is equipped with training parameters. The basic model is used to generate fonts based on text images of target characters in a known font.
[0036] The first training module is used to iteratively adjust the training parameters of the base model using the corresponding training samples until the second preset requirement is met, thereby obtaining the trained base model.
[0037] The adjustment module is used to adjust the base model into a model for font generation based on text images of target texts with multiple preset base fonts, to obtain a font generation model to be trained, wherein the skeleton styles of different base fonts are different;
[0038] The second training module is used to iteratively adjust the training parameters of the font generation model using corresponding training samples until the second preset requirement is met, thereby obtaining the trained font generation model.
[0039] Ninthly, embodiments of this application provide an electronic device, including: a memory and a processor; wherein the memory stores one or more computer instructions, wherein the one or more computer instructions, when executed by the processor, implement the method as described in any one of the first aspects.
[0040] In a tenth aspect, embodiments of this application provide an electronic device, including: a memory and a processor; wherein the memory stores one or more computer instructions, wherein the one or more computer instructions, when executed by the processor, implement the method as described in any one of the second aspects.
[0041] Eleventhly, embodiments of this application provide an electronic device, including: a memory and a processor; wherein the memory stores one or more computer instructions, wherein the one or more computer instructions, when executed by the processor, implement the method as described in any one of the third aspects.
[0042] In a twelfth aspect, embodiments of this application provide an electronic device, including: a memory and a processor; wherein the memory stores one or more computer instructions, wherein the one or more computer instructions, when executed by the processor, implement the method as described in any one of the fourth aspects.
[0043] In a thirteenth aspect, embodiments of this application provide a computer-readable storage medium having a computer program stored thereon that, when executed, implements the method as described in any one of the first aspects.
[0044] In a fourteenth aspect, embodiments of this application provide a computer-readable storage medium having a computer program stored thereon that, when executed, implements the method as described in any one of the second aspects.
[0045] In a fifteenth aspect, embodiments of this application provide a computer-readable storage medium having a computer program stored thereon that, when executed, implements the method as described in any one of the third aspects.
[0046] In a sixteenth aspect, embodiments of this application provide a computer-readable storage medium having a computer program stored thereon that, when executed, implements the method as described in any one of the fourth aspects.
[0047] This application also provides a computer program, which, when executed by a computer, is used to implement the method as described in any of the first aspects.
[0048] This application also provides a computer program, which, when executed by a computer, is used to implement the method described in any of the second aspects.
[0049] This application also provides a computer program that, when executed by a computer, is used to implement the method described in any of the third aspects.
[0050] This application also provides a computer program, which, when executed by a computer, is used to implement the method described in any of the fourth aspects.
[0051] In this embodiment, a text image of a reference text for the target font and text images of target texts from multiple preset base fonts can be obtained. Different base fonts have different skeletal styles. Based on the text image of the reference text, the style features of the target font are determined, and multiple content features of the target text are obtained. The style features and multiple content features of the target text are then mixed to obtain the target text corresponding to the target font. This achieves the generation of target texts corresponding to the target font from text images of target texts from multiple base fonts. Compared to generating texts based on only one known font, this increases the number of fonts referenced for font generation, thus increasing the consistency of the training results and improving the consistency between the skeletal style of the generated text and the skeletal style of the reference text. Attached Figure Description
[0052] To more clearly illustrate the technical solutions in the embodiments of this application or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0053] Figure 1 This is a schematic diagram illustrating an application scenario of an embodiment of this application;
[0054] Figure 2 A schematic flowchart illustrating a font generation method provided in an embodiment of this application;
[0055] Figure 3A Reference text for a target font provided in one embodiment of this application;
[0056] Figure 3B Reference text for the target font provided in another embodiment of this application;
[0057] Figure 4A The font effect of the generated font provided in one embodiment of this application;
[0058] Figure 4B The font effect of the generated font is provided in another embodiment of this application;
[0059] Figure 5 A schematic diagram of the basic model provided in one embodiment of this application;
[0060] Figure 6 A schematic diagram illustrating the calculation of projection distribution loss according to an embodiment of this application;
[0061] Figure 7 A schematic diagram illustrating the determination of multiple base fonts according to an embodiment of this application;
[0062] Figure 8 A schematic diagram illustrating the determination of the weights corresponding to the base font, provided as an embodiment of this application;
[0063] Figure 9 This is a schematic diagram of the structure of a font generation model provided in an embodiment of this application;
[0064] Figure 10 A schematic diagram illustrating an optimized style feature provided in an embodiment of this application;
[0065] Figure 11 A flowchart illustrating a font generation method provided in another embodiment of this application;
[0066] Figure 12 A flowchart illustrating a font generation method provided in yet another embodiment of this application;
[0067] Figure 13 A flowchart illustrating a training method for a font generation model provided in an embodiment of this application;
[0068] Figure 14 This is a schematic diagram of the structure of a font generation device provided in an embodiment of this application;
[0069] Figure 15 This is a schematic diagram of the structure of an electronic device provided in an embodiment of this application;
[0070] Figure 16 This is a schematic diagram of the structure of a font generation device provided in another embodiment of this application;
[0071] Figure 17 A schematic diagram of the structure of an electronic device provided in another embodiment of this application;
[0072] Figure 18 This is a schematic diagram of the structure of a font generation device provided in another embodiment of this application;
[0073] Figure 19 This is a schematic diagram of the structure of an electronic device provided in yet another embodiment of this application;
[0074] Figure 20 A schematic diagram of the structure of a training device for a font generation model provided in an embodiment of this application;
[0075] Figure 21 This is a schematic diagram of the structure of an electronic device provided in another embodiment of this application. Detailed Implementation
[0076] To make the objectives, technical solutions, and advantages of the embodiments of this application clearer, the technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, not all embodiments. Based on the embodiments of this application, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this application.
[0077] The terminology used in the embodiments of this application is for the purpose of describing particular embodiments only and is not intended to limit the application. The singular forms “a,” “said,” and “the” used in the embodiments of this application and the appended claims are also intended to include the plural forms, unless the context clearly indicates otherwise. “Multiple” generally includes at least two, but does not exclude the inclusion of at least one.
[0078] It should be understood that the term "and / or" used in this article is merely a description of the relationship between related objects, indicating that three relationships can exist. For example, A and / or B can represent: A existing alone, A and B existing simultaneously, or B existing alone. Additionally, the character " / " in this article generally indicates that the preceding and following related objects have an "or" relationship.
[0079] Depending on the context, the words “if” or “suppose” as used here can be interpreted as “when” or “in response to determination” or “in response to detection.” Similarly, depending on the context, the phrases “if determination” or “if detection (of the stated condition or event)” can be interpreted as “when determination” or “in response to determination” or “when detection (of the stated condition or event)” or “in response to detection (of the stated condition or event).”
[0080] It should also be noted that the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a product or system comprising a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a product or system. Without further limitations, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the product or system that includes said element.
[0081] Furthermore, the timing of the steps in the following method embodiments is merely an example and not a strict limitation.
[0082] Figure 1 This is a schematic diagram illustrating the application scenario of the method provided in the embodiments of this application, such as... Figure 1As shown, this application scenario may include a terminal 11 and a server 12, which can communicate with each other. The terminal 11 may be, for example, a mobile phone, tablet computer, laptop computer, desktop computer, wearable device, etc. The terminal 11 can execute the font generation method or the font generation model training method provided in this application embodiment. The server 12 provides background services to the terminal 11. The server 12 may be, for example, a physical server, cloud server, etc. The server 12 can also execute the font generation method or the font generation model training method provided in this application embodiment.
[0083] Typically, content features are obtained from the text image of the target text in a known font (e.g., KaiTi), and style features are obtained from the text image of the reference text of the target font. These two types of features are then combined and a decoder is used to generate the target text corresponding to the target font. However, this method has the problem that the skeleton style of the generated text is inconsistent with the skeleton style of the reference text.
[0084] To address the technical problem of inconsistencies between the skeleton style of generated text and the reference font, this embodiment of the application acquires text images of reference text for the target font, as well as text images of target text from multiple preset base fonts. These base fonts have different skeleton styles. Based on the text images of the reference text, the style features of the target font are determined, and multiple content features of the target text are obtained. The style features and the multiple content features of the target text are then mixed to obtain the target text corresponding to the target font. This achieves the generation of target text corresponding to the target font from text images of target text from multiple base fonts. Compared to generation based on only one known font, this increases the number of fonts referenced for font generation, thus increasing the consistency of training results and improving the consistency between the skeleton style of the generated text and the skeleton style of the reference text.
[0085] It should be noted that the skeletons of different characters in the same font are different, while the skeletons of different characters in the same font have the same characteristics. In this embodiment, the characteristics of the skeleton can be referred to as skeleton style.
[0086] It should be noted that the font generation method provided in this application embodiment can be applied to any scenario that requires generating target text based on reference text, including but not limited to advertising creative production, web page design and other scenarios.
[0087] The following detailed description of some embodiments of this application is provided in conjunction with the accompanying drawings. Unless otherwise specified, the following embodiments and features can be combined with each other.
[0088] Figure 2This is a flowchart illustrating a font generation method provided in an embodiment of this application. This embodiment can be applied to... Figure 1 Terminal 11 or server 12 in the middle. For example... Figure 2 As shown, the method in this embodiment may include:
[0089] Step 21: Obtain the text image of the reference text of the target font, as well as the text image of the target text of a variety of preset base fonts, wherein the skeleton styles of different base fonts are different;
[0090] Step 22: Based on the text image of the reference text, determine the style features of the target font, and based on the text image of the target text, obtain multiple content features of the target text.
[0091] Step 23: Mix the style features and multiple content features of the target text to obtain the target text corresponding to the target font.
[0092] In this embodiment of the application, the target font refers to the font to be generated. It can be one or more characters designed in advance by a designer to represent the target font. These one or more characters can be referred to as reference characters. For example, a reference character for a target font might be... Figure 3A As shown, another reference text for the target font can be, for example, as follows: Figure 3B As shown. Target text refers to text whose font needs to be generated as the target font. Based on the text image of the reference text of the target font, and using the font generation method provided in this application embodiment, the target text corresponding to the target font can be generated. Specifically, it can be the text image of the target text of the target font.
[0093] The preset base fonts are all known fonts. Known fonts refer to existing fonts, also known as source fonts. Examples of known fonts include SimSun and KaiTi. Different base fonts have different skeletal styles. In one embodiment, the base fonts can specifically be known fonts with representative skeletal styles, and different base fonts can represent different skeletal styles. Optionally, the base fonts can be determined manually, i.e., manually selecting multiple known fonts from a preset range as base fonts. Alternatively, the base fonts can be determined automatically; an implementation method for automatically determining base fonts can be found in the following description.
[0094] It should be noted that this application does not limit the specific method for obtaining the text images of the reference text and the target text; for example, it can receive text images of the reference text and the target text sent by other devices.
[0095] In this embodiment of the application, after obtaining the text images of the reference text and the target text, the style features of the target font can be determined based on the text image of the reference text, and multiple content features of the target text can be obtained based on the text image of the target text. Then, the style features and multiple content features of the target text are mixed to obtain the target text corresponding to the target font.
[0096] In one embodiment, multiple content features can be fused first, and then the fused result can be mixed with style features to obtain the target text corresponding to the target font. It should be noted that, if the input of the network used for mixing supports this, style features and multiple content features can also be directly mixed to obtain the target text corresponding to the target font.
[0097] Based on this, step 23 may specifically include: fusing multiple content features of the target text to obtain content fusion features; and mixing style features and content fusion features to obtain the target text corresponding to the target font.
[0098] In one embodiment, content fusion features can be obtained by averaging multiple content features. In this case, content features corresponding to different base fonts have the same importance during fusion.
[0099] In another embodiment, content fusion features can be obtained by weighted summation of multiple content features. Based on this, fusing multiple content features of the target text to obtain content fusion features can specifically include: weighted summation of multiple content features of the target text based on the weights corresponding to the base fonts. In this case, the importance of content features corresponding to different base fonts during fusion can vary, and the weights corresponding to the base fonts can be obtained based on the importance of their content features during fusion. In one embodiment, the weights corresponding to the base fonts can be positively correlated with the similarity between the base font and the target font. This ensures that the more similar the base font is to the target font, the more important its corresponding content features are during fusion, enabling the content fusion features to express the skeletal style of the target font, thereby further improving the consistency between the skeletal style of the generated font and the skeletal style of the reference font.
[0100] The weights corresponding to the base fonts can be determined manually, for example, by visually observing the similarity between the base font and the target font to determine the weights corresponding to the base fonts; or, the weights corresponding to the base fonts can be determined automatically, and the specific methods for automatically determining the weights corresponding to the base fonts can be found in the following description.
[0101] In one embodiment, font generation can be performed using a font generation model that includes a style encoder, a content encoder, and a mixer. The style encoder extracts style features from the text image of a reference text, the content encoder extracts content features from the text image of the target text, and the mixer performs feature mixing to generate the target text corresponding to the target font. It should be noted that this application does not limit the specific method of feature mixing; for example, it can use Adaptive Instance Normalization (AdaIN) for mixing.
[0102] Based on this, determining the style features of the target font based on the text image of the reference text includes: inputting the text image of the reference text into a style encoder for processing to determine the style features of the target font; obtaining multiple content features of the target text based on the text image of the target text includes: inputting the text images of the target text from multiple base fonts into a content encoder for processing to obtain multiple content features of the target font; and mixing the style features and content fusion features to obtain the target text corresponding to the target font includes: inputting the style features and content fusion features into a mixer for processing to obtain the target text corresponding to the target font.
[0103] Since font generation models can generate fonts based on content fusion features, they can also be called content fusion modules (CFM). Figure 3A The reference text shown, generated using the font generation model provided in this application, can achieve the following font effect: Figure 4A As shown, based on Figure 3B The reference text shown, generated using the font generation model provided in this application, can achieve the following font effect: Figure 4B As shown.
[0104] In one embodiment, when there is only one reference text, the step of inputting the text image of the reference text into a style encoder for processing to determine the style features of the target font may specifically include: using the style features obtained by inputting the text image of the reference text into the style encoder for processing as the style features of the target font.
[0105] In another embodiment, when there are multiple reference characters for the target font, the step of inputting the text images of the reference characters into a style encoder for processing to determine the style features of the target font may specifically include: taking the average of the multiple style features obtained by inputting the text images of the multiple reference characters into the style encoder for processing as the style features of the target font.
[0106] In another embodiment, a Style Iterative Inference (SII) strategy can be used to obtain the style features of the target font. Specifically, during the inference phase, the style features are iteratively inferred based on initial values to obtain optimized style features. These optimized style features are then used for prediction, thus optimizing the style representation of the target font. This improves the detail information of strokes and edges in the generated text, mitigating problems such as numerous errors and uneven edges in multi-stroke characters. The optimized style features are the style features of the target font.
[0107] Based on this, in one embodiment, the step of inputting the text image of the reference text into the style encoder for processing to determine the style features of the target font may specifically include: inputting the text image of the reference text into the style encoder network for processing to obtain initial values of the style features used for input to the mixer; using corresponding training samples, iteratively adjusting the style features input to the mixer until a preset requirement (hereinafter referred to as the first preset requirement) is met, thereby obtaining the style features of the target font.
[0108] When there is only one reference text, the style feature obtained by inputting the text image of the reference text into the style encoder can be used as the initial value of the style feature; when there are multiple reference texts, the average value of the multiple style features obtained by inputting the text images of the multiple reference texts into the style encoder can be used as the initial value of the style feature.
[0109] The first preset requirement refers to the requirement that the difference between the generated text image and the sample text image must meet. The difference between the generated text image and the sample text image can be represented by the loss value of the loss function (hereinafter referred to as the first loss function). The first preset requirement can be a requirement for the loss value of the first loss function, such as the loss value of the first loss function being less than or equal to the first threshold.
[0110] For example, training samples used for iteratively adjusting the style features of the input mixer may include sample text images of sample text for a base font and sample text images of sample text for a target font. The sample text images of the base font can be input into a content encoder to obtain content features. These content features can then be input into the mixer to obtain generated text images of the target font's sample text. The style features of the input mixer can be iteratively adjusted based on the differences between the generated text images of the target font's sample text and the sample text images of the target font's sample text. The sample text images of the target font's sample text can be pre-designed by a designer.
[0111] In practical applications, the difference between the generated text image of the target font sample text and the sample text image of the target font sample text can be represented by the loss value of the loss function. Based on this, in one embodiment, the style features of the input mixer are iteratively adjusted based on the difference between the generated text image of the target font sample text and the sample text image of the target font sample text until a first preset requirement is met. Specifically, this may include: determining the loss value of the first loss function based on the generated text image of the target font sample text and the sample text image of the target font sample text; and iteratively adjusting the style features of the input mixer until the loss value of the first loss function meets the first preset requirement.
[0112] The first loss function can be constructed based on one or more losses. This application does not limit the loss used to construct the first loss function. For example, when the font generation model is implemented based on Deformable Generative Networks for Unsupervised Font Generation (DG-Font), the loss used to construct the first loss function can include one or more of the four losses used in DG-Font. These four losses can include: 1) Image reconstruction L1 (mean absolute error) loss, used for domain-invariant feature preservation; 2) Content consistency loss, to ensure consistency between the generated and input content images; 3) Adversarial loss, used to generate realistic images; and 4) Deformation offset normalization, to avoid excessive offset in the Feature Deformation SkipConnection (FDSC) module.
[0113] In this embodiment of the application, optionally, a font generation model capable of generating fonts from text images of target characters based on multiple base fonts can be directly constructed and trained; alternatively, a model capable of generating fonts from text images of target characters based on a known font can be constructed and trained first, and then a font generation model capable of generating fonts from text images of target characters based on multiple base fonts can be obtained based on the trained model, thereby simplifying the model training process.
[0114] Based on this, in one embodiment, the font generation model is trained in the following manner: Step A, construct a basic model. Training parameters are set in the basic model, and the basic model is used to generate fonts based on the text images of target characters in a certain known font; Step B, use the corresponding training samples to iteratively adjust the training parameters of the basic model until the preset requirements (hereinafter denoted as the second preset requirements) are met, thereby obtaining a trained font model; Step C, adjust the basic model to a model for generating fonts based on the text images of target characters in multiple base fonts, obtaining a font generation model to be trained; Step D, use the corresponding training samples to iteratively adjust the training parameters of the font generation model until the second preset requirements are met, thereby obtaining a trained font generation model.
[0115] Among them, the second preset requirement refers to the requirement that the difference between the generated text image and the sample text image needs to meet. The difference between the generated text image and the sample text image can be represented by the loss value of a loss function (hereinafter denoted as the second loss function). The second preset requirement can be a requirement for the loss value of the second loss function. For example, the loss value of the second loss function is less than or equal to the second threshold.
[0116] Through Step A and Step B, it is possible to train and obtain a model (denoted as the basic model) for generating fonts based on the text images of target characters in a certain known font. The basic model can learn to transfer text to the target domain by separating content and style. The aforementioned target font can be understood as the font in the target domain, and correspondingly, the aforementioned source font can be understood as the font in the source domain.
[0117] Exemplarily, the structure of the basic model can be as Figure 5 shown. Referring to Figure 5 , the text image of the Chinese character "Chi" in the target font can be input into the style encoder 51 of the basic model for processing to obtain the style vector S1. The text image of the Chinese character "Tong" in a certain existing font (such as regular script) can be input into the content encoder 52 of the basic model for processing to obtain the content feature map C1. The style vector S1 and the content feature map C1 are input into the mixer 53 of the basic model for processing, and the text image of the Chinese character "Tong" in the target font can be obtained. It should be noted that Figure 5 FDSC-1 and FDSC-2 in
[0118] For example, training samples used to iteratively adjust the training parameters of the base model may include sample text images of sample text in a known font and sample text images of sample text in a target font. The sample text images of sample text in a known font can be used to obtain content features, and the sample text images of sample text in the target font can be used to obtain style features. The obtained content features and style features can be used to obtain generated text images of sample text in the target font. The training parameters of the base model can be iteratively adjusted based on the differences between the generated text images of sample text in the target font and the sample text images of sample text in the target font.
[0119] In one embodiment, the training parameters of the base model are iteratively adjusted based on the difference between the generated text image of the sample text of the target font and the sample text image of the sample text of the target font, until a second preset requirement is met. Specifically, this may include: determining the loss value of the second loss function based on the generated text image of the sample text of the target font and the sample text image of the sample text of the target font; and iteratively adjusting the training parameters of the base model until the loss value of the second loss function meets the second preset requirement.
[0120] In one embodiment, the loss used to construct the second loss function may include Projected Character Loss (PCL). Projected Character Loss refers to the similarity between a first pixel value distribution obtained by summing the pixel values of the sample text images of the target font along the target projection direction, and a second pixel value distribution obtained by summing the pixel values of the generated text images of the sample text of the target font along the target projection direction. Since the distributions are sensitive to relative relationships, Projected Character Loss focuses more on the global shape of the text. Therefore, the second loss function constructed using Projected Character Loss can enhance the supervision of the overall glyph of the generated text. For example, Wasserstein distance or Kullback-Leibler divergence can be used to calculate the similarity between pixel value distributions.
[0121] The target projection direction can be one or more. Taking six target projection directions as an example, ... Figure 6 As shown, the projection distribution loss along the projection direction of a target can be obtained by calculating the similarity between the first pixel value distribution and the second pixel value distribution. Figure 6 In PCL_1), the similarity between the first pixel value distribution and the second pixel value distribution along the projection direction of another target is calculated to obtain the projection distribution loss along the projection direction of that other target (e.g., PCL_1). Figure 6For PCL_2 in it, calculate the similarity between the first pixel value distribution and the second pixel value distribution in another target projection direction to obtain the projection distribution loss in this another target projection direction (for example Figure 6 For PCL_3 in it, calculate the similarity between the first pixel value distribution and the second pixel value distribution in another target projection direction to obtain the projection distribution loss in this another target projection direction (for example Figure 6 For PCL_4 in it, calculate the similarity between the first pixel value distribution and the second pixel value distribution in another target projection direction to obtain the projection distribution loss in this another target projection direction (for example Figure 6 For PCL_5 in it, calculate the similarity between the first pixel value distribution and the second pixel value distribution in another target projection direction to obtain the projection distribution loss in this another target projection direction (for example Figure 6 For PCL_6 in it, thus obtain the total projection distribution loss (i.e., Figure 6 PCL in it). It should be noted that Figure 6 The target projection directions in it are only examples.
[0122] Exemplarily, when the base model is implemented based on DG-Font, the loss for constructing the second loss function may further include the aforementioned four losses. It should be noted that the loss for constructing the first loss function and the loss for constructing the second loss function may be the same or different. [[ID=..]]
[0123] Optionally, a trained base model can be used to find the base fonts with representative skeleton styles. In one embodiment, multiple base fonts can be determined in the following manner: Input the text images of the same text in multiple known fonts into the trained base model for processing to obtain multiple content features of the same text; perform clustering on the multiple content features to obtain multiple clusters, and determine multiple base fonts based on the multiple clusters. Among them, each cluster has a corresponding clustering center. Exemplarily, the known font corresponding to the content feature at the clustering center in each cluster can be determined as the base font. Since clustering clusters similar ones together, and dissimilarities can include dissimilarities in skeleton styles, fonts with representative skeleton styles can be selected based on the clustering results.
[0124] Exemplarily, as Figure 7 shown, the text images of the Chinese character 'yong' in multiple known fonts (such as Song typeface, Regular script, Official script, etc.) can be input into the content encoder 52 in the trained base model for processing to obtain the content feature maps of the Chinese character 'yong' in multiple known fonts respectively. Perform clustering processing on the content feature maps of the Chinese character 'yong' in multiple known fonts respectively to obtain multiple clusters, and based on the multiple clusters, obtain multiple base fonts such as Song typeface (song), Official script (li), etc.
[0125] Optionally, a trained base model can be utilized to determine the weights corresponding to the base fonts. In one embodiment, the weights corresponding to multiple base fonts can be determined in the following manner: input the text images of the same character in multiple base fonts and the text image of the same character in the target font into the trained base model for processing, to obtain the content features of the same character in multiple base fonts and the content feature of the same character in the target font respectively; determine the similarity between the content feature of the same character in each base font and the content feature of the same character in the target font; based on the similarities between the content features of the same character in multiple base fonts and the content feature of the same character in the target font respectively, determine the weights corresponding to multiple base fonts respectively.
[0126] Exemplarily, as Figure 8 shown, the text images of the Chinese character "卷" in multiple base fonts and the text image of the Chinese character "卷" in the target font can be input into the content encoder 52 in the trained base model for processing, to obtain the content feature maps of the Chinese character "卷" in multiple bases respectively and the content feature map of the Chinese character "卷" in the target font, and perform weight calculation based on the obtained content feature maps to obtain the content fusion weight W. The content fusion weight W can specifically be a one-dimensional vector, which can include multiple elements, and each element represents the weight corresponding to the corresponding base font.
[0127] Through step C and step D, a font generation model can be obtained based on the trained base model. The obtained font generation model aims to adaptively extract content features by combining the content features of the base fonts, where the adaptiveness is mainly reflected in the adaptive skeleton style.
[0128] The structure of the font generation model can follow the base model, and the content features (the input of the mixer) can be replaced by the weighted sum of the base fonts. Therefore, the base model can be adjusted to a model for font generation based on the text images of the target characters in multiple base fonts, so as to obtain the to-be-trained font generation model. Since the content features generated by the text images of a single known font need to be replaced with the weighted sum of the base fonts, the fused content features can be used to train the font generation model obtained by adjusting the base model.
[0129] Exemplarily, the training samples for iteratively adjusting the training parameters of the base model may include sample text images of sample texts of multiple base fonts and sample text images of sample texts of the target font. Among them, the sample text images of sample texts of multiple base fonts can be used to obtain content fusion features, and the sample text images of sample texts of the target font can be used to obtain style features. The obtained content fusion features and style features can be used to obtain the generated text images of the sample texts of the target font. Based on the difference between the generated text images of the sample texts of the target font and the sample text images of the sample texts of the target font, the training parameters of the font generation model can be iteratively adjusted.
[0130] In one embodiment, based on the difference between the generated text images of the sample texts of the target font and the sample text images of the sample texts of the target font, the training parameters of the font generation model are iteratively adjusted until the second preset requirement is met. Specifically, it may include: determining the loss value of the second loss function based on the generated text images of the sample texts of the target font and the sample text images of the sample texts of the target font; iteratively adjusting the training parameters of the font generation model until the loss value of the second loss function meets the second preset requirement. It should be noted that the relevant description of the second loss function can be referred to the previous description and will not be elaborated here.
[0131] Exemplarily, the structure of the font generation model can be as Figure 9 shown. Referring to Figure 9 , the text image of the Chinese character "Chi" of the target font can be input into the style encoder 91 of the font generation model for processing to obtain the style vector S2. The text images of the Chinese character "Tong" of multiple base fonts can be input into the content encoder 92 of the font generation model for processing to obtain the content feature map matrix C
[0132] , and the content fusion feature C2 can be obtained after fusion based on the content fusion weight W. The style vector S2 and the content fusion feature C2 are input into the mixer 93 of the font generation model for processing, and the text image of the Chinese character "Tong" of the target font can be obtained.
[0132] In Figure 9 the schematic diagram of optimizing the style features based on the shown font generation model can be as Figure 10 shown. Referring to Figure 10 , the sample text images of multiple sample texts (such as the Chinese character "Chi", etc.) of the target font can be input into the style encoder 91 of the font generation model for processing to obtain the initial value S3 of the style feature for input into the mixer 93 of the font generation model. That is, the style feature of the mixer 93 is initialized as S3. Then, using the sample text images of these several sample texts as the supervised samples, calculating the loss with the style vector as the variable and backpropagating the gradient to optimize the style vector, and finally using the optimized style vector for prediction.
[0133] The font generation method provided in this application obtains text images of reference text for a target font, as well as text images of target text in multiple preset base fonts, where different base fonts have different skeletal styles. Based on the text images of the reference text, the style features of the target font are determined, and multiple content features of the target text are obtained based on the text images of the target text. The style features and multiple content features of the target text are mixed to obtain the target text corresponding to the target font. This method realizes the generation of target text corresponding to the target font based on text images of target text in multiple base fonts. Compared with generating based on only one known font, it increases the number of fonts referenced in font generation, thus increasing the consistency of training results and improving the consistency between the skeletal style of the generated text and the skeletal style of the reference text.
[0134] Figure 11 This is a flowchart illustrating a font generation method according to another embodiment of this application. This embodiment can be applied to... Figure 1 Server 12 in the middle. For example... Figure 11 As shown, the method in this embodiment may include:
[0135] Step 111: Obtain the generation request sent by the terminal. The generation request is used to request the generation of the target text corresponding to the target font.
[0136] Step 112: Upon receiving a generation request, obtain the target text corresponding to the target font. The target text corresponding to the target font is obtained in the following way: based on the text image of the reference text of the target font, determine the style features of the target font, and based on the text images of the target text of multiple preset base fonts, obtain multiple content features of the target text. Different base fonts have different skeleton styles. Mix the style features and the multiple content features of the target text to obtain the target text corresponding to the target font.
[0137] Step 113: Send the target text corresponding to the target font to the terminal.
[0138] The generation request may, for example, carry an identifier of the target font and one or more target characters of a known font, to indicate a request to generate these characters of the target font. Of course, in other embodiments, the generation request may also be expressed in other ways to request the generation of the target characters corresponding to the target font.
[0139] In one embodiment, obtaining the target text corresponding to the target font may specifically include: determining the style features of the target font based on the text image of the reference text of the target font, and obtaining multiple content features of the target text based on the text images of the target text of multiple preset base fonts, wherein the skeleton styles of different base fonts are different; and performing mixed processing on the style features and the multiple content features of the target text to obtain the target text corresponding to the target font.
[0140] In another embodiment, obtaining the target text corresponding to the target font may specifically include: receiving the target text corresponding to the target font sent by another device. The other device may determine the style features of the target font based on the text image of the reference text of the target font, and obtain multiple content features of the target text based on the text images of the target text of multiple preset base fonts. Different base fonts have different skeleton styles. The style features and multiple content features of the target text are mixed to obtain the target text corresponding to the target font.
[0141] It should be noted that the specific method for obtaining the target text corresponding to the target font can be referred to the description of the foregoing embodiments, and will not be repeated here.
[0142] After obtaining the target text corresponding to the target font, the target text corresponding to the target font can be sent to the terminal, so that the terminal can output the target font corresponding to the target text, such as displaying or printing it.
[0143] The font generation method provided in this application embodiment obtains a generation request sent by a terminal. The generation request requests the generation of target text corresponding to a target font. Upon obtaining the generation request, the target text corresponding to the target font is obtained and sent to the terminal. The target text corresponding to the target font is obtained in the following way: based on the text image of the reference text of the target font, the style features of the target font are determined, and based on the text images of the target text of multiple preset base fonts, multiple content features of the target text are obtained. Different base fonts have different skeleton styles. The style features and multiple content features of the target text are mixed to obtain the target text corresponding to the target font. This realizes that the target text corresponding to the target font returned to the terminal is generated based on the text image of the target text of multiple base fonts, thereby improving the consistency between the skeleton style of the target text obtained by the terminal and the skeleton style of the reference text.
[0144] Figure 12 This is a flowchart illustrating a font generation method according to another embodiment of this application. This embodiment can be applied to... Figure 1 Terminal 11 in the middle. For example... Figure 12 As shown, the method in this embodiment may include:
[0145] Step 121: In response to the user's operation, a generation request is sent to the server. The generation request is used to request the generation of the target text corresponding to the target font.
[0146] Step 122: Obtain the target text corresponding to the target font sent by the server based on the generation request; the target text corresponding to the target font is obtained in the following way: based on the text image of the reference text of the target font, determine the style features of the target font, and based on the text images of the target text of multiple preset base fonts, obtain multiple content features of the target text, the skeleton styles of different base fonts are different; the style features and the multiple content features of the target text are mixed and processed to obtain the target text corresponding to the target font;
[0147] Step 123: Output the target text corresponding to the target font.
[0148] The user's operation can be any type of operation that can represent the user's need to generate the target text corresponding to the target font, such as touch operation or voice operation.
[0149] It should be noted that the specific method for outputting the target text corresponding to the target font can be flexibly implemented as needed. For example, step 123 may specifically include: displaying the target text corresponding to the target font, and / or printing the target text corresponding to the target font. Alternatively, for example, step 123 may specifically include: sending the target text corresponding to the target font to other devices for display and / or printing by those devices.
[0150] It should be noted that, Figure 12 The illustrated embodiment is similar to Figure 11 For the terminal-side implementation corresponding to the illustrated embodiments, and for the specific implementation on the server side, please refer to [link / reference]. Figure 11 The description in the illustrated embodiment.
[0151] The font generation method provided in this application sends a generation request to the server in response to a user's operation, obtains the target text corresponding to the target font sent by the server based on the generation request, and outputs the target text corresponding to the target font. The target text corresponding to the target font is obtained in the following way: based on the text image of the reference text of the target font, the style features of the target font are determined, and based on the text images of the target text of multiple preset base fonts, multiple content features of the target text are obtained. Different base fonts have different skeleton styles. The style features and multiple content features of the target text are mixed and processed to obtain the target text corresponding to the target font. This realizes that the target text corresponding to the target font output by the terminal is generated based on the text image of the target text of multiple base fonts, which improves the consistency between the skeleton style of the output target text and the skeleton style of the reference text.
[0152] Figure 13 This is a flowchart illustrating a training method for a font generation model according to an embodiment of this application. This embodiment can be applied to... Figure 1 Terminal 11 or server 12 in the middle. For example... Figure 11 As shown, the method in this embodiment may include:
[0153] Step 131: Construct a basic model. The basic model contains training parameters and is used to generate fonts based on text images of target characters in a known font.
[0154] Step 132: Using the corresponding training samples, iteratively adjust the training parameters of the basic model until the second preset requirement is met, thereby obtaining the trained basic model.
[0155] Step 133: Adjust the base model to a model for font generation based on text images of target texts with multiple preset base fonts, and obtain the font generation model to be trained, wherein the skeleton styles of different base fonts are different;
[0156] Step 134: Using the corresponding training samples, iteratively adjust the training parameters of the font generation model until the second preset requirement is met, thereby obtaining the trained font generation model.
[0157] It should be noted that for details on the specific methods for training the font generation model, please refer to [link / reference needed]. Figure 2 The relevant descriptions in the illustrated embodiments will not be repeated here.
[0158] The font generation model training method provided in this application embodiment uses corresponding training samples to iteratively adjust the training parameters of a basic model for font generation from text images of target characters based on a known font until a second preset requirement is met, thereby obtaining a trained basic model. The basic model is then adjusted to a model for font generation from internal text images of target characters based on multiple preset base fonts, resulting in a font generation model to be trained. The training parameters of the font generation model are iteratively adjusted using corresponding training samples until the second preset requirement is met, thereby obtaining a trained font generation model. This method simplifies the model training process by first constructing and training a model capable of font generation from text images of target characters based on a known font, and then using this trained model to obtain a font generation model capable of font generation from text images of target characters based on multiple base fonts.
[0159] Figure 14 This is a schematic diagram of the structure of a font generation device provided in an embodiment of this application; see attached drawing. Figure 14 As shown, this embodiment provides a font generation device that can perform the above-described... Figure 2 The font generation method provided in the illustrated embodiment, specifically, the apparatus may include:
[0160] The acquisition module 141 is used to acquire the text image of the reference text of the target font, as well as the text image of the target text of a variety of preset base fonts, wherein the skeleton styles of different base fonts are different;
[0161] Feature module 142 is used to determine the style features of the target font based on the text image of the reference text, and to obtain multiple content features of the target text based on the text image of the target text;
[0162] The mixing module 143 is used to mix the style features and multiple content features of the target text to obtain the target text corresponding to the target font.
[0163] Optionally, the mixing module 143 is specifically used to: fuse multiple content features of the target text to obtain content fusion features; and mix the style features and the content fusion features to obtain the target text corresponding to the target font.
[0164] Optionally, the mixing module 143 is used to fuse multiple content features of the target text to obtain content fusion features, including: weighted summation of multiple content features of the target text based on the weights corresponding to the base font to obtain content fusion features.
[0165] Optionally, the weight corresponding to the base font is positively correlated with the similarity between the base font and the target font.
[0166] Optionally, the feature module 142 is used to determine the style features of the target font based on the text image of the reference text, including: inputting the text image of the reference text into the style encoder in the font generation model for processing, so as to determine the style features of the target font;
[0167] The feature module 142 is used to obtain multiple content features of the target text based on the text image of the target text, including: inputting the text images of the target text of the multiple base fonts into the content encoder in the font generation model for processing to obtain multiple content features of the target font;
[0168] The mixing module 143 is used to mix the style features and the content fusion features to obtain the target text corresponding to the target font, including: inputting the style features and the content fusion features into the mixer in the font generation model for processing to obtain the target text corresponding to the target font.
[0169] Optionally, the feature module 142 is used to input the text image of the reference text into the style encoder of the font generation model for processing to determine the style features of the target font, including: inputting the text image of the reference text into the style encoder for processing to obtain initial values of the style features used to input the mixer; using corresponding training samples, iteratively adjusting the style features input to the mixer until a first preset requirement is met, thereby determining the style features of the target font.
[0170] Optionally, the font generation model is trained in the following manner:
[0171] A basic model is constructed, which is equipped with training parameters. The basic model is used to generate fonts based on text images of target characters in a known font.
[0172] Using the corresponding training samples, the training parameters of the base model are iteratively adjusted until the second preset requirement is met, thereby obtaining the trained base model;
[0173] The base model is adjusted to a model for font generation based on text images of target characters from the various base fonts, resulting in a font generation model to be trained.
[0174] Using the corresponding training samples, the training parameters of the font generation model are iteratively adjusted until the second preset requirement is met, thereby obtaining the trained font generation model.
[0175] Optionally, the second preset requirement is related to the projection distribution loss, which refers to the similarity between a first pixel value distribution obtained by accumulating the pixel values of the sample text image of the sample text of the target font along the target projection direction and a second pixel value distribution obtained by accumulating the pixel values of the generated text image of the sample text of the target font along the target projection direction.
[0176] Optionally, the multiple base fonts are determined as follows: inputting text images of the same character in multiple known fonts into the trained base model for processing to obtain multiple content features of the same character; clustering the multiple content features to obtain multiple clusters, and determining the multiple base fonts based on the multiple clusters.
[0177] Figure 14 The device shown can perform Figure 2 The method provided in the illustrated embodiment, for parts not described in detail in this embodiment, can be referred to the [examples / descriptions]. Figure 2 The relevant descriptions of the illustrated embodiments are provided below. For the execution process and technical effects of this technical solution, please refer to [link / reference]. Figure 2 The descriptions in the illustrated embodiments will not be repeated here.
[0178] In one possible implementation, Figure 14 The structure of the device shown can be implemented as an electronic device. For example... Figure 15 As shown, the electronic device may include a processor 151 and a memory 152. The memory 152 stores data that supports the controller in performing the above-described functions. Figure 2 The program of the method provided in the illustrated embodiment, processor 151 is configured to execute a program stored in memory 152.
[0179] The program includes one or more computer instructions, wherein when executed by processor 151, the one or more computer instructions can perform the following steps:
[0180] Obtain text images of reference text for the target font, as well as text images of target text for multiple preset base fonts, where the skeleton styles of different base fonts are different;
[0181] Based on the text image of the reference text, the style features of the target font are determined, and based on the text image of the target text, multiple content features of the target text are obtained.
[0182] The style features and multiple content features of the target text are mixed to obtain the target text corresponding to the target font.
[0183] Optionally, processor 151 is also used to perform the aforementioned Figure 2All or part of the steps in the illustrated embodiments.
[0184] The structure of the electronic device may also include a communication interface 153 for communication between the electronic device and other devices or communication networks.
[0185] Figure 16 This is a schematic diagram of the structure of a font generation device provided in another embodiment of this application; see attached diagram. Figure 14 As shown, this embodiment provides a font generation device that can perform the above-described... Figure 11 The font generation method provided in the illustrated embodiment, specifically, the apparatus may include:
[0186] The acquisition module 161 is used to acquire the generation request sent by the terminal, wherein the generation request is used to request the generation of the target text corresponding to the target font;
[0187] The obtaining module 162 is used to obtain the target text corresponding to the target font when the generation request is received; the target text corresponding to the target font is obtained in the following way: based on the text image of the reference text of the target font, the style features of the target font are determined, and based on the text images of the target text of multiple preset base fonts, multiple content features of the target text are obtained, and the skeleton styles of different base fonts are different; the style features and the multiple content features of the target text are mixed to obtain the target text corresponding to the target font;
[0188] The sending module 163 is used to send the target text corresponding to the target font to the terminal.
[0189] Figure 16 The device shown can perform Figure 11 The method provided in the illustrated embodiment, for parts not described in detail in this embodiment, can be referred to the [examples / descriptions]. Figure 11 The relevant descriptions of the illustrated embodiments are provided below. For the execution process and technical effects of this technical solution, please refer to [link / reference]. Figure 11 The descriptions in the illustrated embodiments will not be repeated here.
[0190] In one possible implementation, Figure 16 The structure of the device shown can be implemented as an electronic device, specifically as a server. For example... Figure 17 As shown, the electronic device may include a processor 171 and a memory 172. The memory 172 stores data that supports the controller in performing the above-described functions. Figure 11 The program of the method provided in the illustrated embodiment, processor 171 is configured to execute a program stored in memory 172.
[0191] The program includes one or more computer instructions, wherein when executed by processor 171, the one or more computer instructions can perform the following steps:
[0192] Obtain the generation request sent by the terminal, the generation request being used to request the generation of the target text corresponding to the target font;
[0193] Upon receiving the generation request, the target text corresponding to the target font is obtained. The target text corresponding to the target font is obtained in the following way: based on the text image of the reference text of the target font, the style features of the target font are determined, and based on the text images of the target text of multiple preset base fonts, multiple content features of the target text are obtained, with different skeleton styles for different base fonts; the style features and the multiple content features of the target text are mixed to obtain the target text corresponding to the target font.
[0194] Send the target text corresponding to the target font to the terminal.
[0195] Optionally, processor 171 is also used to perform the aforementioned Figure 11 All or part of the steps in the illustrated embodiments.
[0196] The structure of the electronic device may also include a communication interface 173 for communication between the electronic device and other devices or communication networks.
[0197] Figure 18 This is a schematic diagram of the structure of a font generation device provided in another embodiment of this application; see attached drawing. Figure 18 As shown, this embodiment provides a font generation device that can perform the above-described... Figure 12 The font generation method provided in the illustrated embodiment, specifically, the apparatus may include:
[0198] Sending module 181 is used to send a generation request to the server in response to a user's operation, the generation request being used to request the generation of target text corresponding to the target font;
[0199] The acquisition module 182 is used to acquire the target text corresponding to the target font sent by the server based on the generation request; the target text corresponding to the target font is obtained in the following way: based on the text image of the reference text of the target font, the style features of the target font are determined, and based on the text images of the target text of multiple preset base fonts, multiple content features of the target text are obtained, and the skeleton styles of different base fonts are different; the style features and the multiple content features of the target text are mixed and processed to obtain the target text corresponding to the target font;
[0200] The output module 183 is used to output the target text corresponding to the target font.
[0201] Figure 18 The device shown can perform Figure 12 The method provided in the illustrated embodiment, for parts not described in detail in this embodiment, can be referred to the [examples / descriptions]. Figure 12 The relevant descriptions of the illustrated embodiments are provided below. For the execution process and technical effects of this technical solution, please refer to [link / reference]. Figure 12 The descriptions in the illustrated embodiments will not be repeated here.
[0202] In one possible implementation, Figure 18 The structure of the device shown can be implemented as an electronic device, specifically as a terminal. For example... Figure 19 As shown, the electronic device may include a processor 191 and a memory 192. The memory 192 stores data that supports the controller in performing the above-described functions. Figure 12 The program of the method provided in the illustrated embodiment, processor 191 is configured to execute a program stored in memory 192.
[0203] The program includes one or more computer instructions, wherein when executed by processor 191, the one or more computer instructions can perform the following steps:
[0204] In response to a user's action, a generation request is sent to the server, the generation request being used to request the generation of the target text corresponding to the target font;
[0205] The target text corresponding to the target font sent by the server based on the generation request is obtained. The target text corresponding to the target font is obtained in the following way: based on the text image of the reference text of the target font, the style features of the target font are determined, and based on the text images of the target text of multiple preset base fonts, multiple content features of the target text are obtained, and the skeleton styles of different base fonts are different; the style features and the multiple content features of the target text are mixed to obtain the target text corresponding to the target font.
[0206] Output the target text corresponding to the target font.
[0207] Optionally, processor 191 is also used to perform the aforementioned Figure 12 All or part of the steps in the illustrated embodiments.
[0208] The structure of the electronic device may also include a communication interface 193 for communication between the electronic device and other devices or communication networks.
[0209] Figure 20 This is a schematic diagram of the structure of a training device for a font generation model provided in an embodiment of this application; see attached diagram. Figure 20As shown, this embodiment provides a training device for a font generation model, which can perform the above-described... Figure 13 The training method for the font generation model provided in the illustrated embodiment, specifically, the apparatus may include:
[0210] The construction module 201 is used to construct a basic model, which is equipped with training parameters. The basic model is used to generate fonts based on the text image of a target character in a known font.
[0211] The first training module 202 is used to iteratively adjust the training parameters of the base model using corresponding training samples until the second preset requirement is met, thereby obtaining the trained base model.
[0212] The adjustment module 203 is used to adjust the base model into a model for font generation based on text images of target texts with multiple preset base fonts, to obtain a font generation model to be trained, wherein the skeleton styles of different base fonts are different.
[0213] The second training module 204 is used to iteratively adjust the training parameters of the font generation model using corresponding training samples until the second preset requirement is met, thereby obtaining the trained font generation model.
[0214] Figure 20 The device shown can perform Figure 13 The method provided in the illustrated embodiment, for parts not described in detail in this embodiment, can be referred to the [examples / descriptions]. Figure 13 The relevant descriptions of the illustrated embodiments are provided below. For the execution process and technical effects of this technical solution, please refer to [link / reference]. Figure 13 The descriptions in the illustrated embodiments will not be repeated here.
[0215] In one possible implementation, Figure 20 The structure of the device shown can be implemented as an electronic device. For example... Figure 21 As shown, the electronic device may include a processor 211 and a memory 212. The memory 212 stores data that supports the controller in performing the above-described functions. Figure 13 The program of the method provided in the illustrated embodiment, processor 211 is configured to execute the program stored in memory 212.
[0216] The program includes one or more computer instructions, wherein the one or more computer instructions, when executed by processor 211, can perform the following steps:
[0217] A basic model is constructed, which is equipped with training parameters. The basic model is used to generate fonts based on text images of target characters in a known font.
[0218] Using the corresponding training samples, the training parameters of the base model are iteratively adjusted until the second preset requirement is met, thereby obtaining the trained base model;
[0219] The base model is adjusted to a model for font generation based on text images of target texts with multiple preset base fonts, resulting in a font generation model to be trained, wherein the skeleton styles of different base fonts are different.
[0220] Using the corresponding training samples, the training parameters of the font generation model are iteratively adjusted until the second preset requirement is met, thereby obtaining the trained font generation model.
[0221] Optionally, the processor 211 is also used to perform the aforementioned Figure 13 All or part of the steps in the illustrated embodiments.
[0222] The structure of the electronic device may also include a communication interface 213 for communication between the electronic device and other devices or communication networks.
[0223] This application also provides a computer-readable storage medium having a computer program stored thereon, which, when executed, performs the following... Figure 2 The method described in the illustrated embodiment.
[0224] This application also provides a computer-readable storage medium having a computer program stored thereon, which, when executed, performs the following... Figure 11 The method described in the illustrated embodiment.
[0225] This application also provides a computer-readable storage medium having a computer program stored thereon, which, when executed, performs the following... Figure 12 The method described in the illustrated embodiment.
[0226] This application also provides a computer-readable storage medium having a computer program stored thereon, which, when executed, performs the following... Figure 13 The method described in the illustrated embodiment.
[0227] The device embodiments described above are merely illustrative. The units described as separate components may or may not be physically separate, and the components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the modules can be selected to achieve the purpose of this embodiment according to actual needs. Those skilled in the art can understand and implement this without any creative effort.
[0228] Through the above description of the embodiments, those skilled in the art can clearly understand that each embodiment can be implemented by means of a necessary general-purpose hardware platform, or by a combination of hardware and software. Based on this understanding, the above technical solutions, in essence or the part that contributes to the prior art, can be embodied in the form of a computer product. This application can take the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.
[0229] This application is described with reference to flowchart illustrations and / or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of this application. It will be understood that each block of the flowchart illustrations and / or block diagrams, and combinations of blocks in the flowchart illustrations and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, special-purpose computer, embedded processor, or other programmable device to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable device, generate instructions for implementing the flowchart... Figure 1 One or more processes and / or boxes Figure 1 A device that provides the functions specified in one or more boxes.
[0230] These computer program instructions may also be stored in a computer-readable storage medium that can direct a computer or other programmable device to function in a particular manner, such that the instructions stored in the computer-readable storage medium produce an article of manufacture including instruction means, which are implemented in a process Figure 1 One or more processes and / or boxes Figure 1 The function specified in one or more boxes.
[0231] These computer program instructions may also be loaded onto a computer or other programmable device to cause a series of operational steps to be performed on the computer or other programmable device to produce a computer-implemented process, thereby providing instructions that execute on the computer or other programmable device for implementing the process. Figure 1 One or more processes and / or boxes Figure 1 The steps of the function specified in one or more boxes.
[0232] In a typical configuration, a computing device includes one or more processors (CPU), input / output interfaces, network interfaces, and memory.
[0233] Memory may include non-persistent storage in computer-readable media, such as random access memory (RAM) and / or non-volatile memory, such as read-only memory (ROM) or flash RAM. Memory is an example of computer-readable media.
[0234] Computer-readable media includes both permanent and non-permanent, removable and non-removable media that can store information by any method or technology. Information can be computer-readable instructions, linked lists, modules of programs, or other data. Examples of computer storage media include, but are not limited to, phase-change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technologies, CD-ROM, digital versatile optical disc (DVD) or other optical storage, magnetic tape, magnetic magnetic disk storage or other magnetic storage devices, or any other non-transferable medium that can store information accessible by a computing device. As defined herein, computer-readable media does not include transient computer-readable media, such as modulated data signals and carrier waves.
[0235] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of this application, and are not intended to limit them. Although this application has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some or all of the technical features therein. Such modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the scope of the technical solutions of the embodiments of this application.
Claims
1. A font generation method, characterized in that, include: Obtain text images of reference text for the target font, as well as text images of target text for multiple preset base fonts, where the skeleton styles of different base fonts are different; Based on the text image of the reference text, the style features of the target font are determined, and based on the text image of the target text, multiple content features of the target text are obtained. Based on the weights corresponding to the base font, multiple content features of the target text are weighted and summed to obtain content fusion features; The weight corresponding to the base font is positively correlated with the similarity between the base font and the target font; The style features and the content fusion features are mixed to obtain the target text corresponding to the target font.
2. The method according to claim 1, characterized in that, The step of determining the style features of the target font based on the text image of the reference text includes: inputting the text image of the reference text into the style encoder in the font generation model for processing, so as to determine the style features of the target font; The process of obtaining multiple content features of the target text based on the text image of the target text includes: inputting the text images of the target text of the various base fonts into the content encoder in the font generation model for processing to obtain multiple content features of the target font; The step of mixing the style features and the content fusion features to obtain the target text corresponding to the target font includes: inputting the style features and the content fusion features into the mixer in the font generation model for processing to obtain the target text corresponding to the target font.
3. The method according to claim 2, characterized in that, The step of inputting the text image of the reference text into the style encoder of the font generation model for processing to determine the style features of the target font includes: The text image of the reference text is input into the style encoder for processing to obtain initial values of the style features used to input the mixer; Using the corresponding training samples, the style features input to the mixer are iteratively adjusted until the first preset requirement is met, thereby determining the style features of the target font.
4. The method according to claim 2, characterized in that, The font generation model was trained in the following manner: A basic model is constructed, which is equipped with training parameters. The basic model is used to generate fonts based on text images of target characters in a known font. Using the corresponding training samples, the training parameters of the base model are iteratively adjusted until the second preset requirement is met, thereby obtaining the trained base model; The base model is adjusted to a model for font generation based on text images of target characters from the various base fonts, resulting in a font generation model to be trained. Using the corresponding training samples, the training parameters of the font generation model are iteratively adjusted until the second preset requirement is met, thereby obtaining the trained font generation model.
5. The method according to claim 4, characterized in that, The second preset requirement is related to the projection distribution loss, which refers to the similarity between the first pixel value distribution obtained by accumulating the pixel values of the sample text image of the sample text of the target font along the target projection direction and the second pixel value distribution obtained by accumulating the pixel values of the generated text image of the sample text of the target font along the target projection direction.
6. The method according to claim 4, characterized in that, The various base fonts are determined in the following way: The text images of the same character in multiple known fonts are input into the base model obtained through training and processed to obtain multiple content features of the same character; Multiple content features are clustered to obtain multiple clusters, and multiple base fonts are determined based on the multiple clusters.
7. A font generation method, characterized in that, include: Obtain the generation request sent by the terminal, the generation request being used to request the generation of the target text corresponding to the target font; Upon receiving the generation request, the target text corresponding to the target font is obtained; the target text corresponding to the target font is obtained in the following way: based on the text image of the reference text of the target font, the style features of the target font are determined, and based on the text images of the target text of multiple preset base fonts, multiple content features of the target text are obtained, and the skeleton styles of different base fonts are different; Based on the weights corresponding to the base font, multiple content features of the target text are weighted and summed to obtain content fusion features; The weight corresponding to the base font is positively correlated with the similarity between the base font and the target font; The style features and the content fusion features are combined to obtain the target text corresponding to the target font; Send the target text corresponding to the target font to the terminal.
8. A font generation method, characterized in that, include: In response to a user's action, a generation request is sent to the server, the generation request being used to request the generation of the target text corresponding to the target font; Obtain the target text corresponding to the target font sent by the server based on the generation request; the target text corresponding to the target font is obtained in the following way: based on the text image of the reference text of the target font, determine the style features of the target font, and based on the text images of the target text of multiple preset base fonts, obtain multiple content features of the target text, and the skeleton styles of different base fonts are different; Based on the weights corresponding to the base font, multiple content features of the target text are weighted and summed to obtain content fusion features; The weight corresponding to the base font is positively correlated with the similarity between the base font and the target font; The style features and the content fusion features are combined to obtain the target text corresponding to the target font; Output the target text corresponding to the target font.
9. A training method for a font generation model, characterized in that, include: A basic model is constructed, which is equipped with training parameters. The basic model is used to generate fonts based on text images of target characters in a known font. Using the corresponding training samples, the training parameters of the base model are iteratively adjusted until the second preset requirement is met, thereby obtaining the trained base model; The base model is adjusted to generate fonts from text images of target text based on a set of preset base fonts, resulting in a font generation model to be trained. The different base fonts have different skeletal styles. The font generation from text images of target text based on the preset base fonts includes: determining the style features of the target font based on text images of reference text; obtaining multiple content features of the target text based on text images of the target text; weighted summing of the multiple content features of the target text based on the weights corresponding to the base fonts to obtain content fusion features; the weights corresponding to the base fonts are positively correlated with the similarity between the base font and the target font; and the style features and content fusion features are mixed to obtain the target text corresponding to the target font. Using the corresponding training samples, the training parameters of the font generation model are iteratively adjusted until the second preset requirement is met, thereby obtaining the trained font generation model.
10. A font generation device, characterized in that, include: The acquisition module is used to acquire text images of reference text for the target font, as well as text images of target text for multiple preset base fonts, where the skeleton styles of different base fonts are different; The feature module is used to determine the style features of the target font based on the text image of the reference text, and to obtain multiple content features of the target text based on the text image of the target text. The fusion module is used to perform a weighted summation of multiple content features of the target text based on the weights corresponding to the base font, so as to obtain content fusion features; The weight corresponding to the base font is positively correlated with the similarity between the base font and the target font; The style features and the content fusion features are mixed to obtain the target text corresponding to the target font.
11. A font generation device, characterized in that, include: The acquisition module is used to acquire the generation request sent by the terminal, wherein the generation request is used to request the generation of the target text corresponding to the target font; The acquisition module is used to obtain the target text corresponding to the target font when the generation request is received; the target text corresponding to the target font is obtained in the following way: based on the text image of the reference text of the target font, the style features of the target font are determined, and based on the text images of the target text of a variety of preset base fonts, multiple content features of the target text are obtained, and the skeleton styles of different base fonts are different; Based on the weights corresponding to the base font, multiple content features of the target text are weighted and summed to obtain content fusion features; The weight corresponding to the base font is positively correlated with the similarity between the base font and the target font; The style features and the content fusion features are combined to obtain the target text corresponding to the target font; The sending module is used to send the target text corresponding to the target font to the terminal.
12. A font generation device, characterized in that, include: The sending module is used to send a generation request to the server in response to a user's operation. The generation request is used to request the generation of the target text corresponding to the target font. The acquisition module is used to acquire the target text corresponding to the target font sent by the server based on the generation request; the target text corresponding to the target font is obtained in the following way: based on the text image of the reference text of the target font, the style features of the target font are determined, and based on the text images of the target text of multiple preset base fonts, multiple content features of the target text are obtained, and the skeleton styles of different base fonts are different; Based on the weights corresponding to the base font, multiple content features of the target text are weighted and summed to obtain content fusion features; The weight corresponding to the base font is positively correlated with the similarity between the base font and the target font; The style features and the content fusion features are combined to obtain the target text corresponding to the target font; The output module is used to output the target text corresponding to the target font.
13. A training device for a font generation model, characterized in that, include: The building module is used to build a basic model, which is equipped with training parameters. The basic model is used to generate fonts based on text images of target characters in a known font. The first training module is used to iteratively adjust the training parameters of the base model using the corresponding training samples until the second preset requirement is met, thereby obtaining the trained base model. An adjustment module is used to adjust the base model into a model for font generation based on text images of target text from multiple preset base fonts, resulting in a font generation model to be trained. The different base fonts have different skeletal styles. The font generation based on text images of target text from multiple preset base fonts includes: determining the style features of the target font based on text images of reference text; obtaining multiple content features of the target text based on text images of the target text; weighted summing of the multiple content features of the target text based on the weights corresponding to the base fonts to obtain content fusion features; the weights corresponding to the base fonts are positively correlated with the similarity between the base fonts and the target font; and mixing the style features and the content fusion features to obtain the target text corresponding to the target font. The second training module is used to iteratively adjust the training parameters of the font generation model using corresponding training samples until the second preset requirement is met, thereby obtaining the trained font generation model.
14. An electronic device, characterized in that, include: A memory and a processor; wherein the memory stores one or more computer instructions, wherein the one or more computer instructions, when executed by the processor, implement the method as described in any one of claims 1 to 9.
15. A computer-readable storage medium, characterized in that, It stores a computer program that, when executed, implements the method as described in any one of claims 1 to 9.
Citation Information
Patent Citations
Font generation method and device based on multi-task discriminator generative adversarial network
CN113095038A