A three-layer mathematical formula recognition method, system and storage device integrating dual channels
By introducing a dual-channel three-layer architecture and GRU recurrent neural network into single-stage mathematical formula recognition, combined with spatial and channel attention modules, the problem of repeated and missing symbols in handwritten mathematical formula recognition is solved, and the recognition accuracy and feature representation are improved. force.
Patent Information
- Application Number
- CN202011046709.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2020-09-29
- Publication Date
- 2024-09-13
- Estimated Expiration
- Not applicable · inactive patent
AI Technical Summary
The existing single-stage mathematical formula recognition technology has problems with repeated symbols and missing symbols when identifying handwritten mathematical formulas, and the extracted features have insufficient representational power, resulting in low recognition accuracy.
It adopts a three-layer architecture method that combines dual channels to extract regional visual information through the encoding layer, uses the spatial attention module and channel attention module to enhance feature extraction, combines the GRU recurrent neural network for decoding, and introduces coverage vectors to reduce symbol duplication and missing phenomena. .
It improves the recognition accuracy of mathematical formulas, reduces symbol duplication and missing phenomena, enhances feature representation, and improves the recognition rate.
Smart Images

Figure CN112183544B
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of mathematical formula recognition, and in particular to a mathematical formula recognition method, system and storage device integrating dual channels and a three-layer architecture. Background Art
[0002] Mathematical formulas are widely used in many scientific fields and play an indispensable role in explaining theoretical knowledge and describing scientific problems. We can usually input mathematical formulas by using mathematical tools, but this method usually inputs the mathematical markup language Latex to generate the corresponding mathematical formulas, which requires users to have a certain grammatical foundation. Handwriting input can solve the input problem well, and users can input mathematical formulas more conveniently.
[0003] Compared with the recognition of printed mathematical formulas, the difficulty of handwritten mathematical formula recognition is much higher than that of printed mathematical formula recognition due to the ambiguity of handwritten symbols, the diversity of handwriting styles and the large amount of adhesion between symbols.
[0004] Generally, the mathematical formula recognition process can be divided into three stages: symbol segmentation stage, symbol recognition stage, and structure analysis stage. According to the different ways of implementing the three stages, the current mainstream recognition solutions can be divided into two types: multi-stage recognition and single-stage recognition.
[0005] The multi-stage solution first segmented the symbols in the mathematical formula, then recognized the segmented symbols, and finally performed structural analysis based on the recognition results and symbol positions. Although this solution can realize the modularization of the recognition process, it has a very serious problem: error inheritance. The error in the previous stage will be passed to the next stage, causing error accumulation, thus affecting the recognition accuracy of the entire recognition process. This solution is more disadvantageous in recognizing handwritten mathematical formulas, because handwritten symbols have a lot of adhesion and are difficult to segment accurately. At the same time, the segmented handwritten symbols lose the upper and lower information, which increases the difficulty of symbol recognition.
[0006] The single-stage solution uses a deep neural network to implement an end-to-end recognition network, completing the three stages of formula recognition at one time. The recognition network usually adopts an encoding-decoding structure. First, the encoder is used to extract features from the input mathematical formula image and encode it. Then, the decoder with an attention mechanism scans the features extracted by the encoder, uses the most relevant area to describe the segmented symbols, and outputs the mathematical markup language Latex corresponding to the mathematical formula.
[0007] In the encoder part, due to the inconsistency of symbol sizes of different mathematical formulas, in order to more effectively utilize the visual features in the image, the researchers solved the problem of inconsistent symbol scales by simultaneously extracting multiple feature outputs of different granularities in the encoder. However, although extracting multiple features of different granularities in the encoding layer is enough to solve the symbol size problem, the representation power of the extracted features is insufficient, the context information of the symbols is not fully utilized, and a large number of irrelevant features are introduced.
[0008] In the attention mechanism of the decoder, the output feature map of the encoder is weighted and summed according to the attention feature map at the current moment to obtain a vector that represents the most relevant area of the current recognized character. Then the serialized vector is decoded and output. If only the attention at the current moment is used, symbol duplication and symbol missing may occur in the recognition result.
[0009] Since the prediction ability of recurrent neural networks is very poor in the early stage of model training, the existing technology uses real labels as the input of neural units in the recurrent network to prevent a certain neuron from having a large deviation and affecting the training effect of the recurrent neural network. Although using real labels instead of the input of predicted results allows the model to have better recognition effects in the training stage, the lack of guidance from real labels during the test process will reduce the recognition accuracy. Summary of the invention
[0010] Therefore, it is necessary to provide a mathematical formula recognition method with a three-layer architecture integrating dual channels to solve the problem of low accuracy of existing single-stage formula recognition technology. The specific technical solution is as follows:
[0011] A three-layer mathematical formula recognition method integrating dual channels comprises the following steps:
[0012] Extracting features from the input image through the encoding layer, the features including: regional visual information;
[0013] Capture the context of regional visual information through the attention layer and generate a context vector;
[0014] The context vector is decoded through a decoding layer to generate a mathematical markup language file corresponding to the formula.
[0015] Furthermore, the “extracting features from the input image through the encoding layer” further includes the steps of:
[0016] Use DenseNet as encoder;
[0017] Extract visual information from input images by using the Dense network as the backbone network;
[0018] A spatial attention module and a channel attention module are integrated in the encoder.
[0019] Furthermore, before “extracting features from the input image through the encoding layer”, the following steps are also included:
[0020] Mask information is added to the input image data, and an additional channel is added to the filled part, where the channel is used to record the filled information.
[0021] Furthermore, the “extracting features from the input image through the encoding layer” further includes the steps of:
[0022] The spatial attention module performs average pooling and maximum pooling on the input feature map to obtain two feature maps of the same dimension, concatenates the two feature maps of the same dimension according to the channel, and obtains a spatial attention matrix through a sigmoid function. The spatial attention matrix is multiplied by the input feature map to obtain a spatial attention feature map.
[0023] The channel attention module performs global average pooling and global maximum pooling on the input feature map to obtain two feature maps, inputs the two feature maps into a shared multi-layer perceptron to obtain two vectors, and adds the two vectors and then multiplies them with the input feature map to obtain a channel attention feature map.
[0024] Furthermore, the attention layer is provided with a coverage vector, and the coverage vector is used to represent the cumulative sum of all attention mechanisms at past moments;
[0025] The attention calculation formula is:
[0026] exp ti =f att (α i ,h t-1 )
[0027]
[0028]
[0029] z t =φ({α i , α ti})
[0030] where f att represents a multi-layer perceptron, a i is a vector in the decoder output corresponding to a region in the image, h t-1 is the hidden layer output of the previous unit, α tirepresents the attention weight of the i-th vector at the t-th time step, c represents the coverage vector, and α l represents the attention weight at the lth time step, z t represents the output of the attention mechanism, and φ represents the attention weight applied to the image region.
[0031] Furthermore, the decoding layer uses a GRU recurrent neural network for decoding.
[0032] Furthermore, the "generating a mathematical markup language file corresponding to the formula" further includes the steps of:
[0033] The beam search algorithm is used on the output of the encoding layer to select the sequence with the highest output score as the final output sequence.
[0034] In order to solve the above technical problems, a three-layer mathematical formula recognition system integrating dual channels is also provided. The specific technical solution is as follows:
[0035] A three-layer mathematical formula recognition system integrating dual channels, including: encoding layer, attention layer and decoding layer;
[0036] The encoding layer is used to: extract features from the input image, wherein the features include: regional visual information;
[0037] The attention layer is used to: capture the context of regional visual information and generate a context vector;
[0038] The decoding layer is used to decode the context vector and generate a mathematical markup language file corresponding to the formula.
[0039] Furthermore, DenseNet is used as the encoder;
[0040] Extract visual information from input images by using the Dense network as the backbone network;
[0041] A spatial attention module and a channel attention module are integrated in the encoder;
[0042] The spatial attention module performs average pooling and maximum pooling on the input feature map to obtain two feature maps of the same dimension, concatenates the two feature maps of the same dimension according to the channel, and obtains a spatial attention matrix through a sigmoid function. The spatial attention matrix is multiplied by the input feature map to obtain a spatial attention feature map.
[0043] The channel attention module performs global average pooling and global maximum pooling on the input feature map to obtain two feature maps, inputs the two feature maps into a shared multi-layer perceptron to obtain two vectors, and adds the two vectors and then multiplies them with the input feature map to obtain a channel attention feature map.
[0044] In order to solve the above technical problems, a storage device is also provided, and the specific technical solution is as follows:
[0045] A storage device stores an instruction set, wherein the instruction set is used to execute: the steps of any one of the claims mentioned above.
[0046] The beneficial effects of the present invention are as follows: 1. Extracting features of an input image through an encoding layer, the features include: regional visual information; capturing the context of the regional visual information through an attention layer to generate a context vector; decoding the context vector through a decoding layer to generate a mathematical markup language file corresponding to the formula. Through the above operations of the three layers of the encoding layer, the attention layer and the decoding layer, a mathematical formula with higher accuracy can be obtained.
[0047] 2. By integrating the spatial attention module and the channel attention module into the encoder, the encoder can learn what to pay attention to and where to pay attention to on the channel and spatial axis, thereby improving the expression of the area of interest, making the features extracted by the encoder more representative, and effectively improving the recognition rate.
[0048] 3. Before “extracting features from the input image through the coding layer”, the method further includes the step of adding mask information to the input image data and adding an additional channel to the filled part, wherein the channel is used to record the filled information. By adding mask information, information redundancy in the image filling process can be reduced.
[0049] 4. A coverage vector is set in the attention layer. The coverage vector is used to represent the cumulative sum of all attention mechanisms in the past. It tells the model which parts of the encoder input have been paid attention to and which have not. In order to prevent the model from paying too much attention to the areas that have been paid attention to, the coverage vector is used as a component of the next step of attention. In this way, the attention distribution generated in the next step will consciously reduce the probability of the areas that have been paid attention to, thereby effectively reducing the phenomenon of missing symbols and repeated symbols in formula recognition. BRIEF DESCRIPTION OF THE DRAWINGS
[0050] Figure 1 A flowchart of a mathematical formula recognition method for a three-layer architecture integrating dual channels described in a specific implementation method;
[0051] Figure 2 A schematic diagram of a mathematical formula recognition method of a three-layer architecture integrating dual channels described in a specific implementation method;
[0052] Figure 3 A schematic diagram of a module of a three-layer architecture mathematical formula recognition system integrating dual channels described in a specific implementation method;
[0053] Figure 4 A module schematic diagram of a storage device described in a specific implementation manner.
[0054] Description of reference numerals:
[0055] 300. A three-layer mathematical formula recognition system integrating dual channels.
[0056] 301, coding layer,
[0057] 302. Attention layer,
[0058] 303, decoding layer,
[0059] 400. Storage device. DETAILED DESCRIPTION
[0060] In order to explain the technical content, structural features, achieved objectives and effects of the technical solution in detail, the following is a detailed description in conjunction with specific embodiments and accompanying drawings.
[0061] See also Figure 1 to Figure 2 In this embodiment, a three-layer architecture mathematical formula recognition method integrating dual channels can be applied to storage devices, including but not limited to: personal computers, servers, general-purpose computers, special-purpose computers, network devices, embedded devices, programmable devices, smart mobile terminals, etc. The specific implementation is as follows:
[0062] Step S101: extracting features of an input image through a coding layer, wherein the features include: regional visual information.
[0063] Step S102: Capture the context of regional visual information through the attention layer and generate a context vector.
[0064] Step S103: Decode the context vector through a decoding layer to generate a mathematical markup language file corresponding to the formula.
[0065] The encoding layer extracts features from the input image, including regional visual information; the attention layer captures the context of the regional visual information and generates a context vector; the decoding layer decodes the context vector and generates a mathematical markup language file corresponding to the formula. Through the above operations of the encoding layer, attention layer, and decoding layer, a more accurate mathematical formula can be obtained.
[0066] Wherein step S101 in this embodiment also includes the steps of: using DenseNet as an encoder; extracting visual information from an input image by using a Dense network as a backbone network; integrating a spatial attention module and a channel attention module in the encoder. By integrating a spatial attention module and a channel attention module in the encoder, the encoder can learn what to pay attention to and where to pay attention on the channel and spatial axis, thereby improving the expression of the area of interest, making the features extracted by the encoder more representative, and effectively improving the recognition rate.
[0067] In order to reduce information redundancy in the image filling process, in this embodiment, before "extracting features of the input image through the encoding layer", it also includes the steps of adding mask information to the input image data, and adding an additional channel to the filled part, wherein the channel is used to record the filled information.
[0068] The following is a detailed description of the working mechanisms of the spatial attention module and the channel attention module:
[0069] The spatial attention module performs average pooling and maximum pooling on the input feature map to obtain two feature maps of the same dimension, concatenates the two feature maps of the same dimension according to the channel, and obtains a spatial attention matrix through a sigmoid function. The spatial attention matrix is multiplied by the input feature map to obtain a spatial attention feature map.
[0070] The channel attention module performs global average pooling and global maximum pooling on the input feature map to obtain two feature maps, inputs the two feature maps into a shared multi-layer perceptron to obtain two vectors, and adds the two vectors and then multiplies them with the input feature map to obtain a channel attention feature map.
[0071] It should be noted that, in this embodiment, the DenseNet network structure is mainly composed of DenseBlock and Transition, and a channel attention module and a spatial attention module are added between DenseBlock and Transition in sequence.
[0072] In this embodiment, the attention layer is provided with a coverage vector, and the coverage vector is used to represent the cumulative sum of all attention mechanisms at past moments;
[0073] The attention calculation formula is:
[0074] exp ti =f att (α i ,h t-1 )
[0075]
[0076]
[0077] z t =φ({a i , α ti})
[0078] where f att represents a multi-layer perceptron, a i is a vector in the decoder output corresponding to a region in the image, h t-1 is the hidden layer output of the previous unit, α ti represents the attention weight of the i-th vector at the t-th time step, c represents the coverage vector, and α l represents the attention weight at the lth time step, z t represents the output of the attention mechanism, and φ represents the attention weight applied to the image region.
[0079] The coverage vector is used to represent the cumulative sum of all attention mechanisms at past moments, which tells the model which parts of the encoder input have been paid attention to and which have not. In order to prevent the model from paying too much attention to the areas that have already been paid attention to, the coverage vector is used as a component of the next step of attention, so that the attention distribution generated in the next step will consciously reduce the probability of the areas that have already been paid attention to, thereby effectively reducing the phenomenon of missing symbols and repeated symbols in formula recognition.
[0080] In this embodiment, the decoding layer uses a GRU recurrent neural network for decoding. This alleviates the problem of gradient explosion and gradient vanishing in the recurrent neural network. During the training process, a probability value is selected to choose whether to use the current label or the output of the previous unit as the input of the current unit. Finally, the encoding layer outputs a one-hot encoding set corresponding to each symbol. Figure 2 By randomly selecting the true label and the predicted output as the input of the encoding layer recurrent neural network, the recognition ability of the recognition system in different recognition scenarios can be enhanced.
[0081] Preferably, the "generating a mathematical markup language file corresponding to the formula" further comprises the step of: using a beam search algorithm to select a sequence with the highest output score from the output of the coding layer as the final output sequence.
[0082] See also Figure 3 In this embodiment, a three-layer mathematical formula recognition system 300 integrating dual channels is specifically implemented as follows:
[0083] A three-layer mathematical formula recognition system 300 integrating dual channels includes: a coding layer 301, an attention layer 302 and a decoding layer 303; the coding layer 301 is used to extract features of an input image, wherein the features include: regional visual information; the attention layer 302 is used to capture the context of the regional visual information and generate a context vector; the decoding layer 303 is used to decode the context vector and generate a mathematical markup language file corresponding to the formula.
[0084] The encoding layer 301 extracts features from the input image, and the features include: regional visual information; the attention layer 302 captures the context of the regional visual information and generates a context vector; the decoding layer 303 decodes the context vector and generates a mathematical markup language file corresponding to the formula. Through the above operations of the three layers of the encoding layer 301, the attention layer 302 and the decoding layer 303, a mathematical formula with higher accuracy can be obtained.
[0085] In the encoding layer 301, DenseNet is used as an encoder; the visual information of the input image is extracted by using the Dense network as the backbone network; the encoder is integrated with a spatial attention module and a channel attention module. By integrating the spatial attention module and the channel attention module in the encoder, the encoder can learn what to pay attention to and where to pay attention on the channel and spatial axis, thereby improving the expression of the area of interest, making the features extracted by the encoder more representative, and effectively improving the recognition rate.
[0086] The following is a detailed description of the working mechanisms of the spatial attention module and the channel attention module:
[0087] The spatial attention module performs average pooling and maximum pooling on the input feature map to obtain two feature maps of the same dimension, concatenates the two feature maps of the same dimension according to the channel, and obtains a spatial attention matrix through a sigmoid function. The spatial attention matrix is multiplied by the input feature map to obtain a spatial attention feature map.
[0088] The channel attention module performs global average pooling and global maximum pooling on the input feature map to obtain two feature maps, inputs the two feature maps into a shared multi-layer perceptron to obtain two vectors, and adds the two vectors and then multiplies them with the input feature map to obtain a channel attention feature map.
[0089] It should be noted that, in this embodiment, the DenseNet network structure is mainly composed of DenseBlock and Transition, and a channel attention module and a spatial attention module are added between DenseBlock and Transition in sequence.
[0090] In this embodiment, the attention layer 302 is provided with a coverage vector, and the coverage vector is used to represent the cumulative sum of all attention mechanisms at past moments;
[0091] The attention calculation formula is:
[0092] exp ti =f att (α i ,h t-1 )
[0093]
[0094]
[0095] z t =φ({a i , α ti})
[0096] where f att represents a multi-layer perceptron, a i is a vector in the decoder output corresponding to a region in the image, h t-1 is the hidden layer output of the previous unit, α ti represents the attention weight of the i-th vector at the t-th time step, c represents the coverage vector, and α l represents the attention weight at the lth time step, z t represents the output of the attention mechanism, and φ represents the attention weight applied to the image region.
[0097] The coverage vector is used to represent the cumulative sum of all attention mechanisms at past moments, which tells the model which parts of the encoder input have been paid attention to and which have not. In order to prevent the model from paying too much attention to the areas that have already been paid attention to, the coverage vector is used as a component of the next step of attention, so that the attention distribution generated in the next step will consciously reduce the probability of the areas that have already been paid attention to, thereby effectively reducing the phenomenon of missing symbols and repeated symbols in formula recognition.
[0098] In this embodiment, the decoding layer 303 uses a GRU recurrent neural network for decoding. This alleviates the problem of gradient explosion and gradient vanishing in the recurrent neural network. During the training process, a probability value is selected to choose whether to use the current label or the output of the previous unit as the input of the current unit. Finally, the encoding layer 301 outputs a one-hot encoding set corresponding to each symbol. Figure 2 As shown. By randomly selecting the true label and the predicted output as the input of the recurrent neural network of the encoding layer 301, the recognition ability of the recognition system in different recognition scenarios can be enhanced. The output of the encoding layer 301 is used to select the sequence with the highest output score using the beam search algorithm as the final output sequence.
[0099] See also Figure 4 In this embodiment, a specific implementation of a storage device 400 is as follows: the storage device 400 can be used to execute any step of the above-mentioned three-layer architecture mathematical formula recognition method integrating dual channels, which will not be repeated here.
[0100] It should be noted that, although the above embodiments have been described in this article, the patent protection scope of the present invention is not limited thereby. Therefore, based on the innovative concept of the present invention, changes and modifications made to the embodiments described herein, or equivalent structures or equivalent process changes made using the contents of the present invention specification and drawings, directly or indirectly applying the above technical solutions to other related technical fields, are all included in the patent protection scope of the present invention.
Claims
1. A three-layer mathematical formula recognition method integrating dual channels, characterized in that: Includes steps: Extracting features from the input image through the encoding layer, the features including: regional visual information; Capture the context of regional visual information through the attention layer and generate a context vector; Decoding the context vector through a decoding layer to generate a mathematical markup language file corresponding to the formula; The "extracting features from the input image through the coding layer" also includes the steps of: Use DenseNet as encoder; Extract visual information from input images by using the Dense network as the backbone network; A spatial attention module and a channel attention module are integrated in the encoder; The "extracting features from the input image through the coding layer" also includes the steps of: The spatial attention module performs average pooling and maximum pooling on the input feature map to obtain two feature maps of the same dimension, concatenates the two feature maps of the same dimension according to the channel, and obtains a spatial attention matrix through a sigmoid function. The spatial attention matrix is multiplied by the input feature map to obtain a spatial attention feature map. The channel attention module performs global average pooling and global maximum pooling on the input feature map to obtain two feature maps, inputs the two feature maps into a shared multi-layer perceptron to obtain two vectors, and adds the two vectors and then multiplies them with the input feature map to obtain a channel attention feature map.
2. According to the method for recognizing mathematical formulas of a three-layer architecture integrating dual channels according to claim 1, it is characterized in that: Before "extracting features from the input image through the coding layer", the following steps are also included: Mask information is added to the input image data, and an additional channel is added to the filled part, where the channel is used to record the filled information.
3. According to the method for recognizing mathematical formulas of a three-layer architecture integrating dual channels as described in claim 1, it is characterized in that: The attention layer is provided with a coverage vector, and the coverage vector is used to represent the cumulative sum of all attention mechanisms at past moments; The attention calculation formula is: exp ti =f att (a i ,h t-1 ) z t =φ({α i ,a ti }) where f att represents a multi-layer perceptron, a i is a vector in the decoder output corresponding to a region in the image, h t-1 is the hidden layer output of the previous unit, α ti represents the attention weight of the i-th vector at the t-th time step, c represents the coverage vector, and α l represents the attention weight at the lth time step, z t represents the output of the attention mechanism, and φ represents the attention weight applied to the image region.
4. According to the method for recognizing mathematical formulas of a three-layer architecture integrating dual channels as described in claim 1, it is characterized in that: The decoding layer uses a GRU recurrent neural network for decoding.
5. According to the method for recognizing mathematical formulas of a three-layer architecture integrating dual channels as described in claim 4, it is characterized in that: The "generating a mathematical markup language file corresponding to the formula" also includes the steps of: The beam search algorithm is used on the output of the encoding layer to select the sequence with the highest output score as the final output sequence.
6. A three-layer mathematical formula recognition system integrating dual channels, characterized in that: include: Encoding layer, attention layer, and decoding layer; The encoding layer is used to: extract features from the input image, wherein the features include: regional visual information; The attention layer is used to: capture the context of regional visual information and generate a context vector; The decoding layer is used to: decode the context vector to generate a mathematical markup language file corresponding to the formula; Use DenseNet as encoder; Extract visual information from input images by using the Dense network as the backbone network; A spatial attention module and a channel attention module are integrated in the encoder; The spatial attention module performs average pooling and maximum pooling on the input feature map to obtain two feature maps of the same dimension, concatenates the two feature maps of the same dimension according to the channel, and obtains a spatial attention matrix through a sigmoid function. The spatial attention matrix is multiplied by the input feature map to obtain a spatial attention feature map. The channel attention module performs global average pooling and global maximum pooling on the input feature map to obtain two feature maps, inputs the two feature maps into a shared multi-layer perceptron to obtain two vectors, and adds the two vectors and then multiplies them with the input feature map to obtain a channel attention feature map.
7. A storage device storing an instruction set, characterized in that: The instruction set is used to execute: the steps of any one of claims 1 to 5.
Citation Information
Cited By
Mathematical formula identification method based on artificial intelligence
CN120279563A
