Text recognition model training method, text recognition method, device and equipment

Through collaborative training of dual network models, combined with visual features and annotation results, the problem of low accuracy of existing text recognition models is solved and the accuracy and performance of text recognition are improved.

CN114462580BActive Publication Date: 2024-09-13TENCENT TECHNOLOGY (SHENZHEN) CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202210126459.0
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-02-10
Publication Date
2024-09-13
Estimated Expiration
2042-02-10

AI Technical Summary

Technical Problem

The accuracy of existing text recognition models is not high, resulting in low accuracy of text recognition. This is mainly due to the fact that it only relies on the prediction results and annotation results of sample text images for training, and lacks effective visual feature extraction and fusion.

Method used

A dual-network model collaborative training method is used to obtain the visual features of sample text images, use the first network model and the second network model to predict text characters respectively, and adjust the model based on the annotation results to enhance the text recognition ability of the model.

Benefits of technology

It improves the text recognition model's ability to extract visual features, improves the accuracy of text recognition and the recognition performance of the model, reduces the amount of calculations, and improves real-time performance.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114462580B
    Figure CN114462580B
Patent Text Reader

Abstract

The present application discloses a training method, a text recognition method, a device and an apparatus for a text recognition model, and belongs to the field of computer technology. The method includes: obtaining a sample text image and an annotation result of the sample text image; obtaining the visual features of the sample text image based on a first network model, and the visual features of the sample text image are used to characterize the appearance and position of each character in the sample text image; obtaining a first prediction result of the sample text image based on the first network model and the visual features of the sample text image; obtaining a second prediction result of the sample text image based on the second network model and the visual features of the sample text image; adjusting the first network model based on the first prediction result, the second prediction result and the annotation result to obtain a text recognition model. The text recognition model integrates the text recognition capabilities of different models, improves the text recognition model's ability to extract visual features, and improves the text recognition capability of the text recognition model.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The embodiments of the present application relate to the field of computer technology, and in particular to a text recognition model training method, text recognition method, device and equipment. Background Art

[0002] With the continuous development of computer technology, image recognition technology is becoming more and more important, and text recognition technology, as a branch of image recognition technology, has an increasingly wide range of applications. Text recognition technology is a technology that performs image recognition on text images to identify the text in the text image.

[0003] In the related art, a text recognition model can be obtained based on sample text image training, and the text recognition model can be used to perform text recognition on the target text image. When training the text recognition model based on the sample text image, on the one hand, the sample text image is input into the neural network model, and the neural network model determines the prediction result of the sample text image, and the prediction result is each character in the sample text image obtained by prediction. On the other hand, the annotation result of the sample text image is obtained, and the annotation result is each character in the sample text image obtained by annotation. Afterwards, the neural network model is adjusted using the prediction result and the annotation result to obtain the text recognition model.

[0004] In the above technology, the text recognition model is trained only by using the prediction results and annotation results of the sample text image, which results in low accuracy of the text recognition model, thereby affecting the accuracy of text recognition. Summary of the invention

[0005] The embodiments of the present application provide a text recognition model training method, a text recognition method, an apparatus and a device, which can be used to solve the problem of low accuracy of text recognition caused by low accuracy of the text recognition model in the related art. The technical solution includes the following contents.

[0006] On the one hand, an embodiment of the present application provides a method for training a text recognition model, the method comprising:

[0007] Acquire a sample text image and a labeling result of the sample text image, wherein the labeling result is each character in the sample text image obtained by labeling;

[0008] Acquiring visual features of the sample text image based on the first network model, wherein the visual features of the sample text image are used to characterize the shape and position of each character in the sample text image;

[0009] Based on the first network model and the visual features of the sample text image, obtaining a first prediction result of the sample text image, wherein the first prediction result is each character in the sample text image obtained by prediction by the first network model;

[0010] Based on the second network model and the visual features of the sample text image, obtaining a second prediction result of the sample text image, wherein the second prediction result is each character in the sample text image obtained by prediction by the second network model;

[0011] Based on the first prediction result, the second prediction result and the annotation result, the first network model is adjusted to obtain a text recognition model.

[0012] On the other hand, an embodiment of the present application provides a text recognition method, the method comprising:

[0013] Get the target text image;

[0014] Acquiring visual features of the target text image based on a text recognition model, wherein the visual features of the target text image are used to characterize the shape and position of each character in the target text image, and the text recognition model is obtained according to any of the above-mentioned training methods for the text recognition model;

[0015] Based on the visual features of the target text image, a text recognition result of the target text image is obtained, where the text recognition result is each character in the target text image predicted by the text recognition model.

[0016] On the other hand, an embodiment of the present application provides a training device for a text recognition model, the device comprising:

[0017] An acquisition module, used for acquiring a sample text image and a labeling result of the sample text image, wherein the labeling result is each character in the sample text image obtained by labeling;

[0018] The acquisition module is further used to acquire visual features of the sample text image based on the first network model, wherein the visual features of the sample text image are used to characterize the shape and position of each character in the sample text image;

[0019] The acquisition module is further used to acquire a first prediction result of the sample text image based on the first network model and the visual features of the sample text image, wherein the first prediction result is each character in the sample text image obtained by prediction by the first network model;

[0020] The acquisition module is further used to acquire a second prediction result of the sample text image based on the second network model and the visual features of the sample text image, wherein the second prediction result is each character in the sample text image obtained by prediction by the second network model;

[0021] An adjustment module is used to adjust the first network model based on the first prediction result, the second prediction result and the annotation result to obtain a text recognition model.

[0022] In a possible implementation, the acquisition module is used to acquire the appearance features of each character in the sample text image and the position features of each character in the sample text image based on the first network model; and determine the visual features of the sample text image based on the appearance features of each character in the sample text image and the position features of each character in the sample text image.

[0023] In a possible implementation, the acquisition module is used to fuse the appearance features of each character in the sample text image and the position features of each character in the sample text image for any character in the sample text image to obtain a first fused feature of the any character; and determine the visual features of the sample text image based on the first fused features of each character in the sample text image.

[0024] In a possible implementation, the acquisition module is used to fuse, for any character in the sample text image, the appearance features of at least one adjacent character corresponding to the any character and the position features of the at least one adjacent character to obtain a second fused feature of the any character; and determine the visual features of the sample text image based on the second fused features of each character in the sample text image.

[0025] In one possible implementation, the acquisition module is used to determine, for any character in the sample text image, a first probability that the any character belongs to each reference character based on the first network model and the visual features of the sample text image; determine a first maximum probability from the first probabilities that the any character belongs to each reference character; and determine the reference character corresponding to the first maximum probability as the character corresponding to the any character and obtained by prediction by the first network model.

[0026] In a possible implementation, the acquisition module is used to determine the semantic features of each character in the sample text image based on the second network model and the annotation results; obtain the position features of each character in the sample text image based on the first network model; and obtain a second prediction result of the sample text image based on the visual features of the sample text image, the semantic features of each character in the sample text image, and the position features of each character in the sample text image.

[0027] In a possible implementation, the acquisition module is used to determine the third fusion feature of each character in the sample text image based on the position feature of each character in the sample text image and the semantic feature of each character in the sample text image; and to obtain the second prediction result of the sample text image based on the visual feature of the sample text image and the third fusion feature of each character in the sample text image.

[0028] In a possible implementation, the acquisition module is used to fuse, for any character in the sample text image, the semantic features of the any character, the position features of the any character, the semantic features of each character before the any character, and the position features of each character before the any character to obtain a third fused feature of the any character.

[0029] In a possible implementation, the acquisition module is used to fuse the visual features of the sample text image and the third fusion features of each character in the sample text image for any character in the sample text image to obtain the fourth fusion feature of the any character; and obtain the second prediction result of the sample text image based on the fourth fusion feature of each character in the sample text image.

[0030] In a possible implementation, the acquisition module is used to determine, for any character in the sample text image, a second probability that the any character belongs to each reference character based on the fourth fusion feature of each character in the sample text image; determine a second maximum probability from the second probabilities that the any character belongs to each reference character; and determine the reference character corresponding to the second maximum probability as the character corresponding to the any character and obtained by prediction by the second network model.

[0031] In a possible implementation, the adjustment module is used to determine a first loss value based on the first prediction result and the annotation result; determine a second loss value based on the second prediction result and the annotation result; and adjust the first network model based on the first loss value and the second loss value to obtain a text recognition model.

[0032] In a possible implementation, the adjustment module is further used to determine a third loss value based on the first prediction result and the labeling result; determine a fourth loss value based on the second prediction result and the labeling result; and adjust the second network model based on the third loss value and the fourth loss value to obtain an adjusted second network model.

[0033] In a possible implementation, the acquisition module is used to acquire a text image to be processed; and to crop an image region containing text from the text image to be processed to obtain the sample text image.

[0034] On the other hand, an embodiment of the present application provides a text recognition device, the device comprising:

[0035] A first acquisition module, used for acquiring a target text image;

[0036] A second acquisition module is used to acquire visual features of the target text image based on a text recognition model, wherein the visual features of the target text image are used to characterize the shape and position of each character in the target text image, and the text recognition model is obtained by the training method of the text recognition model described in any one of the above items;

[0037] The third acquisition module is used to acquire the text recognition result of the target text image based on the visual features of the target text image, and the text recognition result is each character in the target text image obtained by prediction by the text recognition model.

[0038] In a possible implementation, the second acquisition module is used to acquire the appearance features of each character in the target text image and the position features of each character in the target text image based on the text recognition model; and determine the visual features of the target text image based on the appearance features of each character in the target text image and the position features of each character in the target text image.

[0039] On the other hand, an embodiment of the present application provides an electronic device, which includes a processor and a memory, wherein the memory stores at least one program code, and the at least one program code is loaded and executed by the processor so that the electronic device implements any of the above-mentioned text recognition model training methods or any of the above-mentioned text recognition methods.

[0040] On the other hand, a computer-readable storage medium is also provided, in which at least one program code is stored, and the at least one program code is loaded and executed by a processor so that a computer implements any of the above-mentioned text recognition model training methods or any of the above-mentioned text recognition methods.

[0041] On the other hand, a computer program or a computer program product is also provided, wherein at least one computer instruction is stored in the computer program or the computer program product, and the at least one computer instruction is loaded and executed by a processor so that a computer implements any of the above-mentioned text recognition model training methods or any of the above-mentioned text recognition methods.

[0042] The technical solution provided by the embodiments of the present application brings at least the following beneficial effects:

[0043] The technical solution provided in the embodiment of the present application, after obtaining the visual features of the sample text image based on the first network model, determines the first prediction result of the sample text image based on the first network model and the visual features, and determines the second prediction result of the sample text image based on the second network model and the visual features. Afterwards, the text recognition model is trained using the first prediction result, the second prediction result, and the annotation result of the sample text image, so that the text recognition model integrates the text recognition capabilities of different models, can improve the text recognition model's ability to extract visual features, and thus improve the text recognition capability of the text recognition model. BRIEF DESCRIPTION OF THE DRAWINGS

[0044] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the drawings required for use in the description of the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work.

[0045] Figure 1 It is a schematic diagram of an implementation environment of a text recognition model training method or a text recognition method provided in an embodiment of the present application;

[0046] Figure 2 is a flowchart of a text recognition model training method provided in an embodiment of the present application;

[0047] Figure 3 is a flowchart of a text recognition method provided by an embodiment of the present application;

[0048] Figure 4 It is a flowchart of a method for training a text recognition model provided in an embodiment of the present application;

[0049] Figure 5 It is a structural diagram of a network model provided in an embodiment of the present application;

[0050] Figure 6 It is a structural schematic diagram of a training device for a text recognition model provided in an embodiment of the present application;

[0051] Figure 7 is a structural schematic diagram of a text recognition device provided in an embodiment of the present application;

[0052] Figure 8 It is a structural diagram of a terminal device provided in an embodiment of the present application;

[0053] Fig. 9 It is a structural diagram of a server provided in an embodiment of the present application. DETAILED DESCRIPTION

[0054] In order to make the objectives, technical solutions and advantages of the present application clearer, the implementation methods of the present application will be further described in detail below with reference to the accompanying drawings.

[0055] Figure 1 is a diagram of a training method for a text recognition model or an implementation environment of a text recognition method provided in an embodiment of the present application, such as Figure 1 The implementation environment shown includes an electronic device 11, and the text recognition model training method or text recognition method in the embodiment of the present application can be executed by the electronic device 11. Exemplarily, the electronic device 11 can include at least one of a terminal device or a server.

[0056] The terminal device may be at least one of a smart phone, a game console, a desktop computer, a tablet computer, and a laptop computer. The server may be a single server, or a server cluster consisting of multiple servers, or any one of a cloud computing platform and a virtualization center, which is not limited in the embodiments of the present application. The server may be connected to the terminal device through a wired network or a wireless network. The server may have functions such as data processing, data storage, and data transmission and reception, which are not limited in the embodiments of the present application.

[0057] Each optional embodiment of the present application is implemented based on artificial intelligence technology. Artificial Intelligence (AI) is the theory, method, technology and application system that uses digital computers or machines controlled by digital computers to simulate, extend and expand human intelligence, perceive the environment, acquire knowledge and use knowledge to obtain the best results. In other words, artificial intelligence is a comprehensive technology in computer science that attempts to understand the essence of intelligence and produce a new intelligent machine that can respond in a similar way to human intelligence. Artificial intelligence is to study the design principles and implementation methods of various intelligent machines so that the machines have the functions of perception, reasoning and decision-making.

[0058] Artificial intelligence technology is a comprehensive discipline that covers a wide range of fields, including both hardware-level and software-level technologies. Basic artificial intelligence technologies generally include sensors, dedicated artificial intelligence chips, cloud computing, distributed storage, big data processing technology, operating / interactive systems, mechatronics and other technologies. Artificial intelligence software technologies mainly include computer vision technology, speech processing technology, natural language processing technology, as well as machine learning / deep learning, autonomous driving, smart transportation and other major directions.

[0059] With the research and advancement of artificial intelligence technology, artificial intelligence technology has been studied and applied in many fields, such as common smart homes, smart wearable devices, virtual assistants, smart speakers, smart marketing, unmanned driving, automatic driving, drones, robots, smart medical care, smart customer service, Internet of Vehicles, automatic driving, smart transportation, etc. I believe that with the development of technology, artificial intelligence technology will be applied in more fields and play an increasingly important role.

[0060] Based on the above implementation environment, the present application embodiment provides a method for training a text recognition model. Figure 2 Taking the flowchart of a text recognition model training method provided in the embodiment of the present application as an example, the method can be performed by Figure 1 The electronic device 11 in the embodiment is executed. Figure 2 As shown, the method includes steps 201 to 205.

[0061] Step 201 : obtaining a sample text image and a labeling result of the sample text image, where the labeling result is each character in the sample text image obtained through labeling.

[0062] In the embodiment of the present application, the number of sample text images is multiple. The sample text image can be a text image in a natural scene, or an image area in a text image in a natural scene. The text image in a natural scene can be a poster image, a logo (Logotype, Logo) image, an advertisement image, a street view image, etc. The shape and layout of the text in these text images are relatively complex and irregular. For example, the text in the poster image can be handwritten, dense text, etc.

[0063] Optionally, obtaining a sample text image includes: obtaining a text image to be processed; and cutting out an image region containing text from the text image to be processed to obtain a sample text image.

[0064] In the embodiment of the present application, any text image in a natural scene can be obtained and used as the text image to be processed. Since the data volume of the text image in the natural scene is large and the image area without text is large, the image area containing text in the text image to be processed can be first determined, and the image area containing text can be cropped out. The image area containing text is the sample text image.

[0065] Optionally, the text image to be processed may be preprocessed to obtain a preprocessed text image, and then the image region containing the text in the preprocessed text image may be determined to crop out the image region containing the text. The preprocessing includes but is not limited to contrast enhancement processing, noise reduction processing, image segmentation processing, etc.

[0066] In the embodiment of the present application, the sample text image may also be annotated to annotate each character in the sample text image to obtain the text in the sample text image.

[0067] Step 202: acquiring visual features of the sample text image based on the first network model. The visual features of the sample text image are used to characterize the shape and position of each character in the sample text image.

[0068] The embodiment of the present application does not limit the model structure and size of the first network model. For example, the first network model can be a connectionist temporal classification (CTC) model based on a neural network. The CTC model has the advantages of simple structure and fast operation speed.

[0069] In an embodiment of the present application, a sample text image is input into a first network model, and the first network model performs feature extraction on the sample text image to extract visual features of the sample text image.

[0070] Optionally, obtaining visual features of the sample text image based on the first network model includes: obtaining appearance features of each character in the sample text image based on the first network model; obtaining position features of each character in the sample text image based on the first network model; and determining the visual features of the sample text image based on the appearance features of each character in the sample text image and the position features of each character in the sample text image.

[0071] In the embodiment of the present application, the first network model includes an appearance feature extraction network and a position feature extraction network. After the sample text image is input into the first network model, the appearance feature extraction network extracts appearance features of the sample text image to obtain the appearance features of each character in the sample text image, and the position feature extraction network extracts position features of the sample text image to obtain the position features of each character in the sample text image. Among them, the appearance features of the characters are used to describe the appearance of the characters (which can also be understood as the outline of the characters), and the position features of the characters are used to describe the positions of the characters (wherein, the position of any character refers to: the sample text image includes multiple characters, and the position information of any character is the number of characters among the multiple characters). The embodiment of the present application does not limit the network structure of the position feature extraction network.

[0072] Optionally, the shape feature extraction network includes two convolution layers. The shape feature extraction network can extract attribute features related to character recognition, while suppressing attribute features unrelated to character recognition. Attribute features related to character recognition include but are not limited to the shape features of each character in the sample text image, and attribute features unrelated to character recognition include but are not limited to the font features, color features, size features, and background features of each character in the sample text image. The shape feature extraction network adopts a two-layer convolution layer structure, which can save a lot of memory consumption and facilitate the extraction of distinctive shape features.

[0073] Optionally, the appearance features of each character in the sample text image can be passed through a feedforward connection network, and after feature processing by the feedforward connection network, the appearance features of each character in the sample text image after feature processing are obtained. The embodiment of the present application does not limit the feature processing. Exemplarily, the feature processing includes but is not limited to at least one of batch normalization processing and activation processing. In this case, the feedforward connection network includes at least one of a batch normalization network and an activation network. The batch normalization network is used to perform batch normalization processing, and the activation network is used to perform activation processing.

[0074] The first network model also includes an encoder, which is used to fuse the appearance features of each character in the sample text image with the position features of each character in the sample text image to obtain the visual features of the sample text image. Optionally, the encoder may include a feedforward connection network, in which case the feedforward connection network of the encoder performs feature processing on the appearance features of each character in the sample text image, and the encoder fuses the appearance features of each character in the sample text image after feature processing with the position features of each character in the sample text image to obtain the visual features of the sample text image.

[0075] In a possible implementation, visual features of a sample text image are determined based on appearance features of each character in the sample text image and position features of each character in the sample text image, including: for any character in the sample text image, the appearance features of each character in the sample text image and the position features of each character in the sample text image are fused to obtain a first fused feature of any character; and the visual features of the sample text image are determined based on the first fused features of each character in the sample text image.

[0076] In the implementation of this application, the encoder includes an attention network, which can focus on long-range global relationship modeling. In the embodiment of this application, for the appearance features of each character in the sample text image, a linear operation is used to reshape it into a length vector Y, which is (T, d in ) in the form of a length vector. Where T is the length of the length vector, d in is the dimension of the length vector. Afterwards, the length vector Y and the position features of each character in the sample text image are fused using the attention network. In the embodiment of the present application, the position features of any character in the sample text image can represent the position information of any character in the sample text image relative to other characters in the sample text image except the any character, and are relative. Therefore, the position features of each character in the sample text image can be called a relative position encoding vector.

[0077] Optionally, the attention network is a multi-head self-attention network, which has the characteristic of relative position encoding, and can incorporate the position features of each character in the sample text image into the attention score calculation of each layer, so as to be well extended to inputs of different lengths and increase the robustness to variable length. The output of each head in the multi-head self-attention network can be expressed as the following formula (1).

[0078]

[0079] Among them, head h represents the output of head h in the multi-head self-attention network, softmax represents the regression function, T is the symbol of the transposed matrix, It is a dimensional parameter corresponding to the query vector Q, the key vector K and the relative position encoding vector R, and V represents the value vector.

[0080] Optionally, the query vector Q satisfies Where Y represents the length vector, W q represents the weight matrix corresponding to the query vector, R represents a real number, d in , is the dimension of the weight matrix corresponding to the query vector. The key vector K satisfies Where Y represents the length vector, W k represents the weight matrix corresponding to the key vector, R represents a real number, d in , is the dimension of the weight matrix corresponding to the key vector. The value vector V satisfies Where Y represents the length vector, W v Represents the weight matrix corresponding to the value vector, R represents a real number, d in , The dimension of the weight matrix corresponding to the value vector is represented by R. The relative position encoding vector R satisfies Among them, P is the position encoding vector (which can represent the position of each character in the sample text image), R represents a real number, T, d in represents the dimension of the position encoding vector, W r Represents the weight matrix corresponding to the relative position encoding vector, d in , Represents the dimension of the weight matrix corresponding to the relative position encoding vector.

[0081] In an embodiment of the present application, the outputs of each head in the multi-head self-attention network are connected to obtain the output of the multi-head self-attention network, as shown in the following formula (2).

[0082] out=Concat(head1,head2,…,head h )W o Formula (2)

[0083] Among them, out is the output of the multi-head self-attention network, Concat represents the connection symbol, head1, head2,…, head h represents the output of each head in the multi-head self-attention network, is a learnable linear transformation matrix, R represents a real number, d v represents the dimension of the linear transformation matrix, h represents the number of heads in the multi-head self-attention network, is a hyperparameter.

[0084] It should be noted that the output of the multi-head self-attention network is the first fused feature of any character. In the embodiment of the present application, the appearance features of each character in the sample text image are first reshaped into a length vector, and then the length vector is fused with the position features of each character in the sample text image to obtain the first fused feature of any character. After that, the visual features of the sample text image are determined based on the first fused features of each character, thereby realizing global feature fusion.

[0085] In another possible implementation, based on the shape features and position features of each character in the sample text image, the visual features of the sample text image are determined, including: for any character in the sample text image, fusing the shape features and position features of at least one adjacent character corresponding to the any character to obtain a second fusion feature of the any character; determining the visual features of the sample text image based on the second fusion features of each character in the sample text image.

[0086] In the implementation of this application, the encoder includes a convolutional network, and the convolutional network includes a pointwise convolution with a gated linear unit activation layer, and the expansion factor of the pointwise convolution is 2. One-dimensional depth convolution operations can be used to reduce the amount of calculation while achieving local context modeling.

[0087] In the embodiment of this application, any character corresponds to at least one adjacent character. Here, the adjacent character can be a character directly adjacent to the any character, or a character indirectly adjacent to the any character. Indirectly adjacent to the any character means adjacent to the character adjacent to the any character. For example, for the text "兴高采烈", the adjacent characters corresponding to the character "兴" can be the characters "高", "采", "烈". Among them, the character "高" is a character directly adjacent to the character "兴", and the characters "采" and "烈" are characters indirectly adjacent to the character "兴". The embodiment of this application does not limit the number of adjacent characters corresponding to any character, and any two characters can correspond to the same number of adjacent characters or different numbers of adjacent characters.

[0088] The convolutional network can fuse the shape features of at least one adjacent character corresponding to any character and the position features of at least one adjacent character corresponding to the any character to obtain a second fusion feature of the any character. Then, based on the second fusion features of each character in the sample text image, the visual features of the sample text image are determined.

[0089] Optionally, the second fusion features of each character in the sample text image can pass through a feedforward connection network, and after at least one of batch normalization processing and activation processing by the feedforward connection network, the visual features of the sample text image are obtained to train and regularize the deep model. Optionally, the feedforward connection network includes at least one of a batch normalization network and an activation network. The batch normalization network is used for batch normalization processing, and the activation network is used for activation processing. The embodiment of this application does not limit the type of the activation network. Exemplarily, the activation network is a Swish activation network.

[0090] It should be noted that the embodiments of the present application can combine the attention network with the convolutional network to jointly determine the visual features of the sample text image, so that the visual features of the sample text image are obtained based on both global features and local features, so that the first network model has the ability to model both the global and local aspects.

[0091] Optionally, for any character in the sample text image, the appearance features of each character in the sample text image and the position features of each character in the sample text image are first fused to obtain a first fused feature of any character, and then the first fused features of at least one adjacent character corresponding to any character are fused to obtain a second fused feature of any character. Thereafter, the visual features of the sample text image are determined based on the second fused features of each character in the sample text image.

[0092] Optionally, for any character in the sample text image, the shape feature of at least one adjacent character and the position feature of at least one adjacent character corresponding to the character are first fused to obtain a second fused feature of the character, and then the second fused features of each character in the sample text image are fused to obtain a first fused feature of the character. Thereafter, the visual features of the sample text image are determined based on the first fused features of each character in the sample text image.

[0093] It is understandable that the first network model may include at least one encoder connected in series, and the encoder connected in series is that the output of the previous encoder is the input of the next encoder. In the embodiment of the present application, the visual features output by the previous encoder can be used as the input of the next encoder. At this time, the visual features output by the previous encoder can be used as the shape features and position features of each character input to the next encoder. The visual features output by the last encoder are used to perform step 203.

[0094] Step 203, based on the first network model and the visual features of the sample text image, obtain a first prediction result of the sample text image, where the first prediction result is each character in the sample text image predicted by the first network model.

[0095] In the embodiment of the present application, the first network model includes a linear network and an activation network, wherein the linear network is used to perform linear transformation processing on the visual features of the sample text image to obtain the visual features after the linear transformation processing, and the activation network is used to perform activation processing on the visual features after the linear transformation processing to obtain the first prediction result of the sample text image. The linear network and the activation network can form a decoder.

[0096] In one possible implementation, based on the first network model and the visual features of the sample text image, a first prediction result of the sample text image is obtained, including: for any character in the sample text image, based on the first network model and the visual features of the sample text image, determining a first probability that any character belongs to each reference character; determining a first maximum probability from the first probabilities that any character belongs to each reference character; and determining the reference character corresponding to the first maximum probability as the character corresponding to any character obtained by prediction by the first network model.

[0097] In an embodiment of the present application, the linear network of the first network model performs linear transformation processing on the visual features of the sample text image, and the activation network performs activation processing on the visual features after the linear transformation processing to obtain a first probability that each character in the sample text image belongs to each reference character.

[0098] For any character in the sample text image, the first maximum probability is determined from the first probabilities that the character belongs to each reference character, and the reference character corresponding to the first maximum probability is determined. The reference character corresponding to the first maximum probability is the character corresponding to the character obtained by prediction by the first network model. In this way, each character in the sample text image obtained by prediction by the first network model can be obtained.

[0099] For example, for a certain character in the sample text image, the first probabilities that the character belongs to each reference character are 0.67, 0.03, 0.2 and 0.1 respectively, among which 0.67 is the first maximum probability. The reference character corresponding to 0.67 is the character corresponding to the character in the sample text image and obtained by prediction by the first network model.

[0100] Step 204, based on the second network model and the visual features of the sample text image, obtain a second prediction result of the sample text image, where the second prediction result is each character in the sample text image predicted by the second network model.

[0101] In an embodiment of the present application, the second network model can determine the second prediction result of the sample text image based on the visual features of the sample text image. The embodiment of the present application does not limit the structure and size of the second network model. Exemplarily, the second network model is an attention model.

[0102] In one possible implementation, based on the second network model and the visual features of the sample text image, a second prediction result of the sample text image is obtained, including: determining the semantic features of each character in the sample text image based on the second network model and the annotation results; obtaining the position features of each character in the sample text image based on the first network model; and obtaining the second prediction result of the sample text image based on the visual features of the sample text image, the semantic features of each character in the sample text image, and the position features of each character in the sample text image.

[0103] In the embodiment of the present application, the second network model includes a semantic feature extraction network, which can map the annotation results of the sample text image into the semantic features of each character in the sample text image. The semantic feature of any character can be called the embedding vector of the character. The dimension of the semantic feature of any character is d v .

[0104] The first network model includes a position feature extraction network, which can extract the position features of each character in the sample text image. The method of extracting the position features has been introduced above and will not be repeated here.

[0105] The second network model also includes a decoder, which is used to obtain a second prediction result of the sample text image based on the visual features of the sample text image, the semantic features of each character in the sample text image, and the position features of each character in the sample text image.

[0106] In a possible implementation, based on the visual features of the sample text image, the semantic features of each character in the sample text image, and the position features of each character in the sample text image, a second prediction result of the sample text image is obtained, including: determining a third fusion feature of each character in the sample text image based on the position features of each character in the sample text image and the semantic features of each character in the sample text image; and obtaining the second prediction result of the sample text image based on the visual features of the sample text image and the third fusion features of each character in the sample text image.

[0107] In the embodiment of the present application, the decoder includes a first Layer Normalization (Layer Norm) network and a first attention network. The first Layer Normalization network is used to normalize the position features of each character in the sample text image to obtain the position features of each character in the sample text image after normalization, and at the same time normalize the semantic features of each character in the sample text image to obtain the semantic features of each character in the sample text image after normalization. The first attention network is used to fuse the position features of each character in the sample text image after normalization and the semantic features of each character in the sample text image after normalization to obtain the third fusion feature of each character in the sample text image.

[0108] Optionally, determining the third fusion feature of each character in the sample text image based on the position features of each character in the sample text image and the semantic features of each character in the sample text image includes: for any character in the sample text image, fusing the semantic feature of any character, the position feature of any character, the semantic features of each character before any character, and the position features of each character before any character to obtain the third fusion feature of any character.

[0109] In the embodiment of the present application, the first attention network of the decoder can be a masked multi-head self-attention network. The masked multi-head self-attention network can prevent the temporal information after the current moment from affecting the feature extraction at the current moment. That is, the features of each character after the current character do not affect the features of the current character, so that the features of the current character only depend on the features of the current character and the features of each character before the current character. Among them, each character before the current character is all characters whose positions are before the current character, and each character after the current character is all characters whose positions are after the current character.

[0110] Optionally, for any character in the sample text image, the masked multi-head self-attention network is to fuse the semantic feature of any character, the position feature of any character, the semantic features of each character before any character, and the position features of each character before any character to obtain the third fusion feature of any character. In this way, the third fusion feature of each character in the sample text image can be determined.

[0111] For example, the sample text image includes five characters "delicious coffee". Among them, the third fusion feature of the second character "wei" is determined based on the semantic feature and position feature of "mei", and the semantic feature and position feature of "wei". The third fusion feature of the fourth character "ka" is determined based on the semantic feature and position feature of "mei", the semantic feature and position feature of "wei", the semantic feature and position feature of "de", and the semantic feature and position feature of "ka".

[0112] After determining the third fused features of each character in the sample text image, a second prediction result of the sample text image is obtained based on the visual features of the sample text image and the third fused features of each character in the sample text image.

[0113] Optionally, based on the visual features of the sample text image and the third fusion features of each character in the sample text image, a second prediction result of the sample text image is obtained, including: for any character in the sample text image, fusing the visual features of the sample text image and the third fusion features of each character in the sample text image to obtain a fourth fusion feature of any character; based on the fourth fusion features of each character in the sample text image, obtaining the second prediction result of the sample text image.

[0114] In the embodiment of the present application, the decoder also includes a second layer standard (Layer Norm) network and a second attention network. The second layer standard network is used to standardize the third fused features of each character in the sample text image to obtain the third fused features of each character in the sample text image after standardization. The second attention network is used to fuse the visual features of the sample text image with the third fused features of each character in the sample text image after standardization to obtain the fourth fused features of each character in the sample text image.

[0115] Optionally, the second attention network is a multi-head self-attention network. The multi-head self-attention network is used to globally fuse the features of each character in the sample text image, that is, for any character in the sample text image, the visual features of the sample text image and the third fused features of each character in the sample text image after standardization are fused to obtain the fourth fused features of any character. Optionally, the key vector and value vector of the multi-head self-attention network are both derived from the output of the multi-head self-attention network in the encoder, and the query vector is derived from the output of the masked multi-head self-attention network in the decoder.

[0116] Afterwards, based on the fourth fusion features of each character in the sample text image, a second prediction result of the sample text image is obtained.

[0117] Optionally, based on the fourth fusion features of each character in the sample text image, a second prediction result of the sample text image is obtained, including: for any character in the sample text image, based on the fourth fusion features of each character in the sample text image, determining a second probability that any character belongs to each reference character; determining a second maximum probability from the second probabilities that any character belongs to each reference character; and determining the reference character corresponding to the second maximum probability as the character corresponding to any character obtained by prediction by the second network model.

[0118] In an embodiment of the present application, the second network model also includes a third-layer standard network, a feedforward connection network, a fourth-layer standard network, a linear network, and an activation network. Among them, the third-layer standard network is used to perform standardization processing on the fourth fusion feature of each character in the sample text image to obtain the fourth fusion feature of each character in the sample text image after standardization processing. The feedforward connection network is used to perform feature processing on the fourth fusion feature of each character in the sample text image after standardization processing to obtain the fifth fusion feature of each character in the sample text image. The fourth-layer standard network is used to perform standardization processing on the fifth fusion feature of each character in the sample text image to obtain the fifth fusion feature of each character in the sample text image after standardization processing. The linear network is used to perform linear transformation processing on each fifth fusion feature in the sample text image after standardization processing to obtain each fifth fusion feature in the sample text image after linear transformation processing. Optionally, the linear network is a linear network with a linear activation function. The activation network is used to activate each fifth fusion feature in the sample text image after linear transformation to obtain a second probability that each character in the sample text image belongs to each reference character. Optionally, the activation network is a linear network activated by a linear rectification function (Linear Rectification Function, ReLU function).

[0119] For any character in the sample text image, the second maximum probability is determined from the second probabilities that the character belongs to each reference character, and the reference character corresponding to the second maximum probability is determined. The reference character corresponding to the second maximum probability is the character corresponding to the character obtained by prediction by the second network model. In this way, each character in the sample text image obtained by prediction by the second network model can be obtained.

[0120] Step 205: Based on the first prediction result, the second prediction result and the annotation result, the first network model is adjusted to obtain a text recognition model.

[0121] In an embodiment of the present application, based on the first prediction result, the second prediction result and the annotation result, the loss value of the first network model is determined, and the first network model is adjusted based on the loss value of the first network model to obtain an adjusted first network model. If the adjusted first network model meets the training end condition, the adjusted first network model is used as the text recognition model. If the adjusted first network model does not meet the training end condition, the adjusted first network model is used as the first network model for the next training, and the first network model is trained again in the manner of steps 201 to 205 until a text recognition model is obtained.

[0122] It should be noted that the embodiment of the present application does not limit the conditions for satisfying the training end. Exemplarily, the training end condition is to reach the target number of training times (such as 500 times). At this time, it is necessary to train the initial first network model for the target number of training times in accordance with steps 201 to 205 until a text recognition model is obtained.

[0123] Optionally, based on the first prediction result, the second prediction result and the annotation result, the first network model is adjusted to obtain a text recognition model, including: determining a first loss value based on the first prediction result and the annotation result; determining a second loss value based on the second prediction result and the annotation result; and adjusting the first network model based on the first loss value and the second loss value to obtain a text recognition model.

[0124] In the embodiment of the present application, based on the first prediction result and the labeling result, the first loss value is determined according to the first loss function. The embodiment of the present application does not limit the first loss function. Exemplarily, the first loss function is a CTC loss function.

[0125] Based on the second prediction result and the labeling result, a second loss value is determined according to a second loss function. The second loss function is not limited in the present embodiment of the application. Exemplarily, the second loss function is a cross entropy loss function.

[0126] After obtaining the first loss value and the second loss value, the loss value of the first network model is determined based on the first loss value and the second loss value, the first network model is adjusted using the loss value of the first network model to obtain the adjusted first network model, and the text recognition model is determined based on the adjusted first network model.

[0127] In a possible implementation, after obtaining the second prediction result of the sample text image based on the second network model and the visual features of the sample text image, it also includes: determining a third loss value based on the first prediction result and the annotation result; determining a fourth loss value based on the second prediction result and the annotation result; and adjusting the second network model based on the third loss value and the fourth loss value to obtain an adjusted second network model.

[0128] In the embodiment of the present application, based on the first prediction result and the labeling result, the third loss value is determined according to the third loss function. The embodiment of the present application does not limit the third loss function. Exemplarily, the third loss function is a CTC loss function.

[0129] Based on the second prediction result and the labeling result, a fourth loss value is determined according to a fourth loss function. The fourth loss function is not limited in the present embodiment of the application. Exemplarily, the fourth loss function is a cross entropy loss function.

[0130] After obtaining the third loss value and the fourth loss value, the loss value of the second network model is determined based on the third loss value and the fourth loss value, and the second network model is adjusted using the loss value of the second network model to obtain an adjusted second network model. If the adjusted second network model meets the training end condition, the adjusted second network model is used as the trained second network model. If the adjusted second network model does not meet the training end condition, the adjusted second network model is used as the second network model for the next training, and the second network model is trained again according to steps 201 to 204, and the method for determining the adjusted second network model of the embodiment of the present application, until a trained second network model is obtained.

[0131] It should be noted that the first loss function and the third loss function may be the same or different. The second loss function and the fourth loss function may be the same or different. The loss value of the first network model may be the same as the loss value of the second network model or different, which is not limited here.

[0132] The embodiment of the present application utilizes the first network model and the second network model for collaborative training, so that the text recognition model can integrate the respective advantages of the first network model and the second network model, and the text recognition model can not only use the features of the characters before the current character to predict the features of the current character, but also use the features of the characters after the current character to predict the features of the current character, thereby increasing the accuracy of the visual features of the sample text graphics. At the same time, collaborative training of the first network model and the second network model not only speeds up the convergence speed of the network, but also improves the recognition performance.

[0133] It is understandable that the width of the text image in the natural scene varies widely, the shortest is less than 200, and the longest can reach 1800. The length of the annotation result is also not fixed, and the length of some annotation results can reach 180. In the process of training the first network model and the second network model, the embodiment of the present application does not directly scale the sample text image to the target height (such as 32) and then randomly select a number of sample text images for training, but first scales a plurality of sample text images in proportion to ensure that the height of the plurality of sample text images is the target height, and then sorts the plurality of sample text images according to the width size. For the plurality of sample text images after sorting, a plurality of sample text images are taken out in order from small to large, and these plurality of sample text images can be used as a mini-batch (Mini-Batch) for padding (Padding) processing to make the size of each sample text image consistent. If a single sample text image is input into the first network model, the sample text image can be directly scaled so that the height of the sample text image is the target height, and there is no width restriction.

[0134] The present embodiment uses the Adam optimizer, whose decay rates β1 and β2 are: β1 = 0.9, β2 = 0.99. The gradient clipping factor of the optimizer is 5, and the learning rate changes continuously with the increase of the number of training times. The learning rate lr satisfies: lr = warmup 0.5 ×min(s -0.5 ,s×warmup -1.5 ). Wherein, s represents the current number of training times, and warmup is a learning rate control parameter used to control the learning rate to increase first and then decrease. The embodiment of the present application does not limit the size of the learning rate control parameter, and for example, warmup=25000.

[0135] After the above method obtains the visual features of the sample text image based on the first network model, on the one hand, the first prediction result of the sample text image is determined based on the first network model and the visual features, and on the other hand, the second prediction result of the sample text image is determined based on the second network model and the visual features. Afterwards, the first prediction result, the second prediction result and the annotation result of the sample text image are used to train a text recognition model, so that the text recognition model integrates the text recognition capabilities of different models, can improve the text recognition model's ability to extract visual features, and thus improve the text recognition capability of the text recognition model.

[0136] Based on the above implementation environment, the present application embodiment provides a text recognition method. Figure 3 As an example, the flowchart of a text recognition method provided in the embodiment of the present application is shown in FIG. Figure 1 The electronic device 11 in the embodiment is executed. Figure 3 As shown, the method includes steps 301 to 303.

[0137] Step 301, obtaining a target text image.

[0138] In the embodiment of the present application, the target text image can be a text image in a natural scene, or an image area in a text image in a natural scene. Optionally, any text image in a natural scene can be obtained and used as the text image to be cut. Since the data volume of the text image in a natural scene is large, and the image area that does not contain text is large, it is possible to first determine the image area containing text in the text image to be cut, and then cut out the image area containing text, and the image area containing text is the target text image.

[0139] Optionally, the text image to be cut may be preprocessed to obtain a preprocessed text image, and then the image region containing the text in the preprocessed text image is determined to cut out the image region containing the text. The preprocessing includes but is not limited to contrast enhancement processing, noise reduction processing, image segmentation processing, etc.

[0140] Step 302, obtaining visual features of the target text image based on the text recognition model, the visual features of the target text image are used to characterize the shape and position of each character in the target text image, and the text recognition model is obtained according to the training method of the text recognition model provided in the above-mentioned optional embodiments.

[0141] In the embodiment of the present application, the text recognition model is trained according to the above-mentioned steps 201 to 205, which will not be described in detail. The target text image is input into the text recognition model, and the text recognition model performs feature extraction on the target text image to extract the visual features of the target text image.

[0142] In one possible implementation, the visual features of the target text image are obtained based on a text recognition model, including: obtaining the appearance features of each character in the target text image based on the text recognition model; obtaining the position features of each character in the target text image based on the text recognition model; and determining the visual features of the target text image based on the appearance features of each character in the target text image and the position features of each character in the target text image.

[0143] In the embodiment of the present application, the text recognition model includes an appearance feature extraction network and a position feature extraction network. After the target text image is input into the text recognition model, the appearance feature extraction network extracts appearance features of the target text image to obtain the appearance features of each character in the target text image, and the position feature extraction network extracts position features of the target text image to obtain the position features of each character in the target text image. Among them, the appearance features of the characters are used to describe the appearance of the characters, and the position features of the characters are used to describe the positions of the characters. Among them, the method for extracting the visual features of the sample text image has been introduced above, and the method for extracting the visual features of the target text image is consistent with the method for extracting the visual features of the sample text image, which will not be repeated here.

[0144] Step 303, based on the visual features of the target text image, a text recognition result of the target text image is obtained. The text recognition result is each character in the target text image predicted by the text recognition model.

[0145] In an embodiment of the present application, the text recognition model includes a linear network and an activation network, wherein the linear network is used to perform linear transformation processing on the visual features of the target text image to obtain the visual features after the linear transformation processing, and the activation network is used to perform activation processing on the visual features after the linear transformation processing to obtain the text recognition result of the target text image.

[0146] Optionally, after the activation network performs activation processing on the visual features after the linear transformation processing, the probability of each character in the target text image belonging to each reference character is obtained. For any character in the target text image, the maximum probability is determined from the probabilities that the character belongs to each reference character, and the reference character corresponding to the maximum probability is determined. The reference character corresponding to the maximum probability is the character corresponding to the character obtained by prediction by the text recognition model. In this way, each character in the target text image obtained by prediction by the text recognition model can be obtained.

[0147] The text recognition model in the above method is trained in the following manner: after the visual features of the sample text image are obtained based on the first network model, on the one hand, the first prediction result of the sample text image is determined based on the first network model and the visual features, and on the other hand, the second prediction result of the sample text image is determined based on the second network model and the visual features. Afterwards, the text recognition model is trained using the first prediction result, the second prediction result and the annotation result of the sample text image. The text recognition model in the embodiment of the present application combines the text recognition capabilities of different models, which can improve the text recognition model's ability to extract visual features, thereby improving the text recognition ability of the text recognition model and improving the accuracy of text recognition. At the same time, when applied, only the text recognition model is used without using the trained second network model to obtain the text recognition result of the target text image, which reduces the amount of calculation, keeps the calculation time within a controllable range, and improves the real-time performance of text recognition.

[0148] The above describes the training method of the text recognition model and the text recognition method in the embodiment of the present application from the perspective of method steps. The following describes the training method of the text recognition model and the text recognition method in the embodiment of the present application from the perspective of a specific embodiment.

[0149] See also Figure 4 , Figure 4 It is a flowchart of a training method for a text recognition model provided in an embodiment of the present application. First, feature extraction is performed on a sample text image to obtain the appearance features, position features, and semantic features of each character in the sample text image. The above has introduced the method for extracting the appearance features, position features, and semantic features of each character, which will not be repeated here.

[0150] Next, the appearance features and position features of each character are locally and globally fused to obtain visual features, and then the first prediction result is obtained based on the visual features. In addition, the semantic features and position features of each character are globally fused to obtain the third fused features of each character, and then the visual features and the third fused features of each character are globally fused to obtain the fourth fused features of each character, and then the second prediction result is obtained based on the fourth fused features of each character.

[0151] Next, see Figure 5 , Figure 5 It is a structural diagram of a network model provided in an embodiment of the present application. The network model includes a first network model and a second network model. Among them, the first network model includes Ne serially connected encoders, the encoder is a CTC model, and the output of the previous encoder is the input of the next encoder. The second network model includes Nd serially connected decoders, a layer normalization network (corresponding to the fourth layer standard network mentioned above), a linear network and an activation network. The decoder is an Attention model, and the output of the previous decoder is the input of the next decoder. Ne and Nd are both positive integers.

[0152] The following is an introduction to the structure of the encoder, which consists of a feedforward connection network, a multi-head self-attention network, a convolutional network, and a feedforward connection network.

[0153] First, the appearance features of each character are input into the feedforward connection network for feature processing to obtain the appearance features of each character after feature processing. Then, the appearance features of each character are fused with the appearance features of each character after feature processing to obtain the fused appearance features of each character, so that the appearance features of each character are more accurate.

[0154] The position features of each character and the fused appearance features of each character are input into the multi-head self-attention network together, so that the multi-head self-attention network performs global feature fusion to obtain the first fused features of each character. Among them, the position features of each character, the fused appearance features of each character, and the first fused features of each character can be fused to obtain the fused first fused features of each character, so that the first fused features of each character are more accurate.

[0155] The first fused features of each character after fusion are input into the convolutional network, and the convolutional network performs local feature fusion to obtain the second fused features of each character. The second fused features of each character can be fused with the first fused features of each character after fusion to obtain the second fused features of each character after fusion, so that the second fused features of each character are more accurate.

[0156] The second fused features of each fused character are input into the feedforward connection network, and the feedforward connection network performs feature processing to obtain the second fused features of each character after feature processing. The second fused features of each fused character and the second fused features of each character after feature processing can be fused to obtain visual features. The visual features output by the previous encoder can be used as the input of the next encoder. At this time, the visual features output by the previous encoder are the shape features and position features of each character input to the next encoder. The visual features output by the last encoder are used for the following processing.

[0157] The first network model can determine and output a first prediction result of the sample text image based on the visual features. In an embodiment of the present application, the annotation result of the sample text image can be obtained, the loss value of the first network model can be determined based on the annotation result and the first prediction result, and the first network model can be adjusted based on the loss value of the first network model. The visual features can also be input into the second network model.

[0158] The structure of the decoder is introduced below. The decoder includes a layer normalization network (corresponding to the first layer of the standard network mentioned above), a masked multi-head self-attention network, a layer normalization network (corresponding to the second layer of the standard network mentioned above), a multi-head self-attention network, a layer normalization network (corresponding to the third layer of the standard network mentioned above), and a feedforward connection network.

[0159] First, the semantic features and position features of each character are input into the layer normalization network, and the layer normalization network normalizes the semantic features of each character to obtain the semantic features of each character after normalization. The layer normalization network can also normalize the position features of each character to obtain the position features of each character after normalization.

[0160] Next, the semantic features of each character after the normalization process and the position features of each character after the normalization process are input into the masked multi-head self-attention network, and the masked multi-head self-attention network performs global feature fusion to obtain the third fused features of each character. Among them, the semantic features of each character, the position features of each character and the third fused features of each character can be fused to obtain the fused third fused features of each character, so that the third fused features of each character are more accurate.

[0161] Then, the third fused features of each character after fusion are input into the layer normalization network, and the layer normalization network performs normalization processing on the third fused features of each character after fusion to obtain the third fused features of each character after normalization. The visual features and the third fused features of each character after normalization are input into the multi-head self-attention network, and the multi-head self-attention network performs global feature fusion to obtain the fourth fused features of each character. Among them, the fourth fused features of each character can be fused with the third fused features of each character after fusion to obtain the fourth fused features of each character after fusion, so that the fourth fused features of each character are more accurate.

[0162] Afterwards, the fourth fused features of each fused character are input into the layer normalization network, and the layer normalization network performs normalization processing on the fourth fused features of each fused character to obtain the fourth fused features of each character after the normalization processing. The fourth fused features of each character after the normalization processing are input into the feedforward connection network, and the feedforward connection network performs feature processing to obtain the fourth fused features of each character after the feature processing. Among them, the fourth fused features of each fused character and the fourth fused features of each character after the feature processing can be fused to obtain the output of the decoder. The output of the previous decoder can be used as the input of the next decoder, that is, the output of the previous decoder can be used as the position features of each character and the semantic features of each character input to the next decoder.

[0163] The last decoder can fuse the fourth fused features of each fused character and the fourth fused features of each character after feature processing to obtain the output of the last decoder. After that, the second prediction result of the sample text image is obtained after being standardized by the layer normalization network, and linearly transformed and activated by the linear network and the activation network respectively. After that, the loss value of the second network model is determined based on the annotation result and the second prediction result, and the second network model is adjusted based on the loss value of the second network model. Among them, one training is a synchronous adjustment of the first network model and the second network model.

[0164] In the embodiment of the present application, the first network model and the second network model can be adjusted synchronously for multiple times until the training end condition is met. The first network model that meets the training end condition can be used as a text recognition model.

[0165] The text recognition model of the embodiment of the present application is a CTC model. Compared with the traditional CTC recognizer, the CTC model of the embodiment of the present application uses the Attention model to assist and guide the CTC model to learn text recognition, so that the CTC model can perform more effective and robust text recognition for text images in natural scenes. Compared with the Attention recognizer, the CTC model of the embodiment of the present application has global and local feature fusion capabilities, and the CTC model includes a multi-head self-attention network, which is a parallel attention mechanism that can avoid the speed bottleneck and video memory consumption caused by the serial decoding structure of Attention.

[0166] Figure 6 FIG. 1 is a schematic diagram of a text recognition model training device provided in an embodiment of the present application. Figure 6 As shown, the device comprises:

[0167] An acquisition module 601 is used to acquire a sample text image and a labeling result of the sample text image, where the labeling result is each character in the sample text image obtained by labeling;

[0168] The acquisition module 601 is further used to acquire visual features of the sample text image based on the first network model, where the visual features of the sample text image are used to characterize the shape and position of each character in the sample text image;

[0169] The acquisition module 601 is further used to acquire a first prediction result of the sample text image based on the first network model and the visual features of the sample text image, where the first prediction result is each character in the sample text image predicted by the first network model;

[0170] The acquisition module 601 is further used to acquire a second prediction result of the sample text image based on the second network model and the visual features of the sample text image, where the second prediction result is each character in the sample text image predicted by the second network model;

[0171] The adjustment module 602 is used to adjust the first network model based on the first prediction result, the second prediction result and the annotation result to obtain a text recognition model.

[0172] In one possible implementation, the acquisition module 601 is used to acquire the appearance features of each character in the sample text image based on the first network model; acquire the position features of each character in the sample text image based on the first network model; and determine the visual features of the sample text image based on the appearance features of each character in the sample text image and the position features of each character in the sample text image.

[0173] In one possible implementation, the acquisition module 601 is used to fuse the appearance features of each character in the sample text image and the position features of each character in the sample text image for any character in the sample text image to obtain a first fused feature of any character; and determine the visual features of the sample text image based on the first fused features of each character in the sample text image.

[0174] In one possible implementation, the acquisition module 601 is used to fuse the appearance features of at least one adjacent character and the position features of at least one adjacent character corresponding to any character in the sample text image to obtain a second fused feature of any character; and determine the visual features of the sample text image based on the second fused features of each character in the sample text image.

[0175] In one possible implementation, the acquisition module 601 is used to determine, for any character in the sample text image, a first probability that any character belongs to each reference character based on the first network model and the visual features of the sample text image; determine a first maximum probability from the first probabilities that any character belongs to each reference character; and determine the reference character corresponding to the first maximum probability as the character corresponding to any character obtained by prediction by the first network model.

[0176] In one possible implementation, the acquisition module 601 is used to determine the semantic features of each character in the sample text image based on the second network model and the annotation results; obtain the position features of each character in the sample text image based on the first network model; and obtain a second prediction result of the sample text image based on the visual features of the sample text image, the semantic features of each character in the sample text image, and the position features of each character in the sample text image.

[0177] In one possible implementation, the acquisition module 601 is used to determine the third fusion feature of each character in the sample text image based on the position feature of each character in the sample text image and the semantic feature of each character in the sample text image; and obtain the second prediction result of the sample text image based on the visual feature of the sample text image and the third fusion feature of each character in the sample text image.

[0178] In one possible implementation, the acquisition module 601 is used to fuse the semantic features of any character, the position features of any character, the semantic features of each character before any character, and the position features of each character before any character for any character in the sample text image to obtain a third fused feature of any character.

[0179] In one possible implementation, the acquisition module 601 is used to fuse the visual features of the sample text image and the third fusion features of each character in the sample text image for any character in the sample text image to obtain the fourth fusion features of any character; based on the fourth fusion features of each character in the sample text image, obtain the second prediction result of the sample text image.

[0180] In one possible implementation, the acquisition module 601 is used to determine, for any character in the sample text image, the second probability that any character belongs to each reference character based on the fourth fusion feature of each character in the sample text image; determine the second maximum probability from the second probabilities that any character belongs to each reference character; and determine the reference character corresponding to the second maximum probability as the character corresponding to any character obtained by prediction by the second network model.

[0181] In one possible implementation, the adjustment module 602 is used to determine a first loss value based on the first prediction result and the annotation result; determine a second loss value based on the second prediction result and the annotation result; and adjust the first network model based on the first loss value and the second loss value to obtain a text recognition model.

[0182] In one possible implementation, the adjustment module 602 is further used to determine a third loss value based on the first prediction result and the labeling result; determine a fourth loss value based on the second prediction result and the labeling result; and adjust the second network model based on the third loss value and the fourth loss value to obtain an adjusted second network model.

[0183] In a possible implementation, the acquisition module 601 is used to acquire a text image to be processed; and to crop an image region containing text from the text image to be processed to obtain a sample text image.

[0184] After obtaining the visual features of the sample text image based on the first network model, the above device determines the first prediction result of the sample text image based on the first network model and the visual features, and determines the second prediction result of the sample text image based on the second network model and the visual features. Afterwards, the first prediction result, the second prediction result and the annotation result of the sample text image are used to train a text recognition model, so that the text recognition model integrates the text recognition capabilities of different models, can improve the text recognition model's ability to extract visual features, and thus improve the text recognition capability of the text recognition model.

[0185] It should be understood that the above Figure 6When the device provided realizes its functions, only the division of the above-mentioned functional modules is used as an example for illustration. In practical applications, the above-mentioned functions can be assigned to different functional modules as needed, that is, the internal structure of the device is divided into different functional modules to complete all or part of the functions described above. In addition, the device and method embodiments provided in the above embodiments belong to the same concept, and their specific implementation process is detailed in the method embodiment, which will not be repeated here.

[0186] Figure 7 FIG. 1 is a schematic diagram of a text recognition device provided in an embodiment of the present application. Figure 7 As shown, the device comprises:

[0187] The first acquisition module 701 is used to acquire a target text image;

[0188] A second acquisition module 702 is used to acquire visual features of a target text image based on a text recognition model, wherein the visual features of the target text image are used to characterize the shape and position of each character in the target text image, and the text recognition model is obtained by any of the above-mentioned text recognition model training methods;

[0189] The third acquisition module 703 is used to acquire the text recognition result of the target text image based on the visual features of the target text image. The text recognition result is each character in the target text image predicted by the text recognition model.

[0190] In one possible implementation, the second acquisition module 702 is used to acquire the appearance features of each character in the target text image based on the text recognition model; acquire the position features of each character in the target text image based on the text recognition model; and determine the visual features of the target text image based on the appearance features of each character in the target text image and the position features of each character in the target text image.

[0191] The text recognition model in the above-mentioned device is trained in the following manner: after the visual features of the sample text image are acquired based on the first network model, on the one hand, a first prediction result of the sample text image is determined based on the first network model and the visual features, and on the other hand, a second prediction result of the sample text image is determined based on the second network model and the visual features. Afterwards, the text recognition model is trained using the first prediction result, the second prediction result, and the annotation result of the sample text image. The text recognition model in the embodiment of the present application combines the text recognition capabilities of different models, and can improve the text recognition model's ability to extract visual features, thereby improving the text recognition capability of the text recognition model.

[0192] It should be understood that the above Figure 7When the device provided realizes its functions, only the division of the above-mentioned functional modules is used as an example for illustration. In practical applications, the above-mentioned functions can be assigned to different functional modules as needed, that is, the internal structure of the device is divided into different functional modules to complete all or part of the functions described above. In addition, the device and method embodiments provided in the above embodiments belong to the same concept, and their specific implementation process is detailed in the method embodiment, which will not be repeated here.

[0193] Figure 8 The structure block diagram of a terminal device 800 provided by an exemplary embodiment of the present application is shown. The terminal device 800 may be a portable mobile terminal, such as a smart phone, a tablet computer, a notebook computer or a desktop computer. The terminal device 800 may also be called a user device, a portable terminal, a laptop terminal, a desktop terminal or other names.

[0194] Typically, the terminal device 800 includes: a processor 801 and a memory 802 .

[0195] The processor 801 may include one or more processing cores, such as a 4-core processor, an 8-core processor, etc. The processor 801 may be implemented in at least one hardware form of DSP (Digital Signal Processing), FPGA (Field-Programmable Gate Array), and PLA (Programmable Logic Array). The processor 801 may also include a main processor and a coprocessor. The main processor is a processor for processing data in an awake state, also known as a CPU (Central Processing Unit); the coprocessor is a low-power processor for processing data in a standby state. In some embodiments, the processor 801 may be integrated with a GPU (Graphics Processing Unit), which is responsible for rendering and drawing the content to be displayed on the display screen. In some embodiments, the processor 801 may also include an AI (Artificial Intelligence) processor, which is used to process computing operations related to machine learning.

[0196] The memory 802 may include one or more computer-readable storage media, which may be non-transitory. The memory 802 may also include a high-speed random access memory, and a non-volatile memory, such as one or more disk storage devices, flash memory storage devices. In some embodiments, the non-transitory computer-readable storage medium in the memory 802 is used to store at least one instruction, which is used to be executed by the processor 801 to implement the training method or text recognition method of the text recognition model provided in the method embodiment of the present application.

[0197] In some embodiments, the terminal device 800 may further optionally include: a peripheral device interface 803 and at least one peripheral device. The processor 801, the memory 802 and the peripheral device interface 803 may be connected via a bus or a signal line. Each peripheral device may be connected to the peripheral device interface 803 via a bus, a signal line or a circuit board. Specifically, the peripheral device includes: at least one of a radio frequency circuit 804, a display screen 805, a camera assembly 806, an audio circuit 807 and a power supply 808.

[0198] The peripheral device interface 803 may be used to connect at least one peripheral device related to I / O (Input / Output) to the processor 801 and the memory 802. In some embodiments, the processor 801, the memory 802, and the peripheral device interface 803 are integrated on the same chip or circuit board; in some other embodiments, any one or two of the processor 801, the memory 802, and the peripheral device interface 803 may be implemented on a separate chip or circuit board, which is not limited in this embodiment.

[0199] The radio frequency circuit 804 is used to receive and transmit RF (Radio Frequency) signals, also known as electromagnetic signals. The radio frequency circuit 804 communicates with communication networks and other communication devices through electromagnetic signals. The radio frequency circuit 804 converts electrical signals into electromagnetic signals for transmission, or converts received electromagnetic signals into electrical signals. Optionally, the radio frequency circuit 804 includes: an antenna system, an RF transceiver, one or more amplifiers, a tuner, an oscillator, a digital signal processor, a codec chipset, a user identity module card, and the like. The radio frequency circuit 804 can communicate with other terminals through at least one wireless communication protocol. The wireless communication protocol includes, but is not limited to: the World Wide Web, a metropolitan area network, an intranet, various generations of mobile communication networks (2G, 3G, 4G and 5G), a wireless local area network and / or a WiFi (Wireless Fidelity) network. In some embodiments, the radio frequency circuit 804 may also include circuits related to NFC (Near Field Communication), which is not limited in this application.

[0200] The display screen 805 is used to display the UI (User Interface). The UI may include graphics, text, icons, videos, and any combination thereof. When the display screen 805 is a touch display screen, the display screen 805 also has the ability to collect touch signals on the surface or above the surface of the display screen 805. The touch signal can be input to the processor 801 as a control signal for processing. At this time, the display screen 805 can also be used to provide virtual buttons and / or virtual keyboards, also known as soft buttons and / or soft keyboards. In some embodiments, the display screen 805 can be one, set on the front panel of the terminal device 800; in other embodiments, the display screen 805 can be at least two, respectively set on different surfaces of the terminal device 800 or in a folding design; in other embodiments, the display screen 805 can be a flexible display screen, set on the curved surface or folding surface of the terminal device 800. Even, the display screen 805 can also be set to a non-rectangular irregular shape, that is, a special-shaped screen. The display screen 805 can be made of materials such as LCD (Liquid Crystal Display), OLED (Organic Light-Emitting Diode, organic light-emitting diode).

[0201] The camera assembly 806 is used to capture images or videos. Optionally, the camera assembly 806 includes a front camera and a rear camera. Typically, the front camera is arranged on the front panel of the terminal, and the rear camera is arranged on the back of the terminal. In some embodiments, there are at least two rear cameras, which are any one of a main camera, a depth of field camera, a wide-angle camera, and a telephoto camera, so as to realize the fusion of the main camera and the depth of field camera to realize the background blur function, the fusion of the main camera and the wide-angle camera to realize panoramic shooting and VR (Virtual Reality) shooting function or other fusion shooting functions. In some embodiments, the camera assembly 806 may also include a flash. The flash can be a monochrome temperature flash or a dual-color temperature flash. A dual-color temperature flash refers to a combination of a warm light flash and a cold light flash, which can be used for light compensation at different color temperatures.

[0202] The audio circuit 807 may include a microphone and a speaker. The microphone is used to collect sound waves from the user and the environment, and convert the sound waves into electrical signals and input them into the processor 801 for processing, or input them into the radio frequency circuit 804 to achieve voice communication. For the purpose of stereo acquisition or noise reduction, there may be multiple microphones, which are respectively arranged at different parts of the terminal device 800. The microphone may also be an array microphone or an omnidirectional acquisition microphone. The speaker is used to convert the electrical signal from the processor 801 or the radio frequency circuit 804 into sound waves. The speaker may be a traditional film speaker or a piezoelectric ceramic speaker. When the speaker is a piezoelectric ceramic speaker, it can not only convert the electrical signal into sound waves audible to humans, but also convert the electrical signal into sound waves inaudible to humans for purposes such as ranging. In some embodiments, the audio circuit 807 may also include a headphone jack.

[0203] The power supply 808 is used to power various components in the terminal device 800. The power supply 808 can be an alternating current, a direct current, a disposable battery, or a rechargeable battery. When the power supply 808 includes a rechargeable battery, the rechargeable battery can be a wired rechargeable battery or a wireless rechargeable battery. A wired rechargeable battery is a battery charged through a wired line, and a wireless rechargeable battery is a battery charged through a wireless coil. The rechargeable battery can also be used to support fast charging technology.

[0204] In some embodiments, the terminal device 800 further includes one or more sensors 809 , including but not limited to: an acceleration sensor 811 , a gyroscope sensor 812 , a pressure sensor 813 , an optical sensor 814 , and a proximity sensor 815 .

[0205] The acceleration sensor 811 can detect the magnitude of acceleration on the three coordinate axes of the coordinate system established by the terminal device 800. For example, the acceleration sensor 811 can be used to detect the components of gravity acceleration on the three coordinate axes. The processor 801 can control the display screen 805 to display the user interface in a horizontal view or a vertical view according to the gravity acceleration signal collected by the acceleration sensor 811. The acceleration sensor 811 can also be used for collecting game or user motion data.

[0206] The gyroscope sensor 812 can detect the body direction and rotation angle of the terminal device 800, and the gyroscope sensor 812 can cooperate with the acceleration sensor 811 to collect the user's 3D actions on the terminal device 800. The processor 801 can implement the following functions based on the data collected by the gyroscope sensor 812: motion sensing (such as changing the UI according to the user's tilt operation), image stabilization during shooting, game control, and inertial navigation.

[0207] The pressure sensor 813 can be set on the side frame of the terminal device 800 and / or the lower layer of the display screen 805. When the pressure sensor 813 is set on the side frame of the terminal device 800, it can detect the user's holding signal of the terminal device 800, and the processor 801 performs left and right hand recognition or shortcut operation according to the holding signal collected by the pressure sensor 813. When the pressure sensor 813 is set on the lower layer of the display screen 805, the processor 801 controls the operability controls on the UI interface according to the user's pressure operation on the display screen 805. The operability controls include at least one of a button control, a scroll bar control, an icon control, and a menu control.

[0208] The optical sensor 814 is used to collect the ambient light intensity. In one embodiment, the processor 801 can control the display brightness of the display screen 805 according to the ambient light intensity collected by the optical sensor 814. Specifically, when the ambient light intensity is high, the display brightness of the display screen 805 is increased; when the ambient light intensity is low, the display brightness of the display screen 805 is reduced. In another embodiment, the processor 801 can also dynamically adjust the shooting parameters of the camera assembly 806 according to the ambient light intensity collected by the optical sensor 814.

[0209] The proximity sensor 815, also called a distance sensor, is usually arranged on the front panel of the terminal device 800. The proximity sensor 815 is used to collect the distance between the user and the front of the terminal device 800. In one embodiment, when the proximity sensor 815 detects that the distance between the user and the front of the terminal device 800 is gradually decreasing, the processor 801 controls the display screen 805 to switch from the screen-on state to the screen-off state; when the proximity sensor 815 detects that the distance between the user and the front of the terminal device 800 is gradually increasing, the processor 801 controls the display screen 805 to switch from the screen-off state to the screen-on state.

[0210] Those skilled in the art will understand that Figure 8 The structure shown in the figure does not constitute a limitation on the terminal device 800, and may include more or fewer components than shown in the figure, or combine certain components, or adopt a different component arrangement.

[0211] Fig. 9This is a schematic diagram of the structure of the server provided in the embodiment of the present application. The server 900 may have relatively large differences due to different configurations or performances, and may include one or more processors 901 and one or more memories 902, wherein the one or more memories 902 store at least one program code, and the at least one program code is loaded and executed by the one or more processors 901 to implement the training method of the text recognition model or the text recognition method provided in the above-mentioned various method embodiments. Exemplarily, the processor 901 is a CPU. Of course, the server 900 may also have components such as a wired or wireless network interface, a keyboard, and an input and output interface for input and output. The server 900 may also include other components for implementing device functions, which will not be described in detail here.

[0212] In an exemplary embodiment, a computer-readable storage medium is also provided, in which at least one program code is stored. The at least one program code is loaded and executed by a processor to enable an electronic device to implement any of the above-mentioned text recognition model training methods or text recognition methods.

[0213] Optionally, the computer-readable storage medium may be a read-only memory (ROM), a random access memory (RAM), a compact disc (CD-ROM), a magnetic tape, a floppy disk, an optical data storage device, etc.

[0214] In an exemplary embodiment, a computer program or a computer program product is also provided, in which at least one computer instruction is stored, and the at least one computer instruction is loaded and executed by a processor to enable a computer to implement any of the above-mentioned text recognition model training methods or text recognition methods.

[0215] It should be understood that the "plurality" mentioned in this article refers to two or more. "And / or" describes the association relationship of the associated objects, indicating that there can be three relationships. For example, A and / or B can mean: A exists alone, A and B exist at the same time, and B exists alone. The character " / " generally indicates that the associated objects are in an "or" relationship.

[0216] The serial numbers of the above-mentioned embodiments of the present application are for description only and do not represent the advantages or disadvantages of the embodiments.

[0217] The above are merely exemplary embodiments of the present application and are not intended to limit the present application. Any modifications, equivalent substitutions, improvements, etc. made within the principles of the present application shall be included in the protection scope of the present application.

Claims

1. A training method for a text recognition model, characterized in that: The method comprises: Acquire a sample text image and a labeling result of the sample text image, wherein the labeling result is each character in the sample text image obtained by labeling; Acquiring visual features of the sample text image based on the first network model, wherein the visual features of the sample text image are used to characterize the shape and position of each character in the sample text image; Based on the first network model and the visual features of the sample text image, obtaining a first prediction result of the sample text image, wherein the first prediction result is each character in the sample text image obtained by prediction by the first network model; Determine the semantic features of each character based on the second network model and the annotation result; obtain a second prediction result of the sample text image based on the visual features of the sample text image, the semantic features and position features of each character, wherein the second prediction result is each character in the sample text image obtained by prediction by the second network model; Based on the first prediction result and the annotation result, a first loss value is determined; based on the second prediction result and the annotation result, a second loss value is determined; based on the first loss value and the second loss value, the first network model is adjusted, and the adjusted first network model is used as a text recognition model, and the text recognition model is used to obtain visual features of a target text image, and based on the visual features of the target text image, a text recognition result of the target text image is obtained.

2. The method according to claim 1, characterized in that The obtaining of visual features of the sample text image based on the first network model includes: Acquire the appearance features of each character in the sample text image and the position features of each character in the sample text image based on the first network model; Based on the appearance features of each character in the sample text image and the position features of each character in the sample text image, the visual features of the sample text image are determined.

3. The method according to claim 2, characterized in that The determining of the visual features of the sample text image based on the appearance features of each character in the sample text image and the position features of each character in the sample text image comprises: For any character in the sample text image, the appearance features of each character in the sample text image and the position features of each character in the sample text image are fused to obtain a first fused feature of the any character; Based on the first fused features of each character in the sample text image, the visual features of the sample text image are determined.

4. The method according to claim 2, characterized in that: The determining of the visual features of the sample text image based on the appearance features of each character in the sample text image and the position features of each character in the sample text image comprises: For any character in the sample text image, fuse the appearance feature of at least one adjacent character corresponding to the any character and the position feature of the at least one adjacent character to obtain a second fused feature of the any character; Based on the second fused features of each character in the sample text image, the visual features of the sample text image are determined.

5. The method according to claim 1, characterized in that The obtaining a first prediction result of the sample text image based on the first network model and the visual features of the sample text image includes: For any character in the sample text image, determining a first probability that the any character belongs to each reference character based on the first network model and visual features of the sample text image; determining a first maximum probability from among the first probabilities that any one of the characters belongs to each of the reference characters; The reference character corresponding to the first maximum probability is determined as the character corresponding to any one of the characters and obtained by prediction by the first network model.

6. The method according to claim 1, characterized in that The obtaining a second prediction result of the sample text image based on the visual features of the sample text image, the semantic features and the position features of each character, comprises: Determining a third fusion feature of each character in the sample text image based on a position feature of each character in the sample text image and a semantic feature of each character in the sample text image; Based on the visual features of the sample text image and the third fusion features of each character in the sample text image, a second prediction result of the sample text image is obtained.

7. The method according to claim 6, characterized in that The determining of the third fusion feature of each character in the sample text image based on the position feature of each character in the sample text image and the semantic feature of each character in the sample text image includes: For any character in the sample text image, the semantic features of the any character, the position features of the any character, the semantic features of each character before the any character, and the position features of each character before the any character are fused to obtain a third fused feature of the any character.

8. The method according to claim 6, characterized in that The obtaining a second prediction result of the sample text image based on the visual feature of the sample text image and the third fusion feature of each character in the sample text image includes: For any character in the sample text image, the visual feature of the sample text image and the third fusion feature of each character in the sample text image are fused to obtain a fourth fusion feature of the any character; Based on the fourth fusion feature of each character in the sample text image, a second prediction result of the sample text image is obtained.

9. The method according to claim 8, characterized in that The obtaining a second prediction result of the sample text image based on the fourth fusion feature of each character in the sample text image includes: For any character in the sample text image, determining a second probability that the any character belongs to each reference character based on the fourth fusion feature of each character in the sample text image; determining a second maximum probability from the second probabilities that any one character belongs to each reference character; The reference character corresponding to the second maximum probability is determined as the character corresponding to any one of the characters and obtained by prediction by the second network model.

10. The method according to any one of claims 1 to 9, characterized in that: The method further comprises: Determining a third loss value based on the first prediction result and the labeling result; Determining a fourth loss value based on the second prediction result and the labeling result; The second network model is adjusted based on the third loss value and the fourth loss value to obtain an adjusted second network model.

11. The method according to any one of claims 1 to 9, characterized in that: The step of obtaining a sample text image comprises: Get the text image to be processed; The image region containing the text is cut out from the text image to be processed to obtain the sample text image.

12. A text recognition method, characterized in that: The method comprises: Get the target text image; Acquiring visual features of the target text image based on a text recognition model, wherein the visual features of the target text image are used to characterize the shape and position of each character in the target text image, wherein the text recognition model is obtained according to the training method of the text recognition model according to any one of claims 1 to 11; Based on the visual features of the target text image, a text recognition result of the target text image is obtained, where the text recognition result is each character in the target text image predicted by the text recognition model.

13. The method according to claim 12, characterized in that The acquiring the visual features of the target text image based on the text recognition model includes: Acquire the shape features of each character in the target text image and the position features of each character in the target text image based on the text recognition model; Based on the appearance features of each character in the target text image and the position features of each character in the target text image, the visual features of the target text image are determined.

14. A training device for a text recognition model, characterized in that: The device comprises: An acquisition module, used for acquiring a sample text image and a labeling result of the sample text image, wherein the labeling result is each character in the sample text image obtained by labeling; The acquisition module is further used to acquire visual features of the sample text image based on the first network model, wherein the visual features of the sample text image are used to characterize the shape and position of each character in the sample text image; The acquisition module is further used to acquire a first prediction result of the sample text image based on the first network model and the visual features of the sample text image, wherein the first prediction result is each character in the sample text image obtained by prediction by the first network model; The acquisition module is further used to determine the semantic features of each character based on the second network model and the annotation result; based on the visual features of the sample text image, the semantic features and position features of each character, acquire a second prediction result of the sample text image, wherein the second prediction result is each character in the sample text image obtained by prediction by the second network model; An adjustment module is used to determine a first loss value based on the first prediction result and the annotation result; determine a second loss value based on the second prediction result and the annotation result; adjust the first network model based on the first loss value and the second loss value, and use the adjusted first network model as a text recognition model, the text recognition model is used to obtain visual features of a target text image, and obtain a text recognition result of the target text image based on the visual features of the target text image.

15. The device according to claim 14, characterized in that The acquisition module is used to acquire the appearance features of each character in the sample text image and the position features of each character in the sample text image based on the first network model; Based on the appearance features of each character in the sample text image and the position features of each character in the sample text image, the visual features of the sample text image are determined.

16. The device according to claim 15, characterized in that The acquisition module is used for fusing the appearance features of each character in the sample text image and the position features of each character in the sample text image for any character in the sample text image to obtain a first fused feature of the any character; Based on the first fused features of each character in the sample text image, the visual features of the sample text image are determined.

17. The device according to claim 15, characterized in that The acquisition module is used for fusing, for any character in the sample text image, the appearance feature of at least one adjacent character corresponding to the any character and the position feature of the at least one adjacent character to obtain a second fused feature of the any character; Based on the second fused features of each character in the sample text image, the visual features of the sample text image are determined.

18. The device according to claim 14, characterized in that The acquisition module is used to determine, for any character in the sample text image, a first probability that the any character belongs to each reference character based on the first network model and the visual features of the sample text image; determine a first maximum probability from the first probabilities that the any character belongs to each reference character; and determine the reference character corresponding to the first maximum probability as the character corresponding to the any character obtained by prediction by the first network model.

19. The device according to claim 14, characterized in that The acquisition module is used to determine the third fusion feature of each character in the sample text image based on the position feature of each character in the sample text image and the semantic feature of each character in the sample text image; Based on the visual features of the sample text image and the third fusion features of each character in the sample text image, a second prediction result of the sample text image is obtained.

20. The device according to claim 19, characterized in that The acquisition module is used to fuse the semantic features of any character in the sample text image, the position features of any character, the semantic features of each character before the any character, and the position features of each character before the any character to obtain a third fused feature of the any character.

21. The device according to claim 19, characterized in that The acquisition module is used for fusing the visual features of the sample text image and the third fusion features of each character in the sample text image for any character in the sample text image to obtain the fourth fusion feature of the any character; Based on the fourth fusion feature of each character in the sample text image, a second prediction result of the sample text image is obtained.

22. The device according to claim 21, characterized in that The acquisition module is used to determine, for any character in the sample text image, a second probability that the any character belongs to each reference character based on the fourth fusion feature of each character in the sample text image; determine a second maximum probability from the second probabilities that the any character belongs to each reference character; and determine the reference character corresponding to the second maximum probability as the character corresponding to the any character obtained by prediction by the second network model.

23. The device according to any one of claims 14 to 22, characterized in that The adjustment module is also used to determine a third loss value based on the first prediction result and the labeling result; determine a fourth loss value based on the second prediction result and the labeling result; and adjust the second network model based on the third loss value and the fourth loss value to obtain an adjusted second network model.

24. The device according to any one of claims 14 to 22, characterized in that The acquisition module is used to acquire the text image to be processed; and to cut out the image area containing the text from the text image to be processed to obtain the sample text image.

25. A text recognition device, characterized in that: The device comprises: A first acquisition module, used for acquiring a target text image; A second acquisition module, configured to acquire visual features of the target text image based on a text recognition model, wherein the visual features of the target text image are used to characterize the shape and position of each character in the target text image, wherein the text recognition model is obtained according to the training method of the text recognition model according to any one of claims 1 to 11; The third acquisition module is used to acquire the text recognition result of the target text image based on the visual features of the target text image, and the text recognition result is each character in the target text image obtained by prediction by the text recognition model.

26. The device according to claim 25, characterized in that The second acquisition module is used to acquire the appearance features of each character in the target text image and the position features of each character in the target text image based on the text recognition model; Based on the appearance features of each character in the target text image and the position features of each character in the target text image, the visual features of the target text image are determined.

27. An electronic device, characterized in that: The electronic device includes a processor and a memory, wherein the memory stores at least one program code, and the at least one program code is loaded and executed by the processor so that the electronic device implements the training method of the text recognition model as described in any one of claims 1 to 11 or the text recognition method as described in any one of claims 12 to 13.

28. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores at least one program code, and the at least one program code is loaded and executed by the processor so that the computer implements the training method of the text recognition model as described in any one of claims 1 to 11 or the text recognition method as described in any one of claims 12 to 13.

29. A computer program product, characterized in that The computer program product stores at least one computer instruction, and the at least one computer instruction is loaded and executed by a processor so that a computer implements the training method of a text recognition model as described in any one of claims 1 to 11 or the text recognition method as described in any one of claims 12 to 13.