A text recognition method based on multi-scale fusion CRNN model
By using a multi-scale fusion CRNN model in the text recognition model, combined with different downsampling and pooling methods, the features are fused to expand the receptive field, which solves the problem of incomplete feature extraction in the existing technology and improves the accuracy and model of text recognition. Ease of training.
Patent Information
- Application Number
- CN202210450071.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-04-25
- Publication Date
- 2024-08-27
- Estimated Expiration
- 2042-04-25
AI Technical Summary
Existing text recognition models cannot effectively extract the complete features of each character in the image due to the small downsampling scale used when extracting features, resulting in poor recognition results for larger text, and a single downsampling method is not conducive to better recognition. Extract image features.
A multi-scale fusion CRNN model is used to extract features by using different downsampling scales in the convolution layer, combined with MaxPooling and AvgPooling methods, to fuse features of different scales to expand the receptive field, improve text feature extraction capabilities, and learn context in the loop layer information, and finally output the prediction result through the CTC loss function.
It improves the accuracy of text recognition and can better extract image features, making it easier to distinguish different types of characters. It is also relatively easy to train the model and achieve better recognition results.
Smart Images

Figure CN114821563B
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of text recognition, and in particular to a text recognition method based on a multi-scale fusion CRNN model (MSF-CRNN). Background Art
[0002] Scene text recognition refers to the recognition of a set of text sequences with semantic information in real scenes, such as the text content on billboards and road signs. The recognition result is usually a text of variable length. Scene text recognition has a wide range of applications in the field of computer vision, including autonomous driving, intelligent robots and other fields.
[0003] Image recognition methods based on convolutional neural networks (CNNs) have successfully broken through the bottleneck of traditional methods that require manual extraction of image features in many computer vision tasks. Common convolutional neural networks such as LeNet-5, AlexNet, VGG, and ResNet have made great breakthroughs in image recognition accuracy. During training, convolutional neural networks use forward propagation and back propagation, and perform gradient descent to automatically learn feature information in the image, greatly improving the recognition accuracy of a single word. However, to recognize text sequences with contextual semantics, it is also necessary to combine methods such as dynamic programming, dictionary search, and conditional random fields (CRF).
[0004] Text recognition models that combine Convolutional Neural Network (CNN) and Recurrent Neural Network (RNN) (such as CRNN, RARE and other models) extract image features and learn contextual semantic information through deep learning, which significantly improves the accuracy of identifying text with contextual semantics and has become the current mainstream text recognition framework.
[0005] The current mainstream text recognition framework usually inputs images with text into a convolutional neural network (CNN) to learn a set of feature sequences, and then inputs the feature sequences into a recurrent neural network (RNN) to learn context information, and finally outputs text according to the length of the feature sequence, thereby realizing text recognition of different lengths.
[0006] However, when learning image features through a convolutional neural network (CNN), in order to obtain more feature sequences, the model usually uses a special downsampling method (such as 2×1 pooling), that is, the height is reduced to 1 / 2 of the original, but the width remains unchanged. Although this method can obtain more feature sequences, it cannot extract features from larger surrounding areas due to the small receptive field, making it difficult to recognize larger text. In addition, the single downsampling method used by the convolutional neural network is not conducive to better extraction of image features. Summary of the invention
[0007] In order to solve the problem that the current mainstream scene text recognition model uses a smaller downsampling scale to obtain more features when extracting features, resulting in the inability to better extract the complete features of each character in the image. The present invention proposes a text recognition method based on a multi-scale fusion CRNN model. By fusing different scales, the receptive field when extracting features is expanded and more text features are extracted, thereby improving the accuracy of text recognition.
[0008] In order to achieve the above object, the technical solution adopted by the present invention is:
[0009] A text recognition method based on a multi-scale fusion CRNN model. When the input image is extracted through the convolution layer of the MSF-CRNN model, different downsampling scales are used to obtain feature outputs of two different scales. Then, the features of different scales are fused in the feature fusion layer to obtain a new feature sequence, thereby extracting the features of the image more accurately. Then, the feature sequence is input into the recurrent layer to learn the context information, and finally the predicted result is output in the transcription layer.
[0010] Specifically, in the text recognition method based on the multi-scale fusion CRNN model:
[0011] The MSF-CRNN model adds multiple scales to VGG in the convolutional layer and constructs a convolutional neural network MS-VGG to extract image features. For an input image (size 32×40×1), where the height is 32, the width is 40, and the number of channels is 1, after downsampling by MS-VGG, two feature sequences of different scales are obtained, namely Scale A and Scale B. The length of the feature sequence of Scale A is 10, and the length of the feature sequence of Scale B is 5.
[0012] In the feature fusion layer, Scale B is upsampled to obtain Scale B', and then Scale A and Scale B' are fused to obtain a feature sequence of length 10;
[0013] In the recurrent layer, the feature sequence is input into the recurrent neural network with a length of 10 to learn the context features. For the recurrent neural network, each input will get an input result;
[0014] In the transcription layer, the output of the loop layer is passed through the CTC loss function to obtain the final result.
[0015] The present invention not only expands the receptive field when extracting features but also extracts more text features by fusing different scales, thereby improving the accuracy of text recognition. Experiments show that on scene text datasets such as IIIT-5K, Street ViewText, ICDAR2003, and ICDAR2013, the text recognition accuracy of the model with multi-scale fusion is better than that of the model without multi-scale fusion. Compared with the prior art, the beneficial effects of the present invention are as follows:
[0016] 1. The addition of a multi-scale fusion model expands the receptive field when extracting image features, and can see features in a larger range, so it has a better recognition effect on text.
[0017] 2. Two different downsampling methods are used to extract more image feature information. MaxPooling is used to extract smaller scales, and AvgPooling is used to extract larger scales. This can extract image features more comprehensively, making it easier to distinguish different types of characters.
[0018] 3. The fusion method of add can well fuse the features of two different scales. After using add, the network training is easier than other fusion methods, and a good recognition effect can be achieved faster. BRIEF DESCRIPTION OF THE DRAWINGS
[0019] Figure 1 This is an introduction to the overall model of MSF-CRNN.
[0020] Figure 2 The expression of Scale A and Scale B is 1#.
[0021] Figure 3 The expression of Scale A and Scale B is 2#.
[0022] Figure 4 Output results of two different scales for the convolutional layer.
[0023] Figure 5 It is the network structure of VGG.
[0024] Figure 6 This is the implementation method of Max Pooling and Avg Pooling downsampling.
[0025] Figure 7 Use different downsampling methods to extract features for MS-VGG.
[0026] Figure 8 It is the upsampling method of the feature sequence Feature Sequence.
[0027] Fig. 9 It is a fusion of Scale A and Scale B'.
[0028] Fig.10 is the output probability matrix of the recurrent layer.
[0029] Fig.11 Comparison between MSF-CRNN and CRNN. DETAILED DESCRIPTION
[0030] Example 1
[0031] Aiming at the problem that too small downsampling scale leads to poor text recognition effect, the present invention proposes a text recognition method based on a multi-scale fusion CRNN model, and constructs a model named Multiple Scales Fusion CRNN (MSF-CRNN). The overall structure of MSF-CRNN is divided into four layers, namely, a convolutional layer, a feature fusion layer, a recurrent layer and a transcription layer. The present invention uses a VGG network in the convolutional layer, a BiLSTM network in the recurrent layer, and a CTC loss function in the transcription layer.
[0032] For an input image, it first passes through the convolution layer, then the fusion layer, then the circulation layer, and finally enters the transcription layer to obtain the final result. When extracting features in the convolution layer, the MSF-CRNN model constructed by the present invention uses different downsampling scales to obtain feature outputs of two different scales, and then fuses the features of different scales in the feature fusion layer to obtain a new feature sequence, thereby more accurately extracting the features of the image, and then inputting the feature sequence into the circulation layer to learn the context information, and finally outputting the predicted result in the transcription layer.
[0033] 1. Introduction to the overall model of MSF-CRNN
[0034] Figure 1 The overall structure of MSF-CRNN is shown, which is divided into four layers: Convolutional Layer, Feature Fusion Layer, Recurrent Layer and Transcription Layer.
[0035] The present invention adds multiple scales to VGG in the convolution layer and constructs a new convolutional neural network Multiple Scales VGG (MS-VGG) to extract image features. For an input image (32×40×1), where the height is 32, the width is 40, and the number of channels is 1 (grayscale images have only one channel), after downsampling by MS-VGG, two feature sequences of different scales are obtained, namely Scale A and Scale B. The length of the feature sequence of Scale A is 10, and the length of the feature sequence of Scale B is 5.
[0036] In the feature fusion layer, Scale B is upsampled to obtain Scale B', and then Scale A and Scale B' are fused to obtain a feature sequence with a length of 10.
[0037] In the recurrent layer, the feature sequence is input into the recurrent neural network with a length of 10 to learn the context features. For the recurrent neural network, each input will get an input result. If the size of the input feature sequence is (1×10×512), 10 output results will be obtained. Figure 1 The 10 results shown are -A-FTTERR-.
[0038] In the transcription layer, the output of the loop layer is passed through Connectionist Temporal Classification (CTC) to obtain the final result, that is, converting -A-FTTERR- to AFTER( Figure 1 shown).
[0039] During recognition, the model input is a text line image. Before text recognition, it is preprocessed with enhancement operations such as Gaussian blur to increase the diversity of samples and improve the recognition ability of the model. Specifically:
[0040] The image is scaled to a specified size, the height is uniformly set to 32, and the width is adjusted while maintaining the aspect ratio, because the model stipulates that the height of the image must be 32; the color image is converted to a grayscale image, because the image is independent of color.
[0041] 2. Convolutional Layer
[0042] The current popular text recognition framework combines convolutional neural networks (CNN) and recurrent neural networks (RNN). The input image first passes through the convolutional neural network (CNN) to obtain a feature sequence, and then is sent to the recurrent neural network (RNN) to learn the relationship between contexts, and then the final prediction result is obtained through Connectionist Temporal Classification (CTC).
[0043] If the Convolutional Neural Network (CNN) uses different downsampling scales, it will get feature sequences of different lengths. If an image is downsampled to 1 / 32, 1 / 16, 1 / 8, or 1 / 4 of its original size, its expressive power will be different. Figure 2 As shown in the figure, Scale A means downsampling to 1 / 8 of the original, and Scale B means downsampling to 1 / 4 of the original. If the width of the image is downsampled to 1 / 8 of the original, the number of feature sequences obtained is the largest, and smaller characters can be expressed more clearly. However, there will also be other problems. For some different characters, the results obtained after downsampling may be the same, so it is impossible to accurately identify what character it is.
[0044] like Figure 3 As shown in the figure, Scale A can predict 10 characters, while Scale B can only predict 5 characters. It can be seen that the first and fifth blocks in Scale A are exactly the same, so after the convolutional neural network (CNN), the same result will be obtained, but it expresses two different letters, H and F. Even if the recurrent layer is used to learn the features of the context, it will affect the recognition accuracy.
[0045] In Scale B, we can see that in block IV, e and i are in the same grid. One grid can only recognize one character, but there are two characters, which affects the accuracy of text recognition.
[0046] Therefore, in order to better extract the information of the text, the Multiple ScalesVGG (MS-VGG) in the MSF-CRNN constructed by the present invention obtains results of two different scales through different downsampling. An image with a width, height, and number of channels of W, H, and C is input into the convolutional layer using multi-scale VGG, and two scales of output are obtained, which are named Scale A and Scale B. The scale of Scale A is [1, W / 4, C], and the scale of Scale B is [1, W / 8, C].
[0047] Figure 4 The results of two different scales are shown in Figure 1. Scale A uses a 2×1 pooling method, and Scale B uses a 2×2 pooling method. In Scale A, the features of smaller text are extracted, and in Scale B, the features of larger text are extracted.
[0048] In the network structure of the convolutional neural network VGG, VGG successively goes through 2 convolutions, 1 downsampling, 2 convolutions, 1 downsampling, 3 convolutions, 1 downsampling, 3 convolutions, 1 downsampling, 3 convolutions, 1 downsampling, 3 convolutions, 1 downsampling, and finally gets the result through full connection and softmax, so VGG has a total of 13 convolutions and 5 downsamplings.
[0049] Common downsampling methods include MaxPooling, AvgPooling, etc. Figure 6 The implementation of Max Pooling and Avg Pooling is shown. Max Pooling takes the maximum value in the region, while Avg Pooling takes the average value in the region. Max Pooling retains the most "important" features in the local region when downsampling, and determines the image category based on the important features. Avg Pooling selects the average features in the region when downsampling, which can more clearly reflect the global characteristics of the region.
[0050] In order to better learn the features of the image, the combination of MaxPooling and AvgPooling is used in Mulitple Scales VGG (MS-VGG). Based on the original VGG, the last two downsampling methods are used, MaxPooling and AvgPooling, to obtain Scale A and Scale B respectively. For Scale A, the MaxPooling downsampling method is used to obtain the most important features in the area, while for Scale B, the AvgPooling downsampling method is used to obtain the average features of the entire area. By fusing the two features of Scale A and Scale B, the features of the image can be better extracted, thereby improving the accuracy of recognition. Figure 7 The overall structure of MS-VGG is shown. The model is divided into two branches. ScaleA uses the MaxPooling downsampling method, and Scale B uses the AvgPooling downsampling method. In order to speed up the training, some parts of the model use a common convolutional layer.
[0051] 3. Feature Fusion Layer
[0052] In order to fuse features of two different scales (Scale A and Scale B) to better express the features of the image, the present invention upsamples Scale B to obtain Scale B' so that Scale A and Scale B' have the same size. Then Scale A and Scale B' are fused.
[0053] 3.1 Upsampling of Scale B
[0054] In order to merge Scale A and Scale B, Scale B needs to be upsampled to get Scale B'. The upsampling method is as follows: Figure 8 shown.
[0055] Suppose the original feature sequence is V1, and after upsampling (Up Sample) we get V2.
[0056] Assume that the size of V1 is [1, ω, c], then the size of V2 is [1, 2ω, c], where 1 represents the height, ω represents the width, and C represents the number of channels. V2 is obtained by formula (1)
[0057]
[0058] 3.2 Fusion of ScaleA and Scale B'
[0059] Fig. 9 The fusion of ScaleA and Scale B' is shown. Currently, there are two mainstream fusion methods: (1) concat (2) add. Among them:
[0060] (1) Concat fusion is to superimpose the two results, and the number of channels obtained is 2×c. For example, if the size of Scale A is [1, 10, 512], and the size of Scale B is [1, 10, 512], after fusion, [1, 10, 1024] is obtained. Since the number of channels of the recurrent layer input is set to 512, it is necessary to convert the 1024 channels into 512 channels through 1×1 convolution, thereby increasing the amount of training.
[0061] (2) Add fusion is to add corresponding elements. For example, if the size of ScaleA is [1, 10, 512] and the size of Scale B is [1, 10, 512], by adding corresponding elements, the result is still [1, 10, 512], which can be directly sent to the recurrent layer to learn context information.
[0062] In Experiment 2 of the experimental part of Example 2, the accuracy of concat and add is compared, because the result obtained by concat needs to undergo 1×1 convolution, which increases both the training time and the difficulty of training. The MSF-CRNN model proposed in the present invention uses the add method for fusion.
[0063] FS i =ScaleA i +ScaleB′ i
[0064] 4. Recurrent Layer
[0065] In order to better learn the context information, the present invention uses a bidirectional recurrent neural network (Bi-directional Recurrent Neural Network) so that the network can learn both the previous information and the following information.
[0066] There are two mainstream bidirectional recurrent neural networks (Bi-directional RNN), namely Bi-directional Long Short Term Memory (BiLSTM) and Bi-directional Gated Recurrent Unit (BiGRU). In order to obtain higher accuracy, the MSF-CRNN model constructed in the present invention adopts BiLSTM as a bidirectional recurrent neural network (Bi-directional Recurrent Neural Network) of the recurrent layer.
[0067] In order to verify the reliability of the model, experiments were conducted using the BiLSTM and BiGRU models in Experiment 3 of the experimental part of Example 2. The experimental results show that BiLSTM has a higher accuracy, but requires more model parameters. BiGRU, on the contrary, has a lower accuracy, but uses fewer model parameters.
[0068] The feature sequence of scale [1, W / 4, C] is input into the recurrent neural network one by one with a length of W / 4 to learn the contextual semantic information. One input corresponds to one output, and the output is a probability matrix of [n, W / 4] (n rows, W / 4 columns) (such as Fig.10 As shown in the figure, n represents the number of letters, and each column represents the probability that an image block is a certain letter. That is, a picture is divided into W / 4 image blocks, and each image block predicts a word, so theoretically at most W / 4 letters can be predicted.
[0069] 5. Transcription layer
[0070] The transcription layer uses the conditional probability defined by the Connectionist Temporal Classification (CTC) proposed by Graves et al. to convert the prediction results of each frame of the recurrent layer into a label sequence. Fig.10 The output of each frame of the recurrent layer is shown. The output of each frame is a vector that represents the probability of a certain character. From a mathematical point of view, transcription is to find the label sequence with the highest probability under the condition of prediction of each frame. In practice, there are two transcription modes, namely dictionary-free transcription and dictionary-based transcription. The dictionary refers to all possible words that are pre-set, and then the output results are matched with the words in the dictionary. However, the model proposed in this invention can predict any word, so there is no pre-set dictionary.
[0071] Define the output of the loop layer y = y 1 ,y 2 ,y 3, ..., y T , where T represents the length of the feature sequence, y i is a vector of length n, n represents the number of all characters to be predicted plus a blank character (if only lowercase English letters are predicted, then n=26+1=27). Represents vector y i Predict the probability of the kth character, so
[0072] Define a mapping function B, whose input π=(π1,π2,π3,...,π T ), the output is L, that is, B(π) = L. The mapping function B performs the following two steps in sequence: (1) removes consecutive repeated characters and (2) removes blank characters.
[0073] For example: B(--hh-el-ll-oo--) = hello, B(-hhh-eel-llloo--) = hello.
[0074] P(π|y) represents the probability of getting π under the condition of input y, and its calculation is shown in formula (2). Indicates that the i-th output prediction is the character π i probability.
[0075]
[0076] P(L|y) represents the probability of obtaining label L under the condition of input y, and its calculation is shown in the following formula:
[0077]
[0078] When P(L|y) reaches its maximum value, it is π, I * =B(π) as the prediction result, but if an accurate search method is used, it will take a lot of time. In order to speed up the search, a fuzzy search strategy is adopted. Under this strategy, I * ≈B(argmax π P(π|y)), that is, each P(π|y) only outputs the maximum probability.
[0079] 6. Loss Function
[0080] Select the optimizer for model update, control the amplitude of parameter update by setting the learning rate of each step, calculate the gradient value of the loss function, and update the parameters of the model through gradient descent. After the model is updated for a certain number of iterations, the model definition and parameters can be saved as a file for subsequent reasoning.
[0081] The present invention sets the loss function O as the negative log-likelihood function of the conditional probability, and minimizes the loss function through training.
[0082]
[0083] X={I i , L i} represents the training set, I i represents the training image, L i represents the true label sequence, y i Represents the output of the recurrent layer.
[0084] Example 2 Experimental Results and Analysis
[0085] 1. Benchmark Datasets
[0086] To evaluate the performance of the algorithm, the present invention uses four commonly used scene text recognition datasets for performance evaluation, namely ICDAR2003 (IC03), ICDAR2013 (IC13), IIIT 5k-word (IIIT5k) and Street View text (SVT).
[0087] The ICDAR2003 dataset consists of 251 scene images with labels. Images containing only letters or numbers with more than or equal to 3 characters are cropped. Finally, 1823 images with characters are obtained, of which 936 images are used as training sets and 860 images are used as test sets.
[0088] The ICDAR2013 dataset consists of 462 (229 for training and 233 for testing) natural scene images annotated in English. Images containing only numbers or letters and with a character count of 3 or more were cropped, resulting in 680 training images and 857 testing images.
[0089] The IIIT 5k-word dataset contains 3,000 cropped word test images collected from the Internet, cropping out images that only contain numbers or letters, ultimately resulting in 2,000 training images and 3,000 test images.
[0090] The Street View text dataset contains 249 street view images collected from Google Street View. Images containing only numbers or letters are cropped, resulting in 647 training images and 257 test images.
[0091] 2. Evaluation Metrics
[0092] Since text recognition and image classification are different, in order to better evaluate the effect of model recognition, the present invention uses two indicators for evaluation, namely, average accuracy (AP) and character accuracy (APc).
[0093] (1) Average Precision (AP)
[0094]
[0095] corrent_num indicates the number of correct answers, and all indicates the total number.
[0096] (2) Average Precision of Character (APc)
[0097] It is used to compare the similarity between two strings. The calculation method is the SequenceMatcher method in the difflib library of Python 3. The Python code is:
[0098] import difflib
[0099] ratio=difflib.SequenceMatcher(None, str1, str2).ratio()
[0100] The calculation steps are to compare the similarity between string a and string b.
[0101] Find the same substrings s1s2, ..., s of strings a and b n . and s1, s2, ..., s n There are two constraints that must be met:
[0102] ①end(s i )<start(s i+1 )1≤i≤n-1, where start represents the substring s i The first character of the string a is the subscript, and end represents the substring s i The last character of a is the subscript of string a.
[0103] ② and The sum of the lengths of the common substrings does not exceed that of string a and string b.
[0104] The similarity ratio calculation formula between string a and string b is as follows:
[0105]
[0106] Indicates the length of the string
[0107] For example: suppose string a = "12345633666", string b = "1123456666". Then the length of string a is 11, and the length of string b is 10. The common substrings of string a and string b are s1 = "123456" and s2 = "666", where the length of s1 is 6 and the length of s2 is 3. Then the similarity ratio calculation formula of string a and string b is as follows.
[0108]
[0109] 3. Implementation details
[0110] The training and testing of the model of the present invention were implemented using Python on a desktop computer with an Intel i5-9500 CPU (3.00GHz), 32GB RAM and GTX 1080Ti 11GB.
[0111] The code uses the PyTorch deep learning framework, scales the input images proportionally, changes the height to 32, and sets the learning rate to 3×10 -3 , the gradient descent method uses Adam, the exponential decay rate of the first-order moment estimate is 0.5, and the exponential decay rate of the second-order moment estimate is 0.999.
[0112] 4. Model performance comparison
[0113] 4.1 Quantitative comparison
[0114] Fig.11 The results predicted by MSF-CRNN with multi-scale fusion and CRNN without multi-scale fusion are shown. It can be seen that the CRNN model without multi-scale fusion uses too small a downsampling scale to obtain more feature sequences, and cannot fully extract the information of the entire text during recognition, resulting in a decrease in recognition accuracy. MSF-CRNN adds multi-scale fusion, obtains results of different scales through downsampling at different scales, and fuses the results of different scales, so that MSF-CRNN can predict larger text more accurately. In the figure:
[0115] In sequence number ①, although CRNN recognizes "2", the other half is mistakenly identified as d due to its too small receptive field. However, MSF-CRNN is more able to correctly identify it as 2 due to multi-scale fusion.
[0116] In sequence number ②, CRNN can only extract half of the features of the number "4" due to its too small receptive field and recognize it as A, while MSF-CRNN fuses features of different scales to extract more comprehensive information and correctly recognizes it as 4. In ③, ④, ⑤, and ⑥, CRNN also makes mistakes in recognition due to its too small receptive field.
[0117] 4.2 Qualitative comparison
[0118] In order to verify the effectiveness of the model, the present invention conducted three experiments. The first experiment compared the different effects of features of different scales on the results. The second experiment compared the recognition accuracy of the two fusion methods of add and concat. The third experiment proved that the MSF-CRNN model with multi-scale fusion has higher text recognition accuracy than the CRNN without multi-scale model. In order to further verify the reliability of the model, Experiment 3 also used BiLSTM and BiGRU in the recurrent layer for comparison.
[0119] Experiment 1: Comparison of the effects of different downsampling
[0120] In order to verify that features of different scales will affect the results, the CRNN model without multi-scale fusion was used on the ICDAR2003 dataset to obtain the results after downsampling at different scales. S4, S8, and S16 represent the accuracy of downsampling to 1 / 4, 1 / 8, and 1 / 16 of the original scale, respectively, where S4 corresponds to Scale A and S8 corresponds to Scale B.
[0121] Table 1: Recognition accuracy of feature sequences extracted at different scales
[0122] Average accuracy AP Character accuracy APc S4 46.3 77.4 S8 25.3 72.1 S16 5.3 44.0
[0123] From Table 1, we can see that different downsampling scales have different effects on the results. The best effect is achieved when the downsampling scale is S4, followed by S8, and the worst effect is S16. This is mainly because the downsampling scale of S16 is too large, resulting in only one result for multiple characters, which reduces the accuracy.
[0124] S4 corresponds to Scale A, and S8 corresponds to Scale B. It can be seen from the experimental data that the accuracy of S4 and S8 is not much different, but the accuracy of S8 and S16 is quite different, indicating that both S4 and S8 can extract image features relatively well. Therefore, the model proposed in the present invention combines S4 and S8 to complement their advantages, thereby obtaining better recognition effect.
[0125] Experiment 2: Comparison of different fusion methods
[0126] In order to compare the two fusion methods of add and concat, the MSF-CRNN model uses two different fusion methods to obtain the accuracy on the dataset ICDAR2003.
[0127] Table 2: Comparison of accuracy of different fusion methods
[0128] Average accuracy AP Character accuracy APc MSF-CRNN+concat 10 58.3 MSF-CRNN+add 50.4 81.4
[0129] From Table 2, we can see that the accuracy of add is higher than that of concat, mainly because:
[0130] 1) concat changes the number of channels of the image through 1×1 convolution, which makes training difficult, increases training time and makes it difficult to converge to a good effect. 2) concat is the superposition of two features, which cannot well fuse the features of two scales. 3) add adds the elements corresponding to the two features, which can well fuse the characteristics of two different scales, and the calculation is simpler and the training is relatively easy. Therefore, add is used for fusion in the MSF-CRNN model proposed in the present invention.
[0131] Experiment 3: Comparison between MSF-CRNN and CRNN
[0132] In order to verify the effectiveness of the model, the MSF-CRNN model with multi-scale fusion and the CRNN without multi-scale fusion were experimented on the ICDAR2003, ICDAR2013, IIIT5K, and SVT datasets respectively. The results are shown in Table 3.
[0133] Table 3: Comparison results between MSF-CRNN and CRNN on different datasets
[0134]
[0135] The experimental data show that the MSF-CRNN model with multi-scale fusion has improved APc by 4.0%, 4.8%, 2.0% and 1.7% on the ICDAR2003, ICDAR2013, IIIT5K and SVT datasets respectively compared with the CRNN model without multi-scale fusion. Both AP and APc have been improved to a certain extent, and the number of model parameters has not changed much, which proves that the recognition accuracy of the model with multi-scale fusion is higher than that without multi-scale fusion.
[0136] The present invention can improve the accuracy of text recognition mainly due to the following reasons:
[0137] (1) The addition of a multi-scale fusion model expands the receptive field when extracting image features, and can see features in a larger range. (2) Two different downsampling methods are used to extract more image feature information. MaxPooling is used to extract smaller scales, and AvgPooling is used to extract larger scales. This can extract image features more comprehensively, making it easier to distinguish different types of characters. (3) The fusion method of add can well fuse features of two different scales, and the network training after using add is easier than other fusion methods, and a good recognition effect can be achieved faster.
[0138] In order to further verify the reliability of the model, the present invention also uses BiGRU in the convolutional layer to learn context information. Table 4 shows the comparison results of the MSF-CRNN model with multi-scale fusion and the CRNN model without multi-scale fusion on different data sets when BiGRU is used in the convolutional layer.
[0139] Table 4: Comparison results between MSF-CRNN and CRNN using BiGRU on different datasets
[0140]
[0141] The experimental results further prove that when BiGRU is used in the recurrent layer, the MSF-CRNN model with multi-scale fusion can also improve the accuracy of scene text recognition compared to CRNN without multi-scale fusion model.
[0142] Using different recurrent neural networks through the recurrent layer shows that different recurrent neural networks have their own advantages. When the recurrent layer uses BiLSTM, its recognition accuracy is higher, but the number of parameters required is also larger. When the recurrent layer uses BiGRU, its recognition accuracy is slightly lower, but the number of parameters required is also relatively small. Therefore, different recurrent neural networks can be used according to different needs. And when using different recurrent neural networks, adding multi-scale fusion MSF-CRNN can achieve better results than the model without multi-scale fusion.
[0143] The above contents are merely examples and explanations of the concept of the present invention. The technicians in this technical field may make various modifications or additions to the specific embodiments described or replace them in a similar manner. As long as they do not deviate from the concept of the invention or exceed the scope defined by the claims, they should all fall within the protection scope of the present invention.
Claims
1. A text recognition method based on multi-scale fusion CRNN model, It is characterized in that When the input image is extracted through the convolution layer of the MSF-CRNN model, different downsampling scales are used to obtain feature outputs of two different scales. Then, the features of different scales are fused in the feature fusion layer to obtain a new feature sequence, thereby extracting the features of the image more accurately. Then, the feature sequence is input into the recurrent layer to learn the context information, and finally the prediction result is output in the transcription layer. The MSF-CRNN model adds multi-scales to VGG in the convolutional layer and constructs a convolutional neural network MS-VGG to extract image features. For an input image with a height of 32, a width of 40, and a channel number of 1, two feature sequences of different scales are obtained after downsampling by MS-VGG, namely Scale A and Scale B. The length of the feature sequence of Scale A is 10, and the length of the feature sequence of Scale B is 5. In the feature fusion layer, Scale B is upsampled to obtain Scale B', and then Scale A and Scale B' are fused to obtain a feature sequence of length 10. In the recurrent layer, the feature sequence is input into the recurrent neural network with a length of 10 to learn the features of the context. For the recurrent neural network, each input will obtain an input result. In the transcription layer, the output of the recurrent layer is subjected to the CTC loss function to obtain the final result. When the convolution layer of the MSF-CRNN model is used for recognition, the input of the model is a text line image. Before text recognition, it is preprocessed with Gaussian blur enhancement operation to improve the diversity of samples and the recognition ability of the model. Specifically, the image is scaled to a specified size, the height is uniformly set to 32, and the width is adjusted while maintaining the aspect ratio; at the same time, the color image is converted into a grayscale image; The MS-VGG in the convolution layer of the MSF-CRNN model obtains results of two different scales through different downsampling; the image with width, height and number of channels W, H and C is input into the convolution layer using multi-scale VGG, and two scales of output are obtained, named Scale A and Scale B respectively; the scale of Scale A is [1, W / 4, C], and the scale of Scale B is [1, W / 8, C]; Scale A uses 2×1 pooling, and Scale B uses 2×2 pooling; the features of smaller text are extracted in Scale A, and the features of larger text are extracted in Scale B; Scale A uses MaxPooling downsampling to obtain the most important features in the area, while Scale B uses AvgPooling downsampling to obtain the average features of the entire area; by fusing the two features of Scale A and Scale B, the features of the image can be better extracted, thereby improving the recognition accuracy; In the feature fusion layer of the MSF-CRNN model, Scale B is upsampled to obtain Scale B', so that Scale A and Scale B' have the same size; then Scale A and Scale B' are fused using the add method; Let the original feature sequence be V 1 , after up sampling (Up Sample) to get V 2 ; Let V 1 The size of V is [1,ω,c], then 2 The size of V is [1,2ω,c], where 1 represents the height, ω represents the width, C represents the number of channels, and V 2 From formula (1), we can get The MSF-CRNN model uses BiLSTM as a bidirectional recurrent neural network in the recurrent layer. The feature sequence of scale [1, W / 4, C] with a length of W / 4 is input into the recurrent neural network one by one to learn contextual semantic information. One input corresponds to one output, and the output is a probability matrix of [n, W / 4]; n represents the number of letters, and each column represents the probability that an image block is a certain letter, that is, a picture is divided into W / 4 image blocks, and each image block predicts a word; The transcription layer of the MSF-CRNN model uses the CTC loss function to convert the prediction results of each frame of the recurrent layer into a label sequence; Define the output of the loop layer y = y 1 ,y 2 ,y 3 ,...,y T , where T represents the length of the feature sequence, y i is a vector of length n, n represents the number of all characters to be predicted plus a blank character. If only lowercase English letters are predicted, then n = 26 + 1 = 27; Represents vector y i Predict the probability of the kth character, so Define a mapping function B, whose input π=(π 1 ,π 2 ,π 3 ,...,π T ), the output is L, that is, B(π) = L; the mapping function B performs the following two steps in sequence: (1) removes consecutive repeated characters; (2) removes blank characters; P(π|y) represents the probability of getting π under the condition of input y, and its calculation is shown in formula (2). Indicates that the i-th output prediction is the character π i probability; P(L|y) represents the probability of obtaining label L under the condition of input y, and its calculation is shown in the following formula: When P(L|y) reaches its maximum value, it is π, I * =B(π) as the prediction result, but if an accurate search method is used, it will take a lot of time. In order to speed up the search, a fuzzy search strategy is adopted. Under this strategy, I * ≈B(argmax π P(π|y)), that is, each P(π|y) only outputs the maximum probability.
2. The text recognition method based on the multi-scale fusion CRNN model as claimed in claim 1, It is characterized in that Select the optimizer for model update, control the amplitude of parameter update by setting the learning rate of each step, calculate the gradient value of the loss function, and update the parameters of the model through gradient descent. After the model is updated for a certain number of iterations, the model definition and parameters can be saved as a file for subsequent reasoning. The loss function O is set as the negative log-likelihood function of the conditional probability, and the loss function is minimized through training; X={I i ,L i } represents the training set, I i represents the training image, L i represents the true label sequence, y i Represents the output of the recurrent layer.
