Text recognition method and related apparatus
By using the target classification model in text recognition technology to obtain the language distribution and text presentation direction, image correction and area segmentation are performed, which solves the problem of low accuracy in multilingual image recognition and recognition, and achieves efficient text recognition effects.
Patent Information
- Application Number
- PCT/CN2023/076411
- Authority / Receiving Office
- WO · WO
- Patent Type
- Applications
- Current Assignee / Owner
- Priority Date
- 2022-04-18
- Filing Date
- 2023-02-16
- Publication Date
- 2024-09-19
AI Technical Summary
Existing text recognition technology cannot effectively identify images containing multiple languages, and target language recognition errors will lead to low recognition accuracy.
By inputting the image to be recognized into the target classification model to obtain the language distribution information and text presentation direction, image correction is performed, and the text area image set is determined based on the language distribution information, and the text recognition model of the corresponding language is used for processing to obtain the text recognition result.
It achieves accurate recognition of multilingual images, improves text recognition accuracy and efficiency, and ensures that each text area is correctly distributed to the corresponding language model for recognition.
Smart Images

Figure CN2023076411_19092024_PF_FP_ABST
Abstract
Description
Text recognition method and related device
[0001] This application claims priority to the Chinese patent application filed with the China Patent Office on April 18, 2022, with application number 2022104029338 and application name “Text Recognition Method and Related Device”, the entire contents of which are incorporated by reference into this application. Technical Field
[0002] The present application relates to the field of artificial intelligence technology, and in particular to text recognition technology. Background Art
[0003] With the continuous development of computer technology, image-based text recognition technology has been widely used. Image-based text recognition technology is used to recognize text information contained in images.
[0004] In related technologies, the target language of the text information in the image to be recognized is usually determined first, and then the text information contained in the image to be recognized is determined using a text recognition model corresponding to the target language.
[0005] However, the above text recognition method cannot perform text recognition on images containing text in multiple languages. In addition, if the target language is incorrectly recognized, it will directly affect the text recognition results, resulting in low recognition accuracy.
[0006] Summary of the Invention
[0007] The embodiments of the present application provide a text recognition method and related apparatus, which can perform text recognition on images containing text in multiple languages and can improve the accuracy of text recognition.
[0008] In a first aspect, an embodiment of the present application provides a text recognition method, performed by an electronic device, comprising:
[0009] Inputting an image to be recognized containing text into a target classification model to obtain language distribution information and original text presentation direction of the image to be recognized, wherein the language distribution information includes multiple languages corresponding to the text and text position information corresponding to each of the multiple languages;
[0010] Correcting the image to be recognized based on the original text presentation direction and the preset target text presentation direction to obtain a target recognition image;
[0011] Based on the text position information corresponding to each of the multiple languages, determining, in the target recognition image, text region image sets corresponding to each of the multiple languages;
[0012] Based on the text region image sets corresponding to the multiple languages, target text recognition models associated with the corresponding languages are used for processing to obtain text recognition results corresponding to the images to be recognized.
[0013] In a second aspect, an embodiment of the present application provides a text recognition device, comprising:
[0014] An image classification unit, configured to input an image to be recognized containing text into a target classification model to obtain language distribution information and original text presentation direction of the image to be recognized, wherein the language distribution information includes multiple languages corresponding to the text and text position information corresponding to each of the multiple languages;
[0015] An image correction unit, configured to correct the image to be recognized based on the original text presentation direction and the preset target text presentation direction to obtain a target recognition image;
[0016] a text locating unit, configured to determine, in the target recognition image, text region image sets corresponding to the multiple languages, based on the text position information corresponding to the multiple languages;
[0017] The image recognition unit is used to process the text area image sets corresponding to the multiple languages using the target text recognition models associated with the corresponding languages to obtain text recognition results corresponding to the images to be recognized.
[0018] In a third aspect, an embodiment of the present application provides an electronic device, comprising a processor and a memory, wherein the memory stores a computer program, and when the computer program is executed by the processor, the processor performs the steps of the above-mentioned text recognition method.
[0019] In a fourth aspect, an embodiment of the present application provides a computer-readable storage medium, which includes a computer program. When the computer program is run on an electronic device, the computer program is used to enable the electronic device to perform the steps of the above-mentioned text recognition method.
[0020] In a fifth aspect, an embodiment of the present application provides a computer program product, which includes a computer program stored in a computer-readable storage medium. The processor of an electronic device reads and executes the computer program from the computer-readable storage medium, so that the electronic device performs the steps of the above-mentioned text recognition method.
[0021] In an embodiment of the present application, an image to be recognized containing text is input into a target classification model to obtain corresponding language distribution information and the original text presentation direction. Then, based on the original text presentation direction and the preset target text presentation direction, the image to be recognized is corrected to obtain a target recognition image. Thereafter, based on the text position information corresponding to each of the multiple languages in the language distribution information, a text area image set corresponding to each of the multiple languages is determined in the target recognition image. Finally, based on each text area image set, the target text recognition model associated with the corresponding language is used to obtain a text recognition result corresponding to the image to be recognized.
[0022] In this way, on the one hand, through language distribution information, the multiple languages contained in the text to be recognized can be located, and thus the problem of multi-language mixing in the image can be solved to a certain extent. On the other hand, image correction combined with the text presentation direction can improve text recognition efficiency and recognition accuracy. In addition, by accurately judging the language distribution information and text presentation direction, the image of each text area can be correctly distributed to the text recognition model of the corresponding language, further improving the text recognition accuracy. BRIEF DESCRIPTION OF THE DRAWINGS
[0023] FIG1 is a schematic diagram of an application scenario provided in an embodiment of the present application;
[0024] FIG2 is a flow chart of a text recognition method provided in an embodiment of the present application;
[0025] FIG3A is a schematic diagram of various languages provided in an embodiment of the present application;
[0026] FIG3B is a schematic diagram of various text presentation directions provided in an embodiment of the present application;
[0027] FIG4 is a schematic diagram of obtaining language distribution information and original text presentation direction provided in an embodiment of the present application;
[0028] FIG5 is a schematic diagram of an image correction process provided in an embodiment of the present application;
[0029] FIG6 is a schematic diagram of a target recognition image provided in an embodiment of the present application;
[0030] FIG7 is a logic diagram of a text recognition method provided in an embodiment of the present application;
[0031] FIG8A is a schematic diagram of the structure of a target text line detection model provided in an embodiment of the present application;
[0032] FIG8B is a schematic diagram of a shape correction process provided in an embodiment of the present application;
[0033] FIG9 is a schematic diagram of a target classification model provided in an embodiment of the present application;
[0034] FIG10A is a flow chart of a method for training a language recognition sub-model according to an embodiment of the present application;
[0035] FIG10B is a logic diagram of determining the first model loss provided in an embodiment of the present application;
[0036] FIG11A is a flow chart of a language recognition sub-model training method provided in an embodiment of the present application;
[0037] FIG11B is a logic diagram of determining the second model loss provided in an embodiment of the present application;
[0038] FIG11C is a schematic diagram of contrast loss and cross entropy loss provided in an embodiment of the present application;
[0039] FIG12 is a schematic diagram of two text recognition results provided in an embodiment of the present application;
[0040] FIG13 is a schematic diagram of the structure of a pre-trained language recognition model provided in an embodiment of the present application;
[0041] FIG14 is a schematic diagram of the structure of the image-text distance recognition model provided in an embodiment of the present application;
[0042] FIG15 is a flow chart of a text recognition model training method provided in an embodiment of the present application;
[0043] FIG16 is a schematic diagram of the spatial distribution characteristics of Thai provided in an embodiment of the present application;
[0044] FIG17A is a schematic diagram of a text recognition model based on SAR and CTC provided in an embodiment of the present application;
[0045] FIG17B is a schematic diagram of several text recognition results provided in an embodiment of the present application;
[0046] FIG18A is a logic diagram of a data synthesis method provided in an embodiment of the present application;
[0047] FIG18B is a schematic diagram of a synthesized labeled sample provided in an embodiment of the present application;
[0048] FIG19 is a logical diagram of data text style transfer provided in an embodiment of the present application;
[0049] FIG20 is a schematic diagram of a sample obtained by text style transfer provided in an embodiment of the present application;
[0050] FIG21 is a schematic structural diagram of a text recognition device provided in an embodiment of the present application;
[0051] FIG22 is a schematic structural diagram of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0052] The following is an introduction to some concepts involved in the embodiments of this application.
[0053] Text detection: Locate the location of text in an image.
[0054] Text recognition: Based on the text position obtained by text detection, the text recognition result is converted, that is, the text information is converted.
[0055] The solutions provided in the embodiments of this application involve machine learning technologies for artificial intelligence. In these embodiments, they primarily involve the training process of text detection models, classification models, and text recognition models, as well as the corresponding model application processes. It should be noted that in these embodiments, the model training process can be conducted using either offline or online training, without limitation.
[0056] The preferred embodiments of the present application are described below in conjunction with the drawings in the specification. It should be understood that the preferred embodiments described herein are only used to illustrate and explain the present application and are not used to limit the present application. In addition, the embodiments of the present application and the features in the embodiments may be combined with each other if there is no conflict.
[0057] Refer to Figure 1, which is a schematic diagram of an application scenario provided by an embodiment of the present application. The application scenario includes at least a terminal device 110 and a server 120. The number of terminal devices 110 can be one or more, and the number of servers 120 can also be one or more. This application does not specifically limit the number of terminal devices 110 and servers 120. A client related to text recognition can be installed on the terminal device 110, and the server 120 can be a server related to data processing. In addition, the client in this application can be software, or a web page, applet, etc., and the server is a background server corresponding to the software, web page, applet, etc., or a server specifically used for data processing, which is not specifically limited in this application.
[0058] In the embodiment of the present application, the terminal device 110 can be a smart phone, a tablet computer, a laptop computer, a desktop computer, a smart speaker, a smart watch, an Internet of Things device, a smart home appliance, a car terminal, etc., but is not limited thereto.
[0059] The server 120 may be an independent physical server, a server cluster or distributed system composed of multiple physical servers, or a cloud server that provides basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, content delivery networks (CDNs), and big data and artificial intelligence platforms. The terminal device 110 and the server 120 may be directly or indirectly connected via wired or wireless communication, which is not limited in this application.
[0060] It should be noted that the text recognition method in the embodiment of the present application can be executed by the server or the terminal device alone, or can be executed by the server and the terminal device in collaboration.
[0061] For example, a terminal device inputs an image to be recognized into a target classification model to obtain corresponding language distribution information and the original text presentation direction. Then, based on the original text presentation direction and the preset target text presentation direction, the image to be recognized is corrected to obtain a target recognition image. Subsequently, based on the position information of each text, a set of text region images corresponding to each of the multiple languages is determined from the target recognition image. Finally, based on each text region image set, the target text recognition model associated with the corresponding language is used to determine the text recognition result corresponding to the image to be recognized. Alternatively, the above text recognition process is performed by a server.
[0062] Alternatively, the terminal device responds to the text recognition operation on the image to be recognized, obtains the image to be recognized, and transmits the image to be recognized to the server. The server then inputs the image to be recognized into the target classification model to obtain the corresponding language distribution information and the original text presentation direction. Then, based on the original text presentation direction and the preset target text presentation direction, the image to be recognized is corrected to obtain the target recognition image. Thereafter, based on the position information of each text, the text area image sets corresponding to multiple languages are determined from the target recognition image. Finally, based on each text area image set, the target text recognition model associated with the corresponding language is used to determine the text recognition result corresponding to the image to be recognized.
[0063] It should be noted that the text recognition method in the embodiment of the present application can be applied to any scenario where text needs to be extracted from an image, such as image text extraction, scan-to-translate, image translation, reading, document retrieval, sorting of letters and parcels, editing and proofreading of manuscripts, summary and analysis of reports and cards, statistical summary of commodity invoices, identification of commodity codes, management of commodity warehouses, etc., but is not limited to these.
[0064] The text recognition method provided by the exemplary embodiment of the present application is described below in combination with the application scenarios described above and with reference to the accompanying drawings. It should be noted that the above application scenarios are only shown to facilitate understanding of the spirit and principles of the present application, and the implementation of the present application is not limited in this respect.
[0065] 2 is a flowchart of a text recognition method provided in an embodiment of the present application. The method can be executed by an electronic device, which can be a terminal device or a server. The specific process is as follows:
[0066] S201. Input an image to be recognized containing text into a target classification model to obtain language distribution information and original text presentation direction of the image to be recognized, wherein the language distribution information includes multiple languages corresponding to the text and text position information corresponding to each of the multiple languages.
[0067] In the embodiment of the present application, the target classification model can also be called a multi-task architecture text language / orientation classification model (Lingual & Orientation Prediction Network, LOPN). The target classification model can detect the language distribution and determine the text presentation direction of the image to be recognized.
[0068] The multiple languages may be multiple of the following: Chinese, Japanese, Korean, Latin, Thai, Arabic, Hindi, and symbolic identifiers, wherein the symbolic identifiers include one or more of numbers and symbols, but are not limited thereto. Referring to FIG3A , which is a schematic diagram of various languages provided in an embodiment of the present application, the semantics of the text corresponding to Chinese, Japanese, Korean, Latin, Thai, Arabic, and Hindi are all "hello", and the symbolic identifier represents 11:00 to 12:00.
[0069] The text presentation direction is used to represent the layout direction of the text. For example, the text presentation direction includes but is not limited to 0°, 90°, 180°, and 270°. Taking Chinese as an example, as shown in Figure 3B, when the text presentation direction is 0° and 180°, the text is laid out horizontally. When the text presentation direction is 90° and 270°, the text is laid out vertically.
[0070] It should be noted that, in the embodiment of the present application, the image to be identified can be the original image, or it can be a partial image containing text extracted from the original image through text detection. The specific text detection method is described below.
[0071] Taking the image to be recognized 1 as an example, as shown in Figure 4, the image to be recognized 1 contains the Chinese character "踏青" and the English word "spring". The image to be recognized 1 is input into the target classification model to obtain the language distribution information corresponding to the image to be recognized 1 and the original text presentation direction. Among them, the original text presentation direction is 180°. The language distribution information contains multiple languages corresponding to the text (i.e., Chinese and English), as well as the text position information corresponding to Chinese and the text position information corresponding to English. The text position information corresponding to Chinese is used to represent the text position where "踏青" is located, and the text position information corresponding to English is used to represent the text position where "spring" is located.
[0072] S202. Based on the original text presentation direction and the preset target text presentation direction, correct the image to be recognized to obtain the target recognition image.
[0073] Still taking the image to be recognized 1 as an example, as shown in Figure 5, assume that the preset target text presentation direction is 0° and the original text presentation direction is 180°. Based on the original text presentation direction and the preset target text presentation direction, correct the image to be recognized 1 to obtain the target recognition image 1, where the text presentation direction of the target recognition image 1 is 0°.
[0074] S203. Based on the text position information corresponding to each of the multiple languages, determine the text region image sets corresponding to each of the multiple languages in the target recognition image.
[0075] Taking the target recognition image 2 as an example, as shown in Figure 6, the target recognition image 2 is obtained by correcting the image to be recognized 2. The target recognition image 2 contains Chinese, Japanese and English. Figure 6 contains dashed boxes 61, 62, 63, 64. Among them, both dashed boxes 61 and 64 represent the text region images corresponding to Japanese, dashed box 62 represents the text region image corresponding to Chinese, and dashed box 63 represents the text region image corresponding to English. That is, the text region images represented by dashed boxes 61 and 64 constitute the text region image set corresponding to Japanese, the text region image represented by dashed box 62 constitutes the text region image set corresponding to Chinese, and the text region image represented by dashed box 63 constitutes the text region image set corresponding to English.
[0076] S204. Based on the text region image sets corresponding to each of the multiple languages, respectively use the target text recognition models associated with the corresponding languages for processing to obtain the text recognition results corresponding to the image to be recognized.
[0077] To improve text recognition efficiency, five target text recognition models can be designed based on the characteristics and scale of the character sets corresponding to different languages. These five target text recognition models are the target text recognition models corresponding to Chinese, Japanese, Korean, English, and mixed Latin. Mixed Latin includes Latin, Thai, Vietnamese, Russian, Arabic, and Hindi, but is not limited to these. The scale of the character sets corresponding to Chinese, Japanese, Korean, Thai, and mixed Latin are 10,000+, 9,000+, 8,000+, 200+, and 1,000+, respectively. The following description uses the above five target text recognition models as examples.
[0078] Specifically, when executing S204, the following operations may be used but are not limited to:
[0079] For each of the multiple languages, a text region image set corresponding to the text region image set is input into a target text recognition model associated with the language to obtain a text recognition sub-result corresponding to the text region image set;
[0080] Based on the text recognition sub-results corresponding to each text region image set, a text recognition result corresponding to the image to be recognized is obtained.
[0081] Still taking the target recognition image 2 as an example, refer to Figure 7. In Figure 7, the dotted box 61 and the dotted box 64 both represent the text area images corresponding to Japanese, the dotted box 62 represents the text area image corresponding to Chinese, and the dotted box 63 represents the text area image corresponding to English. The text area image represented by the dotted box 61 is input into the target text recognition model associated with Japanese to obtain the corresponding text recognition sub-result 61, the text area image represented by the dotted box 64 is input into the target text recognition model associated with Japanese to obtain the corresponding text recognition sub-result 64, the text area image represented by the dotted box 62 is input into the target text recognition model associated with Chinese to obtain the corresponding text recognition sub-result 62, and the text area image represented by the dotted box 63 is input into the target text recognition model associated with English to obtain the corresponding text recognition sub-result 63. Then, based on the text recognition sub-result 61, the text recognition sub-result 62, the text recognition sub-result 63 and the text recognition sub-result 64, the text recognition result is obtained.
[0082] Since the distribution of character sets in different languages varies greatly, the above implementation method can relatively avoid the recognition results being biased towards languages with large character sets (such as Chinese, Japanese, Korean, etc.) and ignoring languages with small character sets (such as Latin, Arabic, Thai, etc.), thereby improving text recognition accuracy. The text recognition model is adaptively optimized according to the text characteristics of the language, realizing flexible model updates.
[0083] In some embodiments, the image to be recognized may be obtained through text detection, which may be achieved by, but not limited to, the following methods:
[0084] Method 1: Obtain an original image and extract at least one sub-image containing text from the original image.
[0085] Specifically, the original image can be input into the target text line detection model to obtain at least one sub-image containing text. The target text line detection model can be implemented using a Differentiable Binarization (DB) algorithm, but is not limited thereto.
[0086] As shown in Figure 8A, the backbone network of the target text line detection model can adopt a fully convolutional network (FCN) architecture based on a lightweight network architecture. The multi-stream branch at the head is used to determine whether pixels in the original image are text and for binarization threshold learning. The target text line detection model can be composed of a 3×3 convolution operator and two deconvolution operators with a stride of 2. 1 / 2, 1 / 4, 1 / 8, 1 / 16, and 1 / 32 respectively represent the ratio compared to the input original image. The lightweight network architecture can adopt, but is not limited to, MobilenetV2, MobilenetV3, and ShuffleNet.
[0087] The input original image passes through the resnet50-vd layer of the Feature Pyramid Networks (FPN). At the same time, the output of the feature pyramid network is transformed to the same size by upsampling and cascaded to generate a feature map. Then, based on the feature map, a probability map and a threshold map can be predicted. The probability map is used to represent the probability that each pixel in the original image belongs to the text, and the threshold map is used to represent the threshold corresponding to each pixel in the original image. Furthermore, based on the probability map and the threshold map, an approximate binary map can be obtained. Finally, based on the binary map, the corresponding sub-images can be obtained, including sub-image 1, sub-image 2 and sub-image 3. Sub-image 1 contains the text "Harvesting", sub-image 2 contains the text "great", and sub-image 3 contains the text "skills".
[0088] Method 2:
[0089] An original image is obtained, and at least one sub-image containing text is extracted from the original image. Based on a preset image shape, shape correction processing is performed on each extracted sub-image, and any one of the sub-images obtained after the correction processing is used as the image to be recognized.
[0090] The preset image shape can be set to a regular shape such as a rectangle, but is not limited thereto. In practical applications, to facilitate subsequent image processing operations, the preset image shape is typically set to a rectangle. In other words, the sub-image shape is corrected to a rectangle. Since the process of extracting a sub-image in Method 2 is the same as that in Method 1, it will not be further described here.
[0091] For example, referring to FIG8B , it is assumed that the preset image shape is a rectangle, sub-image 1 contains the text “Harvesting”, and the image shape of sub-image 1 is curved. Based on the preset image shape, the extracted sub-image 1 is subjected to shape correction processing to obtain the corrected sub-image 1. The corrected sub-image 1 is a rectangular image containing the text “Harvesting”, and this rectangular image can be used as the image to be recognized.
[0092] Obviously, in the embodiment of the present application, by performing polygon fitting on the extracted sub-image, the curved text area is corrected into a rectangular text area, and then subsequent text recognition is performed based on the rectangular text area. It is possible to detect and identify text areas of arbitrary shapes, and at the same time, the text recognition accuracy can be further improved.
[0093] Next, the target classification model and target text recognition model involved in the embodiments of this application are introduced respectively:
[0094] First, target classification model
[0095] As shown in Figure 9, the target classification model can include a target feature extraction network, a target language recognition sub-model, and a target direction recognition sub-model. The target feature extraction network can adopt but is not limited to a convolutional neural network (CNN). The target feature extraction network includes S1, S2, S3, and S4 layers. The S1 layer includes depthwise (DW) convolution, conventional convolution, activation function, matrix multiplication, pointwise (PW) convolution and other operations. Conventional convolution can also be directly called convolution.
[0096] First, the training process of the target language recognition sub-model is introduced.
[0097] In some embodiments, the target language recognition sub-model can be trained by the following operations:
[0098] Based on the acquired first training data set, the initial language recognition sub-model included in the initial recognition model is iteratively trained to obtain a target language recognition sub-model. Referring to FIG. 10A , in one iteration, the following operations are performed:
[0099] S1001: Input training data x into the initial language recognition sub-model to obtain predicted language distribution information corresponding to the training data x. The training data x can be any training data included in the first training data set.
[0100] Taking image a as the training data as an example, refer to Figure 10B. Image a contains the text "20th Anniversary of a Certain Food Company". Image a is input into the initial language recognition sub-model to obtain the predicted language distribution information corresponding to image a. The predicted language distribution information corresponding to image a contains Chinese and character identifiers, as well as the predicted text position information corresponding to Chinese and character identifiers. Among them, the predicted text position information corresponding to Chinese is used to represent the predicted position information of the text "0th Anniversary of a Certain Food Company", and the predicted text position information corresponding to the character identifier is used to represent the predicted position information of the text "2".
[0101] S1002: Determine a first model loss based on the predicted language distribution information and the true language distribution information corresponding to the training data x.
[0102] Still taking image a as the training data as an example, as shown in Figure 10B, the real language distribution information corresponding to image a includes Chinese and character identifiers, as well as the real text position information corresponding to Chinese and character identifiers. Among them, the real text position information corresponding to Chinese is used to represent the real position information of the text "XX Food Company" and "Anniversary", and the real text position information corresponding to the character identifier is used to represent the real position information of the text "20".
[0103] S1003. Adjust the model parameters of the initial language recognition sub-model based on the first model loss.
[0104] Through the above implementation, the model can be trained based on the predicted language distribution information and the actual language distribution information corresponding to the training data, thereby improving the language classification accuracy of the model and further improving the accuracy of text recognition.
[0105] In actual applications, the text contained in an image may not be entirely of a single type. For example, Chinese characters often appear in Japanese and Korean. In another example, Latin characters and symbols often appear mixed with characters of any language. To accurately describe the distribution of mixed characters, in this embodiment of the application, by optimizing model parameters, the predicted language distribution information fits the soft target. The soft target refers to the statistical probability of each type of character appearing in each text string. Specifically, referring to FIG10A , when executing S1002, the following operations may be used, but are not limited to:
[0106] S10021. Determine a predicted distribution probability based on the predicted language distribution information. The predicted distribution probability includes the predicted probability corresponding to each language. The predicted probability is used to represent the proportion of the predicted text length of the corresponding language in each language.
[0107] Taking image a as the training data as an example, the predicted distribution probability is determined based on the predicted language distribution information corresponding to image a. In the predicted distribution probability, the predicted probability of Chinese is 90%, and the predicted probability of symbol identification is 10%.
[0108] S10022. Determine a true distribution probability based on the true language distribution information. The true distribution probability includes the true probability corresponding to each language. The true probability is used to represent the proportion of the true text length of the corresponding language in each language.
[0109] Still taking image a as the training data as an example, based on the real language distribution information, the real distribution probability is determined. In the real distribution probability, the real probability of Chinese is 80%, and the real probability of symbol identification is 20%.
[0110] S10023. Determine the first model loss based on the predicted distribution probability and the true distribution probability.
[0111] Through the above implementation, the mixed character distribution situation can be effectively described, thereby improving the prediction accuracy of language distribution and further improving the recognition accuracy of multilingual text.
[0112] In some embodiments, when executing S10023, the first model loss may adopt cross entropy loss (CE loss) or Kullback-Leibler divergence loss.
[0113] In order to describe the similarity between the predicted distribution probability and the true distribution probability, in the embodiment of the present application, KL divergence loss can be used as the target loss for the network to predict the language. The calculation method of KL divergence loss is shown in formula (1):
[0114] Here, P is used to represent the predicted distribution probability, Q is used to represent the true distribution probability, P(x) is used to represent the predicted probability corresponding to language x, and Q(x) is used to represent the true probability corresponding to language x, where x is a language among all languages.
[0115] Next, the acquisition process of the target direction recognition sub-model is introduced.
[0116] As a possible implementation method, in an embodiment of the present application, in an iterative process, the training data x can be input into the initial direction recognition sub-model to obtain the predicted text presentation direction of the training data x, and then, based on the predicted text presentation direction and the actual text presentation direction of the training data x, the second model loss is determined, and then based on the second model loss, the model parameters of the initial direction recognition sub-model are adjusted.
[0117] As another possible implementation, in order to enable the model to better learn the differences between images with different text presentation directions, in the embodiment of the present application, images with different text presentation directions can be obtained at the input layer. By maximizing the feature distance of images with different text presentation directions during model training, this difference can be increased, allowing the model to better learn to understand the text presentation direction. Specifically, the target direction recognition sub-model is obtained by the following operations:
[0118] Based on the acquired first training data set, the initial direction recognition sub-model included in the initial recognition model is iteratively trained to obtain a target direction recognition sub-model.
[0119] Next, the iteration process is described using the training data x as an example. Referring to FIG. 11A , the following operations are performed during the iteration process:
[0120] S1101 , obtaining training data x, and rotating the training data x according to a preset image rotation angle to obtain comparison data y.
[0121] In the embodiment of the present application, in order to enable the model to better learn the differences between images with opposite text orientations, that is, text presentation orientations of 0° and 180°, and text presentation orientations of 90° and 270°, the preset image rotation angle can be set to 180°. It should be noted that the image rotation angle can be set according to the actual application scenario and is not limited to 180°.
[0122] Taking the training data x as image b as an example, as shown in Figure 11B, image b contains the Korean word "Hello". After obtaining image b, the training data x is rotated according to the preset image rotation angle of 180° to obtain the comparison data y.
[0123] S1102 : Input the training data x and the comparison data y into the initial direction recognition sub-model respectively to obtain the predicted text presentation directions corresponding to the training data x and the comparison data y.
[0124] Still taking the training data x as image b as an example, the training data x is input into the initial direction recognition sub-model to obtain the predicted text presentation direction corresponding to the training data x, and the predicted text presentation direction corresponding to the training data x is 0°, and the comparison data y is input into the initial direction recognition sub-model to obtain the predicted text presentation direction corresponding to the comparison data y, and the predicted text presentation direction corresponding to the comparison data y is 180°.
[0125] S1103 : Determine a second model loss based on the predicted text presentation directions corresponding to the training data x and the comparison data y, and adjust the model parameters of the initial direction recognition sub-model based on the second model loss.
[0126] Through the above implementation method, the model can learn the differences between images with different text presentation directions, thereby improving the recognition accuracy of text under different text presentation directions.
[0127] In some embodiments, the second model loss can be a model prediction loss or a contrast loss, or a weighted combination of the model prediction loss and the contrast loss. The model prediction loss can be a cross-entropy loss or a focal loss, but is not limited thereto. The following description uses the cross-entropy loss as an example.
[0128] If the second model loss adopts the cross entropy loss, the cross entropy loss is calculated based on each predicted text presentation direction and the corresponding true text presentation direction, and the calculated cross entropy loss is used as the second model loss.
[0129] If the second model loss adopts contrast loss, then based on the obtained predicted text presentation directions, the contrast loss between the predicted text presentation directions is calculated, and the calculated contrast loss is used as the second model loss.
[0130] If the second model loss uses the weighted result of cross entropy loss and contrast loss, the second model loss can be determined as follows:
[0131] Determine the contrast loss based on the image features corresponding to the training data x and the comparison data y;
[0132] Based on the actual text presentation directions corresponding to the training data x and the comparison data y, and the predicted text presentation directions corresponding to the training data x and the comparison data y, the cross entropy loss corresponding to the training data x and the comparison data y, i.e., the model prediction loss, is determined;
[0133] The second model loss is determined based on the obtained cross entropy loss, contrast loss, cross entropy loss weight, and contrast loss weight.
[0134] The calculation formula of contrast loss is shown in formula (2): C loss =max(margin-d,0) 2 Formula (2)
[0135] Among them, C loss represents the contrast loss, d is used to represent the Euclidean distance between the image features corresponding to the training data x and the comparison data y, margin is the set threshold, and the max() function is used to obtain the maximum value.
[0136] It should be noted that the image features corresponding to the training data x and the comparison data y respectively refer to the image features obtained after image feature extraction on the image, and the image features can also be called image embedding.
[0137] When determining the loss of the second model based on the obtained cross entropy losses, contrast losses, cross entropy loss weights, and contrast loss weights, the second model loss can be determined based on the sum of the cross entropy losses or the average of the cross entropy losses, using cross entropy loss weights and contrast loss weights, but is not limited to this.
[0138] Still taking the training data x as image b as an example, referring to Figure 11C, based on the image features corresponding to the training data x and the comparison data y, the contrast loss is determined to be 0.2. Then, based on the real text presentation direction and the predicted text presentation direction corresponding to the training data x, the cross-entropy loss corresponding to the training data x is determined to be 0.1. Based on the real text presentation direction and the predicted text presentation direction corresponding to the comparison data y, the cross-entropy loss corresponding to the comparison data y is determined to be 0.1. Then, assuming that the weights corresponding to the cross-entropy loss and the contrast loss are both 0.5, the cross-entropy loss weight and the contrast loss weight are used to perform weighted sum processing on the sum of the cross-entropy losses and the contrast loss, and the second model loss is determined to be 0.2.
[0139] Obviously, in the embodiment of the present application, this difference can be increased by maximizing the distance between images of different text presentation directions in the feature layer during model training, allowing the model to better learn to understand the text presentation direction, thereby improving the model's recognition accuracy of the text presentation direction, and further improving the accuracy of text recognition.
[0140] It should be noted that in the embodiments of the present application, the target direction recognition sub-model and the target language recognition sub-model can be included in the same target classification model, and the target direction recognition sub-model and the target language recognition sub-model can also be configured separately to realize different functions of the target classification model, which will not be described in detail.
[0141] Finally, the acquisition process of the target feature extraction network is introduced.
[0142] For an image containing text, determining the language can rely on the image's surface features, but determining the text's orientation requires identifying and understanding the text's content. This approach, based solely on surface features, cannot handle some special images. For example, as shown in Figure 12, both image c and image d contain the text "codep." The text orientation in image c is 180°, while that in image d is 0°. However, the text recognition result for image d is "codep," while the text recognition result for image c is "dapos." Clearly, the text recognition is incorrect.
[0143] To assist the model in learning the text presentation direction and improve the accuracy of text presentation direction classification, in the embodiment of the present application, a multi-stream recognition model using the same backbone network as the target classification model is introduced as a pre-training task. The multi-stream recognition model is used to recognize multilingual text content. After the multi-stream recognition model is trained, the backbone network of the trained multi-stream recognition model is used as the target feature extraction network. Furthermore, based on the target feature extraction network, the initial language recognition sub-model and the initial direction recognition sub-model are trained to obtain the target language recognition sub-model and the target direction recognition sub-model.
[0144] Specifically, the target feature extraction network is trained through the following operations:
[0145] Build a pre-trained language recognition model based on the initial feature extraction network;
[0146] Based on the acquired second training data set, the pre-trained recognition network is iteratively trained to obtain a target feature extraction network.
[0147] It should be noted that in the embodiment of the present application, the pre-trained language recognition model can also be called a multi-stream recognition model.
[0148] As shown in Figure 13, the pre-trained language recognition model includes an input layer, a backbone network, a timing model, a multi-stream decoder and an output layer. The backbone network has the same structure as the backbone network in the target classification model. The backbone network is used to learn image appearance features, the timing model is used to learn text context information, and the multi-stream decoder includes but is not limited to decoders corresponding to Chinese, Japanese, Korean, Latin, Thai, Arabic, Hindi, and symbol identification.
[0149] Among them, the time series model can use the Long Short-Term Memory (LSTM) network. t represents the input value at time t, yt Represents the output value at time t, σ represents the gate activation function. In LSTM, by forgetting the information in the cell state and remembering new information, the information useful for subsequent calculations can be transmitted, while the useless information is discarded. The forward LSTM and the reverse LSTM are combined to form a bidirectional long short-term memory network (BiLSTM).
[0150] Through the above implementation method, the model convergence speed can be significantly improved. At the same time, the classification accuracy of text presentation direction and language distribution can be improved, thereby improving text recognition accuracy.
[0151] In some embodiments, the target classification model will introduce additional overhead in the entire text recognition process. Once the number of text lines in the image is large, the time overhead will increase exponentially. In order to minimize the time cost of the target classification model, in an embodiment of the present application, the target classification model can be compressed and pruned. Specifically, the target feature extraction network can adopt a lightweight network architecture, and the lightweight network architecture can adopt but is not limited to mobilenetv2, mobilenetv3, and shufflenet, etc. In addition, in order to enhance feature attention, a SE (squeeze-excitation) layer can be added to the target feature extraction network, and a dimensionality reduction layer can be added to at least one of the target direction recognition sub-model and the target language recognition sub-model to further reduce operations.
[0152] In order to further improve the online prediction speed of the model, in an embodiment of the present application, pytorch quantization-aware training (QAT) can be used to adapt TensorRT int8 to perform 8-bit quantization model tuning, thereby improving the prediction speed of the online graphics processing unit (GPU) while ensuring only a slight loss in classification accuracy.
[0153] Second, target text recognition model
[0154] In an embodiment of the present application, the target text recognition model includes an image feature encoder, a timing model, and a decoder, wherein the decoder can adopt a connectionist temporal classification (CTC) decoder and an attention mechanism to implement multi-task decoding, and the attention mechanism is used to assist CTC learning. The image feature encoder can adopt but is not limited to ResNet-50VD, the timing model can adopt but is not limited to bidirectional LSTM, and the timing model is used to enhance the learning of text context information in the image. Since the structure of the text recognition model is similar to that of the multi-stream recognition model, it will not be repeated here.
[0155] Because the scale of real data and synthetic data used in model training is quite different, for example, real data is in the tens of thousands, while synthetic data is in the millions. In addition, unlike Chinese and English recognition tasks, multilingual recognition annotation data is extremely scarce, costly, difficult to check, and requires professional linguists to assist in annotation, which places high demands on the annotators' abilities and makes it impossible to obtain a large amount of training data in a short period of time.
[0156] In order to avoid the impact of the severe scarcity of multilingual recognition annotation data on text recognition performance, in the embodiments of the present application, on the one hand, semi-supervised learning (SSL) can be used to improve text recognition performance. SSL is widely used in image classification tasks and can be used to solve the problem of shortage of labeled training data. On the other hand, text recognition performance can also be improved through data generation.
[0157] Next, we will introduce the semi-supervised learning process.
[0158] Specifically, in the embodiment of the present application, the target text recognition model is trained by the following operations:
[0159] Obtain a third training data set, where the third training data set includes labeled samples and unlabeled samples;
[0160] Based on each labeled sample, a first text recognition model including an image feature extraction network is trained to obtain a second text recognition model, and an image-text distance recognition model is constructed based on the image feature extraction network included in the second text recognition model;
[0161] Based on the labeled samples and the unlabeled samples, and the image-text distance recognition model, the second text recognition model is iteratively trained to obtain a target text recognition model.
[0162] It should be noted that, in the embodiment of the present application, the first training data set, the second training data set, and the third training data set may be the same or different, and there is no limitation on this.
[0163] Among them, each labeled sample contains the corresponding real text recognition result, and each unlabeled sample does not contain the corresponding real text recognition result.
[0164] The first text recognition model is an untrained text recognition model. The image feature extraction network can use, but is not limited to, a CNN. The image-text distance recognition model uses the image feature extraction network included in the second text recognition model as its own image feature extraction network.
[0165] The input of the image-text distance recognition model is each labeled sample and the corresponding sample label. The model loss can adopt the ranking loss, the purpose of which is to minimize the image-text distance of the same pair of labeled samples and sample labels, and maximize the image-text distance of different pairs of labeled samples and sample labels.
[0166] For example, referring to Figure 14, for the labeled sample 1, the labeled sample 1 and its corresponding sample label are input into the image-text distance recognition model to obtain the image features corresponding to the labeled sample 1 and the text features corresponding to the sample label. By optimizing the model parameters, the image-text distance between the image features corresponding to the labeled sample 1 and the text features corresponding to the sample label is minimized.
[0167] Specifically, referring to FIG15 , when iteratively training the second text recognition model, the following operations may be iteratively performed for each labeled sample and each unlabeled sample:
[0168] S1501: Obtain N labeled samples and M unlabeled samples, and input the M unlabeled samples into a second text recognition model respectively to obtain predicted text recognition results corresponding to the M unlabeled samples.
[0169] It should be noted that in the embodiments of the present application, the values of N and M are both positive integers. The values of N and M can be the same or different. The N labeled samples and M unlabeled samples obtained can be called a batch of image data (batch).
[0170] Taking the unlabeled sample 2 as an example, referring to FIG14 , the unlabeled sample 2 is input into the second text recognition model to obtain the predicted text recognition result 2 corresponding to the unlabeled sample 2. The predicted text recognition result 2 is “BA CHU LON CON”.
[0171] S1502. Input M unlabeled samples and their corresponding predicted text recognition results into the image-text distance recognition model to obtain the image-text distance corresponding to each of the M unlabeled samples, and based on the obtained image-text distances, determine the sub-loss of each model corresponding to at least one unlabeled sample.
[0172] Still taking the unlabeled sample 2 as an example, referring to FIG14 , the unlabeled sample 2 and the corresponding predicted text recognition result 2 are input into the image-text distance recognition model to obtain the image-text distance D1 corresponding to the unlabeled sample 2, and the value of D1 is 0.33.
[0173] Specifically, based on the obtained image-text distances, determining the sub-loss of each model corresponding to at least one unlabeled sample includes:
[0174] Based on the obtained image-text distances, unlabeled samples with image-text distances not greater than a preset distance threshold are screened out from the M unlabeled samples, and the screened unlabeled samples are used as samples to be enhanced;
[0175] Obtaining target enhancement samples corresponding to each to-be-enhanced sample, and using the predicted text recognition result corresponding to each to-be-enhanced sample as a sample label of the corresponding target enhancement sample;
[0176] The obtained target enhancement samples are respectively input into the second text recognition model to obtain the model sub-loss corresponding to each target enhancement sample, and the model sub-loss corresponding to each target enhancement sample is used as the model sub-loss corresponding to the M unlabeled samples.
[0177] It should be noted that in the embodiments of the present application, the target enhanced sample refers to the sample data obtained by data augmenting the corresponding sample to be enhanced through data augmentation methods such as rotation, flipping, scaling, contrast change, and noise perturbation. The sample label of the target enhanced sample can also be called the pseudo label of the target enhanced sample.
[0178] Still taking the unlabeled sample 2 as an example, refer to FIG14 , assuming that the preset distance threshold is 0.5, and the image-text distance D1 corresponding to the unlabeled sample 2 is not greater than 0.5, the unlabeled sample 2 can be used as a sample to be enhanced. Then, the target enhanced sample 2 corresponding to the unlabeled sample 2 is obtained, and the predicted text recognition result 2 is "BA CHU LON CON" as the pseudo label of the target enhanced sample 2. Afterwards, the obtained target enhanced sample 2 is input into the second text recognition model to obtain the predicted text recognition result corresponding to the target enhanced sample 2. Then, based on the predicted text recognition result and the pseudo label, the model sub-loss corresponding to the target enhanced sample 2 is obtained. Similarly, the model sub-loss corresponding to each target enhanced sample can be obtained. When the image-text distance corresponding to each of the M unlabeled samples is not greater than the preset distance threshold, the model sub-loss corresponding to each of the M unlabeled samples can be obtained.
[0179] S1503: Input the N labeled samples into the second text recognition model respectively to obtain the model sub-loss corresponding to each of the N labeled samples.
[0180] It should be noted that the model sub-loss can adopt cross entropy loss, focal loss, etc.
[0181] Taking labeled sample 1 as an example, labeled sample 1 is input into the second text recognition model to obtain the predicted text recognition result corresponding to labeled sample 1. Then, based on the difference between the predicted text recognition result and the sample label corresponding to labeled sample 1, the model sub-loss corresponding to labeled sample 1 is obtained. The model sub-loss corresponding to labeled sample 1 is 1.
[0182] S1504: Determine a third model loss based on the obtained sub-losses of each model, and adjust the model parameters of the second text recognition model based on the third model loss.
[0183] In this embodiment of the present application, in an input batch, the sum of the model sub-losses corresponding to the N labeled samples and the M unlabeled samples can be used as the third model loss. Gradient backpropagation is then performed based on the third model loss to achieve the purpose of optimizing model parameters.
[0184] The scales of real data and synthetic data used in model training are quite different. For example, the real data is in the tens of thousands, while the synthetic data is in the millions. Through the above implementation method, on the one hand, through the collaborative training of dual-stream input of real data and synthetic data, it can avoid the real data being "swamped" by the synthetic data. On the other hand, based on the semi-supervised learning method, the text recognition performance can be improved.
[0185] Characters in some specialized languages often contain affixes and tone marks, often located above or below the base character. Therefore, text recognition in these languages requires consideration not only of temporal order but also of two-dimensional spatial information. For example, as shown in Figure 16, Thai characters contain affixes and tone marks, which are often located above or below the base character.
[0186] To improve recognition accuracy for such languages, in some embodiments, the decoder in the target text recognition model can utilize a two-dimensional spatial attention decoder from the irregular text recognition (SAR) method. The introduction of a two-dimensional spatial attention decoder eliminates the need for focusing solely on temporal information at each decoding step, instead incorporating spatial image features. This results in improved recognition performance for irregular, spatially distributed text.
[0187] Since SAR calculates 2D attention weights at each step during decoding, its decoding speed is nearly 15 times that of CTC. In addition, for long texts, the recognition accuracy of SAR is also easily limited. Therefore, in some embodiments, the decoder in the target text recognition model can also adopt a dual-stream decoding structure of CTC and SAR. The two decoders share the temporal features of LSTM and only predict the CTC branch results during decoding. SAR is used to assist CTC learning.
[0188] For example, as shown in Figure 17A, the CNN module can use a 31-layer ResNet to generate a feature map. The feature map then passes through an LSTM-based encoder-decoder framework and a 2D attention module connected to the decoder, ultimately outputting text recognized by SAR. The feature map then passes through a CTC decoder to output text recognized by CTC.
[0189] Through the above implementation method, the image is downsampled to 1 / 8 of its original height after CNN, which can retain more spatial information and improve the recognition accuracy of the text recognition model without incurring any forward time overhead.
[0190] In the SAR-based decoding process, the two-dimensional attention module introduced this algorithm in the Thai recognition model. Experimental data showed that the recognition accuracy of SAR was improved by nearly 7% compared with CTC.
[0191] In the SAR decoding process, the introduction of a two-dimensional attention module enables each decoding step to no longer focus solely on temporal information, but instead considers spatial image features. This results in better recognition performance for irregular, spatially distributed text. Figure 17B shows a Thai language recognition model using SAR and CTC as decoders. In image e, the Thai word "hello" represents "hello," and in image f, the Thai word "summer." CTC contains misrecognized characters. Clearly, SAR achieves higher recognition accuracy than CTC.
[0192] Next, the data generation process is introduced.
[0193] Specifically, at least one of the following operations may be performed:
[0194] Operation A: Data synthesis.
[0195] Specifically, each text corpus, each font format, and each background image are obtained, and each labeled sample is synthesized based on each text corpus, each font format, and each background image.
[0196] In an embodiment of the present application, data synthesis can be performed based on the architecture of TextRenderer, where the input is text corpus, font format, and background image in any language, and the output is a synthesized annotation sample.
[0197] For example, referring to FIG18A , the text corpus 1 is rberinMann, the font format 1 is Robot.ttf, and the background image 1 is a textured background. Based on the text corpus 1, the font format 1, and the background image 1, the synthesized annotation sample is shown in FIG18A .
[0198] In order to further increase the number of samples, referring to FIG18B , in an embodiment of the present application, in the process of synthesizing the annotation samples, for the text corpus, its font size, color, spacing, thickness and other information can be configured, and horizontal text rendering or vertical text rendering can also be performed. For the background image, the background image can be subjected to processing operations such as clipping, image enhancement transformation, etc., and then the processed background image can be superimposed with the text corpus. As an example, the image obtained after superposition can be directly used as a synthesized annotation sample. As another example, for the image obtained after superposition, one or more of the following operations can be performed: Poisson fusion, perspective transformation, alpha channel image superposition, image highlight enhancement, image print enhancement, image enhancement, interference, image size transformation, wherein interference includes but is not limited to blur, noise, and horizontal linear superposition interference.
[0199] This approach, tailored to the characteristics of multilingual data, enables the generation of images in languages such as Chinese, Japanese, Korean, Thai, Vietnamese, Russian, Arabic, Latin, and Hindi. It also supports the generation of both horizontal and vertical text images, as well as text in special languages such as Arabic and Hindi (which are right-to-left and have special distortions). Furthermore, by introducing operations such as highlights, print interference, and data collage into the data synthesis process, the synthesized images can be made closer to the real data.
[0200] Operation B: Data style transfer.
[0201] Specifically, each text corpus is obtained and each text corpus is input into the target data style transfer model to obtain each labeled sample.
[0202] As shown in FIG19 , the target data style transfer model includes a text transfer module, a background extraction module and a text fusion module. The target data style transfer model adopts a generative adversarial network (GAN). After the text corpus and the image of the target text style are input into the target data style transfer model, the text corpus is processed by the text transfer module to obtain the text corpus Osk corresponding to the target text font in the target text style. The target text style is processed by the text transfer module and the background extraction module to output the image background Ob contained in the target text style. In addition, the target text style can also output the text corpus Ot corresponding to the target text font containing the original image background through the text transfer module, thereby generating the corresponding labeled samples. FIG19 also includes L T , L B and L F , where L T represents the model loss of the text transfer module, L B represents the model loss of the background extraction module, L FRepresents the model loss of the text fusion module.
[0203] Referring to Figure 20, when the text corpus is "requires" and the target text style is as shown in image g, the text corpus "requires" and the target text style are input into the target data style transfer model to obtain the corresponding labeled samples. When the text corpus is "crisis" and the target text style is as shown in image h, the text corpus "crisis" and the target text style are input into the target data style transfer model to obtain the corresponding labeled samples. When the text corpus is "beyond" and the target text style is as shown in image i, the text corpus "beyond" and the target text style are input into the target data style transfer model to obtain the corresponding labeled samples.
[0204] Since the model training of GAN is not stable enough, on the one hand, in the embodiment of the present application, the Hinge loss in SN-GAN can be used to replace the original adversarial loss to stabilize the training process and avoid large fluctuations in the gradient. On the other hand, when calculating the L1 loss of the generated labeled samples and the target text style, in the embodiment of the present application, the text mask area weighted L1 loss can be used to reduce the model's over-learning of the background and enhance the constraints on the pixels in the text area. In the testing phase, the trained data style transfer model is used to perform style transfer learning on the input text prediction and target text style images, thereby generating recognition data that is closer to the real data.
[0205] Through the above implementation method, the font style of real data is learned through data style transfer. On the one hand, it can further solve the domain difference between synthetic data and real data. On the other hand, real data can be used to transfer the style of synthesized data, and real data can also be used to transfer the style of other real data, thereby increasing sample diversity.
[0206] It should be noted that in the embodiment of the present application, in the semi-supervised text recognition model, reinforcement learning (DQN) can also be used to train the model, wherein the text recognition model serves as the agent part in DQN, the image and predicted text can serve as the environment part in DQN, and the feedback (reward) can be represented by the image-text distance and edit distance reward.
[0207] The text language / direction classification network (LOPN) proposed in the embodiment of the present application can quickly and accurately predict the language distribution and determine the direction of a text line image. The experimental results on the set test set are shown in Table 1. As can be seen from Table 1, the use of soft target probability to model the language distribution and the use of KL divergence loss can achieve a performance gain of nearly 7% in the accuracy of language classification. At the same time, the classification model pre-trained with the multi-stream text recognition model has made great improvements in language classification and direction classification. The introduction of the recognition task strengthens the model's understanding of image text and makes up for the shortcomings of classification based solely on image appearance features. Furthermore, the addition of dual-stream data supervision in direction classification helps the model better distinguish the direction of image text and improves the performance of direction classification.
[0208] Table 1 LOPN test set accuracy
[0209] In the embodiment of the present application, TensorRT is used to deploy the above classification network model, and the NVIDIA-T4 GPU model is used online. The prediction speed comparison results of the original model and the quantized model are shown in Table 2.
[0210] Table 2 Comparison of prediction accuracy and speed of LOPN TensorRT model
[0211] As shown in Table 3, the text recognition model in the embodiment of the present application combines data synthesis optimization and semi-supervised training, and achieves high recognition performance on the set language test set. At the same time, compared with the open source model, the recognition accuracy significantly exceeds the existing open source model.
[0212] Specifically, normalized edit distance (NED) and sequence accuracy (SeqACC) can be used as evaluation indicators for recognition tasks. NED can be calculated using formula (3), and SeqACC can be calculated using formula (4):
[0213] In formula (3) and formula (4), D represents the Levenshtein distance, s i Represents the predicted text (i.e., text recognition result), represents the true value, N represents the total number of images to be recognized, |x| + Represents a statistical operation, adding 1 when the value of x is true.
[0214] Table 3 Accuracy of multilingual text recognition model
[0215] Obviously, it can be seen from Table 3 that in the training of different language data sets, the multi-stream data training, multi-task decoding, semi-supervised text recognition training, data style transfer and enhanced data enhancement adopted in the embodiments of the present application all bring effective performance gains to the text recognition task, and have high practicality and universality.
[0216] Table 4 shows the Thai recognition accuracy comparison results for models using the CTC decoder, the SAR decoder, and the CTC+SAR dual-stream decoder. Clearly, the CTC+SAR dual-stream decoder performs best in terms of recognition speed and NED.
[0217] Table 4 Comparison of Thai recognition accuracy
[0218] Based on the same inventive concept, the present embodiment provides a text recognition device. As shown in FIG21 , it is a schematic diagram of the structure of the text recognition device 2100, which may include:
[0219] The image classification unit 2101 is configured to input an image to be recognized containing text into a target classification model to obtain language distribution information and the original text presentation direction of the image to be recognized, wherein the language distribution information includes multiple languages corresponding to the text and text position information corresponding to each of the multiple languages;
[0220] An image correction unit 2102 is configured to correct the image to be recognized based on the original text presentation direction and the preset target text presentation direction to obtain a target recognition image;
[0221] A text locating unit 2103 is configured to determine, in the target recognition image, text region image sets corresponding to the multiple languages, based on the text position information corresponding to the multiple languages;
[0222] The image recognition unit 2104 is configured to process the text region image sets corresponding to the multiple languages using target text recognition models associated with the corresponding languages to obtain text recognition results corresponding to the image to be recognized.
[0223] As a possible implementation, the image recognition unit 2104 is specifically configured to:
[0224] For each of the plurality of languages, inputting the text region image set corresponding to the language into a target text recognition model associated with the language to obtain a text recognition sub-result corresponding to the text region image set;
[0225] Based on the text recognition sub-results corresponding to each of the text region image sets, a text recognition result corresponding to the image to be recognized is obtained.
[0226] As a possible implementation, the text recognition device 2100 further includes a model training unit 2105. The target classification model includes a target language recognition sub-model. The model training unit 2105 is configured to:
[0227] Based on the acquired first training data set, iteratively train the initial language recognition sub-model included in the initial recognition model to obtain the target language recognition sub-model, wherein, during one iteration, the following operations are performed:
[0228] Inputting the training data contained in the first training data set into the initial language recognition sub-model to obtain predicted language distribution information corresponding to the training data;
[0229] Based on the predicted language distribution information and the real language distribution information corresponding to the training data, a first model loss is determined, and based on the first model loss, model parameters of the initial language recognition sub-model are adjusted.
[0230] As a possible implementation, when determining the first model loss based on the predicted language distribution information and the real language distribution information corresponding to the training data, the model training unit 2105 is specifically configured to:
[0231] Determining a predicted distribution probability based on the predicted language distribution information, wherein the predicted distribution probability includes a predicted probability corresponding to each language, and the predicted probability is used to represent the proportion of the predicted text length of the corresponding language in the respective languages;
[0232] Determining a true distribution probability based on the true language distribution information, wherein the true distribution probability includes a true probability corresponding to each language, and the true probability is used to represent the proportion of the true text length of the corresponding language in the respective languages;
[0233] The first model loss is determined based on the predicted distribution probability and the true distribution probability.
[0234] As a possible implementation, the text recognition device 2100 further includes a model training unit 2105. The target classification model includes a target direction recognition sub-model. The model training unit 2105 is used to:
[0235] Based on the acquired first training data set, iteratively perform model training on the initial direction recognition sub-model included in the initial recognition model to output the target direction recognition sub-model, wherein, during one iteration, the following operations are performed:
[0236] Obtaining training data contained in the first training data set, and rotating the training data according to a preset image rotation angle to obtain comparison data corresponding to the training data;
[0237] Inputting the training data and the comparison data into the initial direction recognition sub-model respectively to obtain the predicted text presentation directions corresponding to the training data and the comparison data respectively;
[0238] Based on the predicted text presentation directions corresponding to the training data and the comparison data, a second model loss is determined, and based on the second model, model parameters of the initial direction recognition sub-model are adjusted.
[0239] As a possible implementation, when determining the second model loss based on the predicted text presentation directions corresponding to the training data and the comparison data, the model training unit 2105 is specifically configured to:
[0240] Determining a contrast loss based on image features corresponding to the training data and the comparison data;
[0241] Determining the model prediction loss corresponding to the training data and the comparison data based on the real text presentation directions corresponding to the training data and the comparison data, and the predicted text presentation directions corresponding to the training data and the comparison data;
[0242] The second model loss is determined based on the obtained prediction losses of each model, the comparative loss, the model prediction loss weight, and the comparative loss weight.
[0243] As a possible implementation, the target classification model further includes a target feature extraction network, and the model training unit 2105 is further used to:
[0244] Build a pre-trained language recognition model based on the initial feature extraction network;
[0245] Based on the acquired second training data set, the pre-trained recognition model is iteratively trained to obtain the target feature extraction network.
[0246] As a possible implementation, before inputting the image to be recognized containing text into the target classification model and obtaining the language distribution information and the original text presentation direction of the image to be recognized, the image classification unit 2101 is further configured to:
[0247] Acquire an original image, and extract at least one sub-image containing text from the original image;
[0248] Based on the preset image shape, shape correction processing is performed on each extracted sub-image, and any one of the sub-images obtained after the correction processing is used as the image to be recognized.
[0249] As a possible implementation, the model training unit 2105 is further configured to:
[0250] Obtain a third training data set, wherein the third training data set includes each labeled sample and each unlabeled sample
[0251] Based on the labeled samples, a first text recognition model including an image feature extraction network is trained to obtain a second text recognition model, and an image-text distance recognition model is constructed based on the image feature extraction network included in the second text recognition model;
[0252] Based on each labeled sample and each unlabeled sample, and the image-text distance recognition model, the second text recognition model is iteratively trained to obtain the target text recognition model.
[0253] As a possible implementation, when the second text recognition model is iteratively trained based on each labeled sample and each unlabeled sample and the image-text distance recognition model to obtain the target text recognition model, the model training unit 2105 is specifically configured to:
[0254] For each labeled sample and each unlabeled sample, iteratively perform the following operations:
[0255] Obtaining at least one labeled sample and at least one unlabeled sample, and inputting the at least one unlabeled sample into the second text recognition model respectively, to obtain a predicted text recognition result corresponding to each of the at least one unlabeled samples;
[0256] Inputting the at least one unlabeled sample and its corresponding predicted text recognition result into the image-text distance recognition model, obtaining the image-text distance corresponding to each of the at least one unlabeled sample, and determining each model sub-loss corresponding to the at least one unlabeled sample based on the obtained image-text distances;
[0257] Inputting the at least one labeled sample into the second text recognition model respectively to obtain a model sub-loss corresponding to each of the at least one labeled sample;
[0258] Based on the obtained sub-losses of each model, a third model loss is determined, and based on the third model loss, model parameters of the second text recognition model are adjusted.
[0259] As a possible implementation, when determining each model sub-loss corresponding to the at least one unlabeled sample based on the obtained image-text distances, the model training unit 2105 is specifically configured to:
[0260] Based on the obtained image-text distances, unlabeled samples having an image-text distance no greater than a preset distance threshold are screened out from the at least one unlabeled sample, and the screened unlabeled samples are used as samples to be enhanced;
[0261] Obtaining target enhancement samples corresponding to the samples to be enhanced, and using the predicted text recognition results corresponding to the samples to be enhanced as sample labels of the corresponding target enhancement samples;
[0262] The obtained target enhancement samples are respectively input into the second text recognition model to obtain the model sub-loss corresponding to each target enhancement sample, and the model sub-loss corresponding to each target enhancement sample is used as the model sub-loss corresponding to the at least one unlabeled sample.
[0263] As a possible implementation, the model training unit 2105 is further configured to perform at least one of the following operations:
[0264] Acquire each text corpus, each font format, and each background image, and synthesize each labeled sample based on the each text corpus, each font format, and each background image;
[0265] Obtain each text corpus, and input each text corpus into the target data style transfer model to obtain the labeled samples.
[0266] For the convenience of description, the above parts are divided into modules (or units) according to their functions and described separately. Of course, when implementing this application, the functions of each module (or unit) can be implemented in the same or multiple software or hardware.
[0267] Regarding the apparatus in the above embodiment, the specific manner in which each unit executes the request has been described in detail in the embodiment of the method, and will not be elaborated on here.
[0268] Those skilled in the art will appreciate that various aspects of the present application can be implemented as systems, methods, or program products. Therefore, various aspects of the present application can be specifically implemented in the following forms: a complete hardware implementation, a complete software implementation (including firmware, microcode, etc.), or an implementation that combines hardware and software aspects, which may be collectively referred to herein as a "circuit," "module," or "system."
[0269] Based on the same inventive concept, an embodiment of the present application further provides an electronic device. In one embodiment, the electronic device can be a server or a terminal device. Referring to FIG. 22 , which is a schematic diagram of the structure of a possible electronic device provided in an embodiment of the present application, an electronic device 2200 includes a processor 2210 and a memory 2220.
[0270] The memory 2220 stores a computer program that can be executed by the processor 2210 . The processor 2210 can perform the steps of the above-mentioned text recognition method by executing the instructions stored in the memory 2220 .
[0271] Memory 2220 can be a volatile memory, such as random-access memory (RAM); a non-volatile memory, such as read-only memory (ROM), flash memory, a hard disk drive (HDD), or a solid-state drive (SSD); or any other medium capable of carrying or storing desired program code in the form of instructions or data structures and accessible by a computer, but is not limited thereto. Memory 2220 can also be a combination of the above memories.
[0272] The processor 2210 may include one or more central processing units (CPUs) or digital processing units, etc. The processor 2210 is configured to implement the above-mentioned text recognition method when executing the computer program stored in the memory 2220 .
[0273] In some embodiments, the processor 2210 and the memory 2220 may be implemented on the same chip. In some embodiments, they may also be implemented on separate chips.
[0274] The specific connection medium between the processor 2210 and the memory 2220 is not limited in the embodiments of the present application. In the embodiments of the present application, the bus connection between the processor 2210 and the memory 2220 is used as an example. The bus is depicted as a bold line in FIG22 . The connection methods between other components are merely illustrative and are not intended to be limiting. Buses can be divided into address buses, data buses, control buses, etc. For ease of description, FIG22 depicts only a single bold line, but this does not imply that there is only one bus or only one type of bus.
[0275] Based on the same inventive concept, an embodiment of the present application provides a computer-readable storage medium, which includes a computer program. When the computer program is executed on an electronic device, the computer program is used to cause the electronic device to perform the steps of the above-mentioned text recognition method. In some possible implementations, various aspects of the text recognition method provided by the present application can also be implemented in the form of a program product, which includes a computer program. When the program product is executed on an electronic device, the computer program is used to cause the electronic device to perform the steps in the above-mentioned text recognition method. For example, the electronic device can perform the steps shown in Figure 2.
[0276] The program product may employ any combination of one or more readable media. The readable medium may be a readable signal medium or a readable storage medium. The readable storage medium may be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device, or component, or any combination thereof. More specific examples (a non-exhaustive list) of readable storage media include: an electrical connection having one or more wires, a portable disk, a hard disk, RAM, ROM, an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination thereof.
[0277] The program product of the embodiments of the present application may be a CD-ROM and include a computer program, and may be run on an electronic device. However, the program product of the present application is not limited thereto. In this document, a readable storage medium may be any tangible medium that contains or stores a computer program that can be used by or in conjunction with a command execution system, apparatus, or device.
[0278] Obviously, those skilled in the art may make various changes and modifications to this application without departing from the spirit and scope of this application. Thus, if these modifications and variations of this application fall within the scope of the claims of this application and their equivalents, this application is intended to include these modifications and variations.
Claims
1. A text recognition method, performed by an electronic device, comprising: Inputting an image to be recognized containing text into a target classification model to obtain language distribution information of the image to be recognized and the presentation direction of the original text, wherein the language distribution information includes multiple languages corresponding to the text and text position information corresponding to each of the multiple languages; Based on the original text presentation direction and the preset target text presentation direction, the image to be recognized is corrected to obtain a target recognition image; Based on the text position information corresponding to the multiple languages, determining, in the target recognition image, text region image sets corresponding to the multiple languages; Based on the text region image sets corresponding to the multiple languages, target text recognition models associated with the corresponding languages are respectively used for processing to obtain text recognition results corresponding to the images to be recognized.
2. The method according to claim 1, wherein the text region image sets corresponding to the multiple languages are processed using target text recognition models associated with the corresponding languages to obtain text recognition results corresponding to the images to be recognized, comprising: For a text area image set corresponding to each of the multiple languages, input the text area image set into a target text recognition model associated with the language to obtain a text recognition sub-result corresponding to the text area image set; Based on the text recognition sub-results corresponding to each of the text region image sets, a text recognition result corresponding to the image to be recognized is obtained.
3. The method according to claim 1, wherein the target classification model includes a target language recognition sub-model, and the target language recognition sub-model is obtained by the following operations: Based on the acquired first training data set, the initial language recognition sub-model included in the initial recognition model is iteratively trained to obtain the target language recognition sub-model, wherein: During one iteration, the following operations are performed: Inputting the training data contained in the first training data set into the initial language recognition sub-model to obtain predicted language distribution information corresponding to the training data; Based on the predicted language distribution information and the real language distribution information corresponding to the training data, a first model loss is determined, and based on the first model loss, model parameters of the initial language recognition sub-model are adjusted.
4. The method according to claim 3, wherein determining the first model loss based on the predicted language distribution information and the real language distribution information corresponding to the training data comprises: Based on the predicted language distribution information, a predicted distribution probability is determined, wherein the predicted distribution probability includes a predicted probability corresponding to each language, and the predicted probability is used to represent the proportion of the predicted text length of the corresponding language in the various languages; Based on the real language distribution information, determine the real distribution probability, wherein the real distribution probability includes the real probability corresponding to each language, and the real probability is used to represent the proportion of the real text length of the corresponding language in the languages; The first model loss is determined based on the predicted distribution probability and the true distribution probability.
5. The method according to any one of claims 1 to 4, wherein the target classification model includes a target direction recognition sub-model, and the target direction recognition sub-model is obtained by the following operations: Based on the acquired first training data set, the initial direction recognition sub-model included in the initial recognition model is iteratively trained to obtain the target direction recognition sub-model, wherein: During one iteration, the following operations are performed: Acquire the training data contained in the first training data set, and rotate the training data according to a preset image rotation angle to obtain comparison data corresponding to the training data; Inputting the training data and the comparison data into the initial direction recognition sub-model respectively to obtain the predicted text presentation directions corresponding to the training data and the comparison data respectively; Based on the predicted text presentation directions corresponding to the training data and the comparison data respectively, a second model loss is determined, and based on the second model, model parameters of the initial direction recognition sub-model are adjusted.
6. The method according to claim 5, wherein determining the second model loss based on the predicted text presentation directions corresponding to the training data and the comparison data respectively comprises: Determine a contrast loss based on image features corresponding to the training data and the contrast data; Determine the model prediction loss corresponding to the training data and the comparison data based on the real text presentation directions corresponding to the training data and the comparison data, and the predicted text presentation directions corresponding to the training data and the comparison data; The second model loss is determined based on the model prediction loss, the comparative loss, the model prediction loss weight, and the comparative loss weight.
7. The method according to claim 5, wherein the target classification model further comprises a target feature extraction network, and the target feature extraction network is trained by the following operations: Based on the initial feature extraction network, a pre-trained language recognition model is constructed; Based on the acquired second training data set, the pre-trained recognition model is iteratively trained to obtain the target feature extraction network.
8. The method according to any one of claims 1 to 4, wherein before inputting the image to be recognized containing text into the target classification model and obtaining the language distribution information of the image to be recognized and the original text presentation direction, the method further comprises: Acquire an original image, and extract at least one sub-image containing text from the original image; Based on the preset image shape, shape correction processing is performed on each of the extracted sub-images, and any one of the sub-images obtained after the correction processing is used as the image to be recognized.
9. The method according to any one of claims 1 to 4, wherein the target text recognition model is trained by the following operations: Acquire a third training data set, wherein the third training data set includes labeled samples and unlabeled samples; Based on the annotated samples, a first text recognition model including an image feature extraction network is trained to obtain a second text recognition model, and an image-text distance recognition model is constructed based on the image feature extraction network included in the second text recognition model; Based on the labeled samples, the unlabeled samples, and the image-text distance recognition model, the second text recognition model is iteratively trained to obtain the target text recognition model.
10. The method according to claim 9, wherein the iterative training of the second text recognition model based on the labeled samples, the unlabeled samples, and the image-text distance recognition model to obtain the target text recognition model comprises: For each of the labeled samples and each of the unlabeled samples, iteratively perform the following operations: Acquire at least one labeled sample and at least one unlabeled sample, and input the at least one unlabeled sample into the second text recognition model respectively, to obtain a predicted text recognition result corresponding to each of the at least one unlabeled sample; Inputting the at least one unlabeled sample and its corresponding predicted text recognition result into the image-text distance recognition model, obtaining the image-text distance corresponding to each of the at least one unlabeled sample, and determining each model sub-loss corresponding to the at least one unlabeled sample based on each obtained image-text distance; Inputting the at least one labeled sample into the second text recognition model respectively to obtain a model sub-loss corresponding to each of the at least one labeled sample; Based on the obtained model sub-losses, a third model loss is determined, and based on the third model loss, the model parameters of the second text recognition model are adjusted.
11. The method according to claim 10, wherein determining each model sub-loss corresponding to the at least one unlabeled sample based on the obtained image-text distances comprises: Based on the obtained image-text distances, unlabeled samples whose image-text distances are not greater than a preset distance threshold are screened out from the at least one unlabeled sample, and the screened out unlabeled samples are used as samples to be enhanced; Obtaining target enhancement samples corresponding to the samples to be enhanced, and using the predicted text recognition results corresponding to the samples to be enhanced as sample labels of the corresponding target enhancement samples; The acquired target enhancement samples are respectively input into the second text recognition model to obtain the model sub-loss corresponding to each target enhancement sample, and the model sub-loss corresponding to each target enhancement sample is used as the model sub-loss corresponding to the at least one unlabeled sample.
12. The method according to claim 9, wherein each of the labeled samples is obtained by at least one of the following operations: Acquire each text corpus, each font format and each background image, and synthesize each annotation sample based on each text corpus, each font format and each background image; Obtain each text corpus, and input each text corpus into the target data style transfer model to obtain each labeled sample.
13. A text recognition device, comprising: An image classification unit, used to input an image to be recognized containing text into a target classification model, and obtain language distribution information of the image to be recognized and a presentation direction of the original text, wherein the language distribution information includes multiple languages corresponding to the text and text position information corresponding to each of the multiple languages; An image correction unit, configured to correct the image to be recognized based on the original text presentation direction and the preset target text presentation direction to obtain a target recognition image; A text positioning unit, configured to determine, in the target recognition image, text region image sets corresponding to the multiple languages, based on the text position information corresponding to the multiple languages; The image recognition unit is used to process the text area image sets corresponding to the multiple languages respectively using the target text recognition models associated with the corresponding languages to obtain the text recognition results corresponding to the images to be recognized.
14. An electronic device comprising a processor and a memory, wherein: The memory stores a computer program, and when the computer program is executed by the processor, the processor is caused to execute the steps of any one of the methods of claims 1 to 12.
15. A computer-readable storage medium comprising a computer program, wherein when the computer program is run on an electronic device, the computer program is used to cause the electronic device to execute the steps of any one of the methods of claims 1 to 12.
16. A computer program product, comprising a computer program, wherein the computer program is stored in a computer-readable storage medium, and a processor of an electronic device reads and executes the computer program from the computer-readable storage medium, so that the electronic device performs the steps of the method according to any one of claims 1 to 12.
