Text recognition method, device, electronic device and storage medium

By introducing the CTC loss function, multi-head attention layer and residual network layer into the text recognition model, combined with the spatial attention and multi-layer perceptron network, the problem of low accuracy and efficiency of text recognition in the existing technology is solved and achieved More efficient and accurate text recognition.

CN117809314BActive Publication Date: 2024-09-17SINOCHEM AGRI HLDG
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202311562124.4
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2023-11-21
Publication Date
2024-09-17
Estimated Expiration
2043-11-21

AI Technical Summary

Technical Problem

Existing text recognition technology suffers from low accuracy and low recognition efficiency, especially poor performance in recognition of blurry fonts and longer texts.

Method used

Using a text recognition model based on the CTC loss function, combined with a multi-head attention layer and a residual network layer, through the feature extraction, encoding and decoding process, the feature extraction and encoding capabilities of text images are improved, and the spatial attention layer and multi-layer perceptron are used The network performs feature fusion to achieve end-to-end variable-length sequence recognition.

Benefits of technology

It improves the accuracy and efficiency of text recognition, enhances the recognition ability of blurred fonts and longer texts, reduces background interference, and improves the robustness and accuracy of the recognition model.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN117809314B
    Figure CN117809314B
Patent Text Reader

Abstract

The present invention provides a text recognition method, device, electronic device and storage medium, and relates to the field of image processing technology. The method includes: inputting a text image to be recognized into a first feature extraction layer in a text recognition model to obtain a sequence feature vector output by the first feature extraction layer; inputting the sequence feature vector into an encoding layer in the text recognition model to obtain an encoding feature vector output by the encoding layer, wherein the encoding layer includes a multi-head attention layer; inputting the encoding feature vector into a decoding layer in the text recognition model to obtain a text recognition result output by the decoding layer, wherein the decoding layer includes a connection time classification CTC layer; wherein the text recognition model is obtained by training based on a CTC loss function. The present invention can improve the recognition efficiency and recognition accuracy of a text recognition model, that is, improve the text recognition efficiency and text recognition accuracy.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of image processing technology, and in particular to a text recognition method, device, electronic equipment and storage medium. Background Art

[0002] With the rapid development of science and technology, the application scope of text recognition is becoming more and more extensive. Optical Character Recognition (OCR) refers to the use of optical technology and computer technology to detect text in an image and then identify the text content in the image. Traditional OCR text recognition regards the character recognition of a text line as a multi-label task learning process; its recognition process includes image preprocessing (such as grayscale conversion of color images, binarization processing, image change angle detection, correction processing, etc.), layout division (such as straight line detection, tilt detection, etc.), character positioning and segmentation, character recognition, layout restoration, post-processing, proofreading, etc. Traditional text recognition generally requires text area positioning first, correcting the tilted text after positioning and then segmenting out individual characters, and then using artificial features HOG (Histogram of Oriented Gradients) or CNN (Convolutional Neural Network) features, combined with classification models to recognize single words, and finally semantic error correction based on statistical language models (such as hidden Markov chains, etc.) or rules, that is, language rule post-processing. Traditional OCR text recognition algorithms are mainly based on image processing technology (such as projection, expansion, rotation, etc.) and statistical machine learning to extract text content from images. They are mainly used for simple document image recognition with a single background color and high resolution. Therefore, text recognition based on deep learning algorithms is currently needed.

[0003] At present, most text recognition is achieved through the CRNN (Convolutional Recurrent Neural Network) algorithm; specifically, the CRNN algorithm introduces a bidirectional LSTM (Long Short-Term Memory) to enhance context modeling. However, the bidirectional LSTM used in CRNN reduces the reasoning speed, has a low recognition rate for fuzzy fonts, and is not accurate enough for longer texts. Therefore, how to improve the accuracy and efficiency of text recognition is a problem that needs to be solved urgently. Summary of the invention

[0004] The present invention provides a text recognition method, device, electronic device and storage medium, which are used to solve the defects of low accuracy and low recognition efficiency of text recognition in the prior art and realize efficient and accurate text recognition.

[0005] The present invention provides a text recognition method, comprising:

[0006] Inputting the text image to be recognized into the first feature extraction layer in the text recognition model to obtain the sequence feature vector output by the first feature extraction layer;

[0007] Inputting the sequence feature vector into the encoding layer in the text recognition model to obtain the encoding feature vector output by the encoding layer, wherein the encoding layer includes a multi-head attention layer;

[0008] Inputting the encoded feature vector into a decoding layer in the text recognition model to obtain a text recognition result output by the decoding layer, wherein the decoding layer includes a connection time classification CTC layer;

[0009] The text recognition model is trained based on the CTC loss function.

[0010] According to a text recognition method provided by the present invention, the step of inputting a text image to be recognized into a first feature extraction layer in a text recognition model to obtain a sequence feature vector output by the first feature extraction layer comprises:

[0011] Inputting the text image into a first sub-feature extraction layer in the first feature extraction layer to obtain a first feature vector output by the first sub-feature extraction layer, wherein the first sub-feature extraction layer includes a convolution layer;

[0012] Inputting the first feature vector into a second feature extraction layer in the first feature extraction layer to obtain a second feature vector output by the second feature extraction layer, wherein the second feature extraction layer includes a convolution layer and a spatial attention layer;

[0013] Inputting the second feature vector into a pooling layer in the first feature extraction layer to obtain a third feature vector output by the pooling layer;

[0014] Inputting the third feature vector into a first standardization layer in the first feature extraction layer to obtain a fourth feature vector output by the first standardization layer;

[0015] The fourth feature vector is input into the first linear layer in the first feature extraction layer to obtain a sequence feature vector output by the first linear layer.

[0016] According to a text recognition method provided by the present invention, the step of inputting the first feature vector to a second feature extraction layer in the first feature extraction layer to obtain a second feature vector output by the second feature extraction layer includes:

[0017] Inputting the first feature vector to a third feature extraction layer in the second feature extraction layer to obtain a fifth feature vector output by the third feature extraction layer, wherein the third feature extraction layer includes three residual network layers connected in sequence;

[0018] Inputting the fifth eigenvector into a first downsampling layer in the second feature extraction layer to obtain a sixth eigenvector output by the first downsampling layer, wherein the first downsampling layer includes a convolution layer and a spatial attention layer;

[0019] Inputting the sixth feature vector into a fourth feature extraction layer in the second feature extraction layer to obtain a seventh feature vector output by the fourth feature extraction layer, wherein the fourth feature extraction layer includes three residual network layers connected in sequence;

[0020] Inputting the seventh eigenvector into a second downsampling layer in the second feature extraction layer to obtain an eighth eigenvector output by the second downsampling layer, wherein the second downsampling layer includes a convolution layer and a spatial attention layer;

[0021] Inputting the eighth feature vector into a fifth feature extraction layer in the second feature extraction layer to obtain a ninth feature vector output by the fifth feature extraction layer, wherein the fifth feature extraction layer includes nine residual network layers connected in sequence;

[0022] Inputting the ninth eigenvector into a third downsampling layer in the second feature extraction layer to obtain a tenth eigenvector output by the third downsampling layer, wherein the third downsampling layer includes a convolution layer and a spatial attention layer;

[0023] The tenth feature vector is input to the sixth feature extraction layer in the second feature extraction layer to obtain a second feature vector output by the sixth feature extraction layer, wherein the sixth feature extraction layer includes three residual network layers connected in sequence.

[0024] According to a text recognition method provided by the present invention, the step of inputting the fifth feature vector to a first downsampling layer in the second feature extraction layer to obtain a sixth feature vector output by the first downsampling layer includes:

[0025] Inputting the fifth eigenvector into a second normalization layer in the first downsampling layer to obtain a first sub-eigenvector output by the second normalization layer;

[0026] Inputting the first sub-feature vector into a first convolutional layer in the first downsampling layer to obtain a second sub-feature vector output by the first convolutional layer;

[0027] The second sub-feature vector is input into the first spatial attention layer in the first downsampling layer to obtain a sixth feature vector output by the first spatial attention layer.

[0028] According to a text recognition method provided by the present invention, the residual network layer includes a multi-branch feature extraction layer and a feature fusion layer connected in sequence;

[0029] The multi-branch feature extraction layer includes a first branch feature extraction layer, a second branch feature extraction layer and a third branch feature extraction layer connected in parallel;

[0030] The first branch feature extraction layer includes a convolution layer, a layer normalization layer, a convolution layer, an activation layer, a global response normalization layer, a convolution layer and a random dropout layer connected in sequence;

[0031] The input and output of the second branch feature extraction layer are the same;

[0032] The third branch feature extraction layer includes a convolutional layer, an activation layer, a global response normalization layer and a Dropout layer which are connected in sequence.

[0033] According to a text recognition method provided by the present invention, the step of inputting the sequence feature vector into the encoding layer in the text recognition model to obtain the encoding feature vector output by the encoding layer includes:

[0034] Inputting the sequence feature vector into a seventh feature extraction layer in the encoding layer to obtain a first encoding vector output by the seventh feature extraction layer, wherein the seventh feature extraction layer includes a plurality of attention mechanism feature extraction layers connected in sequence, and the attention mechanism feature extraction layer includes a multi-head attention layer;

[0035] Inputting the first coding vector to a third standardization layer in the coding layer to obtain a second coding vector output by the third standardization layer;

[0036] The second encoding vector is input into the multi-layer perceptron layer in the encoding layer to obtain the encoding feature vector output by the multi-layer perceptron layer.

[0037] According to a text recognition method provided by the present invention, the attention mechanism feature extraction layer includes a layer normalization layer, a multi-head attention layer, a first Dropout layer, a first feature fusion layer, a layer normalization layer, a multi-layer perceptron network layer, a second Dropout layer and a second feature fusion layer connected in sequence;

[0038] The first feature fusion layer is used to fuse the input of the attention mechanism feature extraction layer and the output of the first Dropout layer;

[0039] The second feature fusion layer is used to fuse the output of the first feature fusion layer and the output of the second Dropout layer;

[0040] The multi-layer perceptron network layer includes a linear layer, an activation layer, a Dropout layer, a linear layer and a Dropout layer connected in sequence.

[0041] The present invention also provides a text recognition device, comprising:

[0042] A feature extraction module, used for inputting the text image to be recognized into the first feature extraction layer in the text recognition model to obtain the sequence feature vector output by the first feature extraction layer;

[0043] A feature encoding module, used for inputting the sequence feature vector into the encoding layer in the text recognition model to obtain the encoding feature vector output by the encoding layer, wherein the encoding layer includes a multi-head attention layer;

[0044] A text recognition module, used for inputting the encoded feature vector into a decoding layer in the text recognition model to obtain a text recognition result output by the decoding layer, wherein the decoding layer includes a connection time classification CTC layer;

[0045] The text recognition model is trained based on the CTC loss function.

[0046] The present invention also provides an electronic device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein when the processor executes the program, any of the above-mentioned text recognition methods is implemented.

[0047] The present invention also provides a non-transitory computer-readable storage medium on which a computer program is stored. When the computer program is executed by a processor, the text recognition method described in any one of the above is implemented.

[0048] The text recognition method, device, electronic device and storage medium provided by the present invention input the text image to be recognized into the first feature extraction layer in the text recognition model to obtain the sequence feature vector output by the first feature extraction layer, input the sequence feature vector into the encoding layer in the text recognition model to obtain the encoding feature vector output by the encoding layer, and the encoding layer includes a multi-head attention layer, so that different features of the sequence feature vector can be adaptively learned, that is, the parallel capability of the encoding layer is improved to learn each feature vector in the sequence feature vector, thereby improving the recognition accuracy of the text recognition model, that is, improving the text recognition accuracy; input the encoding feature vector into the decoding layer in the text recognition model to obtain the text recognition result output by the decoding layer, and the decoding layer includes a connection time classification CTC layer, and the text recognition model is obtained by training based on the CTC loss function, thereby solving the alignment problem of time series text, thereby improving the recognition efficiency and recognition accuracy of the text recognition model, that is, improving the text recognition efficiency and text recognition accuracy. BRIEF DESCRIPTION OF THE DRAWINGS

[0049] In order to more clearly illustrate the technical solutions in the present invention or the prior art, the following briefly introduces the drawings required for use in the embodiments or the description of the prior art. Obviously, the drawings described below are some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.

[0050] Figure 1 A flowchart of the text recognition method provided by the present invention;

[0051] Figure 2 One of the structural schematic diagrams of the text recognition model provided by the present invention;

[0052] Figure 3 The second structural diagram of the text recognition model provided by the present invention;

[0053] Figure 4 The third structural diagram of the text recognition model provided by the present invention;

[0054] Figure 5 The fourth structural diagram of the text recognition model provided by the present invention;

[0055] Figure 6 The fifth structural diagram of the text recognition model provided by the present invention;

[0056] Figure 7 The sixth structural diagram of the text recognition model provided by the present invention;

[0057] Figure 8 The seventh structural diagram of the text recognition model provided by the present invention;

[0058] Fig. 9 A schematic diagram of the structure of a text recognition device provided by the present invention;

[0059] Fig.10 This is a schematic structural diagram of an electronic device provided by the present invention. DETAILED DESCRIPTION

[0060] In order to make the purpose, technical solution and advantages of the present invention clearer, the technical solution of the present invention will be clearly and completely described below in conjunction with the drawings of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.

[0061] With the rapid development of science and technology, the application scope of text recognition is becoming more and more extensive. Optical Character Recognition (OCR) refers to the use of optical technology and computer technology to detect text in an image and then identify the text content in the image. Traditional OCR text recognition regards the character recognition of a text line as a multi-label task learning process; its recognition process includes image preprocessing (such as grayscale conversion of color images, binarization processing, image change angle detection, correction processing, etc.), layout division (such as straight line detection, tilt detection, etc.), character positioning and segmentation, character recognition, layout restoration, post-processing, proofreading, etc. Traditional text recognition generally requires text area positioning first, correcting the tilted text after positioning and then segmenting out individual characters, and then using artificial features HOG (Histogram of Oriented Gradients) or CNN (Convolutional Neural Network) features, combined with classification models to recognize single words, and finally semantic error correction based on statistical language models (such as hidden Markov chains, etc.) or rules, that is, language rule post-processing. Traditional OCR text recognition algorithms are mainly based on image processing technology (such as projection, expansion, rotation, etc.) and statistical machine learning to extract text content from images. They are mainly used for simple document image recognition with a single background color and high resolution. Therefore, text recognition based on deep learning algorithms is currently needed.

[0062] At present, most text recognition is achieved through the CRNN (Convolutional Recurrent Neural Network) algorithm; specifically, the CRNN algorithm introduces a bidirectional LSTM (Long Short-Term Memory) to enhance context modeling; more specifically, the CRNN algorithm includes a convolutional neural network and a recurrent neural network. However, the bidirectional LSTM used in CRNN reduces the reasoning speed, has a low recognition rate for fuzzy fonts, and is not accurate enough for longer texts. Therefore, how to improve the accuracy and efficiency of text recognition is a problem that needs to be solved urgently.

[0063] In addition, although CRNN can be improved, it only uses CNN convolution instead of LSTM. However, such improvements still have the defects of low text recognition accuracy and low recognition efficiency. In addition, CRNN can only solve one-dimensional sequence recognition problems, and when the deformation of the text line is large, its recognition effect will be greatly affected.

[0064] In view of the above problems, the present invention proposes the following embodiments. Figure 1 A flow chart of the text recognition method provided by the present invention is shown in FIG. Figure 1 As shown, the text recognition method includes:

[0065] Step 110: input the text image to be recognized into the first feature extraction layer in the text recognition model to obtain the sequence feature vector output by the first feature extraction layer.

[0066] Here, the text image is an image to be subjected to text recognition, and the text image includes text content. The text recognition model is used to perform text recognition on the text image to obtain a text recognition result.

[0067] In one embodiment, the text image is input into the convolution layer in the first feature extraction layer to obtain the sequence feature vector output by the convolution layer. That is, the sequence feature vector is obtained by feature extraction through the convolution network. Further, the first feature extraction layer also includes a spatial attention layer (Spatial Attention Module, SAM), which performs feature extraction through the spatial attention mechanism, so that the text recognition model pays more attention to the information that needs to be paid attention to, such as paying more attention to the text content, thereby improving the accuracy of text recognition. Further, the first feature extraction layer also includes a pooling layer, exemplarily, the pooling layer is a global average pooling layer (Global AVGPooling). Further, the first feature extraction layer also includes a layer normalization layer (LayerNorm layer). Further, the first feature extraction layer also includes a linear layer (linear layer).

[0068] In another embodiment, a text image is input into a first sub-feature extraction layer in a first feature extraction layer to obtain a first feature vector output by the first sub-feature extraction layer, and the first sub-feature extraction layer includes a convolutional layer; the first feature vector is input into a second feature extraction layer in the first feature extraction layer to obtain a sequence feature vector output by the second feature extraction layer, and the second feature extraction layer includes a convolutional layer and a spatial attention layer.

[0069] In another embodiment, the text image is input into a plurality of cascaded residual blocks in the first feature extraction layer to obtain a sequence feature vector; any residual block includes a convolution layer. Further, the residual block also includes a layer normalization layer. Further, the residual block also includes an activation layer. Further, the residual block also includes a random dropout layer (Dropout layer). Further, the residual block also includes a spatial attention layer.

[0070] Of course, the first feature extraction layer may also be other structures, which will not be described here one by one.

[0071] Step 120, input the sequence feature vector to the encoding layer in the text recognition model to obtain the encoding feature vector output by the encoding layer, and the encoding layer includes a multi-head attention layer.

[0072] It should be noted that the text recognition model uses an encoding-decoding network structure for text recognition.

[0073] In one embodiment, the sequence feature vector is input into the attention mechanism feature extraction layer in the encoding layer to obtain the encoding feature vector output by the attention mechanism feature extraction layer, and the attention mechanism feature extraction layer includes a multi-head attention layer. Further, the attention mechanism feature extraction layer may also include but is not limited to at least one of the following: a layer normalization layer, a Dropout layer, a feature fusion layer, a multi-layer perceptron network layer, etc. The multi-layer perceptron network layer may include but is not limited to at least one of the following: a linear layer, an activation layer, a Dropout layer, a linear layer, etc.

[0074] In another embodiment, the sequence feature vector is input into the attention mechanism feature extraction layer in the encoding layer to obtain a first encoding vector output by the attention mechanism feature extraction layer; the first encoding vector is input into the multi-layer perceptron layer in the encoding layer to obtain the encoding feature vector output by the multi-layer perceptron layer.

[0075] In another embodiment, the sequence feature vector is input into the attention mechanism feature extraction layer in the encoding layer to obtain a first encoding vector output by the attention mechanism feature extraction layer; the first encoding vector is input into the third normalization layer in the encoding layer to obtain the encoding feature vector output by the third normalization layer.

[0076] Of course, the coding layer may also be other structures, which will not be described in detail here.

[0077] Here, the multi-head attention layer is also called the grouped self-attention mechanism layer. Based on this, the different features of the sequence feature vector can be adaptively learned, that is, the parallel ability of the encoding layer can be improved to learn each feature vector in the sequence feature vector, making the model more interpretable, thereby improving the accuracy of text recognition. At the same time, through the multi-head attention layer, it is possible to give greater weight to the target data and related data, so that the "attention" of the encoding layer is focused on the target data, obtaining information details, and realizing a reasonable vector representation of a longer input sequence, thereby improving the accuracy of text recognition.

[0078] Step 130, input the encoded feature vector to the decoding layer in the text recognition model to obtain the text recognition result output by the decoding layer, and the decoding layer includes a connection time classification CTC layer.

[0079] Here, the encoded feature vector can be decoded through the CTC (Connectionist Temporal Classification) layer to obtain the text recognition result. The CTC layer can transcribe the encoded feature vector into a string sequence, thereby solving the alignment problem of temporal text, that is, ensuring that the predicted text recognition result is consistent with the actual string sequence order and length.

[0080] The text recognition model is trained based on the CTC loss function.

[0081] It should be understood that by training the text recognition model through the CTC loss function, end-to-end variable-length sequence recognition can be achieved, thereby improving the recognition efficiency and recognition accuracy of the text recognition model, that is, improving the text recognition efficiency and text recognition accuracy. It should be understood that after outputting the predicted label, the CTC loss function can be used to convert a series of label distributions obtained from the encoding layer into a final label sequence. The CTC loss function is mainly used to solve the problem of misalignment between the target value and the output value of the neural network. Its advantage is that there is no need to force alignment of the labels and the labels can be variable in length. Only the input sequence and the supervision label sequence are required for training.

[0082] Specifically, the text recognition model is trained based on sample text images.

[0083] In one embodiment, the sample text image may be augmented to obtain more sample text images, for example, the sample text image may be randomly blurred, rotated (angle less than 10 degrees), or have noise added.

[0084] Exemplarily, the embodiment of the present invention is applied to the text recognition of township-level address text, and the sample text image can be generated based on the Chinese-English dictionary and the township-level address text information. Further, the Chinese-English dictionary can be used to randomly generate a text image with a character length less than or equal to 30 as the sample text image. Further, based on the township-level address text information, a text image with a character length less than or equal to 12 of the address information can be intercepted as the sample text image.

[0085] To better understand the text recognition model of the embodiment of the present invention, Figure 2 As shown, the text recognition model includes a first feature extraction layer, an encoding layer and a decoding layer.

[0086] It should be understood that the above attention layer can supervise and guide the alignment of CTC.

[0087] The text recognition method provided by the embodiment of the present invention inputs the text image to be recognized into the first feature extraction layer in the text recognition model to obtain the sequence feature vector output by the first feature extraction layer, inputs the sequence feature vector into the encoding layer in the text recognition model to obtain the encoded feature vector output by the encoding layer, and the encoding layer includes a multi-head attention layer, so that different features of the sequence feature vector can be adaptively learned, that is, the parallel capability of the encoding layer is improved to learn each feature vector in the sequence feature vector, thereby improving the recognition accuracy of the text recognition model, that is, improving the text recognition accuracy; the encoded feature vector is input into the decoding layer in the text recognition model to obtain the text recognition result output by the decoding layer, and the decoding layer includes a connection time classification CTC layer, and the text recognition model is trained based on the CTC loss function, thereby solving the alignment problem of time series text, thereby improving the recognition efficiency and recognition accuracy of the text recognition model, that is, improving the text recognition efficiency and text recognition accuracy.

[0088] Based on any of the above embodiments, in the method, the above step 110 includes:

[0089] Inputting the text image into a first sub-feature extraction layer in the first feature extraction layer to obtain a first feature vector output by the first sub-feature extraction layer, wherein the first sub-feature extraction layer includes a convolution layer;

[0090] Inputting the first feature vector into a second feature extraction layer in the first feature extraction layer to obtain a second feature vector output by the second feature extraction layer, wherein the second feature extraction layer includes a convolution layer and a spatial attention layer;

[0091] Inputting the second feature vector into a pooling layer in the first feature extraction layer to obtain a third feature vector output by the pooling layer;

[0092] Inputting the third feature vector into a first standardization layer in the first feature extraction layer to obtain a fourth feature vector output by the first standardization layer;

[0093] The fourth feature vector is input into the first linear layer in the first feature extraction layer to obtain a sequence feature vector output by the first linear layer.

[0094] In one embodiment, the text image is input into a convolution layer in the first sub-feature extraction layer to obtain a first feature vector output by the convolution layer.

[0095] In another embodiment, the text image is input into the convolution layer in the first sub-feature extraction layer to obtain a feature vector output by the convolution layer, and the feature vector output by the convolution layer is input into the normalization layer to obtain a first feature vector output by the normalization layer.

[0096] Taking into account that text recognition detection is mainly aimed at identifying text areas, and the proportion of text in a text image may not be very large, it is generally difficult for those tasks in which the text to be recognized only occupies a small part of the image; based on this, through the above-mentioned spatial attention layer, the text spatial information of the input image can be automatically located, thereby reducing the interference of the background on the task, thereby improving the recognition accuracy and robustness of the text recognition model, that is, improving the accuracy of text recognition.

[0097] Exemplarily, the pooling layer may be a global average pooling layer (Global AVGPooling).

[0098] The text recognition method provided by the embodiment of the present invention can improve the extraction accuracy of the sequence feature vector by extracting the sequence feature vector in the above-mentioned manner; and because the second feature extraction layer includes a spatial attention layer, the spatial attention layer allows the feature extraction process to pay more attention to the text part, thereby improving the extraction accuracy of the sequence feature vector, and ultimately improving the recognition accuracy of the text recognition model, that is, improving the text recognition accuracy.

[0099] Based on any of the above embodiments, in the method, inputting the first feature vector to a second feature extraction layer in the first feature extraction layer to obtain a second feature vector output by the second feature extraction layer includes:

[0100] Inputting the first feature vector to a third feature extraction layer in the second feature extraction layer to obtain a fifth feature vector output by the third feature extraction layer, wherein the third feature extraction layer includes three residual network layers connected in sequence;

[0101] Inputting the fifth eigenvector into a first downsampling layer in the second feature extraction layer to obtain a sixth eigenvector output by the first downsampling layer, wherein the first downsampling layer includes a convolution layer and a spatial attention layer;

[0102] Inputting the sixth feature vector into a fourth feature extraction layer in the second feature extraction layer to obtain a seventh feature vector output by the fourth feature extraction layer, wherein the fourth feature extraction layer includes three residual network layers connected in sequence;

[0103] Inputting the seventh eigenvector into a second downsampling layer in the second feature extraction layer to obtain an eighth eigenvector output by the second downsampling layer, wherein the second downsampling layer includes a convolution layer and a spatial attention layer;

[0104] Inputting the eighth feature vector into a fifth feature extraction layer in the second feature extraction layer to obtain a ninth feature vector output by the fifth feature extraction layer, wherein the fifth feature extraction layer includes nine residual network layers connected in sequence;

[0105] Inputting the ninth eigenvector into a third downsampling layer in the second feature extraction layer to obtain a tenth eigenvector output by the third downsampling layer, wherein the third downsampling layer includes a convolution layer and a spatial attention layer;

[0106] The tenth feature vector is input to the sixth feature extraction layer in the second feature extraction layer to obtain a second feature vector output by the sixth feature extraction layer, wherein the sixth feature extraction layer includes three residual network layers connected in sequence.

[0107] In one embodiment, the residual network layer includes a multi-branch feature extraction layer and a feature fusion layer connected in sequence, the multi-branch feature extraction layer includes a plurality of branch feature extraction layers, different branch feature extraction layers have different convolution levels, and the feature fusion layer is used to fuse the feature vectors output by different branch feature extraction layers. Based on this, the network depth can be increased to better extract the features of the text image, thereby improving the extraction accuracy of the sequence feature vector, and ultimately improving the recognition accuracy of the text recognition model, that is, improving the text recognition accuracy.

[0108] In one embodiment, the fifth eigenvector is input into the first convolution layer in the first downsampling layer to obtain the second sub-eigenvector output by the first convolution layer; the second sub-eigenvector is input into the first spatial attention layer in the first downsampling layer to obtain the sixth eigenvector output by the first spatial attention layer. Further, the first downsampling layer also includes a layer normalization layer.

[0109] Here, the structures of the second downsampling layer and the third downsampling layer are substantially the same as those of the first downsampling layer, and are not described in detail here.

[0110] To better understand the first feature extraction layer of the embodiment of the present invention, as shown in FIG. Figure 3 As shown, the first feature extraction layer includes a first sub-feature extraction layer, three residual network layers connected in sequence, a first downsampling layer, three residual network layers connected in sequence, a second downsampling layer, nine residual network layers connected in sequence, a third downsampling layer, three residual network layers connected in sequence, a pooling layer, a layer normalization layer and a linear layer.

[0111] The text recognition method provided by the embodiment of the present invention can improve the extraction accuracy of the second feature vector by extracting the second feature vector in the above-mentioned manner; and because the second feature extraction layer includes a residual network layer, the network depth can be increased to better extract the features of the text image, thereby improving the extraction accuracy of the sequence feature vector, and ultimately improving the recognition accuracy of the text recognition model, that is, improving the text recognition accuracy; and by deploying the residual network layer in a 3-3-9-3 manner, the extraction accuracy of the sequence feature vector can be improved; and there is a downsampling layer between the residual network layers, thereby improving the extraction accuracy of the sequence feature vector; and the downsampling layer includes a spatial attention layer, so that through the spatial attention layer, more attention is paid to the text part during the feature extraction process, thereby improving the extraction accuracy of the sequence feature vector, and ultimately improving the recognition accuracy of the text recognition model, that is, improving the text recognition accuracy.

[0112] Based on any of the foregoing embodiments, in the method, inputting the fifth feature vector to a first downsampling layer in the second feature extraction layer to obtain a sixth feature vector output by the first downsampling layer includes:

[0113] Inputting the fifth eigenvector into a second normalization layer in the first downsampling layer to obtain a first sub-eigenvector output by the second normalization layer;

[0114] Inputting the first sub-feature vector into a first convolutional layer in the first downsampling layer to obtain a second sub-feature vector output by the first convolutional layer;

[0115] The second sub-feature vector is input into the first spatial attention layer in the first downsampling layer to obtain a sixth feature vector output by the first spatial attention layer.

[0116] In one embodiment, the second sub-feature vector is input into the global maximum pooling layer in the first spatial attention layer to obtain a first sub-feature map output by the global maximum pooling layer, and the second sub-feature vector is input into the global average pooling layer in the first spatial attention layer to obtain a second sub-feature map output by the global average pooling layer; the first sub-feature map output by the global maximum pooling layer and the second sub-feature map output by the global average pooling layer are channel-concatenated to obtain a third sub-feature map; the third sub-feature map is input into the convolution layer in the first spatial attention layer to obtain a fourth sub-feature map output by the convolution layer, so that the number of channels of the fourth sub-feature map is 1; the fourth sub-feature map is input into the first activation layer in the first spatial attention layer to obtain a fifth sub-feature map output by the first activation layer; and a sixth feature vector is generated based on the product of the fifth sub-feature map and the second sub-feature vector.

[0117] Exemplarily, the first activation layer may be a sigmoid activation layer. Preferably, the convolution layer is a 7*7 convolution layer. After a lot of creative work and experiments, it is known that the 7*7 convolution layer has better effect than the 3*3 convolution layer.

[0118] Exemplarily, the first spatial attention layer first performs a channel-based global max pooling and global average pooling on the second sub-feature vector of the input, and obtains two H×W×1 first sub-feature maps and second sub-feature maps, and then performs a concat operation (i.e., channel splicing) on ​​these two feature maps based on the channel to generate a three-sub-feature map of H×W×2, and then undergoes a 7×7 convolution operation to reduce the dimension to 1 channel, i.e., H×W×1, and then generates a spatial attention feature map (fifth sub-feature map) through sigmoid (activation function), and finally multiplies the second sub-feature vector of the input and the spatial attention feature map to obtain the final generated sixth feature vector. For ease of understanding, the first spatial attention layer can be expressed by the following formula:

[0119] M s (F) = σ(f 7×7 ([AvgPool(F):MaxPool(F)]));

[0120]

[0121] Where M s (F) represents the fifth sub-feature map, F represents the second sub-feature vector, σ represents the activation function, f 7×7 Indicates 7*7 convolution, AvgPool(F), Indicates average pooling of the second sub-feature vector, MaxPool(F), Indicates maximum pooling of the second sub-feature vector, and [:] indicates channel concatenation.

[0122] It can be understood that through the above-mentioned first spatial attention layer, the text spatial information of the input image can be automatically located, thereby reducing the interference of the background on the task, thereby improving the recognition accuracy and robustness of the text recognition model, that is, improving the accuracy of text recognition; and the first spatial attention layer constructed in the above manner can better perform feature extraction of the spatial attention mechanism, thereby further improving the accuracy of text recognition.

[0123] To better understand the first downsampling layer of the embodiment of the present invention, as shown in FIG. Figure 4 As shown, the first downsampling layer includes a second normalization layer, a first convolutional layer and a first spatial attention layer.

[0124] In addition, the structures of the second downsampling layer and the third downsampling layer are substantially the same as those of the first downsampling layer, and are not described in detail here.

[0125] The text recognition method provided by the embodiment of the present invention can improve the extraction accuracy of the sixth feature vector by extracting the sixth feature vector in the above-mentioned manner; and because the first downsampling layer includes a first spatial attention layer, the spatial attention layer is used to pay more attention to the text part during the feature extraction process, thereby improving the extraction accuracy of the sixth feature vector, and ultimately improving the recognition accuracy of the text recognition model, that is, improving the text recognition accuracy.

[0126] Based on any of the above embodiments, in the method, the residual network layer includes a multi-branch feature extraction layer and a feature fusion layer connected in sequence.

[0127] The multi-branch feature extraction layer includes a first branch feature extraction layer, a second branch feature extraction layer and a third branch feature extraction layer connected in parallel; the first branch feature extraction layer includes a convolution layer, a layer standardization layer, a convolution layer, an activation layer, a global response normalization layer, a convolution layer and a random discard Dropout layer connected in sequence; the input and output of the second branch feature extraction layer are the same; the third branch feature extraction layer includes a convolution layer, an activation layer, a global response normalization layer and a Dropout layer connected in sequence.

[0128] Here, the multi-branch feature extraction layer includes multiple branch feature extraction layers, and different branch feature extraction layers have different convolution levels. Specifically, the first branch feature extraction layer includes 3 convolution layers; the second branch feature extraction layer is a blank layer, that is, no processing is performed; and the third branch feature extraction layer includes 1 convolution layer.

[0129] Here, the feature fusion layer is used to fuse the feature vectors output by the first branch feature extraction layer, the second branch feature extraction layer, and the third branch feature extraction layer. For example, the feature vectors output by the first branch feature extraction layer, the second branch feature extraction layer, and the third branch feature extraction layer are added.

[0130] Exemplarily, the activation layer in the first branch feature extraction layer is a GELU activation layer. The activation layer in the third branch feature extraction layer is a GELU activation layer.

[0131] Here, the Global Response Normalization (GRN) layer is used to normalize the feature maps on each channel, thereby enhancing the feature competition between channels. Compared with the batch normalization (BN) layer, the GRN layer has two advantages: first, it does not require additional parameters because it only normalizes the feature maps; second, it can handle batches of any size, while the BN layer needs to dynamically adjust parameters according to the batch size, which requires a large amount of calculation. The GRN layer can be divided into three steps: global feature aggregation, feature normalization, and feature calibration; in the global feature aggregation step, the feature maps on each channel are aggregated using the L2 norm to obtain an aggregated vector; in the feature normalization step, the aggregated vector is normalized using the standard division normalization function; in the feature calibration step, the normalized vector is used to calibrate the original feature map. The entire GRN layer has a very small amount of calculation, so it can be easily added to the convolutional neural network to enhance feature competition and improve the performance of the text recognition model.

[0132] To better understand the residual network layer of the embodiment of the present invention, Figure 5 As shown, the residual network layer includes a first branch feature extraction layer, a second branch feature extraction layer and a third branch feature extraction layer, the first branch feature extraction layer includes a convolutional layer, a layer standardization layer, a convolutional layer, an activation layer, a global response normalization layer, a convolutional layer and a random discard layer connected in sequence; the third branch feature extraction layer includes a convolutional layer, an activation layer, a global response normalization layer and a random discard layer connected in sequence.

[0133] The text recognition method provided by the embodiment of the present invention can perform feature extraction of three different branches in the above manner, and the feature extraction depths of different branches are different; and the features of the three branches can be fused, so as to improve the representation ability of the features and avoid the problems caused by the training model, thereby ultimately improving the accuracy of text recognition; in other words, the network depth can be increased in the above manner to better extract the features of the text image, thereby improving the extraction accuracy of the sequence feature vector, and ultimately improving the recognition accuracy of the text recognition model, that is, improving the text recognition accuracy; and the first branch feature extraction layer includes a global response normalization layer, and the third branch feature extraction layer includes a global response normalization layer, thereby enhancing the feature competition between feature channels, thereby improving the recognition accuracy of the text recognition model, that is, improving the text recognition accuracy.

[0134] Based on any of the above embodiments, in the method, the above step 120 includes:

[0135] Inputting the sequence feature vector into a seventh feature extraction layer in the encoding layer to obtain a first encoding vector output by the seventh feature extraction layer, wherein the seventh feature extraction layer includes a plurality of attention mechanism feature extraction layers connected in sequence, and the attention mechanism feature extraction layer includes a multi-head attention layer;

[0136] Inputting the first coding vector to a third standardization layer in the coding layer to obtain a second coding vector output by the third standardization layer;

[0137] The second encoding vector is input into the multi-layer perceptron layer in the encoding layer to obtain the encoding feature vector output by the multi-layer perceptron layer.

[0138] The attention mechanism feature extraction layer also includes at least one of the following: a layer normalization layer, a Dropout layer, a feature fusion layer, a multi-layer perceptron network layer, and the like.

[0139] Here, the multilayer perceptron (MLP) layer can be set according to actual needs. For example, the multilayer perceptron layer includes a linear layer, an activation layer, a Dropout layer, a linear layer and a Dropout layer connected in sequence.

[0140] To better understand the coding layer of the embodiment of the present invention, Figure 6 As shown, the encoding layer includes N attention mechanism feature extraction layers, a third normalization layer and a multi-layer perceptron layer (MLP Head) connected in sequence.

[0141] The text recognition method provided by the embodiment of the present invention can improve the encoding accuracy of the encoding feature vector by extracting the encoding feature vector in the above-mentioned manner; and because the attention mechanism feature extraction layer includes a multi-head attention layer, it can adaptively learn the different features of the sequence feature vector, that is, improve the parallel capability of the encoding layer to learn each feature vector in the sequence feature vector, so that the model is more interpretable, thereby improving the accuracy of text recognition; at the same time, through the multi-head attention layer, it is possible to give greater weight to the target data and related data, so that the "attention" of the encoding layer is focused on the target data, obtain information details, and achieve a reasonable vector representation of a longer input sequence, thereby improving the accuracy of text recognition; at the same time, the seventh feature extraction layer includes a plurality of attention mechanism feature extraction layers connected in sequence, thereby further improving the encoding accuracy of the encoding feature vector, and ultimately improving the accuracy of text recognition.

[0142] Based on any of the above embodiments, in the method, the attention mechanism feature extraction layer includes a layer normalization layer, a multi-head attention layer, a first Dropout layer, a first feature fusion layer, a layer normalization layer, a multi-layer perceptron network layer, a second Dropout layer and a second feature fusion layer connected in sequence;

[0143] The first feature fusion layer is used to fuse the input of the attention mechanism feature extraction layer and the output of the first Dropout layer;

[0144] The second feature fusion layer is used to fuse the output of the first feature fusion layer and the output of the second Dropout layer;

[0145] The multi-layer perceptron network layer includes a linear layer, an activation layer, a Dropout layer, a linear layer and a Dropout layer connected in sequence.

[0146] Exemplarily, the activation layer in the multilayer perceptron (MLP) network layer is a GELU activation layer.

[0147] To better understand the attention mechanism feature extraction layer of the embodiment of the present invention, as shown in Figure 7 As shown, the attention mechanism feature extraction layer includes a layer normalization layer, a multi-head attention layer (Multi-Head Attention), a first random discard layer, a layer normalization layer, a multi-layer perceptron network layer (MLP Block) and a second random discard layer connected in sequence.

[0148] To better understand the multi-layer perceptron network layer of the embodiment of the present invention, Figure 8 As shown, the multi-layer perceptron network layer includes a linear layer, an activation layer, a random dropout layer, a linear layer and a random dropout layer connected in sequence.

[0149] The text recognition method provided by the embodiment of the present invention can improve the encoding accuracy of the encoding feature vector by extracting the encoding feature vector in the above-mentioned manner; and because the attention mechanism feature extraction layer includes a multi-head attention layer, it can adaptively learn the different features of the sequence feature vector, that is, improve the parallel capability of the encoding layer to learn each feature vector in the sequence feature vector, so that the model is more interpretable, thereby improving the accuracy of text recognition; at the same time, through the multi-head attention layer, it is possible to give greater weight to the target data and related data, so that the "attention" of the encoding layer is focused on the target data, obtain information details, and achieve a reasonable vector representation of a longer input sequence, thereby improving the accuracy of text recognition.

[0150] The text recognition device provided by the present invention is described below. The text recognition device described below and the text recognition method described above can be referenced to each other.

[0151] Fig. 9 A structural diagram of a text recognition device provided by the present invention, such as Fig. 9 As shown, the text recognition device comprises:

[0152] A feature extraction module 910 is used to input the text image to be recognized into the first feature extraction layer in the text recognition model to obtain a sequence feature vector output by the first feature extraction layer;

[0153] A feature encoding module 920, configured to input the sequence feature vector into an encoding layer in the text recognition model to obtain an encoding feature vector output by the encoding layer, wherein the encoding layer includes a multi-head attention layer;

[0154] A text recognition module 930, configured to input the encoded feature vector into a decoding layer in the text recognition model to obtain a text recognition result output by the decoding layer, wherein the decoding layer includes a connection time classification CTC layer;

[0155] The text recognition model is trained based on the CTC loss function.

[0156] Fig.10 An example of a physical structure diagram of an electronic device is shown in FIG. Fig.10As shown, the electronic device may include: a processor 1010, a communication interface 1020, a memory 1030 and a communication bus 1040, wherein the processor 1010, the communication interface 1020 and the memory 1030 communicate with each other through the communication bus 1040. The processor 1010 may call the logic instructions in the memory 1030 to execute the text recognition method, which includes: inputting the text image to be recognized into the first feature extraction layer in the text recognition model to obtain the sequence feature vector output by the first feature extraction layer; inputting the sequence feature vector into the encoding layer in the text recognition model to obtain the encoding feature vector output by the encoding layer, wherein the encoding layer includes a multi-head attention layer; inputting the encoding feature vector into the decoding layer in the text recognition model to obtain the text recognition result output by the decoding layer, wherein the decoding layer includes a connection time classification CTC layer; wherein the text recognition model is trained based on the CTC loss function.

[0157] In addition, the logic instructions in the above-mentioned memory 1030 can be implemented in the form of software functional units and can be stored in a computer-readable storage medium when sold or used as an independent product. Based on such an understanding, the technical solution of the present invention, in essence, or the part that contributes to the prior art or the part of the technical solution, can be embodied in the form of a software product, which is stored in a storage medium and includes several instructions for 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 method described in each embodiment of the present invention. The aforementioned storage medium includes: various media that can store program codes, such as a USB flash drive, a mobile hard disk, a read-only memory (ROM), a random access memory (RAM), a disk or an optical disk.

[0158] On the other hand, the present invention also provides a non-transitory computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, is implemented to execute the text recognition method provided by the above-mentioned methods, the method comprising: inputting the text image to be recognized into the first feature extraction layer in the text recognition model to obtain the sequence feature vector output by the first feature extraction layer; inputting the sequence feature vector into the encoding layer in the text recognition model to obtain the encoding feature vector output by the encoding layer, the encoding layer comprising a multi-head attention layer; inputting the encoding feature vector into the decoding layer in the text recognition model to obtain the text recognition result output by the decoding layer, the decoding layer comprising a connection time classification CTC layer; wherein the text recognition model is trained based on the CTC loss function.

[0159] The device embodiments described above are merely illustrative, wherein the units described as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units, that is, they may be located in one place, or they may be distributed on multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the scheme of this embodiment. Ordinary technicians in this field can understand and implement it without paying creative labor.

[0160] Through the description of the above implementation methods, those skilled in the art can clearly understand that each implementation method can be implemented by means of software plus a necessary general hardware platform, and of course, it can also be implemented by hardware. Based on this understanding, the above technical solution is essentially or the part that contributes to the prior art can be embodied in the form of a software product, and the computer software product can be stored in a computer-readable storage medium, such as ROM / RAM, a disk, an optical disk, etc., including a number of instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to execute the methods described in each embodiment or some parts of the embodiments.

[0161] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit it. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or make equivalent replacements for some of the technical features therein. However, these modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present invention.

Claims

1. A method for character recognition, characterized in that: include: Inputting the text image to be recognized into the first feature extraction layer in the text recognition model to obtain the sequence feature vector output by the first feature extraction layer; Inputting the sequence feature vector into the encoding layer in the text recognition model to obtain the encoding feature vector output by the encoding layer, wherein the encoding layer includes a multi-head attention layer; Inputting the encoded feature vector into a decoding layer in the text recognition model to obtain a text recognition result output by the decoding layer, wherein the decoding layer includes a connection time classification CTC layer; Wherein, the text recognition model is trained based on the CTC loss function; The step of inputting the text image to be recognized into the first feature extraction layer in the text recognition model to obtain the sequence feature vector output by the first feature extraction layer includes: Inputting the text image into a first sub-feature extraction layer in the first feature extraction layer to obtain a first feature vector output by the first sub-feature extraction layer, wherein the first sub-feature extraction layer includes a convolution layer; Inputting the first feature vector into a second feature extraction layer in the first feature extraction layer to obtain a second feature vector output by the second feature extraction layer, wherein the second feature extraction layer includes a convolution layer and a spatial attention layer; Inputting the second feature vector into a pooling layer in the first feature extraction layer to obtain a third feature vector output by the pooling layer; Inputting the third feature vector into a first standardization layer in the first feature extraction layer to obtain a fourth feature vector output by the first standardization layer; Inputting the fourth feature vector into the first linear layer in the first feature extraction layer to obtain a sequence feature vector output by the first linear layer; The step of inputting the first feature vector to a second feature extraction layer in the first feature extraction layer to obtain a second feature vector output by the second feature extraction layer includes: Inputting the first feature vector to a third feature extraction layer in the second feature extraction layer to obtain a fifth feature vector output by the third feature extraction layer, wherein the third feature extraction layer includes three residual network layers connected in sequence; Inputting the fifth eigenvector into a first downsampling layer in the second feature extraction layer to obtain a sixth eigenvector output by the first downsampling layer, wherein the first downsampling layer includes a convolution layer and a spatial attention layer; Inputting the sixth feature vector into a fourth feature extraction layer in the second feature extraction layer to obtain a seventh feature vector output by the fourth feature extraction layer, wherein the fourth feature extraction layer includes three residual network layers connected in sequence; Inputting the seventh eigenvector into a second downsampling layer in the second feature extraction layer to obtain an eighth eigenvector output by the second downsampling layer, wherein the second downsampling layer includes a convolution layer and a spatial attention layer; Inputting the eighth feature vector into a fifth feature extraction layer in the second feature extraction layer to obtain a ninth feature vector output by the fifth feature extraction layer, wherein the fifth feature extraction layer includes nine residual network layers connected in sequence; Inputting the ninth eigenvector into a third downsampling layer in the second feature extraction layer to obtain a tenth eigenvector output by the third downsampling layer, wherein the third downsampling layer includes a convolution layer and a spatial attention layer; Inputting the tenth feature vector into a sixth feature extraction layer in the second feature extraction layer to obtain a second feature vector output by the sixth feature extraction layer, wherein the sixth feature extraction layer includes three residual network layers connected in sequence; The step of inputting the sequence feature vector into the encoding layer in the character recognition model to obtain the encoding feature vector output by the encoding layer includes: Inputting the sequence feature vector into a seventh feature extraction layer in the encoding layer to obtain a first encoding vector output by the seventh feature extraction layer, wherein the seventh feature extraction layer includes a plurality of attention mechanism feature extraction layers connected in sequence, and the attention mechanism feature extraction layer includes a multi-head attention layer; Inputting the first coding vector to a third standardization layer in the coding layer to obtain a second coding vector output by the third standardization layer; The second encoding vector is input into the multi-layer perceptron layer in the encoding layer to obtain the encoding feature vector output by the multi-layer perceptron layer.

2. The text recognition method according to claim 1, characterized in that: The step of inputting the fifth feature vector to a first down-sampling layer in the second feature extraction layer to obtain a sixth feature vector output by the first down-sampling layer includes: Inputting the fifth eigenvector into a second normalization layer in the first downsampling layer to obtain a first sub-eigenvector output by the second normalization layer; Inputting the first sub-feature vector into a first convolutional layer in the first downsampling layer to obtain a second sub-feature vector output by the first convolutional layer; The second sub-feature vector is input into the first spatial attention layer in the first downsampling layer to obtain a sixth feature vector output by the first spatial attention layer.

3. The text recognition method according to claim 1, characterized in that: The residual network layer includes a multi-branch feature extraction layer and a feature fusion layer connected in sequence; The multi-branch feature extraction layer includes a first branch feature extraction layer, a second branch feature extraction layer and a third branch feature extraction layer connected in parallel; The first branch feature extraction layer includes a convolution layer, a layer normalization layer, a convolution layer, an activation layer, a global response normalization layer, a convolution layer and a random dropout layer connected in sequence; The input and output of the second branch feature extraction layer are the same; The third branch feature extraction layer includes a convolutional layer, an activation layer, a global response normalization layer and a Dropout layer which are connected in sequence.

4. The text recognition method according to claim 1, characterized in that: The attention mechanism feature extraction layer includes a layer normalization layer, a multi-head attention layer, a first Dropout layer, a first feature fusion layer, a layer normalization layer, a multi-layer perceptron network layer, a second Dropout layer and a second feature fusion layer connected in sequence; The first feature fusion layer is used to fuse the input of the attention mechanism feature extraction layer and the output of the first Dropout layer; The second feature fusion layer is used to fuse the output of the first feature fusion layer and the output of the second Dropout layer; The multi-layer perceptron network layer includes a linear layer, an activation layer, a Dropout layer, a linear layer and a Dropout layer connected in sequence.

5. A text recognition device, characterized in that: include: A feature extraction module, used for inputting the text image to be recognized into the first feature extraction layer in the text recognition model to obtain the sequence feature vector output by the first feature extraction layer; A feature encoding module, used for inputting the sequence feature vector into the encoding layer in the text recognition model to obtain the encoding feature vector output by the encoding layer, wherein the encoding layer includes a multi-head attention layer; A text recognition module, used for inputting the encoded feature vector into a decoding layer in the text recognition model to obtain a text recognition result output by the decoding layer, wherein the decoding layer includes a connection time classification CTC layer; Wherein, the text recognition model is trained based on the CTC loss function; The step of inputting the text image to be recognized into the first feature extraction layer in the text recognition model to obtain the sequence feature vector output by the first feature extraction layer includes: Inputting the text image into a first sub-feature extraction layer in the first feature extraction layer to obtain a first feature vector output by the first sub-feature extraction layer, wherein the first sub-feature extraction layer includes a convolution layer; Inputting the first feature vector into a second feature extraction layer in the first feature extraction layer to obtain a second feature vector output by the second feature extraction layer, wherein the second feature extraction layer includes a convolution layer and a spatial attention layer; Inputting the second feature vector into a pooling layer in the first feature extraction layer to obtain a third feature vector output by the pooling layer; Inputting the third feature vector into a first standardization layer in the first feature extraction layer to obtain a fourth feature vector output by the first standardization layer; Inputting the fourth feature vector into the first linear layer in the first feature extraction layer to obtain a sequence feature vector output by the first linear layer; The step of inputting the first feature vector to a second feature extraction layer in the first feature extraction layer to obtain a second feature vector output by the second feature extraction layer includes: Inputting the first feature vector to a third feature extraction layer in the second feature extraction layer to obtain a fifth feature vector output by the third feature extraction layer, wherein the third feature extraction layer includes three residual network layers connected in sequence; Inputting the fifth eigenvector into a first downsampling layer in the second feature extraction layer to obtain a sixth eigenvector output by the first downsampling layer, wherein the first downsampling layer includes a convolution layer and a spatial attention layer; Inputting the sixth feature vector into a fourth feature extraction layer in the second feature extraction layer to obtain a seventh feature vector output by the fourth feature extraction layer, wherein the fourth feature extraction layer includes three residual network layers connected in sequence; Inputting the seventh eigenvector into a second downsampling layer in the second feature extraction layer to obtain an eighth eigenvector output by the second downsampling layer, wherein the second downsampling layer includes a convolution layer and a spatial attention layer; Inputting the eighth feature vector into a fifth feature extraction layer in the second feature extraction layer to obtain a ninth feature vector output by the fifth feature extraction layer, wherein the fifth feature extraction layer includes nine residual network layers connected in sequence; Inputting the ninth eigenvector into a third downsampling layer in the second feature extraction layer to obtain a tenth eigenvector output by the third downsampling layer, wherein the third downsampling layer includes a convolution layer and a spatial attention layer; Inputting the tenth feature vector into a sixth feature extraction layer in the second feature extraction layer to obtain a second feature vector output by the sixth feature extraction layer, wherein the sixth feature extraction layer includes three residual network layers connected in sequence; The step of inputting the sequence feature vector into the encoding layer in the character recognition model to obtain the encoding feature vector output by the encoding layer includes: Inputting the sequence feature vector into a seventh feature extraction layer in the encoding layer to obtain a first encoding vector output by the seventh feature extraction layer, wherein the seventh feature extraction layer includes a plurality of attention mechanism feature extraction layers connected in sequence, and the attention mechanism feature extraction layer includes a multi-head attention layer; Inputting the first coding vector to a third standardization layer in the coding layer to obtain a second coding vector output by the third standardization layer; The second encoding vector is input into the multi-layer perceptron layer in the encoding layer to obtain the encoding feature vector output by the multi-layer perceptron layer.

6. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that: When the processor executes the program, the text recognition method according to any one of claims 1 to 4 is implemented.

7. A non-transitory computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the text recognition method according to any one of claims 1 to 4 is implemented.