Performance testing method, device, equipment and storage medium of text detection algorithm
By injecting target code and annotation information into the text recognition model, the performance test results of the text detection algorithm are generated, which solves the problem of performance testing of the text detection algorithm and improves the accuracy of the text detection and recognition model.
Patent Information
- Application Number
- CN201911369631.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2019-12-26
- Publication Date
- 2024-09-13
- Estimated Expiration
- 2039-12-26
AI Technical Summary
The existing technology makes it difficult to test and adjust the performance of the text detection algorithm without changing the source code of the text recognition model, resulting in insufficient text detection accuracy and overall recognition accuracy.
By injecting target code into the text recognition model, target object samples are obtained for text information annotation, and performance test results are generated based on text detection information and annotation information, and the text detection algorithm is adjusted to improve accuracy.
Without changing the source code of the text recognition model, the accuracy of the single-layer text detection algorithm is improved, thereby improving the accuracy of the entire text recognition model.
Smart Images

Figure CN111178350B
Abstract
Description
Technical Field
[0001] The present application relates to the field of text recognition technology, and in particular to a performance testing method, device, equipment and storage medium for a text detection algorithm. Background Art
[0002] OCR (Optical Character Recognition) is a technology that converts the text of various certificates, bills, newspapers, books, manuscripts and other printed materials into image information through optical input methods such as scanning, and then uses text recognition technology to convert the image information into usable computer input technology. A complete OCR algorithm implementation process usually includes multiple steps, typical steps include: image preprocessing, text detection and text recognition, among which the steps that affect the recognition accuracy are text detection and text recognition. Text detection is to detect the location, range and layout of the text, including layout analysis and text line detection, and then perform text recognition on the detected text box image containing the text. It can be seen that the accuracy of text detection affects the recognition accuracy of the entire OCR algorithm implementation process, so the performance test of the text detection algorithm is particularly important. Summary of the invention
[0003] The technical problem to be solved by the present application is to provide a performance testing method, apparatus, device and storage medium for a text detection algorithm, which can test the performance of the text detection algorithm in a text recognition model without changing the source code of the text recognition model, and adjust the text detection algorithm based on the performance test results, thereby improving the accuracy of a single-layer text detection algorithm, and also improving the accuracy of the entire text recognition model.
[0004] In order to solve the above technical problems, on the one hand, the present application provides a performance testing method of a text detection algorithm, the method comprising:
[0005] Injecting the target code into a text recognition model; the text recognition model includes a text detection layer for performing text detection based on a text detection algorithm to be tested; the target code includes code for extracting output information of the text detection layer;
[0006] Acquire target object samples, and annotate text information for each target object in the target object samples to obtain text annotation information corresponding to each target object;
[0007] Inputting each target object sequentially into the text recognition model into which the target code has been injected, and extracting text detection information corresponding to each target object based on the target code;
[0008] Based on the text detection information of each target object and the text annotation information of each target object, a performance test result of the text detection algorithm to be tested is generated.
[0009] On the other hand, the present application provides a performance testing device for a text detection algorithm, the device comprising:
[0010] A target code injection module, used for injecting a target code into a text recognition model, wherein the target code includes a code for extracting output information of the text detection layer;
[0011] A target object sample acquisition module is used to acquire target object samples, annotate text information of each target object in the target object samples, and obtain text annotation information corresponding to each target object;
[0012] A text detection information extraction module, used to sequentially input each target object into a text recognition model into which the target code has been injected, and extract text detection information corresponding to each target object based on the target code;
[0013] The test result generation module is used to generate a performance test result of the text detection algorithm to be tested based on the text detection information of each target object and the text annotation information of each target object.
[0014] On the other hand, the present application provides a device, comprising a processor and a memory, wherein the memory stores at least one instruction or at least one program, and the at least one instruction or the at least one program is loaded by the processor and executed by the performance testing method of the text detection algorithm as described above.
[0015] On the other hand, the present application provides a computer storage medium, in which at least one instruction or at least one program is stored, and the at least one instruction or the at least one program is loaded by a processor and executed by the performance testing method of the text detection algorithm as described above.
[0016] Implementing the embodiments of the present application has the following beneficial effects:
[0017] The present application injects target code into the text recognition model, wherein the target code includes code for extracting the output information of the text detection layer; annotates text information of each target object in the target object sample to obtain text annotation information of the target object; sequentially inputs each target object into the text recognition model into which the target code has been injected, and extracts text detection information corresponding to each target object based on the target code; and generates performance test results of the text detection algorithm to be tested based on the text detection information and text annotation information of each target object. The present application can test the performance of the text detection algorithm in the text recognition model without changing the source code of the text recognition model, and adjust the text detection algorithm based on the performance test results, thereby improving the accuracy of the single-layer text detection algorithm, and also improving the accuracy of the entire text recognition model. BRIEF DESCRIPTION OF THE DRAWINGS
[0018] In order to more clearly illustrate the technical solutions and advantages in the embodiments of the present invention or the prior art, the drawings required for use in the embodiments or the prior art descriptions are briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0019] Figure 1 It is a schematic diagram of the implementation environment provided by the embodiment of the present application;
[0020] Figure 2 It is a flow chart of a performance testing method of a text detection algorithm provided in an embodiment of the present application;
[0021] Figure 3 This is a flow chart of a text annotation method for a target object provided in an embodiment of the present application;
[0022] Figure 4 It is a flow chart of a text detection information extraction method provided by an embodiment of the present application;
[0023] Figure 5 It is a flow chart of a method for generating performance test results of a text detection algorithm provided in an embodiment of the present application;
[0024] Figure 6 is a flow chart of a method for restoring location information provided by an embodiment of the present application;
[0025] Figure 7 It is a flow chart of a performance test result calculation method provided in an embodiment of the present application;
[0026] Figure 8 is a flow chart of a method for generating performance test results of another text detection algorithm provided in an embodiment of the present application;
[0027] FIG9 is a schematic diagram of an example process provided by an embodiment of the present application;
[0028] Fig.10 This is a schematic diagram of the intermediate result image file format provided in an embodiment of the present application;
[0029] Fig.11 It is a schematic diagram of a performance testing device for a text detection algorithm provided in an embodiment of the present application;
[0030] Fig.12 It is a schematic diagram of a device structure provided in an embodiment of the present application. DETAILED DESCRIPTION
[0031] To make the purpose, technical solutions and advantages of the present application clearer, the present application will be further described in detail below in conjunction with the accompanying drawings. Obviously, the described embodiments are only part of the embodiments of the present application, rather than all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in the field without making creative work are within the scope of protection of the present application.
[0032] It should be noted that the terms "first", "second", etc. in the specification and claims of the present application and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the data used in this way can be interchangeable where appropriate, so that the embodiments of the present application described herein can be implemented in an order other than those illustrated or described herein. In addition, the terms "including" and "having" and any of their variations are intended to cover non-exclusive inclusions, for example, a process, method, system, product or server that includes a series of steps or units is not necessarily limited to those steps or units clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.
[0033] First, the relevant terms involved in the embodiments of the present application are explained as follows:
[0034] AOP: Aspect-Oriented Programming, extracts aspects from the business processing process and dynamically cuts the code into specified methods and locations.
[0035] Text detection: In the field of OCR, text detection is a prerequisite for scene text recognition. The problem to be solved is how to accurately locate the position of the text box that matches the text in a complex, disordered and bizarre scene.
[0036] Intersection over union (IOU): It is the ratio between the intersection and union of the detection box predicted by the model and the real detection box. The overlapping area of the predicted box and the real box is the intersection area, and the total area of the predicted box and the real box is the union box. Using IOU to see whether the detection is correct requires setting a threshold. The most commonly used threshold is 0.5 (the threshold can be customized according to actual conditions). That is, if IOU>0.5, it is considered a true detection (true detection), otherwise it is considered a false detection (false detection).
[0037] OpenCV: is a cross-platform computer vision library that can run on Linux, Windows, Android and MacOS operating systems. It consists of a series of C functions and a small number of C++ classes. It also provides interfaces for languages such as Python, Ruby, and MATLAB, and implements many common algorithms in image processing and computer vision.
[0038] See also Figure 1 , which shows a schematic diagram of an application scenario, the environment may include: at least one user terminal 110 and a server 120, the user terminal 110 and the server 120 may communicate data via a network. Specifically, the user terminal 110 submits a performance test request for a text detection algorithm to the server 120, the server 120 receives the performance test request, obtains data required for related performance tests, performs performance tests on the text detection algorithm in the text recognition model, and generates performance test results.
[0039] The user terminal 110 can communicate with the server 120 based on the browser / server mode (B / S) or the client / server mode (C / S). The user terminal 110 may include: physical devices such as smart phones, tablet computers, laptops, digital assistants, smart wearable devices, vehicle terminals, servers, etc., and may also include software running in physical devices, such as applications, etc. The operating system running on the user terminal 110 in the embodiment of the present invention may include but is not limited to Android system, IOS system, Linux, Windows, etc.
[0040] The server 120 and the user terminal 110 may establish a communication connection via wired or wireless communication. The server 120 may include an independently operated server, or a distributed server, or a server cluster consisting of multiple servers, wherein the server may be a cloud server.
[0041] Since the accuracy of the text detection algorithm affects the recognition accuracy of the entire OCR algorithm implementation process, it is necessary to test the performance of the text detection algorithm. In the prior art, the performance index test of the OCR algorithm is generally an end-to-end overall performance index test, that is, a large number of test sample sets that meet the business requirements are collected manually or by program synthesis, and a script is written to call the entire OCR engineering service to calculate the overall index, but there is no technical solution for separately testing the performance of the text detection algorithm in the OCR algorithm process. Therefore, the embodiment of the present application provides a performance testing method for a text detection algorithm, and its execution subject can be the above Figure 1 For servers in , see Figure 2 , the method may include:
[0042] S210. Injecting the target code into a text recognition model; the text recognition model includes a text detection layer for performing text detection based on a text detection algorithm to be tested; the target code includes a code for extracting output information of the text detection layer.
[0043] Before injecting the target code into the text recognition model, the method may also include: obtaining a text recognition model, wherein the text recognition model includes an object preprocessing layer, a text detection layer, and a character recognition layer; wherein the text detection layer performs text detection based on the text detection algorithm to be tested.
[0044] The text recognition model in this application is an OCR algorithm model, which refers to a model that can recognize the text of various certificates, bills, newspapers, books, manuscripts and other printed materials and convert them into usable computer input.
[0045] When recognizing based on the text recognition model, the image containing text information obtained by optical input methods such as scanning is first preprocessed through the object preprocessing layer. The preprocessing methods here include grayscale, binarization, geometric transformation, distortion correction, blur removal, image enhancement and light correction, as well as line and word segmentation, smoothing, normalization, etc. of the image containing text information; the preprocessed image is sent to the text detection layer, and the text detection layer uses the text detection algorithm to be tested to detect the position, range and layout of the text, including layout analysis and text line detection; the detected text box image containing text is sent to the text recognition layer for text recognition.
[0046] The target code in the embodiment of the present application is injected into the text recognition model through aspect-oriented programming AOP technology. The tester can inject customized rule code according to specific test requirements, so that the tester can achieve the purpose of extracting the output value of the text detection algorithm through the log or other output files generated by the injected target code.
[0047] S220. Obtain target object samples, and annotate text information for each target object in the target object samples to obtain text annotation information corresponding to each target object.
[0048] The target object may be one of the above-mentioned certificates, bills, newspapers, books, manuscripts and other printed materials. The target object is an original target object, that is, an object that has not been processed. Therefore, the original target object is annotated with a text box. The text annotation information of each original target object can be regarded as the source label of each target object, which can be used as the basis for subsequent comparison with the detection information obtained after the detection processing. For details, please refer to Figure 3 , which shows a text annotation method for a target object, the method may include:
[0049] S310. Determine the text area included in each target object, and mark each text area to obtain a corresponding text box.
[0050] The text area may be a related area containing text information. In the target object, text in different lines may be regarded as different areas. Different text areas are marked to obtain corresponding text boxes.
[0051] S320. Determine the source position information of each text box in the target object.
[0052] Taking the original target object as a certificate as an example, the upper left corner of each certificate is directly taken as the origin to establish a coordinate system, so that the position information of each text box in each certificate in step S310 in the corresponding coordinate system can be obtained, and this position information can be regarded as the source position information of each text box in each certificate in the corresponding certificate. Specifically, the source position information of each text box can be determined by the coordinate values of the four vertices of the text box, that is, the position information of each text box can be uniquely identified by the coordinate values of the four points.
[0053] S330. Use the source position information of each text box corresponding to the target object as the text annotation information of the target object.
[0054] The source position information of each text box in each target object can be used as the text annotation information of the target object.
[0055] Through the above Figure 3 The text annotation method of the target object shown can annotate the position information of all text boxes contained in each original target object. The position annotation information can be used as the label information of the original target object and can be used as the basis for subsequent comparison with the information obtained after processing.
[0056] S230. Input each target object in turn into the text recognition model into which the target code has been injected, and extract text detection information corresponding to each target object based on the target code.
[0057] For the text recognition model that has been injected with the target code, it needs to be recompiled and run. For details, please refer to Figure 4 , which shows a text detection information extraction method, the method may include:
[0058] S410. Compile the text recognition model injected into the target code to generate an executable model.
[0059] S420. Use each target object as the input of the executable model in turn, and run the executable model.
[0060] S430. Based on the target code in the executable model, extract text detection information corresponding to each target object at the output end of the text detection layer.
[0061] By compiling and running the text recognition model injected with the target code, and extracting the output information of the text detection layer after running the model based on the target code, it is achieved that the preset operation can be performed at the preset injection point by injecting the target code without modifying the original model code.
[0062] S240. Based on the text detection information of each target object and the text annotation information of each target object, generate a performance test result of the text detection algorithm to be tested.
[0063] The text detection information in the embodiment of the present application is the detection position information of the text box obtained based on the text detection algorithm to be tested, and the detection position information of the text box is the position information of the detected text box in the processed object after passing through the object preprocessing layer. Figure 5 , which shows a method for generating performance test results of a text detection algorithm, the method may include:
[0064] S510. For each processed object after being processed by the object preprocessing layer, restore the position information based on the detected position information of each text box in the processed object to obtain the restored position information of each text box in the processed object.
[0065] The reason why the position information needs to be restored here is that the detection information position of each text box in the processed object is the position information of each text box in the processed object, and the processed object is obtained after preprocessing the target object, that is, the processed object has changed relative to the target object, so the position information of each text box in the processed object is not the position of each text box in the target object. In order to compare the position information of each text box in the processed object with the source position information of each text box in the target object, it is necessary to first restore the detection position information of each text box in the processed object to the position of each text box in the target object, thereby obtaining the restored position information of each text box in the processed object.
[0066] S520. Determine the target object corresponding to the processed object, and obtain source position information of each text box in the target object.
[0067] Since there is a corresponding relationship between the target object and the processed object, the corresponding target object can be determined according to the processed object, and the source position information of each text box in the target object can be obtained.
[0068] S530. Perform calculations based on a preset method, the restored position information of each text box in the processed object, and the source position information of each text box in the target object to obtain a performance test result of the text detection algorithm to be tested.
[0069] For each processed object, after obtaining the restored position information of each text box in the processed object and the source position information of each text box in the corresponding target object, a performance test result of the text detection algorithm to be tested is obtained through a preset processing method. The specific implementation process of the preset method can be found in Figure 7 The content shown.
[0070] For details on the location information restoration process in step S510, please refer to Figure 6 , which shows a method for restoring location information, the method may include:
[0071] S610. Determine a reverse object preprocessing method based on the object preprocessing method in the object preprocessing layer.
[0072] The target object is processed into a processed object through the object preprocessing layer, and its corresponding method is the object preprocessing method. When restoration is required, it is the inverse process of the object preprocessing method, and the inverse object preprocessing method needs to be determined. The inverse object preprocessing method is a processing process opposite to the object preprocessing method. The object preprocessing method is used to process the target object into a processed object. Accordingly, the inverse object preprocessing method is used to restore the processed object to the target object. For example, the original image of the target object is processed into a processed image using the object preprocessing method, and the inverse object preprocessing method can be used to restore the processed image to the original image of the target object.
[0073] S620. Based on the inverse object preprocessing method and the detected position information of each text box in each processed object, calculate the restored position information of each text box in each processed object in the corresponding target object.
[0074] According to the reverse object preprocessing method, the position information of each text box in each preprocessed object is restored to the position information of each text box in the target object. In the embodiment of the present application, each text box in each target object and each text box in the processed object can be labeled based on the same labeling rule, where each text box in the target object refers to the text box determined when marking the source position information, and each text box in the processed object refers to each text box detected by the text detection algorithm; the specific labeling rule can be: starting from the upper left corner of each target object or processed object, the text boxes therein are labeled in sequence from left to right and from top to bottom, so that each text box has a corresponding label; for the specific generation process of the performance test results in the above step S530, please refer to Figure 7 , which shows a method for calculating performance test results, the method may include:
[0075] S710. Traverse each processed object.
[0076] S720. Determine a current target object corresponding to the currently processed object.
[0077] S730. Generate at least one text box pair based on the text boxes with the same label in the currently processed object and the current target object.
[0078] Each text box in each processed object is combined with a text box in a corresponding target object. Specifically, the combination method is to combine two text boxes with the same label to obtain at least one text box pair.
[0079] S740. In each text box pair, based on the restored position information of the currently processed object and the source position information of the current target object, calculate the intersection-and-union ratio of the two text boxes in the text box pair.
[0080] The restored position information and the source position information here may specifically be in the form of coordinate values, that is, for each text box, its position information is represented by four coordinate values.
[0081] The intersection-in-union ratio is the ratio between the intersection and union of the detection box and the true box. Specifically, in the embodiment of the present application, the intersection of the detection box and the true box is the intersection area of the text box in the processed object and the text box in the target object, and the union is the total area of the text box in the processed object and the text box in the target object. The specific area calculation can be performed through the coordinate values of the text boxes, thereby obtaining the intersection-in-union ratio of this text box pair.
[0082] For each text box pair of each target object, the corresponding text box intersection-to-union ratio can be obtained based on the above calculation method.
[0083] S750. Count the first number of text box pairs corresponding to each target object.
[0084] The first quantity here refers to the total quantity of text box pairs of all target objects.
[0085] S760. Count the second number of text box pairs whose intersection-over-union ratio is greater than the first threshold among the first number of text box pairs.
[0086] According to the calculation result of the intersection-and-union ratio of each text box pair, the number of text box pairs whose intersection-and-union ratio is greater than the first threshold is obtained.
[0087] S770. Generate a performance test result based on the first quantity and the second quantity.
[0088] The ratio of the number of text box pairs whose intersection-and-union ratio is greater than the first threshold to the total number of text box pairs is calculated, and the ratio is used as the performance test result of the text detection algorithm to be tested; or the ratio of the number of text box pairs whose intersection-and-union ratio is greater than the first threshold to the number of text box pairs whose intersection-and-union ratio is less than or equal to the first threshold is calculated, and the ratio is used as the performance test result of the text detection algorithm to be tested. According to the performance test results, the recognition accuracy of the text detection algorithm to be tested can be determined. The higher the recognition accuracy, the more stable and reliable the text detection algorithm is. On the contrary, it is considered that the accuracy of the text detection algorithm is not high, and it is necessary to continue to train the text detection model to improve the text detection accuracy.
[0089] During the above implementation process, when the number of text boxes in the processed object is consistent with the number of text boxes marked in the target object, at least one text box pair can be generated based on the text boxes with the same label; however, when the number of text boxes in the processed object obtained through the text detection layer is greater than or less than the number of text boxes marked in the corresponding target object, each text box in the processed object can be cyclically compared with each text box in the target object in order from top to bottom and from left to right, and the text box closest to its position is found in the target object to generate a text box pair. The remaining text boxes that are missed or extra after detection can be considered whether to need to be re-detected or not taken into consideration according to the actual situation.
[0090] Furthermore, when implementing the above-mentioned performance testing method of the text detection algorithm, the text detection information of each target object can also be annotated with a text box based on the target code, and the analysis result of the annotated information can be used to assist the method of performing performance testing on the text detection algorithm based on the intersection-and-union ratio. For details, please refer to Figure 8 , which shows another method for generating performance test results of a text detection algorithm, the method may include:
[0091] S810. Based on the target code, obtain each processed object after being pre-processed by the object processing layer.
[0092] S820. Based on the text detection information of each target object, respectively mark the text boxes of the processed objects corresponding to each target object.
[0093] S830. Based on the processed object with text box annotation, generate a performance test result of the text detection algorithm to be tested.
[0094] Whether the result of labeling the processed object based on the text detection information is reasonable is determined by direct manual inspection. If a text box drawn in a non-text area appears in the processed object, or a text box with many different types of text connected together, it is considered that the text detection algorithm has a problem with text detection and recognition in the object. All objects with this problem are counted, and a performance testing method based on position information to assist in calculating the intersection-over-union ratio is used to further improve the accuracy of the detection algorithm.
[0095] The implementation process of the present application is described below with a specific example. Taking the document OCR recognition scenario as an example, the implementation process diagram is shown in FIG9 (a) and FIG9 (b). The corresponding implementation process may include:
[0096] 1. Write AOP code to implement output injection control of the text detection algorithm layer in the document OCR recognition process. The injection point rules must match all modules that affect the text detection algorithm, including corresponding functions, threads, processes, etc.
[0097] The injection point content mainly consists of two parts:
[0098] (1) The recognition result output of the text detection algorithm for the execution sample in the OCR engineering code: mainly the output of the recognized text box position. In order not to affect the original OCR log file, etc., these output results can be redefined into a new output file in a certain format. The output file saves the output values of the text detection algorithm during the execution of each sample that can be distinguished.
[0099] (2) The text detection algorithm in the OCR engineering code outputs the intermediate image file of the execution sample: through the text box position of the sample identified in the above (1), the current text box position is drawn on the image through OPENCV technology and the intermediate image is stored according to a certain naming convention.
[0100] Specifically, the text box position of the sample identified in (1) is used in the OCR process for the sample input image that has been preprocessed and is ready to be sent to the text detection algorithm model for recognition. The current text box position is processed on the image through OPENCV technology, and the intermediate result image file of the current drawn text box position is saved according to certain rules. The image file is used for subsequent manual assistance to check whether there are any problems with the function effect of the text detection algorithm and whether the text box position is detected correctly. The output intermediate result image file format is as follows: Fig.10 shown.
[0101] 2. Compile and deploy
[0102] Deploy the OCR engineering service version compiled by AOP to the test or other available environment and run it.
[0103] 3. Test Execution
[0104] (1) Prepare a certain number of test samples that meet the business scenarios, annotate the text box position for each test sample ID card image, and generate a source label file containing the text box annotations in a unified storage format.
[0105] Generally, annotation software is used for manual or script-automated annotation work to generate text box annotation results for each test sample image. For example, the label file content (text box position) obtained by annotating a test sample certificate is as follows:
[0106] {"object":[{"name":"Hong Kong Identity Card","polygon":{"x1":649,"y1":63,"x2":1129,"y2":57,"x3":1133,"y3":113,"x4":649,"y4":119}},{"name":"HONGKONG IDENTITY CARD","polygon":{"x1":483,"y1":125,"x2":1293,"y2":117,"x3":1291,"y3":159,"x4":483,"y4":167}},{"name":"cn_name","polygon":{"x1":193,"y1":199,"x2":451,"y2":197,"x3":449,"y3":263,"x4":193,"y4":269}},{"name":"en_name","polygon":{"x1":193,"y1":281,"x2":545,"y2":273,"x3":545,"y3":325,"x4":193,"y4":327}},{"name":"num","polygon":{"x1":585,"y1":365,"x2":1085,"y2":357,"x3":1085,"y3":407,"x4":585,"y4":413}},{"name":"Date of Birth","polygon":{"x1":-82,"y1":573}},{"name":"birth","polygon":{"x1":585,"y1":493,"x2":989,"y2":493,"x3":989,"y3":533,"x4":579,"y4":541}},{"name":"sex","polygon":{"x1":589,"y1":553,"x2":941,"y2":549,"x3":941,"y3":597}},{"name":"Date of Issue","polygon":{"x1":585,"y1":629,"x2":657,"y2":629,"x3":657,"y3":673,"x4":587,"y4":677}},{"name":"issue_date1","polygon":{"x1":585,"y1":693,"x2":1009,"y2":693,"x3":1009,"y3":733,"x4":585,"y4":741}} It should be noted that there are some incorrect commas and colons in the original Chinese text which have been corrected in the translation for proper English grammar.{"name":"issue_date2","polygon"1":759,"x2":833,"y2":759,"x3":833,"y3":809,"x4":587,"y4":809}},{"n ame":"id","polygon":{"x1":581,"y1":861,"x2":947,"y2":861,"x3":949,"y3":925,"x4":581,"y4":927}}]}.,
[0107] For example, for a set of data such as {"name":"Hong Kong Resident Identity Card","polygon":{"x1":649,"y1":63,"x2":1129,"y2":57,"x3":1133,"y3":113,"x4":649,"y4":119}}, it corresponds to a text box information, and the specific meaning is: the text in the text box is "Hong Kong Resident Identity Card", and the position of the text box can be represented by four coordinate points: ("x1":649,"y1":63), ("x2":1129,"y2":57), ("x3":1133,"y3":113) and ("x4":649,"y4":119).
[0108] (2) Write a test execution script to call the OCR engineering service after AOP instrumentation and batch test the test samples.
[0109] 4. Extracting the output results of the text detection algorithm
[0110] (1) Perform script extraction on the output results of the file detection algorithm generated during the execution of the OCR engineering service test to generate an intermediate result label file corresponding to the test sample.
[0111] The text detection model algorithm extracts the model result output value of each sample from the sample recognition result output file, that is, the position coordinates of the text box output after each sample is recognized by the text detection algorithm, and stores it as an intermediate result label file according to certain rules.
[0112] (2) The script extracts the intermediate image file with the text box position drawn, which is generated by OPENCV technology.
[0113] 5. Text detection algorithm verification
[0114] The verification process includes:
[0115] (1) Write a script for the coordinate position of the sample in the intermediate result label file extracted in step 4, and use mathematical formulas and OPENCV technology to restore it to the coordinate position point of the original sample image.
[0116] (2) For the coordinate position of the text box in the source label file and the restored coordinate position, the script loops through and compares each text box in each sample, uses the area of the text box position to calculate the IOU, and determines whether the text box is detected correctly by whether the IOU of the text box area is greater than a certain threshold.
[0117] (3) The script counts whether all text boxes in all samples are detected correctly or not, and uses mathematical formulas to calculate the accuracy index of the text detection algorithm, thereby judging the quality of the algorithm.
[0118] (4) By collecting and viewing the intermediate result image files generated by the OPENCV code inserted by AOP, we can further assist in locating the function and accuracy problems of the text detection algorithm.
[0119] The verification method of the two text detection algorithms in step 5 above is specifically as follows:
[0120] a. Script calculates IOU intersection-over-union ratio
[0121] For the test samples, after obtaining the source label file and the intermediate result label file, we write scripts and perform certain preprocessing coordinate restoration (because the text box position coordinates obtained in the intermediate result label file are not necessarily for the original test sample image, but to a large extent the image position coordinates after certain preprocessing of the original image, so it is necessary to use mathematical formulas or OPENCV technology to reversely restore the coordinates in the intermediate result label file to the text box coordinates for the original image according to the image preprocessing process in the OCR process). Then, through loop traversal, according to the specified calculation rules, the intersection and union ratio of the position coordinates of each text box of each sample in the source label file and the corresponding position coordinate area after restoration are calculated in turn, and the intersection and union ratio of the area is set to be greater than a certain threshold, then the text box position recognition is considered to be passed, otherwise it is considered to be unrecognized, and then the ratio of recognition pass to recognition fail of all samples is counted, and the accuracy of the text detection algorithm is calculated according to the corresponding calculation formula. The higher the text detection recognition accuracy, the more stable and reliable the algorithm is, otherwise it is considered that the accuracy of the algorithm is not friendly enough, and the model needs to be trained to improve the accuracy.
[0122] b. Check the intermediate result image file of the drawn text box position generated by OPENCV
[0123] For the test samples, after the test is completed, the intermediate result image file generated by the OPENCV code inserted by AOP is manually viewed to determine whether the text box coordinate position is accurately recognized. If a text box in a non-text area or a text box with many different types of text connected together appears in the ID image, it is considered that the text detection algorithm has problems recognizing the sample. All these sample images with problems are counted to assist in locating the algorithm problem and further improve the accuracy of the algorithm effect.
[0124] The use of AOP technology in the above-mentioned algorithm performance testing process does not require changing the source code, and retains the design architecture of the source code. By using AOP technology, various output values related to the algorithm model that are desired by the test can be injected in a controllable manner and tested for the text detection algorithm, thereby improving the accuracy and reliability of the text detection algorithm. The OCR engineering code is injected using AOP, and the injected code and OCR engineering code are compiled, deployed and run. Then, the text box position of each sample in a certain number of certificate samples collected manually or by program is marked to generate a test sample label file. Then, the engineering service with the AOP code inserted is called by script to batch test the test samples. The coordinate position output value of the text box detection algorithm is extracted from the specified output log and file generated by the engineering service. The output value is sorted, analyzed and extracted to generate a text detection algorithm result output file. Then, the script is used to calculate whether the intersection and union ratio of the text box positions in the label file and the algorithm result output file is greater than a certain threshold to verify the accuracy of the text box detection algorithm. The output image generated by the AOP insertion code is used for function-assisted verification to detect whether the accuracy and function of the text box detection algorithm meet the expected test requirements. Through the above-mentioned test method for a single text detection algorithm for document OCR, the accuracy of the single-layer text detection algorithm can be improved, thereby achieving the purpose of improving the accuracy of the overall OCR effect. The same idea can also be applied to the verification of other algorithm modules in the overall OCR process, and by improving the accuracy of a single algorithm module layer by layer, the overall accuracy can be finally improved.
[0125] The present application can test the performance of the text detection algorithm in the text recognition model without changing the source code of the text recognition model, and adjust the text detection algorithm based on the performance test results, thereby improving the accuracy of the single-layer text detection algorithm, and also improving the accuracy of the entire text recognition model.
[0126] This embodiment also provides a performance testing device for a text detection algorithm. Fig.11 , the device may include:
[0127] A target code injection module 1110 is used to obtain a target code and inject the target code into the text recognition model, wherein the target code includes a code for extracting output information of the text detection layer;
[0128] The target object sample acquisition module 1120 is used to acquire target object samples, annotate text information of each target object in the target object samples, and obtain text annotation information corresponding to each target object;
[0129] A text detection information extraction module 1130, configured to sequentially input each target object in the target object sample into a text recognition model into which the target code has been injected, and extract text detection information corresponding to each target object based on the target code;
[0130] The test result generating module 1140 is used to generate a performance test result of the text detection algorithm to be tested based on the text detection information of each target object and the text annotation information of each target object.
[0131] Furthermore, the target object sample acquisition module 1120 includes:
[0132] The first annotation module is used to determine the text area contained in each target object and annotate each text area to obtain a corresponding text box;
[0133] A source location information determination module, used to determine the source location information of each text box in the target object;
[0134] The text annotation information determination module is used to use the source position information of each text box corresponding to the target object as the text annotation information of the target object.
[0135] Furthermore, the text detection information extraction module 1130 includes:
[0136] A model compilation module, used to compile the text recognition model injected with the target code to generate an executable model;
[0137] An executable model running module, used to take each target object as the input of the executable model in turn and run the executable model;
[0138] The first extraction module is used to extract text detection information corresponding to each target object at the output end of the text detection layer based on the target code in the executable model.
[0139] Further, the text detection information is the detection position information of the text box obtained based on the text detection algorithm to be tested, and the detection position information of the text box is the position information of the detected text box in the processed object after passing through the object preprocessing layer; accordingly, the test result generation module 1140 includes:
[0140] A position information restoration module, used for restoring the position information of each processed object after being processed by the object preprocessing layer based on the detected position information of each text box in the processed object, so as to obtain the restored position information of each text box in the processed object;
[0141] A source location information acquisition module, used to determine a target object corresponding to the processed object, and acquire source location information of each text box in the target object;
[0142] The first performance test result generating module is used to calculate based on a preset method, the restored position information of each text box in the processed object and the source position information of each text box in the target object to obtain the performance test result of the text detection algorithm to be tested.
[0143] Furthermore, the location information restoration module includes:
[0144] An inverse object preprocessing method determination module, configured to determine an inverse object preprocessing method based on the object preprocessing method in the object preprocessing layer;
[0145] The restoration position information calculation module is used to calculate the restoration position information of each text box in each processed object in the corresponding target object based on the inverse object preprocessing method and the detection position information of each text box in each processed object.
[0146] Furthermore, in the embodiment of the present application, each text box in each target object and each text box in each processed object are numbered based on the same rule; accordingly, the performance test result generation module includes:
[0147] The traversal module is used to traverse each processed object;
[0148] A current target object determination module, used to determine a current target object corresponding to a currently processed object;
[0149] A text box pair generating module, used for generating at least one text box pair based on the text boxes with the same label in the currently processed object and the current target object;
[0150] An IOR calculation module is used to calculate the IOR of two text boxes in each text box pair based on the restored position information of the currently processed object and the source position information of the current target object;
[0151] A first counting module, used for counting a first number of text box pairs corresponding to each target object;
[0152] A second statistical module, configured to count a second number of text box pairs whose intersection-over-union ratio is greater than a first threshold among the first number of text box pairs;
[0153] The first calculation module is used to generate a performance test result based on the first number and the second number.
[0154] Furthermore, the device also includes:
[0155] A processed object acquisition module, used for acquiring each processed object after being pre-processed by the object processing layer based on the target code;
[0156] A second annotation module is used to perform text box annotation on the processed objects corresponding to each target object based on the text detection information of each target object;
[0157] The second performance test result generating module is used to generate a performance test result of the text detection algorithm to be tested based on the processed object with text box annotation.
[0158] The device provided in the above embodiment can execute the method provided in any embodiment of the present application, and has the corresponding functional modules and beneficial effects of executing the method. For technical details not described in detail in the above embodiment, please refer to the method provided in any embodiment of the present application.
[0159] This embodiment also provides a computer-readable storage medium, in which at least one instruction, at least one program, code set or instruction set is stored, and the at least one instruction, at least one program, code set or instruction set is loaded by a processor and executed by any of the above methods of this embodiment.
[0160] This embodiment also provides a device, whose structure diagram can be seen in Fig.12The device 1200 may have relatively large differences due to different configurations or performances, and may include one or more central processing units (CPU) 1222 (for example, one or more processors) and memory 1232, one or more storage media 1230 (for example, one or more mass storage devices) storing application programs 1242 or data 1244. Among them, the memory 1232 and the storage medium 1230 may be short-term storage or persistent storage. The program stored in the storage medium 1230 may include one or more modules (not shown in the figure), and each module may include a series of instruction operations on the device. Furthermore, the central processing unit 1222 can be configured to communicate with the storage medium 1230 and execute a series of instruction operations in the storage medium 1230 on the device 1200. The device 1200 may also include one or more power supplies 1226, one or more wired or wireless network interfaces 1250, one or more input and output interfaces 1258, and / or, one or more operating systems 1241, such as Windows Server TM , Mac OS X TM , Unix TM , Linux TM , FreeBSD TM Etc. Any of the above methods in this embodiment can be based on Fig.12 The device shown is implemented.
[0161] This specification provides method operation steps as described in the embodiments or flow charts, but more or fewer operation steps may be included based on conventional or non-creative labor. The steps and sequence listed in the embodiments are only one way of executing the sequence of many steps and do not represent the only execution sequence. When the actual system or interrupt product is executed, it can be executed in sequence or in parallel according to the method shown in the embodiments or the drawings (for example, in a parallel processor or multi-threaded processing environment).
[0162] The structure shown in this embodiment is only a partial structure related to the scheme of the present application, and does not constitute a limitation on the device to which the scheme of the present application is applied. The specific device may include more or fewer components than shown, or combine certain components, or have different arrangements of components. It should be understood that the method, device, etc. disclosed in this embodiment can be implemented in other ways. For example, the device embodiment described above is only schematic. For example, the division of the modules is only a division of a logical function. There may be other division methods in actual implementation, such as multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be an indirect coupling or communication connection through some interfaces, devices or unit modules.
[0163] Based on this understanding, the technical solution of the present application, or the part that contributes to the prior art, or the whole or part of the technical solution can be embodied in the form of a software product, which is stored in a storage medium and includes several instructions for enabling a computer device (which can be a personal computer, a server, or a network device, etc.) to execute all or part of the steps of the method described in each embodiment of the present application. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), disk or optical disk, etc., various media that can store program codes.
[0164] Those skilled in the art may further appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed in this specification can be implemented in electronic hardware, computer software, or a combination of the two. In order to clearly illustrate the interchangeability of hardware and software, the composition and steps of each example have been generally described in the above description according to function. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professional and technical personnel can use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of this application.
[0165] As described above, the above embodiments are only used to illustrate the technical solutions of the present application, rather than to limit them. Although the present application has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or make equivalent replacements for some of the technical features therein. However, these modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present application.
Claims
1. A performance testing method for a text detection algorithm, characterized in that: include: Inject the target code into the text recognition model; The text recognition model includes a text detection layer for performing text detection based on a text detection algorithm to be tested; the target code includes a code for extracting output information of the text detection layer; Acquire target object samples, and annotate text information for each target object in the target object samples to obtain text annotation information corresponding to each target object; Inputting each target object sequentially into the text recognition model into which the target code has been injected, and extracting text detection information corresponding to each target object based on the target code; Based on the text detection information of each target object and the text annotation information of each target object, a performance test result of the text detection algorithm to be tested is generated.
2. The performance testing method of a text detection algorithm according to claim 1, characterized in that: The acquiring of target object samples and the tagging of text information for each target object in the target object samples to obtain text tagging information corresponding to each target object include: Determine the text area contained in each target object, and mark each text area to obtain a corresponding text box; Determining source position information of each text box in the target object; The source position information of each text box corresponding to the target object is used as the text annotation information of the target object.
3. The performance testing method of a text detection algorithm according to claim 1, characterized in that: The step of sequentially inputting each target object into a text recognition model into which the target code has been injected, and extracting text detection information corresponding to each target object based on the target code comprises: Compiling the text recognition model injected with the target code to generate an executable model; Taking each target object as input of the executable model in turn, and running the executable model; Based on the target code in the executable model, text detection information corresponding to each target object is extracted at the output end of the text detection layer.
4. The performance testing method of a text detection algorithm according to claim 2, characterized in that: The text recognition model further includes an object preprocessing layer; the text detection information is the detection position information of the text box obtained based on the text detection algorithm to be tested, and the detection position information of the text box is the position information of the detected text box in the processed object after passing through the object preprocessing layer; Accordingly, the generating of the performance test result of the text detection algorithm to be tested based on the text detection information of each target object and the text annotation information of each target object includes: For each processed object after being processed by the object preprocessing layer, restoring the position information of each text box in the processed object based on the detected position information of each text box in the processed object, so as to obtain the restored position information of each text box in the processed object; Determine a target object corresponding to the processed object, and obtain source position information of each text box in the target object; Based on a preset method, the restored position information of each text box in the processed object and the source position information of each text box in the target object, calculation is performed to obtain a performance test result of the text detection algorithm to be tested.
5. The performance testing method of a text detection algorithm according to claim 4, characterized in that: For each processed object processed by the object preprocessing layer, restoring the position information based on the detected position information of each text box in the processed object to obtain the restored position information of each text box in the processed object includes: Determining a reverse object preprocessing method based on the object preprocessing method in the object preprocessing layer; Based on the inverse object preprocessing method and the detected position information of each text box in each processed object, the restored position information of each text box in each processed object in the corresponding target object is calculated.
6. The performance testing method of a text detection algorithm according to claim 5, characterized in that: The method further comprises: labeling each text box in each target object and each text box in each processed object based on the same labeling rule; Accordingly, the performance test results of the text detection algorithm to be tested are obtained by calculating based on the preset method, the restored position information of each text box in the processed object, and the source position information of each text box in the target object, including: Traverse each processed object; determining a current target object corresponding to a currently processed object; Generate at least one text box pair based on the text boxes with the same label in the currently processed object and the current target object; In each text box pair, based on the restored position information of the currently processed object and the source position information of the current target object, the intersection-and-union ratio of the two text boxes in the text box pair is calculated; Counting a first number of text box pairs corresponding to each target object; Counting a second number of text box pairs whose intersection-over-union ratio is greater than a first threshold among the first number of text box pairs; A performance test result is generated based on the first number and the second number.
7. The performance testing method of a text detection algorithm according to claim 1, characterized in that: The target code also includes code for marking text boxes based on text detection information of each target object; Accordingly, the method further comprises: Based on the target code, obtaining each processed object after being preprocessed by the object preprocessing layer; Based on the text detection information of each target object, the processed objects corresponding to each target object are respectively marked with text boxes; Based on the processed objects that have been annotated with text boxes, a performance test result of the text detection algorithm to be tested is generated.
8. A performance testing device for a text detection algorithm, characterized in that: include: A target code injection module, used to inject the target code into the text recognition model; The text recognition model includes a text detection layer for performing text detection based on a text detection algorithm to be tested; the target code includes a code for extracting output information of the text detection layer; A target object sample acquisition module is used to acquire target object samples, annotate text information of each target object in the target object samples, and obtain text annotation information corresponding to each target object; A text detection information extraction module, used to sequentially input each target object into a text recognition model into which the target code has been injected, and extract text detection information corresponding to each target object based on the target code; The test result generation module is used to generate a performance test result of the text detection algorithm to be tested based on the text detection information of each target object and the text annotation information of each target object.
9. A device, characterized in that: The device includes a processor and a memory, wherein the memory stores at least one instruction or at least one program, and the at least one instruction or at least one program is loaded by the processor and executes the performance testing method of the text detection algorithm as described in any one of claims 1-7.
10. A computer storage medium, characterized in that: The storage medium stores at least one instruction or at least one program, and the at least one instruction or the at least one program is loaded by the processor and executes the performance testing method of the text detection algorithm as described in any one of claims 1-7.
