Text recognition method, text recognition network training method and device
Through the encoding, decoding and attention layer mechanisms of the text recognition network, combined with character-level text instance training, the problem that the existing text detection pre-training method cannot fully mine semantic information is solved, and the detection effect in the absence of real data is improved. .
Patent Information
- Application Number
- CN202210034363.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-01-12
- Publication Date
- 2024-09-06
- Estimated Expiration
- 2042-01-12
Smart Images

Figure CN114495102B
Abstract
Description
Technical Field
[0001] The present disclosure relates to the field of image processing technology, and in particular to an artificial intelligence text recognition method, a text recognition network training method and a device. Background Art
[0002] Text recognition refers to the recognition of text in an image after the existing text detection method has been used to determine the location of the text in the image and find its bounding box. It can be widely used in business scenarios such as ID card recognition and bill recognition, thereby greatly saving manual input time and improving efficiency in various application scenarios. Summary of the invention
[0003] The present invention provides a text recognition method, a training method and a device for a text recognition network.
[0004] According to one aspect of the present disclosure, a text recognition method is provided, comprising:
[0005] Determine the encoded sequence features corresponding to the image to be identified;
[0006] Determining a decoded sequence vector based on the encoded sequence features and the character features corresponding to the text instance;
[0007] Determining the text included in the image to be recognized based on the decoded sequence vector;
[0008] The text instance includes at least one preset character.
[0009] According to another aspect of the present disclosure, a training method for a text recognition network is provided, wherein the text recognition network includes an encoding subnetwork, a decoding subnetwork, and an output subnetwork, and the method includes:
[0010] Determine, based on the encoding subnetwork, encoded sequence sample features corresponding to the sample images in the training sample set;
[0011] Using the encoded sequence sample features and the character sample features corresponding to the text instance sample as inputs of the cross-layer attention layer of the decoding subnetwork, and determining the output of the cross-layer attention layer as a decoded sample sequence vector;
[0012] Using the decoded sample sequence vector as the input of the output sub-network, and determining the predicted text included in the sample image according to the output of the output sub-network;
[0013] Matching the predicted text included in the sample image with the annotated text included in the sample image, and adjusting the parameters of the text recognition network based on the matching result;
[0014] The text instance includes at least one preset character; the character includes at least one of letters, numbers, symbols, and words.
[0015] A third aspect of the present disclosure provides a text recognition device, comprising:
[0016] An encoding unit, used to determine the encoded sequence features corresponding to the image to be identified;
[0017] A decoding unit, used to determine a decoded sequence vector based on the encoded sequence features and character features corresponding to the text instance;
[0018] An output unit, used for determining the text included in the image to be recognized based on the decoded sequence vector;
[0019] The text instance includes at least one preset character.
[0020] A fourth aspect of the present disclosure provides a training device for a text recognition network, comprising:
[0021] A first determining unit, configured to determine, based on the encoding subnetwork, encoded sequence sample features corresponding to the sample images in the training sample set;
[0022] A second determining unit is used to use the encoded sequence sample features and the character sample features corresponding to the text instance sample as inputs of the cross-layer attention layer of the decoding subnetwork, and determine the output of the cross-layer attention layer as a decoded sample sequence vector;
[0023] a third determining unit, configured to use the decoded sample sequence vector as an input of the output subnetwork, and determine the predicted text included in the sample image according to the output of the output subnetwork;
[0024] An adjustment unit, configured to match the predicted text included in the sample image with the annotated text included in the sample image, and adjust the parameters of the text recognition network based on the matching result;
[0025] The text instance includes at least one preset character; the character includes at least one of letters, numbers, symbols, and words.
[0026] A fifth aspect of the present disclosure provides an electronic device, comprising: at least one processor; and a memory communicatively connected to the at least one processor; wherein the memory stores instructions executable by the at least one processor, and the instructions are executed by the at least one processor so that the at least one processor can execute the above-mentioned text recognition method or text recognition network training method.
[0027] A sixth aspect of the present disclosure provides a non-transitory computer-readable storage medium storing computer instructions, wherein the computer instructions are used to enable the computer to execute the above-mentioned text recognition method or text recognition network training method.
[0028] A seventh aspect of the present disclosure provides a computer program product, including a computer program / instruction, which, when executed by a processor, implements the above-mentioned text recognition method or text recognition network training method.
[0029] It should be understood that the content described in this section is not intended to identify the key or important features of the embodiments of the present disclosure, nor is it intended to limit the scope of the present disclosure. Other features of the present disclosure will become easily understood through the following description. BRIEF DESCRIPTION OF THE DRAWINGS
[0030] The accompanying drawings are used to better understand the present solution and do not constitute a limitation of the present disclosure.
[0031] Figure 1 An optional flow chart of a text recognition method provided by an embodiment of the present disclosure is shown;
[0032] Figure 2 An optional flow chart of a text recognition network training method provided by an embodiment of the present disclosure is shown;
[0033] Figure 3 Another optional flow chart of the text recognition network training method provided by the embodiment of the present disclosure is shown;
[0034] Figure 4 A data schematic diagram showing a text recognition method provided by an embodiment of the present disclosure;
[0035] Figure 5 A schematic diagram of basic sub-network migration provided by an embodiment of the present disclosure is shown;
[0036] Figure 6 An optional structural diagram of a text recognition device provided by an embodiment of the present disclosure is shown;
[0037] Figure 7 An optional structural schematic diagram of a text recognition network training device provided by an embodiment of the present disclosure is shown;
[0038] Figure 8 A schematic block diagram of an example electronic device that can be used to implement embodiments of the present disclosure is shown. DETAILED DESCRIPTION
[0039] The following is a description of exemplary embodiments of the present disclosure in conjunction with the accompanying drawings, including various details of the embodiments of the present disclosure to facilitate understanding, which should be considered as merely exemplary. Therefore, it should be recognized by those of ordinary skill in the art that various changes and modifications may be made to the embodiments described herein without departing from the scope and spirit of the present disclosure. Similarly, for the sake of clarity and conciseness, descriptions of well-known functions and structures are omitted in the following description.
[0040] Text detection technology refers to determining the location of text in an image and finding its bounding box. It is a prerequisite for many visual tasks, such as text recognition and scene understanding. It can be widely used in business scenarios such as ID card recognition and bill recognition, thereby greatly saving manual input time and improving efficiency in various application scenarios. Text detection in natural scenes has its own particularity compared to general target detection. As the main visual target, the text has diverse characteristics in terms of font, size, color, direction, shape, etc., which makes it more difficult to detect than general targets. In recent years, text detection technology has developed rapidly. Pre-training of text detection models is an important method to improve model performance, especially in real application scenarios where there is a lack of large amounts of data.
[0041] There are two main methods for pre-training text detection. One is to directly transfer the model trained on a large-scale dataset of image classification tasks to the text detection task. The other is to train on large-scale synthetic text detection data and then use real data for tuning. Both methods can alleviate the problem of too little real data to a certain extent. However, since there are still huge differences between pre-training tasks and synthetic data and detection tasks in real scenarios, it is impossible to fully mine the semantic information of text and cannot achieve the best results.
[0042] The main text detection methods include algorithms such as EAST[2]. There are two main types of existing text detection pre-training methods: one is to directly transfer the model trained on a large-scale dataset of image classification tasks to the text detection task; the other is to train on large-scale synthetic text detection data and then use real data for tuning. Both methods can alleviate the problem of too little real data to a certain extent. However, since there is still a huge difference between the pre-training task and the synthetic data and the detection task in the real scene, it is impossible to fully explore the semantic information of the text and cannot achieve the best effect.
[0043] In the related art, the text detection pre-training method has the following disadvantages:
[0044] 1. The difference between the pre-training task and the text detection task. Directly transferring the image classification model does not take into account the uniqueness of the text detection task and cannot achieve the best pre-training effect.
[0045] 2. The difference between synthetic data and real data. Large-scale synthetic text detection data makes up for the task difference, but the difference between data cannot be made up. It is easy to overfit on synthetic data and fail to fully explore the semantic features of text.
[0046] The present disclosure provides a text recognition method and a training method for a text recognition network, so as to at least solve the defects of text recognition in the prior art.
[0047] Figure 1 An optional flow chart of the text recognition method provided by the embodiment of the present disclosure is shown, and will be explained according to each step.
[0048] Step S101, determining the encoded sequence features corresponding to the image to be identified.
[0049] In some embodiments, a text recognition device (hereinafter referred to as the first device) converts an image matrix corresponding to an image to be recognized into a one-dimensional vector; determines that the feature corresponding to the one-dimensional vector is a sequence feature of the image to be recognized; and then encodes the sequence feature to obtain the encoded sequence feature.
[0050] In a specific implementation, the first device can convert the image matrix corresponding to the image to be recognized into a one-dimensional vector based on the basic subnetwork included in the text recognition network; determine the feature corresponding to the one-dimensional vector as the sequence feature of the image to be recognized; encode the sequence feature based on the encoding subnetwork included in the text recognition network to obtain the encoded sequence feature; that is, input the image to be recognized into the basic subnetwork to obtain the sequence feature of the image to be recognized; input the sequence feature of the image to be recognized into the encoding subnetwork to obtain the encoded sequence feature.
[0051] Step S102: determining a decoded sequence vector based on the encoded sequence features and the character features corresponding to the text instance.
[0052] In some embodiments, before the first device determines the decoded sequence vector, it obtains the embedding value corresponding to the text instance, and the embedding value is the character feature corresponding to the text instance; wherein the text instance includes at least one preset character, and different text instances have different corresponding embedding values; the characters may include at least one of numbers, letters, symbols and words.
[0053] In a specific implementation, the first device can obtain the embedding value corresponding to the text instance based on the self-attention layer of the decoding subnetwork included in the text recognition network; that is, the text instance is used as the input of the self-attention layer, and the output of the self-attention layer is the embedding value corresponding to the text instance.
[0054] In some embodiments, the first device can obtain the decoded sequence vector based on the cross-layer attention layer included in the decoding subnetwork; that is, the encoded sequence features and the character features corresponding to the text instance are used as inputs of the cross-layer attention layer, and the output of the cross-layer attention layer is the decoded sequence vector.
[0055] Step S103: determining the text included in the image to be recognized based on the decoded sequence vector.
[0056] In some embodiments, the first device can determine the type of the image to be recognized based on the output subnetwork included in the text recognition network; that is, the decoded sequence vector is used as the input of the front subnetwork included in the output subnetwork, and the output of the front subnetwork is at least one text type included in the image to be recognized; the at least one text type corresponds to the text included in the image to be recognized.
[0057] For example, the image to be recognized includes a first letter, a second letter, a first number and a first symbol; the output of the feedforward subnetwork is that the image to be recognized includes a first letter type, the image to be recognized includes a second letter type, the image to be recognized includes a first number type and the image to be recognized includes a first symbol type. Further, the first device determines that the image to be recognized includes a first letter, a second letter, a first number and a first symbol.
[0058] In some optional embodiments, after the first device determines the text included in the image, the first device can also determine the position information (or order) of the text included in the image; specifically, the first device multiplies the decoded sequence vector with the vector corresponding to the encoded sequence feature to obtain a product result; based on the product result, the position information of the text in the encoded sequence feature is determined; based on the position information of the text in the encoded sequence feature, the position information of the text in the image to be recognized is determined; based on the position information of the text in the image to be recognized and the text included in the image to be recognized, the text included in the image to be recognized is output according to the order of the text in the image to be recognized.
[0059] Optionally, the decoded sequence vector and the vector corresponding to the encoded sequence feature can be subjected to a Tensor multiplication operation; when performing the Tensor multiplication operation, the length of the decoded sequence vector and the vector corresponding to the encoded sequence feature can be made the same by padding with 0, copying or repeating.
[0060] In this way, through the text recognition method provided by the embodiment of the present disclosure, the encoded sequence features corresponding to the image to be recognized are determined; based on the encoded sequence features and the character features corresponding to the text instance, the decoded sequence vector is determined; based on the decoded sequence vector, the text included in the image to be recognized is determined; wherein the text instance includes at least one preset character. Since the text instance is at the character level, the specific content (type) of the text included in the image to be recognized can be directly detected, thereby realizing text recognition in the text detection stage. Moreover, because the text instance is at the character level, it is possible to get rid of the restrictions on the authenticity or quantity of the sample image, and fully mine the semantic information of the text itself based on the character-level text instance (i.e., determine the character-level text type), so that the model can achieve better detection results in the absence of a large amount of real data in business scenarios.
[0061] Figure 2 An optional flow chart of a text recognition network training method provided by an embodiment of the present disclosure is shown, and will be described according to each step.
[0062] Step S201, determining encoded sequence sample features corresponding to sample images in a training sample set based on the encoding subnetwork.
[0063] In some embodiments, the text recognition network includes a base subnetwork, an encoding subnetwork, a decoding subnetwork and an output subnetwork; the decoding subnetwork includes a self-attention layer and a cross-layer attention layer; the output subnetwork includes a pre-subnetwork.
[0064] In some embodiments, a training device for a text recognition network (hereinafter referred to as the second device) converts the image matrix corresponding to the sample image into a one-dimensional vector representing the sample image based on the basic subnetwork; the feature corresponding to the one-dimensional vector of the sample image is the sequence sample feature of the sample image; and the sequence sample feature is encoded based on the encoding subnetwork to form an encoded sequence sample feature.
[0065] Step S202, using the encoded sequence sample features and the character sample features corresponding to the text instance sample as the input of the cross-layer attention layer of the decoding sub-network, and determining the output of the cross-layer attention layer as the decoded sample sequence vector.
[0066] In some embodiments, before the second device determines the decoded sample sequence vector, it can also input the text instance sample into the self-attention layer of the decoding subnetwork, and obtain the embedding value corresponding to the text instance sample based on the output of the self-attention layer, and the embedding value is the character sample feature corresponding to the text instance sample; wherein the text instance sample includes at least one preset character, and different text instance samples have different corresponding embedding values; optionally, the character sample feature can be a one-dimensional vector; the character can include at least one of numbers, letters, symbols and words.
[0067] In some embodiments, the second device inputs the encoded sequence sample features and the character sample features into the cross-layer attention layer; and determines that the output of the cross-layer attention layer is the decoded sample sequence vector.
[0068] Step S203: using the decoded sample sequence vector as the input of the output sub-network, and determining the predicted text included in the sample image according to the output of the output sub-network.
[0069] In some embodiments, the second device uses the decoded sample sequence vector as the input of the feedforward subnetwork included in the output subnetwork to obtain at least one prediction type corresponding to the sample image; wherein the at least one prediction type corresponding to the sample image includes the type corresponding to the text included in the sample image (such as the first letter corresponding to the first letter type).
[0070] For example, the sample image includes a first letter, a second letter, a first number, and a first symbol; the output of the feedforward subnetwork is that the sample image includes a first letter type, the sample image includes a third letter type, the sample image includes a first number type, and the sample image includes a first symbol type, and further, the second device determines that the sample image includes a first letter, a third letter, a first number, and a first symbol. The third letter and the second letter may be the same or different; the prediction results here are only examples and do not represent the prediction results obtained during the actual training process.
[0071] Step S204: matching the predicted text included in the sample image with the annotated text included in the sample image, and adjusting the parameters of the text recognition network based on the matching result.
[0072] In some embodiments, the second device matches the predicted text included in the sample image and the annotated text included in the sample image, and adjusts the parameters of the text recognition network based on the matching result; if the predicted text and the annotated text are the same, it is determined not to adjust the parameters of the text recognition network; if the predicted text and the annotated text are different, the parameters of the text recognition network are adjusted based on the difference between the predicted text of the sample image and the annotated text of the sample image.
[0073] In a specific implementation, the second device may determine the category loss based on the predicted text of the sample image and the annotated text of the sample image, and adjust the parameters of the text recognition network based on the category loss.
[0074] In some optional embodiments, the second device may also multiply the decoded sample sequence vector and the vector corresponding to the encoded sample sequence feature to obtain a product result; based on the product result, determine the predicted position information of the text in the encoded sample sequence feature; based on the predicted position information of the text in the encoded sample sequence feature, determine the predicted position information of the predicted text in the sample image. Based on the predicted position information of the predicted text in the sample image, arrange the predicted text in order from top to bottom and from left to right to generate a predicted text sequence; based on the difference between the predicted text sequence and the marked text sequence corresponding to the sample image, adjust the parameters of the text recognition network. Among them, the marked text sequence corresponding to the sample image can be obtained by sorting the text included in the sample image from top to bottom and from left to right.
[0075] In some optional embodiments, the second device migrates the basic sub-network to a text detection method based on the input and / or output of the basic sub-network and the output of the output sub-network. For example, after inputting an image into the basic sub-network, the type of the image (whether it includes text) and the location information of the text in the image are output; subsequently, text recognition can be performed based on the location information of the text in the image (such as the ORC method).
[0076] In this way, through the training method of the text recognition network provided by the embodiment of the present disclosure, a neural network that can directly predict character-level instances in an image can be obtained, thereby solving the problem of text recognition network training with limited samples; the trained model can improve the accuracy of text recognition when a large amount of real data is lacking in the business scenario.
[0077] Figure 3 Another optional flow chart of the text recognition network training method provided by the embodiment of the present disclosure is shown. Figure 4A data schematic diagram of the text recognition method provided by an embodiment of the present disclosure is shown; the method will be described according to each step.
[0078] The text recognition network provided by the present disclosure first extracts features of an input image (a sample image in the training phase, or an image to be recognized in the application phase) through a basic subnetwork, and then outputs a text sequence of the text included in the image based on an encoding-decoding subnetwork (Encoder-Decoder subnetwork) and / or an output subnetwork composed of an encoding subnetwork and a decoding subnetwork. After training based on a large amount of synthetic data, the basic subnetwork is partially migrated to a real data text detection task (i.e., migrated to an application that should be used for the text detection task) to obtain a final detection model. The output of the basic subnetwork includes the type of image (whether it includes text) and the location information of the text in the image.
[0079] Step S301: input the sample image into the text recognition network.
[0080] In some embodiments, the sample image may be an image including text of any shape. Optionally, the text in the sample image is distorted, deformed, or lacks some features; the sample image may be a synthetic image or a natural scene image.
[0081] Step S302: The basic subnetwork included in the text detection network determines the sequence sample features of the sample image.
[0082] In some embodiments, the basic subnetwork (or backbone module) included in the text recognition network can be a network structure based on a convolutional neural network (CNN), Transform (a machine learning model) or a mixture of CNN and Transform. The purpose of the basic subnetwork is to extract the sequence sample features of the sample image, which can be directly migrated to the text detection method after training. The sequence includes a vector obtained by arranging the sample images in rows (such as a sample image can be represented as an h*w matrix, then the sequence corresponding to the sample image is a one-dimensional vector of 1*hw).
[0083] In some embodiments, the basic sub-network converts an image matrix corresponding to a sample image into a one-dimensional vector; and determines that the sample feature corresponding to the one-dimensional vector is a sequence sample feature of the sample image.
[0084] Step S303: the encoding and decoding subnetwork included in the text detection network determines the decoded sample sequence vector.
[0085] In some embodiments, the encoding and decoding subnetwork is composed of a self-attention layer and a cross-layer attention layer, and the purpose is to encode and decode the sequence sample features of the sample image determined by the basic subnetwork to obtain the prediction result of the text in the sample image. Specifically, the sequence sample features of the sample image output by the basic subnetwork are used as the input of the encoding subnetwork; the encoded sequence sample features are output after self-attention learning; at least one learnable text instance sample (Queries) is used as the input of the self-attention layer included in the decoding subnetwork, and the output of the self-attention layer of the decoding subnetwork and the output of the encoding subnetwork are used together as the input of the cross-layer attention layer, and finally the decoded sample sequence vector is output. Among them, the text instance sample includes at least one preset character; the character includes at least one of letters, numbers, symbols, and words.
[0086] like Figure 4 As shown, after the sample image is input into the basic sub-network, the sequence sample features are obtained; after the sequence sample features are input into the encoding sub-network, the encoded sequence sample features are output through self-attention learning; the text instance sample is input into the decoding sub-network, and the corresponding character sample features are obtained through the self-attention layer; the encoded sequence sample features and the character sample features are input into the cross-layer attention layer, and finally the decoded sample sequence vector is output.
[0087] In some embodiments, the decoded sample sequence vector can be passed through a feed-forward sub-network to obtain a predicted text output of specific text content.
[0088] In some embodiments, the predicted text included in the sample image and the annotated text included in the sample image are matched, and the parameters of the text recognition network are adjusted based on the matching result; specifically, if the predicted text and the annotated text are the same, it is determined not to adjust the parameters of the text recognition network; if the predicted text and the annotated text are different, the parameters of the text recognition network are adjusted based on the difference between the predicted text of the sample image and the annotated text of the sample image.
[0089] In some optional embodiments, the second device may further arrange the predicted texts included in the sample image into a predicted text sequence from top to bottom and from left to right according to the position information of the predicted texts in the sample image.
[0090] In a specific implementation, the second device may multiply the decoded sample sequence vector and the vector corresponding to the encoded sample sequence feature to obtain a product result; based on the product result, determine the predicted position information of the text in the encoded sample sequence feature; based on the predicted position information of the text in the encoded sample sequence feature, determine the predicted position information of the predicted text in the sample image. Based on the predicted position information of the predicted text in the sample image, arrange the predicted text in order from top to bottom and from left to right to generate a predicted text sequence; based on the difference between the predicted text sequence and the marked text sequence corresponding to the sample image, adjust the parameters of the text recognition network. Among them, the marked text sequence corresponding to the sample image can be obtained by sorting the text included in the sample image from top to bottom and from left to right.
[0091] In some embodiments, the method may further include:
[0092] Step S304, migrating the basic sub-network to the text detection model.
[0093] In some embodiments, the second device determines the sample image type and location information of the text in the sample image corresponding to the input and / or output of the basic sub-network based on the output of the text recognition network.
[0094] Figure 5 A schematic diagram of basic sub-network migration provided by an embodiment of the present disclosure is shown.
[0095] like Figure 5 As shown, the text detection network is based on Figure 4 After training according to the data schematic diagram shown, the second device migrates the basic sub-network to the text detection method based on the input and / or output of the basic sub-network in the text detection network and the output of the output sub-network; for example, in the training process of the text recognition network, the input of the basic sub-network, the image type corresponding to the input of the basic sub-network obtained by the encoding and decoding sub-network and the position information of the text in the image are confirmed, the image is used as the input of the basic sub-network, the image type corresponding to the image and the position information of the text in the image are used as the output of the basic sub-network, and the basic sub-network is migrated to the text detection method for use, which is used to detect whether there is text in the image (and confirm the image type) and the position information of the text in the image. Subsequently, in the text detection method, it can be confirmed whether the image includes text based on the output of the basic sub-network, and if the image includes text, the position information of the text in the image, and further based on the position information of the text in the image output by the basic sub-network, text recognition is performed through a text recognition method (such as ORC).
[0096] In some optional embodiments, after the basic sub-network is migrated to the existing text detection method, it is fine-tuned through training with real images (images of natural scenes, not artificially synthesized) to obtain a text detection model corresponding to the final text detection method.
[0097] In this way, through the training method of the text recognition network provided by the embodiment of the present disclosure, the use of character-level text instances for text recognition pre-training tasks can fully mine the semantic information of the text itself, and can enable the model to achieve better detection effects in business scenarios where a large amount of real data is lacking.
[0098] Figure 6 An optional structural schematic diagram of a text recognition device provided by an embodiment of the present disclosure is shown, and will be described according to each part.
[0099] In some embodiments, the text recognition device 600 includes an encoding unit 601 , a decoding unit 602 and an output unit 603 .
[0100] The encoding unit 601 is used to determine the encoded sequence features corresponding to the image to be identified;
[0101] A decoding unit 602, configured to determine a decoded sequence vector based on the encoded sequence features and character features corresponding to the text instance;
[0102] An output unit 603, configured to determine the text included in the image to be recognized based on the decoded sequence vector;
[0103] The text instance includes at least one preset character; the character includes at least one of letters, numbers, symbols, and words.
[0104] The encoding unit 601 is specifically used to convert the image matrix corresponding to the image to be identified into a one-dimensional vector; determine the feature corresponding to the one-dimensional vector as the sequence feature of the image to be identified; encode the sequence feature to determine the encoded sequence feature corresponding to the image to be identified.
[0105] The decoding unit 602 is further used to obtain an embedding value corresponding to the text instance, where the embedding value is a character feature corresponding to the text instance; wherein different text instances have different corresponding embedding values.
[0106] The output unit 603 is specifically configured to use the decoded sequence vector as an input of a feed-forward sub-network, and determine the text included in the image to be recognized according to the output of the feed-forward sub-network.
[0107] The output unit 603 is further used to multiply the decoded sequence vector with the vector corresponding to the encoded sequence feature to obtain a product result; determine the position information of the text in the encoded sequence feature based on the product result; determine the position information of the text in the image to be recognized based on the position information of the text in the encoded sequence feature; and output the text included in the image to be recognized according to the order of the text in the image to be recognized based on the position information of the text in the image to be recognized and the text included in the image to be recognized.
[0108] Figure 7 An optional structural schematic diagram of a training device for a text recognition network provided in an embodiment of the present disclosure is shown, and will be described according to each part.
[0109] In some embodiments, the text recognition network training device 700 includes: a first determination unit 701 , a second determination unit 702 , a third determination unit 703 and an adjustment unit 704 .
[0110] A first determining unit 701 is used to determine, based on the encoding subnetwork, encoded sequence sample features corresponding to the sample image in the training sample set;
[0111] A second determining unit 702 is configured to use the encoded sequence sample features and the character sample features corresponding to the text instance sample as inputs of the cross-layer attention layer of the decoding subnetwork, and determine the output of the cross-layer attention layer as a decoded sample sequence vector;
[0112] A third determining unit 703 is used to use the decoded sample sequence vector as an input of the output sub-network, and determine the predicted text included in the sample image according to the output of the output sub-network;
[0113] An adjustment unit 704, configured to match the predicted text included in the sample image with the annotated text included in the sample image, and adjust the parameters of the text recognition network based on the matching result;
[0114] The text instance includes at least one preset character; the character includes at least one of letters, numbers, symbols, and words.
[0115] The first determination unit 701 is specifically used to convert the image matrix corresponding to the sample image into a one-dimensional vector representing the sample image based on the basic sub-network; the feature corresponding to the one-dimensional vector of the sample image is the sequence sample feature of the sample image; the encoding sub-network encodes the sequence sample feature to determine the encoded sequence sample feature corresponding to the sample image in the training sample set.
[0116] The second determination unit 702 is also used to input the text instance sample into the self-attention layer of the decoding sub-network, and obtain the embedding value corresponding to the text instance sample based on the output of the self-attention layer, wherein the embedding value is the character sample feature corresponding to the text instance sample; wherein different text instance samples have different corresponding embedding values.
[0117] The third determination unit 703 is specifically used to use the decoded sample sequence vector as the input of the feedforward subnetwork included in the output subnetwork to obtain at least one prediction type corresponding to the sample image; wherein the at least one prediction type corresponding to the sample image includes a type corresponding to the text included in the sample image.
[0118] The adjustment unit 704 is specifically used to determine not to adjust the parameters of the text recognition network if the predicted text and the annotated text are the same; if the predicted text and the annotated text are different, adjust the parameters of the text recognition network based on the difference between the predicted text of the sample image and the annotated text of the sample image.
[0119] According to an embodiment of the present disclosure, the present disclosure also provides an electronic device, a readable storage medium and a computer program product.
[0120] Figure 8 A schematic block diagram of an example electronic device 800 that can be used to implement an embodiment of the present disclosure is shown. The electronic device is intended to represent various forms of digital computers, such as laptop computers, desktop computers, workstations, personal digital assistants, servers, blade servers, mainframe computers, and other suitable computers. The electronic device can also represent various forms of mobile devices, such as personal digital processing, cellular phones, smart phones, wearable devices, and other similar computing devices. The components shown herein, their connections and relationships, and their functions are merely examples and are not intended to limit the implementation of the present disclosure described and / or required herein.
[0121] like Figure 8 As shown, the device 800 includes a computing unit 801, which can perform various appropriate actions and processes according to a computer program stored in a read-only memory (ROM) 802 or a computer program loaded from a storage unit 808 into a random access memory (RAM) 803. In the RAM 803, various programs and data required for the operation of the device 800 can also be stored. The computing unit 801, the ROM 802, and the RAM 803 are connected to each other via a bus 804. An input / output (I / O) interface 805 is also connected to the bus 804.
[0122] A number of components in the device 800 are connected to the I / O interface 805, including: an input unit 806, such as a keyboard, a mouse, etc.; an output unit 807, such as various types of displays, speakers, etc.; a storage unit 808, such as a disk, an optical disk, etc.; and a communication unit 809, such as a network card, a modem, a wireless communication transceiver, etc. The communication unit 809 allows the device 800 to exchange information / data with other devices through a computer network such as the Internet and / or various telecommunication networks.
[0123] The computing unit 801 may be a variety of general and / or special processing components with processing and computing capabilities. Some examples of the computing unit 801 include, but are not limited to, a central processing unit (CPU), a graphics processing unit (GPU), various dedicated artificial intelligence (AI) computing chips, various computing units running machine learning model algorithms, digital signal processors (DSPs), and any appropriate processors, controllers, microcontrollers, etc. The computing unit 801 performs the various methods and processes described above, such as a text recognition method or a training method for a text recognition network. For example, in some embodiments, the text recognition method or the training method for a text recognition network may be implemented as a computer software program, which is tangibly contained in a machine-readable medium, such as a storage unit 808. In some embodiments, part or all of the computer program may be loaded and / or installed on the device 800 via the ROM 802 and / or the communication unit 809. When the computer program is loaded into the RAM 803 and executed by the computing unit 801, one or more steps of the text recognition method or the training method for the text recognition network described above may be performed. Alternatively, in other embodiments, the computing unit 801 may be configured to execute the text recognition method or the text recognition network training method in any other appropriate manner (for example, by means of firmware).
[0124] Various implementations of the systems and techniques described above herein can be implemented in digital electronic circuit systems, integrated circuit systems, field programmable gate arrays (FPGAs), application specific integrated circuits (ASICs), application specific standard products (ASSPs), systems on chips (SOCs), load programmable logic devices (CPLDs), computer hardware, firmware, software, and / or combinations thereof. These various implementations can include: being implemented in one or more computer programs that can be executed and / or interpreted on a programmable system including at least one programmable processor, which can be a special purpose or general purpose programmable processor that can receive data and instructions from a storage system, at least one input device, and at least one output device, and transmit data and instructions to the storage system, the at least one input device, and the at least one output device.
[0125] The program code for implementing the method of the present disclosure may be written in any combination of one or more programming languages. These program codes may be provided to a processor or controller of a general-purpose computer, a special-purpose computer, or other programmable data processing device, so that the program code, when executed by the processor or controller, enables the functions / operations specified in the flow chart and / or block diagram to be implemented. The program code may be executed entirely on the machine, partially on the machine, partially on the machine and partially on a remote machine as a stand-alone software package, or entirely on a remote machine or server.
[0126] In the context of the present disclosure, a machine-readable medium may be a tangible medium that may contain or store a program for use by or in conjunction with an instruction execution system, device, or equipment. A machine-readable medium may be a machine-readable signal medium or a machine-readable storage medium. A machine-readable medium may include, but is not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, device, or equipment, or any suitable combination of the foregoing. A more specific example of a machine-readable storage medium may include an electrical connection based on one or more lines, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.
[0127] To provide interaction with a user, the systems and techniques described herein can be implemented on a computer having: a display device (e.g., a CRT (cathode ray tube) or LCD (liquid crystal display) monitor) for displaying information to the user; and a keyboard and pointing device (e.g., a mouse or trackball) through which the user can provide input to the computer. Other types of devices can also be used to provide interaction with the user; for example, the feedback provided to the user can be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user can be received in any form (including acoustic input, voice input, or tactile input).
[0128] The systems and techniques described herein may be implemented in a computing system that includes back-end components (e.g., as a data server), or a computing system that includes middleware components (e.g., an application server), or a computing system that includes front-end components (e.g., a user computer with a graphical user interface or a web browser through which a user can interact with implementations of the systems and techniques described herein), or a computing system that includes any combination of such back-end components, middleware components, or front-end components. The components of the system may be interconnected by any form or medium of digital data communication (e.g., a communication network). Examples of communication networks include: a local area network (LAN), a wide area network (WAN), and the Internet.
[0129] A computer system may include a client and a server. The client and the server are generally remote from each other and usually interact through a communication network. The relationship of client and server is generated by computer programs running on respective computers and having a client-server relationship with each other. The server may be a cloud server, a server of a distributed system, or a server combined with a blockchain.
[0130] It should be understood that the various forms of processes shown above can be used to reorder, add or delete steps. For example, the steps recorded in this disclosure can be executed in parallel, sequentially or in different orders, as long as the desired results of the technical solutions disclosed in this disclosure can be achieved, and this document does not limit this.
[0131] The above specific implementations do not constitute a limitation on the protection scope of the present disclosure. It should be understood by those skilled in the art that various modifications, combinations, sub-combinations and substitutions can be made according to design requirements and other factors. Any modification, equivalent substitution and improvement made within the spirit and principle of the present disclosure shall be included in the protection scope of the present disclosure.
Claims
1. A text recognition method, comprising: Determine the encoded sequence features corresponding to the image to be identified; Input the text instance into the self-attention layer of the decoding subnetwork to obtain the character features corresponding to the text instance; different text instances correspond to different character features; Input the encoded sequence features and the character features corresponding to the text instance into the cross-layer attention layer of the decoding subnetwork to determine the decoded sequence vector; Using the decoded sequence vector as an input of a feed-forward sub-network, and determining an output of the feed-forward sub-network as at least one text type included in the image to be recognized; Determine position information of text included in the image to be recognized, and output the text included in the image to be recognized according to the order of the text in the image to be recognized based on the position information of the text in the image to be recognized and the text included in the image to be recognized; Among them, the at least one text type corresponds to the text included in the image to be recognized; the text instance is character-level, including at least one preset character; the character includes at least one of letters, numbers, symbols, and words.
2. The method according to claim 1, wherein: The step of determining the encoded sequence features corresponding to the image to be identified comprises: Convert the image matrix corresponding to the image to be recognized into a one-dimensional vector; Determining that the feature corresponding to the one-dimensional vector is a sequence feature of the image to be identified; The sequence features are encoded to determine the encoded sequence features corresponding to the image to be identified.
3. The method according to claim 1, wherein: The determining the position information of the text included in the image comprises: Multiplying the decoded sequence vector by the vector corresponding to the encoded sequence feature to obtain a product result; Based on the multiplication result, determining the position information of the text in the encoded sequence feature; Based on the position information of the text in the encoded sequence features, determining the position information of the text in the text included in the image to be recognized; Based on the position information of the text in the text included in the image to be recognized and the text included in the image to be recognized, the text included in the image to be recognized is output in the order of the text in the image to be recognized.
4. A method for training a text recognition network, wherein: The text recognition network includes an encoding subnetwork, a decoding subnetwork and an output subnetwork, and the method includes: Determine, based on the encoding subnetwork, encoded sequence sample features corresponding to the sample images in the training sample set; Input the text instance sample into the self-attention layer of the decoding subnetwork to obtain the character sample features corresponding to the text instance sample; different text instance samples correspond to different character sample features; Using the encoded sequence sample features and the character sample features corresponding to the text instance sample as inputs of the cross-layer attention layer of the decoding subnetwork, and determining the output of the cross-layer attention layer as a decoded sample sequence vector; Using the decoded sample sequence vector as the input of the output sub-network, and determining the predicted text type included in the sample image according to the output of the output sub-network; Determining predicted position information of the text included in the sample image, and outputting the predicted text included in the sample image based on the predicted position information and in the order of the predicted text in the sample image; Matching the predicted text included in the sample image with the annotated text included in the sample image, and adjusting the parameters of the text recognition network based on the matching result; The method of using the decoded sample sequence vector as the input of the output sub-network and determining the predicted text included in the sample image according to the output of the output sub-network comprises: using the decoded sample sequence vector as the input of the feedforward sub-network included in the output sub-network to obtain at least one prediction type corresponding to the sample image; Among them, at least one predicted type corresponding to the sample image includes a type corresponding to the text included in the sample image; the text instance is character-level, including at least one preset character; the character includes at least one of letters, numbers, symbols, and words.
5. The method according to claim 4, wherein: The text recognition network also includes a basic subnetwork; the step of determining the encoded sequence sample features corresponding to the sample images in the training sample set based on the encoding subnetwork includes: The basic sub-network converts the image matrix corresponding to the sample image into a one-dimensional vector representing the sample image; The feature corresponding to the one-dimensional vector of the sample image is the sequence sample feature of the sample image; The encoding subnetwork encodes the sequence sample features to determine the encoded sequence sample features corresponding to the sample images in the training sample set.
6. The method according to claim 4, wherein: The step of inputting the text instance sample into the self-attention layer of the decoding subnetwork to obtain the character sample features corresponding to the text instance sample includes: Based on the output of the self-attention layer, an embedding value corresponding to the text instance sample is obtained, and the embedding value is a character sample feature corresponding to the text instance sample.
7. The method according to claim 4, wherein: Matching the predicted text included in the sample image with the annotated text included in the sample image, and adjusting the parameters of the text recognition network based on the matching result, including: If the predicted text is the same as the annotated text, determining not to adjust the parameters of the text recognition network; If the predicted text is different from the annotated text, the parameters of the text recognition network are adjusted based on the difference between the predicted text of the sample image and the annotated text of the sample image.
8. A text recognition device, comprising: An encoding unit, used to determine the encoded sequence features corresponding to the image to be identified; A decoding unit is used to input the text instance into the self-attention layer of the decoding subnetwork to obtain the character features corresponding to the text instance; input the encoded sequence features and the character features corresponding to the text instance into the cross-layer attention layer of the decoding subnetwork to determine the decoded sequence vector; different text instances correspond to different character features; an output unit, configured to use the decoded sequence vector as an input of a feedforward subnetwork, determine the output of the feedforward subnetwork as at least one text type included in the image to be recognized; determine the position information of the text included in the image to be recognized, and output the text included in the image to be recognized based on the position information of the text in the image to be recognized and the text included in the image to be recognized, in the order of the text in the image to be recognized; Among them, the at least one text type corresponds to the text included in the image to be recognized; the text instance is character-level, including at least one preset character; the character includes at least one of letters, numbers, symbols, and words.
9. The device according to claim 8, wherein: The encoding unit is specifically used for: Convert the image matrix corresponding to the image to be recognized into a one-dimensional vector; Determining that the feature corresponding to the one-dimensional vector is a sequence feature of the image to be identified; The sequence features are encoded to determine the encoded sequence features corresponding to the image to be identified.
10. The device according to claim 8, wherein: The output unit is specifically used for: Multiplying the decoded sequence vector by the vector corresponding to the encoded sequence feature to obtain a product result; Based on the multiplication result, determining the position information of the text in the encoded sequence feature; Based on the position information of the text in the encoded sequence features, determining the position information of the text in the text included in the image to be recognized; Based on the position information of the text in the text included in the image to be recognized and the text included in the image to be recognized, the text included in the image to be recognized is output in the order of the text in the image to be recognized.
11. A training device for a text recognition network, comprising: A first determining unit, configured to determine, based on the encoding subnetwork, encoded sequence sample features corresponding to the sample image in the training sample set; Input the text instance sample into the self-attention layer of the decoding subnetwork to obtain the character sample features corresponding to the text instance sample; different text instance samples correspond to different character sample features; A second determining unit is used to use the encoded sequence sample features and the character sample features corresponding to the text instance sample as inputs of the cross-layer attention layer of the decoding subnetwork, and determine the output of the cross-layer attention layer as a decoded sample sequence vector; A third determining unit is used to use the decoded sample sequence vector as an input of an output subnetwork, and determine the predicted text included in the sample image according to the output of the output subnetwork; determine the predicted position information of the text included in the sample image, and output the predicted text included in the sample image based on the predicted position information and in the order of the predicted text in the sample image; An adjustment unit, configured to match the predicted text included in the sample image with the annotated text included in the sample image, and adjust the parameters of the text recognition network based on the matching result; The third determining unit is specifically configured to use the decoded sample sequence vector as an input of a feedforward subnetwork included in the output subnetwork to obtain at least one prediction type corresponding to the sample image; Among them, at least one predicted type corresponding to the sample image includes a type corresponding to the text included in the sample image; the text instance is character-level, including at least one preset character; the character includes at least one of letters, numbers, symbols, and words.
12. The device according to claim 11, wherein The first determining unit is specifically configured to: Converting the image matrix corresponding to the sample image into a one-dimensional vector representing the sample image based on the basic sub-network; The feature corresponding to the one-dimensional vector of the sample image is the sequence sample feature of the sample image; The encoding subnetwork encodes the sequence sample features to determine the encoded sequence sample features corresponding to the sample images in the training sample set.
13. The device according to claim 11, wherein: The second determining unit is further configured to: The text instance sample is input into the self-attention layer of the decoding sub-network, and an embedding value corresponding to the text instance sample is obtained based on the output of the self-attention layer, where the embedding value is a character sample feature corresponding to the text instance sample.
14. The device according to claim 11, wherein: The adjustment unit is specifically used for: If the predicted text is the same as the annotated text, determining not to adjust the parameters of the text recognition network; If the predicted text is different from the annotated text, the parameters of the text recognition network are adjusted based on the difference between the predicted text of the sample image and the annotated text of the sample image.
15. An electronic device comprising: at least one processor; as well as a memory communicatively connected to the at least one processor; wherein, The memory stores instructions executable by the at least one processor, and the instructions are executed by the at least one processor so that the at least one processor can perform the method according to any one of claims 1 to 3; Alternatively, the at least one processor is enabled to execute the method of any one of claims 4-7.
16. A non-transitory computer-readable storage medium storing computer instructions, wherein: The computer instructions are used to cause the computer to execute the method according to any one of claims 1 to 3; Alternatively, the computer instructions are used to cause the computer to execute the method according to any one of claims 4-7.
Citation Information
Patent Citations
Text recognition model training method, text recognition method, device and equipment
CN111401375A
Text recognition method and device, electronic equipment and storage medium
CN111753822A
Text detection model training method and text detection method and device and equipment
CN113657390A
Content identification method and device, computer equipment and storage medium
CN113723166A
Character recognition method and device, equipment and storage medium
CN113792741A
