Font generation method and device, electronic equipment and storage medium
By using a sparse block diagonal coupling model to perform sparse low-rank decomposition and determinant decomposition on font vector blocks, the consistency and speed issues of font generation in existing technologies are resolved, and efficient generation of fonts with consistent styles is achieved.
Patent Information
- Application Number
- CN202511061447.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-07-30
- Publication Date
- 2025-11-07
AI Technical Summary
Existing technologies struggle to accurately and quickly generate highly consistent and structured fonts, especially neural networks that utilize adversarial networks and flow networks, which suffer from insufficient consistency and high computational resource requirements during the generation process.
A sparse block diagonal coupling model is used to perform sparse low-rank decomposition and determinant decomposition on the original font vector blocks. The target font is generated by block processing and splicing of sparse low-rank matrices.
It enables accurate and rapid generation of fonts with consistent styles, reduces computing resource requirements, and improves generation speed and consistency.
Smart Images

Figure CN120911403A_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the technical field of font generation, and is suitable for the financial field, and particularly relates to a font generation method and device, an electronic device and a storage medium. BACKGROUND
[0002] Font generation refers to generating characters with specific styles, which can be used in various application scenarios, such as generating artistic characters on insurance product promotional posters. In the method of font generation, one method is to use a neural network of a non-flow model such as an adversarial network or a diffusion network, but due to the lack of explicit modeling ability of likelihood calculation, it is difficult to control the consistency of the generated font, and it cannot be responsible for tasks that require highly consistent and structured font generation. Another method is to use a neural network with a flow network structure, but due to the insufficient ability of the flow network to capture local features and the high computational power requirement of calculating the determinant, the generation process is not accurate enough and is relatively slow. Therefore, how to accurately and quickly generate fonts has become a problem to be solved. SUMMARY
[0003] The main purpose of the embodiments of the present application is to provide a font generation method and device, an electronic device and a storage medium, which can accurately and quickly generate fonts.
[0004] To achieve the above-mentioned purpose, the first aspect of the embodiments of the present application provides a font generation method, which comprises:
[0005] obtaining an original font;
[0006] performing block processing on the original font to obtain an original font vector block;
[0007] performing sparse low-rank decomposition on the original font vector block through a preset target sparse block diagonal coupling model to obtain a sparse low-rank matrix;
[0008] performing splicing on the sparse low-rank matrix to obtain a font sparse low-rank matrix;
[0009] performing determinant decomposition on the target sparse block diagonal coupling model to obtain a determinant matrix;
[0010] generating a font according to the determinant matrix and the font sparse low-rank matrix to obtain a target font.
[0011] In some embodiments, the target sparse block diagonal coupling model comprises at least one target sparse block diagonal coupling layer, and each target sparse block diagonal coupling layer comprises a first low-rank factor matrix, a second low-rank factor matrix, a dense basis matrix, a binary mask matrix and a bias term; and the sparse low-rank decomposition on the original font vector block through the preset target sparse block diagonal coupling model to obtain a sparse low-rank matrix comprises:
[0012] performing low-rank decomposition on the original font vector block through the first low-rank factor matrix and the second low-rank factor matrix to obtain a font low-rank matrix;
[0013] performing sparse decomposition on the original font vector block through the dense base matrix and the binary mask matrix to obtain a font sparse matrix;
[0014] obtaining a sum of the font low-rank matrix, the font sparse matrix and the bias term to obtain the sparse low-rank matrix.
[0015] In some embodiments, before the sparse low-rank decomposition on the original font vector block through the preset target sparse block diagonal coupling model to obtain a sparse low-rank matrix, the method further comprises pre-training the target sparse block diagonal coupling model, specifically comprising:
[0016] obtaining a sample font vector block of a sample font and a preset sparse block diagonal coupling model; wherein the preset sparse block diagonal coupling model comprises a preset sparse block diagonal coupling layer;
[0017] performing sparse low-rank decomposition on the sample font vector block through the preset sparse block diagonal coupling layer to obtain a sample decomposition matrix;
[0018] performing font generation through the sample decomposition matrix to obtain a predicted font;
[0019] training the preset sparse block diagonal coupling layer of the preset sparse block diagonal coupling model according to the predicted font and the sample font to obtain the target sparse block diagonal coupling model.
[0020] In some embodiments, the training of the preset sparse block diagonal coupling layer of the preset sparse block diagonal coupling model according to the predicted font and the sample font to obtain the target sparse block diagonal coupling model comprises:
[0021] performing loss value calculation according to the predicted font and the sample font to obtain a model loss value;
[0022] performing adaptive update on the binary mask matrix of the preset sparse block diagonal coupling layer according to the model loss value and the dense base matrix of the preset sparse block diagonal coupling layer;
[0023] performing gradient descent update on the first low-rank factor matrix, the second low-rank factor matrix, the dense base matrix and the bias term of the preset sparse block diagonal coupling layer according to the model loss value.
[0024] In some embodiments, the adaptive updating of the binary mask matrix of the preset sparse block-diagonal coupled layer according to the model loss value and the dense base matrix of the preset sparse block-diagonal coupled layer comprises:
[0025] The gradient information threshold calculation of the dense base matrix of the preset sparse block-diagonal coupled layer according to the model loss value is performed to obtain a gradient threshold value;
[0026] The updating matrix is calculated according to the gradient threshold value and the dense base matrix of the preset sparse block-diagonal coupled layer;
[0027] The binary mask matrix of the preset sparse block-diagonal coupled layer is replaced according to the updating matrix.
[0028] In some embodiments, the determinant decomposition of the target sparse block-diagonal coupled model comprises:
[0029] For each target sparse block-diagonal coupled layer, the block determinant is calculated according to the first low-rank factor matrix, the second low-rank factor matrix, the dense base matrix and the binary mask matrix;
[0030] The product of each block determinant is obtained to obtain the determinant matrix.
[0031] In some embodiments, the block processing of the original font to obtain the original font vector block comprises:
[0032] The original font is vector mapped to obtain an original font vector;
[0033] The original font vector is clustered to obtain the original font vector block.
[0034] To achieve the above-mentioned purposes, a second aspect of the embodiment of the present application proposes a font generation device, the device comprises:
[0035] An acquisition module is configured to acquire an original font;
[0036] A block processing module is configured to perform block processing on the original font to obtain an original font vector block;
[0037] A matrix decomposition module is configured to perform sparse low-rank decomposition on the original font vector block by using a preset target sparse block-diagonal coupled model to obtain a sparse low-rank matrix;
[0038] A matrix splicing module is configured to splice the sparse low-rank matrix to obtain a font sparse low-rank matrix;
[0039] a determinant decomposition module, configured to perform determinant decomposition on the target sparse block diagonal coupling model to obtain a determinant matrix;
[0040] a font generation module, configured to perform font generation based on the determinant matrix and the font sparse low-rank matrix to obtain a target font.
[0041] To achieve the above object, a third aspect of the embodiments of the present application provides an electronic device, which comprises a memory and a processor, the memory stores a computer program, and the processor implements the method of the first aspect when executing the computer program.
[0042] To achieve the above object, a fourth aspect of the embodiments of the present application provides a computer readable storage medium, which stores a computer program, and the computer program is executed by a processor to implement the method of the first aspect.
[0043] The font generation method and device, electronic device and storage medium provided by the present application obtain an original font, then perform block processing on the original font to obtain an original font vector block. Then, the original font vector block is subjected to sparse low-rank decomposition through a preset target sparse block diagonal coupling model to obtain a sparse low-rank matrix. Next, the sparse low-rank matrix is spliced into a font sparse low-rank matrix, and the target sparse block diagonal coupling model is further subjected to determinant decomposition to obtain a determinant matrix. Finally, font generation is performed based on the determinant matrix and the font sparse low-rank matrix to obtain a target font. In this way, the embodiments of the present application convert font information into a vector block by obtaining an original font and performing block processing thereon, extract the low-rank structure of the font by performing sparse low-rank decomposition on the target sparse block diagonal coupling model based on a flow model, reduce redundant information, on the one hand, utilize the realistic modeling capability of the flow model that can use likelihood calculation to enable subsequent generation of fonts with consistent styles, on the other hand, convert the font into a vector block in the form of blocks to enable the network to capture local features of the font. Then, the target sparse block diagonal coupling model is subjected to determinant decomposition to reduce the computing power required for calculating the determinant and improve the speed of generating the font. Finally, font generation is performed based on the determinant matrix and the font sparse low-rank matrix to obtain a target font, which realizes accurate and rapid generation of fonts with consistent styles. BRIEF DESCRIPTION OF DRAWINGS
[0044] Figure 1 is a flowchart of the font generation method provided by the embodiments of the present application;
[0045] Figure 2 is a flowchart of step S102 in Figure 1
[0046] Figure 3 is a flow chart of the font generation method provided by another embodiment of the present application;
[0047] Figure 4 is Figure 3 is a flow chart of step S304 in
[0048] Figure 5 is Figure 4 is a flow chart of step S402 in
[0049] Figure 6 is Figure 1 is a flow chart of step S103 in
[0050] Figure 7 is Figure 1 is a flow chart of step S105 in
[0051] Figure 8 is a structural schematic diagram of the font generation apparatus provided by an embodiment of the present application;
[0052] Figure 9 is a hardware structural schematic diagram of the electronic device provided by an embodiment of the present application. DETAILED DESCRIPTION
[0053] In order to make the objectives, technical solutions and advantages of the present application clearer, the present application is further described in detail below with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application, and are not intended to limit the present application.
[0054] It should be noted that although the functional modules are divided in the apparatus schematic diagram, and the logical order is shown in the flow chart, in some cases, the steps shown or described can be executed in a manner different from the module division in the apparatus or the order in the flow chart. The terms "first", "second", etc. in the specification and claims and the above-described drawings are used to distinguish similar objects, and do not necessarily describe a specific order or sequence.
[0055] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as commonly understood by one of ordinary skill in the art to which the present application belongs. The terms used herein are only for the purpose of describing the embodiments of the present application, and are not intended to limit the present application.
[0056] Font generation refers to generating characters with a specific style, which can be used in various application scenarios, for example, artistic characters can be generated on insurance product promotional posters. In the method of font generation, one method is to use a neural network of a non-flow model such as an adversarial network or a diffusion network, but due to the lack of explicit modeling ability of likelihood calculation, it is difficult to control the consistency of the generated font, and it cannot be responsible for tasks that require highly consistent and structured font generation. Another method is to use a neural network with a flow network structure, but due to the insufficient ability of the flow network to capture local features and the high computing power requirement of calculating the determinant, the generation process is not accurate enough and is relatively slow. Therefore, how to accurately and quickly generate font has become a problem to be solved.
[0057] Based on this, the embodiment of the present application provides a font generation method and device, electronic equipment and storage medium, aiming to accurately and quickly generate font.
[0058] The font generation method and device, electronic equipment and storage medium provided by the embodiment of the present application are specifically explained by the following embodiment, first, the font generation method in the embodiment of the present application is described.
[0059] The embodiment of the present application can acquire and process related data based on artificial intelligence technology. Among them, artificial intelligence (Artificial Intelligence, AI) is to use digital computers or digital computer controlled machines to simulate, extend and expand human intelligence, perceive environment, acquire knowledge and use knowledge to obtain the best results. Theory, method, technology and application system.
[0060] The basic technology of artificial intelligence generally includes technologies such as sensors, special artificial intelligence chips, cloud computing, distributed storage, big data processing technology, operation / interaction system, mechatronics, etc. Artificial intelligence software technology mainly includes computer vision technology, robot technology, biometric technology, speech processing technology, natural language processing technology, and machine learning / deep learning, etc. Several major directions.
[0061] The font generation method provided by the embodiments of the present application relates to the technical field of font generation and is applicable to the financial field. The font generation method provided by the embodiments of the present application can be applied to a terminal, can be applied to a server end, and can also be software running in a terminal or a server end. In some embodiments, the terminal can be a smart phone, a tablet computer, a notebook computer, a desktop computer, or the like; the server end can be configured as a stand-alone physical server, can be configured as a server cluster or a distributed system formed by multiple physical servers, or can be configured as a cloud server providing basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communication, middleware services, domain name services, security services, CDNs, and big data and artificial intelligence platforms; and the software can be an application that implements the font generation method, but is not limited to the above forms.
[0062] The present application can be used in many general or special computer system environments or configurations. For example: personal computers, server computers, handheld devices or portable devices, tablet devices, multi-processor systems, microprocessor-based systems, set-top boxes, programmable consumer electronics, network PCs, minicomputers, mainframe computers, distributed computing environments including any of the above systems or devices, and the like. The present application can be described in the general context of computer-executable instructions executed by a computer, such as program modules. Generally, program modules include routines, programs, objects, components, data structures, and the like that perform specific tasks or implement specific abstract data types. The present application can also be practiced in a distributed computing environment, in which tasks are performed by remote processing devices connected by a communication network. In a distributed computing environment, program modules can be located in local and remote computer storage media, including storage devices.
[0063] It should be noted that in each specific embodiment of the present application, when relevant processing needs to be performed on data related to the identity or characteristics of the user, such as user information, user behavior data, user history data, and user location information, the user's permission or consent will be obtained first, and the collection, use, and processing of such data will comply with relevant laws, regulations, and standards. In addition, when the embodiments of the present application need to obtain sensitive personal information of the user, the separate permission or separate consent of the user will be obtained through a pop-up window or a jump to a confirmation page, and after obtaining the separate permission or separate consent of the user, the necessary user-related data for enabling the embodiments of the present application to normally operate will be obtained.
[0064] Figure 1 is an optional flowchart of the font generation method provided by the embodiments of the present application, Figure 1 The method in can include but is not limited to steps S101 to S106.
[0065] Step S101, obtaining an original font;
[0066] Step S102, performing block processing on the original font to obtain an original font vector block;
[0067] Step S103, performing sparse low-rank decomposition on the original font vector block through a preset target sparse block diagonal coupling model to obtain a sparse low-rank matrix;
[0068] Step S104, splicing the sparse low-rank matrix to obtain a font sparse low-rank matrix;
[0069] Step S105, performing determinant decomposition on the target sparse block diagonal coupling model to obtain a determinant matrix;
[0070] Step S106, generating a font based on the determinant matrix and the font sparse low-rank matrix to obtain a target font.
[0071] The steps S101 to S106 shown in the embodiments of the present application obtain an original font, then perform block processing on the original font to obtain an original font vector block. Then, sparse low-rank decomposition is performed on the original font vector block through a preset target sparse block diagonal coupling model to obtain a sparse low-rank matrix. Next, the sparse low-rank matrix is spliced into a font sparse low-rank matrix, and further determinant decomposition is performed on the target sparse block diagonal coupling model to obtain a determinant matrix. Finally, font generation is performed based on the determinant matrix and the font sparse low-rank matrix to obtain a target font. In this way, the embodiments of the present application obtain an original font and perform block processing thereon, convert font information into a vector block, perform sparse low-rank decomposition on the target sparse block diagonal coupling model based on a flow model, extract the low-rank structure of the font, reduce redundant information, on the one hand, utilize the realistic modeling capability of the flow model that can use likelihood calculation, so that subsequent font generation can be consistent in style, on the other hand, through the form of block, the font is changed into a vector block, so that the network can capture the local features of the font. Then, determinant decomposition is performed on the target sparse block diagonal coupling model, thereby reducing the computing power required for calculating the determinant and improving the speed of generating the font. Finally, font generation is performed based on the determinant matrix and the font sparse low-rank matrix to obtain a target font, realizing accurate and rapid generation of font with consistent style.
[0072] In step S101 of some embodiments, the original font is a set of given fonts, and the content of the original font can be used to indicate the basis for subsequent font generation. The font form of the original font is not limited, and can be a mixed style input font. For example, the original font can include "Songti" style letters "AB" and "Black" style letters "CD". In the process of subsequent font generation, "ABCD" of the target style will be generated. The data format of the original font can be a vector contour or a raster image.
[0073] Referring to Figure 2 In some embodiments, step S102 can include, but is not limited to, steps S201 to S202:
[0074] In step S201, the original font is vector mapped to obtain an original font vector;
[0075] In step S202, the original font vector is clustered to obtain an original font vector block.
[0076] The steps S201 to S202 shown in the embodiments of the present application, by vector mapping the original font to obtain an original font vector, and then clustering the original font vector to obtain an original font vector block, the original font is converted into a vector block that can be processed by a model. At the same time, by the form of the vector block, the font is decoupled, so that the subsequent target sparse block diagonal coupling model can capture the local features of the font, and improve the information capture ability of the font.
[0077] In step S201 of some embodiments, vector mapping refers to converting the original font (such as a vector contour or a raster image) into a vector form. In implementation, the font contour can be processed by a feature point extraction-based algorithm or a shape descriptor method, thereby obtaining a vector representation of each character.
[0078] In step S202 of some embodiments, clustering refers to dividing the original font vector into different categories according to similarity by a clustering algorithm, forming a plurality of vector blocks. The implementation method of clustering includes K-means clustering, DBSCAN clustering, etc. Through clustering, font vectors with similar morphological features can be classified into the same category, and then form an original font vector block. Each original font vector block represents a part of the features of the original font, which can correspond to a local structure in the font.
[0079] Taking the letter "A" as an example, the letter "A" can be converted into a set of vectors by vector mapping. In the clustering process, the vectors of the letter "A" can be divided into a plurality of vector blocks, for example: the left vector block (representing the shape of the left half of the letter), the middle vector block (representing the middle part of the letter, including the horizontal connecting line), and the right vector block (representing the shape of the right half of the letter).
[0080] Referring to Figure 6 In some embodiments, the target sparse block-diagonal coupled model comprises at least one target sparse block-diagonal coupled layer, each target sparse block-diagonal coupled layer comprising a first low-rank factor matrix, a second low-rank factor matrix, a dense basis matrix, a binary mask matrix, and a bias term, and step S103 comprises but is not limited to steps S601 to S603:
[0081] In step S601, the original font vector block is decomposed into a font low-rank matrix by the first low-rank factor matrix and the second low-rank factor matrix.
[0082] In step S602, the original font vector block is decomposed into a font sparse matrix by the dense basis matrix and the binary mask matrix.
[0083] In step S603, the sum of the font low-rank matrix, the font sparse matrix, and the bias term is obtained to obtain a sparse low-rank matrix.
[0084] The steps S601 to S603 shown in the embodiments of the present application decompose the original font vector block into a font low-rank matrix by the first low-rank factor matrix and the second low-rank factor matrix, convert the original high-dimensional data into a low-rank representation, compress under the premise of retaining the main features, and reduce the computational burden of redundant information. Further, most elements of the original font vector block are set to zero by sparse decomposition, reducing the complexity of the calculation. Finally, the sum of the font low-rank matrix, the font sparse matrix, and the bias term is obtained to obtain a sparse low-rank matrix, which retains the core structural features of the font and eliminates redundant information, and can retain important structural information while ensuring efficient calculation.
[0085] In steps S601 to S603 of some embodiments, the sparse block-diagonal coupled model comprises a plurality of sparse block-diagonal coupled layers, and each sparse block-diagonal coupled layer comprises four trainable matrices, namely a first low-rank factor matrix, a second low-rank factor matrix, a dense basis matrix, and a binary mask matrix, and a trainable bias term. Each sparse block-diagonal coupled layer is connected by a residual connection.
[0086] The low-rank decomposition, the sparse decomposition, and the summation are shown in formula (1):
[0087]
[0088] wherein x k is the original font vector block, f k (x k ) is the sparse low-rank matrix, U k is the first low-rank factor matrix, V kis a second low-rank factor matrix, M k is a binary mask matrix, S k is a dense basis matrix, b k is a bias term.
[0089] Please refer to Figure 3 In some embodiments, before step S103, steps S301 to S304 can also be included, but not limited to:
[0090] In step S301, a sample font vector block of a sample font and a preset sparse block diagonal coupling model are obtained; wherein the preset sparse block diagonal coupling model includes a preset sparse block diagonal coupling layer;
[0091] In step S302, the sample font vector block is sparsely and low-rank decomposed by the preset sparse block diagonal coupling layer to obtain a sample decomposition matrix;
[0092] In step S303, a font is generated by the sample decomposition matrix to obtain a predicted font;
[0093] In step S304, the preset sparse block diagonal coupling layer of the preset sparse block diagonal coupling model is trained according to the predicted font and the sample font to obtain a target sparse block diagonal coupling model.
[0094] The steps S301 to S304 shown in the embodiments of the present application are as follows: a sample font vector block of a sample font and a preset sparse block diagonal coupling model including a preset sparse block diagonal coupling layer are obtained, then the sample font vector block is sparsely and low-rank decomposed by the preset sparse block diagonal coupling layer to obtain a sample decomposition matrix, then a font is generated by the sample decomposition matrix to obtain a predicted font, and finally the preset sparse block diagonal coupling layer of the preset sparse block diagonal coupling model is trained according to the predicted font and the sample font to obtain a target sparse block diagonal coupling model capable of accurately generating a font.
[0095] In step S301 of some embodiments, the sample font refers to a font with a style to be generated, for example, the sample font is a Songti type font, or a series of artistic characters preset by an artificial, which have the same artistic style. The way to obtain the sample font vector block of the sample font is similar to the principles of steps S201 to S202, which will not be described here.
[0096] The preset sparse block diagonal coupling model is the target sparse block diagonal coupling model before training, and the network structure of the preset sparse block diagonal coupling model is completely consistent with that of the target sparse block diagonal coupling model, except that the parameter matrices in the network structure are not the same.
[0097] It can be understood that the structures of the preset sparse block-diagonal coupling layer and the target sparse block-diagonal coupling layer are also completely consistent, except that the parameter matrices in the network structure are different.
[0098] In step S302 of some embodiments, the sample font vector block is sparsely and low-rank decomposed by the preset sparse block-diagonal coupling layer, and the principle of obtaining the sample decomposition matrix is the same as that of steps S601 to S603, which will not be repeated here.
[0099] In step S303 of some embodiments, the font is generated by the sample decomposition matrix, and the principle of obtaining the predicted font is the same as that of subsequent steps S104 to S106, which will not be repeated here.
[0100] Please refer to Figure 4 In some embodiments, step S304 can include but is not limited to steps S401 to S403:
[0101] Step S401, loss value calculation is performed according to the predicted font and the sample font, and a model loss value is obtained;
[0102] Step S402, the binary mask matrix of the preset sparse block-diagonal coupling layer is adaptively updated according to the model loss value and the dense base matrix of the preset sparse block-diagonal coupling layer;
[0103] Step S403, the first low-rank factor matrix, the second low-rank factor matrix, the dense base matrix and the bias term of the preset sparse block-diagonal coupling layer are updated by gradient descent according to the model loss value.
[0104] The steps S401 to S403 shown in the embodiments of the present application perform loss value calculation according to the predicted font and the sample font to obtain a model loss value, then adaptively update the binary mask matrix of the preset sparse block-diagonal coupling layer according to the model loss value and the dense base matrix of the preset sparse block-diagonal coupling layer, and finally update the first low-rank factor matrix, the second low-rank factor matrix, the dense base matrix and the bias term of the preset sparse block-diagonal coupling layer by gradient descent according to the model loss value. In this way, on the one hand, the binary mask matrix is adaptively updated to dynamically adjust the non-zero elements in the matrix, ensuring that key features are effectively selected according to the current gradient information in each iteration, thereby improving the attention of the model to important information, reducing the complexity of unnecessary calculation, and further improving the generation accuracy and speed. On the other hand, the first low-rank factor matrix, the second low-rank factor matrix, the dense base matrix and the bias term of the preset sparse block-diagonal coupling layer are updated by gradient descent, gradually reducing the model loss value, and improving the accuracy of the generated font of the model.
[0105] In step S401 of some embodiments, the loss value calculation refers to measuring the difference between the prediction result and the real sample, and in this embodiment, the loss value calculation is used to evaluate the error between the generated font and the sample font. The loss value calculation is achieved by comparing the similarity of the predicted font and the sample font, such as mean square error (MSE) or cross-entropy loss function, to calculate the difference between the generated font and the target font.
[0106] Please refer to Figure 5 In some embodiments, step S402 includes but is not limited to steps S501 to S503:
[0107] Step S501, gradient information quantity threshold calculation is performed on the dense base matrix of the preset sparse block diagonal coupling layer according to the model loss value, to obtain a gradient threshold value;
[0108] Step S502, the update matrix is obtained by calculating the gradient threshold value and the dense base matrix of the preset sparse block diagonal coupling layer;
[0109] Step S503, the binary mask matrix of the preset sparse block diagonal coupling layer is replaced according to the update matrix.
[0110] The steps S501 to S503 shown in the embodiments of the present application perform gradient information quantity threshold calculation on the dense base matrix of the preset sparse block diagonal coupling layer according to the model loss value, to obtain a gradient threshold value, then calculate the gradient threshold value and the dense base matrix of the preset sparse block diagonal coupling layer to obtain an update matrix, and finally replace the binary mask matrix of the preset sparse block diagonal coupling layer according to the update matrix, thereby realizing dynamic update of the dense base matrix of the preset sparse block diagonal coupling layer, dynamically adjusting the non-zero elements in the matrix, ensuring effective selection of key features according to the current gradient information in each iteration, thereby improving the attention of the model to important information, reducing the complexity of unnecessary calculation, and further improving the generation accuracy and generation speed.
[0111] In step S501 of some embodiments, the calculation of the gradient information quantity threshold is used to dynamically adjust the update of the binary mask matrix, thereby controlling which elements in the sparse low-rank matrix can be retained. By calculating the gradient threshold value, the importance of which elements can be determined according to the magnitude of the current gradient information, so as to selectively retain or discard certain features in the subsequent update. The gradient information quantity threshold calculation obtains the gradient threshold value as shown in formula (2):
[0112]
[0113] wherein τ is the gradient threshold value, is the dimension of the matrix S k is the square of the dimension of the matrix S is a model loss value L to a dense base matrix S of a preset sparse block diagonal coupled layer k each element S k,ij gradient.
[0114] In step S502 of some embodiments, according to the gradient threshold and the dense base matrix of the preset sparse block diagonal coupled layer, an update matrix is calculated as shown in formula (3):
[0115]
[0116] wherein, is an update matrix, is a dense base matrix, t represents the round of cyclic iteration, and τ is a gradient threshold.
[0117] It should be noted that in the traditional model, the binary mask matrix is generally updated by gradient, but is dynamically adjusted by some fixed rules or preset threshold. These update rules are usually rigid and will not be flexibly adjusted with the change of gradient information. Therefore, the update of the binary mask matrix in the traditional method often cannot adaptively optimize the selection of features according to the needs of different training stages, which may lead to important features being ignored or irrelevant features being retained, thereby affecting the effect of the model.
[0118] In the embodiments of the present application, the update mode of the binary mask matrix overcomes this shortcoming and adopts an adaptive adjustment mode based on gradient information. By calculating the gradient threshold and dynamically adjusting the mask matrix according to the current gradient amplitude, the structure of the sparse matrix can be optimized in real time, so that the model can more flexibly select and retain important features during the training process.
[0119] In step S403 of some embodiments, the first low-rank factor matrix, the second low-rank factor matrix, the dense base matrix and the bias term are adjusted according to the gradient information of the loss value. Gradient descent updates these parameters in the negative direction of the gradient by calculating the partial derivative of the loss function with respect to each parameter, thereby reducing the loss value and optimizing the prediction ability of the model.
[0120] In step S104 of some embodiments, each original font vector block corresponds to a sparse low-rank matrix, and each original font vector block corresponds to a position in the original font vector. The sparse low-rank matrices are spliced according to the positions in the original font vector to obtain a font sparse low-rank matrix.
[0121] Please refer to Figure 7 In some embodiments, step S105 can include but is not limited to steps S701 to S702:
[0122] Step S701, for each target sparse block-diagonal coupled layer, calculating according to the first low-rank factor matrix, the second low-rank factor matrix, the dense basis matrix and the binary mask matrix to obtain a block determinant;
[0123] Step S702, obtaining the product of each block determinant to obtain a determinant matrix.
[0124] The steps S701 to S702 shown in the embodiments of the present application calculate the first low-rank factor matrix, the second low-rank factor matrix, the dense basis matrix and the binary mask matrix of each target sparse block-diagonal coupled layer to obtain a block determinant, and then obtain the product of each block determinant to obtain a determinant matrix, thereby reducing the required computing power and increasing the font generation speed in the flow network.
[0125] In steps S701 to S702 of some embodiments, the determinant matrix is calculated as shown in equation (4):
[0126]
[0127] wherein det(J f ) is the determinant matrix.
[0128] It should be noted that in the traditional flow network, calculating the determinant of the Jacobian matrix involves calculating the entire Jacobian matrix, and the time complexity is O(N 3 ), where N is the dimension of the matrix. This high time complexity makes the calculation cost high in practical applications, especially when multiple matrix operations are required, which affects the efficiency of the model.
[0129] In the present application, in order to reduce the calculation complexity, the original font vector is first divided into blocks. By dividing the original high-dimensional matrix into multiple smaller sub-matrices, each sub-matrix only contains local features. These local features correspond to different regions or different character parts of the font, so each matrix block is processed independently and does not involve the calculation of other regions.
[0130] Then, when calculating the Jacobian matrix corresponding to the original font vector, using the property of matrix determinant, the determinant of the Jacobian matrix can be expressed as the product of the determinants of each small block. Therefore, the calculation of the determinant is simplified to the calculation of the determinant of each sub-matrix, without the need to calculate the entire matrix. The calculation complexity is reduced from O(N 3 ) to O(r 3 ). Wherein r is the matrix dimension of the first low-rank factor matrix, the second low-rank factor matrix, the dense basis matrix and the binary mask matrix, which significantly reduces the computing power requirement, as shown in equation (5):
[0131]
[0132] Under the premise of formula (5), then the determinant calculation is simplified as the product of the determinant of each block, that is, as shown in formula (4).
[0133] It should be noted that, in the training stage, the sample font is used as the training set of the preset sparse block diagonal coupled model, and in the training process, the preset sparse block diagonal coupled model can gradually generate a font similar in style to the sample font to obtain a target sparse block diagonal coupled model. After obtaining the target sparse block diagonal coupled model, in the application stage, that is, the inference stage, the determinant of the target sparse block diagonal coupled model will not change, so the first low-rank factor matrix, the second low-rank factor matrix, the dense basis matrix and the binary mask matrix will also not change, and the corresponding determinant matrix will also not change, which means that the target sparse block diagonal coupled model is a model that can strictly generate a style, that is, the style of the sample font, and cannot generate other style fonts.
[0134] In step S106 of some embodiments, font generation is performed according to the determinant matrix and the font sparse low-rank matrix to obtain a target font, as shown in formula (7):
[0135] y = z * det(J f )(7),
[0136] Wherein, z is the font sparse low-rank matrix, and y is the target font.
[0137] It should be noted that clustering the font into font vector blocks is used to capture the local features of the font on the one hand, thereby improving the generation accuracy of the network. On the other hand, it is used to simplify the calculation of the Jacobian matrix, thereby simplifying the calculation of the determinant and improving the training speed of the model.
[0138] Secondly, the target sparse block diagonal coupled model processes the font vector blocks to be sparse and low-rank, so that the target sparse block diagonal coupled model can quickly and accurately generate a font in the generation stage, that is, the inference stage, and is suitable for real-time generation scenarios.
[0139] Please refer to Figure 8 The embodiment of the application also provides a font generation device, which can implement the font generation method described above, and the device comprises:
[0140] The acquisition digital module 801 is configured to acquire an original font.
[0141] The block processing module 802 is configured to perform block processing on the original font to obtain original font vector blocks.
[0142] The matrix decomposition module 803 is configured to perform sparse low-rank decomposition on the original font vector block by using a preset target sparse block diagonal coupling model to obtain a sparse low-rank matrix.
[0143] The matrix splicing module 804 is configured to splice the sparse low-rank matrix to obtain a font sparse low-rank matrix.
[0144] The determinant decomposition module 805 is configured to perform determinant decomposition on the target sparse block diagonal coupling model to obtain a determinant matrix.
[0145] The font generation module 806 is configured to perform font generation according to the determinant matrix and the font sparse low-rank matrix to obtain a target font.
[0146] The specific implementation of the font generation apparatus is basically the same as the specific implementation of the font generation method described above, and thus will not be repeated here.
[0147] The embodiments of the present application further provide an electronic device, which includes a memory and a processor. The memory stores a computer program, and the processor implements the font generation method described above when executing the computer program. The electronic device can be any intelligent terminal, such as a tablet computer or a vehicle-mounted computer.
[0148] Please refer to Figure 9 , Figure 9 The hardware structure of the electronic device of another embodiment is shown, which includes:
[0149] The processor 901 can be implemented in a general-purpose CPU (Central Processing Unit), a microprocessor, an ASIC (Application Specific Integrated Circuit), or one or more integrated circuits, and is configured to execute related programs to implement the technical solutions provided by the embodiments of the present application.
[0150] The memory 902 can be implemented in the form of a ROM (ReadOnly Memory), a static storage device, a dynamic storage device, or a RAM (Random Access Memory). The memory 902 can store an operating system and other application programs. When the technical solutions provided by the embodiments of the present application are implemented by software or firmware, the related program codes are stored in the memory 902 and are called and executed by the processor 901 to implement the font generation method of the embodiments of the present application.
[0151] The input / output interface 903 is configured to realize information input and output.
[0152] The communication interface 904 is configured to realize the communication interaction between the device and other devices. The communication can be realized in a wired manner (for example, a USB, a network cable, or the like) or in a wireless manner (for example, a mobile network, WIFI, Bluetooth, or the like).
[0153] The bus 905 is configured to transmit information between various components (for example, the processor 901, the memory 902, the input / output interface 903, and the communication interface 904) of the device.
[0154] The processor 901, the memory 902, the input / output interface 903, and the communication interface 904 are connected to each other through the bus 905 to realize the communication connection between the device.
[0155] The embodiment of the present application further provides a computer readable storage medium, which stores a computer program. The computer program is executed by a processor to realize the font generation method.
[0156] The memory is a non-transitory computer readable storage medium, and is configured to store a non-transitory software program and a non-transitory computer executable program. In addition, the memory can include a high-speed random access memory, and can further include a non-transitory memory, for example, at least one magnetic disk storage device, a flash memory device, or other non-transitory solid-state memory device. In some embodiments, the memory can optionally include a memory remotely arranged relative to the processor, and the remote memory can be connected to the processor through a network. Examples of the network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and a combination thereof.
[0157] The font generation method, font generation device, electronic equipment and storage medium provided by the embodiments of the present application obtain an original font, then perform block processing on the original font to obtain an original font vector block. Then, the original font vector block is subjected to sparse low-rank decomposition through a preset target sparse block diagonal coupling model to obtain a sparse low-rank matrix. Next, the sparse low-rank matrix is spliced into a font sparse low-rank matrix, and the target sparse block diagonal coupling model is further subjected to determinant decomposition, so as to obtain a determinant matrix. Finally, font generation is performed based on the determinant matrix and the font sparse low-rank matrix, and a target font is obtained. In this way, the embodiments of the present application obtain the original font and perform block processing thereon, convert the font information into a vector block, perform sparse low-rank decomposition on the target sparse block diagonal coupling model based on a flow model, extract the low-rank structure of the font, reduce the redundant information, on the one hand, the flow model can use the realistic modeling capability of likelihood calculation, so that the subsequent font with consistent style can be generated, on the other hand, the font is converted into a vector block in the form of block, so that the network can capture the local features of the font. Then, the target sparse block diagonal coupling model is subjected to determinant decomposition, so as to reduce the computing power required for calculating the determinant and improve the speed of generating the font. Finally, font generation is performed based on the determinant matrix and the font sparse low-rank matrix, and the target font is obtained, so that the font with consistent style can be accurately and quickly generated.
[0158] The embodiments described in the embodiments of the present application are used to more clearly illustrate the technical solutions of the embodiments of the present application, and do not constitute a limitation on the technical solutions provided by the embodiments of the present application. Those skilled in the art can know that, with the evolution of technology and the appearance of new application scenarios, the technical solutions provided by the embodiments of the present application are also applicable to similar technical problems.
[0159] Those skilled in the art can understand that the technical solutions shown in the figures do not constitute a limitation on the embodiments of the present application, and can include more or fewer steps than the figures shown, or combine certain steps or different steps.
[0160] The device embodiments described above are only schematic, and the units illustrated as separate components can or can not be physically separate, that is, they can be located in one place or distributed on multiple network units. Part or all of the modules can be selected according to actual needs to achieve the purpose of the embodiments of the present application.
[0161] Those skilled in the art can understand that all or some of the steps in the above disclosed method, the function modules / units in the system and the device can be implemented as software, firmware, hardware and their appropriate combinations.
[0162] The terms "first", "second", "third", "fourth", and the like in the description and in the claims of this application, if any, are used for distinguishing between similar elements and not necessarily for describing a particular sequential or chronological order. It is to be understood that the use of the terms so termed is interchangeable under appropriate circumstances such that the embodiments of the application described herein are, for example, capable of orderly or chronological mundane operation, reverse order operation, based on circuitry availability, based on stated preference or the like, and that "default" or other orderings are thus permissible. Further, the terms "comprise", "comprising", "include", "including", and the like, are specifically intended to be open-ended. That is, references to individual steps and the like do not suhstantially exclude the presence of two or more of a given step or its integral presence in the process, method, system, article, or apparatus having been made with a wider scope. The use of notation such as "first", "second", "third", etc. does not generally limit the areas, but can be used for clarity, and merely establishes the order of the steps or placement of components. Moreover, singular forms "a", "an" and "the" include plural referents unless the context clearly dictates otherwise.
[0163] It should be understood that, in the application, "at least one" means one or more, and "multiple" means two or more. "And / or" is used to describe the relationship between associated objects, which means that there can be three relationships, for example, "A and / or B" can mean that there are three cases: only A, only B, and A and B at the same time, where A and B can be singular or plural. The character " / " generally represents an "or" relationship between the associated objects. "At least one of the following" or similar expressions means any combination of these items, including any combination of single or multiple items. For example, at least one of a, b or c can mean a, b, c, "a and b", "a and c", "b and c", or "a and b and c", where a, b, and c can be single or multiple.
[0164] In several embodiments provided in the application, it should be understood that the disclosed devices and methods can be implemented in other ways. For example, the above-described device embodiments are only illustrative, for example, the division of the above-mentioned units is only a logical functional division, and actual implementation can have another division manner, for example, multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. In addition, the coupling or direct coupling or communication connection between the displayed or discussed objects can be indirect coupling or communication connection through some interfaces, devices or units, which can be electrical, mechanical or other forms.
[0165] The units described above as separate components can or can not be physically separate, and the components shown as units can or can not be physical units, i.e. they can be located in one place or distributed on multiple network units. Part or all of the units can be selected according to actual needs to achieve the purpose of the embodiments.
[0166] In addition, each function unit in each embodiment of the present application can be integrated in one processing unit, or each unit can be physically present separately, or two or more units can be integrated in one unit. The integrated unit can be realized in the form of hardware or in the form of a software function unit.
[0167] When the integrated unit is realized in the form of a software function unit and sold or used as an independent product, it can be stored in a computer readable storage medium. Based on such understanding, the technical solutions of the present application, essentially or in part, or all or part of the technical solutions can be embodied in the form of a software product. The computer software product is stored in a storage medium, and includes multiple instructions used to cause a computer device (which can be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the methods in the embodiments of the present application. The foregoing storage medium includes: a U disk, a mobile hard disk, a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk, and various other media that can store programs.
[0168] The preferred embodiments of the embodiments of the present application are described above with reference to the accompanying drawings, and are not limited to the scope of the embodiments of the present application. Any modifications, equivalent replacements and improvements made by those skilled in the art without departing from the scope and essence of the embodiments of the present application shall be within the scope of the embodiments of the present application.
Claims
1. A font generation method characterized by, The method comprises: acquiring an original font; performing block processing on the original font to obtain an original font vector block; performing sparse low-rank decomposition on the original font vector block through a preset target sparse block diagonal coupling model to obtain a sparse low-rank matrix; performing splicing on the sparse low-rank matrix to obtain a font sparse low-rank matrix; performing determinant decomposition on the target sparse block diagonal coupling model to obtain a determinant matrix; generating a font according to the determinant matrix and the font sparse low-rank matrix to obtain a target font.
2. The method of claim 1, wherein, The target sparse block diagonal coupling model comprises at least one target sparse block diagonal coupling layer, and each target sparse block diagonal coupling layer comprises a first low-rank factor matrix, a second low-rank factor matrix, a dense base matrix, a binary mask matrix and a bias term. The sparse low-rank decomposition on the original font vector block through the preset target sparse block diagonal coupling model to obtain a sparse low-rank matrix comprises: performing low-rank decomposition on the original font vector block through the first low-rank factor matrix and the second low-rank factor matrix to obtain a font low-rank matrix; performing sparse decomposition on the original font vector block through the dense base matrix and the binary mask matrix to obtain a font sparse matrix; obtaining the sum of the font low-rank matrix, the font sparse matrix and the bias term to obtain the sparse low-rank matrix.
3. The method of claim 2, wherein, Before the sparse low-rank decomposition on the original font vector block through the preset target sparse block diagonal coupling model to obtain a sparse low-rank matrix, the method further comprises pre-training the target sparse block diagonal coupling model, specifically comprising: obtaining a sample font vector block and a preset sparse block diagonal coupling model of a sample font; wherein the preset sparse block diagonal coupling model comprises a preset sparse block diagonal coupling layer; performing sparse low-rank decomposition on the sample font vector block through the preset sparse block diagonal coupling layer to obtain a sample decomposition matrix; generating a font through the sample decomposition matrix to obtain a predicted font; training the preset sparse block diagonal coupling layer of the preset sparse block diagonal coupling model according to the predicted font and the sample font to obtain the target sparse block diagonal coupling model.
4. The method of claim 3, wherein, The training of the preset sparse block diagonal coupling layer of the preset sparse block diagonal coupling model according to the predicted font and the sample font to obtain the target sparse block diagonal coupling model comprises: calculating a loss value according to the predicted font and the sample font to obtain a model loss value; performing adaptive update on the binary mask matrix of the preset sparse block diagonal coupling layer according to the model loss value and the dense base matrix of the preset sparse block diagonal coupling layer; performing gradient descent update on the first low-rank factor matrix, the second low-rank factor matrix, the dense base matrix and the bias term of the preset sparse block diagonal coupling layer according to the model loss value.
5. The method of claim 4, wherein, The adaptive update on the binary mask matrix of the preset sparse block diagonal coupling layer according to the model loss value and the dense base matrix of the preset sparse block diagonal coupling layer comprises: The gradient information quantity threshold value of the dense base matrix of the preset sparse block diagonal coupling layer is calculated according to the model loss value, to obtain a gradient threshold value; The update matrix is calculated according to the gradient threshold value and the dense base matrix of the preset sparse block diagonal coupling layer; The binary mask matrix of the preset sparse block diagonal coupling layer is replaced according to the update matrix.
6. The method of claim 2, wherein, The determinant matrix is obtained by performing determinant decomposition on the target sparse block diagonal coupling model, and the determinant matrix includes: For each target sparse block diagonal coupling layer, the block determinant is calculated according to the first low-rank factor matrix, the second low-rank factor matrix, the dense base matrix and the binary mask matrix; The product of each block determinant is obtained to obtain the determinant matrix.
7. The method according to any one of claims 1 to 6, characterized in that, The original font is subjected to block processing to obtain an original font vector block, and the block processing includes: The original font is subjected to vector mapping to obtain an original font vector; The original font vector is clustered to obtain the original font vector block.
8. A font generating apparatus characterized by comprising: The device includes: An acquisition digital module is configured to acquire an original font; A block processing module is configured to perform block processing on the original font to obtain an original font vector block; A matrix decomposition module is configured to perform sparse low-rank decomposition on the original font vector block by using a preset target sparse block diagonal coupling model to obtain a sparse low-rank matrix; A matrix splicing module is configured to splice the sparse low-rank matrix to obtain a font sparse low-rank matrix; A determinant decomposition module is configured to perform determinant decomposition on the target sparse block diagonal coupling model to obtain a determinant matrix; A font generation module is configured to generate a target font according to the determinant matrix and the font sparse low-rank matrix.
9. An electronic device, comprising: The electronic device includes a memory and a processor, the memory stores a computer program, and the processor implements the font generation method in any one of claims 1 to 7 when executing the computer program.
10. A computer-readable storage medium storing a computer program, the computer program comprising instructions that, when executed by a computer, cause the computer to perform the method of any one of claims 1 to 9. The computer program is executed by the processor to implement the font generation method in any one of claims 1 to 7.