Model training method, apparatus and device
By training a combination of multiple sub-models for recognition, the problem of inaccurate text region recognition in seal images was solved, achieving high-accuracy recognition of seal images.
Patent Information
- Application Number
- CN202210314934.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-03-28
- Publication Date
- 2025-11-18
- Estimated Expiration
- 2042-03-28
AI Technical Summary
Existing text recognition models cannot accurately identify text regions and text boxes in seal images, resulting in low accuracy in seal image recognition.
Multiple sub-models (Text Centerline (TCL) sub-model, Text Edgeline (TML) sub-model, and Text Boundary Offset (TBO) sub-model) are trained and combined with feature extraction and text recognition to identify text and text boxes in seal images from multiple dimensions.
It improves the accuracy of seal image recognition, and can accurately identify text areas and text boxes in seal images.
Smart Images

Figure CN114677680B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the technical field of computer, and particularly relates to a model training method, device and equipment. BACKGROUND
[0002] In actual work, many work files will use a seal to prove the authenticity and regularity of the work files.
[0003] In many scenarios, it is necessary to identify a seal image to determine text included in the seal image and a text box in which the text is located (the text box is used to represent the position of the text in the seal image). In the related art, a conventional text recognition model is usually used to perform text recognition on the seal image. However, since the text in the seal image is usually curvedly distributed and the text distribution is relatively dense, the conventional text recognition model cannot accurately recognize the text region in the seal image, and thus cannot recognize the text in the seal image and the text box in which the text is located, resulting in low accuracy of identifying the seal image. SUMMARY
[0004] Aspects of the present application provide a model training method, device and equipment to improve the accuracy of identifying a seal image.
[0005] In a first aspect, an embodiment of the present application provides a model training method, comprising:
[0006] obtaining a plurality of sample data, the sample data comprising a sample seal image and a label result, the label result comprising: a labeled text and a labeled text box of the sample seal image;
[0007] performing sub-model training according to the plurality of sample data to obtain a text center line TCL sub-model, a text edge line TML sub-model and a text boundary offset TBO sub-model;
[0008] performing model training according to the plurality of sample data to obtain an identification model, the identification model comprising the TCL sub-model, the TML sub-model and the TBO sub-model, and the identification model being used to identify text in a seal image and a text box in which the text is located.
[0009] In a possible implementation, performing sub-model training according to the plurality of sample data to obtain a text center line TCL sub-model, a text edge line TML sub-model and a text boundary offset TBO sub-model comprises:
[0010] training an initial TCL sub-model according to the plurality of sample data to obtain the TCL sub-model;
[0011] According to the plurality of sample data, an initial TML sub-model is trained to obtain the TML sub-model.
[0012] According to the plurality of sample data, an initial TBO sub-model is trained to obtain the TBO sub-model.
[0013] In a possible implementation, according to the plurality of sample data, an initial TCL sub-model is trained to obtain the TCL sub-model, including:
[0014] A sample seal image in the sample data is processed by the initial TCL sub-model to obtain a first TCL feature map, and a pixel value of a pixel point in the first TCL feature map is used to indicate a probability that the pixel point is a text center.
[0015] A text region in the first TCL feature map is contracted inward by a preset proportion to obtain a second TCL feature map, and a pixel value in the text region is greater than or equal to a first threshold value.
[0016] According to the second TCL feature map and a labeled text box in the sample data, a model parameter of the initial TCL sub-model is updated until the TCL sub-model is obtained.
[0017] In a possible implementation, according to the plurality of sample data, an initial TML sub-model is trained to obtain the TML sub-model, including:
[0018] A sample seal image in the sample data is processed by the initial TML sub-model to obtain a first TML feature map, and a pixel value of a pixel point in the first TML feature map is used to indicate a probability that the pixel point is a text box.
[0019] A text box region in the first TML feature map is contracted inward by a preset proportion to obtain a second TML feature map, and a pixel value in the text box region is greater than or equal to a second threshold value.
[0020] According to the second TML feature map and a labeled text box in the sample data, a model parameter of the initial TML sub-model is updated until the TML sub-model is obtained.
[0021] In a possible implementation, according to the plurality of sample data, an initial TBO sub-model is trained to obtain the TBO sub-model, including:
[0022] The sample seal image in the sample data is processed by the initial TBO sub-model to obtain a first TBO feature map, and pixel values of pixel points in the first TBO feature map are used to indicate distances between the pixel points and an upper edge of a text box and distances between the pixel points and a lower edge of the text box.
[0023] According to the first TBO feature map and the labeled text box in the sample data, model parameters of the initial TBO sub-model are updated until the TBO sub-model is obtained.
[0024] In a possible implementation, the recognition model further includes a feature extraction sub-model and a text recognition sub-model.
[0025] According to the plurality of sample data, model training is performed to obtain a recognition model, including:
[0026] According to the TCL sub-model, the TML sub-model and the TBO sub-model, a sample seal image in the sample data is processed to obtain a predicted text box.
[0027] According to the TCL sub-model, the TML sub-model, the feature extraction sub-model and the text recognition sub-model, a sample seal image in the sample data is processed to obtain a predicted text.
[0028] According to the labeled text box in the sample data, the predicted text box, the labeled text in the sample data and the predicted text, model parameters of the recognition model are updated until the recognition model is obtained.
[0029] In a possible implementation, according to the TCL sub-model, the TML sub-model and the TBO sub-model, a sample seal image in the sample data is processed to obtain a predicted text box, including:
[0030] According to the TCL sub-model and the TML sub-model, a sample seal image in the sample data is processed to obtain an approximate binary map (ABM) feature map, and pixel values of each pixel point in the ABM feature map are used to indicate whether the pixel point is a text region or a non-text region.
[0031] The sample seal image in the sample data is processed by the TBO sub-model to obtain a second TBO feature map.
[0032] According to the ABM feature map and the second TBO feature map, a predicted text box is determined.
[0033] In a possible implementation, according to the TCL sub-model, the TML sub-model, the feature extraction sub-model, and the text recognition sub-model, processing a sample seal image in the sample data to obtain predicted text includes:
[0034] According to the TCL sub-model and the TML sub-model, processing a sample seal image in the sample data to obtain an ABM feature map;
[0035] According to the feature extraction sub-model, processing the sample seal image to obtain a seal feature;
[0036] According to the ABM feature map and the seal feature, determining a text region feature;
[0037] Processing the text region feature through the text recognition sub-model to obtain the predicted text.
[0038] In a possible implementation, according to the TCL sub-model and the TML sub-model, processing a sample seal image in the sample data to obtain an ABM feature map includes:
[0039] Processing a sample seal image in the sample data through the TCL sub-model to obtain a third TCL feature map;
[0040] Processing a sample seal image in the sample data through the TML sub-model to obtain a third TML feature map;
[0041] According to the third TCL feature map and the third TML feature map, determining the ABM feature map.
[0042] In a possible implementation, a plurality of sample data is obtained, including:
[0043] Obtaining a plurality of first sample data manually labeled; and,
[0044] According to seal configuration information and a plurality of texts in a corpus, generating a plurality of second sample data;
[0045] The plurality of sample data includes the plurality of first sample data and the plurality of second sample data.
[0046] In a possible implementation, for any one first text in the corpus; according to seal configuration information and the first text, generating second sample data includes:
[0047] According to the seal configuration information, generating a seal frame;
[0048] determine positions of characters in the first text in the seal frame according to the text length of the first text and the seal configuration information;
[0049] fill the first text into the seal frame according to the positions of the characters in the first text in the seal frame, to obtain a background-free seal image;
[0050] obtain a background image, and generate a sample seal image according to the background image and the background-free seal image;
[0051] determine the first text as labeled text of the sample seal image, and determine a labeled text box of the sample seal image according to the positions of the characters in the first text in the seal frame.
[0052] In a possible implementation, the generating of the sample seal image according to the background image and the background-free seal image includes:
[0053] superimposing the background image and the background-free seal image to obtain the sample seal image; or
[0054] superimposing the background image and the background-free seal image to obtain a superimposed image, performing at least one of an erosion operation, a brightness transformation operation, or a seal rotation operation on the superimposed image, to obtain the sample seal image.
[0055] In a second aspect, an embodiment of the present application provides a seal image recognition method, including:
[0056] determining a first seal image;
[0057] processing the first seal image through an identification model, to obtain text included in the first seal image and a text box in which the text is located;
[0058] The identification model is determined according to the method of any one of the first aspect.
[0059] In a third aspect, an embodiment of the present application provides a model training device, including an acquisition module, a first training module, and a second training module, wherein:
[0060] The acquisition module is configured to acquire a plurality of sample data, the sample data including a sample seal image and a labeled result, the labeled result including labeled text and a labeled text box of the sample seal image;
[0061] The first training module is configured to perform sub-model training according to the plurality of sample data, to obtain a text center line TCL sub-model, a text margin line TML sub-model, and a text boundary offset TBO sub-model.
[0062] The second training module is configured to perform model training according to the plurality of sample data to obtain an identification model, the identification model comprising the TCL sub-model, the TML sub-model and the TBO sub-model, and the identification model being configured to identify text in a seal image and a text box in which the text is located.
[0063] In a possible implementation, the first training module is specifically configured to:
[0064] perform training on an initial TCL sub-model according to the plurality of sample data to obtain the TCL sub-model;
[0065] perform training on an initial TML sub-model according to the plurality of sample data to obtain the TML sub-model;
[0066] perform training on an initial TBO sub-model according to the plurality of sample data to obtain the TBO sub-model.
[0067] In a possible implementation, the first training module is specifically configured to:
[0068] perform processing on a sample seal image in the sample data by using the initial TCL sub-model to obtain a first TCL feature map, and a pixel value of a pixel point in the first TCL feature map being used to indicate a probability that the pixel point is a text center;
[0069] perform inward contraction on a text region in the first TCL feature map by a preset proportion to obtain a second TCL feature map, and a pixel value in the text region being greater than or equal to a first threshold value;
[0070] update a model parameter of the initial TCL sub-model according to the second TCL feature map and a labeled text box in the sample data until the TCL sub-model is obtained.
[0071] In a possible implementation, the first training module is specifically configured to:
[0072] perform processing on a sample seal image in the sample data by using the initial TML sub-model to obtain a first TML feature map, and a pixel value of a pixel point in the first TML feature map being used to indicate a probability that the pixel point is a text box;
[0073] perform inward contraction on a text box region in the first TML feature map by a preset proportion to obtain a second TML feature map, and a pixel value in the text box region being greater than or equal to a second threshold value;
[0074] According to the second TML feature map and the labeled text box in the sample data, model parameters of the initial TML sub-model are updated until the TML sub-model is obtained.
[0075] In a possible implementation, the first training module is specifically configured to:
[0076] The sample seal image in the sample data is processed by the initial TBO sub-model to obtain a first TBO feature map, and pixel values of pixel points in the first TBO feature map are used to indicate distances between the pixel points and upper edges of a text box and distances between the pixel points and lower edges of the text box.
[0077] According to the first TBO feature map and the labeled text box in the sample data, model parameters of the initial TBO sub-model are updated until the TBO sub-model is obtained.
[0078] In a possible implementation, the recognition model further includes a feature extraction sub-model and a text recognition sub-model, and the second training module is specifically configured to:
[0079] The sample seal image in the sample data is processed according to the TCL sub-model, the TML sub-model and the TBO sub-model to obtain a predicted text box.
[0080] The sample seal image in the sample data is processed according to the TCL sub-model, the TML sub-model, the feature extraction sub-model and the text recognition sub-model to obtain a predicted text.
[0081] According to the labeled text box in the sample data, the predicted text box, the labeled text in the sample data and the predicted text, model parameters of the recognition model are updated until the recognition model is obtained.
[0082] In a possible implementation, the second training module is specifically configured to:
[0083] The sample seal image in the sample data is processed according to the TCL sub-model and the TML sub-model to obtain an approximate binary map (ABM) feature map, and pixel values of pixel points in the ABM feature map are used to indicate whether the pixel points are text regions or non-text regions.
[0084] The sample seal image in the sample data is processed by the TBO sub-model to obtain a second TBO feature map.
[0085] According to the ABM feature map and the second TBO feature map, a predicted text box is determined.
[0086] In a possible implementation, the second training module is specifically configured to:
[0087] According to the TCL sub-model and the TML sub-model, the sample seal image in the sample data is processed to obtain an ABM feature map;
[0088] According to the feature extraction sub-model, the sample seal image is processed to obtain a seal feature;
[0089] According to the ABM feature map and the seal feature, a text region feature is determined;
[0090] The text region feature is processed by the text recognition sub-model to obtain the predicted text.
[0091] In a possible implementation, the second training module is specifically configured to:
[0092] The sample seal image in the sample data is processed by the TCL sub-model to obtain a third TCL feature map;
[0093] The sample seal image in the sample data is processed by the TML sub-model to obtain a third TML feature map;
[0094] According to the third TCL feature map and the third TML feature map, the ABM feature map is determined.
[0095] In a possible implementation, the obtaining module is specifically configured to:
[0096] Obtain a plurality of first sample data manually labeled; and,
[0097] According to the seal configuration information and a plurality of texts in a corpus, a plurality of second sample data are generated;
[0098] The plurality of sample data include the plurality of first sample data and the plurality of second sample data.
[0099] In a possible implementation, the obtaining module is specifically configured to:
[0100] According to the seal configuration information, a seal frame is generated;
[0101] According to the text length of the first text and the seal configuration information, the positions of characters in the first text in the seal frame are determined;
[0102] According to the positions of the characters in the first text in the seal frame, the first text is filled into the seal frame to obtain a background-free seal image;
[0103] acquire a background image, and generate a sample seal image according to the background image and the seal image without background;
[0104] determine the first text as the labeled text of the sample seal image, and determine a labeled text box of the sample seal image according to positions of characters in the first text in a seal frame.
[0105] In a possible implementation, the acquisition module is specifically configured to:
[0106] superimpose the background image and the seal image without background to obtain the sample seal image; or
[0107] superimpose the background image and the seal image without background to obtain a superimposed image, and perform at least one of an erosion operation, a brightness transformation operation, or a seal rotation operation on the superimposed image to obtain the sample seal image.
[0108] In a fourth aspect, an embodiment of the present application provides a seal image recognition apparatus, comprising a determination module and a processing module, wherein
[0109] The determination module is configured to determine a first seal image.
[0110] The processing module is configured to process the first seal image by using an identification model to obtain text included in the first seal image and a text box in which the text is located; and the identification model is determined according to the method of any one of the first aspect.
[0111] In a fifth aspect, an embodiment of the present application provides an electronic device, comprising a memory and a processor.
[0112] The memory stores computer execution instructions.
[0113] The processor executes the computer execution instructions stored in the memory, so that the processor executes the model training method of any one of the first aspect.
[0114] In a sixth aspect, an embodiment of the present application provides an electronic device, comprising a memory and a processor.
[0115] The memory stores computer execution instructions.
[0116] The processor executes the computer execution instructions stored in the memory, so that the processor executes the seal image recognition method of the second aspect.
[0117] In a seventh aspect, an embodiment of the present application provides a computer readable storage medium, wherein the computer readable storage medium stores computer execution instructions, and the computer execution instructions, when executed by a processor, are used to implement the model training method in any one of the first aspect.
[0118] In an eighth aspect, an embodiment of the present application provides a computer readable storage medium, wherein the computer readable storage medium stores computer execution instructions, and the computer execution instructions, when executed by a processor, are used to implement the model training method in the second aspect.
[0119] In a ninth aspect, an embodiment of the present application provides a computer program product, comprising a computer program, and the computer program, when executed by a processor, implements the model training method in any one of the first aspect.
[0120] In a tenth aspect, an embodiment of the present application provides a computer program product, comprising a computer program, and the computer program, when executed by a processor, implements the seal image recognition method in the second aspect.
[0121] In the embodiment of the present application, the electronic device can obtain a plurality of sample data, and perform sub-model training according to the plurality of sample data to obtain a text center line TCL sub-model, a text edge line TML sub-model, and a text boundary offset TBO sub-model. The electronic device can process a sample seal image in the sample data through the text center line TCL sub-model, the text edge line TML sub-model, and the text boundary offset TBO sub-model to obtain a predicted text box; can process the sample seal image in the sample data through the TCL sub-model, the TML sub-model, a feature extraction sub-model, and a text recognition sub-model to obtain a predicted text, and further, can update model parameters of the recognition model according to a labeled text box in the sample data, the predicted text box, a labeled text in the sample data, and the predicted text, until the recognition model is obtained. Since the plurality of sub-models in the recognition model can identify a text region from different dimensions, the recognition model can accurately identify a text region in a seal image, and further accurately identify a text in the seal image and a text box in which the text is located, so that the accuracy of identifying the seal image can be improved. BRIEF DESCRIPTION OF DRAWINGS
[0122] The accompanying drawings, which are included to provide a further understanding of the present application and constitute a part of this application, illustrate certain illustrative embodiments of the present application and together with the general description of the present application and the detailed description of the illustrative embodiments provided in the specification, serve to explain the principles of the present application. In the drawings:
[0123] Figure 1A A schematic diagram of a double-column character seal provided for the illustrative embodiments of the present application;
[0124] Figure 1BA schematic diagram of a single-column character seal provided for an exemplary embodiment of the present application;
[0125] Figure 2 A schematic diagram of seal image recognition provided for an exemplary embodiment of the present application;
[0126] Figure 3 A schematic diagram of a method for generating sample data provided for an exemplary embodiment of the present application;
[0127] Figure 4A A schematic diagram of a seal frame provided for an exemplary embodiment of the present application;
[0128] Figure 4B A schematic diagram of another seal frame provided for an exemplary embodiment of the present application;
[0129] Figure 5 A schematic diagram of character coordinates provided for an exemplary embodiment of the present application;
[0130] Figure 6 A schematic diagram of a background image provided for an exemplary embodiment of the present application;
[0131] Figure 7 A schematic diagram of a process for producing sample data provided for an exemplary embodiment of the present application;
[0132] Figure 8 A schematic diagram of a model training method provided for an exemplary embodiment of the present application;
[0133] Figure 9A A schematic diagram of a first TCL feature map provided for an exemplary embodiment of the present application;
[0134] Figure 9B A schematic diagram of a first TML feature map provided for an exemplary embodiment of the present application;
[0135] Figure 9C A schematic diagram of a first TBO feature map provided for an exemplary embodiment of the present application;
[0136] Figure 10 A schematic diagram of a method for training a TCL sub-model provided for an exemplary embodiment of the present application;
[0137] Figure 11 A schematic diagram of a process for generating a second TCL feature map provided for an exemplary embodiment of the present application;
[0138] Figure 12 A schematic diagram of a method for training a TML sub-model provided for an exemplary embodiment of the present application;
[0139] Figure 13A schematic diagram illustrating the process of generating a second TML feature map provided for an exemplary embodiment of this application;
[0140] Figure 14 A flowchart illustrating the method for training a TBO sub-model provided in an embodiment of this application;
[0141] Figure 15 A schematic diagram illustrating the process of training a recognition model provided in an exemplary embodiment of this application;
[0142] Figure 16 A schematic diagram of an ABM feature map provided for an exemplary embodiment of this application;
[0143] Figure 17 A schematic diagram of the recognition model provided for an exemplary embodiment of this application;
[0144] Figure 18 A schematic diagram illustrating the process of a seal image recognition method provided for an exemplary embodiment of this application;
[0145] Figure 19 A schematic diagram of the structure of a model training device provided for an exemplary embodiment of this application;
[0146] Figure 20 A schematic diagram of the structure of a seal image recognition device provided for an exemplary embodiment of this application;
[0147] Figure 21 This application provides a schematic diagram of the structure of an electronic device as an exemplary embodiment. Detailed Implementation
[0148] To make the objectives, technical solutions, and advantages of this application clearer, the technical solutions of this application will be clearly and completely described below in conjunction with specific embodiments and corresponding drawings. Obviously, the described embodiments are only a part of the embodiments of this application, and not all of them. Based on the embodiments in this application, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this application.
[0149] This application relates to seals, including two-column text seals and single-column text seals. For ease of understanding, the following describes them in conjunction with... Figures 1A-1B The text provides explanations for both double-column and single-column text seals.
[0150] Figure 1A A schematic diagram of a two-column text seal provided for an exemplary embodiment of this application. Please see below. Figure 1A The double-column text seal includes both upward and downward text. For example, the upward text could be "a certain limited liability company," and the downward text could be "financial seal."
[0151] Figure 1B A schematic diagram of a single-column text seal is provided for the exemplary embodiments of the present application. Please refer to Figure 1B The single-column text seal includes uplink corpus and no downlink corpus. For example, the uplink corpus is "a certain liability limited company".
[0152] In various scenarios, it is necessary to identify the seal image (the image formed by the seal) to identify the text in the seal image and the text box where the text is located. Next, the identification of the seal image is described. Figure 2
[0153] Figure 2 A schematic diagram of identification of the seal image is provided for the exemplary embodiments of the present application. Please refer to Figure 2 Take the seal image of the single-column text seal as an example for description. The seal image includes the text "a certain liability limited company", and each character in the text has a corresponding position in the seal image. The identification model can identify the text and the position of the text in the seal image to obtain the corresponding identification result. As Figure 2 The identification result can include the text identification result and the text box identification result. The text identification result is "a certain liability limited company", and the text box identification result is the text box where the text is located.
[0154] In the related art, a conventional text recognition model is usually used to recognize the text of the seal image. However, since the text in the seal image is usually curvedly distributed and the text distribution is relatively dense, the conventional text recognition model cannot accurately recognize the text region in the seal image, and thus cannot identify the text in the seal image and the text box where the text is located, resulting in low accuracy of identifying the seal image.
[0155] In the embodiments of the present application, the seal image can be identified by the identification model, the identification model includes a plurality of sub-models for identifying the text region, and in the process of training the identification model, the plurality of sub-models can be trained respectively, and after the training of the sub-models is completed, the identification model is trained as a whole. The plurality of sub-models in the identification model can identify the text region from different dimensions, so that the identification model can accurately identify the text region in the seal image, and thus accurately identify the text in the seal image and the text box where the text is located, thereby improving the accuracy of identifying the seal image.
[0156] Next, the technical solutions shown in the present application are described in detail through specific embodiments. It should be noted that the following embodiments can exist independently or in combination. For the same or similar content, it is not repeated in different embodiments.
[0157] Embodiments of the present application relate to a training process of a recognition model and a process of recognizing a seal image by the trained recognition model. In the training process of the recognition model, in order to ensure the richness, sufficiency of the training samples and the convenience of obtaining the training samples, the training samples (sample data) can be automatically generated. For the convenience of understanding, first, the process of generating the sample data is described by taking the seal image of the single-column text seal as an example. Figures 3-7
[0158] Figure 3 The flowchart of the method for generating sample data provided by the exemplary embodiments of the present application is shown. Please refer to Figure 3 The method can include:
[0159] S301, obtaining a first text in a corpus.
[0160] The execution subject of the embodiments of the present application can be an electronic device, or a model training device arranged in the electronic device. The model training device can be realized by software, or realized by the combination of software and hardware. The model training device can be a processor in the electronic device. For the convenience of understanding, in the following, the execution subject is taken as an example of the electronic device.
[0161] The corpus can include an uplink corpus and a downlink corpus. The uplink corpus can include corpora such as companies and enterprises. For example, the uplink corpus can be "a certain liability limited company", "a certain technology limited company", etc. The downlink corpus can include corpora such as department names and special seals. For example, the downlink corpus can be "financial special seal", "personnel special seal", etc.
[0162] The electronic device can read the uplink corpus and the downlink corpus in the corpus to generate the seal image of the double-column text seal, and the first text includes the uplink corpus and the downlink corpus. The electronic device can also read the uplink corpus in the corpus to generate the seal image of the single-column text seal, and the first text includes the uplink corpus.
[0163] After the computer obtains the first text, the length of the first text can be determined. For example, if the first text is "a certain liability limited company", the text length can be 7.
[0164] In the following, the process of generating the sample data of the single-column text seal by the electronic device is described.
[0165] S302, obtaining seal configuration information to generate a seal frame.
[0166] The stamp configuration information can include one or more of the following: a radius of an inner border circle of the stamp and a corresponding line width, a radius of an inner ring circle of the stamp and a corresponding line width, a five-pointed star, and total radians occupied by characters.
[0167] The electronic device can obtain the stamp configuration information and generate a stamp frame according to the stamp configuration information.
[0168] In the following, the stamp frame is described in conjunction with Figures 4A-4B The stamp frame is described in conjunction with
[0169] Figure 4A A schematic diagram of a stamp frame is provided for the exemplary embodiments of the present application. Please refer to Figure 4A The stamp frame includes an inner border circle and a five-pointed star. The radius of the inner border circle can be 2.1 cm and the line width can be 0.1 cm. The diameter of the star tip of the five-pointed star can be 0.8 cm and the total radians occupied by characters can be 150 degrees.
[0170] Figure 4B Another schematic diagram of a stamp frame is provided for the exemplary embodiments of the present application. Please refer to Figure 4B The stamp frame includes an inner border circle and an inner ring circle. The radius of the inner border circle can be 2.0 cm and the line width can be 0.1 cm. The radius of the inner ring circle can be 1.5 cm and the line width can be 0.01 cm. The total radians occupied by characters can be 120 degrees.
[0171] Optionally, after the electronic device generates the stamp frame, the electronic device can also perform an anti-aliasing operation to soften the edges of the stamp frame.
[0172] S303, according to the text length of the first text and the stamp configuration information, determining the positions of the characters in the first text in the stamp frame.
[0173] Optionally, the electronic device can determine the average radians occupied by each character according to the total radians occupied by the characters and the set character gap, dynamically configure the sizes of the characters according to the text length of the first text and the total radians occupied by the characters, and determine the coordinates of each character in the stamp frame according to the sizes of the characters and the average radians occupied by each character, thereby determining the positions of the characters in the first text in the stamp frame.
[0174] For example, if the text length of the first text is "Xinli Zeren Youxian Gongsi" (Xinli Liability Company Limited), there are 7 characters in total. The total radians occupied by the characters in the first text is 150 degrees and the set character gap is 2 degrees, so the average radians occupied by each character can be determined to be about 19.7 degrees.
[0175] The correspondence between text length, total radians occupied by characters, and character size can be preset. The character size can then be determined based on the text length, total radians occupied by characters, and this correspondence. For example, if the text length of the first text is "a certain limited liability company" and the total radians occupied by the characters in the first text are 150 degrees, the character size can be dynamically configured to size 4 (the height of size 4 font is approximately 5mm).
[0176] Below, in conjunction with Figure 5 The coordinates of the characters within the seal frame are explained.
[0177] Figure 5 A schematic diagram of the coordinates of characters provided for an exemplary embodiment of this application. For example... Figure 5 A Cartesian coordinate system can be established within the seal frame. The origin can be the center of the seal frame, represented by "O". The coordinates of the character "X" can include four coordinates: top, bottom, and top. A(1, 1.73) can be the top starting coordinate, B(0.75, 1.30) the bottom starting coordinate, C(1.03, 0.6) the bottom ending coordinate, and D(1.29, 0.75) the top ending coordinate. The angle between OA and OD is the radian area occupied by the character "X". For example, the radian area occupied by the character "X" can be 30°.
[0178] Optionally, a polar coordinate system can be established within the seal frame to determine the coordinates of each character in the polar coordinate system.
[0179] S304. Based on the position of each character in the first text within the seal frame, fill the first text into the seal frame to obtain a seal image without background.
[0180] Once the electronic device can determine the position of each character in the first text within the seal frame, it can fill the corresponding positions of each character in the first text according to the left-to-right text order, thus obtaining a seal image without a background. For example, if the electronic device can determine 7 characters and their corresponding positions, where the order of the characters from left to right is character-1, character-2, character-3, character-4, character-5, character-6, and character-7, and the first text is "a certain liability company", then the electronic device can fill the 7 characters of "a certain liability company" in the positions of character-1, character-2, character-3, character-4, character-5, character-6, and character-7 respectively, according to the left-to-right text order, to obtain a seal image without a background.
[0181] S305. Obtain the background image.
[0182] The electronic device can acquire pictures of files with preset characters in the database, and detect file pictures with the seal and file pictures without the seal through the seal detection network. The electronic device can randomly crop the file pictures without the seal as background images. For example, the preset characters can include "contract", "table", and the like.
[0183] Figure 6 A schematic diagram of a background image is provided for the exemplary embodiments of the present application. As shown in FIG. 4, the background image can include dates, characters, and the like. Figure 6
[0184] S306, determining a sample seal image according to the background seal-free image and the background image.
[0185] The electronic device can determine the sample seal image in the following two ways:
[0186] Method 1, superimposing the background seal-free image and the background image.
[0187] The electronic device can directly superimpose the background seal-free image on the background image to determine the sample seal image.
[0188] The sample seal image generated in this way is usually a relatively regular and clear image.
[0189] Method 2, superimposing the background seal-free image and the background image to obtain a superimposed image, and performing at least one of blurring processing, rotation processing, and the like on the superimposed image.
[0190] In actual processes, there are some abnormal situations in the process of data collection of the seal and the seal image. For example, insufficient force when pressing the seal, insufficient background brightness when sampling, and the like, which can cause the seal image to be relatively blurred.
[0191] In order to make the generated sample seal image more real, the electronic device can directly superimpose the background seal-free image on the background image to obtain a superimposed image, and then the electronic device can perform at least one of blurring processing, rotation processing, and the like on the superimposed image to obtain the sample seal image.
[0192] For example, the electronic device can perform an erosion operation on the superimposed image to simulate the situation that the seal is blurred due to insufficient force when pressing the seal; can perform a brightness change operation on the superimposed image to simulate the situation that the picture is dark due to insufficient background brightness when collecting data; and can use a random rotation operation on the seal to simulate the operation of an abnormal angle when pressing the seal.
[0193] Optionally, when the seal is rotated, the coordinates of the corresponding seal border also need to be rotated. Assuming the image has a length of H and a width of W, and the rotation angle from the image center is β degrees, the original coordinates that need to be transformed are (X, Y). The formula for calculating the coordinates (Xt, Yt) after the coordinate transformation is as follows:
[0194] Xt=X*cos(β)-Y*sin(β)-0.5*W*cos(β)+0.5*H*sin(β)+0.5*W;
[0195] Yt=Y*cos(β)+X*sin(β)-0.5*W*sin(β)-0.5*H*cos(β)+0.5*H.
[0196] S307. The first text is determined as the annotation text of the sample seal image, and the text box where the annotation text is located is determined according to the position of each character in the first text in the seal frame.
[0197] The electronic device can identify the first text as the annotation text of the sample stamp image, and connect the upper and lower starting coordinates in sequence according to the upper and lower starting coordinates of each character in the first text to form a text box, which can then be identified as the text box where the annotation text is located.
[0198] To ensure a certain gap between the characters and the text box, a certain offset can be added to ensure the accuracy of the text box.
[0199] Below, in conjunction with Figure 7 The process of generating sample data is illustrated through specific examples.
[0200] Figure 7 This is a schematic diagram illustrating a process for producing sample data, provided as an exemplary embodiment of this application. Please refer to... Figure 7 It includes process 1, process 2, process 3 and process 4.
[0201] Please refer to process 1. The electronic device can obtain the first text "a certain limited liability company" and seal configuration information, and generate a seal frame based on the seal configuration information. For example... Figure 7 The radius of the inner edge circle of the seal frame can be 2.1cm, and the line width can be 0.1cm; the diameter of the star tip of the five-pointed star can be 0.8cm, and the total arc occupied by the characters can be 150 degrees.
[0202] Please refer to process 2. The electronic device can determine the average radius of each character based on the text length of the first text and the stamp configuration information, dynamically configure the size of each character, and determine the coordinates of each character within the stamp frame, thereby determining the position of each character within the stamp frame. The position of each character within the stamp frame can be represented by coordinates or by the text box corresponding to each character.
[0203] Please see process 3, the electronic device determines the position of each character in the seal frame, and then fills the first text "X Liability Co. Ltd." in the text box to obtain a background-free seal image.
[0204] Please see process 4, the electronic device can determine the first text "X Liability Co. Ltd." as the labeled text of the sample seal image, and connect the coordinates corresponding to each character in the first text to determine the text box where the labeled text is located.
[0205] Please see process 5, the electronic device can obtain a background image, and superimpose the background image and the background-free seal image to generate a superimposed image, and determine the superimposed image as the sample seal image.
[0206] Optionally, the electronic device can also perform blur processing, brightness change operation, rotation operation, etc. on the superimposed image to simulate the actual situation in the process of actually using the seal and collecting data on the seal image.
[0207] In the embodiments of the present application, the electronic device can obtain the first text in the corpus and determine the text length of the first text. The electronic device can obtain the seal configuration information and generate the seal frame according to the seal configuration information. The electronic device can determine the position of each character in the first text in the seal frame according to the text length of the first text and the seal configuration information, and fill the first text in the seal frame to obtain a background-free seal image. The electronic device can obtain a background image and superimpose the background-free seal image and the background image to determine a sample seal image. The electronic device can determine the first text as the labeled text of the sample seal image, and determine the text box where the labeled text is located according to the position of each character in the first text in the seal frame. Since the electronic device can generate a sample seal image according to the first text and the seal configuration information, and determine the labeled result of the sample seal image, manual labeling of a large amount of sample data is avoided, and therefore the efficiency of obtaining sample data can be improved.
[0208] On the basis of any one of the above embodiments, the following will be combined Figure 8 - Figure 9, the training process of the recognition model is described.
[0209] Figure 8 A flowchart of a model training method provided by an exemplary embodiment of the present application is shown. Please see Figure 8 , the method can include:
[0210] S801, obtaining a plurality of sample data.
[0211] The sample data can include sample seal images and labeled results. The labeled results can include labeled texts and labeled text boxes of the sample seal images.
[0212] The plurality of sample data can include artificially annotated first sample data and generated second sample data. The electronic device can obtain the seal image in the database, and obtain the first sample data through artificial annotation; the process of generating the second sample data can be referred to Figure 3 , which will not be described here.
[0213] S802, according to the plurality of sample data, the sub-model training is carried out, and the text center line (TCL) sub-model, the text margin line (TML) sub-model and the text border offset (TBO) sub-model are obtained.
[0214] The electronic device can train the initial TCL sub-model according to the plurality of sample data to obtain the TCL sub-model. The sample seal image in the sample data can be processed through the TCL sub-model to obtain a first TCL feature map. The first TCL feature map includes a plurality of pixel points, each pixel point has a corresponding pixel value, and the pixel value is used to indicate the probability that the pixel point is the text center. The first TCL feature map includes a text region and a non-text region, wherein the pixel value of the pixel point in the text region is greater than or equal to a first threshold value, and the pixel value of the pixel point in the non-text region is less than the first threshold value. For example, the first threshold value can be set to 0.2, and the electronic device can determine that the pixel point with a pixel value greater than or equal to 0.2 belongs to the text region, and the pixel point with a pixel value less than 0.2 belongs to the non-text region.
[0215] The electronic device can train the initial TML sub-model according to the plurality of sample data to obtain the TML sub-model. The sample seal image in the sample data can be processed through the TML sub-model to obtain a first TML feature map. The first TML feature map includes a plurality of pixel points, each pixel point has a corresponding pixel value, and the pixel value is used to indicate the probability that the pixel point is the text box. The first TML feature map includes a text box region and a non-text box region, wherein the pixel value of the pixel point in the text box region is greater than or equal to a second threshold value, and the pixel value of the pixel point in the non-text box region is less than the second threshold value. For example, the second threshold value can be set to 0.2, and the electronic device can determine that the pixel point with a pixel value greater than or equal to 0.2 belongs to the text box region, and the pixel point with a pixel value less than 0.2 belongs to the non-text box region.
[0216] The electronic device can train the initial TBO sub-model according to the plurality of sample data to obtain the TBO sub-model. The sample seal image in the sample data can be processed by the TBO sub-model to obtain a first TBO feature map. The first TBO feature map includes a plurality of pixel points, and each pixel point has a corresponding pixel value, which is used to indicate the distance between the pixel point and the upper edge of the text box and the distance between the pixel point and the lower edge of the text box.
[0217] In the following, the first TCL feature map, the first TML feature map and the first TBO feature map are described respectively. Figures 9A-9C
[0218] A schematic diagram of the first TCL feature map provided by the exemplary embodiments of the present application is shown in FIG. 6. Referring to FIG. 6, if the electronic device can determine that the labeled text in the sample seal image includes “company, group”, wherein “company” belongs to the first line of characters, “group” belongs to the second line of characters, and the positions of “company” and “group” are as shown in FIG. 6, for the convenience of description, the part of the image in the sample seal image including the “company, group” text is taken as an example for description. Figure 9A Figure 9A As shown in FIG. 6, if the first threshold value is set to 0.2, the electronic device can determine the text region corresponding to “company”. The pixel value corresponding to the pixel point at the center of the text is 1. From the center of the text to the periphery of the text, the pixel value corresponding to the pixel point gradually decreases and is between 0.2 and 1, respectively. For example, the pixel points at the periphery of “company” are 0.9, 0.8, 0.7, 0.6, 0.5, 0.3, 0.2, etc. The pixel value corresponding to the pixel point in the non-text region can be 0-0.1. Figure 9A Similarly, the electronic device can determine the text regions corresponding to “company” and “group”. The pixel value corresponding to the pixel point at the center of the text is 1. The pixel value corresponding to the pixel point at the periphery of the text can be 0.9, 0.8, 0.7, 0.6, 0.5, 0.3, 0.2, etc. The pixel value corresponding to the pixel point in the non-text region can be 0-0.1.
[0219] Figure 9A A schematic diagram of the first TML feature map provided by the exemplary embodiments of the present application is shown in FIG. 7. Referring to FIG. 7, if the electronic device can determine that the labeled text box in the sample seal image includes text box 1 and text box 2, and the positions of text box 1 and text box 2 are as shown in FIG. 7, for the convenience of description, the part of the image in the sample seal image is taken as an example for description.
[0220]
[0221] Figure 9B A schematic diagram of the first TML feature map provided by the exemplary embodiments of the present application is shown in FIG. 7. Referring to FIG. 7, if the electronic device can determine that the labeled text box in the sample seal image includes text box 1 and text box 2, and the positions of text box 1 and text box 2 are as shown in FIG. 7, for the convenience of description, the part of the image in the sample seal image is taken as an example for description. Figure 9B Figure 9B
[0222] If the second threshold value is set as 0.2, the electronic device can determine the text box area corresponding to the text box 1. The pixel value corresponding to the pixel points gradually decreases from the text box to the surrounding of the text box, and is between 0.2 and 1, respectively. For example, the pixel value of the pixel points corresponding to the text box 1 can be 0.9, 0.8, 0.7, 0.6, 0.5, 0.2, and the like. The pixel value corresponding to the pixel points in the non-text box area is 0-0.1.
[0223] Similarly, the electronic device can determine the text box area corresponding to the text box 2, and the corresponding pixel value can be 0.9, 0.8, 0.7, 0.6, 0.5, 0.2, and the like. The pixel value corresponding to the pixel points in the non-text box area is 0-0.1.
[0224] Due to the need for drawing, the size of the pixel point is large, and the line of the text box is not enough to cover the entire pixel point. In actual work, the pixel point is small, and the line of the text box can cover multiple pixel points. For the pixel points completely covered by the line of the text box, the corresponding pixel value can be 1.
[0225] Figure 9C The schematic diagram of the first TBO feature map provided for the exemplary embodiments of the present application. For the convenience of description, part of the image in the sample seal image is used for illustration.
[0226] Please refer to Figure 9C If the electronic device can determine that the labeled text in the sample seal image includes “public”, and the corresponding labeled text box is text box 1, the electronic device can determine a plurality of pixel points corresponding to “public”, and determine the distance between each pixel point and the upper edge of the text box 1, and the distance between the pixel point and the lower edge of the text box 1. The distance can be represented by a pixel value. As shown in Figure 9C The electronic device can determine that the distance between point a and the upper edge of the text 1 is 10px, and the distance between point a and the lower edge of the text box 1 is 8px.
[0227] S803, model training is performed according to the plurality of sample data to obtain a recognition model.
[0228] The recognition model includes a TCL sub-model, a TML sub-model, and a TBO sub-model, and can also include a feature (Feature) extraction sub-model and a text recognition sub-model. The recognition model can be used to identify the text in the seal image and the text box where the text is located.
[0229] The electronic device can process the sample seal image in the sample data through the TCL sub-model, the TML sub-model, and the TBO sub-model to obtain a predicted text box; and can also process the sample seal image in the sample data through the TCL sub-model, the TML sub-model, the feature extraction sub-model, and the text recognition sub-model to obtain a predicted text.
[0230] After acquiring the predicted text boxes and predicted text, the computer can compare the predicted text boxes with the labeled text boxes in the sample data to obtain the comparison results; it can also compare the predicted text with the labeled text in the sample data to obtain the comparison results. Based on the comparison results of the text boxes and the text, the electronic device can update the model parameters of the recognition model until the recognition model is obtained.
[0231] In this embodiment, the electronic device can acquire multiple sample data and train sub-models based on these sample data to obtain TCL, TML, and TBO sub-models. Then, it performs overall training using the sample data to obtain a recognition model. This recognition model can be used to identify text in a seal image and the text boxes containing that text. Because the multiple sub-models in the recognition model can identify text regions from different dimensions, the model can accurately identify text regions in the seal image, thereby accurately identifying the text in the seal image and the text boxes containing that text, thus improving the accuracy of seal image recognition.
[0232] Based on any of the above embodiments, during the training of the recognition model, it is necessary to first train the TCL sub-model, TML sub-model, and TBO sub-model within the recognition model. The training methods for the sub-models differ depending on their specific characteristics. The results are as follows. Figures 10-14 The process of training the sub-model is explained.
[0233] Figure 10 This is a flowchart illustrating a method for training a TCL sub-model provided as an exemplary embodiment of this application. Please refer to [link / reference]. Figure 10 The method may include:
[0234] S1001. The sample stamp image in the sample data is processed through the initial TCL sub-model to obtain the first TCL feature map.
[0235] Optionally, the sample data may include manually labeled first sample data and generated second sample data, and the number of first sample data and the number of second sample data can be the same.
[0236] For any given training iteration, the initial TCL sub-model processes the sample stamp image to obtain the first TCL feature map. The first TCL feature map includes multiple pixels, and the pixel value indicates the probability that the pixel is the center of the text. For a detailed introduction to the first TCL feature map, please refer to [link to documentation]. Figure 9A This will not be elaborated upon here.
[0237] During the first iteration of training, the initial TCL sub-model refers to the untrained TCL sub-model.
[0238] In the i-th (greater than or equal to 2) iteration of training, the initial TCL sub-model refers to the TCL sub-model obtained after the previous iteration. For example, in the 2nd iteration of training, the initial TCL sub-model refers to the TCL sub-model obtained after the 1st iteration of training; in the 3rd iteration of training, the initial TCL sub-model refers to the TCL sub-model obtained after the 2nd iteration of training.
[0239] S1002. Shrink the text region in the first TCL feature map inward by a preset ratio to obtain the second TCL feature map.
[0240] Since the text in the sample stamp image is usually curved and the text distribution is relatively dense, the text areas in the first TCL feature map may overlap or stick together, making it difficult to identify the text area corresponding to each character. Therefore, the text area of the first TCL feature map can be shrunk inward by a preset ratio so that the text areas of each character can be distinguished.
[0241] Below, in conjunction with Figure 11 The second TCL feature map will be introduced.
[0242] Figure 11 This is a schematic diagram illustrating the process of generating a second TCL feature map, provided for an exemplary embodiment of this application. Please refer to [link / reference]. Figure 11 It includes the first TCL feature map and the second TCL feature map.
[0243] like Figure 11 Electronic devices can identify regions with pixel values greater than 0.2 as text regions. It can be seen in the first TCL feature map that the text regions for "Company" and "Group" are partially merged and indistinguishable.
[0244] After shrinking the first TCL feature map by a preset ratio, the second TCL feature map can be obtained. It can be seen that the text regions corresponding to "Company" and "Group" are reduced. A pixel with a value of 0 appears between "Company" and "Group," indicating that the TCL sub-model can distinguish the text regions corresponding to "Company" and "Group," facilitating TCL sub-model recognition.
[0245] S1003. Update the model parameters of the initial TCL sub-model based on the second TCL feature map and the labeled text boxes in the sample data.
[0246] After the electronic device acquires the second TCL feature map, it can compare the second TCL feature map with the labeled text boxes in the sample data to obtain the first loss function, and update the model parameters of the initial TCL sub-model according to the first loss function.
[0247] S1004. Determine whether the TCL sub-model has converged.
[0248] If so, then execute S1005.
[0249] If not, then execute S1001.
[0250] Optionally, if the value of the first loss function obtained in the multiple iterations prior to the current iteration is less than or equal to the first preset threshold, and the value of the first loss function remains stable, then the TCL sub-model can be determined to have converged.
[0251] S1005. The TCL sub-model with updated model parameters is identified as the trained TCL sub-model.
[0252] In this embodiment, the electronic device can process the sample stamp image in the sample data using an initial TCL sub-model to obtain a first TCL feature map, and then shrink the text region in the first TCL feature map inward by a preset ratio to obtain a second TCL feature map. The electronic device can update the model parameters of the initial TCL sub-model based on the second TCL feature map and the labeled text boxes in the sample data. If the TCL sub-model is in a convergent state, the TCL sub-model with updated model parameters can be determined as the trained TCL sub-model; if the TCL sub-model is not in a convergent state, iterative training can continue until the TCL sub-model is in a convergent state to determine the trained TCL sub-model. During the training of the TCL sub-model, manually labeled first sample data and generated second sample data are used. The rich and comprehensive sample data ensures the accuracy of the trained TCL sub-model. Furthermore, the text region in the first TCL feature map output by the TCL sub-model is shrunk inward by a preset ratio to ensure the accuracy of the identified text region, further improving the accuracy of the trained TCL sub-model and enhancing the accuracy of the TCL sub-model in recognizing text regions.
[0253] Figure 12 This is a flowchart illustrating a method for training a TML sub-model provided as an exemplary embodiment of this application. Please refer to [link / reference]. Figure 12 The method may include:
[0254] S1201. The sample stamp images in the sample data are processed through the initial TML sub-model to obtain the first TML feature map.
[0255] Optionally, the sample data may include manually labeled first sample data and generated second sample data, and the number of first sample data and the number of second sample data can be the same.
[0256] For any given training iteration, the initial TML sub-model processes the sample stamp image to obtain the first TML feature map. The first TML feature map includes multiple pixels, and the pixel value indicates the probability that the pixel is a text box. For a detailed introduction to the first TML feature map, please refer to [link to documentation]. Figure 9B This will not be elaborated upon here.
[0257] During the first iteration of training, the initial TML sub-model refers to the TML sub-model that has not been trained.
[0258] In the nth (greater than or equal to 2) iteration of training, the initial TML sub-model refers to the TML sub-model obtained after the previous iteration. For example, in the second iteration of training, the initial TML sub-model refers to the TML sub-model obtained after the first iteration of training; in the third iteration of training, the initial TML sub-model refers to the TML sub-model obtained after the second iteration of training.
[0259] S1202. Shrink the text box area in the first TML feature map inward by a preset ratio to obtain the second TML feature map.
[0260] Since the text in the sample stamp image is usually densely distributed, the text box areas may stick together in the first TML feature map, making it difficult for the TML sub-model to identify each text box. Therefore, the text box area of the first TML feature map can be shrunk inward by a preset ratio so that each text box area can be distinguished, making it easier for the TML sub-model to identify.
[0261] Below, in conjunction with Figure 13 The second TML feature map will be introduced.
[0262] Figure 13 This is a schematic diagram illustrating the process of generating a second TML feature map, provided for an exemplary embodiment of this application. Please refer to [link / reference]. Figure 13 This includes the first TML feature map and the second TML feature map.
[0263] like Figure 13 Electronic devices can identify regions with pixel values greater than 0.2 as text box regions. It can be seen that in the first TML feature map, the regions of text box 1 and text box 2 are partially overlapped and cannot be distinguished.
[0264] After shrinking the first TML feature map by a preset ratio, the second TML feature map can be obtained. It can be seen that the regions of text box 1 and text box 2 are reduced in size. A pixel with a value of 0 appears between the regions of text box 1 and text box 2, indicating that the TML sub-model can distinguish between the regions of text box 1 and text box 2, facilitating TML sub-model recognition.
[0265] S1203. Update the model parameters of the initial TML sub-model based on the second TML feature map and the labeled text boxes in the sample data.
[0266] After the electronic device acquires the second TML feature map, it can compare the second TML feature map with the labeled text boxes in the sample data to obtain the second loss function, and update the model parameters of the initial TML sub-model according to the second loss function.
[0267] S1204. Determine whether the TML sub-model has converged.
[0268] If so, then execute S1205.
[0269] If not, then execute S1201.
[0270] Optionally, if the value of the second loss function obtained in the multiple iterations prior to the current iteration is less than or equal to the second preset threshold, and the value of the second loss function remains stable, then the TML sub-model can be determined to have converged.
[0271] S1205. The TML sub-model with updated model parameters is identified as the trained TML sub-model.
[0272] In this embodiment, the electronic device can process the sample stamp image in the sample data using an initial TML sub-model to obtain a first TML feature map. The text box region in the first TML feature map is then shrunk inward by a preset ratio to obtain a second TML feature map. The electronic device can update the model parameters of the initial TML sub-model based on the second TML feature map and the labeled text boxes in the sample data. If the TML sub-model is converged, the TML sub-model with updated model parameters can be identified as the trained TML sub-model. If the TML sub-model is non-converged, iterative training can continue until the TML sub-model is converged, thus identifying the trained TML sub-model. During the training of the TML sub-model, manually labeled first sample data and generated second sample data are used. The rich and comprehensive sample data ensures the accuracy of the trained TML sub-model. Furthermore, the text region in the first TML feature map output by the TML sub-model is shrunk inward by a preset ratio to ensure the accuracy of the identified text region, further improving the accuracy of the trained TML sub-model and enhancing the accuracy of the TML sub-model in recognizing text box regions.
[0273] Figure 14 This is a flowchart illustrating the method for training a TBO sub-model provided in an embodiment of this application. Please refer to [link / reference]. Figure 14 The method may include:
[0274] S1401. The sample stamp images in the sample data are processed through the initial TBO sub-model to obtain the first TBO feature map.
[0275] Optionally, the sample data may include manually labeled first sample data and generated second sample data, and the number of first sample data and the number of second sample data can be the same.
[0276] For any given training iteration, the initial TBO sub-model processes the sample stamp image to obtain the first TBO feature map. The first TBO feature map includes multiple pixels, where the pixel value indicates the distance between the pixel and the top edge of the text box, and the distance between the pixel and the bottom edge of the text box. For a detailed introduction to the first TBO feature map, please refer to [link to relevant documentation]. Figure 9C This will not be elaborated upon here.
[0277] During the first iteration of training, the initial TBO sub-model refers to the untrained TBO sub-model.
[0278] In the m-th (greater than or equal to 2)-th iteration of training, the initial TBO sub-model refers to the TBO sub-model obtained after the previous iteration. For example, in the 2nd iteration of training, the initial TBO sub-model refers to the TBO sub-model obtained after the 1st iteration of training; in the 3rd iteration of training, the initial TBO sub-model refers to the TBO sub-model obtained after the 2nd iteration of training.
[0279] S1402. Update the model parameters of the initial TBO sub-model based on the first TBO feature map and the labeled text boxes in the sample data.
[0280] After the electronic device acquires the first TBO feature map, it can compare the first TBO feature map with the labeled text boxes in the sample data to obtain the third loss function, and update the model parameters of the initial TBO sub-model according to the third loss function.
[0281] S1403. Determine whether the TBO sub-model has converged.
[0282] If so, then execute S1404.
[0283] If not, then execute S1401.
[0284] Optionally, if the value of the third loss function obtained in the multiple iterations prior to the current iteration is less than or equal to the third preset threshold, and the value of the third loss function remains stable, then the TBO sub-model can be determined to have converged.
[0285] S1404. The TBO sub-model with updated model parameters is identified as the trained TBO sub-model.
[0286] In this embodiment, the electronic device can process the sample stamp image in the sample data using an initial TBO sub-model to obtain a first TBO feature map. The electronic device can update the model parameters of the initial TBO sub-model based on the first TBO feature map and the labeled text boxes in the sample data. If the TBO sub-model is in a convergent state, the TBO sub-model with updated model parameters can be identified as the trained TBO sub-model; if the TBO sub-model is not in a convergent state, iterative training can continue until the TBO sub-model is in a convergent state, thus identifying the trained TBO sub-model. During the training of the TBO sub-model, manually labeled first sample data and generated second sample data are used. The rich and comprehensive sample data ensures the accuracy of the trained TBO sub-model and improves the accuracy of the TBO sub-model in recognizing text regions.
[0287] After the electronic device has completed training the TCL sub-model, TML sub-model, and TBO sub-model, it can then train the overall recognition model based on the sample data. Below, we will combine...Figures 15-16 The training method and the recognition model are explained.
[0288] Figure 15 This is a schematic diagram illustrating the process of training a recognition model provided for an exemplary embodiment of this application. Please refer to [link / reference]. Figure 15 The method may include:
[0289] S1501. Based on the TCL sub-model and TML sub-model, the sample stamp images in the sample data are processed to obtain the approximate binary ABM feature map.
[0290] In one optional embodiment, the electronic device can process the sample stamp image in the sample data using the trained TCL sub-model to obtain a third TCL feature map; it can also process the sample stamp image in the sample data using the trained TML sub-model to obtain a third TML feature map, and obtain an ABM feature map based on the third TCL feature map and the third TML feature map.
[0291] For a detailed introduction to the third TCL feature map, please refer to [link / reference]. Figure 11 The second TCL feature map is not described in detail here. For a detailed introduction to the third TCL feature map, please refer to [link to relevant documentation]. Figure 13 The second TML feature map in the image will not be described further here.
[0292] ABM feature maps can be approximate binary maps, where pixel values can be 0 or 1, indicating whether a pixel belongs to a text region or a non-text region. Pixels in text regions have a value of 1, while pixels in non-text regions have a value of 0. Compared to the third TCL feature map, the ABM feature map removes some non-text regions, making the text regions more precise, thus optimizing the third TCL feature map.
[0293] Below, in conjunction with Figure 16 The ABM feature map will be explained.
[0294] Figure 16 This is a schematic diagram of an ABM feature map provided for an exemplary embodiment of this application. Please refer to... Figure 16 If the electronic device can determine that the labeled text in the sample seal image includes "Company" and "Group", for ease of description, we will use a partial image of the sample seal image that includes the text "Company" and "Group" as an example.
[0295] like Figure 16 The ABM feature map includes text regions corresponding to "Company" and "Group". The electronic device can identify the text regions corresponding to "Company" and "Group". Pixels within the text regions have a value of 1, while pixels outside the text regions have a value of 0.
[0296] S1502. The sample stamp images in the sample data are processed by the TBO sub-model to obtain the second TBO feature map.
[0297] Electronic devices can process the sample stamp images in the sample data using the trained TBO sub-model to obtain a second TBO feature map. The pixel values of the pixels in the second TBO feature map can be used to indicate the distance between the pixel and the top edge of the text box, and the distance between the pixel and the bottom edge of the text box.
[0298] For a detailed introduction to the second TBO feature map, please refer to [link / reference]. Figure 9C The first TBO feature map in the image will not be described in detail here.
[0299] S1503. Determine the predicted text box based on the ABM feature map and the second TBO feature map.
[0300] Electronic devices can calculate the distance between the corresponding pixel and the top and bottom edges of the text box based on the ABM feature map and the second TBO feature map, thereby accurately determining the position of the top and bottom edges of the text box and thus determining the predicted text box.
[0301] S1504. Process the sample seal image according to the feature extraction sub-model to obtain seal features.
[0302] Electronic devices can perform feature extraction processing on sample seal images through a feature extraction sub-model to determine seal features.
[0303] S1505. Determine the text region features based on the ABM feature map and the seal features.
[0304] Electronic devices can expand the ABM feature map outward by a preset ratio to obtain a mask for the text region. Then, based on the text region mask and the seal features, the text region features in the sample seal image are determined. For example, the electronic device can multiply the seal features by the text region mask to obtain the text region features. These text region features can include textual features. The removal of interference from other regions in the text region features is beneficial for training the recognition model.
[0305] S1506. The text region features are processed by the text recognition sub-model to obtain the predicted text.
[0306] Electronic devices can use a text recognition sub-model to identify and process text region features to obtain predicted text in a sample stamp image.
[0307] The text in the sample stamp image is usually curved. When recognizing curved text, the text recognition sub-model can choose functions including one-dimensional Connectionist Temporal Classification (CTC Loss) and two-dimensional (2D) CTC Loss.
[0308] If the text recognition sub-model uses a one-dimensional CTC Loss, the text needs to be forcibly converted into one dimension. This compressed text will be distorted and deformed, which is not conducive to text recognition. Therefore, the text recognition sub-model can use a two-dimensional (2D) CTC Loss to constrain text recognition and recognize curved text.
[0309] S1507. Update the model parameters of the recognition model based on the labeled text boxes, predicted text boxes, labeled text, and predicted text in the sample data.
[0310] The annotation text and annotation text boxes in the sample data are determined when the sample data is generated. For details, please refer to [link / reference needed]. Figure 3 This will not be elaborated further here.
[0311] For any given training iteration, after the electronic device acquires the predicted text boxes and predicted text of the sample stamp images in the sample data, it can compare the predicted text boxes with the labeled text boxes to obtain the comparison results; it can also compare the predicted text with the labeled text to obtain the comparison results. The electronic device can then update the model parameters of the recognition model based on the comparison results of the text boxes and the text.
[0312] S1508. Determine whether the recognition model has converged.
[0313] If so, then execute S1509.
[0314] If not, then execute S1501.
[0315] S1509. The recognition model with updated model parameters is determined as the trained recognition model.
[0316] Electronic devices can perform multiple end-to-end trainings on the recognition model and calibrate the model based on the training results to obtain an accurate recognition model.
[0317] In this embodiment, the electronic device can process the sample stamp image using the TCL sub-model and TML sub-model to obtain the ABM feature map. The electronic device can also process the sample stamp image using the TBO sub-model to obtain the second TBO feature map, and determine the predicted text box based on the ABM feature map and the second TBO feature map. Furthermore, it can process the sample stamp image using the feature extraction sub-model to obtain stamp features, and determine the text region features based on the ABM feature map and the stamp features. Then, it can process the text region features using the text recognition sub-model to obtain the predicted text. The electronic device can update the model parameters of the recognition model based on the labeled text boxes, predicted text boxes, labeled text, and predicted text in the sample data. If the recognition model is in a convergent state, the updated recognition model can be identified as the trained recognition model; if the recognition model is not in a convergent state, iterative training can continue until the recognition model is in a convergent state to identify the trained recognition model. Because electronic devices can identify text regions in sample stamp images from different dimensions by recognizing multiple sub-models in the recognition model, the recognition model can accurately identify text regions in stamp images, and thus accurately identify the text in stamp images and the text boxes in which the text is located, thereby improving the accuracy of stamp image recognition.
[0318] Below, in conjunction with Figure 17 This paper presents a schematic diagram of the structure of a recognition model through a specific example.
[0319] Figure 17 A schematic diagram of the recognition model provided for an exemplary embodiment of this application. Please refer to... Figure 17 The recognition model can include a preprocessing module, a TCL sub-model, a TML sub-model, a TBO sub-model, a feature extraction sub-model, and a text recognition sub-model.
[0320] Assume the input sample stamp image has a length of h, a width of w, and 3 channels. Electronic devices can preprocess the input sample stamp image. For example, the electronic device can first process the input sample stamp image using a Residual Network-50 (ResNet-50).
[0321] Specifically, the ResNet-50 network can include downsampling and upsampling. Downsampling can include convolution stage 1, convolution stage 2, convolution stage 3, and convolution stage 4, while upsampling can include deconvolution stage 1, deconvolution stage 2, and deconvolution stage 3.
[0322] First, the electronic device can input the sample stamp image (h×w×3) into the pooling stage for pooling to obtain the pooled image. The pooling stage uses a 7×7 convolution kernel, has 64 kernels, and a stride of 2.
[0323] Then, the electronic device can process the pooled image through convolution stage 1, convolution stage 2, convolution stage 3, and convolution stage 4. Specifically, convolution stage 1 has a 3×3 kernel, 64 kernels, and a stride of 2; convolution stage 2 has a 3×3 kernel, 128 kernels, and a stride of 2; convolution stage 3 has a 3×3 kernel, 256 kernels, and a stride of 2; and convolution stage 4 has a 3×3 kernel, 512 kernels, and a stride of 2.
[0324] Next, the electronic device can process the output image of convolution stage 4 through deconvolution stage 1, deconvolution stage 2, and deconvolution stage 3. Specifically, deconvolution stage 1 has a 3×3 kernel, 512 kernels, and a stride of 2; deconvolution stage 2 has a 3×3 kernel, 256 kernels, and a stride of 2; and deconvolution stage 3 has a 3×3 kernel, 128 kernels, and a stride of 2.
[0325] Electronic devices can perform feature extraction on sample stamp images through the above processing to obtain multiple feature maps corresponding to the sample stamp images. The size of the first feature map input to the TBO sub-model is... The dimension is 4; the size of the second feature map input to the TCL sub-model is... The dimension is 2; the size of the third feature map input to the TML sub-model is... The dimension is 2; the size of the fourth feature map input to the feature extraction sub-model is... The dimension is 128. The size of each of these feature maps is one-quarter the size of the sample stamp image. Reducing the size of the feature maps helps to decrease the computational cost of subsequent multi-task learning.
[0326] After the electronic device has completed the preprocessing of the sample stamp image, it can continue to process it through multiple sub-models.
[0327] The electronic device can freeze the feature extraction sub-model and the text recognition sub-model, and then train the TCL sub-model, TML sub-model, and TBO sub-model respectively based on these multiple feature maps. The electronic device can process the corresponding feature maps through the TCL sub-model, TML sub-model, and TBO sub-model respectively to obtain the corresponding TCL feature map, TML feature map, and TBO feature map.
[0328] Electronic devices can determine the ABM feature map based on the TCL feature map and TML feature map, and determine the text detection box of the sample stamp image based on the TBO feature map and ABM feature map.
[0329] The ABM feature map can be enlarged by a preset ratio to obtain a mask for the text region. The electronic device can unfreeze the feature extraction sub-model and the text recognition sub-model, obtaining the seal features of the sample seal image through the feature extraction sub-model. The electronic device can multiply the mask and the seal features to determine the text region features, and then use the text recognition sub-model to recognize these features to determine the text annotations of the sample seal image.
[0330] Electronic devices can iteratively update the model parameters of the recognition model based on the text detection box and text annotation of the sample stamp image to obtain an accurate recognition model.
[0331] In this embodiment, the electronic device can first train the TCL sub-model, TML sub-model, and TBO sub-model based on the sample seal image. After training the three sub-models, the recognition model is then trained end-to-end. Since the TCL, TML, and TBO sub-models in the recognition model can identify text regions in the sample seal image from different dimensions, the recognition model can accurately identify the text regions in the seal image, thereby accurately identifying the text in the seal image and the text box containing the text, thus improving the accuracy of seal image recognition.
[0332] Below, in conjunction with Figure 18 The process of using the model is explained, that is, the process of processing the seal image through the recognition model is explained.
[0333] Figure 18 This is a schematic diagram illustrating a seal image recognition method provided for an exemplary embodiment of this application. Please refer to... Figure 18 The method may include:
[0334] S1801. Determine the image of the first seal.
[0335] Electronic devices can use a seal detection network to identify images of documents and determine the first seal image.
[0336] S1802. The first seal image is processed by the recognition model to obtain the text included in the first seal image and the text box in which the text is located.
[0337] The recognition model can be determined according to the model training method of any of the above embodiments, which will not be elaborated here.
[0338] After the electronic device identifies the first seal image, it can recognize the first seal image through the TCL sub-model in the recognition model to obtain a TCL feature map; it can recognize the first seal image through the TML sub-model to obtain a TML feature map; and it can recognize the first seal image through the TBO sub-model to obtain a TBO feature map. Furthermore, the electronic device can also delineate the TCL feature map based on the TML feature map to generate an ABM feature map.
[0339] Electronic devices can process the first seal image using a feature extraction sub-model to obtain seal features, and then determine text region features based on the ABM feature map and seal features. Electronic devices can then identify the text region features using a text recognition sub-model to determine the text included in the first seal image.
[0340] Electronic devices can calculate the distance between the corresponding pixel and the top and bottom edges of the text box based on the ABM feature map and the TBO feature map, thereby accurately determining the position of the top and bottom edges of the text box, and thus determining the text box in which the text is located in the first stamp image.
[0341] In this embodiment, the electronic device can recognize an image of a document, identify a first seal image, and then use a TCL sub-model, a TML sub-model, and a TBO sub-model to recognize the first seal image, obtaining corresponding TCL feature maps, TML feature maps, and TBO feature maps, and further obtaining an ABM feature map. The electronic device can determine the text boxes in the first seal image based on the TBO feature map and the ABM feature map; it can also recognize the first seal image through a feature extraction sub-model in the recognition model, determine the seal features, and determine the text region features based on the ABM feature map and the seal features. Then, it uses a text recognition sub-model to recognize the text region features and determine the text included in the first seal image. Because the electronic device can recognize the text region in the sample seal image from different dimensions through multiple sub-models in the recognition model, the recognition model can accurately identify the text region in the seal image, and thus accurately identify the text in the seal image and the text box containing the text, thereby improving the accuracy of seal image recognition.
[0342] Figure 19 For a schematic diagram of a model training apparatus provided as an exemplary embodiment of this application, please refer to [link / reference]. Figure 19 The model training device includes: an acquisition module 11, a first training module 12, and a second training module 13, wherein...
[0343] The acquisition module 11 is used to acquire multiple sample data, the sample data including sample seal images and annotation results, the annotation results including: annotation text and annotation text boxes of the sample seal images;
[0344] The first training module 12 is used to train sub-models based on the multiple sample data to obtain a text center line (TCL) sub-model, a text edge line (TML) sub-model, and a text boundary offset (TBO) sub-model.
[0345] The second training module 13 is used to train a model based on the multiple sample data to obtain a recognition model. The recognition model includes the TCL sub-model, the TML sub-model, and the TBO sub-model. The recognition model is used to recognize the text in the seal image and the text box in which the text is located.
[0346] The model training device provided in this application embodiment can execute the technical solution shown in the above method embodiment. Its implementation principle and beneficial effects are similar, and will not be described again here.
[0347] In one possible implementation, the first training module 12 is specifically used for:
[0348] Based on the multiple sample data, the initial TCL sub-model is trained to obtain the TCL sub-model;
[0349] Based on the multiple sample data, the initial TML sub-model is trained to obtain the TML sub-model;
[0350] Based on the multiple sample data, the initial TBO sub-model is trained to obtain the TBO sub-model.
[0351] In one possible implementation, the first training module 12 is specifically used for:
[0352] The sample stamp image in the sample data is processed by the initial TCL sub-model to obtain a first TCL feature map. The pixel value of the pixel in the first TCL feature map is used to indicate the probability that the pixel is the center of the text.
[0353] The text region in the first TCL feature map is shrunk inward by a preset ratio to obtain a second TCL feature map, wherein the pixel value in the text region is greater than or equal to a first threshold.
[0354] Based on the second TCL feature map and the labeled text boxes in the sample data, update the model parameters of the initial TCL sub-model until the TCL sub-model is obtained.
[0355] In one possible implementation, the first training module 12 is specifically used for:
[0356] The sample stamp image in the sample data is processed by the initial TML sub-model to obtain a first TML feature map. The pixel value of the pixel in the first TML feature map is used to indicate the probability that the pixel is a text box.
[0357] The text box region in the first TML feature map is shrunk inward by a preset ratio to obtain a second TML feature map, wherein the pixel value in the text box region is greater than or equal to a second threshold.
[0358] Based on the second TML feature map and the labeled text boxes in the sample data, update the model parameters of the initial TML sub-model until the TML sub-model is obtained.
[0359] In one possible implementation, the first training module 12 is specifically used for:
[0360] The sample stamp image in the sample data is processed by the initial TBO sub-model to obtain a first TBO feature map. The pixel value of the pixel in the first TBO feature map is used to indicate the distance between the pixel and the upper edge of the text box, and the distance between the pixel and the lower edge of the text box.
[0361] Based on the first TBO feature map and the labeled text boxes in the sample data, update the model parameters of the initial TBO sub-model until the TBO sub-model is obtained.
[0362] In one possible implementation, the recognition model further includes a feature extraction sub-model and a text recognition sub-model; the second training module is specifically used for:
[0363] Based on the TCL sub-model, the TML sub-model, and the TBO sub-model, the sample stamp images in the sample data are processed to obtain predicted text boxes;
[0364] Based on the TCL sub-model, the TML sub-model, the feature extraction sub-model, and the text recognition sub-model, the sample seal images in the sample data are processed to obtain the predicted text;
[0365] The model parameters of the recognition model are updated based on the labeled text boxes in the sample data, the predicted text boxes, the labeled text in the sample data, and the predicted text, until the recognition model is obtained.
[0366] In one possible implementation, the second training module 13 is specifically used for:
[0367] Based on the TCL sub-model and the TML sub-model, the sample stamp image in the sample data is processed to obtain an approximate binary ABM feature map. The pixel value of each pixel in the ABM feature map is used to indicate whether the pixel is a text region or a non-text region.
[0368] The sample stamp images in the sample data are processed by the TBO sub-model to obtain the second TBO feature map;
[0369] The predicted text box is determined based on the ABM feature map and the second TBO feature map.
[0370] In one possible implementation, the second training module 13 is specifically used for:
[0371] Based on the TCL sub-model and the TML sub-model, the sample stamp images in the sample data are processed to obtain the ABM feature map;
[0372] The sample seal image is processed according to the feature extraction sub-model to obtain seal features;
[0373] Based on the ABM feature map and the seal features, determine the text region features;
[0374] The predicted text is obtained by processing the text region features through the text recognition sub-model.
[0375] In one possible implementation, the second training module 13 is specifically used for:
[0376] The sample stamp image in the sample data is processed by the TCL sub-model to obtain the third TCL feature map;
[0377] The sample stamp image in the sample data is processed by the TML sub-model to obtain the third TML feature map;
[0378] The ABM feature map is determined based on the third TCL feature map and the third TML feature map.
[0379] In one possible implementation, the acquisition module 11 is specifically used for:
[0380] Obtain multiple manually labeled first sample data; and,
[0381] Based on the seal configuration information and multiple texts in the corpus, multiple second sample data are generated;
[0382] The plurality of sample data includes a plurality of first sample data and a plurality of second sample data.
[0383] In one possible implementation, the acquisition module 11 is specifically used for:
[0384] Generate a seal frame based on the seal configuration information;
[0385] Based on the text length of the first text and the seal configuration information, determine the position of each character in the first text within the seal frame;
[0386] Based on the position of each character in the first text within the seal frame, the first text is filled into the seal frame to obtain a seal image without a background.
[0387] Obtain a background image, and generate a sample stamp image based on the background image and the backgroundless stamp image;
[0388] The first text is determined as the annotation text of the sample seal image, and the annotation text box of the sample seal image is determined according to the position of each character in the first text in the seal frame.
[0389] In one possible implementation, the acquisition module 11 is specifically used for:
[0390] The sample stamp image is obtained by overlaying the background image and the backgroundless stamp image; or,
[0391] The background image and the backgroundless stamp image are overlaid to obtain an overlaid image. At least one of the following operations is performed on the overlaid image: erosion, brightness transformation, or stamp rotation, to obtain the sample stamp image.
[0392] The model training device provided in this application embodiment can execute the technical solution shown in the above method embodiment. Its implementation principle and beneficial effects are similar, and will not be described again here.
[0393] Figure 20 Please refer to the structural schematic diagram of a seal image recognition device provided for an exemplary embodiment of this application. Figure 20 The seal image recognition device includes: a determining module 21 and a processing module 22, wherein,
[0394] The determining module 21 is used to determine the first seal image;
[0395] The processing module 22 is used to process the first seal image through a recognition model to obtain the text included in the first seal image and the text box in which the text is located; wherein the recognition model is determined according to the method of the above embodiment.
[0396] The seal image recognition device provided in this application embodiment can execute the technical solution shown in the above method embodiment. Its implementation principle and beneficial effects are similar, and will not be described again here.
[0397] An exemplary embodiment of this application provides a structural schematic diagram of an electronic device. Please refer to [link / reference]. Figure 21 The electronic device 30 may include a processor 31 and a memory 32. Exemplarily, the processor 31 and the memory 32 are interconnected via a bus 33.
[0398] The memory 32 stores computer-executed instructions;
[0399] The processor 31 executes the computer execution instructions stored in the memory 32, causing the processor 31 to execute the model training method or the seal image recognition method as shown in the above method embodiments.
[0400] Accordingly, embodiments of this application provide a computer-readable storage medium storing computer-executable instructions, which, when executed by a processor, are used to implement the model training method or the seal image recognition method described in the above method embodiments.
[0401] Accordingly, embodiments of this application may also provide a computer program product, including a computer program, which, when executed by a processor, can implement the model training method or the seal image recognition method shown in the above method embodiments.
[0402] Those skilled in the art will understand that embodiments of the present invention can be provided as methods, systems, or computer program products. Therefore, the present invention can take the form of a completely hardware embodiment, a completely software embodiment, or an embodiment combining software and hardware aspects. Furthermore, the present invention can take the form of a computer program product embodied on one or more computer-usable storage media (including, but not limited to, disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.
[0403] This invention is described with reference to flowchart illustrations and / or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of the invention. It will be understood that each block of the flowchart illustrations and / or block diagrams, and combinations of blocks in the flowchart illustrations and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, special-purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, create means for implementing the functions specified in one or more blocks of the flowchart illustrations and / or one or more blocks of the block diagrams.
[0404] These computer program instructions may also be stored in a computer-readable storage medium that can direct a computer or other programmable data processing device to function in a particular manner, such that the instructions stored in the computer-readable storage medium produce an article of manufacture including instruction means that implement the functions specified in one or more flowcharts and / or one or more block diagrams.
[0405] These computer program instructions may also be loaded onto a computer or other programmable data processing apparatus to cause a series of operational steps to be performed on the computer or other programmable apparatus to produce a computer-implemented process, such that the instructions, which execute on the computer or other programmable apparatus, provide steps for implementing the functions specified in one or more flowcharts and / or one or more block diagrams.
[0406] In a typical configuration, a computing device includes one or more processors (CPU), input / output interfaces, network interfaces, and memory.
[0407] Memory may include non-persistent storage in computer-readable media, such as random access memory (RAM) and / or non-volatile memory, such as read-only memory (ROM) or flash RAM. Memory is an example of computer-readable media.
[0408] Computer-readable media includes both permanent and non-permanent, removable and non-removable media that can store information using any method or technology. Information can be computer-readable instructions, data structures, modules of programs, or other data. Examples of computer storage media include, but are not limited to, phase-change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technologies, CD-ROM, digital versatile optical disc (DVD) or other optical storage, magnetic tape, magnetic magnetic disk storage or other magnetic storage devices, or any other non-transferable medium that can be used to store information accessible by a computing device. As defined herein, computer-readable media does not include transient computer-readable media, such as modulated data signals and carrier waves.
[0409] It should also be noted that the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Without further limitation, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes said element.
[0410] The above description is merely an embodiment of this application and is not intended to limit the scope of this application. Various modifications and variations can be made to this application by those skilled in the art. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of this application should be included within the scope of the claims of this application.
Claims
1. A model training method, characterized in that, include: Acquire multiple sample data, the sample data including sample seal images and annotation results, the annotation results including: annotation text and annotation text boxes of the sample seal images; Sub-models are trained based on the multiple sample data to obtain the text centerline TCL sub-model, the text edgeline TML sub-model, and the text boundary offset TBO sub-model. The model is trained based on the multiple sample data to obtain a recognition model, which includes the TCL sub-model, the TML sub-model and the TBO sub-model. The recognition model is used to recognize the text in the seal image and the text box in which the text is located. The recognition model also includes a feature extraction sub-model and a text recognition sub-model; The recognition model is obtained by training the model based on the multiple sample data, including: Based on the TCL sub-model, the TML sub-model, and the TBO sub-model, the sample stamp images in the sample data are processed to obtain predicted text boxes; Based on the TCL sub-model, the TML sub-model, the feature extraction sub-model, and the text recognition sub-model, the sample seal images in the sample data are processed to obtain the predicted text; The model parameters of the recognition model are updated based on the labeled text boxes in the sample data, the predicted text boxes, the labeled text in the sample data, and the predicted text, until the recognition model is obtained.
2. The method according to claim 1, characterized in that, Based on the multiple sample data, sub-models are trained to obtain the Text Centerline (TCL) sub-model, the Text Edgeline (TML) sub-model, and the Text Boundary Offset (TBO) sub-model, including: Based on the multiple sample data, the initial TCL sub-model is trained to obtain the TCL sub-model; Based on the multiple sample data, the initial TML sub-model is trained to obtain the TML sub-model; Based on the multiple sample data, the initial TBO sub-model is trained to obtain the TBO sub-model.
3. The method according to claim 2, characterized in that, Based on the multiple sample data, the initial TCL sub-model is trained to obtain the TCL sub-model, including: The sample stamp image in the sample data is processed by the initial TCL sub-model to obtain a first TCL feature map. The pixel value of the pixel in the first TCL feature map is used to indicate the probability that the pixel is the center of the text. The text region in the first TCL feature map is shrunk inward by a preset ratio to obtain a second TCL feature map, wherein the pixel value in the text region is greater than or equal to a first threshold. Based on the second TCL feature map and the labeled text boxes in the sample data, update the model parameters of the initial TCL sub-model until the TCL sub-model is obtained.
4. The method according to claim 2, characterized in that, Based on the multiple sample data, the initial TML sub-model is trained to obtain the TML sub-model, including: The sample stamp image in the sample data is processed by the initial TML sub-model to obtain a first TML feature map. The pixel value of the pixel in the first TML feature map is used to indicate the probability that the pixel is a text box. The text box region in the first TML feature map is shrunk inward by a preset ratio to obtain a second TML feature map, wherein the pixel value in the text box region is greater than or equal to a second threshold. Based on the second TML feature map and the labeled text boxes in the sample data, update the model parameters of the initial TML sub-model until the TML sub-model is obtained.
5. The method according to claim 2, characterized in that, Based on the multiple sample data, the initial TBO sub-model is trained to obtain the TBO sub-model, including: The sample stamp image in the sample data is processed by the initial TBO sub-model to obtain a first TBO feature map. The pixel value of the pixel in the first TBO feature map is used to indicate the distance between the pixel and the upper edge of the text box, and the distance between the pixel and the lower edge of the text box. Based on the first TBO feature map and the labeled text boxes in the sample data, update the model parameters of the initial TBO sub-model until the TBO sub-model is obtained.
6. The method according to claim 1, characterized in that, Based on the TCL sub-model, the TML sub-model, and the TBO sub-model, the sample stamp images in the sample data are processed to obtain predicted text boxes, including: Based on the TCL sub-model and the TML sub-model, the sample stamp image in the sample data is processed to obtain an approximate binary ABM feature map. The pixel value of each pixel in the ABM feature map is used to indicate whether the pixel is a text region or a non-text region. The sample stamp images in the sample data are processed by the TBO sub-model to obtain the second TBO feature map; The predicted text box is determined based on the ABM feature map and the second TBO feature map.
7. The method according to claim 1, characterized in that, Based on the TCL sub-model, the TML sub-model, the feature extraction sub-model, and the text recognition sub-model, the sample seal images in the sample data are processed to obtain predicted text, including: Based on the TCL sub-model and the TML sub-model, the sample stamp images in the sample data are processed to obtain the ABM feature map; The sample seal image is processed according to the feature extraction sub-model to obtain seal features; Based on the ABM feature map and the seal features, determine the text region features; The predicted text is obtained by processing the text region features through the text recognition sub-model.
8. The method according to claim 6 or 7, characterized in that, Based on the TCL sub-model and the TML sub-model, the sample stamp images in the sample data are processed to obtain ABM feature maps, including: The sample stamp image in the sample data is processed by the TCL sub-model to obtain the third TCL feature map; The sample stamp image in the sample data is processed by the TML sub-model to obtain the third TML feature map; The ABM feature map is determined based on the third TCL feature map and the third TML feature map.
9. The method according to any one of claims 1-5, characterized in that, Obtain multiple sample data, including: Obtain multiple manually labeled first sample data; and, Based on the seal configuration information and multiple texts in the corpus, multiple second sample data are generated; The plurality of sample data includes a plurality of first sample data and a plurality of second sample data.
10. The method according to claim 9, characterized in that, For any first text in the corpus; Based on the seal configuration information and the first text, second sample data is generated, including: Generate a seal frame based on the seal configuration information; Based on the text length of the first text and the seal configuration information, determine the position of each character in the first text within the seal frame; Based on the position of each character in the first text within the seal frame, the first text is filled into the seal frame to obtain a seal image without a background. Obtain a background image, and generate a sample stamp image based on the background image and the backgroundless stamp image; The first text is determined as the annotation text of the sample seal image, and the annotation text box of the sample seal image is determined according to the position of each character in the first text in the seal frame.
11. A method for recognizing seal images, characterized in that, include: Identify the image of the first seal; The first seal image is processed by a recognition model to obtain the text included in the first seal image and the text box in which the text is located. The identification model is determined by the method according to any one of claims 1-10.
12. An electronic device, characterized in that, include: Memory and processor; The memory stores computer-executed instructions; The processor executes computer execution instructions stored in the memory, causing the processor to perform the model training method as described in any one of claims 1 to 10, or the seal image recognition method as described in claim 11.
13. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores computer-executable instructions, which, when executed by a processor, are used to implement the model training method according to any one of claims 1 to 10, or the seal image recognition method according to claim 11.
Citation Information
Patent Citations
Text recognition method and device, electronic equipment and storage medium
CN112464798A
Seal character detection and recognition method, device, and medium for complex environments
WO2021115490A1