Text recognition method and device
Through feature channel expansion and feature enhancement processing, advanced features of the text recognizer are extracted, which solves the complexity and deployment problems of the existing text recognizer model, and realizes the localized deployment and efficient recognition capabilities of the lightweight text recognition model.
Patent Information
- Application Number
- CN202410715887.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-06-04
- Publication Date
- 2024-08-30
AI Technical Summary
The model structure of existing text recognizers is complex and large, making it impossible to deploy locally and unable to meet the local deployment needs of users.
By obtaining the text image to be recognized, feature extraction and feature channel expansion processing are performed, the initial feature map is expanded into a multi-channel feature map, and advanced features are extracted from the multi-channel feature map, using the progressive feature channel expansion network and feature enhancement network, Reduce the number of convolution kernels and fully connected layer parameters to achieve a lightweight text recognition model.
The deployment of a lightweight text recognition model is realized, which can effectively recognize a large number of text characters and meet localized deployment requirements, while reducing the model size and computational complexity.
Smart Images

Figure CN118570789A
Abstract
Description
Technical Field
[0001] The present application relates to the field of computers, and in particular to a text recognition method and device. Background Art
[0002] With the development of deep learning in the field of text recognition, more and more powerful text recognizers have been gradually proposed, and the performance indicators of text recognition have gradually improved.
[0003] However, most of these text recognizers have complex and large model structures and cannot be deployed locally. They can only be deployed on the server side using GPU (Graphics Processing Unit) for accelerated inference deployment. Summary of the invention
[0004] The present application provides a text recognition method and device to solve the technical problem that the text recognizer in the prior art has a complex and bulky structure and cannot be deployed locally, thus failing to meet the user's local deployment needs.
[0005] In a first aspect, the present application provides a text recognition method, the method comprising:
[0006] Get the text image to be recognized;
[0007] Extracting features of the text image to be recognized to obtain an initial feature map of the text image to be recognized;
[0008] Performing feature channel expansion processing on the initial feature map to expand the initial feature map into a multi-channel feature map;
[0009] Extracting high-level features of the to-be-recognized text image from the multi-channel feature map;
[0010] The text characters included in the to-be-recognized text image are determined according to the high-level features.
[0011] In a possible implementation, performing feature channel expansion processing on the initial feature map to expand the initial feature map into a multi-channel feature map includes:
[0012] The initial feature map is processed by feature channel expansion using a progressive feature channel expansion network in a trained text recognition model, so that the initial feature map is gradually expanded into a multi-channel feature map.
[0013] In a possible implementation, the progressive feature channel expansion module includes N sequentially connected feature channel expansion submodules, wherein N is a natural number greater than 1, the number of convolution kernels in the i-th feature channel expansion submodule is greater than the number of convolution kernels in the i-1th feature channel expansion submodule, and i takes values one by one within the integer interval range of [2, N]; the progressive feature channel expansion network in the trained text recognition model is used to perform feature channel expansion processing on the initial feature map to gradually expand the initial feature map into a multi-channel feature map, including:
[0014] Using the first feature channel expansion submodule in the progressive feature channel expansion module to perform feature channel expansion processing on the initial feature map to obtain a first feature channel expansion result;
[0015] Using the i-th feature channel expansion submodule in the progressive feature channel expansion module to perform feature channel expansion processing on the i-1-th feature channel expansion result to obtain the i-th feature channel expansion result;
[0016] The Nth feature channel expansion result obtained by the Nth feature channel expansion submodule in the progressive feature channel expansion module is determined as the multi-channel feature map.
[0017] In a possible implementation, the feature channel expansion submodule includes: a depth convolution submodule and a point-by-point convolution submodule; the step of using the i-th feature channel expansion submodule in the progressive feature channel expansion module to perform feature channel expansion processing on the i-1-th feature channel expansion result to obtain the i-th feature channel expansion result includes:
[0018] Using the depth convolution submodule in the i-th feature channel expansion submodule to perform depth convolution processing on the i-1-th feature channel expansion result, to obtain an i-th depth convolution result;
[0019] The i-th depth convolution result is processed point by point by using the point-by-point convolution submodule in the i-th feature channel expansion submodule to obtain the i-th feature channel expansion result.
[0020] In a possible implementation, extracting high-level features of the to-be-recognized text image from the multi-channel feature map includes:
[0021] Performing feature enhancement processing on the multi-channel feature map using a feature enhancement network in a trained text recognition model to obtain a feature enhancement map of the multi-channel feature map;
[0022] The high-level feature extraction network in the text recognition model is used to extract features from the feature enhancement map to obtain high-level features of the text image to be recognized.
[0023] In a possible implementation, the feature enhancement network includes M sequentially connected feature enhancement modules, where M is a natural number greater than 1; the feature enhancement network in the trained text recognition model is used to perform feature enhancement processing on the multi-channel feature map to obtain a feature enhancement map of the multi-channel feature map, including:
[0024] Using the first feature enhancement module in the feature enhancement network to perform feature enhancement processing on the multi-channel feature map to obtain a first feature enhancement result;
[0025] Using the j-th feature enhancement module in the feature enhancement network to perform feature enhancement processing on the j-1-th feature enhancement result to obtain the j-th feature enhancement result; wherein j is taken one by one in the integer interval range of [2, M];
[0026] The Mth feature enhancement result obtained by the Mth feature enhancement module in the feature enhancement network is determined as the feature enhancement graph.
[0027] In a possible implementation, the high-level feature extraction network includes a deep convolution module, an attention module, and a point-by-point convolution module, and the high-level feature extraction network in the text recognition model is used to extract features from the feature enhancement map to obtain high-level features of the text image to be recognized, including:
[0028] Using the deep convolution module to perform deep convolution processing on the feature enhancement map to obtain a deep convolution result;
[0029] Using the attention module to perform attention learning on the deep convolution result to obtain an attention learning result;
[0030] The point-by-point convolution module is used to perform point-by-point convolution processing on the attention learning result to obtain high-level features of the text image to be recognized.
[0031] In a possible implementation, the text recognition model is trained in the following manner:
[0032] Get the original text image set;
[0033] The following processing is performed for each original text image in the original text image set: the original text image is rotated by a set angle, and image enhancement processing is performed on the original text image after the angle rotation by using two different image enhancement methods to obtain a group of training sample images corresponding to the original text image;
[0034] Inputting the set of training sample images into the text recognition model to be trained to obtain image features of each training sample image in the set of training sample images;
[0035] Performing comparative learning on the image features of each of the training sample images in the group of training sample images to obtain comparative learning results, and determining the predicted angle of each of the training sample images in the group of training sample images;
[0036] According to the comparison learning result and the difference value between the predicted angle and the set angle, the model parameters of the text recognition model are adjusted until the text recognition model converges.
[0037] In a possible implementation, performing comparative learning on the image features of each training sample image in the group of training sample images to obtain a comparative learning result includes:
[0038] Performing feature mapping processing on the image features of each training sample image in the group of training sample images to obtain a first mapping feature and a second mapping feature;
[0039] Performing feature prediction processing on the first mapping feature and the second mapping feature respectively to obtain the first prediction result and the second prediction result, wherein the first prediction result corresponds to the first mapping feature and the second prediction result corresponds to the second mapping feature;
[0040] Determining a first cosine similarity loss value between the first mapping feature and the second prediction result, and determining a second cosine similarity loss value between the second mapping feature and the first prediction result;
[0041] A sum of the first cosine similarity loss value and the second cosine similarity loss value is determined as the comparative learning result.
[0042] In a second aspect, the present application provides a text recognition device, the device comprising:
[0043] An acquisition module, used for acquiring a text image to be recognized;
[0044] An initial feature extraction module, used for extracting features of the text image to be recognized, and obtaining an initial feature map of the text image to be recognized;
[0045] A feature expansion module, used to perform feature channel expansion processing on the initial feature map to expand the initial feature map into a multi-channel feature map;
[0046] A high-level feature extraction module, used to extract high-level features of the text image to be recognized from the multi-channel feature map;
[0047] The text recognition module is used to determine the text characters included in the text image to be recognized according to the high-level features.
[0048] In a possible implementation manner, the feature expansion module is specifically used to:
[0049] The initial feature map is processed by feature channel expansion using a progressive feature channel expansion network in a trained text recognition model, so that the initial feature map is gradually expanded into a multi-channel feature map.
[0050] In a possible implementation, the progressive feature channel expansion module includes N sequentially connected feature channel expansion submodules, wherein N is a natural number greater than 1, the number of convolution kernels in the i-th feature channel expansion submodule is greater than the number of convolution kernels in the i-1-th feature channel expansion submodule, and i takes values one by one within the integer interval range of [2, N]; the feature expansion module is specifically used to:
[0051] Using the first feature channel expansion submodule in the progressive feature channel expansion module to perform feature channel expansion processing on the initial feature map to obtain a first feature channel expansion result;
[0052] Using the i-th feature channel expansion submodule in the progressive feature channel expansion module to perform feature channel expansion processing on the i-1-th feature channel expansion result to obtain the i-th feature channel expansion result;
[0053] The Nth feature channel expansion result obtained by the Nth feature channel expansion submodule in the progressive feature channel expansion module is determined as the multi-channel feature map.
[0054] In a possible implementation, the feature channel expansion submodule includes: a depth convolution submodule and a point-by-point convolution submodule; the feature expansion module is specifically used to:
[0055] Using the depth convolution submodule in the i-th feature channel expansion submodule to perform depth convolution processing on the i-1-th feature channel expansion result, to obtain an i-th depth convolution result;
[0056] The i-th depth convolution result is processed point by point by using the point-by-point convolution submodule in the i-th feature channel expansion submodule to obtain the i-th feature channel expansion result.
[0057] In a possible implementation, the advanced feature extraction module includes:
[0058] A feature enhancement unit, used to perform feature enhancement processing on the multi-channel feature map using a feature enhancement network in a trained text recognition model to obtain a feature enhancement map of the multi-channel feature map;
[0059] The feature extraction unit is used to extract features from the feature enhancement map using the high-level feature extraction network in the text recognition model to obtain high-level features of the text image to be recognized.
[0060] In a possible implementation, the feature enhancement network includes M sequentially connected feature enhancement modules, where M is a natural number greater than 1; the feature enhancement unit is specifically configured to:
[0061] Using the first feature enhancement module in the feature enhancement network to perform feature enhancement processing on the multi-channel feature map to obtain a first feature enhancement result;
[0062] Using the j-th feature enhancement module in the feature enhancement network to perform feature enhancement processing on the j-1-th feature enhancement result to obtain the j-th feature enhancement result; wherein j is taken one by one in the integer interval range of [2, M];
[0063] The Mth feature enhancement result obtained by the Mth feature enhancement module in the feature enhancement network is determined as the feature enhancement graph.
[0064] In a possible implementation, the high-level feature extraction network includes a deep convolution module, an attention module, and a point-by-point convolution module, and the feature extraction unit is specifically used to:
[0065] Using the deep convolution module to perform deep convolution processing on the feature enhancement map to obtain a deep convolution result;
[0066] Using the attention module to perform attention learning on the deep convolution result to obtain an attention learning result;
[0067] The point-by-point convolution module is used to perform point-by-point convolution processing on the attention learning result to obtain high-level features of the text image to be recognized.
[0068] In a possible implementation, the device further includes:
[0069] The model training module is used to train the text recognition model in the following way:
[0070] Get the original text image set;
[0071] The following processing is performed for each original text image in the original text image set: the original text image is rotated by a set angle, and image enhancement processing is performed on the original text image after the angle rotation by using two different image enhancement methods to obtain a group of training sample images corresponding to the original text image;
[0072] Inputting the set of training sample images into the text recognition model to be trained to obtain image features of each training sample image in the set of training sample images;
[0073] Performing comparative learning on the image features of each of the training sample images in the group of training sample images to obtain comparative learning results, and determining the predicted angle of each of the training sample images in the group of training sample images;
[0074] According to the comparison learning result and the difference value between the predicted angle and the set angle, the model parameters of the text recognition model are adjusted until the text recognition model converges.
[0075] In a possible implementation, the model training module includes:
[0076] A comparative learning unit, used for performing feature mapping processing on the image features of each training sample image in the group of training sample images to obtain a first mapping feature and a second mapping feature;
[0077] Performing feature prediction processing on the first mapping feature and the second mapping feature respectively to obtain the first prediction result and the second prediction result, wherein the first prediction result corresponds to the first mapping feature and the second prediction result corresponds to the second mapping feature;
[0078] Determining a first cosine similarity loss value between the first mapping feature and the second prediction result, and determining a second cosine similarity loss value between the second mapping feature and the first prediction result;
[0079] A sum of the first cosine similarity loss value and the second cosine similarity loss value is determined as the comparative learning result.
[0080] In a third aspect, the present application provides an electronic device, comprising: a processor and a memory, wherein the processor is used to execute a text recognition program stored in the memory to implement the text recognition method described in any one of the first aspects.
[0081] In a fourth aspect, the present application provides a storage medium storing one or more programs, wherein the one or more programs can be executed by one or more processors to implement the text recognition method described in any one of the first aspects.
[0082] The above-mentioned technical scheme provided by the embodiment of the present application has the following advantages compared with the prior art: the method provided by the embodiment of the present application, by acquiring the text image to be recognized, performing feature extraction on the text image to be recognized, obtaining the initial feature map of the text image to be recognized, performing feature channel expansion processing on the initial feature map, and expanding the initial feature map into a multi-channel feature map, can realize the extraction of more and more complex features from the text image to be recognized; further, by extracting high-level features of the text image to be recognized from the multi-channel feature map, and determining the text characters included in the text image to be recognized according to the high-level features, on the one hand, since the high-level features can better describe the content of the text image, extracting the high-level features of the text image to be recognized from the multi-channel feature map helps to better understand and recognize the text characters in the text image to be recognized; on the other hand, since the number of channels of the high-level features is reduced compared to the multi-channel feature map, the high-level feature extraction layer will have a smaller number of convolution kernels, so that the number of convolution kernels is first reduced, and then the fully connected layer is connected, thereby reducing the parameters of the fully connected layer, so that the size of the text recognition model can be significantly reduced. It can be seen that the text recognition model constructed based on the above method provided in the embodiment of the present application will have the advantage of being lightweight and can be locally deployed, thereby being able to meet the user's needs for localized deployment of the text recognition model. BRIEF DESCRIPTION OF THE DRAWINGS
[0083] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the present application and, together with the description, serve to explain the principles of the present application.
[0084] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, for ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative labor.
[0085] One or more embodiments are exemplarily described by pictures in the corresponding drawings, and these exemplified descriptions do not constitute limitations on the embodiments. Elements with the same reference numerals in the drawings represent similar elements, and unless otherwise stated, the figures in the drawings do not constitute proportional limitations.
[0086] Figure 1 A flowchart of an embodiment of a text recognition method provided in an embodiment of the present application;
[0087] Figure 2 A structural diagram of a text recognition model provided by the technical solution of an embodiment of the present application;
[0088] Figure 3It is a structural diagram of the preprocessing network;
[0089] Figure 4 It is a structural diagram of the feature channel extension submodule;
[0090] Figure 5 It is a schematic diagram of the structure of the progressive feature channel expansion network;
[0091] Figure 6 This is a schematic diagram of the structure of the feature enhancement network;
[0092] Figure 7 It is a schematic diagram of the structure of the high-level feature extraction network;
[0093] Figure 8 Another structural diagram of the advanced feature extraction network;
[0094] Fig. 9 A structural diagram of a text recognition model provided in an embodiment of the present application;
[0095] Fig.10 A flowchart of an embodiment of a training process of an encoder in a text recognition model provided in an embodiment of the present application;
[0096] Fig.11 A schematic diagram of a self-supervisory framework provided in an embodiment of the present application;
[0097] Fig.12 A block diagram of an embodiment of a text recognition device provided in an embodiment of the present application;
[0098] Fig.13 A schematic diagram of the structure of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0099] In order to make the purpose, technical solution and advantages of the embodiments of the present application clearer, the technical solution in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without making creative work are within the scope of protection of this application.
[0100] The disclosure below provides many different embodiments or examples to realize the different structures of the present application. In order to simplify the disclosure of the present application, the parts and settings of specific examples are described below. Of course, they are only examples, and the purpose is not to limit the present application. In addition, the present application can repeat reference numbers and / or letters in different examples. This repetition is for the purpose of simplification and clarity, and does not itself indicate the relationship between the various embodiments and / or settings discussed.
[0101] In order to solve the technical problem that the text recognizer in the prior art has a complex and large structure and cannot be locally deployed, thus failing to meet the user's local deployment needs, the present application provides a text recognition method and device that can realize a lightweight text recognition network, and the lightweight text recognition network has a good text recognition effect, and can also support scenarios where a large number of text characters are recognized.
[0102] Figure 1 A flowchart of an embodiment of a text recognition method provided in an embodiment of the present application.
[0103] like Figure 1 As shown, the process includes the following steps:
[0104] Step 101: Obtain a text image to be recognized.
[0105] The above-mentioned text image to be recognized refers to an image of text characters to be recognized. In most application scenarios, the text image to be recognized includes multiple text characters. Here, the text characters include but are not limited to: text (which can be text in any language), numbers, letters (including uppercase and lowercase letters), special symbols (such as π, б, etc.), etc. Further, multiple text characters in the text image to be recognized can use the same or different fonts, sizes and colors, and the embodiments of the present application do not limit this.
[0106] As an optional implementation manner, the text image to be recognized is input or specified by the user.
[0107] As another optional implementation, the above-mentioned text image to be recognized is obtained by processing a document input or specified by a user. Here, processing the document includes but is not limited to format conversion, screenshot, photo, scanning and other processing methods to convert the document or part of the content in the document into an image. The above-mentioned document can be a document in a non-image format such as .PPT, .PDF, .doc, .docx, etc.
[0108] As another optional implementation, the text image to be recognized is obtained from a document input by a user or specified by a user. The document may be a document in a non-image format such as .PPT, .PDF, .doc, or .docx.
[0109] Step 102: extract features of the text image to be recognized to obtain an initial feature map of the text image to be recognized.
[0110] The feature extraction in step 102 refers to extracting basic features related to text characters from the text image to be recognized, such as edge features, corner features, texture features, etc. of the text. The extracted feature map is referred to as the initial feature map. By performing feature extraction on the text image to be recognized, the initial feature map of the text image to be recognized is obtained, which helps to extract more information and more expressive image features in the subsequent process.
[0111] In addition, in the application, before extracting features from the text image to be recognized, the text image to be recognized may be preprocessed, including but not limited to grayscale, binarization, denoising, normalization, etc., which are not limited in the present embodiment. Preprocessing the text image to be recognized facilitates the subsequent feature extraction process.
[0112] Step 103: perform feature channel expansion processing on the initial feature map to expand the initial feature map into a multi-channel feature map.
[0113] The purpose of performing feature channel expansion processing on the initial feature map of the text image to be recognized in step 103 is to increase the number of channels in the initial feature map. By increasing the number of channels in the initial feature map, feature information of different dimensions can be learned, thereby capturing richer and more abstract feature information in the text image to be recognized, and the complex features in the text image to be recognized can be better expressed through the combination of multi-channel features.
[0114] On this basis, by performing feature channel expansion processing on the initial feature map and expanding the initial feature map into a multi-channel feature map, more and higher-level features can be extracted, which will help to accurately identify the text characters in the text image to be identified later.
[0115] Step 104: extract high-level features of the text image to be recognized from the multi-channel feature map.
[0116] Step 105: Determine the text characters included in the text image to be recognized based on the high-level features.
[0117] The above-mentioned high-level features refer to higher-level and more abstract feature representations. High-level features usually have stronger semantic information and can better describe the content of text images. Therefore, extracting high-level features of the text image to be recognized from the multi-channel feature map helps to better understand and recognize the text characters in the text image to be recognized.
[0118] On the other hand, since the text recognition model requires a fully connected layer to classify the recognized text, if the text recognition model supports too many recognized characters and the number of convolution kernels in the previous layer is large (that is, the number of channels is large), the parameter amount of the fully connected layer will become very large, but if the number of convolution kernels is too small and the extracted features are not good enough, it will affect the final recognition effect of the text recognition model. In this regard, the technical solution of the embodiment of the present application adopts a processing scheme of first executing step 103 and then executing step 104, that is, after the feature channel expansion of the initial feature map, the advanced feature extraction mechanism is used to extract the advanced features, and finally the text characters are recognized according to the advanced features. Compared with the multi-channel feature map, the number of channels of the advanced features is reduced, so the advanced feature extraction layer will have a smaller number of convolution kernels, so that the number of convolution kernels is first reduced, and then the fully connected layer is connected, so that rich features can be extracted and the scene of recognizing a large number of text characters can be supported.
[0119] The technical solution provided by the embodiment of the present application obtains a text image to be recognized, performs feature extraction on the text image to be recognized, obtains an initial feature map of the text image to be recognized, performs feature channel expansion processing on the initial feature map, and expands the initial feature map into a multi-channel feature map, so as to achieve the extraction of more and more complex features from the text image to be recognized; further, by extracting high-level features of the text image to be recognized from the multi-channel feature map, and determining the text characters included in the text image to be recognized according to the high-level features, on the one hand, since the high-level features can better describe the content of the text image, extracting the high-level features of the text image to be recognized from the multi-channel feature map helps to better understand and recognize the text characters in the text image to be recognized; on the other hand, since the high-level features have a reduced number of channels compared to the multi-channel feature map, the high-level feature extraction layer will have a smaller number of convolution kernels, thereby achieving the goal of first reducing the number of convolution kernels and then connecting the fully connected layer, thereby reducing the parameters of the fully connected layer, so that the size of the text recognition model can be significantly reduced. It can be seen that the text recognition model constructed based on the above method provided in the embodiment of the present application will have the advantage of being lightweight and can be locally deployed, thereby being able to meet the user's needs for localized deployment of the text recognition model.
[0120] To achieve Figure 1 As shown in the process, an embodiment of the present application provides a text recognition model, which can accurately recognize text characters in an input image and supports scenarios where the input image includes a large number of text characters, that is, a large number of text characters need to be recognized.
[0121] See also Figure 2 , is a schematic diagram of the structure of the text recognition model provided by the technical solution of the embodiment of the present application. Figure 2As shown, the text recognition model includes an encoder and a decoder. The input end of the encoder is the input end of the entire text recognition model, the output end of the encoder is connected to the input end of the decoder, and the output end of the decoder is the output end of the entire text recognition model.
[0122] Furthermore, the above decoder is usually implemented using a fully connected layer. Optionally, in order to support the recognition of 8,000 characters, the number of fully connected layers is 8,000.
[0123] like Figure 2 As shown, the encoder includes a preprocessing network, a progressive feature channel expansion network, a feature enhancement network, and an advanced feature extraction network. The input end of the preprocessing network is the input end of the entire encoder, the output end of the preprocessing network is connected to the input end of the progressive feature channel expansion network, the output end of the progressive feature channel expansion network is connected to the input end of the feature enhancement network, the output end of the feature enhancement network is connected to the input end of the advanced feature extraction network, and the output end of the advanced feature extraction network is the output end of the entire encoder.
[0124] based on Figure 2 The text recognition model described above Figure 1 The specific implementation of the process shown includes: obtaining a text image to be recognized, inputting the text image to be recognized into a trained text recognition model, and using the preprocessing network in the text recognition model to extract features from the text image to be recognized to obtain an initial feature map of the text image to be recognized. Then the initial feature map of the text image to be recognized is input into a progressive feature channel expansion network, and the initial feature map is processed by the progressive feature channel expansion network to gradually expand the initial feature map into a multi-channel feature map. Then the multi-channel feature map is input into a feature enhancement network, and the multi-channel feature map is processed by the feature enhancement network to obtain a feature enhancement map of the multi-channel feature map. Then the feature enhancement map is input into a high-level feature extraction network, and the feature enhancement map is extracted by the high-level feature extraction network to obtain high-level features of the text image to be recognized. Finally, the high-level features of the text image to be recognized are input into a decoding network, and the decoding network is used to determine the text characters included in the text image to be recognized according to the high-level features.
[0125] In order to enable those skilled in the art to better understand the technical solution of the present application, the components of the above-mentioned text recognition model and its processing process are explained in detail below.
[0126] (I) Preprocessing Network
[0127] The preprocessing network is used to extract features of the text image to be recognized and obtain an initial feature map of the text image to be recognized. Optionally, the preprocessing network accepts a grayscale image as an input image, that is, the text recognition model provided in the embodiment of the present application accepts a grayscale image as an input image. For example, assume that the input image is (b, 1, 32, w). Wherein b represents batch size, 1 represents the number of channels of the image is 1, that is, the image is a grayscale image, 32 represents the height of the input image is 32, and w represents the width of the input image.
[0128] See also Figure 3 , is a schematic diagram of the structure of the preprocessing network. Figure 3 As shown, the preprocessing network includes the first convolution layer, the first batch normalization layer, and the first activation layer. The input end of the first convolution layer is the input end of the entire preprocessing network, the output end of the first convolution layer is connected to the input end of the first batch normalization layer, the output end of the first batch normalization layer is connected to the input end of the first activation layer, and the output end of the first activation layer is the input end of the entire preprocessing network.
[0129] Optionally, the convolution kernel size of the first convolution layer is 1*1, the convolution step size is 2, and the number of channels is 16.
[0130] Optionally, the first activation layer uses the Hard Swish activation function. The reason for using the Hard Swish activation function is mainly due to the following considerations: the Hard Swish activation function is a continuous and differentiable function, which makes the HardSwish activation function more applicable in some scenarios that require continuity; the Hard Swish activation function is smooth over the entire domain, which makes the Hard Swish activation function perform better in some applications that require smoothness, such as image processing and audio processing; the Hard Swish activation function has a non-zero gradient over the entire domain, which can well solve the problem of gradient vanishing in the saturated area.
[0131] Continuing with the example of the input image (b, 1, 32, w), the input image enters Figure 3 After the preprocessing network shown in the example, convolution processing is first performed through the first convolution layer to obtain a tensor of (b, 16, 16, w / 2); then the tensor of (b, 16, 16, w / 2) is standardized through the first batch of standardization layers, and the output scale remains unchanged; finally, the tensor of (b, 16, 16, w / 2) is activated by the first activation layer using the Hard Swish activation function to obtain the initial feature map of the input image.
[0132] (II) Progressive Feature Channel Expansion Network
[0133] The progressive feature channel expansion network is used to perform feature channel expansion processing on the initial feature map, and gradually expands the initial feature map into a multi-channel feature map.
[0134] It should be noted here that the progressive feature channel expansion network adopts the method of gradually expanding the number of channels of the initial feature map, which allows the network to capture and fuse feature information at different levels at multiple scales, thereby helping to improve the accuracy of subsequent text character recognition. At the same time, the progressive feature channel expansion network also has good scalability and flexibility, and can be customized and optimized according to the needs of specific tasks.
[0135] Specifically, the progressive feature channel expansion module includes N sequentially connected feature channel expansion submodules, wherein N is a natural number greater than 1, the number of convolution kernels in the i-th feature channel expansion submodule is higher than the number of convolution kernels in the i-1th feature channel expansion submodule, and i takes values one by one in the integer interval range of [2, N]. For example, the number of convolution kernels in the second feature channel expansion submodule is higher than the number of convolution kernels in the first feature channel expansion submodule. For another example, the number of convolution kernels in the third feature channel expansion submodule is higher than the number of convolution kernels in the second feature channel expansion submodule. Through this design, the number of channels allowed by the N sequentially connected feature channel expansion submodules is gradually increased, thereby using the progressive feature channel expansion network to gradually expand the initial feature map into a multi-channel feature map.
[0136] Furthermore, the initial feature map is subjected to feature channel expansion processing by using the progressive feature channel expansion network in the trained text recognition model, and the specific implementation of gradually expanding the initial feature map into a multi-channel feature map includes: using the first feature channel expansion submodule in the progressive feature channel expansion module to perform feature channel expansion processing on the initial feature map to obtain the first feature channel expansion result; using the i-th feature channel expansion submodule in the progressive feature channel expansion module to perform feature channel expansion processing on the i-1-th feature channel expansion result to obtain the i-th feature channel expansion result; and determining the N-th feature channel expansion result obtained by the N-th feature channel expansion submodule in the progressive feature channel expansion module as the final multi-channel feature map.
[0137] In one embodiment, see Figure 4 , is a schematic diagram of the structure of the feature channel extension submodule. Figure 4As shown, any of the above-mentioned feature channel expansion submodules includes: a deep convolution submodule and a point-by-point convolution submodule. Among them, the deep convolution performs convolution operations independently on each input channel, and the point-by-point convolution is used to combine the outputs of these channels. The number of channels of the feature map can be effectively expanded by combining deep convolution and point-by-point convolution. It can be seen that in the technical solution of the embodiment of the present application, the traditional convolution is replaced by a deep separable convolution, so as to reduce the number of parameters of the model and facilitate the lightweight model.
[0138] Based on this, the i-th feature channel expansion submodule in the progressive feature channel expansion module is used to perform feature channel expansion processing on the i-1-th feature channel expansion result, and the specific implementation of obtaining the i-th feature channel expansion result includes: using the depth convolution submodule in the i-th feature channel expansion submodule to perform depth convolution processing on the i-1-th feature channel expansion result to obtain the i-th depth convolution result; using the point-by-point convolution submodule in the i-th feature channel expansion submodule to perform point-by-point convolution processing on the i-th depth convolution result to obtain the i-th feature channel expansion result.
[0139] Further, such as Figure 4 As shown, the depth convolution submodule includes a second convolution layer, a second batch normalization layer, and a second activation layer. The point-by-point convolution submodule includes a third convolution layer, a third batch normalization layer, and a third activation layer.
[0140] Optionally, the second convolution layer is a grouped convolution, and the number of groups is consistent with the number of input channels.
[0141] The third convolution layer is a normal convolution, the convolution kernel size is 1*1, and the convolution step is 1. It should be noted that the number of channels of the third convolution layer in different feature channel expansion submodules is different, and the number of channels of the third convolution layer increases gradually according to the connection order of the feature channel expansion submodules from top to bottom.
[0142] The second and third activation layers use the Hard Swish activation function.
[0143] To facilitate understanding of the above progressive feature channel expansion network, it is shown here Figure 5 See also Figure 5 , which is a schematic diagram of the structure of the progressive feature channel expansion network. Figure 5As shown, the progressive feature channel expansion network includes 6 sequentially connected feature channel expansion submodules: a first feature channel expansion submodule, a second feature channel expansion submodule, a third feature channel expansion submodule, a fourth feature channel expansion submodule, a fifth feature channel expansion submodule and a sixth feature channel expansion submodule. Among them, the input end of the first feature channel expansion submodule is the input end of the entire progressive feature channel expansion network, the output end of the first feature channel expansion submodule is connected to the input end of the second feature channel expansion submodule, the output end of the second feature channel expansion submodule is connected to the input end of the third feature channel expansion submodule, the output end of the third feature channel expansion submodule is connected to the input end of the fourth feature channel expansion submodule, the output end of the fourth feature channel expansion submodule is connected to the input end of the fifth feature channel expansion submodule, the output end of the fifth feature channel expansion submodule is connected to the input end of the sixth feature channel expansion submodule, and the output end of the sixth feature channel expansion submodule is the output end of the entire progressive feature channel expansion network.
[0144] Assuming that the initial feature map is (b, 16, 16, w / 2), after the initial feature map is input into the first feature channel expansion submodule, it is firstly grouped through the depth convolution submodule for convolution, where the number of grouped convolutions is consistent with the number of input channels, the convolution step is 1, and the output is (b, 16, 16, w / 2), and then the output is scaled unchanged after passing through the batch normalization layer and the activation layer. Then, ordinary convolution is performed through the point-by-point convolution submodule, where the number of convolution output channels is 32, the convolution step is 1, and the output is (b, 32, 16, w / 2), and then the output is scaled unchanged after passing through the batch normalization layer and the activation layer.
[0145] After the output (b, 32, 16, w / 2) of the first feature channel expansion submodule is input to the second feature channel expansion submodule, it is first grouped through the depth convolution submodule for convolution, where the number of grouped convolutions is consistent with the number of input channels, the convolution step is 1, and the output is (b, 32, 16, w / 2), and then the output is scaled unchanged after passing through the batch normalization layer and the activation layer. Then, ordinary convolution is performed through the point-by-point convolution submodule, where the number of convolution output channels is 64, the convolution step is 1, and the output is (b, 64, 16, w / 2), and then the output is scaled unchanged after passing through the batch normalization layer and the activation layer.
[0146] After the output (b, 64, 16, w / 2) of the second feature channel expansion submodule is input to the third feature channel expansion submodule, it is first grouped through the depth convolution submodule for convolution, where the number of grouped convolutions is consistent with the number of input channels, the convolution step is 1, and the output is (b, 64, 16, w / 2), and then the output is scaled unchanged after passing through the batch normalization layer and the activation layer. Then, ordinary convolution is performed through the point-by-point convolution submodule, where the number of convolution output channels is 64 and the convolution step is 1, so that the output is (b, 64, 16, w / 2), and then the output is scaled unchanged after passing through the batch normalization layer and the activation layer.
[0147] After the output (b, 64, 16, w / 2) of the third feature channel expansion submodule is input to the fourth feature channel expansion submodule, it is first grouped through the depth convolution submodule for convolution, where the number of grouped convolutions is consistent with the number of input channels, the convolution step is (2, 1), and the output is (b, 64, 8, w / 2), and then the output is scaled unchanged after passing through the batch normalization layer and the activation layer. Then, ordinary convolution is performed through the point-by-point convolution submodule, where the number of convolution output channels is 128 and the convolution step is 1, and the output is (b, 128, 8, w / 2), and then the output is scaled unchanged after passing through the batch normalization layer and the activation layer.
[0148] After the output (b, 128, 8, w / 2) of the fourth feature channel expansion submodule is input to the fifth feature channel expansion submodule, it is first grouped through the depth convolution submodule for convolution, where the number of grouped convolutions is consistent with the number of input channels, the convolution step is 1, and the output is (b, 128, 8, w / 2), and then the output passes through the batch normalization layer and the activation layer, and the output scale remains unchanged. Then, ordinary convolution is performed through the point-by-point convolution submodule, where the number of convolution output channels is 128, the convolution step is 1, and the output is (b, 128, 8, w / 2), and then the output scale remains unchanged after passing through the batch normalization layer and the activation layer.
[0149] After the output (b, 128, 8, w / 2) of the fifth feature channel expansion submodule is input to the sixth feature channel expansion submodule, it is first grouped through the depth convolution submodule for convolution, where the number of grouped convolutions is consistent with the number of input channels, the convolution step is (2, 1), and the output is (b, 128, 4, w / 2), and then the output passes through the batch normalization layer and the activation layer, and the output scale remains unchanged. Then, ordinary convolution is performed through the point-by-point convolution submodule, where the number of convolution output channels is 256 and the convolution step is 1, so that the output is (b, 256, 4, w / 2), and then the output scale remains unchanged after passing through the batch normalization layer and the activation layer.
[0150] (III) Feature Enhancement Network
[0151] The feature enhancement network is used to perform feature enhancement processing on the multi-channel feature map to obtain a feature enhancement map of the multi-channel feature map. The feature enhancement network can be used to perform a deeper analysis and expression of features and extract higher-level and more abstract feature representations.
[0152] In one embodiment, the feature enhancement network includes M sequentially connected feature enhancement modules, where M is a natural number greater than 1. On this basis, the feature enhancement network in the trained text recognition model is used to perform feature enhancement processing on the multi-channel feature map, and the specific implementation of obtaining the feature enhancement map of the multi-channel feature map includes: using the first feature enhancement module in the feature enhancement network to perform feature enhancement processing on the multi-channel feature map to obtain the first feature enhancement result; using the jth feature enhancement module in the feature enhancement network to perform feature enhancement processing on the j-1th feature enhancement result to obtain the jth feature enhancement result; j takes values one by one within the integer interval range of [2, M]; and determining the Mth feature enhancement result obtained by the Mth feature enhancement module in the feature enhancement network as the final feature enhancement map.
[0153] Further, in one embodiment, the feature enhancement module includes a depth convolution submodule and a point-by-point convolution submodule. The depth convolution submodule includes a fourth convolution layer, a fourth batch normalization layer, and a fourth activation layer. The point-by-point convolution submodule includes a fifth convolution layer, a fifth batch normalization layer, and a fifth activation layer.
[0154] Optionally, the fourth convolution layer is a grouped convolution, the number of groups is consistent with the number of input channels, the convolution step is 1, the convolution kernel size is 5*5, and the padding is 2. On this basis, the input is (b, 256, 4, w / 2) and the output is (b, 256, 4, w / 2) after grouped convolution.
[0155] The third convolution layer is a normal convolution with a kernel size of 1*1, a convolution step of 1, and an output channel number of 256. On this basis, the input is (b, 256, 4, w / 2) and the output after convolution is (b, 256, 4, w / 2).
[0156] The fourth and fifth activation layers use the Hard Swish activation function.
[0157] It should be noted here that the number of channels of the third convolutional layer in different feature channel expansion submodules is different, and the number of channels of the third convolutional layer increases gradually according to the connection order of the feature channel expansion submodules from top to bottom.
[0158] The second and third activation layers use the Hard Swish activation function.
[0159] By performing multiple feature enhancement processes on multi-channel feature maps, the diversity of feature representation can be further increased and the generalization ability of the model can be improved.
[0160] To facilitate understanding of the above feature enhancement network, it is shown here Figure 6 See also Figure 6 , which is a schematic diagram of the structure of the feature enhancement network. Figure 6 As shown, the feature enhancement network includes 5 feature enhancement modules connected in sequence: a first feature enhancement module, a second feature enhancement module, a third feature enhancement module, a fourth feature enhancement module and a fifth feature enhancement module. Among them, the input end of the first feature enhancement module is the input end of the entire feature enhancement network, the output end of the first feature enhancement module is connected to the input end of the second feature enhancement module, the output end of the second feature enhancement module is connected to the input end of the third feature enhancement module, the output end of the third feature enhancement module is connected to the input end of the fourth feature enhancement module, the output end of the fourth feature enhancement module is connected to the input end of the fifth feature enhancement module, and the output end of the fifth feature enhancement module is the output end of the entire feature enhancement network.
[0161] Optionally, the above five feature enhancement modules are completely consistent.
[0162] (IV) Advanced Feature Extraction Network
[0163] The high-level feature extraction network is used to extract features from the feature enhancement map to obtain high-level features of the text image to be recognized. Extracting high-level features of the text image to be recognized from the multi-channel feature map helps to better understand and recognize the text characters in the text image to be recognized.
[0164] In one embodiment, see Figure 7 , which is a schematic diagram of the structure of the advanced feature extraction network. Figure 7 As shown, the advanced feature extraction network includes a deep convolution module, an attention module, and a point-by-point convolution module. On this basis, the advanced feature extraction network in the text recognition model is used to extract features from the feature enhancement map, and the specific implementation of obtaining the advanced features of the text image to be recognized includes: using the deep convolution module to perform deep convolution processing on the feature enhancement map to obtain the deep convolution result; using the attention module to perform attention learning on the deep convolution result to obtain the attention learning result; using the point-by-point convolution module to perform point-by-point convolution processing on the attention learning result to obtain the advanced features of the text image to be recognized.
[0165] Further, such as Figure 7As shown, the deep convolution module includes the sixth convolution layer, the sixth batch normalization layer, and the sixth activation layer. Optionally, the sixth convolution layer is a grouped convolution, the number of groups is consistent with the number of input channels, the convolution step is (2, 1), the convolution kernel size is 5*5, and the padding is 2. The sixth activation layer uses the Hard Swish activation function.
[0166] The attention module includes a pooling layer, a downsampling convolution layer, an eighth activation layer, an upsampling convolution layer, and a ninth activation layer. Optionally, the pooling layer is average pooling, the eighth activation layer uses a ReLU activation function, and the ninth activation layer uses a HardSwish activation function.
[0167] The point-by-point convolution submodule includes the seventh convolution layer, the seventh batch normalization layer, and the seventh activation layer. Optionally, the seventh convolution layer is a normal convolution, the convolution kernel size is 1*1, and the convolution step size is 1. The seventh activation layer uses the Hard Swish activation function.
[0168] In another embodiment, see Figure 8 , which is another structural diagram of the advanced feature extraction network. Figure 8 As shown, the high-level feature extraction network includes three sequentially connected deep separable attention modules: the first deep separable attention module, the second deep separable attention module and the third deep separable attention module. The input end of the first deep separable attention module is the input end of the entire high-level feature extraction network, the output end of the first deep separable attention module is connected to the input end of the second deep separable attention module, the output end of the second deep separable attention module is connected to the input end of the third deep separable attention module, and the output end of the third deep separable attention module is the output end of the entire high-level feature extraction network. The structures of the above three deep separable attention modules can be found in Figure 7 As shown, it includes a deep convolution module, an attention module, and a point-by-point convolution module, which will not be described in detail here.
[0169] based on Figure 8In the advanced feature extraction network of the example, after the feature enhancement map (b, 256, 4, w / 2) is input to the first deep separable attention module, it is first grouped and convolved through the deep convolution module. Here, the number of groups is consistent with the number of input channels, and the output is (b, 256, 2, w / 2). Then, the output scale remains unchanged after the batch normalization layer and the activation layer. Then, the output is average pooled through the attention module to obtain the output (b, 256, 1, 1), and then the output is obtained through downsampling convolution to obtain the output (b, 128, 1, 1). Then, the ReLU activation function is used for activation processing, and the output scale remains unchanged. Then, the upsampling convolution is used to obtain the output (b, 256, 1, 1), and then the Hard Swish activation function is used for activation processing, and the output scale remains unchanged. Finally, the feature map in the corresponding channel in the input and the weight value in the corresponding channel in the output are multiplied to obtain the learning result of the attention mechanism. Here, the output size of the attention module is (b, 256, 2, w / 2). Then, ordinary convolution is performed through the point-by-point convolution module. Here, the number of convolution output channels is 512, the step size is 1, and the output is (b, 512, 2, w / 2). After the batch normalization layer and the activation layer, the output scale remains unchanged.
[0170] After the output (b, 512, 2, w / 2) of the first depth-separable attention module is input to the second depth-separable attention module, it is first grouped and convolved through the depth convolution module. Here, the number of groups is consistent with the number of input channels, and the output is (b, 512, 2, w / 2). Then, the output is passed through the batch normalization layer and the activation layer, and the output scale remains unchanged. Then, the output is average-pooled through the attention module to obtain the output (b, 512, 1, 1), and then the output is obtained through downsampling convolution to obtain the output (b, 256, 1, 1). Then, the ReLU activation function is used for activation processing, and the output scale remains unchanged. Then, the upsampling convolution is used to obtain the output (b, 512, 1, 1), and then the Hard Swish activation function is used for activation processing, and the output scale remains unchanged. Finally, the feature map in the corresponding channel in the input and the weight value in the corresponding channel in the output are multiplied to obtain the learning result of the attention mechanism. Here, the output size of the attention module is (b, 512, 2, w / 2). Then, ordinary convolution is performed through the point-by-point convolution module. Here, the number of convolution output channels is 512, the step size is 1, and the output is (b, 512, 2, w / 2). After the batch normalization layer and the activation layer, the output scale remains unchanged.
[0171] After the output (b, 512, 2, w / 2) of the second deep separable attention module is input to the third deep separable attention module, it is first grouped and convolved through the deep convolution module. Here, the number of groups is 64, and the output is (b, 64, 2, w / 2). Then, the output is passed through the batch normalization layer and the activation layer, and the output scale remains unchanged. Then, the output is average pooled through the attention module to obtain the output (b, 64, 1, 1), and then the output is obtained through downsampling convolution to obtain the output (b, 32, 1, 1). Then, the ReLU activation function is used for activation processing, and the output scale remains unchanged. Then, the upsampling convolution is used to obtain the output (b, 64, 1, 1), and then the Hard Swish activation function is used for activation processing, and the output scale remains unchanged. Finally, the feature map in the corresponding channel in the input and the weight value in the corresponding channel in the output are multiplied to obtain the learning result of the attention mechanism. Here, the output size of the attention module is (b, 64, 2, w / 2). Then, ordinary convolution is performed through the point-by-point convolution module. Here, the number of convolution output channels is 64, the step size is 1, and the output is (b, 64, 2, w / 2). After the batch normalization layer and the activation layer, the output scale remains unchanged.
[0172] The encoder of the text recognition model provided in the embodiment of the present application also includes: an average pooling layer and a feature compression layer. The input end of the average pooling layer is connected to the output end of the high-level feature extraction layer, the output end of the average pooling layer is connected to the input end of the feature compression layer, and the output end of the feature compression layer is the output end of the entire encoder.
[0173] Optionally, the pooling step size of the average pooling layer is 2, and the pooling kernel is 2. The average pooling layer can reduce the height and width of the feature map by half. For example, the output of the high-level feature extraction layer is (b, 64, 2, w / 2), and the output obtained by the average pooling layer is (b, 64, 1, w / 4).
[0174] The feature compression layer is used to compress the height dimension of the feature map. For example, the output (b, 64, 1, w / 4) above is obtained by the feature compression layer as (b, 64, w / 4).
[0175] At this point, the explanation of the various components of the text recognition model and its processing process is completed.
[0176] For ease of understanding, based on the above description, the text recognition model provided in the technical solution of the embodiment of the present application is further illustrated here as a whole. Fig. 9 , which is a schematic diagram of the structure of the text recognition model provided by the technical solution of the embodiment of the present application. As for the specific processing process of the text recognition model, please refer to the above description, which will not be repeated here.
[0177] The text recognition model provided in the embodiment of the present application designs the number of channels to be as large as possible in the design of the previous backbone network, so that the extracted features are richer, and finally extracts high-level features through the high-level feature extraction network to reduce the number of channels, thereby reducing the parameters of the fully connected layer of the decoder, so that the size of the model is significantly reduced. Therefore, the text recognition model provided in the embodiment of the present application has the advantage of being lightweight and can be deployed locally, thereby meeting the user's demand for localized deployment of the text recognition model.
[0178] See also Fig.10 , is a flow chart of an embodiment of a text recognition model training process provided in an embodiment of the present application. Fig.10 As shown, the following steps are included:
[0179] Step 1001: Obtain an original text image set.
[0180] The original text image set includes a plurality of text images containing text characters. Optionally, the source of the text images in the original text image set includes but is not limited to: the Internet, a scanner, a camera, and the like.
[0181] Step 1002, perform the following processing on each original text image in the original text image set: rotate the original text image by a set angle, and use two different image enhancement methods to perform image enhancement processing on the original text image after the angle rotation, to obtain a set of training sample images corresponding to the original text image.
[0182] The above-mentioned set angle is, for example, 90°, 180° or 270°, etc. Here, a rotation angle may be randomly selected for each original text image.
[0183] The above-mentioned image enhancement methods include but are not limited to: blur enhancement, noise enhancement, distortion enhancement, camera image enhancement, etc. Here, two image enhancement methods can be randomly selected for each original text image.
[0184] Step 1003: input the group of training sample images into the text recognition model to be trained to obtain image features of each training sample image in the group of training sample images.
[0185] Step 1004: perform comparative learning on the image features of each training sample image in the group of training sample images to obtain comparative learning results, and determine the prediction angle of each training sample image in the group of training sample images.
[0186] Step 1005: Adjust the model parameters of the text recognition model according to the comparison learning result and the difference between the predicted angle and the set angle until the text recognition model converges.
[0187] For ease of understanding, steps 1002 to 1005 are described in a unified manner as follows:
[0188] It can be seen from the description of the above steps 1002 to 1005 that the technical solution of the embodiment of the present application adopts self-supervision technology to train the text recognition model, specifically to train the encoder in the text recognition model. Further, two proxy tasks are designed, namely, the contrast learning task and the prediction angle task. The loss of the model is calculated by the two proxy tasks, and then the model is adjusted, so that the robustness of the finally trained text recognition model can be increased.
[0189] In one embodiment, comparative learning is performed on the image features of each training sample image in a group of training sample images, and a specific implementation of obtaining the comparative learning result includes: performing feature mapping processing on the image features of each training sample image in the group of training sample images to obtain a first mapping feature and a second mapping feature; performing feature prediction processing on the first mapping feature and the second mapping feature to obtain a first prediction result and a second prediction result, the first prediction result corresponds to the first mapping feature, and the second prediction result corresponds to the second mapping feature; determining a first cosine similarity loss value between the first mapping feature and the second prediction result, and determining a second cosine similarity loss value between the second mapping feature and the first prediction result; and determining the sum of the first cosine similarity loss value and the second cosine similarity loss value as the comparative learning result.
[0190] For details, see Fig.11 , which is a schematic diagram of a self-supervisory framework provided in an embodiment of the present application. Fig.11 The self-supervisory framework shown includes a first projector, a first predictor, a second projector, a second predictor, and a third predictor. The first projector is connected to the first predictor, and the second projector is connected to the second predictor. The third predictor is similar to a parallel relationship with the first predictor and the second predictor.
[0191] based on Fig.11 The self-supervised framework shown in the technical solution of the embodiment of the present application first performs data enhancement processing on an original text image S by two different data enhancement methods to obtain image s1 and image s2, and then rotates image s1 and image s2 by a certain angle, such as 90°, 180° or 270° to obtain a set of training sample images corresponding to the original text image.
[0192] Then, s1 and s2 are respectively input into the encoder of the text recognition model to be trained to obtain e1 and e2. Here, the network structure of the encoder refers to the description in the above embodiment, which will not be repeated here. Subsequently, e1 and e2 are respectively subjected to feature mapping processing by a projector to obtain p1 (corresponding to the above-mentioned first mapping feature) and p2 (corresponding to the above-mentioned second mapping feature). Then, p1 and p2 are respectively subjected to feature prediction processing by a predictor to obtain z1 (corresponding to the above-mentioned first prediction result) and z2 (corresponding to the above-mentioned second prediction result). Finally, the cosine similarity loss value between p1 and z2 (corresponding to the above-mentioned first cosine similarity loss value) is calculated, and the cosine similarity loss value between p2 and z1 (corresponding to the above-mentioned second cosine similarity loss value) is calculated, and the sum of the first cosine similarity loss value and the second cosine similarity loss value is determined as the comparative learning result.
[0193] At the same time, the rotation angles of e1 and e2 are predicted by the third predictor to obtain predicted angles.
[0194] From the above description, we can see that in contrastive learning tasks, the cross-calculation cosine loss method is used. The main reasons for this are as follows:
[0195] Learning invariance: The goal of contrastive learning is to learn a representation so that different views (or enhanced versions) of the same object are as close as possible in the representation space, while different objects are as far apart as possible in the representation space. By cross-calculating the cosine loss, that is, minimizing the similarity between p1 and z2 (representations from different samples but processed differently), we are actually strengthening the model's invariance to different views. In this way, when the model encounters deformations or new views of an object in downstream tasks, it can still recognize the object.
[0196] Avoid trivial solutions: If we do not use cross-calculation cosine loss, but only calculate the similarity loss between the projected features and the predicted features of the same sample (i.e. p1 with z1, p2 with z2), then the model may find a simple trivial solution, such as all samples are mapped to the same representation vector. By introducing cross-calculation, we force the model to learn features that distinguish different samples, thereby avoiding such trivial solutions.
[0197] Increased learning difficulty: Cross-calculating cosine loss actually increases the difficulty of learning because the model needs to learn how to distinguish the characteristics of different samples instead of just remembering the specific representation of each sample. This increased difficulty helps improve the generalization ability of the model in downstream tasks.
[0198] Meet the goal of contrastive learning: The goal of contrastive learning is to learn a representation so that the representations of similar samples are close in the representation space, while the representations of dissimilar samples are far away in the representation space. The cross-calculated cosine loss meets this goal because it forces the model to learn to distinguish different samples by minimizing the similarity loss between different samples.
[0199] In summary, cross-calculating cosine loss is an effective strategy in contrastive learning, which helps the model learn invariance, avoids trivial solutions, increases learning difficulty, and meets the goal of contrastive learning.
[0200] Finally, as an optional implementation, the model parameters of the encoder are adjusted according to the difference between the comparison learning results and the predicted angle and the set angle until the encoder converges. The specific implementation includes: directly summing or weighted summing the difference between the comparison learning results and the predicted angle and the set angle to obtain the final loss value, and adjusting the model parameters of the encoder based on the loss value until the encoder converges. Optionally, the encoder convergence, for example, means that the loss value of the encoder meets the set conditions, such as being less than a set threshold.
[0201] In addition, in one embodiment, by Fig. 9 After the encoder in the text recognition model is trained by the process shown, the encoder can also be supervised trained on this basis to improve the performance of the text recognition model finally trained.
[0202] The technical solution provided in the embodiment of the present application adopts self-supervision technology to train the encoder in the text recognition model, and designs two proxy tasks, namely, a contrast learning task and a prediction angle task. The loss of the model is jointly calculated through the two proxy tasks, and then the model parameters are adjusted. This can increase the robustness of the text recognition model finally trained.
[0203] Fig.12 This is a block diagram of an embodiment of a text recognition device provided in an embodiment of the present application. Fig.12 As shown, the device comprises:
[0204] An acquisition module 1201 is used to acquire a text image to be recognized;
[0205] An initial feature extraction module 1202 is used to extract features of the text image to be recognized to obtain an initial feature map of the text image to be recognized;
[0206] A feature expansion module 1203 is used to perform feature channel expansion processing on the initial feature map to expand the initial feature map into a multi-channel feature map;
[0207] A high-level feature extraction module 1204 is used to extract high-level features of the text image to be recognized from the multi-channel feature map;
[0208] The text recognition module 1205 is used to determine the text characters included in the text image to be recognized according to the high-level features.
[0209] In a possible implementation, the feature expansion module 1203 is specifically configured to:
[0210] The initial feature map is processed by feature channel expansion using a progressive feature channel expansion network in a trained text recognition model, so that the initial feature map is gradually expanded into a multi-channel feature map.
[0211] In a possible implementation, the progressive feature channel expansion module includes N sequentially connected feature channel expansion submodules, wherein N is a natural number greater than 1, the number of convolution kernels in the i-th feature channel expansion submodule is greater than the number of convolution kernels in the i-1-th feature channel expansion submodule, and i takes values one by one within the integer interval range of [2, N]; the feature expansion module is specifically used to:
[0212] Using the first feature channel expansion submodule in the progressive feature channel expansion module to perform feature channel expansion processing on the initial feature map to obtain a first feature channel expansion result;
[0213] Using the i-th feature channel expansion submodule in the progressive feature channel expansion module to perform feature channel expansion processing on the i-1-th feature channel expansion result to obtain the i-th feature channel expansion result;
[0214] The Nth feature channel expansion result obtained by the Nth feature channel expansion submodule in the progressive feature channel expansion module is determined as the multi-channel feature map.
[0215] In a possible implementation, the feature channel expansion submodule includes: a depth convolution submodule and a point-by-point convolution submodule; the feature expansion module is specifically used to:
[0216] Using the depth convolution submodule in the i-th feature channel expansion submodule to perform depth convolution processing on the i-1-th feature channel expansion result, to obtain an i-th depth convolution result;
[0217] The i-th depth convolution result is processed point by point by using the point-by-point convolution submodule in the i-th feature channel expansion submodule to obtain the i-th feature channel expansion result.
[0218] In a possible implementation, the high-level feature extraction module 1204 includes:
[0219] A feature enhancement unit, used to perform feature enhancement processing on the multi-channel feature map using a feature enhancement network in a trained text recognition model to obtain a feature enhancement map of the multi-channel feature map;
[0220] The feature extraction unit is used to extract features from the feature enhancement map using the high-level feature extraction network in the text recognition model to obtain high-level features of the text image to be recognized.
[0221] In a possible implementation, the feature enhancement network includes M sequentially connected feature enhancement modules, where M is a natural number greater than 1; the feature enhancement unit is specifically configured to:
[0222] Using the first feature enhancement module in the feature enhancement network to perform feature enhancement processing on the multi-channel feature map to obtain a first feature enhancement result;
[0223] Using the j-th feature enhancement module in the feature enhancement network to perform feature enhancement processing on the j-1-th feature enhancement result to obtain the j-th feature enhancement result; wherein j is taken one by one in the integer interval range of [2, M];
[0224] The Mth feature enhancement result obtained by the Mth feature enhancement module in the feature enhancement network is determined as the feature enhancement graph.
[0225] In a possible implementation, the high-level feature extraction network includes a deep convolution module, an attention module, and a point-by-point convolution module, and the feature extraction unit is specifically used to:
[0226] Using the deep convolution module to perform deep convolution processing on the feature enhancement map to obtain a deep convolution result;
[0227] Using the attention module to perform attention learning on the deep convolution result to obtain an attention learning result;
[0228] The point-by-point convolution module is used to perform point-by-point convolution processing on the attention learning result to obtain high-level features of the text image to be recognized.
[0229] In a possible implementation, the device further includes:
[0230] The model training module is used to train the text recognition model in the following way:
[0231] Get the original text image set;
[0232] The following processing is performed for each original text image in the original text image set: the original text image is rotated by a set angle, and image enhancement processing is performed on the original text image after the angle rotation by using two different image enhancement methods to obtain a group of training sample images corresponding to the original text image;
[0233] Inputting the set of training sample images into the text recognition model to be trained to obtain image features of each training sample image in the set of training sample images;
[0234] Performing comparative learning on the image features of each of the training sample images in the group of training sample images to obtain comparative learning results, and determining the predicted angle of each of the training sample images in the group of training sample images;
[0235] According to the comparison learning result and the difference value between the predicted angle and the set angle, the model parameters of the text recognition model are adjusted until the text recognition model converges.
[0236] In a possible implementation, the model training module includes:
[0237] A comparative learning unit, used for performing feature mapping processing on the image features of each training sample image in the group of training sample images to obtain a first mapping feature and a second mapping feature;
[0238] Performing feature prediction processing on the first mapping feature and the second mapping feature respectively to obtain the first prediction result and the second prediction result, wherein the first prediction result corresponds to the first mapping feature and the second prediction result corresponds to the second mapping feature;
[0239] Determining a first cosine similarity loss value between the first mapping feature and the second prediction result, and determining a second cosine similarity loss value between the second mapping feature and the first prediction result;
[0240] A sum of the first cosine similarity loss value and the second cosine similarity loss value is determined as the comparative learning result.
[0241] like Fig.13 As shown, an embodiment of the present application provides an electronic device, including a processor 111, a communication interface 112, a memory 113 and a communication bus 114, wherein the processor 111, the communication interface 112, and the memory 113 communicate with each other through the communication bus 114.
[0242] Memory 113, used for storing computer programs;
[0243] In one embodiment of the present application, the processor 111 is used to execute the program stored in the memory 113 to implement the text recognition method provided by any of the above method embodiments, including:
[0244] Get the text image to be recognized;
[0245] Extracting features of the text image to be recognized to obtain an initial feature map of the text image to be recognized;
[0246] Performing feature channel expansion processing on the initial feature map to expand the initial feature map into a multi-channel feature map;
[0247] Extracting high-level features of the to-be-recognized text image from the multi-channel feature map;
[0248] The text characters included in the to-be-recognized text image are determined according to the high-level features.
[0249] An embodiment of the present application further provides a computer-readable storage medium having a computer program stored thereon. When the computer program is executed by a processor, the steps of the text recognition method provided in any of the aforementioned method embodiments are implemented.
[0250] 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 shown as units may or may not be physical units, that is, they may be located in one place, or 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 solution of this embodiment.
[0251] 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 general hardware platform, and of course, by hardware. Based on this understanding, the above technical solution is essentially or the part that contributes to the relevant technology 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.
[0252] It should be understood that the terms used herein are only for the purpose of describing specific example embodiments and are not intended to be limiting. Unless the context clearly indicates otherwise, the singular forms "one", "an" and "said" as used herein may also be meant to include plural forms. The terms "include", "comprise", "contain", and "have" are inclusive, and therefore specify the existence of stated features, steps, operations, elements and / or parts, but do not exclude the existence or addition of one or more other features, steps, operations, elements, parts, and / or combinations thereof. The method steps, processes, and operations described herein are not interpreted as necessarily requiring them to be performed in the specific order described or illustrated, unless the execution order is clearly indicated. It should also be understood that additional or alternative steps may be used.
[0253] The above description is only a specific implementation of the present application, so that those skilled in the art can understand or implement the present application. Various modifications to these embodiments will be apparent to those skilled in the art, and the general principles defined herein can be implemented in other embodiments without departing from the spirit or scope of the present application. Therefore, the present application will not be limited to the embodiments shown herein, but will conform to the widest range consistent with the principles and novel features applied for herein.
Claims
1. A text recognition method, characterized in that: The method comprises: Get the text image to be recognized; Extracting features of the text image to be recognized to obtain an initial feature map of the text image to be recognized; Performing feature channel expansion processing on the initial feature map to expand the initial feature map into a multi-channel feature map; Extracting high-level features of the to-be-recognized text image from the multi-channel feature map; The text characters included in the to-be-recognized text image are determined according to the high-level features.
2. The method according to claim 1, characterized in that The step of performing feature channel expansion processing on the initial feature map to expand the initial feature map into a multi-channel feature map includes: The initial feature map is processed by feature channel expansion using a progressive feature channel expansion network in a trained text recognition model, so that the initial feature map is gradually expanded into a multi-channel feature map.
3. The method according to claim 2, characterized in that The progressive feature channel expansion module includes N sequentially connected feature channel expansion submodules, wherein N is a natural number greater than 1, the number of convolution kernels in the i-th feature channel expansion submodule is greater than the number of convolution kernels in the i-1th feature channel expansion submodule, and i takes values one by one within the integer interval range of [2, N]; the progressive feature channel expansion network in the trained text recognition model is used to perform feature channel expansion processing on the initial feature map, and the initial feature map is gradually expanded into a multi-channel feature map, including: Using the first feature channel expansion submodule in the progressive feature channel expansion module to perform feature channel expansion processing on the initial feature map to obtain a first feature channel expansion result; Using the i-th feature channel expansion submodule in the progressive feature channel expansion module to perform feature channel expansion processing on the i-1-th feature channel expansion result to obtain the i-th feature channel expansion result; The Nth feature channel expansion result obtained by the Nth feature channel expansion submodule in the progressive feature channel expansion module is determined as the multi-channel feature map.
4. The method according to claim 3, characterized in that The feature channel expansion submodule includes: a depth convolution submodule and a point-by-point convolution submodule; the i-th feature channel expansion submodule in the progressive feature channel expansion module performs feature channel expansion processing on the i-1-th feature channel expansion result to obtain the i-th feature channel expansion result, including: Using the depth convolution submodule in the i-th feature channel expansion submodule to perform depth convolution processing on the i-1-th feature channel expansion result, to obtain an i-th depth convolution result; The i-th depth convolution result is processed point by point by using the point-by-point convolution submodule in the i-th feature channel expansion submodule to obtain the i-th feature channel expansion result.
5. The method according to claim 1, characterized in that The step of extracting high-level features of the to-be-recognized text image from the multi-channel feature map comprises: Performing feature enhancement processing on the multi-channel feature map using a feature enhancement network in a trained text recognition model to obtain a feature enhancement map of the multi-channel feature map; The high-level feature extraction network in the text recognition model is used to extract features from the feature enhancement map to obtain high-level features of the text image to be recognized.
6. The method according to claim 5, characterized in that The feature enhancement network includes M sequentially connected feature enhancement modules, where M is a natural number greater than 1; the feature enhancement network in the trained text recognition model is used to perform feature enhancement processing on the multi-channel feature map to obtain a feature enhancement map of the multi-channel feature map, including: Using the first feature enhancement module in the feature enhancement network to perform feature enhancement processing on the multi-channel feature map to obtain a first feature enhancement result; Using the j-th feature enhancement module in the feature enhancement network to perform feature enhancement processing on the j-1-th feature enhancement result to obtain the j-th feature enhancement result; wherein j is taken one by one in the integer interval range of [2, M]; The Mth feature enhancement result obtained by the Mth feature enhancement module in the feature enhancement network is determined as the feature enhancement graph.
7. The method according to claim 5, characterized in that The high-level feature extraction network includes a deep convolution module, an attention module and a point-by-point convolution module. The high-level feature extraction network in the text recognition model is used to extract features from the feature enhancement map to obtain high-level features of the text image to be recognized, including: Using the deep convolution module to perform deep convolution processing on the feature enhancement map to obtain a deep convolution result; Using the attention module to perform attention learning on the deep convolution result to obtain an attention learning result; The point-by-point convolution module is used to perform point-by-point convolution processing on the attention learning result to obtain high-level features of the text image to be recognized.
8. The method according to any one of claims 2 to 7, characterized in that: The text recognition model is trained in the following way: Get the original text image set; The following processing is performed for each original text image in the original text image set: the original text image is rotated by a set angle, and image enhancement processing is performed on the original text image after the angle rotation by using two different image enhancement methods to obtain a group of training sample images corresponding to the original text image; Inputting the set of training sample images into the text recognition model to be trained to obtain image features of each training sample image in the set of training sample images; Performing comparative learning on the image features of each of the training sample images in the group of training sample images to obtain comparative learning results, and determining the predicted angle of each of the training sample images in the group of training sample images; According to the comparison learning result and the difference value between the predicted angle and the set angle, the model parameters of the text recognition model are adjusted until the text recognition model converges.
9. The method according to claim 8, characterized in that The comparative learning of the image features of each training sample image in the group of training sample images to obtain the comparative learning result includes: Performing feature mapping processing on the image features of each training sample image in the group of training sample images to obtain a first mapping feature and a second mapping feature; Performing feature prediction processing on the first mapping feature and the second mapping feature respectively to obtain the first prediction result and the second prediction result, wherein the first prediction result corresponds to the first mapping feature and the second prediction result corresponds to the second mapping feature; Determining a first cosine similarity loss value between the first mapping feature and the second prediction result, and determining a second cosine similarity loss value between the second mapping feature and the first prediction result; A sum of the first cosine similarity loss value and the second cosine similarity loss value is determined as the comparative learning result.
10. A text recognition device, characterized in that: The device comprises: An acquisition module, used for acquiring a text image to be recognized; An initial feature extraction module, used for extracting features of the text image to be recognized, and obtaining an initial feature map of the text image to be recognized; A feature expansion module, used to perform feature channel expansion processing on the initial feature map to expand the initial feature map into a multi-channel feature map; A high-level feature extraction module, used to extract high-level features of the text image to be recognized from the multi-channel feature map; The text recognition module is used to determine the text characters included in the text image to be recognized according to the high-level features.
Citation Information
Patent Citations
Text graph offset angle prediction and correction method
CN112784836A
Method and device for detecting primitive in architectural plan, equipment and medium
CN113537026A
Electric tower plate detection and identification method based on CS-ABCNet
CN116052149A
Neural network architecture for implementing group convolutions
WO2023059336A1
