Table detection method, table detection model training method and device
By training the detection model, combining table line classification, cell regression and alignment features, the comprehensive loss value is calculated to update parameters, which solves the problem of the existing technology being unable to adapt to multi-scale and arbitrary length-width ratio table line detection, and improves detection accuracy and applicability.
Patent Information
- Application Number
- CN202111463289.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-12-02
- Publication Date
- 2024-09-27
- Estimated Expiration
- Not applicable · inactive patent
AI Technical Summary
The existing technology fails to fully consider the global characteristics of the table in table detection, resulting in the inability to adapt to multi-scale and arbitrary length-width ratio table line detection, and the algorithm and model are not consistent with the table characteristics.
By training the detection model, combining the table line classification results, cell regression results and table alignment features, the comprehensive loss value is calculated to update the model parameters, taking into account the overall characteristics and local information of the table, it is suitable for multi-scale and arbitrary length-width ratio table lines. detection.
The accuracy of table detection is improved, and the model's performance in detection is more objective and accurate. It is suitable for table line detection at multiple scales and with any length-to-width ratio.
Smart Images

Figure CN114399780B
Abstract
Description
Technical Field
[0001] The present invention relates to the field of big data, and in particular to a table detection method, a table detection model training method and a device. Background Art
[0002] In the application scenarios of big data and artificial intelligence, a large amount of information needs to be collected, processed and analyzed, and the data needs to be structured to discover the patterns in the data to guide production. However, information exists in various and unstructured forms. Tables are a common content form of text. A large amount of information exists in tables, which may exist in PDFs, web pages or images. If information is to be collected, detecting and identifying tables is a problem that needs to be solved at present.
[0003] The current methods basically use object detection or image segmentation methods to detect table lines using open source deep learning models. For example, based on the image segmentation method, each pixel of the table is predicted as a category, divided into foreground and background.
[0004] This type of method borrows from the field of image segmentation but does not consider the global features of the table, that is, it does not fully consider the characteristics of the table, so the algorithm and model cannot fit well. For example, this type of method cannot adapt to the table line detection of cells with multiple scales and arbitrary length and width ratios. Summary of the invention
[0005] In view of the problems existing in the prior art, the present invention provides a table detection method, a table detection model training method and a device.
[0006] The present invention provides a table detection method, comprising: obtaining a table image to be detected; inputting the table image to be detected into a trained detection model to obtain a table prediction segmentation map output by the detection model; determining the position information of a table prediction box according to the table prediction segmentation map; wherein the detection model is trained in the following manner: inputting training samples of known table lines and background into a detection model backbone network to obtain a table prediction segmentation map; according to the segmentation map obtained from the training samples, respectively calculating a first loss value based on a table line classification result, calculating a second loss value based on a cell regression result, and calculating a third loss value based on a table alignment feature; calculating a comprehensive loss value of the detection model according to the first loss value, the second loss value and the third loss value, and updating the parameters of the detection model according to the comprehensive loss value.
[0007] According to a table detection method of an embodiment of the present invention, the calculation of the first loss value based on the table line classification result includes: obtaining a probability map after logistic regression of the feature map, dividing the pixels in the probability map that are greater than a preset threshold and less than a preset threshold into a first category and a second category, and determining the number of pixels in the first category and the number of pixels in the second category respectively; using the ratio of the sum of the corresponding classification probabilities to the number of pixels in the first category when each pixel in the probability map is the first category, or the ratio of the sum of the corresponding classification probabilities to the number of pixels in the second category when the pixel is the second category, as weights for calculating the loss values of positive and negative samples, respectively, to calculate the first loss value.
[0008] According to a table detection method of one embodiment of the present invention, the calculation of the second loss value based on the cell regression result includes: calculating the second loss value according to the area of each cell of the predicted segmentation map output by the detection model and the actual area of the sample cell.
[0009] According to a table detection method of one embodiment of the present invention, the third loss value is calculated based on the table alignment feature, including: pairing two adjacent cells in the predicted segmentation map when the vertical overlap of two adjacent cells meets a preset condition or the Euclidean distance between coordinates is within a preset range; determining the degree of alignment of the paired cells based on the ratio of the vertical overlap to the height of the left and right adjacent cells and half; accumulating the degree of alignment of each row and dividing it by the number of rows in the table to obtain an average score in the row direction; and determining the third loss value based on the average score.
[0010] According to a table detection method of one embodiment of the present invention, the comprehensive loss value of the detection model is calculated based on the first loss value, the second loss value and the first loss value, including: determining the comprehensive loss value of the detection model based on a weighted value of the first loss value, the second loss value and the first loss value.
[0011] According to a table detection method of an embodiment of the present invention, when each pixel point in the probability map is of the first category, the ratio of the sum of the corresponding classification probabilities to the number of pixels of the first category, or when the pixel point is of the second category, the ratio of the sum of the corresponding classification probabilities to the number of pixels of the second category, respectively, are used as weights for calculating the loss values of positive and negative samples, and the first loss value is calculated, including:
[0012]
[0013] Among them, n pre+ and n pre- are the number of pixels in the first category and the number of pixels in the second category respectively; J pre+ and J pre- are the sum of the classification probabilities when the pixel is of the first and second categories respectively; y i represents the label of pixel i; pi It represents the probability that sample i is predicted to be a positive sample.
[0014] According to a table detection method according to an embodiment of the present invention, the second loss value is calculated based on the area of each cell of the predicted segmentation map output by the detection model and the actual area of the sample cell, including:
[0015]
[0016] Among them, A sum is the sum of the areas of the table cells in the actual annotation, A area-i represents the area of the i-th cell of the predicted segmentation map, and N represents the number of cells;
[0017] For each cell L reg :
[0018]
[0019] Among them, (x i ,y i ) and (x ip ,y ip ) are the true and predicted values of the four corner coordinates of the cell (x1, y1), (x2, y2), (x3, y3) and (x4, y4), and δ is a preset hyperparameter.
[0020] The present invention also provides a table detection model training method, comprising: inputting a training sample image with known table lines and background into a detection model backbone network, and extracting a predicted segmentation map; calculating a first loss value based on a table line classification result, a second loss value based on a cell regression result, and a third loss value based on a table alignment feature according to the segmentation map obtained from the training sample; calculating a comprehensive loss value of the detection model according to the first loss value, the second loss value, and the third loss value, and updating the parameters of the detection model according to the comprehensive loss value.
[0021] The present invention also provides a table detection device, comprising: an input module for acquiring a table image to be detected; a processing module for inputting the table image to be detected into a trained detection model to obtain a table prediction segmentation map output by the detection model; a detection module for determining the position information of a table prediction box according to the table prediction segmentation map; wherein the detection model is trained in the following manner: inputting training samples of known table lines and background into a detection model backbone network to obtain a table prediction segmentation map; according to the segmentation map obtained from the training samples, calculating a first loss value based on a table line classification result, calculating a second loss value based on a cell regression result, and calculating a third loss value based on a table alignment feature; calculating a comprehensive loss value of the detection model according to the first loss value, the second loss value and the third loss value, and updating the parameters of the detection model according to the comprehensive loss value.
[0022] The present invention also provides an electronic device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein when the processor executes the program, the steps of any of the table detection methods described above are implemented.
[0023] The present invention also provides a non-transitory computer-readable storage medium on which a computer program is stored. When the computer program is executed by a processor, the steps of any of the table detection methods described above are implemented.
[0024] The table detection method, table detection model training method and device provided by the present invention are obtained by training the detection model after comprehensively calculating the loss value based on the table line classification result, the cell regression result and the table alignment feature, which not only considers the global characteristics of the table segmentation task, but also obtains the local information of the cell regression and cell alignment tasks, that is, comprehensively considers the overall characteristics of the table, and the loss value calculation is more objective, so that the model has a higher accuracy when performing table detection. At the same time, the present invention is suitable for table line detection of multi-scale and arbitrary length-width ratio cells. BRIEF DESCRIPTION OF THE DRAWINGS
[0025] In order to more clearly illustrate the technical solutions in the present invention or the prior art, the following briefly introduces the drawings required for use in the embodiments or the description of the prior art. Obviously, the drawings described below are 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.
[0026] Figure 1 It is a flow chart of the table detection method provided by the present invention;
[0027] Figure 2 It is a schematic diagram of the network structure of the detection model provided by the present invention;
[0028] Figure 3 It is a schematic diagram of the output layer structure provided by the present invention;
[0029] Figure 4 It is a structural schematic diagram of the table detection device provided by the present invention;
[0030] Figure 5 It is a structural schematic diagram of the electronic device provided by the present invention. DETAILED DESCRIPTION
[0031] In order to make the purpose, technical solution and advantages of the present invention clearer, the technical solution of the present invention will be clearly and completely described below in conjunction with the drawings of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0032] The loss function commonly used in image segmentation is the binary cross entropy loss. The specific formula is as follows:
[0033]
[0034] Among them, y i represents the label of pixel i, the positive sample (the pixel is the foreground, that is, the pixel representing the straight line) is 1, and the negative sample is 0. i Indicates that sample i is predicted to be a positive sample, and N is the number of pixels of the sample.
[0035] The process of learning a binary classification task can be summarized as follows:
[0036] Score → s → sigmoid → p → cross entropy → L loss can be calculated as Right now
[0037] Substituting the corresponding formula into the above formula, we can get:
[0038]
[0039] Substitute the variables and the corresponding formula is:
[0040]
[0041] From the above formula, we can see that the calculation formula is simple and the value of the partial derivative depends on x i and [σ(s i )-y i], especially the latter has a greater impact, the larger the value, the worse the model. Therefore, the advantage of binary cross entropy loss is that it is not only easy to measure the effect of the model but also simple to derive. However, there are still problems with binary cross entropy loss for table line prediction: one is the imbalance of positive and negative samples, for example, the width of the table line occupies 2-4 pixels, and the background pixels account for the vast majority; the other is that this segmentation method does not fully consider the global characteristics of the table.
[0042] In order to solve the problem of table line detection by combining table feature design model and achieve the goal of table line detection that can adapt to multi-scale and arbitrary length and width ratio cells, a table detection method and device are proposed.
[0043] Combine the following Figure 1-Figure 5 The table detection method and device of the present invention are described. Figure 1 It is a flow chart of the table detection method provided by the present invention, such as Figure 1 As shown, the present invention provides a table detection method, comprising:
[0044] 101. Obtain an image of a table to be detected;
[0045] In the present invention, the table image to be detected is not limited to being obtained from image data, but can also be obtained from various text data. For example, the image to be detected containing a table is obtained from word or pdf.
[0046] 102. Input the table image to be detected into a trained detection model to obtain a table prediction segmentation map output by the detection model.
[0047] The present invention does not specifically limit the form of the detection model. For example, it can be the current deep network U-net, whose structure is as follows: Figure 2 As shown, the descriptions in the figure can refer to the specific instructions of the model and will not be repeated here.
[0048] The detection model of the present invention is trained in the following way:
[0049] The training samples of known table lines and backgrounds are input into the backbone network of the detection model to obtain a table prediction segmentation map; according to the segmentation map obtained from the training samples, a first loss value is calculated based on the table line classification results, a second loss value is calculated based on the cell regression results, and a third loss value is calculated based on the table alignment features; according to the first loss value, the second loss value and the third loss value, the comprehensive loss value of the detection model is calculated, and the parameters of the detection model are updated according to the comprehensive loss value.
[0050] Specifically, the output layer of the network training in the present invention adopts a multi-head mode, and the structure Figure 3 As shown. seg , Lcell-sum and S are the calculation parameters of the first loss value, the second loss value and the third loss value respectively. The multi-head structure has three branches from top to bottom, representing table line prediction, cell regression and table alignment. Among them, the input of table line prediction is a binary image with 1 positive sample and 0 negative sample. The feature map obtained by the backbone network is passed through the sigmoid function to obtain a probability map. When the probability value is greater than the set threshold, it indicates a positive sample, otherwise it is a negative sample. The positive sample is represented as a table line on the image, as can be seen in the branch output.
[0051] Cell regression can be achieved by directly calculating the coordinates of the four corner points of the cell. The input is the value of the four corner point coordinates normalized to [0,1]. The information of this feature layer not only contains the regression features but also the feature map of the table line prediction. The two features are superimposed together to complement each other. The information obtained by the point and line layers is richer.
[0052] In the cell alignment part, the feature information of points and lines is also integrated. The coordinates of the cell corners are calculated from the perspectives of points and lines respectively. The intersection of the row line and the column line predicted by the table line is the corner of the cell. The cell regression also obtains the coordinates of the cell corners. The two sets of corner points are calculated by nearest neighbor to get the final cell. The overlap and Euclidean distance are calculated on the final cell to perform cell matching and achieve table alignment.
[0053] Based on the above three branches, the corresponding first loss value, second loss value and third loss value are calculated respectively according to the feature map and the training sample.
[0054] Finally, a comprehensive loss value is determined based on the first loss value, the second loss value, and the third loss value, and the model parameters are updated, such as determining the comprehensive loss value of the detection model based on the weighted value.
[0055] Then, the parameters of the detection model are updated according to the calculated comprehensive loss value, such as the current gradient descent, back propagation and other methods.
[0056] The table image to be detected is input into the trained U-net network to extract features, and further processed to obtain the predicted segmentation map. The predicted segmentation map is the image output by the detection model that distinguishes the table lines and the background.
[0057] 103. Determine position information of a table prediction box according to the table prediction segmentation map.
[0058] The position information of the table prediction box may be the position information of the table line or the position information of the cell, for example, the vertex coordinates of each cell of the table line or the coordinates of each line of the table line, which is not specifically limited in the present invention.
[0059] The table detection method of the present invention is a detection model that is trained after comprehensively calculating the loss value based on the table line classification results, the cell regression results, and the table alignment features. It not only considers the global features of the table segmentation task, but also obtains the local information of the cell regression and cell alignment tasks, that is, it comprehensively considers the overall features of the table, and its loss value calculation is more objective, so that the model has a higher accuracy when performing table detection. At the same time, the present invention is suitable for table line detection of multi-scale and arbitrary length-width ratio cells.
[0060] In one embodiment, a first loss value is calculated based on a table line classification result, including: according to a probability map of the segmentation map obtained from the training sample before logistic regression, pixels in the probability map that are greater than a preset threshold and less than a preset threshold are divided into a first category and a second category, and the number of pixels in the first category and the number of pixels in the second category are determined respectively; when each pixel in the probability map is of the first category, the ratio of the corresponding sum of the classification probabilities to the number of pixels in the first category, or when the pixel is of the second category, the ratio of the corresponding sum of the classification probabilities to the number of pixels in the second category, are used as weights for calculating the loss values of positive and negative samples, respectively, to calculate the first loss value.
[0061] Specifically, the feature map after output undergoes logistic regression, such as sigmoid regression, and then a probability map is obtained, where
[0062] When the probability value is greater than the set threshold (between (0,1)), it is the first category and is recorded as J pre+ Otherwise, it is the second type, denoted by J pre- , and record the number of both cases, that is, n pre+ and n pre- Then, according to the two situations, the first loss value is calculated by taking the ratio of the sum of the corresponding probabilities and the number as the weights of the positive and negative samples. The above parameters can be automatically updated by the model during the training process. As the number of model iterations increases, the probability value of the first category gradually approaches 1, while the probability value of the second category is closer to 0, and n pre+ The number is much smaller than n pre- So after the division, the weight of the positive sample is greater than the weight of the negative sample, thus balancing the positive and negative samples.
[0063] Specifically, in one embodiment, when each pixel point in the probability map is the first class, the ratio of the sum of the corresponding classification probabilities to the number of pixels in the first class, or when the pixel point is the second class, the ratio of the sum of the corresponding classification probabilities to the number of pixels in the second class, are used as weights for calculating the positive and negative sample loss values, respectively, and the first loss value is calculated, including calculation according to the following formula:
[0064]
[0065] Among them, n pre+ and n pre- are the number of pixels in the first category and the number of pixels in the second category respectively; J pre+ and J pre- are the sum of the classification probabilities when the pixel is of the first and second categories respectively; y i represents the label of pixel i; p i It represents the probability that sample i is predicted to be a positive sample.
[0066] The above formula gives the calculation formula of the first loss value. From the above formula, it can be seen that as the number of model iterations increases, the value of the first category probability gradually approaches 1, while the value of the second category probability is closer to 0, and n pre+ The number is much smaller than n pre- So after the division, the weight of the positive sample is greater than the weight of the negative sample, thus balancing the positive and negative samples.
[0067] In one embodiment, calculating the second loss value based on the cell regression result includes: calculating the second loss value according to the area of each cell of the predicted segmentation map output by the detection model and the actual area of the sample cell.
[0068] Compared with a table composed of multiple cells, the coordinate positions of adjacent cells overlap. In the loss calculation process, the same value may be calculated only once, resulting in cell loss. In order to avoid this problem, the embodiment of the present invention introduces a method for calculating the area variable of the cell.
[0069] Specifically, in one embodiment, the calculating the second loss value according to the area of each cell of the prediction result and the actual area of the sample cell includes:
[0070]
[0071] Among them, A sum is the sum of the areas of the table cells in the actual annotation, A area-i represents the area of the i-th cell of the predicted segmentation map, and N represents the number of cells.
[0072] When the cell is lost A area-i The area is 0, L cell-sum The value of will also become smaller, thus reflecting the overall situation of the table.
[0073] For each cell, L reg The calculation method is as follows:
[0074]
[0075] Among them, (x i ,yi ) and (x ip ,y ip ) are the true and predicted values of the four corner coordinates of the cell (x1, y1), (x2, y2), (x3, y3) and (x4, y4), and δ is a preset hyperparameter.
[0076] Specifically, in the calculation of cell regression loss, the regression head is mainly used to improve the accuracy of the table cell coordinates. Common regression loss calculation methods include l1 and l2 norm losses, but since the gradient of the l1 loss function is relatively stable and cannot be differentiated at 0, it will affect the convergence speed of the model; the l2 loss function is greatly affected by outliers and may lead to a deviation in the model. Therefore, the present invention proposes a loss function based on the fusion of l1 and l2 norms. i -x ip In the interval |<1, the derivative is parabolic and its size changes with the change of x and y, thus avoiding the problem of constant gradient. i -x ip When |>=1, the derivative is relatively stable, and no abnormal points will appear, thus avoiding the influence of abnormal values on the model. The specific formula is as shown above. reg , δ is an adjustable hyperparameter.
[0077] In one embodiment, the calculation of the third loss value based on the table alignment feature includes: pairing two adjacent cells in the predicted segmentation map when the vertical overlap of two adjacent cells meets a preset condition or the Euclidean distance between the coordinates is within a preset range; determining the degree of alignment of the paired cells based on the ratio of the vertical overlap to the height of the left and right adjacent cells and half; adding up the degree of alignment of each row and dividing it by the number of rows in the table to obtain an average score in the row direction; and determining the third loss value based on the average score.
[0078] First, all cells in the table are paired. The pairing criteria are that the vertical overlap of two adjacent cells meets certain conditions or the Euclidean distance between coordinates is within a certain range. The calculation formulas for overlap and Euclidean distance are:
[0079]
[0080]
[0081] Among them, l vertical and l m They represent the vertical overlap length and the maximum value of the height of the cell and the adjacent cells, i.e. max(l i ,l i+1). (x1, y1), (x2, y2) represent the coordinates of the corner points of two adjacent cells. There are different combinations in the table, such as one-to-one and one-to-many, so it is necessary to calculate the Euclidean distance of at least one coordinate point to match the many-to-one situation; therefore, the higher the overlap and the smaller the Euclidean distance between the coordinate points, the greater the possibility of pairing with the current cell.
[0082] Calculate the alignment characteristics of paired cells by dividing the vertical overlap by half of the sum of the heights of the left and right adjacent cells. The specific expression is as follows:
[0083]
[0084] Among them, h l and h r They represent the height of the two cells on the left and right of this cell respectively. The higher the value is, the more accurate the table alignment is.
[0085] Each line of s row Add up and divide by the number of rows in the table to get the average score S in the row direction, that is:
[0086]
[0087] Among them, m represents the number of matched cell pairs. The larger S is, the better the matching effect is, and vice versa.
[0088] Finally, the third loss value is determined according to S.
[0089] In one embodiment, the comprehensive loss value of the detection model is calculated based on the first loss value, the second loss value and the first loss value, including: determining the comprehensive loss value of the detection model based on the weighted value of the first loss value, the second loss value and the first loss value.
[0090] Combining the loss functions of the three tasks of table line prediction, cell regression, and table alignment in the output layer, the final loss function is expressed as follows:
[0091]
[0092] Among them, α, β, and γ represent weights.
[0093] It can be seen that the new loss calculation method proposed by the present invention improves the existing imbalance problem and proposes a method for cell alignment. Therefore, the present invention not only realizes the table line prediction task, but also achieves the purpose of aligning each cell in the table.
[0094] The present invention also provides a table detection model training method, comprising:
[0095] After inputting the training sample images with known table lines and background into the backbone network of the detection model, a predicted segmentation map is extracted; according to the segmentation map obtained from the training samples, a first loss value is calculated based on the table line classification results, a second loss value is calculated based on the cell regression results, and a third loss value is calculated based on the table alignment features; according to the first loss value, the second loss value and the third loss value, the comprehensive loss value of the detection model is calculated, and the parameters of the detection model are updated according to the comprehensive loss value.
[0096] The training method of the detection model is to obtain the above detection model. Based on the current detection model, a more accurate recognition result can be obtained through the training method of the present invention. The specific training method can be referred to the embodiment of the above detection method, which will not be repeated here.
[0097] The table detection device provided by the present invention is described below. The table detection device described below and the table detection method described above can be referenced to each other.
[0098] Figure 4 Schematic diagram of the structure of the table detection device provided by the present invention. Figure 4 As shown, the table detection device includes: an input module 401, a processing module 402 and a detection module 403. The input module 401 is used to obtain a table image to be detected; the processing module 402 is used to input the table image to be detected into a trained detection model to obtain a table prediction segmentation map output by the detection model; the detection module 403 is used to determine the position information of the table prediction box according to the table prediction segmentation map; the detection model is trained in the following manner: inputting training samples of known table lines and backgrounds into the detection model backbone network to obtain a table prediction segmentation map; according to the segmentation map obtained from the training samples, respectively calculating a first loss value based on the table line classification result, calculating a second loss value based on the cell regression result, and calculating a third loss value based on the table alignment feature; calculating a comprehensive loss value of the detection model according to the first loss value, the second loss value and the third loss value, and updating the parameters of the detection model according to the comprehensive loss value.
[0099] In one device embodiment, the processing module 402 is also used to: divide the pixels in the probability map that are greater than a preset threshold and less than a preset threshold into the first category and the second category according to the probability map before the logical regression of the segmentation map obtained from the training sample, and determine the number of pixels in the first category and the number of pixels in the second category respectively; use the ratio of the sum of the corresponding classification probabilities to the number of pixels in the first category when each pixel in the probability map is the first category, or the ratio of the sum of the corresponding classification probabilities to the number of pixels in the second category when the pixel is the second category, as weights for calculating the loss values of positive and negative samples, respectively, to calculate the first loss value.
[0100] In one device embodiment, the processing module 402 is further used to calculate a second loss value based on the area of each cell of the predicted segmentation map output by the detection model and the actual area of the training sample cell.
[0101] In one device embodiment, the processing module 402 is also used to: pair two adjacent cells in the predicted segmentation map when the vertical overlap of two adjacent cells meets a preset condition or the Euclidean distance between the coordinates is within a preset range; determine the degree of alignment of the paired cells based on the ratio of the vertical overlap to the height of the left and right adjacent cells and half; add up the degree of alignment of each row and divide it by the number of rows in the table to obtain an average score in the row direction; and determine a third loss value based on the average score.
[0102] In one device embodiment, the processing module 402 is further used to determine a comprehensive loss value of the detection model according to the first loss value, the second loss value and a weighted value of the first loss value.
[0103] The device embodiments provided in the embodiments of the present invention are for implementing the above-mentioned method embodiments. For specific processes and detailed contents, please refer to the above-mentioned method embodiments, which will not be repeated here.
[0104] The table detection device provided by the embodiment of the present invention has a detection model that is trained after comprehensively calculating the loss value based on the table line classification result, the cell regression result, and the table alignment feature. It not only considers the global features of the table segmentation task, but also obtains the local information of the cell regression and cell alignment tasks, that is, it comprehensively considers the overall features of the table, and its loss value calculation is more objective, so that the model has a higher accuracy when performing table detection. At the same time, the present invention is suitable for table line detection of multi-scale and arbitrary length-width ratio cells.
[0105] Figure 5 is a schematic diagram of the structure of the electronic device provided by the present invention, such as Figure 5As shown, the electronic device may include: a processor 501, a communication interface 502, a memory 503 and a communication bus 504, wherein the processor 501, the communication interface 502 and the memory 503 communicate with each other through the communication bus 504. The processor 501 may call the logic instructions in the memory 503 to execute the table detection method, which includes: obtaining a table image to be detected; inputting the table image to be detected into a trained detection model to obtain a table prediction segmentation map output by the detection model; determining the position information of the table prediction box according to the table prediction segmentation map; wherein the detection model is trained in the following manner: inputting a training sample of known table lines and background into the detection model backbone network to obtain a table prediction segmentation map; according to the segmentation map obtained from the training sample, respectively calculating a first loss value based on the table line classification result, calculating a second loss value based on the cell regression result, and calculating a third loss value based on the table alignment feature; calculating a comprehensive loss value of the detection model according to the first loss value, the second loss value and the third loss value, and updating the parameters of the detection model according to the comprehensive loss value.
[0106] In addition, the logic instructions in the above-mentioned memory 503 can be implemented in the form of software functional units and can be stored in a computer-readable storage medium when sold or used as an independent product. Based on such an understanding, the technical solution of the present invention, in essence, or the part that contributes to the prior art or the part of the technical solution, can be embodied in the form of a software product, and the computer software product is stored in a storage medium, including several instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the method described in each embodiment of the present invention. The aforementioned storage medium includes: various media that can store program codes, such as a USB flash drive, a mobile hard disk, a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk.
[0107] On the other hand, the present invention also provides a computer program product, which includes a computer program stored on a non-transitory computer-readable storage medium, and the computer program includes program instructions. When the program instructions are executed by a computer, the computer can execute the table detection method provided by the above methods, and the method includes: obtaining a table image to be detected; inputting the table image to be detected into a trained detection model to obtain a table prediction segmentation map output by the detection model; determining the position information of the table prediction box according to the table prediction segmentation map; wherein the detection model is trained in the following manner: inputting training samples of known table lines and background into the detection model backbone network to obtain a table prediction segmentation map; according to the segmentation map obtained from the training samples, calculating a first loss value based on the table line classification result, calculating a second loss value based on the cell regression result, and calculating a third loss value based on the table alignment feature; calculating the comprehensive loss value of the detection model according to the first loss value, the second loss value and the third loss value, and updating the parameters of the detection model according to the comprehensive loss value.
[0108] On the other hand, the present invention also provides a non-transitory computer-readable storage medium having a computer program stored thereon, which is implemented by a processor to execute the table detection method provided in the above-mentioned embodiments, the method comprising: obtaining a table image to be detected; inputting the table image to be detected into a trained detection model to obtain a table prediction segmentation map output by the detection model; determining the position information of the table prediction box according to the table prediction segmentation map; wherein the detection model is trained in the following manner: inputting training samples of known table lines and background into a detection model backbone network to obtain a table prediction segmentation map; according to the segmentation map obtained from the training samples, calculating a first loss value based on the table line classification result, calculating a second loss value based on the cell regression result, and calculating a third loss value based on the table alignment feature; calculating a comprehensive loss value of the detection model according to the first loss value, the second loss value and the third loss value, and updating the parameters of the detection model according to the comprehensive loss value.
[0109] The device embodiments described above are merely illustrative, wherein the units described as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units, that is, they may be located in one place, or they may be distributed on multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the scheme of this embodiment. Ordinary technicians in this field can understand and implement it without paying creative labor.
[0110] Through the description of the above implementation methods, those skilled in the art can clearly understand that each implementation method can be implemented by means of software plus a necessary general hardware platform, and of course, it can also be implemented by hardware. Based on this understanding, the above technical solution is essentially or the part that contributes to the prior art can be embodied in the form of a software product, and the computer software product can be stored in a computer-readable storage medium, such as ROM / RAM, a disk, an optical disk, etc., including a number of instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to execute the methods described in each embodiment or some parts of the embodiments.
[0111] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit it. Although the present invention 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 invention.
Claims
1. A table detection method, characterized in that: include: Get the table image to be detected; Inputting the table image to be detected into the trained detection model to obtain a table prediction segmentation map output by the detection model; Determining position information of a table prediction box according to the table prediction segmentation map; The detection model is trained in the following way: Input the training samples of known table lines and background into the detection model backbone network to obtain the table prediction segmentation map; According to the segmentation map obtained from the training sample, a first loss value is calculated based on the table line classification result, a second loss value is calculated based on the cell regression result, and a third loss value is calculated based on the table alignment feature; Calculating a comprehensive loss value of a detection model according to the first loss value, the second loss value, and the third loss value, and updating parameters of the detection model according to the comprehensive loss value; The step of calculating the first loss value based on the table line classification result includes: According to the probability map before the logical regression of the segmentation map obtained from the training sample, the pixels in the probability map that are greater than a preset threshold and those that are less than a preset threshold are divided into a first category and a second category, and the number of pixels in the first category and the number of pixels in the second category are determined respectively; The first loss value is calculated by taking the ratio of the sum of the corresponding classification probabilities to the number of pixels in the first category when each pixel in the probability map is in the first category, or the ratio of the sum of the corresponding classification probabilities to the number of pixels in the second category when the pixel is in the second category, as the weights for calculating the loss values of the positive and negative samples respectively; The step of calculating the second loss value based on the cell regression result includes: Calculate the second loss value based on the area of each cell of the predicted segmentation map output by the detection model and the actual area of the training sample cell; The step of calculating the third loss value based on the table alignment feature includes: When the vertical overlap of two adjacent cells meets the preset condition or the Euclidean distance between the coordinates is within the preset range, two adjacent cells in the predicted segmentation map are paired; The degree of alignment of paired cells is determined based on the ratio of the vertical overlap to the height of the left and right adjacent cells and half; Add up the alignment of each row and divide it by the number of rows in the table to get the average score in the row direction; A third loss value is determined based on the average score.
2. The table detection method according to claim 1, characterized in that: When each pixel in the probability map is in the first category, the ratio of the sum of the corresponding classification probabilities to the number of pixels in the first category, or when the pixel is in the second category, the ratio of the sum of the corresponding classification probabilities to the number of pixels in the second category, are used as weights for calculating the loss values of positive and negative samples, respectively, to calculate the first loss value. include: Among them, n pre+ and n pre- are the number of pixels in the first category and the number of pixels in the second category respectively; J pre+ and J pre- are the sum of the classification probabilities when the pixel is of the first and second categories respectively; y i represents the label of pixel i; p i It represents the probability that sample i is predicted to be a positive sample.
3. The table detection method according to claim 1, characterized in that: The second loss value is calculated based on the area of each cell of the predicted segmentation map output by the detection model and the actual area of the sample cell. include: Among them, A sum is the sum of the areas of the table cells in the actual annotation, A area-i represents the area of the i-th cell of the predicted segmentation map, and N represents the number of cells; For each cell L reg : Among them, (x i ,y i ) and (x ip ,y ip ) are the true value and predicted value of the coordinates of the four corner points of the cell, and δ is a preset hyperparameter.
4. A table detection model training method, characterized in that: include: After the training sample image with known table lines and background is input into the detection model backbone network, the predicted segmentation map is extracted; According to the segmentation map obtained from the training sample, a first loss value is calculated based on the table line classification result, a second loss value is calculated based on the cell regression result, and a third loss value is calculated based on the table alignment feature; Calculate a comprehensive loss value of the detection model according to the first loss value, the second loss value, and the third loss value, and update parameters of the detection model according to the comprehensive loss value; The step of calculating the first loss value based on the table line classification result includes: According to the probability map before the logical regression of the segmentation map obtained from the training sample, the pixels in the probability map that are greater than a preset threshold and those that are less than a preset threshold are divided into a first category and a second category, and the number of pixels in the first category and the number of pixels in the second category are determined respectively; The first loss value is calculated by taking the ratio of the sum of the corresponding classification probabilities to the number of pixels in the first category when each pixel in the probability map is in the first category, or the ratio of the sum of the corresponding classification probabilities to the number of pixels in the second category when the pixel is in the second category, as the weights for calculating the loss values of the positive and negative samples respectively; The step of calculating the second loss value based on the cell regression result includes: Calculate the second loss value based on the area of each cell of the predicted segmentation map output by the detection model and the actual area of the training sample cell; The step of calculating the third loss value based on the table alignment feature includes: When the vertical overlap of two adjacent cells meets the preset condition or the Euclidean distance between the coordinates is within the preset range, two adjacent cells in the predicted segmentation map are paired; The degree of alignment of paired cells is determined based on the ratio of the vertical overlap to the height of the left and right adjacent cells and half; Add up the alignment of each row and divide it by the number of rows in the table to get the average score in the row direction; A third loss value is determined based on the average score.
5. A table detection device, characterized in that: include: An input module, used for acquiring an image of a table to be detected; A processing module, used for inputting the table image to be detected into a trained detection model to obtain a table prediction segmentation map output by the detection model; A detection module, used to determine the position information of the table prediction box according to the table prediction segmentation map; The detection model is trained in the following way: Input the training samples of known table lines and background into the detection model backbone network to obtain the table prediction segmentation map; According to the segmentation map obtained from the training sample, a first loss value is calculated based on the table line classification result, a second loss value is calculated based on the cell regression result, and a third loss value is calculated based on the table alignment feature; Calculating a comprehensive loss value of a detection model according to the first loss value, the second loss value, and the third loss value, and updating parameters of the detection model according to the comprehensive loss value; The step of calculating the first loss value based on the table line classification result includes: According to the probability map before the logical regression of the segmentation map obtained from the training sample, the pixels in the probability map that are greater than a preset threshold and those that are less than a preset threshold are divided into a first category and a second category, and the number of pixels in the first category and the number of pixels in the second category are determined respectively; The first loss value is calculated by taking the ratio of the sum of the corresponding classification probabilities to the number of pixels in the first category when each pixel in the probability map is in the first category, or the ratio of the sum of the corresponding classification probabilities to the number of pixels in the second category when the pixel is in the second category, as the weights for calculating the loss values of the positive and negative samples respectively; The step of calculating the second loss value based on the cell regression result includes: Calculate the second loss value based on the area of each cell of the predicted segmentation map output by the detection model and the actual area of the training sample cell; The step of calculating the third loss value based on the table alignment feature includes: When the vertical overlap of two adjacent cells meets the preset condition or the Euclidean distance between the coordinates is within the preset range, two adjacent cells in the predicted segmentation map are paired; The degree of alignment of paired cells is determined based on the ratio of the vertical overlap to the height of the left and right adjacent cells and half; Add up the alignment of each row and divide it by the number of rows in the table to get the average score in the row direction; A third loss value is determined based on the average score.
6. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that: When the processor executes the program, the steps of the table detection method according to any one of claims 1 to 3 or the table detection model training method according to claim 4 are implemented.
7. A non-transitory computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of the table detection method according to any one of claims 1 to 3 or the table detection model training method according to claim 4 are implemented.
