Sample generation method and device
By identifying and clustering bill images, and combining seals and background samples to generate real bill sample images, the problem of low accuracy of OCR+NER in non-standard bill recognition in the existing technology is solved, and efficient sample generation and models are achieved. Generalization ability.
Patent Information
- Application Number
- CN202410953322.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-16
- Publication Date
- 2024-10-15
- Estimated Expiration
- 2044-07-16
AI Technical Summary
In the existing technology, OCR+NER has low accuracy in identifying non-standard bills, requires a large number of manual annotation samples, leads to high resource consumption and low efficiency, and cannot effectively support the identification of bills with any appearance.
By identifying the bill image, clustering to obtain standard text information clusters, selecting the target standard text information to generate an initial bill sample image, and combining the seal and background sample images for fusion, updating to the target bill sample image, and adding it to the sample set of the recognition model .
The efficiency of sample generation is improved, the generated samples are more realistic, and the trained model has better generalization ability and can accurately identify bills with any display effect.
Smart Images

Figure CN118506380B_ABST
Abstract
Description
Technical Field
[0001] The embodiments of the present specification relate to the field of image processing technology, and in particular to a sample generation method and device. Background Art
[0002] With the development of computer technology, OCR recognition technology has been applied in more and more scenarios. The current industry has a good OCR recognition effect for standard materials, such as materials in a predetermined standard format, paper scans, etc. (such as invoices, order tickets, etc.). However, in actual application scenarios, due to objective reasons such as non-standard tickets, paper wrinkles, seal coverage, light and shadows caused by mobile phone photography, the OCR+NER technical solution is often difficult to accurately obtain the text type, content, and relationship between entities in the image, resulting in low accuracy of ticket recognition and inability to be applied to downstream businesses. In the prior art, in order to support the OCR+NER technical solution to recognize tickets of any appearance, it is usually necessary to construct a large number of samples through manual annotation, which are then used for training models to make the model have better recognition effects. However, most of the samples used in this process are real data, which requires a lot of human resources to complete the sample construction, and the sample construction efficiency is low. Therefore, an effective solution is urgently needed to solve the above problems. Summary of the invention
[0003] In view of this, the embodiments of this specification provide a sample generation method. One or more embodiments of this specification also relate to a sample generation device, a computing device, a computer-readable storage medium and a computer program product to solve the technical defects existing in the prior art.
[0004] According to a first aspect of an embodiment of this specification, a sample generation method is provided, including:
[0005] Recognize the bill images contained in the bill image set, and cluster the recognized multiple text information to obtain standard text information clusters;
[0006] Selecting target standard text information from the standard text information cluster according to a preset bill image generation strategy, and generating an initial bill sample image and a sample label corresponding to the initial bill sample image according to the target standard text information;
[0007] Selecting a seal sample image from a preset seal sample image set, and selecting a background sample image from a preset background sample image set; wherein the seal sample image is obtained by enhancing the seal pixel domain image, and the background sample image is generated according to a blank paper image and a prompt word corresponding to the blank paper image;
[0008] Fusion the initial bill sample image and the seal sample image according to the sample label to obtain an intermediate bill sample image;
[0009] The intermediate bill sample image is updated to a target bill sample image based on the background sample image, and the target bill sample image is added to a sample set corresponding to a bill recognition model.
[0010] Optionally, the identifying the bill images contained in the bill image set and clustering the identified multiple text information to obtain a standard text information cluster includes:
[0011] Acquire a bill image set, and identify the bill images contained in the bill image set by using a named entity recognition model to obtain a plurality of text information; wherein each bill image corresponds to at least one text information;
[0012] Performing data cleaning on the plurality of pieces of text information, and generating a plurality of pieces of standard text information according to the data cleaning results;
[0013] The plurality of pieces of standard text information are clustered according to the primary key information corresponding to each piece of standard text information to obtain a standard text information cluster.
[0014] Optionally, selecting target standard text information from the standard text information cluster according to a preset bill image generation strategy includes:
[0015] Selecting a set number of initial standard text information from the standard text information cluster according to a preset bill image generation strategy, and determining target primary key information;
[0016] The initial standard text information is updated using the target primary key information to obtain target standard text information.
[0017] Optionally, generating an initial bill sample image according to the target standard text information includes:
[0018] Determining bill image configuration information according to the bill image generation strategy, and determining bill image size information according to the target standard text information;
[0019] Constructing a bill image template based on the bill image configuration information and the bill image size information;
[0020] The target standard text information is added to the bill image template to obtain an initial bill sample image.
[0021] Optionally, the generation of any one candidate seal sample image included in the seal sample image set includes:
[0022] Acquire a seal image, and identify a seal color area and a seal background area in the seal image;
[0023] Performing color update on the seal color area and the seal background area in the seal image to obtain a mask seal image;
[0024] A candidate seal pixel domain image is constructed according to the seal image and the mask seal image, and a candidate seal sample image is obtained by performing enhancement processing on the candidate seal pixel domain image.
[0025] Optionally, the generation of any one candidate background sample image included in the background sample image set includes:
[0026] Acquire an initial blank paper image, and configure an image type prompt word for the initial blank paper image;
[0027] Inputting the initial blank paper image and the image type prompt word into an image diffusion model for processing to obtain at least two intermediate blank paper images;
[0028] A target blank paper image is selected from the at least two intermediate blank paper images as a candidate background sample image.
[0029] Optionally, the fusing the initial bill sample image and the seal sample image according to the sample label to obtain an intermediate bill sample image includes:
[0030] Determine text position information corresponding to the text area in the initial bill sample image according to the sample label;
[0031] Adjust the size of the seal sample image according to the text position information to obtain a target seal sample image;
[0032] Selecting a seal adding area for the target seal sample image in the initial bill sample image, wherein the seal adding area is located within the text area;
[0033] The target seal sample image is added to the seal adding area in the initial bill sample image, and an intermediate bill sample image is generated according to the adding result.
[0034] Optionally, updating the intermediate bill sample image to a target bill sample image based on the background sample image includes:
[0035] Obtaining a first pixel value corresponding to a pixel point in the background sample image, and obtaining a second pixel value corresponding to a pixel point in the intermediate bill sample image;
[0036] The first pixel value is adjusted according to a preset pixel value ratio, and a background sample image to be fused is generated according to the adjustment result; and the second pixel value is adjusted according to the pixel value ratio, and a bill sample image to be fused is generated according to the adjustment result;
[0037] The background sample image to be fused and the bill sample image to be fused are fused to obtain a target bill sample image.
[0038] Optionally, after the step of adding the target bill sample image to the sample set corresponding to the bill recognition model is performed, the method further includes:
[0039] Selecting a bill sample image from the sample set;
[0040] Inputting the bill sample image into a bill recognition model for processing to obtain predicted bill recognition information;
[0041] The bill recognition model is optimized according to the bill recognition label corresponding to the bill sample image and the predicted bill recognition information until a target bill recognition model that meets the training stop condition is obtained.
[0042] According to a second aspect of an embodiment of this specification, another sample generation method is provided, including:
[0043] Recognize the pet medical bill images contained in the pet medical bill image set, and cluster the recognized multiple text information to obtain a standard text information cluster;
[0044] Selecting target standard text information from the standard text information cluster according to a preset pet medical bill image generation strategy, and generating an initial pet medical bill sample image and a sample label corresponding to the initial pet medical bill sample image according to the target standard text information;
[0045] Selecting a seal sample image from a preset seal sample image set, and selecting a background sample image from a preset background sample image set; wherein the seal sample image is obtained by enhancing the seal pixel domain image, and the background sample image is generated according to a blank paper image and a prompt word corresponding to the blank paper image;
[0046] According to the sample label, the initial pet medical bill sample image and the seal sample image are merged to obtain an intermediate pet medical bill sample image;
[0047] The intermediate pet medical bill sample image is updated to a target pet medical bill sample image based on the background sample image, and the target pet medical bill sample image is added to a sample set corresponding to a pet medical bill recognition model.
[0048] According to a third aspect of an embodiment of this specification, there is provided a sample generation device, including:
[0049] A recognition module is configured to recognize the bill images contained in the bill image set, and cluster the recognized multiple text information to obtain a standard text information cluster;
[0050] A generation module is configured to select target standard text information from the standard text information cluster according to a preset bill image generation strategy, and generate an initial bill sample image and a sample label corresponding to the initial bill sample image according to the target standard text information;
[0051] A selection module is configured to select a seal sample image from a preset seal sample image set, and to select a background sample image from a preset background sample image set; wherein the seal sample image is obtained by enhancing the seal pixel domain image, and the background sample image is generated according to a blank paper image and a prompt word corresponding to the blank paper image;
[0052] a fusion module, configured to fuse the initial bill sample image and the seal sample image according to the sample label to obtain an intermediate bill sample image;
[0053] An updating module is configured to update the intermediate bill sample image to a target bill sample image based on the background sample image, and add the target bill sample image to a sample set corresponding to a bill recognition model.
[0054] According to a fourth aspect of the embodiments of this specification, another sample generation device is provided, including:
[0055] An image recognition module is configured to recognize the pet medical bill images contained in the pet medical bill image set, and cluster the recognized multiple text information to obtain a standard text information cluster;
[0056] An image generation module is configured to select target standard text information from the standard text information cluster according to a preset pet medical bill image generation strategy, and generate an initial pet medical bill sample image and a sample label corresponding to the initial pet medical bill sample image according to the target standard text information;
[0057] An image selection module is configured to select a seal sample image from a preset seal sample image set, and to select a background sample image from a preset background sample image set; wherein the seal sample image is obtained by enhancing the seal pixel domain image, and the background sample image is generated according to a blank paper image and a prompt word corresponding to the blank paper image;
[0058] a fusion image module, configured to fuse the initial pet medical bill sample image and the seal sample image according to the sample label to obtain an intermediate pet medical bill sample image;
[0059] The image updating module is configured to update the intermediate pet medical bill sample image to a target pet medical bill sample image based on the background sample image, and add the target pet medical bill sample image to a sample set corresponding to a pet medical bill recognition model.
[0060] According to a fifth aspect of an embodiment of this specification, a computing device is provided, including:
[0061] Memory and processor;
[0062] The memory is used to store computer executable instructions, and the processor is used to execute the computer executable instructions. When the computer executable instructions are executed by the processor, the steps of the above-mentioned sample generation method are implemented.
[0063] According to a sixth aspect of the embodiments of this specification, a computer-readable storage medium is provided, which stores computer-executable instructions, and when the instructions are executed by a processor, the steps of the above-mentioned sample generation method are implemented.
[0064] According to a seventh aspect of the embodiments of this specification, a computer program product is provided, including a computer program or instructions, which implement the steps of the above-mentioned sample generation method when executed by a processor.
[0065] The sample generation method provided in this embodiment can improve the sample generation efficiency and ensure that the generated samples are more realistic, so as to train a bill recognition model with better generalization ability in the model training stage. The bill images contained in the bill image set can be first recognized to obtain multiple text information according to the recognition results. After that, the multiple recognized text information can be clustered to obtain a standard text information cluster; on this basis, the target standard text information can be selected from the standard text information cluster according to the preset bill image generation strategy, and then the initial bill sample image and the sample label corresponding to the initial bill sample image can be generated according to the target standard text information. At this time, considering that the authenticity of the generated initial bill sample image is low and does not have the display effect of photographing the bill in a real scene, the seal sample image can be selected from the preset seal sample image set, and the background sample image can be selected from the preset background sample image set; wherein the seal sample image is obtained by enhancing the seal pixel domain image, and the background sample image is generated according to the blank paper image and the prompt word corresponding to the blank paper image. On this basis, the initial bill sample image and the seal sample image can be fused according to the sample label to obtain the intermediate bill sample image; the intermediate bill sample image obtained incorporates the seal content. Then, the intermediate bill sample image can be updated to the target bill sample image based on the background sample image, and finally the target bill sample image can be added to the sample set corresponding to the bill recognition model. In the sample stage of building the training bill recognition model, multiple text information can be obtained by identifying the bill image, and then the initial bill sample image can be generated by combining multiple text information, which can effectively expand the sample richness. After that, by fusing the background sample image and the seal sample image, the target bill sample image has a more realistic display effect. Therefore, as a sample training model, the model can have better generalization ability, and when recognizing bills with any display effect, it can have a more accurate recognition effect. BRIEF DESCRIPTION OF THE DRAWINGS
[0066] Figure 1 is a schematic diagram of a sample generation method provided by an embodiment of this specification;
[0067] Figure 2 is a flow chart of a sample generation method provided by an embodiment of this specification;
[0068] Figure 3a is a schematic diagram of a bill image in a sample generation method provided in an embodiment of this specification;
[0069] Figure 3b is a schematic diagram of an initial bill sample image in a sample generation method provided by an embodiment of this specification;
[0070] Figure 3c is a schematic diagram of a seal sample image in a sample generation method provided in an embodiment of the present specification;
[0071] Figure 3d is a schematic diagram of a background sample image in a sample generation method provided by an embodiment of this specification;
[0072] Figure 3e is a schematic diagram of an intermediate bill sample image in a sample generation method provided by an embodiment of the present specification;
[0073] Figure 4 is a schematic diagram of a target bill sample image in a sample generation method provided by an embodiment of this specification;
[0074] Figure 5 is a flow chart of another sample generation method provided by an embodiment of this specification;
[0075] Figure 6 is a schematic diagram of the structure of a sample generating device provided by an embodiment of this specification;
[0076] Figure 7 is a schematic diagram of the structure of another sample generating device provided by an embodiment of this specification;
[0077] Figure 8 It is a structural block diagram of a computing device provided by an embodiment of this specification. DETAILED DESCRIPTION
[0078] Many specific details are described in the following description to facilitate a full understanding of this specification. However, this specification can be implemented in many other ways than those described herein, and those skilled in the art can make similar generalizations without violating the connotation of this specification, so this specification is not limited to the specific implementation disclosed below.
[0079] The terms used in one or more embodiments of this specification are only for the purpose of describing specific embodiments, and are not intended to limit one or more embodiments of this specification. The singular forms of "a", "said" and "the" used in one or more embodiments of this specification and the appended claims are also intended to include plural forms, unless the context clearly indicates other meanings. It should also be understood that the term "and / or" used in one or more embodiments of this specification refers to and includes any or all possible combinations of one or more associated listed items.
[0080] It should be understood that although the terms first, second, etc. may be used to describe various information in one or more embodiments of this specification, this information should not be limited to these terms. These terms are only used to distinguish the same type of information from each other. For example, without departing from the scope of one or more embodiments of this specification, the first may also be referred to as the second, and similarly, the second may also be referred to as the first. Depending on the context, the word "if" as used herein may be interpreted as "at the time of" or "when" or "in response to determining".
[0081] In addition, it should be noted that the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, stored data, displayed data, etc.) involved in one or more embodiments of this specification are all information and data authorized by the user or fully authorized by all parties, and the collection, use and processing of relevant data must comply with the relevant laws, regulations and standards of the relevant countries and regions, and provide corresponding operation entrances for users to choose to authorize or refuse.
[0082] First, the terms involved in one or more embodiments of this specification are explained.
[0083] OCR: Optical Character Recognition, a technology that aims to convert text information in images or scanned documents into editable text data by analyzing them. This technology allows computer systems to understand and extract text from images so that these texts can be searched, edited and stored in a digital environment.
[0084] NER: Named Entity Recognition is a technology in the field of natural language processing (NLP). This technology aims to identify named entities from text. These entities can be words or phrases with specific meanings, such as names of people, places, organizations, dates, times, currencies, etc.
[0085] SDM: Stable Diffusion Model, is a model in the multimodal field with applications such as generating high-quality images through prompt words (text2img) and changing specified images through prompt words (text guidedimg2img).
[0086] LoRA: Low-Rank Adaptation of Large Language Models, is a technical solution to reduce the training cost of large models. The core is to freeze the parameters of the pre-trained model and add up block and down block layers in specific layers, and fine-tune the pre-trained model by fine-tuning the parameters of the newly added layers. For example, the number of training parameters in the original feature layer is n_in * n_out, the number of training parameters in the newly added down block is n_in * m, and the number of training parameters in the up block is m * n_out, where m << min(n_in, n_out), so as to achieve the goal of reducing the training cost. bbox: bounding box. In the fields of computer vision and image processing, a bounding box is a rectangular box used to frame or surround the position of the target object. This rectangular box is usually defined by four boundary parameters, including the coordinates of the upper left corner and the lower right corner, or the coordinates of the upper left corner and the length and width of the bbox.
[0087] Cocoformat: The data structure used by bbox. The specific structure is as follows: [x, y, height, width], which successively represents the starting coordinates (x, y) of the bbox, as well as the width: width and height: height of the bbox.
[0088] prompt: Prompt words, which are used to guide the training or generation of corresponding images in SDM. During the training of SDM, they are used as prompt words associated with the training set, and in the generation task, they are used to guide the generation of corresponding images.
[0089] negative_prompt: Negative prompt words, which refer to the content that is not expected to be generated in the SDM image generation task.
[0090] strength: A measure of the added noise. The higher the value, the more noise there is and the longer the denoising process.
[0091] HSV: "Hue, Saturation, Value" in the color space. This is a way of describing colors. Different from the RGB (Red, Green, Blue) color model, HSV is more in line with human perception of colors.
[0092] In this specification, a sample generation method is provided. This specification also relates to a sample generation device, a computing device, a computer-readable storage medium, and a computer program product, which will be described in detail one by one in the following embodiments.
[0093] See Figure 1As shown in the schematic diagram, the sample generation method provided in this embodiment can improve the sample generation efficiency and ensure that the generated samples are more realistic, so as to train a bill recognition model with better generalization ability in the model training stage. The bill images contained in the bill image set can be first recognized to obtain multiple text information according to the recognition results. After that, the multiple recognized text information can be clustered to obtain a standard text information cluster; on this basis, the target standard text information can be selected from the standard text information cluster according to the preset bill image generation strategy, and then the initial bill sample image and the sample label corresponding to the initial bill sample image can be generated according to the target standard text information. At this time, considering that the authenticity of the generated initial bill sample image is low and does not have the display effect of photographing the bill in the real scene, the seal sample image can be selected from the preset seal sample image set, and the background sample image can be selected from the preset background sample image set; wherein, the seal sample image is obtained by enhancing the seal pixel domain image, and the background sample image is generated according to the blank paper image and the prompt word corresponding to the blank paper image. On this basis, the initial bill sample image and the seal sample image can be fused according to the sample label to obtain the intermediate bill sample image; the intermediate bill sample image obtained incorporates the seal content. Then, the intermediate bill sample image can be updated to the target bill sample image based on the background sample image, and finally the target bill sample image can be added to the sample set corresponding to the bill recognition model. In the sample stage of building the training bill recognition model, multiple text information can be obtained by identifying the bill image, and then the initial bill sample image can be generated by combining multiple text information, which can effectively expand the sample richness. After that, by fusing the background sample image and the seal sample image, the target bill sample image has a more realistic display effect. Therefore, as a sample training model, the model can have better generalization ability, and when recognizing bills with any display effect, it can have a more accurate recognition effect.
[0094] See also Figure 2 , Figure 2 A flow chart of a sample generation method provided according to an embodiment of the present specification is shown, which specifically includes the following steps.
[0095] Step S202: identifying the bill images contained in the bill image set, and clustering the identified multiple text information to obtain standard text information clusters.
[0096] The sample generation method provided in this embodiment can be applied to the sample construction process in any bill recognition scenario, such as user medical bill recognition scenario, pet medical bill recognition scenario, daily necessities invoice recognition scenario, building materials invoice recognition scenario, etc. This embodiment takes the application of the sample generation method in the pet medical bill recognition scenario as an example to illustrate the above method. For descriptions of other scenarios, please refer to the same or corresponding descriptions in this embodiment, and this embodiment will not be repeated in detail here.
[0097] Specifically, the bill image set refers to a set of high-quality bill images, and the bill images contained in the set are real bill images. By constructing the target bill sample image based on the bill image, the constructed bill image can be guaranteed to be more realistic. Accordingly, the bill image recognition can be realized through the NER model recognition. Accordingly, the text information specifically refers to a piece of information obtained after the bill image is recognized, which is composed of the text content, category, and relationship contained in the bill image.
[0098] For example, a bill image such as Figure 3a As shown, by recognizing the bill image, multiple pieces of information can be obtained, among which the first piece of text information is {'Product Name':'Ordinary X-ray (DR electronic film, no film)', 'Invoice Price':'120.00', 'Quantity':'1', 'Subtotal':'120.00', 'Actual Amount':'118.49'}; the second piece of text information is {'Product Name':'Ordinary X-ray (DR electronic film, no film)', 'Invoice Price':'120.00' ,'Quantity':'1','Subtotal':'120.00','Actual amount collected':'118.49'}; the third text information is {'Product Name':'Subcutaneous Injection','Invoice Unit Price':'10.00','Quantity':'1','Subtotal':'10.00','Actual amount collected':'9.87'}, and the fourth text information is...; that is, each text information can be understood as an information structure composed of a line of related text content in the bill image.
[0099] Correspondingly, the standard text information cluster specifically refers to the cluster obtained after clustering multiple text information. Since the bill image set contains multiple bill images, after identifying each bill image, at least one text information corresponding to each bill image can be obtained, and then the recognition results of multiple bill images can obtain multiple text information. On this basis, considering that different bill images may have different formats and contain different text information, when clustering, it is actually clustered according to the primary key information corresponding to each text information, ensuring that the text information contained in the standard text information cluster obtained after clustering has the same primary key, and the obtained standard text information cluster can be one or more, so that when constructing the bill sample image later, the text information contained in each standard text information cluster can be combined to randomly combine the bill sample image for use.
[0100] Based on this, in order to improve the efficiency of sample generation and ensure that the generated samples are more realistic, and thus to achieve a bill recognition model with better generalization ability in the model training stage, the bill images contained in the bill image set can be first identified to obtain multiple text information based on the recognition results. After that, the multiple identified text information can be clustered to obtain a standard text information cluster; after obtaining the standard text information cluster, the bill sample image can be constructed and the text information can be selected from the cluster for use, thereby ensuring the richness of the constructed bill image.
[0101] Furthermore, when clustering multiple text information, in order to ensure that the constructed standard text information cluster can be used as the basic elements of the bill sample image and the constructed bill sample image is more consistent with the actual bill, the text information can be cleaned first. In this embodiment, the specific implementation method is as follows:
[0102] A bill image set is obtained, and the bill images contained in the bill image set are recognized through a named entity recognition model to obtain multiple text information; wherein each bill image corresponds to at least one text information; data cleaning is performed on the multiple text information, and multiple standard text information is generated according to the data cleaning results; the multiple standard text information are clustered according to the primary key information corresponding to each standard text information to obtain a standard text information cluster.
[0103] Specifically, the named entity recognition model specifically refers to a general NER recognition model, which can identify the text content, relationship, and category in the bill image, and then multiple text information can be obtained based on the recognition results. Correspondingly, data cleaning specifically refers to the processing of unified primary key information of multiple text information with the same representation but different forms, such as project name, medical project, and product name can be unified as project name, thereby achieving the purpose of standardizing text information. Correspondingly, standard text information is text information with more standard text form after data cleaning of text information. Correspondingly, primary key information specifically refers to the primary key corresponding to each information type, such as the bill contains project name {ordinary X-ray, subcutaneous injection, disposable urine pad...}, consumption amount {ordinary X-ray: 120 yuan; subcutaneous injection: 10 yuan; disposable urine pad: 5 yuan...}, etc., among which the project name and consumption amount are the primary key information.
[0104] Based on this, in order to make the bill sample images generated later more abundant and realistic, text information recognition and clustering processing can be performed first. At this time, a bill image set can be obtained first, and then each bill image contained in the bill image set can be recognized through a named entity recognition model. After obtaining at least one text information corresponding to each bill image, multiple text information can be obtained by combination. On this basis, in order to use more standard text information, multiple text information can be cleaned, and multiple standard text information can be generated according to the data cleaning results; on this basis, multiple standard text information can be clustered according to the primary key information corresponding to each standard text information, so that standard text information with the same primary key information can be formed into standard text information clusters, and then multiple standard text information clusters can be obtained for downstream use.
[0105] This embodiment takes the application of the sample generation method in the scenario of generating sample images of pet medical bills as an example to illustrate. Figure 3aThe multiple pet medical bill images shown (can be in PDF format). By inputting each pet medical bill image into the NER named entity recognition model for processing, multiple text information is obtained, namely the first text information {'Product Name':'Ordinary X-ray (DR electronic film, no film)', 'Invoice Unit Price':'120.00', 'Quantity':'1', 'Subtotal':'120.00', 'Actual Received Amount':'118.49'}; the second text information {'Product Name':'Ordinary X-ray (DR electronic film, no film)', 'invoice price':'120.00', 'quantity':'1', 'subtotal':'120.00', 'actual amount received':'118.49'}; the third text information is {'product name':'subcutaneous injection', 'invoice price':'10.00', 'quantity':'1', 'subtotal':'10.00', 'actual amount received':'9.87'}, the fourth text information is...etc.
[0106] Furthermore, pet medical bill image 1 contains the category elements of product name, billing unit price, quantity, subtotal, and actual amount received; pet medical bill image 2 contains the category elements of project name, unit price, quantity, subtotal, and actual amount received; pet medical bill image 3 contains the category elements of project name, commodity unit price, quantity, subtotal, and actual amount received...; that is, different bills have different descriptions, and in order to facilitate downstream use, the category elements can be unified by primary key. In other words, the names of the same type but different names on different bills are unified, and a primary key matching list can be generated for subsequent use, where the primary key matching list refers to a list that records the corresponding relationship between the primary keys before and after unification. Therefore, {project name, product name...} can be unified into project name, {unit price, commodity unit price, billing unit price...} can be unified into amount, etc. Multiple standard text information can be obtained by performing primary key unification.
[0107] Furthermore, considering that in real scenarios, each line of data in the bill is associated, including the price of a specific service, etc., in order to retain these associated information, all text information can be kept intact, and the multiple pieces of standard text information obtained above can be classified according to the same primary key information, such as setting the cluster center to a-type data, whose corresponding primary key includes {project name, unit price, quantity, amount}, and setting the cluster center to b-type data, whose corresponding primary key includes {project name, amount}. By classifying multiple pieces of text information according to the set cluster center, the standard text information cluster a corresponding to a-type data (the text information contained in the cluster all has project name, unit price, quantity, amount), and the standard text information cluster b corresponding to b-type data (the text information contained in the cluster all has project name, unit price). So that standard text information can be selected in the standard text information clusters a and b later for use in constructing bill sample images.
[0108] In addition, considering that the constructed standard text information cluster may contain a small amount of standard text information, in order to ensure that subsequent applications have the conditions for simulated random sampling, a quantity threshold can be set. By comparing the number of standard text information contained in each cluster with the quantity threshold, standard text information greater than the quantity threshold is selected as an alternative cluster for use, thereby generating richer and more realistic bill sample images for use.
[0109] In summary, by performing data cleaning on multiple text information and constructing a standard text information cluster based on this, it is possible to provide rich alternative content for use when subsequently constructing a bill sample image, and this part of the alternative content all comes from the bill image, thereby ensuring that the text content of the subsequently constructed bill sample image is more realistic.
[0110] Step S204 , selecting target standard text information from the standard text information cluster according to a preset bill image generation strategy, and generating an initial bill sample image and a sample label corresponding to the initial bill sample image according to the target standard text information.
[0111] Specifically, after the standard text information cluster is generated based on the bill image set, further, when constructing the bill sample image, the text content in the bill sample image can be generated first, so that the display effect of the bill sample image containing the text content can be changed later, so as to obtain a target bill sample image that is more similar to the actual bill image shooting effect. Therefore, when generating the text content in the image, the target standard text information that can be used as the text content in the bill can be selected from the standard text information cluster according to the preset bill image generation strategy. On this basis, the target standard text information can be combined to generate the initial bill sample image according to the combination result. At the same time, considering that the image at the current stage contains fewer external influence features, and the image will be used as a sample for model training in the subsequent construction, the sample label corresponding to the initial bill sample image can be determined at the same time, so that the sample pair can be constructed in combination with the initial bill sample image and the sample label for training the bill recognition model.
[0112] Among them, the bill image generation strategy specifically refers to the strategy of selecting target standard text information in the standard text information cluster and combining the selected target standard text information to generate the initial bill sample image. The strategy can record the quantity information of the selected target standard text information, the size information of the generated image, the font size information in the image, the font style information, the border information, etc.; that is, the bill image generation strategy records the setting information for generating the initial bill sample image. Accordingly, the target standard text information specifically refers to the standard text information selected in the standard text information cluster, and the selected standard text information can come from the same bill image or from different bill images, so as to ensure that the generated initial bill sample image is richer. Accordingly, the initial bill sample image specifically refers to combining the target standard text information according to the bill image generation strategy and generating an image with a bill format. It should be noted that the initial bill sample image only contains the bill text content and the bill format, and does not have the shooting effect corresponding to the real bill. Therefore, the initial bill sample image needs to be processed later to make it closer to the image shot by the real bill.
[0113] Correspondingly, the sample label specifically refers to the label generated by the model that needs to be trained according to the image. For example, if the bill sample image needs to be used as a sample to train the OCR recognition model, the sample label can be a text box that selects the text content contained in the image and the text content in the text box. For another example, if it is used as a sample to train the NER recognition model, the sample label can be a text box that selects the entity contained in the image, as well as entity category information, etc. In other words, for OCR tasks, if it is necessary to meet the OCR detection and recognition requirements, the dependent bbox can be detected through the first color box, and the text in the bbox is the recognition-dependent text content. For NER recognition, if it is necessary to meet NER entity recognition and association relationship recognition, the NER-dependent entity category can be selected through the second color box, and the NER-dependent entity content can be selected through the third color box.
[0114] In actual applications, the tag structure can be as follows: id: generate a unique token for the image; image: generate an image path; width: image width; height: image height; rotate: image rotation angle; header: generate a list of column name information contained in the sample; [{ id: unique id of the header in the image sample, type: header content, bbox: bbox, Cocoformat},]; nodes: generate a list of content information contained in the sample; [{ id: unique id of the node in the image sample, type: node type, one of the header types, value: specific information of the node, bbox: bbox, Cocoformat},]; edges: generate a list of sample association information; [ [id, id, id, id ], #The content in the list represents a single piece of data, #serving the downstream information extraction module].
[0115] During specific implementation, the structure and content of the sample label can be set according to actual needs, and this embodiment does not impose any limitation thereto.
[0116] Furthermore, when selecting the target standard text information, in order to make the constructed initial bill sample image have a more realistic display effect, the primary key information can be updated. In this embodiment, the specific implementation method is as follows:
[0117] According to the preset bill image generation strategy, a set number of initial standard text information is selected from the standard text information cluster, and target primary key information is determined; the initial standard text information is updated using the target primary key information to obtain target standard text information.
[0118] Specifically, the set quantity can be set according to the demand. Correspondingly, the target primary key information specifically refers to the primary key selected according to the primary key matching list, and by updating the initial annotation text information using the target primary key information, new text information, namely the target standard text information, can be obtained.
[0119] Based on this, when selecting standard text information from the standard text information cluster, in order to make the generated bill sample image richer and more realistic, you can first select a set number of initial standard text information from the standard text information cluster according to the preset bill image generation strategy, and at the same time, you can determine the target primary key information according to the primary key matching list; thereafter, you can use the target primary key information to update the initial standard text information, and you can obtain the target standard text information based on the update result, so that you can subsequently use the target standard text information to construct the bill sample image.
[0120] In summary, by selecting standard text information in the standard text information cluster and then updating the primary key information for the standard text information, it is possible to ensure that the generated target standard text information is the latest text information, so that the generated bill sample image is richer.
[0121] Furthermore, after obtaining the target standard text information, the initial bill sample image can be generated by combining the target standard text information. In order to ensure that the bill structure and form in the generated image are more similar to the real bill, a template can be constructed first and then the text information can be filled. In this embodiment, the specific implementation method is as follows:
[0122] Determine the bill image configuration information according to the bill image generation strategy, and determine the bill image size information according to the target standard text information; construct a bill image template based on the bill image configuration information and the bill image size information; add the target standard text information to the bill image template to obtain an initial bill sample image.
[0123] Specifically, the bill image configuration information specifically refers to the basic image information that needs to be configured for the bill sample image when constructing the bill sample image, such as the font size, font style, bill format, etc. in the bill. Correspondingly, the bill image size information specifically refers to the image size information calculated based on the size of the occupied area of the target standard text information. Correspondingly, the bill image template specifically refers to the constructed empty bill template, and text information has not been added yet.
[0124] Based on this, when constructing the initial bill image based on the selected target standard text information and the bill image generation strategy, in order to ensure that the currently constructed image can be used as the basic element for subsequent enhancement, the bill image configuration information can be determined according to the bill image generation strategy, and the bill image size information can also be determined according to the occupied size corresponding to the target standard text information; on this basis, the bill image template can be first constructed based on the bill image configuration information and the bill image size information; finally, the target standard text information is added to the bill image template, and the initial bill sample image can be generated according to the addition result, so that the sample can be constructed in combination with the initial bill sample image later.
[0125] In practical applications, after obtaining the standard text information clusters a and b, we can first randomly determine the single generation classification data category x (which can be category a or category b) according to the pet medical bill image generation strategy, and determine the number of rows of generated list data. Then, in order to ensure that the generated pet medical bill is more realistic, we can combine the data distribution of the pet whole material list content in the real scene, with a mean of 10, a variance of 6, a truncated normal random sampling number of rows n, and a sampling interval of [1,50]. Randomly extract n data from the standard text information cluster corresponding to the data category x as the basic content of the single generation sample. Determine that the selected n data include: n=1{project name: ordinary X-ray, unit price: 120.00, quantity: 1, amount: 118.49}; n=2{project name: disposable urine pad, unit price: 10.00, quantity: 1, amount: 8.49}; n=3…
[0126] Furthermore, combined with the primary key matching list obtained above, the actual primary key of a single sample can be randomly assigned. For example, the project name is assigned as the product name in this sample. Then, after updating n pieces of data, the updated n pieces of data are determined to be: n=1{product name: ordinary X-ray, unit price: 120.00, quantity: 1, amount: 118.49}; n=2{product name: disposable urine pad, unit price: 10.00, quantity: 1, amount: 8.49}; n=3…
[0127] Furthermore, in order to ensure that the generated pet medical bill image is more realistic, the font font_type can be randomly selected from the preset font list; the random font size font_size; the random range is [15,20]. At the same time, the bill format can be set to achieve a random row width height_buffer, and the random range is [5, int(font_size*2 / 3)]. The column spacing width_buffer=3*font_size. At the same time, the width and height of the image excluding the core text content can be configured to simulate the outer border part of the real bill h_buff=w_buff=200. After obtaining the above-mentioned bill image configuration information, the length im_height and width im_width of the current pet medical bill sample image to be generated can be calculated to generate the corresponding preset blank canvas to realize the subsequent addition of text content. In specific implementation, the length im_height and width im_width of the pet medical bill sample image can be calculated by the following formulas (1) and (2):
[0128] im_height = len(data)*(font_size+buffer_height) + font_size + h_buff(1)
[0129] im_width = max_row*font_size + (len(keylist)-1)*buffer_width + w_buff(2)
[0130] Among them, len(data) is the number of target standard text information selected, max_row is the maximum value of each primary key corresponding to a single diagnosis and treatment data, and to ensure that the final image width can accommodate all diagnosis and treatment information, len(keylist) is the number of primary keys of this diagnosis and treatment data, ensuring that there is a width of buffer_width between each type of primary key.
[0131] On this basis, the starting coordinates of the text of the n pieces of data that need to be added to the canvas can be randomly determined, table_start_x = random.randint(font_size,100); table_start_y = random.randint(1,100); and then, the updated n pieces of data are drawn to the preset canvas in turn, and the following is obtained: Figure 3b The initial pet medical bill sample image shown can also generate sample labels for the image. For OCR tasks, if the OCR detection and recognition requirements need to be met, the dependent bbox can be detected through the first color box, and the text in the bbox is the recognition dependent text content. For NER recognition, if NER entity recognition and association relationship recognition need to be met, the entity category that the NER depends on can be selected through the second color box, and the entity content that the NER depends on can be selected through the third color box. In the future, a more realistic sample image can be constructed based on the initial pet medical bill sample image and its corresponding sample label to train the pet medical bill recognition model.
[0132] In summary, by combining the bill image generation strategy with the method of first generating a bill image template and then adding the target standard text information, it can ensure that the generated initial bill sample image is more similar to the real bill style. On this basis, the target bill sample image is constructed to ensure that the generated image display effect is more realistic, and then when training the model, the model can have better generalization ability.
[0133] Step S206, selecting a seal sample image from a preset seal sample image set, and selecting a background sample image from a preset background sample image set; wherein the seal sample image is obtained by enhancing the seal pixel domain image, and the background sample image is generated according to a blank paper image and a prompt word corresponding to the blank paper image.
[0134] Specifically, after the initial bill sample image and its corresponding sample label are obtained as described above, further, in order to make the initial bill sample image have a more realistic display effect, so that the model can consider this part of external factors in the training stage, and thus have better bill recognition ability and generalization ability, the seal and background can be fused for the initial bill sample image, and the seal content can be added to the initial bill sample image, and the background setting can be adjusted, so that the target bill sample image finally obtained has a more realistic shooting effect. Therefore, before the seal image and background fusion are performed on the initial bill sample image, it is necessary to first select a more realistic seal sample image and background sample image, so as to achieve the desired effect. Therefore, the seal sample image can be selected from the preset seal sample image set, and the background sample image can be selected from the preset background sample image set; and the seal sample image is obtained by enhancing the seal pixel domain image, and the background sample image is generated according to the blank paper image and the prompt word corresponding to the blank paper image, so that the seal sample image and the background sample image have a more realistic seal shooting effect, as well as a background shooting effect (such as shadow effect, lighting effect, wrinkle effect, etc.).
[0135] The seal sample image set specifically refers to a set consisting of multiple seal sample images, and the seal sample images contained in the set are obtained by enhancing the seal pixel domain image, so that they can be smoother and more matched when fused with the initial bill sample image; the seal sample image is an image containing the stamped content. Correspondingly, the background sample image set specifically refers to a geometry consisting of multiple background sample images, and the background sample images contained in the set are blank paper images generated according to the prompt words, which do not have text content but have the shooting effects of paper, such as shadow effects, lighting effects, wrinkle effects, etc. The background sample image is a blank paper image that does not contain text and image content.
[0136] In specific implementation, in order to provide more abundant seal sample images for use in constructing bill sample images, the generation of any candidate seal sample image contained in the seal sample image set can be achieved in the following manner:
[0137] A seal image is obtained, and a seal color area and a seal background area are identified in the seal image; the seal color area and the seal background area in the seal image are updated in color to obtain a mask seal image; a candidate seal pixel domain image is constructed according to the seal image and the mask seal image, and a candidate seal sample image is obtained by enhancing the candidate seal pixel domain image.
[0138] Specifically, the seal image specifically refers to the image obtained after photographing the real seal. Correspondingly, the seal color area specifically refers to the area in the seal image associated with the seal content, and the seal background area specifically refers to the area in the seal image that is not associated with the seal content. Correspondingly, the mask seal image specifically refers to the seal image obtained after color updating of the seal color area and the seal background area. The seal image only has the seal content and the blank area, so that when fusion is achieved, interference caused by other contents in the seal image can be avoided. Correspondingly, the candidate seal pixel domain image specifically refers to the RGB pixel domain image obtained by pixel processing of the image.
[0139] Based on this, in order to be able to take into account the actual impact of the seal when constructing the target bill sample image, a seal sample image set can be constructed, and any candidate seal sample image contained in the seal sample image set can be generated in the following way: first, obtain the seal image, and identify the seal color area and the seal background area in the seal image; secondly, in order to ensure that the generated candidate seal sample image is not affected by other text content, the seal color area and the seal background area in the seal image can be updated in color to generate a mask seal image based on the update result; thirdly, construct a candidate seal pixel domain image based on the seal image and the mask seal image, and finally enhance the candidate seal pixel domain image to obtain the candidate seal sample image, and add it to the seal sample image set.
[0140] In practical applications, a batch of real sample images with seals can be prepared first, and then the seal area mask corresponding to this part of the seal image can be extracted based on the HSV seal, thereby forming a batch of pairs of real seal images and seal areas. It should be noted that in real scenes, seals are usually red or blue, but not pure colors. Therefore, compared with the RGB pixel space, HSV can more flexibly obtain the approximate red and blue parts. Therefore, the mask can be generated by setting the specified color area to white and the background area to black. Then, based on the mask and the real seal image pair, pixel processing can be performed to extract a batch of RGB pixel domain images of the seal. In this process, the RGB domain of the seal image can be binarized and the pixel value of the white part can be set to (1,1,1), and the pixel value of the black part can be set to (0,0,0). After that, the binary mask and the original real seal image pair are multiplied by the corresponding position pixel value to retain the real seal part in the original image. See Figure 3cAs shown in the schematic diagram, the seal image is first obtained, which contains not only the seal content but also the text content in the background. In order to enable the seal to be used in constructing the bill sample image, the seal image can be processed to obtain a mask seal image, and then binarization and seal extraction processing can be performed to obtain a seal sample image, which is added to the seal sample image set for use in constructing the bill sample image.
[0141] In addition, considering that the quality of the automatically generated candidate seal sample images varies, such as incomplete content or incorrect color of some seals, the generated candidate seal sample images can be screened by set rules and enhanced by rotating them at different angles, so that multiple seal sample images with higher quality can be obtained for use.
[0142] In summary, by combining the pixel domain image with the seal sample image when constructing the candidate seal sample image, the constructed seal sample image can be made more realistic and not affected by other text content. Therefore, when the bill sample image is subsequently fused, not only can the bill sample image have a more realistic display effect, but also the introduction of redundant image content can be avoided.
[0143] At the same time, in order to provide more abundant background sample images for use in constructing bill sample images, the generation of any candidate background sample image contained in the background sample image set can be achieved in the following way:
[0144] An initial blank paper image is obtained, and an image type prompt word is configured for the initial blank paper image; the initial blank paper image and the image type prompt word are input into an image diffusion model for processing to obtain at least two intermediate blank paper images; a target blank paper image is selected from the at least two intermediate blank paper images as a candidate background sample image.
[0145] Specifically, the initial blank paper image specifically refers to a blank paper image with a paper shooting effect. Accordingly, the image type prompt word specifically refers to a prompt word set for the initial blank paper image, and the prompt word can convert the initial blank paper image into a blank paper image with a different paper shooting effect. It can be understood that the image type prompt word is a prompt word for an extended paper shooting effect. Accordingly, the image expansion model is an SDM model, which is used to generate blank paper images with different paper shooting effects according to the prompt word. Accordingly, the target blank paper image is a blank paper image selected from multiple intermediate blank paper images.
[0146] Based on this, in order to be able to combine different paper effects to generate a bill image that is closer to the real shooting effect when constructing the target bill sample image, a background sample image set can be constructed first, and any candidate background sample image contained in the background sample image set can be generated in the following way: first, an initial blank paper image is obtained, and at the same time, an image type prompt word is configured for the initial blank paper image according to the paper effect that needs to be expanded; secondly, the initial blank paper image and the image type prompt word can be input into an image diffusion model with an image expansion effect for processing, so that at least two intermediate blank paper images can be obtained according to the processing results; on this basis, considering that different images have different paper display effects, and some may be out of touch with the actual situation, the target blank paper image can be selected from at least two intermediate blank paper images as a candidate background sample image, and then added to the background sample image set to support its use when constructing the bill sample image.
[0147] In practical applications, a set number (such as 100 sheets) of paper samples can be prepared, and the paper samples are required to contain no text content and can have a small amount of folds, all under different types of lighting and shadows, and the image quality can be selected as a high-definition version. This is used as the construction of the background sample image. Furthermore, the valid prompt can be configured in a targeted manner; where prompt can be {paper, blanked, shadowed, rectangle...}; by fine-tuning the LoRA model and iterating a set number of times, the paper type generation fine-tuning diffusion model SDM can be obtained. Then, by controlling parameters such as prompt, number of iterations, and random seeds, the background sample images can be batch generated through the paper type generation fine-tuning diffusion model SDM. In this process, you can first set the multi-accumulated prompt weighted combination, negative_prompt weighted combination, and grid tuning iterations, where the iteration number tuning range is [10,50], the grid tuning guidance_rescale, the tuning range is [0.3, 15], and the grid tuning strength, the tuning range is [0.1, 0.9]; so as to obtain the parameters with the best generation performance. On this basis, you can combine the five types of parameter combinations with the best generation effect with random seeds to batch generate paper-style images, that is, background sample images that can be added to the background sample image set.
[0148] In addition, considering that the paper-based fine-tuning diffusion model SDM has the problem of freedom in generating background sample images, some image generation effects do not meet the bill paper standard. Therefore, the generated background sample images can be screened by setting rules, and the background sample images that meet the rules can be retained for use. Figure 3dAs shown, different background sample images have different lighting effects, wrinkle effects, shadow effects, etc.
[0149] Based on this, when generating a pet medical bill sample image, you can select the following from the set generated by the seal sample image construction scheme: Figure 3c The seal sample image shown in the figure can also be selected from the set generated by the above background sample image scheme as follows Figure 3d The background sample image shown in the figure can be combined with Figure 3b The initial pet medical bill sample images shown generate more realistic pet medical bill sample images for training a pet medical bill recognition model.
[0150] In summary, by adopting the above scheme to construct candidate background sample images and candidate seal sample images, it can be ensured that the constructed sample images have a more realistic display effect. Based on this, combined with the initial bill sample image, a bill sample image that is closer to the actual shooting effect can be obtained. This ensures that the images added to the sample set can improve the model training accuracy.
[0151] Step S208: fusing the initial bill sample image and the seal sample image according to the sample label to obtain an intermediate bill sample image.
[0152] Specifically, after obtaining the initial bill sample image, background sample image and seal sample image as mentioned above, the initial bill sample image and the seal sample image can be further fused first. Considering that in actual scenarios, the seal is usually stamped on the text content, in order to present the actual situation through the generated intermediate bill sample image, the initial bill sample image and the seal sample image can be fused according to the sample label, so that the seal sample image can be overlaid on the text content in the initial bill sample image, and then the intermediate bill sample image is obtained for subsequent use.
[0153] The intermediate bill sample image specifically refers to a bill sample image in which a seal sample image is added to an initial bill sample image and a text content in the initial bill sample image is covered.
[0154] Furthermore, in the stage of fusing the seal sample image and the initial bill sample image, in order to avoid a poor display effect caused by a blunt combination, the two can be fused according to a set strategy. In this embodiment, the specific implementation method is as follows:
[0155] Determine text position information corresponding to a text area in the initial bill sample image according to the sample label; adjust the size of the seal sample image according to the text position information to obtain a target seal sample image; select a seal adding area for the target seal sample image in the initial bill sample image, wherein the seal adding area is located within the text area; add the target seal sample image to the seal adding area in the initial bill sample image, and generate an intermediate bill sample image according to the adding result.
[0156] Specifically, the text area specifically refers to the area in the initial bill sample image that corresponds to the target standard text information. Accordingly, the text position information specifically refers to the position corresponding to the target standard text information contained in the initial bill sample image, including but not limited to coordinate information, and the length and width information of the area. Correspondingly, the target seal sample image specifically refers to the seal sample image obtained by enlarging, reducing, stretching, etc. the seal sample image according to the text position information, so that it has a more matching size relationship with the initial bill sample image to avoid being too large or too small to highlight its unauthenticity. Correspondingly, the seal addition area is the area of the conditional target seal sample image in the initial bill sample image, and the area is located in the text area, thereby reflecting a more realistic stamping effect.
[0157] Based on this, when the initial bill sample image and the seal sample image are merged, in order to improve the real effect of the seal in the bill image, the text position information corresponding to the text area in the initial bill sample image can be determined according to the sample label; the text position information contains the text position and the length and width information of the coverage area, so the seal sample image can be resized according to the text position information to achieve a target seal sample image that is more harmonious with the initial bill sample image; then, a seal adding area can be selected for the target seal sample image in the initial bill sample image, and the seal adding area is within the text area; thereby, the target seal sample image is added to the seal adding area in the initial bill sample image, and an intermediate bill sample image can be generated according to the adding result.
[0158] In practical applications, when obtaining Figure 3c The stamp sample images shown and Figure 3bAfter the initial pet medical bill sample image shown, the position where the text content is located can be determined in the initial pet medical bill sample image first. That is to say, combined with the real scenario, the seal is often within the text area. Therefore, the position coordinates of the part where the text content is located in the initial pet medical bill sample image can be obtained by combining the sample labels obtained above. They are x0, y0, x1, y1 = min(new_bbox[:,0]), min(new_bbox[:,1]), max(new_bbox[:,2]), max(new_bbox[:,3]); where new_bbox is the coordinate array of all bboxes in the sample labels. The 0 and 1 in the second dimension represent the upper left coordinates of a single bbox, and 2 and 3 represent the lower right coordinates of a single bbox.
[0159] Furthermore, the size adaptation of the seal sample image and the text content area can be carried out. That is to say, to ensure that the seal can be added to the specified part of the text (such as the lower right part) in a suitable size, making the seal width w, height h, more matched with the text content width w_text and height h_text, the following relationship can be set: h_text / 4 < h < h_text / 2; w_text / 4 < w < w_text / 2; and a corresponding transformation size α is randomly generated within a reasonable range. α_h_min = h_text / (4*h); α_h_max = h_text / (2*h); α_w_min = w_text / (4*w); α_w_max = w_text / (2*w); where α = random.uniform(max(α_h_min, α_w_min), min(α_h_max, α_w_max)). Thus, the size of the seal sample image adapted to the initial pet medical bill sample image can be obtained as (int(alpha*w), int(alpha*h)).
[0160] Even further, to make the fused result more realistic, the position where the seal sample image is added can be set within the text content range in the initial pet medical bill sample image. Therefore, the starting coordinates of this set position can be randomly selected from the upper left coordinates and the lower right coordinates of the text content, and subtract the area required for the width and height of the seal. Finally, by adding the seal sample image to the specified position in the initial pet medical bill sample image, a white background with black text can be obtained. The RGB pixel value of the text part is (0, 0, 0), the RGB pixel value of the background part is (255, 255, 255), and the background part of the seal is also (255, 255, 255). The pixel value of the content part of the seal is between 0 and 255. At the same time, ensuring that the text part remains unchanged and taking the minimum pixel value at the corresponding position, the result can be obtained as Figure 3eThe intermediate bill sample image shown can be combined with the background sample image later to obtain a bill sample image that can be used as a sample.
[0161] In summary, when fusing the initial bill sample image with the seal sample image, in order to achieve a more realistic fusion effect, the seal sample image will be adjusted according to the actual situation, and the seal adding position will be determined, so as to ensure that the generated intermediate bill sample image is more realistic.
[0162] Step S210: updating the intermediate bill sample image to a target bill sample image based on the background sample image, and adding the target bill sample image to a sample set corresponding to a bill recognition model.
[0163] Specifically, after obtaining the intermediate bill sample image and the background sample image, further, considering the actual application scenario, the effect of photographing the bill may present different display effects due to issues such as paper wrinkles and shooting light. In order to present this effect when constructing the bill sample image, the intermediate bill sample image can be updated to the target bill sample image based on the background sample image, thereby ensuring that the obtained target bill sample image has a more realistic bill display shooting effect, and then the target bill sample image can be added to the sample set corresponding to the bill recognition model, so as to be used for subsequent training of the bill recognition model using the target bill sample image in the sample set.
[0164] The target bill sample image specifically refers to the bill sample image obtained by fusing the background sample image to the intermediate bill sample image, and the image has effects such as shadows, uneven lighting, and wrinkles. Correspondingly, the bill recognition model specifically refers to a model that can recognize bill images and extract entities or text content contained in the bill. Correspondingly, the sample set specifically refers to the sample set required for training the bill recognition model.
[0165] Furthermore, in order to make the fused result more similar to the real bill shooting effect, the image fusion processing can be performed by changing the pixel value. In this embodiment, the specific implementation method is as follows:
[0166] Obtain a first pixel value corresponding to a pixel point in the background sample image, and obtain a second pixel value corresponding to a pixel point in the intermediate bill sample image; adjust the first pixel value according to a preset pixel value ratio, and generate a background sample image to be fused according to the adjustment result; and adjust the second pixel value according to the pixel value ratio, and generate a bill sample image to be fused according to the adjustment result; fuse the background sample image to be fused and the bill sample image to be fused to obtain a target bill sample image.
[0167] Specifically, the first pixel value specifically refers to the pixel value corresponding to each pixel point in the background sample image, and correspondingly, the second pixel value specifically refers to the pixel value corresponding to each pixel point in the intermediate bill sample image. Correspondingly, the pixel value ratio relationship specifically refers to the preset pixel value weight ratio relationship, and the pixel value adjustment based on this relationship can make the adjusted and fused image have a more realistic display effect.
[0168] Based on this, when fusing the intermediate bill sample image with the background sample image, in order to improve the authenticity after fusion and improve the adaptability between the two, the first pixel value corresponding to the pixel point in the background sample image and the second pixel value corresponding to the pixel point in the intermediate bill sample image can be obtained first; thereafter, the first pixel value can be adjusted according to the preset pixel value ratio relationship, so as to generate the background sample image to be fused according to the adjustment result, and the second pixel value can be adjusted according to the pixel value ratio relationship, so as to generate the bill sample image to be fused according to the adjustment result; finally, by fusing the background sample image to be fused and the bill sample image to be fused, the target bill sample image that can be added to the sample set can be obtained according to the fusion result.
[0169] In practical applications, considering the generated Figure 3e In the middle bill sample image shown, the text is in pure black font and the pixel value is (0, 0, 0). To simulate the real environment and enhance the influence of background pixels, the pixel weights of the background sample image and the middle bill sample image can be controlled between 8:2 and 7:3. Based on this, the pixel values are adjusted and the two are merged to obtain the following: Figure 4 The target bill sample image shown has a more realistic bill display effect.
[0170] In summary, by fusing the intermediate bill sample image with the background sample image according to the pixel value ratio, it can be ensured that the fused image has a more realistic bill display effect. Training the model in this way can make the model more generalizable.
[0171] In addition, after the sample set is constructed, the bill recognition model can be trained using the bill sample images contained in the sample set. In this embodiment, the specific implementation method is as follows:
[0172] Select a bill sample image from the sample set; input the bill sample image into a bill recognition model for processing to obtain predicted bill recognition information; optimize the bill recognition model according to the bill recognition label corresponding to the bill sample image and the predicted bill recognition information until a target bill recognition model that meets the training stop condition is obtained.
[0173] That is to say, in the model training stage, bill sample images can be selected from the sample set; thereafter, the bill sample images can be input into the bill recognition model for processing, and then the predicted bill recognition information can be obtained based on the prediction results; on this basis, the loss value can be calculated based on the bill recognition label corresponding to the bill sample image and the predicted bill recognition information, and the bill recognition model can be optimized based on the loss value until the target bill recognition model that meets the training stop conditions is obtained.
[0174] In practical applications, the training stop condition can be set to an iteration number condition, a loss value comparison condition, or a validation set verification condition, and this embodiment does not make any limitation here.
[0175] The sample generation method provided in this embodiment can improve the sample generation efficiency and ensure that the generated samples are more realistic, so as to train a bill recognition model with better generalization ability in the model training stage. The bill images contained in the bill image set can be first recognized to obtain multiple text information according to the recognition results. After that, the multiple recognized text information can be clustered to obtain a standard text information cluster; on this basis, the target standard text information can be selected from the standard text information cluster according to the preset bill image generation strategy, and then the initial bill sample image and the sample label corresponding to the initial bill sample image can be generated according to the target standard text information. At this time, considering that the authenticity of the generated initial bill sample image is low and does not have the display effect of photographing the bill in a real scene, the seal sample image can be selected from the preset seal sample image set, and the background sample image can be selected from the preset background sample image set; wherein the seal sample image is obtained by enhancing the seal pixel domain image, and the background sample image is generated according to the blank paper image and the prompt word corresponding to the blank paper image. On this basis, the initial bill sample image and the seal sample image can be fused according to the sample label to obtain the intermediate bill sample image; the intermediate bill sample image obtained incorporates the seal content. Then, the intermediate bill sample image can be updated to the target bill sample image based on the background sample image, and finally the target bill sample image can be added to the sample set corresponding to the bill recognition model. In the sample stage of building the training bill recognition model, multiple text information can be obtained by identifying the bill image, and then the initial bill sample image can be generated by combining multiple text information, which can effectively expand the sample richness. After that, by fusing the background sample image and the seal sample image, the target bill sample image has a more realistic display effect. Therefore, as a sample training model, the model can have better generalization ability, and when recognizing bills with any display effect, it can have a more accurate recognition effect.
[0176] Corresponding to the above method embodiment, this specification also provides another sample generation method embodiment, Figure 5 FIG. 2 shows a flow chart of another sample generation method provided by an embodiment of the present specification. Figure 5 As shown, the method includes:
[0177] Step S502, identifying the pet medical bill images contained in the pet medical bill image set, and clustering the identified multiple text information to obtain a standard text information cluster;
[0178] Step S504, selecting target standard text information from the standard text information cluster according to a preset pet medical bill image generation strategy, and generating an initial pet medical bill sample image and a sample label corresponding to the initial pet medical bill sample image according to the target standard text information;
[0179] Step S506, selecting a seal sample image from a preset seal sample image set, and selecting a background sample image from a preset background sample image set; wherein the seal sample image is obtained by enhancing the seal pixel domain image, and the background sample image is generated according to a blank paper image and a prompt word corresponding to the blank paper image;
[0180] Step S508, fusing the initial pet medical bill sample image and the seal sample image according to the sample label to obtain an intermediate pet medical bill sample image;
[0181] Step S510: updating the intermediate pet medical bill sample image to a target pet medical bill sample image based on the background sample image, and adding the target pet medical bill sample image to a sample set corresponding to a pet medical bill recognition model.
[0182] Another sample generation method provided in this embodiment is applied to a pet medical scenario, and the related description contents can refer to the same or corresponding descriptions in the above embodiments, and this embodiment will not be elaborated in detail here.
[0183] The sample generation method provided in this embodiment can improve the sample generation efficiency and ensure that the generated samples are more realistic, so as to train a bill recognition model with better generalization ability in the model training stage. The bill images contained in the bill image set can be first recognized to obtain multiple text information according to the recognition results. After that, the multiple recognized text information can be clustered to obtain a standard text information cluster; on this basis, the target standard text information can be selected from the standard text information cluster according to the preset bill image generation strategy, and then the initial bill sample image and the sample label corresponding to the initial bill sample image can be generated according to the target standard text information. At this time, considering that the authenticity of the generated initial bill sample image is low and does not have the display effect of photographing the bill in a real scene, the seal sample image can be selected from the preset seal sample image set, and the background sample image can be selected from the preset background sample image set; wherein the seal sample image is obtained by enhancing the seal pixel domain image, and the background sample image is generated according to the blank paper image and the prompt word corresponding to the blank paper image. On this basis, the initial bill sample image and the seal sample image can be fused according to the sample label to obtain the intermediate bill sample image; the intermediate bill sample image obtained incorporates the seal content. Then, the intermediate bill sample image can be updated to the target bill sample image based on the background sample image, and finally the target bill sample image can be added to the sample set corresponding to the bill recognition model. In the sample stage of building the training bill recognition model, multiple text information can be obtained by identifying the bill image, and then the initial bill sample image can be generated by combining multiple text information, which can effectively expand the sample richness. After that, by fusing the background sample image and the seal sample image, the target bill sample image has a more realistic display effect. Therefore, as a sample training model, the model can have better generalization ability, and when recognizing bills with any display effect, it can have a more accurate recognition effect.
[0184] Corresponding to the above method embodiment, this specification also provides a sample generation device embodiment, Figure 6 FIG. 1 shows a schematic diagram of the structure of a sample generation device provided by an embodiment of the present specification. Figure 6 As shown, the device comprises:
[0185] The recognition module 602 is configured to recognize the bill images contained in the bill image set, and cluster the recognized multiple text information to obtain a standard text information cluster;
[0186] The generating module 604 is configured to select target standard text information from the standard text information cluster according to a preset bill image generating strategy, and generate an initial bill sample image and a sample label corresponding to the initial bill sample image according to the target standard text information;
[0187] The selection module 606 is configured to select a seal sample image from a preset seal sample image set, and select a background sample image from a preset background sample image set; wherein the seal sample image is obtained by enhancing the seal pixel domain image, and the background sample image is generated according to a blank paper image and a prompt word corresponding to the blank paper image;
[0188] A fusion module 608 is configured to fuse the initial bill sample image and the seal sample image according to the sample label to obtain an intermediate bill sample image;
[0189] The updating module 610 is configured to update the intermediate bill sample image to a target bill sample image based on the background sample image, and add the target bill sample image to a sample set corresponding to the bill recognition model.
[0190] In an optional embodiment, the identification module 602 is further configured to:
[0191] A bill image set is obtained, and the bill images contained in the bill image set are recognized through a named entity recognition model to obtain multiple text information; wherein each bill image corresponds to at least one text information; data cleaning is performed on the multiple text information, and multiple standard text information is generated according to the data cleaning results; the multiple standard text information are clustered according to the primary key information corresponding to each standard text information to obtain a standard text information cluster.
[0192] In an optional embodiment, the generating module 604 is further configured to:
[0193] According to the preset bill image generation strategy, a set number of initial standard text information is selected from the standard text information cluster, and target primary key information is determined; the initial standard text information is updated using the target primary key information to obtain target standard text information.
[0194] In an optional embodiment, the generating module 604 is further configured to:
[0195] Determine the bill image configuration information according to the bill image generation strategy, and determine the bill image size information according to the target standard text information; construct a bill image template based on the bill image configuration information and the bill image size information; add the target standard text information to the bill image template to obtain an initial bill sample image.
[0196] In an optional embodiment, the generation of any candidate seal sample image included in the seal sample image set includes:
[0197] A seal image is obtained, and a seal color area and a seal background area are identified in the seal image; the seal color area and the seal background area in the seal image are updated in color to obtain a mask seal image; a candidate seal pixel domain image is constructed according to the seal image and the mask seal image, and a candidate seal sample image is obtained by enhancing the candidate seal pixel domain image.
[0198] In an optional embodiment, the generation of any one candidate background sample image included in the background sample image set includes:
[0199] An initial blank paper image is obtained, and an image type prompt word is configured for the initial blank paper image; the initial blank paper image and the image type prompt word are input into an image diffusion model for processing to obtain at least two intermediate blank paper images; a target blank paper image is selected from the at least two intermediate blank paper images as a candidate background sample image.
[0200] In an optional embodiment, the fusion module 608 is further configured to:
[0201] Determine text position information corresponding to a text area in the initial bill sample image according to the sample label; adjust the size of the seal sample image according to the text position information to obtain a target seal sample image; select a seal adding area for the target seal sample image in the initial bill sample image, wherein the seal adding area is located within the text area; add the target seal sample image to the seal adding area in the initial bill sample image, and generate an intermediate bill sample image according to the adding result.
[0202] In an optional embodiment, the updating module 610 is further configured to:
[0203] Obtain a first pixel value corresponding to a pixel point in the background sample image, and obtain a second pixel value corresponding to a pixel point in the intermediate bill sample image; adjust the first pixel value according to a preset pixel value ratio, and generate a background sample image to be fused according to the adjustment result; and adjust the second pixel value according to the pixel value ratio, and generate a bill sample image to be fused according to the adjustment result; fuse the background sample image to be fused and the bill sample image to be fused to obtain a target bill sample image.
[0204] In an optional embodiment, the device further comprises:
[0205] The model training module is configured to select a bill sample image from the sample set; input the bill sample image into the bill recognition model for processing to obtain predicted bill recognition information; and optimize the bill recognition model according to the bill recognition label corresponding to the bill sample image and the predicted bill recognition information until a target bill recognition model that meets the training stop condition is obtained.
[0206] The sample generation device provided in this embodiment can improve the sample generation efficiency and ensure that the generated samples are more realistic, so as to train a bill recognition model with better generalization ability in the model training stage. The bill images contained in the bill image set can be first recognized to obtain multiple text information according to the recognition results. After that, the multiple recognized text information can be clustered to obtain a standard text information cluster; on this basis, the target standard text information can be selected from the standard text information cluster according to the preset bill image generation strategy, and then the initial bill sample image and the sample label corresponding to the initial bill sample image can be generated according to the target standard text information. At this time, considering that the authenticity of the generated initial bill sample image is low and does not have the display effect of photographing the bill in the real scene, the seal sample image can be selected from the preset seal sample image set, and the background sample image can be selected from the preset background sample image set; wherein, the seal sample image is obtained by enhancing the seal pixel domain image, and the background sample image is generated according to the blank paper image and the prompt word corresponding to the blank paper image. On this basis, the initial bill sample image and the seal sample image can be fused according to the sample label to obtain the intermediate bill sample image; the intermediate bill sample image obtained incorporates the seal content. Then, the intermediate bill sample image can be updated to the target bill sample image based on the background sample image, and finally the target bill sample image can be added to the sample set corresponding to the bill recognition model. In the sample stage of building the training bill recognition model, multiple text information can be obtained by identifying the bill image, and then the initial bill sample image can be generated by combining multiple text information, which can effectively expand the sample richness. After that, by fusing the background sample image and the seal sample image, the target bill sample image has a more realistic display effect. Therefore, as a sample training model, the model can have better generalization ability, and when recognizing bills with any display effect, it can have a more accurate recognition effect.
[0207] The above is a schematic scheme of a sample generation device of this embodiment. It should be noted that the technical scheme of the sample generation device and the technical scheme of the sample generation method described above are of the same concept, and the details not described in detail in the technical scheme of the sample generation device can be referred to the description of the technical scheme of the sample generation method described above.
[0208] Corresponding to the above method embodiment, this specification also provides another sample generation device embodiment, Figure 7 FIG. 2 shows a schematic diagram of the structure of another sample generation device provided by an embodiment of the present specification. Figure 7 As shown, the device comprises:
[0209] The image recognition module 702 is configured to recognize the pet medical bill images contained in the pet medical bill image set, and cluster the recognized multiple text information to obtain a standard text information cluster;
[0210] The image generation module 704 is configured to select target standard text information from the standard text information cluster according to a preset pet medical bill image generation strategy, and generate an initial pet medical bill sample image and a sample label corresponding to the initial pet medical bill sample image according to the target standard text information;
[0211] The image selection module 706 is configured to select a seal sample image from a preset seal sample image set, and select a background sample image from a preset background sample image set; wherein the seal sample image is obtained by enhancing the seal pixel domain image, and the background sample image is generated according to a blank paper image and a prompt word corresponding to the blank paper image;
[0212] The fusion image module 708 is configured to fuse the initial pet medical bill sample image and the seal sample image according to the sample label to obtain an intermediate pet medical bill sample image;
[0213] The image updating module 710 is configured to update the intermediate pet medical bill sample image to a target pet medical bill sample image based on the background sample image, and add the target pet medical bill sample image to a sample set corresponding to a pet medical bill recognition model.
[0214] The sample generation device provided in this embodiment can improve the sample generation efficiency and ensure that the generated samples are more realistic, so as to train a bill recognition model with better generalization ability in the model training stage. The bill images contained in the bill image set can be first recognized to obtain multiple text information according to the recognition results. After that, the multiple recognized text information can be clustered to obtain a standard text information cluster; on this basis, the target standard text information can be selected from the standard text information cluster according to the preset bill image generation strategy, and then the initial bill sample image and the sample label corresponding to the initial bill sample image can be generated according to the target standard text information. At this time, considering that the authenticity of the generated initial bill sample image is low and does not have the display effect of photographing the bill in the real scene, the seal sample image can be selected from the preset seal sample image set, and the background sample image can be selected from the preset background sample image set; wherein, the seal sample image is obtained by enhancing the seal pixel domain image, and the background sample image is generated according to the blank paper image and the prompt word corresponding to the blank paper image. On this basis, the initial bill sample image and the seal sample image can be fused according to the sample label to obtain the intermediate bill sample image; the intermediate bill sample image obtained incorporates the seal content. Then, the intermediate bill sample image can be updated to the target bill sample image based on the background sample image, and finally the target bill sample image can be added to the sample set corresponding to the bill recognition model. In the sample stage of building the training bill recognition model, multiple text information can be obtained by identifying the bill image, and then the initial bill sample image can be generated by combining multiple text information, which can effectively expand the sample richness. After that, by fusing the background sample image and the seal sample image, the target bill sample image has a more realistic display effect. Therefore, as a sample training model, the model can have better generalization ability, and when recognizing bills with any display effect, it can have a more accurate recognition effect.
[0215] The above is a schematic scheme of another sample generation device of this embodiment. It should be noted that the technical scheme of the sample generation device and the technical scheme of the above sample generation method belong to the same concept, and the details not described in detail in the technical scheme of the sample generation device can be referred to the description of the technical scheme of the above sample generation method.
[0216] Figure 8 The block diagram of a computing device 800 according to an embodiment of the present specification is shown. The components of the computing device 800 include but are not limited to a memory 810 and a processor 820. The processor 820 is connected to the memory 810 via a bus 830, and a database 850 is used to store data.
[0217] The computing device 800 also includes an access device 840 that enables the computing device 800 to communicate via one or more networks 860. Examples of these networks include a public switched telephone network (PSTN), a local area network (LAN), a wide area network (WAN), a personal area network (PAN), or a combination of communication networks such as the Internet. The access device 840 may include one or more of any type of network interface (e.g., a network interface card (NIC)) of wired or wireless, such as an IEEE 802.11 wireless local area network (WLAN) wireless interface, a world-wide interoperability for microwave access (Wi-MAX) interface, an Ethernet interface, a universal serial bus (USB) interface, a cellular network interface, a Bluetooth interface, and a near field communication (NFC).
[0218] In one embodiment of the present specification, the above components of the computing device 800 and Figure 8 Other components not shown in the figure may also be connected to each other, for example, via a bus. It should be understood that Figure 8 The computing device structure block diagram shown is only for the purpose of illustration, and is not intended to limit the scope of this specification. Those skilled in the art can add or replace other components as needed.
[0219] The computing device 800 may be any type of stationary or mobile computing device, including a mobile computer or mobile computing device (e.g., a tablet computer, a personal digital assistant, a laptop computer, a notebook computer, a netbook, etc.), a mobile phone (e.g., a smart phone), a wearable computing device (e.g., a smart watch, smart glasses, etc.), or other types of mobile devices, or a stationary computing device such as a desktop computer or a personal computer (PC). The computing device 800 may also be a mobile or stationary server.
[0220] The processor 820 is used to execute the following computer executable instructions, which implement the steps of the above-mentioned sample generation method when executed by the processor.
[0221] The above is a schematic scheme of a computing device of this embodiment. It should be noted that the technical scheme of the computing device and the technical scheme of the above sample generation method belong to the same concept, and the details not described in detail in the technical scheme of the computing device can be referred to the description of the technical scheme of the above sample generation method.
[0222] An embodiment of the present specification further provides a computer-readable storage medium storing computer-executable instructions, which can implement the steps of the above-mentioned sample generation method when executed by a processor.
[0223] The above is a schematic scheme of a computer-readable storage medium of this embodiment. It should be noted that the technical scheme of the storage medium and the technical scheme of the sample generation method described above are of the same concept, and the details not described in detail in the technical scheme of the storage medium can be referred to the description of the technical scheme of the sample generation method described above.
[0224] An embodiment of the present specification further provides a computer program product, including a computer program or instructions, which implement the steps of the above-mentioned sample generation method when executed by a processor.
[0225] The above is a schematic solution of a computer program product of this embodiment. It should be noted that the technical solution of the computer program product and the technical solution of the sample generation method described above are of the same concept, and the details not described in detail in the technical solution of the computer program product can be found in the description of the technical solution of the sample generation method described above.
[0226] The above is a description of a specific embodiment of the specification. Other embodiments are within the scope of the appended claims. In some cases, the actions or steps recorded in the claims can be performed in an order different from that in the embodiments and still achieve the desired results. In addition, the processes depicted in the drawings do not necessarily require the specific order or continuous order shown to achieve the desired results. In some embodiments, multitasking and parallel processing are also possible or may be advantageous.
[0227] The computer instructions include computer program codes, which may be in source code form, object code form, executable files or some intermediate forms, etc. The computer-readable medium may include: any entity or device capable of carrying the computer program code, recording medium, USB flash drive, mobile hard disk, magnetic disk, optical disk, computer memory, read-only memory (ROM), random access memory (RAM), electric carrier signal, telecommunication signal and software distribution medium, etc. It should be noted that the content contained in the computer-readable medium may be appropriately increased or decreased according to the requirements of patent practice. For example, in some regions, according to patent practice, computer-readable media do not include electric carrier signals and telecommunication signals.
[0228] It should be noted that, for the above-mentioned method embodiments, for the sake of simplicity of description, they are all expressed as a series of action combinations, but those skilled in the art should be aware that the embodiments of this specification are not limited by the order of the actions described, because according to the embodiments of this specification, some steps can be performed in other orders or simultaneously. Secondly, those skilled in the art should also be aware that the embodiments described in the specification are all preferred embodiments, and the actions and modules involved are not necessarily required by the embodiments of this specification.
[0229] In the above embodiments, the description of each embodiment has its own emphasis. For parts that are not described in detail in a certain embodiment, reference can be made to the relevant descriptions of other embodiments.
[0230] The preferred embodiments of this specification disclosed above are only used to help explain this specification. The optional embodiments do not describe all the details in detail, nor do they limit the invention to the specific implementation methods described. Obviously, many modifications and changes can be made according to the content of the embodiments of this specification. This specification selects and specifically describes these embodiments in order to better explain the principles and practical applications of the embodiments of this specification, so that technicians in the relevant technical field can understand and use this specification well.
Claims
1. A sample generation method, characterized in that: include: Acquire a bill image set, and identify the bill images contained in the bill image set through a named entity recognition model to obtain a plurality of text information; wherein each bill image corresponds to at least one text information; perform data cleaning on the plurality of text information, and generate a plurality of standard text information according to the data cleaning result; cluster the plurality of standard text information according to the primary key information corresponding to each standard text information, and obtain a standard text information cluster; Selecting target standard text information from the standard text information cluster according to a preset bill image generation strategy, and generating an initial bill sample image and a sample label corresponding to the initial bill sample image according to the target standard text information; A seal sample image is selected from a preset seal sample image set, and a background sample image is selected from a preset background sample image set; wherein the seal sample image is obtained by enhancing the seal pixel domain image, and the generation of any candidate seal sample image contained in the seal sample image set includes: acquiring a seal image, and identifying a seal color area and a seal background area in the seal image; performing color update on the seal color area and the seal background area in the seal image to obtain a mask seal image; constructing a candidate seal pixel domain image according to the seal image and the mask seal image, and The candidate seal pixel domain image is enhanced to obtain a candidate seal sample image; the background sample image is generated according to a blank paper image and a prompt word corresponding to the blank paper image, and the generation of any candidate background sample image contained in the background sample image set includes: obtaining an initial blank paper image, and configuring an image type prompt word for the initial blank paper image; inputting the initial blank paper image and the image type prompt word into an image diffusion model for processing to obtain at least two intermediate blank paper images; selecting a target blank paper image from the at least two intermediate blank paper images as a candidate background sample image; Fusion the initial bill sample image and the seal sample image according to the sample label to obtain an intermediate bill sample image; The intermediate bill sample image is updated to a target bill sample image based on the background sample image, and the target bill sample image is added to a sample set corresponding to a bill recognition model.
2. The method according to claim 1, characterized in that The step of selecting target standard text information from the standard text information cluster according to a preset bill image generation strategy includes: Selecting a set number of initial standard text information from the standard text information cluster according to a preset bill image generation strategy, and determining target primary key information; The initial standard text information is updated using the target primary key information to obtain target standard text information.
3. The method according to claim 1, characterized in that The generating an initial bill sample image according to the target standard text information includes: Determining bill image configuration information according to the bill image generation strategy, and determining bill image size information according to the target standard text information; Constructing a bill image template based on the bill image configuration information and the bill image size information; The target standard text information is added to the bill image template to obtain an initial bill sample image.
4. The method according to any one of claims 1 to 3, characterized in that The step of fusing the initial bill sample image and the seal sample image according to the sample label to obtain an intermediate bill sample image includes: Determine text position information corresponding to the text area in the initial bill sample image according to the sample label; Adjust the size of the seal sample image according to the text position information to obtain a target seal sample image; Selecting a seal adding area for the target seal sample image in the initial bill sample image, wherein the seal adding area is located within the text area; The target seal sample image is added to the seal adding area in the initial bill sample image, and an intermediate bill sample image is generated according to the adding result.
5. The method according to any one of claims 1 to 3, characterized in that: The updating of the intermediate bill sample image to the target bill sample image based on the background sample image comprises: Obtaining a first pixel value corresponding to a pixel point in the background sample image, and obtaining a second pixel value corresponding to a pixel point in the intermediate bill sample image; The first pixel value is adjusted according to a preset pixel value ratio, and a background sample image to be fused is generated according to the adjustment result; and the second pixel value is adjusted according to the pixel value ratio, and a bill sample image to be fused is generated according to the adjustment result; The background sample image to be fused and the bill sample image to be fused are fused to obtain a target bill sample image.
6. The method according to any one of claims 1 to 3, characterized in that: After the step of adding the target bill sample image to the sample set corresponding to the bill recognition model is performed, the method further includes: Selecting a bill sample image from the sample set; Inputting the bill sample image into a bill recognition model for processing to obtain predicted bill recognition information; The bill recognition model is optimized according to the bill recognition label corresponding to the bill sample image and the predicted bill recognition information until a target bill recognition model that meets the training stop condition is obtained.
7. A sample generation method, characterized in that: include: Acquire a pet medical bill image set, and identify the pet medical bill images contained in the pet medical bill image set through a named entity recognition model to obtain multiple text information; wherein each pet medical bill image corresponds to at least one text information; perform data cleaning on the multiple text information, and generate multiple standard text information according to the data cleaning results; cluster the multiple standard text information according to the primary key information corresponding to each standard text information to obtain a standard text information cluster; Selecting target standard text information from the standard text information cluster according to a preset pet medical bill image generation strategy, and generating an initial pet medical bill sample image and a sample label corresponding to the initial pet medical bill sample image according to the target standard text information; A seal sample image is selected from a preset seal sample image set, and a background sample image is selected from a preset background sample image set; wherein the seal sample image is obtained by enhancing the seal pixel domain image, and the generation of any candidate seal sample image contained in the seal sample image set includes: acquiring a seal image, and identifying a seal color area and a seal background area in the seal image; performing color update on the seal color area and the seal background area in the seal image to obtain a mask seal image; constructing a candidate seal pixel domain image according to the seal image and the mask seal image, and The candidate seal pixel domain image is enhanced to obtain a candidate seal sample image; the background sample image is generated according to a blank paper image and a prompt word corresponding to the blank paper image, and the generation of any candidate background sample image contained in the background sample image set includes: obtaining an initial blank paper image, and configuring an image type prompt word for the initial blank paper image; inputting the initial blank paper image and the image type prompt word into an image diffusion model for processing to obtain at least two intermediate blank paper images; selecting a target blank paper image from the at least two intermediate blank paper images as a candidate background sample image; According to the sample label, the initial pet medical bill sample image and the seal sample image are merged to obtain an intermediate pet medical bill sample image; The intermediate pet medical bill sample image is updated to a target pet medical bill sample image based on the background sample image, and the target pet medical bill sample image is added to a sample set corresponding to a pet medical bill recognition model.
8. A sample generating device, characterized in that: include: The recognition module is configured to obtain a bill image set, and recognize the bill images contained in the bill image set through a named entity recognition model to obtain a plurality of text information; wherein each bill image corresponds to at least one text information; perform data cleaning on the plurality of text information, and generate a plurality of standard text information according to the data cleaning result; cluster the plurality of standard text information according to the primary key information corresponding to each standard text information, and obtain a standard text information cluster; A generation module is configured to select target standard text information from the standard text information cluster according to a preset bill image generation strategy, and generate an initial bill sample image and a sample label corresponding to the initial bill sample image according to the target standard text information; The selection module is configured to select a seal sample image from a preset seal sample image set and a background sample image from a preset background sample image set; wherein the seal sample image is obtained by enhancing the seal pixel domain image, and the generation of any candidate seal sample image contained in the seal sample image set includes: acquiring a seal image, and identifying a seal color area and a seal background area in the seal image; performing color update on the seal color area and the seal background area in the seal image to obtain a mask seal image; constructing a candidate seal pixel domain image according to the seal image and the mask seal image, and A candidate seal sample image is obtained by enhancing the candidate seal pixel domain image; the background sample image is generated according to a blank paper image and a prompt word corresponding to the blank paper image, and the generation of any candidate background sample image contained in the background sample image set includes: obtaining an initial blank paper image, and configuring an image type prompt word for the initial blank paper image; inputting the initial blank paper image and the image type prompt word into an image diffusion model for processing to obtain at least two intermediate blank paper images; and selecting a target blank paper image from the at least two intermediate blank paper images as a candidate background sample image; a fusion module, configured to fuse the initial bill sample image and the seal sample image according to the sample label to obtain an intermediate bill sample image; An updating module is configured to update the intermediate bill sample image to a target bill sample image based on the background sample image, and add the target bill sample image to a sample set corresponding to a bill recognition model.
9. A sample generating device, characterized in that: include: The image recognition module is configured to obtain a pet medical bill image set, and recognize the pet medical bill images contained in the pet medical bill image set through a named entity recognition model to obtain multiple text information; wherein each pet medical bill image corresponds to at least one text information; perform data cleaning on the multiple text information, and generate multiple standard text information according to the data cleaning results; cluster the multiple standard text information according to the primary key information corresponding to each standard text information to obtain a standard text information cluster; An image generation module is configured to select target standard text information from the standard text information cluster according to a preset pet medical bill image generation strategy, and generate an initial pet medical bill sample image and a sample label corresponding to the initial pet medical bill sample image according to the target standard text information; The image selection module is configured to select a seal sample image from a preset seal sample image set and a background sample image from a preset background sample image set; wherein the seal sample image is obtained by enhancing the seal pixel domain image, and the generation of any candidate seal sample image contained in the seal sample image set includes: acquiring a seal image, and identifying a seal color area and a seal background area in the seal image; performing color update on the seal color area and the seal background area in the seal image to obtain a mask seal image; constructing a candidate seal pixel domain image according to the seal image and the mask seal image, and obtaining a candidate seal sample image by performing enhancement processing on the candidate seal pixel domain image; the background sample image is generated according to a blank paper image and a prompt word corresponding to the blank paper image, and the generation of any candidate background sample image contained in the background sample image set includes: obtaining an initial blank paper image, and configuring an image type prompt word for the initial blank paper image; inputting the initial blank paper image and the image type prompt word into an image diffusion model for processing to obtain at least two intermediate blank paper images; and selecting a target blank paper image from the at least two intermediate blank paper images as a candidate background sample image; a fusion image module, configured to fuse the initial pet medical bill sample image and the seal sample image according to the sample label to obtain an intermediate pet medical bill sample image; The image updating module is configured to update the intermediate pet medical bill sample image to a target pet medical bill sample image based on the background sample image, and add the target pet medical bill sample image to a sample set corresponding to a pet medical bill recognition model.
10. A computing device, characterized in that: include: Memory and processor; The memory is used to store computer-executable instructions, and the processor is used to execute the computer-executable instructions. When the computer-executable instructions are executed by the processor, the steps of the method described in any one of claims 1 to 7 are implemented.
11. A computer-readable storage medium, characterized in that: It stores computer executable instructions, which, when executed by a processor, implement the steps of the method described in any one of claims 1 to 7.
12. A computer program product, characterized in that The method comprises a computer program or an instruction, which, when executed by a processor, implements the steps of the method according to any one of claims 1 to 7.
Citation Information
Patent Citations
Invoice seal removing method, device and computer storage medium
CN109284758A
Image recognition method and device, and storage medium
CN110781877A
Bill element identification method and device and storage medium
CN113011349A
Bank bill identification method, equipment and medium
CN114581927A
Bill identification method, apparatus and device, and computer storage medium
CN115273123A
