Text recognition method, device and equipment
By using a combined loss function of similarity loss and classification loss in the text recognition algorithm, the training model focuses on the overall structure of the text, solving the problem of low recognition accuracy caused by overfitting in the existing technology, and improving the accuracy of text recognition. .
Patent Information
- Application Number
- CN202110788604.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-07-13
- Publication Date
- 2024-09-13
- Estimated Expiration
- 2041-07-13
AI Technical Summary
Existing text recognition algorithms are prone to overfitting when there are few training samples, resulting in low recognition accuracy. This is mainly because convolutional neural networks focus on local information and ignore the overall structure.
The combined loss function of similarity loss and classification loss is used to train the target recognition model, the glyph similarity is calculated through the cosine distance formula, and the similarity loss and classification loss are obtained by combining the preset algorithm, and the model parameters are adjusted to improve the recognition accuracy.
By paying attention to the overall structure of the text, the accuracy of text recognition is improved, the over-fitting problem is avoided, and the generalization ability of the model is enhanced.
Smart Images

Figure CN113627262B
Abstract
Description
Technical Field
[0001] The present invention relates to the field of artificial intelligence technology, and in particular to a text recognition method, device and equipment. Background Art
[0002] Character recognition is a technology that uses computers to automatically recognize characters. It is an important field of artificial intelligence. People have to deal with a lot of text in production and life. Through character recognition technology, people's labor can be reduced and processing efficiency can be improved.
[0003] Current text recognition algorithms generally classify text images directly through models such as convolutional neural networks, and models such as convolutional neural networks generally use classification loss functions. If there are only classification loss functions, models such as convolutional neural networks tend to focus on local information of text, and are prone to overfitting when there are fewer training samples, resulting in lower accuracy in text recognition. Summary of the invention
[0004] The embodiments of the present invention provide a method, apparatus and device for character recognition, so as to improve the accuracy of character recognition.
[0005] According to the first aspect, an embodiment provides a text recognition method, the method comprising:
[0006] Get a picture of a single character to be recognized;
[0007] Input the image into a pre-trained target recognition model to obtain the similarity between the single character to be recognized and each character in the character library;
[0008] Determine the single character to be recognized as the character corresponding to the maximum similarity;
[0009] Wherein, training the target recognition model includes:
[0010] Acquire multiple sample images, wherein each sample image includes a single word;
[0011] Input each sample image into the initial recognition model to obtain a first feature vector of a single character included in each sample image;
[0012] Calculating the similarity between any two of the single characters according to the first feature vector using a cosine distance formula, and summing the obtained multiple similarities to obtain first glyph similarity information;
[0013] Obtaining second glyph similarity information by a preset algorithm, and obtaining similarity loss according to the first glyph similarity information and the second glyph similarity information;
[0014] Determine a combined loss according to the similarity loss and the classification loss, wherein the classification loss is obtained by a preset classification loss function;
[0015] According to the combined loss, adjusting the parameters of the initial recognition model to obtain an updated recognition model;
[0016] For the updated recognition model, iterate the above training process until the combined loss is less than the first preset threshold or the number of iterations is greater than the preset number of training iterations, and take the recognition model corresponding to the combined loss being less than the first preset threshold or the number of iterations being greater than the preset number of training iterations as the target recognition model.
[0017] Optionally, obtaining the second glyph similarity information by a preset algorithm includes:
[0018] Scale any two sample images to the preset size respectively;
[0019] Divide the scaled sample images respectively to obtain the second feature vector of a single character included in each sample image;
[0020] The similarity between any two of the single characters is calculated according to the second feature vector by using the cosine distance formula, and the obtained multiple similarities are summed to obtain the second glyph similarity information.
[0021] Optionally, before scaling any two sample images to preset sizes respectively, the method further includes:
[0022] Any sample image is cropped respectively so that the distance between the single text and the cropped sample image frame is less than a second preset threshold.
[0023] Optionally, the similarity loss is obtained by the following formula:
[0024]
[0025] Where N is the number of sample images, Loss_Sim is the similarity loss, Sim gt is the second glyph similarity information, and Sim_pd is the first glyph similarity information.
[0026] Optionally, the combined loss is obtained by the following formula:
[0027]
[0028] Among them, Loss is the combined loss, and Loss_Cls is the classification loss.
[0029] Optionally, the preset classification loss function is a cross entropy loss function.
[0030] According to the second aspect, an embodiment provides a text recognition device, the device comprising:
[0031] A first acquisition module is used to acquire a picture of a single character to be recognized;
[0032] A second acquisition module is used to input the image into a pre-trained target recognition model to obtain the similarity between the single character to be recognized and each character in the character library;
[0033] A determination module, used for determining the single character to be recognized as the character corresponding to the maximum similarity;
[0034] A training module is used to obtain multiple sample images, each of which includes a single character; input each sample image into an initial recognition model to obtain a first feature vector of the single character included in each sample image; calculate the similarity of any two of the single characters according to the first feature vector through a cosine distance formula, and sum the obtained multiple similarities to obtain first glyph similarity information; obtain second glyph similarity information through a preset algorithm, and obtain similarity loss according to the first glyph similarity information and the second glyph similarity information; determine a combined loss according to the similarity loss and the classification loss, wherein the classification loss is obtained by a preset classification loss function; adjust the parameters of the initial recognition model according to the combined loss to obtain an updated recognition model; iterate the above training process for the updated recognition model until the combined loss is less than a first preset threshold or the number of iterations is greater than a preset training iteration number, and use the recognition model corresponding to the combined loss being less than the first preset threshold or the number of iterations being greater than a preset training iteration number as the target recognition model.
[0035] Optionally, the training module is specifically used to scale any two sample images to preset sizes respectively; divide the scaled sample images respectively to obtain a second feature vector of a single character included in each sample image; calculate the similarity between any two of the single characters according to the second feature vector using a cosine distance formula, and sum the multiple similarities obtained to obtain second glyph similarity information.
[0036] Optionally, the training module is further used to crop any sample image respectively so that the distance between the single text and the cropped sample image frame is less than a second preset threshold.
[0037] Optionally, the similarity loss is obtained by the following formula:
[0038]
[0039] Where N is the number of sample images, Loss_Sim is the similarity loss, Sim gt is the second glyph similarity information, and Sim_pd is the first glyph similarity information.
[0040] Optionally, the combined loss is obtained by the following formula:
[0041]
[0042] Among them, Loss is the combined loss, and Loss_Cls is the classification loss.
[0043] Optionally, the preset classification loss function is a cross entropy loss function.
[0044] According to the third aspect, an embodiment provides an electronic device, comprising: a memory for storing a program; and a processor for implementing the text recognition method described in any one of the first aspects by executing the program stored in the memory.
[0045] According to the fourth aspect, an embodiment provides a computer-readable storage medium, on which a program is stored, and the program can be executed by a processor to implement any of the text recognition methods described in the first aspect.
[0046] The embodiment of the present invention provides a method, device and equipment for character recognition, which obtains a picture of a single character to be recognized; inputs the picture into a pre-trained target recognition model to obtain the similarity between the single character to be recognized and each character in the character library, wherein when training the target recognition model, similarity loss and classification loss are used to determine whether the target recognition model converges, and the similarity loss is determined according to the first glyph similarity information and the second glyph similarity information, the first glyph similarity information is obtained by the target recognition model, the second glyph similarity information is obtained by a preset algorithm, and the classification loss is obtained by a preset classification loss function; the single character to be recognized is determined as the character corresponding to the maximum similarity. Since the loss function of the present invention is composed of two parts, one part is the classification loss obtained by a preset classification loss function, and the other part is the similarity loss for determining the similarity between two characters, and the similarity loss can make the target recognition model focus on the overall structure of the character, thereby improving the accuracy of character recognition. BRIEF DESCRIPTION OF THE DRAWINGS
[0047] Figure 1 A flowchart of a method for training a target recognition model provided by an embodiment of the present invention;
[0048] Figure 2A flowchart of a text recognition method provided by an embodiment of the present invention;
[0049] Figure 3 A schematic diagram of a process for obtaining second glyph similarity information provided by an embodiment of the present invention;
[0050] Figure 4 A schematic diagram of a divided text image provided by an embodiment of the present invention;
[0051] Figure 5 A structural schematic diagram of a text recognition device provided by an embodiment of the present invention. DETAILED DESCRIPTION
[0052] The present invention is further described in detail below by specific embodiments in conjunction with the accompanying drawings. Wherein similar elements in different embodiments adopt associated similar element numbers. In the following embodiments, many detailed descriptions are for making the present application better understood. However, those skilled in the art can easily recognize that some features can be omitted in different situations, or can be replaced by other elements, materials, methods. In some cases, some operations related to the present application are not shown or described in the specification, this is to avoid the core part of the present application being overwhelmed by too much description, and for those skilled in the art, it is not necessary to describe these related operations in detail, and they can fully understand the related operations according to the description in the specification and the general technical knowledge in the art.
[0053] In addition, the features, operations or characteristics described in the specification can be combined in any appropriate manner to form various implementations. At the same time, the steps or actions in the method description can also be interchanged or adjusted in a manner that is obvious to those skilled in the art. Therefore, the various sequences in the specification and the drawings are only for the purpose of clearly describing a certain embodiment and are not meant to be a required sequence, unless otherwise specified that a certain sequence must be followed.
[0054] The serial numbers of the components in this document, such as "first", "second", etc., are only used to distinguish the objects described and do not have any order or technical meaning. The "connection" and "coupling" mentioned in this application, unless otherwise specified, include direct and indirect connections (couplings).
[0055] Since current text recognition algorithms generally directly classify text images through models such as convolutional neural networks, and models such as convolutional neural networks generally use classification loss functions, if only classification loss functions are included, models such as convolutional neural networks tend to focus on local information of text, and are prone to overfitting problems when there are fewer training samples, resulting in low accuracy in text recognition. In order to improve the accuracy of text recognition, the embodiments of the present invention provide a text recognition method, device, and equipment, which are described in detail below. In addition, the execution subject of each of the following methods can be any device with processing capabilities.
[0056] Before introducing the text recognition method provided by the embodiment of the present invention, the training method of the target recognition model is first described. Figure 1 A flow chart of a method for training a target recognition model provided by an embodiment of the present invention is shown in FIG. Figure 1 As shown, the method of the embodiment of the present invention may include:
[0057] S101, obtaining multiple sample images.
[0058] Among them, each sample image only includes a single word.
[0059] S102, input each sample image into an initial recognition model to obtain a first feature vector of a single character included in each sample image.
[0060] In each model training, the output vector of the last hidden layer of the recognition model is the first eigenvector.
[0061] S103, calculating the similarity between any two single characters according to the first eigenvector using a cosine distance formula, and performing a sum operation on the obtained multiple similarities to obtain first glyph similarity information.
[0062] At this point, the first feature vectors of the single characters corresponding to all sample images have been obtained through the recognition model, and the similarity of the characters is calculated by the cosine distance formula, and the sum operation is performed to obtain the first character similarity information.
[0063] S104, obtaining second glyph similarity information through a preset algorithm, and obtaining similarity loss according to the first glyph similarity information and the second glyph similarity information.
[0064] Specifically, the similarity loss can be obtained by the following formula (1):
[0065]
[0066] Among them, N is the number of sample images, Loss_Sim is the similarity loss, Sim_gt is the second glyph similarity information, and Sim_pd is the first glyph similarity information.
[0067] S105, determining the combination loss according to the similarity loss and the classification loss.
[0068] Specifically, the classification loss can be obtained by a preset classification loss function. For example, the preset classification loss function can be a cross entropy loss function. Then, the classification loss can be obtained by the following formula (2):
[0069]
[0070] Among them, Loss_Cls is the classification loss, Y is the true value of the sample, is the predicted value of the sample.
[0071] Specifically, the combined loss is the loss function mentioned above, and the combined loss can be obtained by the following formula (3):
[0072]
[0073] Among them, Loss is the combined loss.
[0074] S106, adjusting the parameters of the initial recognition model according to the combined loss to obtain an updated recognition model.
[0075] S107, for the updated recognition model, iterate the above training process until the combined loss is less than the first preset threshold or the number of iterations is greater than the preset number of training iterations, and use the recognition model corresponding to the combined loss less than the first preset threshold or the number of iterations greater than the preset number of training iterations as the target recognition model.
[0076] The training method of the target recognition model provided by an embodiment of the present invention, since the combined loss of the present invention is composed of two parts, one part is the classification loss obtained by a preset classification loss function, and the other part is the similarity loss for determining the similarity between two characters, and the similarity loss can make the target recognition model pay attention to the overall structure of the text, thereby improving the accuracy of the target recognition model in recognizing the text.
[0077] Figure 2 A flowchart of a text recognition method provided by an embodiment of the present invention is shown in FIG. Figure 2 As shown, the text recognition method provided in this embodiment may include:
[0078] S201, obtaining a picture of a single character to be recognized.
[0079] Optionally, a font file can be used to generate a picture containing only a single character in a preset format, where the preset format needs to clearly distinguish the background and text in the picture. For example, the preset format can be "black text on a white background".
[0080] Optionally, for existing text pictures obtained by handwriting or photographing, the picture background of such text pictures can also be extracted and the picture background can be set to a format that can be clearly distinguished from the text. For example, if the current text is black, the background can be set to white.
[0081] S202: Input the picture into a pre-trained target recognition model to obtain the similarity between the single character to be recognized and each character in the character library. When training the target recognition model, a similarity loss and a classification loss are used to determine the loss function.
[0082] Specifically, through the Figure 1 model training method shown above, the target recognition model of this embodiment can be obtained. The output layer of the target recognition model can output the similarity between the single character to be recognized and each character in the character library.
[0083] S203: Determine the single character to be recognized as the character corresponding to the maximum similarity.
[0084] For example, assume that the character library contains 20,000 characters, and the similarity between the current single character to be recognized and the character "soil" in the character library is the largest. Then, it can be determined that the current single character to be recognized is "soil".
[0085] The text recognition method provided by the embodiments of the present invention includes: obtaining a picture of a single character to be recognized; inputting the picture into a pre-trained target recognition model to obtain the similarity between the single character to be recognized and each character in the character library. When training the target recognition model, a similarity loss and a classification loss are used to determine whether the target recognition model converges. The similarity loss is determined according to the first glyph similarity information and the second glyph similarity information. The first glyph similarity information is obtained through the target recognition model, and the second glyph similarity information is obtained through a preset algorithm. The classification loss is obtained through a preset classification loss function; determining the single character to be recognized as the character corresponding to the maximum similarity. Since the loss function of the present invention consists of two parts, one part is the classification loss obtained through the preset classification loss function, and the other part is the similarity loss for determining the similarity between two characters. The similarity loss can enable the target recognition model to focus on the overall structure of the text, thereby improving the accuracy of text recognition.
[0086] Figure 3 It is a schematic flowchart of a process for obtaining the second glyph similarity information provided by the embodiments of the present invention, as Figure 3 shown, including:
[0087] S301, scaling any two sample images in the same training batch to a preset size respectively.
[0088] The same training batch mentioned above refers to the process of each model training. Figure 1 The sample images of the corresponding embodiments are the same as the sample images of this embodiment. That is, in each model training process, the sample images of the same training batch can be processed by the recognition model to obtain the first glyph similarity information; at the same time, the sample images of the same training batch can also be processed by the preset algorithm to obtain the second glyph similarity information.
[0089] Since the pixels of each sample image obtained may be different, it is necessary to scale the rectangular text image to a x b pixel text image. Among them, a and b can be set according to the actual situation, and it is necessary to ensure that the text can be recognized through the scaled image, for example, a and b are both 100.
[0090] S302, dividing the scaled sample images respectively to obtain a second feature vector of a single character included in each sample image.
[0091] In specific implementation, the text image can be divided into c times d grids. Among them, c and d can be set according to the required recognition accuracy. The larger the c and d are, the more accurate the similarity calculation is, but the more time the calculation takes. Therefore, it can be adjusted according to the actual situation. For example, c and d are both 10, so that the text image is divided into 100 grids. And, if the grid contains non-white pixels, the grid is "1", otherwise it is "0", thereby generating a vector corresponding to the text. Figure 4 As shown, Figure 4Schematic diagrams of the text images corresponding to the divided "big", "too", and "gentleman" respectively. Through the above division, the second feature vector corresponding to the character "big" can be obtained as: 0000110000000011000000001100111111111111000011000000001110000001111000000110110000100001111100000011; the second feature vector corresponding to the character "too" is: 0000110000000011000000001100111111111111000011100000001110000001101100000111111000101101111100000011; the second feature vector corresponding to the character "gentleman" is: 0000110000000011000000001100000000110011111111111100001100000000110000000011000000001101100111111111.
[0092] S303. Through the cosine distance formula, according to the second feature vector, calculate the similarity between any two single characters, and perform a summation operation on the obtained multiple similarities to obtain the second glyph similarity information.
[0093] At this time, the second feature vectors of all single characters corresponding to the sample images have been obtained through the above preset algorithm, and furthermore, the glyph similarities are calculated pairwise through the cosine distance formula and a summation operation is performed to obtain the second glyph similarity information. For example, after dividing the text image into 100 grids, a 100-dimensional second feature vector corresponding to the text is generated. The similarity between two characters x and y is calculated through the cosine distance formula as shown in the following formula (4):
[0094]
[0095] For example, through the above formula (4), it can be obtained that the similarity between "big" and "too" is 0.917; the similarity between "big" and "gentleman" is 0.564.
[0096] Optionally, before the above S301, the above text recognition method may further include: respectively cropping any sample image so that the distance between a single character and the border of the cropped sample image is less than a second preset threshold. For example, assuming the sample image is a black-on-white text image, the white edges around the image can be cropped, which helps to remove redundant background elements in the image.
[0097] Figure 5 Schematic diagram of the structure of a text recognition device provided by an embodiment of the present invention, as Figure 5As shown, the text recognition device 50 may include:
[0098] The first acquisition module 510 may be used to acquire a picture of a single character to be recognized.
[0099] The second acquisition module 520 can be used to input the image into a pre-trained target recognition model to obtain the similarity between the single character to be recognized and each character in the character library.
[0100] The determination module 530 may be used to determine the single character to be recognized as the character corresponding to the maximum similarity.
[0101] The training module 540 can be used to obtain multiple sample images, each of which includes a single character; input each sample image into the initial recognition model to obtain the first feature vector of the single character included in each sample image; calculate the similarity of any two single characters according to the first feature vector through the cosine distance formula, and sum the obtained multiple similarities to obtain the first glyph similarity information; obtain the second glyph similarity information through a preset algorithm, and obtain the similarity loss according to the first glyph similarity information and the second glyph similarity information; determine the combined loss according to the similarity loss and the classification loss, wherein the classification loss is obtained by a preset classification loss function; adjust the parameters of the initial recognition model according to the combined loss to obtain an updated recognition model; iterate the above training process for the updated recognition model until the combined loss is less than the first preset threshold or the number of iterations is greater than the preset number of training iterations, and use the recognition model corresponding to the combined loss being less than the first preset threshold or the number of iterations being greater than the preset number of training iterations as the target recognition model.
[0102] The text recognition device provided by the embodiment of the present invention obtains a picture of a single text to be recognized through a first acquisition module; obtains a trained target recognition model through a training module, wherein when training the target recognition model, similarity loss and classification loss are used to determine whether the target recognition model converges, and the similarity loss is determined according to the first glyph similarity information and the second glyph similarity information, the first glyph similarity information is obtained through the target recognition model, the second glyph similarity information is obtained through a preset algorithm, and the classification loss is obtained through a preset classification loss function; through a second acquisition module, the picture is input into the pre-trained target recognition model to obtain the similarity between the single text to be recognized and each text in the text library; through a determination module, the single text to be recognized is determined as the text corresponding to the maximum similarity. Since the loss function of the present invention is composed of two parts, one part is the classification loss obtained by a preset classification loss function, and the other part is the similarity loss for determining the similarity between two characters, and the similarity loss can make the target recognition model pay attention to the overall structure of the text, thereby improving the accuracy of text recognition.
[0103] Optionally, the above-mentioned training module 540 can be specifically used to scale any two sample images to preset sizes respectively; divide the scaled sample images respectively to obtain the second feature vector of the single text included in each sample image; calculate the similarity between any two single texts according to the second feature vector through the cosine distance formula, and sum up the multiple similarities obtained to obtain the second glyph similarity information.
[0104] Optionally, the training module 540 may also be used to crop any sample image, so that the distance between a single character and the border of the cropped sample image is less than a second preset threshold.
[0105] Optionally, the preset classification loss function may be a cross entropy loss function.
[0106] In addition, corresponding to the text recognition method provided in the above embodiment, an embodiment of the present invention also provides an electronic device, which may include: a memory for storing programs; a processor for implementing all steps of the text recognition method provided in the embodiment of the present invention by executing the programs stored in the memory.
[0107] In addition, corresponding to the text recognition method provided in the above embodiment, the embodiment of the present invention also provides a computer-readable storage medium, in which computer execution instructions are stored. When the computer execution instructions are executed by the processor, all steps of the text recognition method of the embodiment of the present invention are implemented.
[0108] Those skilled in the art will appreciate that all or part of the functions of the various methods in the above-mentioned embodiments can be implemented by hardware or by computer programs. When all or part of the functions in the above-mentioned embodiments are implemented by computer programs, the program can be stored in a computer-readable storage medium, and the storage medium can include: read-only memory, random access memory, disk, optical disk, hard disk, etc., and the program is executed by a computer to implement the above-mentioned functions. For example, the program is stored in the memory of the device, and when the program in the memory is executed by the processor, all or part of the above-mentioned functions can be implemented. In addition, when all or part of the functions in the above-mentioned embodiments are implemented by computer programs, the program can also be stored in a storage medium such as a server, another computer, disk, optical disk, flash disk or mobile hard disk, and can be downloaded or copied and saved in the memory of the local device, or the system of the local device is updated, and when the program in the memory is executed by the processor, all or part of the functions in the above-mentioned embodiments can be implemented.
[0109] The above specific examples are used to illustrate the present invention, which is only used to help understand the present invention and is not intended to limit the present invention. For those skilled in the art, according to the concept of the present invention, some simple deductions, modifications or substitutions can be made.
Claims
1. A text recognition method, It is characterized in that The method comprises: Get a picture of a single character to be recognized; Input the image into a pre-trained target recognition model to obtain the similarity between the single character to be recognized and each character in the character library; Determine the single character to be recognized as the character corresponding to the maximum similarity; Wherein, training the target recognition model includes: Acquire multiple sample images, wherein each sample image includes a single word; Input each sample image into the initial recognition model to obtain a first feature vector of a single character included in each sample image; Calculating the similarity between any two of the single characters according to the first feature vector using a cosine distance formula, and summing the obtained multiple similarities to obtain first glyph similarity information; The second glyph similarity information is obtained by a preset algorithm, and the similarity loss is obtained according to the first glyph similarity information and the second glyph similarity information; wherein the second glyph similarity information is obtained by a preset algorithm, including: Scale any two sample images to the preset size respectively; The scaled sample images are divided respectively to obtain sample images divided into a plurality of grids. If a plurality of grids in the sample image contain non-white pixels, the grid is 1, otherwise, the grid is 0, and the second feature vector of a single character included in each sample image is obtained; Calculating the similarity between any two of the single characters according to the second feature vector using a cosine distance formula, and summing the obtained multiple similarities to obtain second glyph similarity information; Determine a combined loss according to the similarity loss and the classification loss, wherein the classification loss is obtained by a preset classification loss function; According to the combined loss, adjusting the parameters of the initial recognition model to obtain an updated recognition model; For the updated recognition model, iterate the above training process until the combined loss is less than the first preset threshold or the number of iterations is greater than the preset number of training iterations, and use the recognition model corresponding to the combined loss being less than the first preset threshold or the number of iterations being greater than the preset number of training iterations as the target recognition model.
2. The method according to claim 1, It is characterized in that Before scaling any two sample images to preset sizes respectively, the method further includes: Any sample image is cropped respectively so that the distance between the single text and the cropped sample image frame is less than a second preset threshold.
3. The method according to claim 1, It is characterized in that The similarity loss is obtained by the following formula: Wherein, N is the number of sample images, Loss_Sim is the similarity loss, Sim_gt is the second glyph similarity information, and Sim_pd is the first glyph similarity information.
4. The method according to claim 3, It is characterized in that The combined loss is obtained by the following formula: Among them, Loss is the combined loss, Loss_Cls is the classification loss, and Y is the true value of the sample. is the predicted value of the sample.
5. The method according to claim 1, It is characterized in that The preset classification loss function is a cross entropy loss function.
6. A text recognition device, It is characterized in that The device comprises: A first acquisition module, used to acquire a picture of a single character to be recognized; A second acquisition module is used to input the image into a pre-trained target recognition model to obtain the similarity between the single character to be recognized and each character in the character library; A determination module, used for determining the single character to be recognized as the character corresponding to the maximum similarity; A training module is used to obtain multiple sample images, wherein each sample image includes a single character; input each sample image into an initial recognition model to obtain a first feature vector of the single character included in each sample image; calculate the similarity of any two of the single characters according to the first feature vector using a cosine distance formula, and sum the obtained multiple similarities to obtain first glyph similarity information; obtain second glyph similarity information using a preset algorithm, and obtain similarity loss based on the first glyph similarity information and the second glyph similarity information; wherein obtaining the second glyph similarity information using a preset algorithm includes: scaling any two sample images to preset sizes respectively; dividing the scaled sample images respectively to obtain sample images divided into multiple grids, and if multiple grids in the sample image contain non-white pixels , then the grid is 1, otherwise, the grid is 0, and the second feature vector of the single character included in each sample image is obtained; the similarity of any two of the single characters is calculated according to the second feature vector through the cosine distance formula, and the multiple similarities obtained are summed to obtain the second glyph similarity information; according to the similarity loss and the classification loss, the combined loss is determined, wherein the classification loss is obtained by a preset classification loss function; according to the combined loss, the parameters of the initial recognition model are adjusted to obtain an updated recognition model; for the updated recognition model, the above training process is iterated until the combined loss is less than the first preset threshold or the number of iterations is greater than the preset number of training iterations, and the recognition model corresponding to the combined loss being less than the first preset threshold or the number of iterations being greater than the preset number of training iterations is used as the target recognition model.
7. An electronic device, It is characterized in that include: Memory, used to store programs; A processor, configured to implement the method according to any one of claims 1 to 5 by executing the program stored in the memory.
8. A computer-readable storage medium, It is characterized in that The medium stores a program, which can be executed by a processor to implement the method according to any one of claims 1 to 5.
Citation Information
Patent Citations
A method and apparatus for image recognition
CN109241985A
Method for determining user tag and self-coding network training method and device
CN109753608A
Image-text cross-modal retrieval method, system and device and storage medium
CN110059157A
Text image processing method and device
CN110503054A
Character recognition method, device and equipment and storage medium
CN111444907A
