Document image quality evaluation method and device, computer equipment and medium
By using a lightweight convolutional neural network to generate text masks and attention maps, this method solves the problems of high dependence on labeled data and high computational resource consumption in existing document image quality assessment models, and achieves accurate assessment and real-time processing capabilities for key regions of document images.
Patent Information
- Application Number
- CN202511689591.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-11-18
- Publication Date
- 2026-02-06
AI Technical Summary
Existing document image quality assessment models require a large amount of labeled data, cannot accurately assess the quality of specific regions in document images, and consume high computational resources, making it difficult to meet real-time processing requirements.
A lightweight convolutional neural network is used to generate text masks and attention maps. Through joint supervised training using consistency loss and evaluation result data, a lightweight model is generated that can automatically generate text masks and attention maps during the training phase, reducing the reliance on precise annotations and pruning unnecessary computational paths during the inference phase.
It enables accurate quality assessment of key areas of document images, reduces data costs and computing resource requirements, adapts to document images of different formats, and meets the needs of real-time processing scenarios.
Smart Images

Figure CN121482810A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of image recognition, and more particularly to a method and apparatus for document image quality assessment, as well as computer equipment and media. Background Technology
[0002] Document image quality assessment plays a crucial role in various application scenarios, particularly in optical character recognition (OCR), automated document processing, and e-government. Traditional methods for assessing document image quality primarily rely on manual inspection or automated detection based on simple rules. However, these methods have significant limitations when handling complex images and diverse document types.
[0003] In recent years, the rapid development of deep learning technology has provided new solutions for document image quality assessment. In particular, models such as Convolutional Neural Networks (CNNs) and Feature Pyramid Networks (FPNs) have been widely applied to image recognition and segmentation tasks. These models learn deep features of images, enabling them to identify key content regions, such as text regions, and assess their quality. However, despite their significant achievements in image recognition and segmentation, some technical challenges remain in specific applications of document image quality assessment.
[0004] First, existing deep learning-based image quality assessment models typically require large amounts of labeled data for training. This data includes not only the images themselves but also precise annotation information, such as accurate boundaries of text regions and detailed image quality scores. Acquiring such data is both time-consuming and expensive, limiting the widespread application and rapid deployment of these models.
[0005] Secondly, most existing models, when evaluating image quality, primarily focus on the overall sharpness of the image, neglecting the importance of specific regions (such as text regions) within the document image. This global evaluation method fails to accurately reflect the actual readability and information completeness of the document, especially when some text regions are sharp while other regions are blurry.
[0006] Furthermore, existing models lack sufficient flexibility and adaptability when processing document images of different types and formats. For example, different types of documents (such as scanned copies, photographs, electronic documents, etc.) may have different image characteristics and quality requirements, and existing models cannot effectively adapt to these differences.
[0007] Furthermore, existing models typically require significant computational resources and time in practical applications, which is impractical for application scenarios that require real-time or near-real-time processing (such as online document submission and automated review systems).
[0008] It is evident that there is still room for improvement in image quality assessment models. This application attempts to explore this area in order to contribute to the development of automated text recognition technology. Summary of the Invention
[0009] The primary objective of this application is to address at least one of the aforementioned problems by providing a document image quality assessment method, apparatus, computer equipment, and medium.
[0010] To achieve the various objectives of this application, the following technical solution is adopted: A document image quality assessment method provided for one of the purposes of this application includes the following steps: Retrieve the original document image submitted by the user; The original document image is inferred using a pre-defined document image quality assessment model to determine the corresponding evaluation result data. Trigger the business notification event corresponding to the original document image based on the evaluation result data; In the training phase, the document image quality assessment model extracts depth feature maps from sample images, generates attention maps and text masks indicating text information regions based on the depth feature maps, and evaluation result data representing the image quality assessment results. It also associates the loss between the attention maps and the text masks, the loss between the evaluation result data and its evaluation reference data, and determines the comprehensive loss corresponding to the current training.
[0011] A document image quality assessment apparatus, proposed for one of the purposes of this application, includes: The image acquisition module is configured to acquire the original document image submitted by the user. The model reasoning module is configured to use a preset document image quality assessment model to reason about the original document image and determine the evaluation result data corresponding to the original document image. The business notification module is configured to trigger a business notification event corresponding to the original document image based on the evaluation result data. In the training phase, the document image quality assessment model extracts depth feature maps from sample images, generates attention maps and text masks indicating text information regions based on the depth feature maps, and evaluation result data representing the image quality assessment results. It also associates the loss between the attention maps and the text masks, the loss between the evaluation result data and its evaluation reference data, and determines the comprehensive loss corresponding to the current training.
[0012] In another aspect, a computer device provided for one of the purposes of this application includes a processor and a memory, wherein the processor invokes and runs a computer program in the memory to perform the steps of the document image quality assessment method.
[0013] On another aspect, a computer-readable storage medium is provided to suit another purpose of this application, which stores, in the form of computer-readable instructions, a computer program implemented according to the document image quality assessment method, which, when invoked by a computer, performs the steps included in the corresponding method.
[0014] Compared to traditional technologies, this application improves the document image quality assessment model and uses it to evaluate the image quality of the original document image to trigger downstream business, thereby achieving rich technical effects. Specifically, the document image quality assessment model of this application first performs feature representation on the sample images to obtain deep feature maps during the training phase. Then, it automatically generates attention maps and text masks indicating text information regions. The consistency loss between the two is combined with the loss between the evaluation result data and its evaluation reference data to form a comprehensive loss for supervised training. This ensures that the evaluation result data output during the inference phase no longer relies on a global coarse judgment, but accurately reflects the true quality of key content regions. Even if some text regions are clear while other regions are blurry, the readability and information integrity of the document can still be guaranteed. The training data only requires sample images and corresponding evaluation reference data. The text mask and attention map are generated internally by the model, saving a lot of manual fine annotation, significantly reducing data costs and shortening the deployment cycle. The joint loss takes into account both dimensional errors and image-level errors, enabling the model to adaptively learn different formats such as scanned documents, photographs, and electronic documents, making it more flexible and robust. The branch used to generate the text mask can be pruned during the inference phase, reducing the overall parameter size to below 15 MB. It can run in real time on mobile devices or edge devices, quickly triggering corresponding business notification events and meeting the real-time requirements of scenarios such as online document submission and automatic review. Attached Figure Description
[0015] The above and / or additional aspects and advantages of this application will become apparent and readily understood from the following description of the embodiments taken in conjunction with the accompanying drawings, wherein: Figure 1 This is a schematic diagram of the network architecture of the document image quality assessment model in this application during the training phase. Figure 2 This is a flowchart illustrating a typical embodiment of the document image quality assessment method of this application; Figure 3 Examples of original document images and corresponding attention maps used in the application of the document quality image evaluation model of this application; Figure 4This is a schematic block diagram of the document image quality assessment device of this application; Figure 5 This is a schematic diagram of the structure of a computer device used in this application. Detailed Implementation
[0016] In various business scenarios that rely on document images for information extraction and automated processing, the quality of the image itself often becomes a key precondition for determining the accuracy of subsequent recognition and the efficiency of business processes. For example, images such as prescriptions, test reports, insurance documents, and government receipts uploaded by mobile devices are often degraded to varying degrees due to camera shake, screen capture moiré patterns, uneven lighting, or compression artifacts. If these images are directly fed into text detection or structured recognition processes, it will not only significantly prolong the recognition time but may also trigger manual review due to misidentification or omission, increasing operating costs. Therefore, deploying a lightweight, high-response document image quality assessment model that does not require a complete text recognition process before optical character recognition or other downstream business modules has become a common requirement in engineering practice. The document image quality assessment method and apparatus proposed in this application are designed for such scenarios. It can output evaluation result data that reflects the true visual quality of key text content areas through a single forward inference and trigger corresponding business notification events in real time based on the result data, realizing an end-to-end optimized link of "evaluation before recognition".
[0017] Figure 1 The network architecture shown corresponds to the complete form of the document image quality assessment model of this application during the training phase. Its design aims to guide the backbone network to focus on the text information region in the document image through a parallel supervision mechanism, so that document image quality assessment can be achieved by retaining only the lightweight backbone network and the required output path during the inference phase.
[0018] The sample images (original document images) input to the document image quality assessment model first enter the feature representation networks of the backbone network. These feature representation networks can employ lightweight convolutional neural networks such as PPLCNetV3, or can be replaced with visual Transformers, ConvNeXt, Swin Transformers, or other hybrid structures that balance computational efficiency and feature expressiveness. They are responsible for outputting deep feature maps that preserve text edges, texture details, and moiré interference information. The deep feature maps are then fed into a mask prediction network. In this implementation, the mask prediction network can be a modified DBNet binarization branch, which retains convolution and sigmoid activation while discarding threshold prediction and differentiable binarization operations. This generates a text mask consistent with the spatial distribution of the text information regions. This text mask only participates in computation during the training phase, providing spatial-level supervision signals.
[0019] In parallel with the mask prediction network, the deep feature map is also fed into the attention layer of the backbone network. This attention layer generates a single-channel attention map through 1×1 convolutions and sigmoid activation. Each pixel value represents the probability that the corresponding position belongs to the text information region, thereby emphasizing the text region and suppressing background, reflection, or moiré regions in the spatial dimension. The attention map output by the attention layer and the text mask are used to calculate the consistency loss during the training phase. This loss measures the difference between the attention map and the text mask through element-wise L2 norm, ensuring that the high response of the attention map to the foreground region and the low response to the background region are spatially consistent with the text mask, thus improving the robustness of the model under complex imaging conditions. The attention map is then fed together with the deep feature map into the fusion layer in the backbone network. The fusion layer uses learnable coefficients. Linear combination of attention-weighted pooling features and global average pooling features can also be used, or alternatively, channel attention, multi-scale feature pyramids, or Transformer encoders can be employed to form fused features that combine local sensitivity and global receptive field.
[0020] The fused features are simultaneously fed into the deactivation layer and the classifier, forming two output paths that can be used independently or in combination. The deactivation layer can consist of Dropout and a fully connected layer in sequence, used to map the fused features into a single image quality score between 0 and 1. This score can be directly expressed as a continuous value for any document image quality index such as sharpness, exposure quality, contrast adequacy, noise or compression artifact intensity, shadow or reflection coverage, etc. The classifier consists of a fully connected layer followed by a Softmax layer, used to map the fused features into a probability distribution of a preset number of image quality levels. This probability distribution can be used to calculate the cross-entropy loss with the score probability distribution transformed from the evaluation reference data, specifically a flexible cross-entropy loss, thus introducing discrete level supervision during the training phase. The deactivation layer path and the classifier path can be used selectively during the training phase, or they can be used simultaneously and their respective difference losses can be combined in a weighted manner. During the inference phase, one or both paths can be used as needed.
[0021] Before training the document image quality assessment model, only a training dataset containing sample images and their evaluation reference data is needed. The sample images must at least partially contain text information, and the evaluation reference data consists of values within a preset scoring range, which can be obtained through manual coarse labeling, automatic reference, or other weakly supervised methods, without requiring detailed text region boundary annotation. During model training, the comprehensive loss is a weighted fusion of consistency loss, first difference loss, and second difference loss. The consistency loss constrains the spatial consistency between the attention map and the text mask; the first difference loss uses cross-entropy loss to measure the difference between the classifier's output level probability distribution and the score probability distribution; and the second difference loss uses mean squared error to measure the difference between the image quality score output by the deactivated layer and the evaluation reference data. Training is completed by backpropagating the comprehensive loss and iteratively updating the network parameters until the loss converges or a preset stopping condition is met.
[0022] After training, the entire mask prediction network can be completely pruned, and the deployment form retains only the feature representation network, attention layer, fusion layer, and selected output path. Thanks to the complete pruning of the mask prediction branch during the inference stage, the number of parameters in the deployment form is compressed to the tens of megabytes level, enabling millisecond-level response on a central processing unit. Therefore, it can be directly embedded into mobile applications, edge computing boxes, or high-concurrency cloud services, providing instant, interpretable, and stable quality assessment capabilities for scenarios such as online document submission, automatic review, and real-time retake prompts.
[0023] It should be noted upfront that the image quality evaluation results referred to in this application can be set according to the quality dimensions that the business side focuses on, and can be flexibly mapped to the quantitative performance of any one or more document image quality indicators such as image sharpness, exposure quality, contrast adequacy, noise or compression artifact intensity, shadow and reflection coverage, etc. In other words, as long as the model is given the corresponding supervision target through the evaluation reference data in the training data, the same network architecture can complete the evaluation task of different quality dimensions without structural modifications.
[0024] Therefore, the document image quality assessment method of this application can be implemented as a computer program and deployed to a cloud server or a terminal device with sufficient performance to achieve its function. In the following embodiments, the various steps and technical details of this application will be described in detail, further illustrating the technical advantages and innovations of this application.
[0025] Please see Figure 2 In some embodiments, the document image quality assessment method of this application can be implemented as an application program running on a computer device, and the method includes: Step S3100: Obtain the original document image submitted by the user; Users can load the image to be evaluated, carrying text information, into the storage area of a computer device as the original document image through any electronic channel capable of image acquisition and data transmission, for subsequent use by the document quality assessment model. The acquisition process is not limited to the source form of the image, including but not limited to: photos taken instantly by the user through a mobile terminal camera, stored images selected from a local photo album or file manager, scanned copies uploaded through a webpage or application programming interface, electronic documents forwarded through cloud storage links or messaging applications, and image streams directly read from external scanners, multifunction printers, portable shooting aids, etc., via a data bus. Common raster formats are supported, such as JPEG, PNG, BMP, and TIFF, as well as compressed or encoded PDF page objects. Upon receiving the original document image, the computer device in this application can uniformly convert it into a pixel matrix representation through a decoding library, thereby ensuring the consistency of data input for subsequent feature representation networks.
[0026] The content of the original document images is not limited. It can include prescriptions, test reports, and medical imaging reports in medical scenarios, as well as insurance policies, receipts, application forms, and invoices in insurance, finance, and government scenarios, or general paper contracts, notices, and express delivery slips, as long as the image contains text information that can be identified by the naked eye, it falls within the processing scope of this application.
[0027] In practical deployments, basic pre-verification can be added to the acquisition channel, such as file size, resolution, color bit width, or format validity checks. However, these checks are only used to filter out obviously non-image data and do not involve judging the quality of image content, thus not introducing additional computational latency. For images captured by mobile devices, the acquisition steps may also include low-level calls to autofocus, exposure lock, or image stabilization buffers to minimize the probability of introducing blur, overexposure, or moiré patterns at the physical acquisition level. However, these calls fall within the scope of hardware capabilities and do not change the essential meaning of the acquisition actions described in this application.
[0028] In one alternative implementation, the computer device may record additional metadata, including shooting time, terminal model, resolution, focal length information, compression ratio, and user identifier, while acquiring the image, for subsequent business log tracking or online model monitoring. However, the collection of metadata does not affect the pixel content itself and is therefore not considered a modification of the original document image.
[0029] If the image is transmitted via encryption or signature mechanisms, the acquisition steps also include decrypting the encrypted packet and verifying the signature digest to ensure data integrity and source credibility. The image data is then written to the memory buffer after the decryption and verification are successful.
[0030] Step S3200: Use a preset document image quality assessment model to infer the original document image and determine the evaluation result data corresponding to the original document image; After acquiring the original document image in pixel matrix form, the computer device can immediately call the document image quality assessment model that has been trained in this application to perform a forward calculation on the original document image to output evaluation result data that can reflect the visual quality of key content areas.
[0031] As revealed above, the executable file of the document image quality assessment model can retain only the core parts determined during the training phase in the deployment form, namely the feature representation network, attention layer, fusion layer, and inactive layer or classifier enabled on demand. The mask prediction network and its weights have been pruned, so the inference process does not need to generate text masks, thereby compressing the computation to within the 15-megabyte parameter scale and enabling single image evaluation to be completed on the central processing unit with millisecond latency.
[0032] The feature representation network first performs spatial resolution normalization on the input original document image, scaling the shorter side to a predetermined pixel value while maintaining the aspect ratio. Then, it outputs a depth feature map through convolution or transformation operations. This depth feature map carries text edges, texture details, and background interference information.
[0033] Then, the attention layer generates a single-channel attention map based on the deep feature map. Each pixel value represents the probability that the corresponding spatial location belongs to the text information region. This is used to weight the features in the subsequent fusion step, so that the text region gets higher weight while the background noise region is suppressed.
[0034] The fusion layer multiplies the attention map and the deep feature map element by element along the spatial dimension, and then integrates them into a fixed-length fusion feature vector through learnable coefficients or pooling operations. This vector retains global structural information while highlighting local key region features, providing a basis for the discrimination of the output path.
[0035] In one implementation, if the business side focuses on continuous quality scores, the fused feature vector is fed into the deactivated layer and mapped by the fully connected weights to a floating-point value between 0 and 1. This value is the evaluation result data, which can directly represent the quantitative results of any document image quality index such as sharpness, exposure quality, contrast adequacy, noise or compression artifact intensity, shadow or reflection coverage.
[0036] In another implementation, if the business side requires graded output, the fused feature vector is fed into the classifier, and the Softmax function outputs a probability distribution of a preset number of image quality grades. The grade corresponding to the highest probability can be used as discrete evaluation result data, or it can be converted back to continuous score through expectation calculation to meet the docking needs of different downstream systems.
[0037] The inactive layer and the classifier can be selectively enabled during the inference phase, or both can be enabled simultaneously and return evaluation results data in two forms. As long as the corresponding loss has been used to complete supervision during the training phase, the results can be kept consistent.
[0038] As described above regarding the principles of the training process of the document image quality assessment model, the model is trained to convergence before being used in the inference phase. During its training phase, depth feature maps are extracted from the input sample images. Then, based on the depth feature maps, attention maps and text masks indicating text information regions are generated, along with evaluation result data representing the image quality assessment results. The loss between the attention map and the text mask, and the loss between the evaluation result data and its evaluation reference data are correlated to determine the comprehensive loss corresponding to the current training.
[0039] Specifically, in one embodiment, the forward computation and supervision method of the document image quality assessment model during the training phase is based on the aforementioned network architecture. Through a complete forward propagation, three types of intermediate results for supervision can be obtained simultaneously: First, the feature representation network outputs a depth feature map for the sample image; then, the mask prediction network generates a text mask based on the depth feature map, and the attention layer generates an attention map based on the same depth feature map. Both of them point to the text information region in the spatial dimension; the fusion layer weights and merges the attention map and the depth feature map, and then maps them to a continuous image quality score through the deactivation layer, and then maps them to a discrete level probability distribution through the classifier. The above scores or probability distributions together constitute the evaluation result data. During the backpropagation phase, the model calculates a consistency loss to measure the pixel-wise difference between the attention map and the text mask; a first difference loss to measure the cross-entropy between the rank probability distribution and the rating probability distribution transformed from the evaluation reference data; and a second difference loss to measure the mean squared error between the image quality score and the evaluation reference data. The consistency loss, first difference loss, and second difference loss are then weighted and summed according to preset weights to obtain the comprehensive loss for that training iteration. The network parameters are then updated using gradient descent until convergence. This training process ensures that only the backbone network, attention layer, fusion layer, and selected output path are retained during the inference phase, allowing the reuse of training-obtained weights and achieving accurate quality assessment of key regions in the original document image.
[0040] Step S3300: Trigger the business notification event corresponding to the original document image based on the evaluation result data; After obtaining the evaluation results data output by the model, the data can be judged according to preset scoring conditions, and downstream actions corresponding to the judgment results can be executed to achieve closed-loop control of evaluation before processing. The scoring conditions are written into the configuration file or database field by the business side during the deployment phase, and their forms include, but are not limited to: single threshold comparison, multi-interval segmentation, level label matching, or comprehensive weighted score judgment. For example, the continuous scores output by the deactivated layer can be compared with the exemplary first threshold of 0.7, or the sum of the probabilities of "clear" and "relatively clear" in the level probability distribution output by the classifier can be used as the passing condition, or the level corresponding to the highest probability in the level probability distribution can be directly compared with the target level label as the matching judgment condition.
[0041] When the evaluation results meet the preset scoring conditions, a first business notification event can be generated. This event can trigger a downstream business system or module to start another business process. For example, this event can be used to start a subsequent high-quality image processing process, including but not limited to any one or more of the following: calling a text detection model, calling a text recognition model, sending the image to the structured information extraction module, writing the recognition results to the business database, returning a "successful upload" message to the user, or sending an "automatic approval" notification to the subsequent approval system.
[0042] In one implementation of a medical scenario, the first business notification event further includes the attention generated during the model inference process. Figure 1 The information is then distributed to downstream modules, which use the attention map to crop the text region of the original document image. The resulting text region image is then sent to the optical character recognition engine to obtain structured medical information. This information is then filled into a preset prompt template and input into the medical information analysis model to automatically generate diagnostic suggestions or medication reminders.
[0043] When the evaluation results fail to meet the preset scoring conditions, a second business notification event can be generated. This event notifies the user that the current image does not meet the quality requirements and needs to be re-captured or replaced. Notification methods include, but are not limited to, any one or more of the following: displaying a pop-up message "Image is blurry, please retake" on the mobile application interface; sending a retransmission link via SMS or email; or highlighting the substandard area and providing shooting instructions on the webpage. The entire triggering process requires no manual intervention. After the event is generated, it is immediately sent to the corresponding module via an internal message queue or function call interface, ensuring a smooth experience in high-concurrency scenarios such as online document submission, automatic review, real-time insurance application, or remote consultation.
[0044] Compared to traditional technologies, this application significantly improves the adaptability and accuracy of a lightweight document image quality assessment model through unique training. It can efficiently and quickly determine image quality assessment results for original document images, thereby rapidly triggering corresponding downstream business processes. This application demonstrates significant beneficial effects and technical advantages in several aspects, including but not limited to: First, the evaluation results of this application can more accurately reflect the image quality of key content regions in document images. Unlike traditional deep learning models that focus on global assessment, this application obtains deep feature maps by representing the original document images during the training phase. Based on these deep feature maps, attention maps and text masks indicating text information regions are automatically generated. The loss between these maps is correlated with the loss between the evaluation results data and the evaluation reference data to determine a comprehensive loss. The model training is supervised based on this comprehensive loss, which can more accurately evaluate the image quality of these key regions. Especially when some text regions are clear while other regions are blurry, it can still reflect the actual readability and information integrity of the document image, thus providing a more accurate and practical document image quality evaluation solution.
[0045] Secondly, this application significantly reduces the reliance on large amounts of precisely labeled data. Traditional deep learning model training requires collecting and labeling vast amounts of training data, including the images themselves and detailed annotation information such as precise boundaries of text regions and detailed image quality scores. This process is not only time-consuming and labor-intensive but also costly. This application employs a unique training strategy, requiring only sample images and their corresponding evaluation reference data in its training data. The text mask and attention map are generated automatically by the document image quality assessment model during training, requiring no additional cost. Therefore, it can train a high-performance model with limited labeled data, thereby reducing the cost of data collection and processing and accelerating model deployment.
[0046] Furthermore, this application demonstrates greater flexibility and adaptability when processing document images of different types and formats. Different types of documents (such as scanned copies, photographs, electronic documents, etc.) may have different image features and quality requirements, and existing models often cannot effectively adapt to these differences. This application, by implementing dimensional supervision not only on the loss between evaluation result data using evaluation reference data during the training process, but also on the image-level supervision using the loss between self-generated text masks and attention maps, enables the model to better learn and adapt to these differences, thereby maintaining efficiency and accuracy in diverse document image processing.
[0047] Finally, this application demonstrates higher computational efficiency and real-time performance in practical applications. Existing models typically require significant computational resources and time, which is impractical. The branch used to generate the text mask during the training phase of this application can be completely pruned during the inference phase, making the document image quality assessment model more lightweight. After deployment, the total number of parameters in actual tests can be below 15MB, enabling it to adapt to various performance-constrained mobile devices and handle various application scenarios requiring real-time or near-real-time processing, such as online document submission and automated review systems. It achieves fast and accurate image quality assessment at a lower computational cost, meeting the demands of real-time processing.
[0048] Based on any embodiment of the method in this application, before obtaining the original document image submitted by the user, the method includes: Step S2100: Obtain the training dataset, which includes multiple training data, each training data including sample images and their evaluation reference data, wherein at least some of the sample images contain text information; The training dataset consists of multiple training data sets, each containing at least one sample image and one evaluation reference image. The sources of the sample images include, but are not limited to, photos taken by mobile devices, scans output by flatbed scanners, electronic documents captured by screen captures, image files acquired via fax or multifunction printers, and real user-uploaded images recovered from existing business system logs. Image formats supported include JPEG, PNG, BMP, TIFF, and raster matrices decoded from PDF page objects. Resolutions cover common acquisition specifications from two megapixels to twenty megapixels to ensure the model's robustness to subsequent resolution changes.
[0049] Evaluation reference data can be numerical labels that correspond one-to-one with the sample images, used to provide supervision targets during the training phase. The values are located within a preset scoring range, such as continuous floating points between 0 and 1, or integers between 0 and 100. Their physical meaning is consistent with the quality dimensions that the business side focuses on, including but not limited to document image quality indicators such as sharpness, exposure quality, contrast adequacy, noise or compression artifact intensity, shadow and reflection coverage.
[0050] Evaluation parameter data can be generated through three methods: manual coarse labeling, automatic referencing, and weakly supervised synthesis. Manual coarse labeling can be completed by annotators dragging sliders or selecting level buttons in a visual interface, without requiring pixel-level precision. Automatic referencing can calculate Laplacian variance, gradient energy, or frequency domain signal-to-noise ratio using validated objective indicator scripts and then map these values to a score. Weakly supervised synthesis utilizes a generative model to apply different intensities of Gaussian blur, motion blur, moiré overlay, brightness shift, or compression distortion to the same high-resolution original image, thereby generating images with known degradation levels and corresponding scores in batches. These three methods can be used individually or in combination to expand the sample size while controlling costs.
[0051] At least a portion, and typically the majority, of the sample images in the training dataset must contain visually recognizable text information. This text can take the form of printed text, handwritten text, table lines, stamps, barcodes, or QR codes. This ensures the model can learn the visual quality differences between text and background regions during training. Simultaneously, another portion of the sample images can be blank pages without text, texture templates, or background patterns to provide negative samples and prevent the model from misclassifying non-text areas as critical regions. The number of sample images is determined based on the complexity of the business scenario and the model capacity; a typical implementation uses between 10,000 and 100,000 images, which allows the overall loss to converge after several dozen iterations.
[0052] If the actual use case covers multiple document types, categories such as medical prescriptions, test reports, insurance documents, government receipts, contract texts, and express delivery slips can be mixed in proportion to enable the model to generalize across types. After pairing sample images and evaluation reference data, the computer equipment writes both into structured files or database records to form a training dataset.
[0053] Step S2200: Call the training data to input the document image quality assessment model for training. The model extracts depth feature maps from the sample images in the training data. Based on the depth feature maps, it generates attention maps and text membranes indicating text information regions, as well as evaluation result data characterizing the image quality assessment results. Based on the training dataset, training data can be batch-processed and input into the document image quality assessment model for training. Specifically, sample images can be fed into the model in batches according to a preset batch size to complete one full forward propagation, yielding depth feature maps, attention maps, text masks, and evaluation result data. This process can be reused. Figure 1 The training phase network is shown as follows: the feature representation network first outputs a deep feature map, the mask prediction network and the attention layer generate text masks and attention maps in parallel, and the fusion layer combines the attention map and the deep feature map with weights. The result is then passed through the deactivation layer to output a continuous score and through the classifier to output a level probability distribution. The two together constitute the evaluation result data.
[0054] The optimizer employs stochastic gradient descent or adaptive moment estimation with momentum, and weight updates are performed after backpropagation of the comprehensive loss until the convergence condition is met.
[0055] Step S2300: Associate the loss between the text mask and the attention map with the loss between the evaluation result data and the evaluation reference data in the training data to determine the comprehensive loss corresponding to the sample image; After completing one forward propagation, three types of supervisory signals can be acquired in parallel and weighted summed to form the comprehensive loss used for backpropagation. As revealed earlier, the comprehensive loss consists of a consistency loss and two difference losses.
[0056] The consistency loss measures the spatial difference between the attention map and the text mask using the pixel-wise L2 norm. It is calculated by subtracting the two matrices, taking the sum of the squares, and then dividing by the total number of pixels. This is used to ensure that the attention map maintains a high response in the text region and close to zero in the background region.
[0057] When the model enables the classifier path, the evaluation reference data is converted into a rating probability distribution equal to the number of grades, and the cross-entropy loss is calculated with the grade probability distribution output by the classifier as the first difference loss. This loss guides the model to maintain its discriminative ability on discrete quality grades.
[0058] When the model enables the deactivated layer path, the mean squared error loss is calculated using the evaluation reference data as the true value and the image quality score output by the deactivated layer as the predicted value. This loss is used as the second difference loss to refine the model's sensitivity to continuous quality changes.
[0059] The consistency loss, the first difference loss, and the second difference loss are added together with preset weights to obtain the comprehensive loss. The weight coefficients are fixed values set by grid search or experience, or a dynamic adjustment strategy can be adopted during training to ensure the balance of each loss term on the numerical scale and promote the rapid convergence of the model.
[0060] Step S2400: Supervise the iterative training of the model until convergence based on the comprehensive loss.
[0061] After obtaining the comprehensive loss value, the gradient of the trainable parameters can be calculated using the backpropagation algorithm. The optimizer then updates the weights and biases in the feature representation network, mask prediction network, attention layer, fusion layer, and deactivation layer or classifier, ensuring the comprehensive loss decreases in subsequent iterations. The optimizer employs methods including, but not limited to, stochastic gradient descent with momentum, adaptive moment estimation, or adaptive learning rate. The initial learning rate and decay strategy are set through a configuration file.
[0062] In one embodiment, during training, forward propagation, loss calculation, backpropagation, and parameter updates can be performed in batches and cyclically until the overall loss decreases below a preset threshold over several consecutive rounds, or the training rounds reach their maximum limit, at which point convergence is considered achieved. After convergence, the weights of the feature representation network, attention layer, fusion layer, and selected output path are saved, while the mask prediction network weights are discarded, forming a lightweight model for deployment and subsequent quality assessment tasks in the inference phase. The batch size, learning rate, and number of iterations used during batch training can be specified by a configuration file.
[0063] The above embodiments, through weakly supervised annotation, only require providing overall numerical evaluation reference data for sample images, eliminating the need for pixel-level text boundary or region delineation, significantly reducing annotation workload and labor costs. Both the text mask and attention map are automatically generated by the model's internal forward computation and self-corrected using consistency loss, avoiding the introduction of additional annotation branches and further improving data preparation efficiency. By comprehensively utilizing a weighted supervision strategy combining consistency loss, cross-entropy loss, and mean squared error loss, text information region attention learning and quality score data fitting are simultaneously completed in a single round of forward inference and backpropagation, shortening the training cycle and reducing computational consumption. The mask prediction network can be pruned entirely after convergence, reducing the final deployed model parameters to the tens of megabytes level, enabling millisecond-level iteration on a central processing unit without the need for high-end graphics processors, significantly saving training and inference costs.
[0064] Based on any embodiment of the method in this application, the training data is input into a document image quality assessment model for training. The model extracts depth feature maps from the sample images in the training data, and generates attention maps and text wrappings indicating text information regions based on the depth feature maps, as well as evaluation result data characterizing the image quality assessment results, including: Step S2210: Input the sample images from the training data into the feature representation network of the document image quality assessment model to perform feature representation and obtain a deep feature map; The sample images from the training data are input into the feature representation network to complete the mapping from the original pixels to a high-dimensional semantic space, resulting in a deep feature map. Its tensor shape is denoted as ,in and These represent the spatial height and width of the feature map, respectively. Indicates the number of channels.
[0065] In practical implementation, the feature representation network adopts the PPLCNetV3 lightweight convolutional backbone, which is composed of multiple depthwise separable convolutional units stacked together. Each unit includes pointwise convolution, channel-wise convolution, batch normalization, and activation functions. The overall computational cost, measured in multiply-accumulate units, does not exceed several hundred mega-operations, enabling millisecond-level feature extraction on a central processing unit. When the business side has higher requirements for global modeling capabilities, this network can also be replaced with a visual Transformer, Swin Transformer, ConvNeXt, or a hybrid convolutional-attention architecture, as long as the output feature map maintains spatial resolution and channel dimension compatibility with subsequent mask prediction networks and attention layers.
[0066] The feature extraction process can be expressed using formulas. It means that among them For the input sample image, The set of learnable parameters for a feature representation network. This represents a nonlinear mapping function formed by cascading multiple convolutional or transform operators. Through this mapping, text strokes, table lines, moiré patterns, and compression block effects in the original output sample image are all encoded into the same feature space, providing a unified basis for subsequent parallel generation of segmentation masks and attention weights.
[0067] Deep feature map Each spatial location vector The semantic description of the local receptive field corresponding to the original image is used. The size of the receptive field is determined by the number of network layers, the convolutional kernel size, and the downsampling stride. While maintaining lightweight inference, the following approach is adopted: Max pooling or strided convolution performs only two downsampling operations, making the output feature map spatial size about one-quarter of the input image. This reduces computation while preserving sufficient spatial details for fine localization of text regions by the mask prediction network and attention layer.
[0068] After completing the forward computation, the depth feature map The data is simultaneously fed into the mask prediction network and the attention layer, and steps S2220 and S2230 are executed in parallel. No additional annotation information is required in the entire feature extraction stage. Self-supervised correction is achieved solely by the evaluation reference data and subsequent consistency loss, which can significantly reduce data preparation costs and improve training efficiency.
[0069] Step S2220: The mask prediction network of the model generates a text mask indicating the text information region of the sample image based on the depth feature map; The mask prediction network is based on deep feature maps Generate a text mask indicating the text information region of the sample image. Its input is the depth feature map output in step S2210. The output is the same as Text mask with consistent spatial dimensions Text mask Each pixel value represents the probability that the corresponding position belongs to the text or structured foreground. The value range can be constrained between 0 and 1 by the Sigmoid activation, or it can be represented by binary 0 or 1, where 1 indicates that the pixel belongs to the foreground and 0 indicates that the pixel belongs to the background.
[0070] In a more specific implementation, the mask prediction network employs a modified DBNet binarization branch, retaining the convolution stacking and sigmoid output from the original DBHead while discarding the threshold prediction branch and differentiable binarization operation. This reduces the computational cost to a combination of one 3×3 convolution and one 1×1 convolution, with fewer than five percent of the parameters of the backbone network, ensuring only negligible increases in memory and latency during training. The specific mapping process of the mask prediction network can be represented as follows: in Used to aggregate local contexts Indicates batch normalization, Introducing nonlinearity, Compress the number of channels to 1. This represents the Sigmoid function.
[0071] This formula preserves the high responses of text strokes, table lines, or stamp areas in the depth feature map, while suppressing the low responses of blank backgrounds, moiré patterns, or reflective areas, thus forming a spatially continuous and edge-accurate foreground probability map.
[0072] The mask prediction network works in parallel with the attention layer during the training phase, and its output... For use only with attention maps The consistency loss is calculated without participating in any pixel-level truth supervision, thus eliminating the need for manual annotation of text regions and achieving fully self-supervised spatial constraints.
[0073] During the inference phase, the mask prediction network and its weights are pruned as a whole, without increasing deployment size or runtime. When the business scenario has higher requirements for mask edge accuracy, the mask prediction network can be replaced with a lightweight U-Net, SegFormer, or self-attention segmentation head. As long as the output size is the same as the depth feature map and the number of channels is 1, the existing consistency loss can be directly reused to achieve the same function.
[0074] Step S2230: The attention layer of the model generates an attention map that indicates the text information region of the sample image based on the depth feature map; The attention layer outputs the deep feature map in step S2210. Using a single input, a single-channel attention map is generated through a single spatial transformation. For reference Figure 3 The image on the right is used to indicate the importance of text information regions in a spatial dimension.
[0075] In a more specific embodiment, the attention layer uses a 1×1 convolution to encode the depth feature map. of The 3D channels are compressed to 1D, and then the output value is constrained to the [0,1] interval by Sigmoid activation, resulting in a value similar to... Attention maps of the same height and width Its calculation formula is expressed as: in This represents the Sigmoid function. The weights are updated synchronously with the backbone network during training. Each pixel value This represents the probability weight of the corresponding spatial location belonging to the foreground text. The closer the value is to 1, the more attention the subsequent fusion layer needs to pay to this location. The closer the value is to 0, the more the location belongs to the background, reflection, or moiré interference area and should be suppressed.
[0076] Using this formula, the attention layer can achieve interaction with the text mask without introducing additional annotations. The self-supervised localization effect with spatially converging distribution provides a differentiable and interpretable weight mask for the fusion layer. When the business side has higher requirements for attention granularity, the attention layer can be replaced with a channel-space dual attention module, a lightweight Transformer self-attention block, or a cross-attention structure based on learnable query vectors, as long as the output remains single-channel and its size is similar to that of the channel-space dual attention module. If consistent, existing fusion strategies and consistency losses can be directly reused to achieve the same text region emphasis function.
[0077] Step S2240: The fusion layer of the model fuses the depth feature map and the attention map, and outputs and maps them as evaluation result data.
[0078] The fusion layer fuses the deep feature map and the attention map, outputting the result and mapping it to the evaluation data. This is achieved by first modifying the deep feature map in the spatial dimension. With attention map Perform pixel-by-pixel weighting to obtain weighted features. Its expression is: ,in and Using spatial subscripts, this multiplication operation gives higher confidence locations in the text region a larger feature amplitude, while features corresponding to background, reflective, or moiré regions are suppressed.
[0079] To preserve global context and prevent overfitting, the fusion layer computes global average pooling features in parallel. Its expression is: ,in and These represent the height and width of the feature map, respectively. This vector encodes the global statistical characteristics of the entire document image.
[0080] After completing the two paths mentioned above, the fusion layer introduces learnable coefficients. A linear combination is performed on the weighted features and the global features to output the fused features. ,in For weighted features The vector obtained after performing global average pooling again. The initial value is set to 0.5 and updated via backpropagation along with the rest of the network parameters during training to adaptively balance the tendencies of local sensitivity and global stability.
[0081] Fusion features It is then fed into two parallel paths: the deactivation layer and the classifier. This is the deactivation path: the deactivation layer first uses probability... Perform Dropout, then pass through the fully connected weight matrix With bias Perform a linear transformation and finally output an image quality score. The expression used as the evaluation result data is: The score is constrained to the [0,1] range under Sigmoid or Min-Max scaling, and can be directly used as a continuous quantitative result of any document image quality index such as sharpness, exposure quality, contrast adequacy, noise or compression artifact intensity, shadow / reflection coverage, etc.
[0082] The second is the classification path: the classifier path uses another set of fully connected weights to... Mapped to dimension Then, the level probability distribution is obtained through Softmax. ,in The expected distribution of the number of preset quality levels. It can be used as a continuous score, or the level corresponding to the highest probability can be directly taken as the discrete evaluation result.
[0083] Two paths coexist during the training phase and are supervised by regression loss and cross-entropy loss respectively. During the inference phase, one or both paths can be enabled depending on business needs. As long as the paths remain consistent during training and inference, the stability and interpretability of the evaluation results data can be ensured. Through the above fusion and mapping operations, the model can simultaneously complete the focus on key regions and the quantification of quality indicators without additional annotation, providing timely, reliable, and lightweight decision-making basis for subsequent business notification events.
[0084] The above embodiments, by employing a lightweight backbone network such as PPLCNetV3, obtain deep feature maps containing text details and interfering textures with only two downsampling operations, achieving millisecond-level feature extraction; leveraging self-generated text masks and attention maps, they achieve self-supervised localization of foreground regions without manual pixel annotation, significantly reducing data preparation costs; and by using a fusion layer to apply learnable coefficients to attention-weighted features and global average features. The linear combination of these methods balances local sensitivity and overall robustness, and outputs continuous scores and discrete level probability distributions in parallel. Combined with joint supervision of regression loss and cross-entropy loss, the model can simultaneously optimize region consistency and quality discrimination accuracy during the training phase. When finally deployed, the mask prediction network is pruned as a whole, and the total number of parameters of the remaining backbone, attention layer, fusion layer and selected output path is reduced to less than 15MB. It can complete millisecond-level inference on the central processing unit, significantly saving computing power and storage overhead, and ensuring that it provides real-time, interpretable and stable image quality assessment capabilities in high-concurrency scenarios such as online document upload and real-time retake prompts.
[0085] Based on any embodiment of the method in this application, the comprehensive loss corresponding to the sample image is determined by associating the loss between the text mask and the attention map, and the loss between the evaluation result data and the evaluation reference data in the training data, including: Step S2310: Using the text mask and attention map generated by the model, calculate the consistency loss between the text mask and the attention map; Consistency loss is used to quantize text masks. With attention map By forcing the distributions of the two to converge, the difference in spatial dimensions allows the attention map to automatically approximate the foreground region during the training phase, thus enabling spatial supervision without the need for manual pixel-level labeling.
[0086] In practice, this loss is calculated using pixel-wise L2 distance, and its expression is as follows: in and These represent the height and width of the feature map, respectively. Spatial subscript, and All values are constrained to the [0,1] interval by the Sigmoid function, so the loss value falls between 0 and 1, which makes it easy to keep the magnitude consistent with the difference loss.
[0087] When attention map With text mask When the text region is close to 1 or the background region is close to 0, the loss approaches 0, indicating good spatial consistency. Conversely, if the attention map responds highly to the background but poorly to the foreground, the loss increases rapidly. Backpropagation will drive the update of the attention layer parameters, causing high weights to focus on text strokes, table lines, or stamp areas. To avoid numerical instability caused by a zero denominator or weak spatial response, the loss can be adjusted before summation. and At the same time, a very small constant is added, or a Clip operation is performed on the loss after the calculation is completed, so that its upper limit does not exceed 1, thereby ensuring that the gradient magnitude is within a controllable range.
[0088] When the business side has higher requirements for edge accuracy, the consistency loss can be extended to a weighted form, that is, a learnable or manually set spatial weight map is introduced into the summation to assign a larger penalty coefficient to edge regions; the L1 norm, Huber loss, or Dice loss can also be used instead of the L2 norm, as long as the output remains a scalar and attention map is maintained. Text mask If the gradient is differentiable, it can be directly embedded into the existing backpropagation process to achieve the same self-supervised correction effect.
[0089] Step S2320: Using the evaluation result data output by the model and the evaluation reference data in the training data, calculate the difference loss between each evaluation result data and the evaluation reference data. The difference loss quantifies the numerical deviation between the evaluation result data output by the model and the evaluation reference data in the training data, providing a supervisory signal that can be directly optimized for the quality score or grade distribution. Depending on the actual configuration, the evaluation result data can include, alone or simultaneously, the continuous image quality score output by the deactivated layer and the discrete grade probability distribution output by the classifier. The evaluation reference data is the pre-prepared evaluation reference data in the corresponding training data, and its form is a floating-point value within a preset scoring range.
[0090] For the deactivated layer path, the difference loss is calculated using the mean squared error, and its corrected expression is as follows: in The image quality score is obtained after linear transformation of the deactivated layer and sigmoid constraint. To evaluate the reference data, both were scaled to the [0,1] interval, so the upper limit of the loss range is 1, which makes it easier to keep the magnitude consistent with the consistency loss.
[0091] For the classifier path, the difference loss uses soft cross entropy, and its expression is: in For batch size, To preset the quantity of quality grades, For the classifier corresponding to the first The nth sample image, after being processed by Softmax, is the nth... The probability obtained at each level To make the first Evaluation reference data The first, obtained through Gaussian weighted or linear interpolation transformation The probability of soft labels at each level This allows the model to still obtain continuous gradient feedback at discrete levels.
[0092] The two paths can be used individually or simultaneously and combined in a weighted manner. As long as the same path is used in both the training and inference phases, the stability and interpretability of the evaluation results data can be ensured. When the business side is sensitive to outliers, the difference loss can be replaced with L1 norm, Huber loss, or Smooth L1, as long as the appropriate parameters are met. and By maintaining differentiability, it can be directly embedded into the existing backpropagation process to achieve the same numerical regression or level discrimination effect.
[0093] Step S2330: The consistency loss and each of the difference losses are weighted and fused into a comprehensive loss corresponding to the sample image.
[0094] After determining the consistency loss and each individual difference loss, the consistency loss and difference loss are weighted and merged into a comprehensive loss. Simultaneous optimization under spatial and numerical supervision is achieved through preset weight coefficients. The expression for the comprehensive loss is: in , , All of these are non-negative weight coefficients, used to balance the magnitude of different losses with gradient contributions. Their values can be obtained through grid search, empirical fixing, or dynamic adaptation. As long as the same set of coefficients is maintained throughout the training process, convergence stability can be ensured. Corresponding to the text mask and attention defined earlier Figure 1 Sexual damage, Mean square error corresponding to the path of the deactivation layer The soft cross-entropy loss corresponding to the classifier path.
[0095] When only a single path is enabled on the business side, the weight coefficients of the unenabled paths are set to zero, and the overall loss degenerates into a two-item or single-item form. Parameter updates can still be completed through backpropagation. The weight coefficients can be stored in floating-point form in the configuration file, or they can be implemented as learnable parameters and updated with gradients along with the network weights. As long as the coefficients are non-negative and sum to one, training oscillations caused by imbalances in the magnitude of the loss can be avoided. Through this weighted fusion method, the model receives spatial consistency and numerical accuracy supervision simultaneously in one forward and backward loop, thus achieving a lightweight deployment form that focuses on text regions and outputs accurate scores at the end of training.
[0096] The above embodiments calculate consistency loss, mean squared error loss, and soft cross-entropy loss in one go, and perform weighted fusion with configurable weight coefficients. This allows the model to simultaneously receive multi-task joint supervision of spatial consistency and numerical accuracy in a single iteration, ensuring that the attention map and the self-generated text mask converge, and that the continuous scoring and discrete level distribution approximate the evaluation reference data. As a result, after training convergence, a lightweight network form that focuses on text regions and outputs accurate quality indicators is obtained, which significantly reduces annotation costs and improves training efficiency.
[0097] Based on any embodiment of the method in this application, using the evaluation result data output by the model and the evaluation reference data in the training data, the difference loss corresponding to each evaluation result data and the evaluation reference data is calculated, including: Step S2321: Call the evaluation reference data in the training data. The evaluation reference data is a value within a preset scoring range. The model includes a classifier and / or a deactivation layer for mapping the fused features formed by the fusion of the deep feature map and the attention map. The classifier is used to map the fused features to multiple image quality levels to obtain the corresponding level probability distribution as the evaluation result data. The deactivation layer is used to map the fused features to a single image quality score as the evaluation result data. In this step, the evaluation reference data from the training data is invoked, and the current output path type enabled by the model is determined simultaneously. As revealed earlier, the evaluation reference data consists of continuous values within a preset scoring range, and its numerical range is consistent with the quality dimensions that the business focuses on, including but not limited to floating-point numbers between 0 and 1 or integers between 0 and 100.
[0098] The model can be flexibly configured with classifiers and / or deactivation layers for mapping fused features: the classifier transforms the fused features into a probability distribution of K image quality levels through a fully connected Softmax layer, and the deactivation layer transforms the fused features into a single image quality score through a fully connected layer with optional Dropout; the two paths can be enabled individually or simultaneously during the training phase, as long as they correspond to the evaluation reference data in subsequent loss calculations.
[0099] After reading the evaluation reference data, the computer equipment binds its value to the current batch of sample image identifiers and determines whether to enter the grade distribution conversion process in step S2322 or the continuous value regression process in step S2323 based on the configured flag bit, thereby ensuring that the difference loss calculation and the form of the supervision signal are strictly aligned.
[0100] Step S2322: When the model includes the classifier, the evaluation reference data is converted into a rating probability distribution corresponding to the multiple image quality levels, and the cross-entropy loss is calculated as the first difference loss using the rating probability distribution and the level probability distribution as the evaluation result data. When a classifier branch is incorporated into a document image quality assessment model, the corresponding first difference loss needs to be considered. Since the evaluation reference data is represented by numerical single values, a flexible transformation is required to convert it into a rating probability distribution. This allows continuous labels to be compared dimension-by-dimensionally with the discrete level probability distribution output by the classifier, thereby completing backpropagation through flexible cross-entropy loss.
[0101] The conversion process uses a preset... Centered on an image quality level, Gaussian weighting or linear interpolation methods can be used to transform a single numerical value... Expanded into a probability vector equal to the number of levels. ,satisfy ,and .
[0102] In the Gaussian weighted implementation, each level center and The difference is measured by standard deviation After control, the probability is obtained through the normalization exponent: in It can take a fixed value, such as 0.1 or 0.2, or it can be adaptively set according to the statistical standard deviation of the training set. For example, when Take the smaller value (e.g., 0.1). When the value is 0.6, this formula can achieve the following soft label probability. This Gaussian smoothing-based label expansion method can maintain gradient continuity between adjacent levels, avoid training oscillations caused by hard labels, thereby improving early convergence speed and enhancing the regression smoothness of the model.
[0103] In the linear interpolation implementation, only for Two adjacent levels are assigned non-zero weights, which are inversely proportional to the distance. The remaining levels are set to zero to ensure that the peak position of the probability distribution remains consistent with the original value.
[0104] Both transformation methods are performed independently for each sample within a batch, resulting in a transformed probability vector. The probability distribution of the classifier output They are fed together into the cross-entropy loss calculation to obtain the first difference loss, thus achieving a seamless mapping from continuous labels to discrete supervision.
[0105] Step S2323: When the model includes the deactivated layer, the regression loss is calculated as the second difference loss using the scoring reference data and the image quality score as the evaluation result data.
[0106] When the model uses the deactivated layer path, as revealed above, the evaluation reference data and the image quality score output by the deactivated layer are directly fed into the regression loss calculation. The specific solution can be obtained by following the formula revealed above, which will not be elaborated further.
[0107] In the training phase, the above embodiments only require assigning coarse-grained numerical evaluation reference data to the sample images, without any pixel-level or grade-level fine annotation. The computer device can instantly convert this value into a scoring probability distribution corresponding to the classifier path through Gaussian weighting or linear interpolation. At the same time, it can directly perform regression loss calculation with the image quality score output by the deactivated layer. Thus, within the same training process, it can flexibly adapt to model configurations that enable the classifier, enable the deactivated layer, or enable both output paths simultaneously. It achieves a seamless two-way mapping from continuous labels to discrete distributions and continuous scores, significantly reducing annotation costs and manpower input, and ensuring that different paths maintain strict alignment of the supervision signal form during the training and inference phases, thereby improving the model convergence speed and deployment efficiency.
[0108] Based on any embodiment of the method in this application, triggering a business notification event corresponding to the original document image according to the evaluation result data includes: Step S3310: Determine whether the evaluation result data meets the preset scoring conditions. When the preset scoring conditions are met, trigger the first business notification event corresponding to the downstream business. After obtaining the evaluation results data output by the model, it is compared with the preset scoring criteria to determine whether to trigger the first business notification event. These scoring criteria can be set by the business side once during the deployment phase, and support various forms such as single threshold comparison, multi-interval segmentation, level label matching, or comprehensive weighted score determination.
[0109] For example, when the evaluation result data is a continuous image quality score output by the deactivated layer, the threshold can be set to 0.7. If the image quality score... If the condition is met, it is considered passed; otherwise, it is considered failed. When the evaluation result data is the probability distribution of the classifier's output levels, the condition can be set to the sum of the probabilities of "clear" and "relatively clear" being ≥0.8. The condition judgment logic runs in memory in an atomic manner, with a latency of less than milliseconds, ensuring that the traffic splitting can still be completed in real time under high-concurrency scenarios.
[0110] Once the scoring criteria are determined and confirmed, a first business notification event is generated to send corresponding notification messages to subsequent processes. The event content may include evaluation result data, image identifiers, timestamps, and optional attention maps, which are used to drive downstream modules such as text detection, text recognition, structured information extraction, or automatic review, to achieve an end-to-end automated link of evaluation before processing.
[0111] Step S3320: When the preset scoring conditions are not met, a second business notification event is triggered to notify the user to retransmit the original document image.
[0112] When the evaluation results fail to meet the preset scoring conditions, a second business notification event can be triggered to instruct the user to re-collect or replace the original document images. The event can be delivered via in-app pop-ups, SMS, emails, instant messages, or web scripts. The content fields can include an identifier such as "quality unsatisfactory," optional reasons for failure labels, and a re-upload link, allowing users to complete subsequent operations independently without the need for human customer service.
[0113] The retransmission entry link is provided in the form of a Uniform Resource Locator or a deep link, which can directly invoke the mobile terminal's camera or scanner driver and automatically bring in the business serial number of the last upload, ensuring that the re-captured image is continuously bound to the original business process.
[0114] In one embodiment, the second service notification event may also include shooting guidance illustrations, including suggested lighting angles, shooting distances, background selection, and image stabilization tips, to guide users to avoid the same quality defects during the second data capture.
[0115] After the event is triggered, the computer device marks the current original document image as returned and writes it to the log to prevent images that have not passed the recognition process from entering the downstream recognition process, thereby reducing the waste of computing power while ensuring recognition accuracy.
[0116] When the business side needs to perform batch operations, the second business notification event can be pushed in batches through message queues or application interfaces, supporting second-level retransmission prompts in high-concurrency online insurance, remote account opening, mobile government affairs and remote medical consultation scenarios, ensuring that the overall link maintains closed-loop control of assessment before processing.
[0117] The above embodiments use millisecond-level judgment to instantly separate qualified and unqualified images. On the qualified side, the first business notification event triggers the subsequent business process within seconds, while on the unqualified side, the second business notification event pushes relevant notification messages and processing information within seconds. This not only prevents low-quality images from entering the downstream computing power link to reduce resource waste, but also improves the success rate of secondary acquisition through standardized re-capture guidance, ensuring the overall recognition accuracy and business processing efficiency.
[0118] Based on any embodiment of the method in this application, after triggering the first service notification event corresponding to the initiation of downstream services, the method includes: Step S4100: In response to the first service notification event, obtain the attention map output by the document image quality assessment model; Upon triggering the first business notification event, the downstream business module responds by retrieving the attention map corresponding to the current original document image from the document image quality assessment model's memory buffer. For visualization of this attention map, please refer to [link / reference needed]. Figure 3 The image on the right is shown in the image below, which is based on... Figure 3 The attention map is generated from the image on the left. It corresponds to a single-channel probability matrix generated during the training phase, where each pixel value represents the importance of its corresponding location within the text information region. Therefore, it can be transformed into... Figure 3 The heatmap or grayscale image shown on the right side of the image effectively acts as a mask. Attention map extraction can be accomplished by calling the tensor handle provided by the model inference interface, eliminating the need for further forward computation and ensuring latency is below milliseconds. The spatial size of the attention map maintains a fixed proportional relationship with the original image and can be quickly scaled to the original resolution using bilinear interpolation or nearest-neighbor interpolation, allowing for direct use in subsequent pixel-level masking operations.
[0119] Step S4200: Extract the text region image of the original document image based on the attention map; Further reference Figure 3The original document image (left image) is spatially masked using a scaled attention map (right image). By setting a preset threshold or using an adaptive segmentation algorithm, pixel regions in the attention map above the threshold are marked as text regions. Based on this, a minimum bounding rectangle or polygonal cropping box is generated. After performing affine transformation or perspective correction on the original image, the text region image is obtained, thus completing the cropping of the original document image. In some embodiments, the cropping process can be performed independently on the color or grayscale channels, the output image format can be kept consistent with the input, and the resolution can be automatically adjusted according to the text size to ensure that the subsequent optical character recognition engine obtains the best recognition effect, while eliminating background, reflection, and moiré interference.
[0120] Step S4300: Perform text recognition based on the text region image to obtain structured medical information, wherein the structured information includes multiple attribute fields and their corresponding attribute data; Furthermore, the text region image is fed into a pre-set optical character recognition engine. Through text detection, character segmentation, and semantic error correction algorithms, printed or handwritten text content is extracted. Based on the characteristics of medical documents, the recognition results are mapped into structured medical information. This structured information includes, but is not limited to, attribute fields and their corresponding attribute data such as patient name, gender, age, date of visit, diagnosis, drug name, dosage, usage, test items, and reference ranges. The recognition process supports general medical terminology dictionaries and departmental custom dictionaries. Fields can be automatically labeled and normalized using regular expressions or natural language processing models such as named entity recognition models to ensure that the output conforms to relevant well-known medical information standard formats, facilitating direct parsing by downstream systems.
[0121] Step S4400: Add the structured medical information to a preset prompt template to obtain the corresponding prompt text, input it into a preset medical information analysis model, and obtain the corresponding medical information analysis results.
[0122] Structured medical information is populated according to a preset prompt template to generate prompt text in natural language. This template includes fixed field placeholders and optional medical knowledge base references, such as "Patient {name}, {age} years, diagnosis {diagnosis result}, suggested attention to {drug name} dosage". The populated prompt text is then fed into a preset medical information analysis model, which includes, but is not limited to, a Transformer-based disease risk assessment network, a medication conflict detection rule engine, or a clinical decision support system. This model outputs corresponding medical information analysis results, which can be returned to the business system in the form of risk level, medication recommendations, or follow-up reminders, completing an end-to-end automated link from image quality assessment to clinical decision support.
[0123] As explained above, in medical scenarios where data integrity, recognition accuracy, and response speed are critically demanding, this embodiment achieves millisecond-level precise text region localization and cropping by reusing the attention map output by the document image quality assessment model. This prevents low-quality images from entering the subsequent optical character recognition stage, significantly improving the accuracy of structured medical information extraction. By combining a medical terminology dictionary and a named entity recognition model, the recognition results are automatically mapped to standard attribute fields. Furthermore, through prompt templates and a medical information analysis model, second-level feedback on risk levels, medication conflicts, or follow-up reminders is achieved, forming an end-to-end automated link from image upload to clinical decision-making recommendations. This reduces the cost of manual review while ensuring the timeliness and reliability of treatment decisions.
[0124] Please see Figure 4 This document image quality assessment device, provided to meet one of the purposes of this application, is a functional embodiment of the document image quality assessment method of this application. The device includes an image acquisition module 3100, a model inference module 3200, and a business notification module 3300. The image acquisition module 3100 is configured to acquire original document images submitted by users. The model inference module 3200 is configured to use a preset document image quality assessment model to infer the original document image and determine the corresponding evaluation result data. The business notification module 3300 is configured to trigger a business notification event corresponding to the original document image based on the evaluation result data. During its training phase, the document image quality assessment model extracts depth feature maps from sample images, generates attention maps and text masks indicating text information regions based on the depth feature maps, and generates evaluation result data representing the image quality assessment results. It then correlates the loss between the attention map and the text mask, and the loss between the evaluation result data and its evaluation reference data, to determine the comprehensive loss corresponding to the current training iteration.
[0125] Based on any embodiment of the device in this application, prior to the image acquisition module 3100, this device further includes: a data preparation module, configured to acquire a training dataset, the training dataset including multiple training data, each training data including sample images and their evaluation reference data, wherein at least some sample images contain text information; a data input module, configured to call the training data to input a document image quality assessment model for training, the model extracting depth feature maps from the sample images in the training data, generating an attention map and a text mask indicating the text information region based on the depth feature maps, and evaluation result data characterizing the image quality evaluation result; a loss determination module, configured to correlate the loss between the text mask and the attention map, and the loss between the evaluation result data and the evaluation reference data in the training data, to determine the comprehensive loss corresponding to the sample image; and a supervised iteration module, configured to supervise the iterative training of the model until convergence based on the comprehensive loss.
[0126] Based on any embodiment of the apparatus in this application, the data input module includes: a representation learning module, configured to call the feature representation network of the document image quality assessment model in the training data to perform feature representation and obtain a depth feature map; a mask generation module, configured to generate a text mask indicating the text information region of the sample image based on the depth feature map by the mask prediction network of the model; an attention conversion module, configured to generate an attention map indicating the text information region of the sample image based on the depth feature map by the attention layer of the model; and a fusion mapping module, configured to fuse the depth feature map and the attention map by the fusion layer of the model, and output and map it as evaluation result data.
[0127] Based on any embodiment of the device in this application, the loss determination module includes: a consistency loss determination module, configured to calculate the consistency loss between the text mask and the attention map generated by the model; a difference loss determination module, configured to calculate the difference loss between each evaluation result data and the evaluation reference data in the training data using the evaluation result data output by the model and the evaluation reference data; and a loss fusion determination module, configured to weight and fuse the consistency loss and each difference loss into a comprehensive loss corresponding to the sample image.
[0128] Based on any embodiment of the apparatus in this application, the difference loss determination module includes: a reference data retrieval module, configured to retrieve evaluation reference data from the training data, wherein the evaluation reference data is a value within a preset scoring range; the model includes a classifier and / or a deactivated layer for mapping the fused features formed by fusing the deep feature map and the attention map; the classifier is used to map the fused features to multiple image quality levels to obtain corresponding level probability distributions as the evaluation result data; the deactivated layer is used to map the fused features to a single image quality score as the evaluation result data; a classification loss determination module, configured to, when the model includes the classifier, convert the evaluation reference data into a scoring probability distribution corresponding to the multiple image quality levels, and calculate a cross-entropy loss as a first difference loss using the scoring probability distribution and the level probability distribution used as the evaluation result data; and a regression loss determination module, configured to, when the model includes the deactivated layer, calculate a regression loss as a second difference loss using the scoring reference data and the image quality score used as the evaluation result data.
[0129] Based on any embodiment of the device in this application, the service notification module 3300 includes: a judgment triggering module, configured to judge whether the evaluation result data meets the preset scoring conditions, and when the preset scoring conditions are met, triggering a first service notification event corresponding to the downstream service; and an exception handling module, configured to trigger a second service notification event to notify the user to retransmit the original document image when the preset scoring conditions are not met.
[0130] Based on any embodiment of the device in this application, following the determination triggering module, the device further includes: a notification response module, configured to respond to the first business notification event and obtain the attention map output by the document image quality assessment model; a text region extraction module, configured to extract the text region image of the original document image based on the attention map; a text recognition module, configured to perform text recognition based on the text region image to obtain structured medical information, the structured information including multiple attribute fields and their corresponding attribute data; and an information analysis module, configured to add the structured medical information to a preset prompt template to obtain corresponding prompt text, input it into a preset medical information analysis model, and obtain corresponding medical information analysis results.
[0131] To address the aforementioned technical problems, embodiments of this application also provide a computer device. For example... Figure 5The diagram shows the internal structure of a computer device. This computer device includes a processor, a computer-readable storage medium, a memory, a network interface, and various communication components connected via a system bus. The computer-readable storage medium stores an operating system, a database, and computer-readable instructions. The database may store a sequence of control information. When executed by the processor, the computer-readable instructions enable the processor to implement a document image quality assessment method. The processor provides computational and control capabilities, supporting the operation of the entire computer device. The memory stores computer-readable instructions, which, when executed by the processor, enable the processor to execute the document image quality assessment method of this application. The network interface of the computer device is used for communication with a terminal. Those skilled in the art will understand that… Figure 5 The structure shown is merely a block diagram of a portion of the structure related to the present application and does not constitute a limitation on the computer device to which the present application is applied. Specific computer devices may include more or fewer components than those shown in the figure, or combine certain components, or have different component arrangements.
[0132] In this embodiment, the processor is used to execute... Figure 4 The system includes the specific functions of each module and its sub-modules, and stores the program code and various data required to execute these modules or sub-modules. A network interface is used for data transmission between the user terminal and the server. In this embodiment, the memory stores the program code and data required to execute all modules / sub-modules in the document image quality assessment device of this application, and the server can call the server's program code and data to execute the functions of all sub-modules.
[0133] This application also provides a storage medium storing computer-readable instructions, which, when executed by one or more processors, cause the one or more processors to perform the steps of the document image quality assessment method of any embodiment of this application.
[0134] Those skilled in the art will understand that all or part of the processes in the methods of the above embodiments of this application can be implemented by a computer program instructing related hardware. This computer program can be stored in a computer-readable storage medium, and when executed, it can include the processes of the embodiments of the methods described above. The aforementioned storage medium can be a magnetic disk, optical disk, read-only memory (ROM), or random access memory (RAM), etc.
[0135] Those skilled in the art will understand that the steps, measures, and solutions in the various operations, methods, and processes discussed in this application can be alternated, modified, combined, or deleted. Furthermore, other steps, measures, and solutions in the various operations, methods, and processes discussed in this application can also be alternated, modified, rearranged, decomposed, combined, or deleted. Furthermore, steps, measures, and solutions in the prior art that are similar to those in the open-source operations, methods, and processes of this application can also be alternated, modified, rearranged, decomposed, combined, or deleted.
[0136] The above description is only a partial embodiment of this application. It should be noted that for those skilled in the art, several improvements and modifications can be made without departing from the principle of this application, and these improvements and modifications should also be considered within the scope of protection of this application.
Claims
1. A method of document image quality assessment, characterized by, The method comprises: obtaining an original document image submitted by a user; using a preset document image quality evaluation model to infer the original document image to determine corresponding evaluation result data of the original document image; triggering a business notification event corresponding to the original document image according to the evaluation result data; wherein, in the training stage of the document image quality evaluation model, a deep feature map is extracted from a sample image, an attention map and a text mask indicating a text information region are generated based on the deep feature map, and evaluation result data representing an image quality evaluation result is generated, a loss between the attention map and the text mask, a loss between the evaluation result data and evaluation reference data thereof are associated, and a comprehensive loss corresponding to the current training is determined.
2. The method of claim 1, wherein, Before obtaining the original document image submitted by the user, the method comprises: obtaining a training data set, the training data set comprising a plurality of training data, each training data comprising a sample image and evaluation reference data thereof, wherein at least part of the sample images contain text information; calling the training data to input a document image quality evaluation model to implement training, extracting a deep feature map from the sample image in the training data by the model, generating an attention map and a text mask indicating a text information region based on the deep feature map, and generating evaluation result data representing an image quality evaluation result; associating a loss between the text mask and the attention map, a loss between the evaluation result data and the evaluation reference data in the training data, and determining a comprehensive loss corresponding to the sample image; supervising iterative training of the model to convergence according to the comprehensive loss.
3. The method of claim 2, wherein calling the training data to input a document image quality evaluation model to implement training, extracting a deep feature map from the sample image in the training data by the model, generating an attention map and a text mask indicating a text information region based on the deep feature map, and generating evaluation result data representing an image quality evaluation result, comprises: calling the sample image in the training data to input a feature representation network of the document image quality evaluation model for feature representation to obtain a deep feature map; generating a text mask indicating a text information region of the sample image based on the deep feature map by a mask prediction network of the model; generating an attention map indicating a text information region of the sample image based on the deep feature map by an attention layer of the model; fusing the deep feature map and the attention map by a fusion layer of the model, and then outputting and mapping as evaluation result data.
4. The method of claim 2, wherein, associating a loss between the text mask and the attention map, a loss between the evaluation result data and the evaluation reference data in the training data, and determining a comprehensive loss corresponding to the sample image, comprises: calculating a consistency loss of the text mask and the attention map using the text mask and the attention map generated by the model; calculating a difference loss between each evaluation result data and the evaluation reference data corresponding thereto using the evaluation result data output by the model and the evaluation reference data in the training data; The consistency loss and each of the difference losses are fused as a comprehensive loss corresponding to the sample image.
5. The method of claim 4, wherein, The evaluation result data output by the model and evaluation reference data in the training data are used to calculate a difference loss corresponding to each evaluation result data and the evaluation reference data, including: The evaluation reference data in the training data is called, the evaluation reference data is a numerical value in a preset score range, the model includes a classifier and / or an inactive layer for mapping a fusion feature formed by fusing the deep feature map and the attention map, the classifier is used to map the fusion feature to a plurality of image quality levels to obtain a corresponding level probability distribution as the evaluation result data, and the inactive layer is used to map the fusion feature to a single image quality score as the evaluation result data; When the model contains the classifier, the evaluation reference data is converted into a score probability distribution corresponding to the plurality of image quality levels, and a cross-entropy loss is calculated as a first difference loss between the score probability distribution and the level probability distribution as the evaluation result data; When the model contains the inactive layer, a regression loss is calculated as a second difference loss between the score reference data and the image quality score as the evaluation result data.
6. The method of claim 1 to 5, wherein According to the evaluation result data, a business notification event corresponding to the original document image is triggered, including: It is judged whether the evaluation result data meets a preset score condition, and when the preset score condition is met, a first business notification event corresponding to a downstream business is triggered; When the preset score condition is not met, a second business notification event is triggered to notify the user to retransmit the original document image.
7. The method of claim 6, wherein, After triggering the first business notification event corresponding to the downstream business, including: In response to the first business notification event, the attention map output by the document image quality evaluation model is obtained; According to the attention map, a text region image of the original document image is extracted; Text recognition is performed based on the text region image to obtain structured medical information, the structured information including a plurality of attribute fields and corresponding attribute data; The structured medical information is added to a preset prompt template to obtain corresponding prompt text, which is input into a preset medical information analysis model to obtain corresponding medical information analysis results.
8. A document image quality evaluation apparatus characterized by comprising: Including: An image acquisition module is configured to acquire an original document image submitted by a user; A model inference module is configured to infer the original document image using a preset document image quality evaluation model to determine evaluation result data corresponding to the original document image; A business notification module is configured to trigger a business notification event corresponding to the original document image according to the evaluation result data. In the training phase of the document image quality evaluation model, a deep feature map is extracted from a sample image, an attention map indicating a text information region and a text mask are generated based on the deep feature map, evaluation result data representing an image quality evaluation result are generated, a loss between the attention map and the text mask is determined, a loss between the evaluation result data and evaluation reference data thereof is determined, and a comprehensive loss corresponding to the current training is determined. 9.A computer device, comprising a processor and a memory, wherein the computer device is configured to perform the method according to any one of claims 1-8. The processor invokes a computer program in the memory to execute the steps of the document image quality evaluation method according to any one of claims 1 to 7.
10. A computer-readable storage medium, characterized in that, The computer program is stored in the form of computer readable instructions and is implemented according to the method of any one of claims 1 to 7. When the computer program is invoked and run by a computer, the steps included in the corresponding method are executed.