A document artifact removal method based on improved Transformer
By introducing Swin Transformer and multi-head cross attention connection into the U-Net network, combined with the dual upsampling module, the problem of artifact removal in scanned documents is solved, the model's ability to identify artifacts and errors in scanned documents is improved, and the Accuracy of document information extraction.
Patent Information
- Application Number
- CN202311076341.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-08-25
- Publication Date
- 2024-09-03
- Estimated Expiration
- 2043-08-25
AI Technical Summary
Existing technologies struggle to effectively remove artifacts when processing scanned documents, especially new entities such as rare names, addresses, or contact details, and the datasets are relatively small and have low variability, and cannot effectively handle compression errors, image downsampling, and characters. Problems such as blur.
Introduce Swin Transformer into the U-Net network to form the SU-Net network, replace the skip connection with a multi-head cross-attention connection, avoid checkerboard artifacts through a double upsampling module, and construct a synthetic data set containing artifacts and clear contrast images for training .
Establish the association between the decoder and the encoder through the multi-head cross-attention module, improve the model's ability to identify artifacts and errors in documents, enhance the model's expression ability and performance, especially when processing scanned documents, it can extract key points more effectively information.
Smart Images

Figure CN117196972B
Abstract
Description
Technical Field
[0001] The present invention relates to the field of OCR technology, and in particular to a document artifact removal method based on an improved Transformer. Background Art
[0002] As Natural Language Processing (NLP) and Natural Language Understanding (NLU) continue to grow in importance, powerful language models create a wide range of possibilities for optimizing outdated processes.
[0003] In the existing technology, these outdated processes include processing non-fully digital data such as scanned documents, printouts, and faxes. However, extracting text information from these scanned documents and obtaining high-quality OCR results is not always easy. Various errors and quality issues may exist in the document scanning process, and improving document quality is a challenging task. Therefore, the problem is usually solved by correcting errors in the extracted text instead of directly improving the document quality. This approach can help improve the performance of natural language models and improve the ability to accurately extract important information from documents. However, these methods cannot correct new entities, such as rare names, addresses, or contact information (telephone, fax, email address), which are very important for information extraction tasks.
[0004] To address these issues, several approaches have been proposed, such as using generative adversarial networks (GANs) or convolutional autoencoders to improve the quality of text in documents. These approaches aim to improve the accuracy of OCR results and the readability of text, thereby providing a more reliable foundation for information extraction and other related tasks. The application of these techniques allows for better processing of text information in documents, identifying and correcting errors, and making the text easier to understand and analyze. However, these studies primarily focus on removing artifacts generated by noisy backgrounds, using relatively small datasets with low data variability. In addition to noise, OCR recognition results are often affected by compression errors, image downsampling, and character blurring. Summary of the Invention
[0005] The purpose of the present invention is to provide a document artifact removal method based on an improved Transformer to solve the problems raised in the above background technology.
[0006] To achieve the above objectives, the present invention provides the following technical solution: a document artifact removal method based on an improved Transformer, the method comprising the following steps:
[0007] S1. Introduce Swin Transformer into U-Net network to form SU-Net network;
[0008] S2, replace the skip connection in the SU-Net network with a multi-head cross attention connection;
[0009] S3. Build the improved SU-Net network after dataset training.
[0010] Preferably, the specific operations of introducing Swin Transformer into the U-Net network to form the SU-Net network include:
[0011] In SU-Net, 3×3 convolution is used to obtain shallow features of the input image, and feature extraction is performed through the U-Net network. The Swin Transform Block is used as the basic extraction module to replace the ordinary convolution layer in U-Net and obtain high-level semantic information, and 3×3 convolution is used to restore the reconstructed image.
[0012] Preferably, when Swin Transformer is introduced into the U-Net network to form the SU-Net network, a double upsampling module is proposed, which combines bilinear interpolation and pixel rearrangement to avoid checkerboard artifacts.
[0013] Preferably, in U-Net, the skip connection is achieved by connecting the feature map of the encoder with the feature map of the corresponding layer of the decoder.
[0014] Preferably, when constructing a dataset to train the improved SU-Net network, the model is trained with documents containing both artifacts and their clear counterparts.
[0015] Preferably, when constructing a dataset to train the improved SU-Net network, a synthetic dataset is created. The clean real documents come from the PubLayNet dataset. The dataset is used for document layout analysis tasks and has a variety of document structures, fonts, and font sizes. Comparative images containing artifacts are constructed by synthetically adding compression errors, pixelation errors in text, and noise.
[0016] Compared with the prior art, the present invention has the following beneficial effects:
[0017] The document artifact removal method based on the improved Transformer proposed in this invention introduces a multi-head cross-attention module in SU-Net, which enables the model to establish associations between the decoder and the encoder and selectively pass important contextual information. This design allows the model to better understand the correlations in the image, thereby more effectively processing the key information in the scanned document. Especially when processing images containing text, the model can focus on processing artifacts and errors close to the text area, improving the ability to recognize important information. In addition, passing the encoder information into the deep state of the decoder provides the model with the opportunity to access pixels and features extracted from the encoder, further enhancing the model's expressiveness and performance. BRIEF DESCRIPTION OF THE DRAWINGS
[0018] Figure 1 This is the SU-Net network structure diagram of the present invention;
[0019] Figure 2 Schematic diagram of the decoder that introduces cross-attention connections for the present invention;
[0020] Figure 3 Schematic diagram of the SU-Net network structure that introduces cross-attention connections in this invention. DETAILED DESCRIPTION
[0021] In order to clearly and completely describe the objectives and technical solutions of the present invention and make the advantages more clearly understood, the embodiments of the present invention are further described in detail below with reference to the accompanying drawings. It should be understood that the specific embodiments described herein are part of the embodiments of the present invention, not all of them, and are only used to explain the embodiments of the present invention, not to limit the embodiments of the present invention. All other embodiments obtained by ordinary technicians in this field without making creative efforts are within the scope of protection of the present invention.
[0022] See also Figures 1 to 3 The present invention provides a technical solution: a document artifact removal method based on an improved Transformer, the method comprising the following steps:
[0023] S1. Introduce Swin Transformer into U-Net network to form SU-Net network;
[0024] S2, replace the skip connection in the SU-Net network with a multi-head cross attention connection;
[0025] S3. Build the improved SU-Net network after dataset training.
[0026] In step S1, the U-Net network is a well-known architecture in many image processing applications because it has a hierarchical feature map that can capture rich multi-scale contextual features. In addition, it also uses jump connections between the encoder and decoder to enhance the image reconstruction process. U-Net is widely used in many computer vision tasks, such as image segmentation, image restoration, etc. Due to its powerful adaptive backbone structure, U-Net can be easily combined with different feature extraction modules to improve performance. The Transformer model has achieved success in the field of natural language processing (NLP). However, there are two major problems in directly applying the Transformer to visual tasks: 1) The scale difference between images and sequences is large. The Transformer has shortcomings in modeling long sequences because it requires more parameters to model than one-dimensional sequences, which is approximately the square of the number of parameters. 2) The Transformer is not good at solving pixel-level dense prediction tasks, such as instance segmentation. The Swin Transformer solves the above problems by using a moving window to reduce the number of parameters and achieves state-of-the-art performance in many pixel-level visual tasks.
[0027] In SU-Net, 3×3 convolution is first used to obtain the shallow features of the input image. Then, feature extraction is performed through the U-Net network, and the Swin Transform Block is used as the basic extraction module to replace the ordinary convolution layer in U-Net and obtain high-level semantic information. Finally, 3×3 convolution is used to restore the reconstructed image. The SU-Net network structure is as follows Figure 1 As shown in Figure 2 , SU-Net uses a patch merging operation for downsampling. Patch merging involves concatenating the input features of adjacent 2×2 patches and applying a linear layer to produce output features with a specified number of channels. This operation can be considered the first step of a convolution operation, namely, expanding the input feature map. In this process, adjacent patches are merged together to reduce the size of the feature map. Through concatenation and linear transformation, the input feature map is converted into output features with a specified number of channels. This provides richer context for subsequent processing and allows for feature representations at different scales. For upsampling, the original SwinTransformer model uses a patch expansion method, which is equivalent to the transposed convolution in the upsampling module. However, transposed convolution is prone to blocking artifacts, meaning that the generated image may exhibit checkerboard artifacts. To address this issue, a new module, called the dual upsampling module, is proposed. It combines two commonly used upsampling methods: bilinear interpolation and pixel reordering, to avoid checkerboard artifacts. By combining these two methods, smoother and more accurate upsampling results can be achieved, improving the quality of image reconstruction and reducing undesirable artifacts.
[0028] In step S2, the jump connection refers to the jump connection in the original U-Net network. In U-Net, the jump connection is achieved by connecting the feature map of the encoder (downsampling path) with the feature map of the corresponding layer of the decoder (upsampling path). Specifically, the encoder gradually reduces the spatial size of the feature map through a series of convolution and pooling operations while increasing the number of channels. The decoder gradually restores the spatial size of the feature map through upsampling operations while reducing the number of channels. At each layer of the decoder, the feature map of the current layer is connected to the feature map of the corresponding encoder layer to form a jump connection. The role of the jump connection is to fuse low-level features with high-level features, so that the network can simultaneously use the underlying detail information and high-level semantic information for image segmentation. This fusion of multi-scale information helps to improve the accuracy and robustness of the network, especially when processing tasks such as boundary details and small objects.
[0029] The cross attention is the idea of mapping one potential array to another potential array. In the cross attention process, the key and value are defined as K = S e W k , V=S e W v , where K and V are the encoder states S e The linear projection of , represents the context information input to the module. This approach allows the selection of a context matrix with high dimensions, because the latent dimension of the representation passed by the previous decoder layer remains unchanged. The query vector Q = S d W Q is the linear projection of the current decoder state Sd. By projecting the key and value onto the encoder state and the query onto the decoder state, the attention mechanism is used to calculate the correlation between the query and the key and value, thereby achieving selective learning of context information. The decoder with cross attention connection is as follows Figure 2 As shown in Figure 2. The input of the decoder with a depth of n is the output of the nth SwinTransformerBlock and the input of the encoder with a depth of n-1. It is provided as context information to the decoder module with the cross attention connection. The SU-Net network with the cross attention connection is shown in Figure 2. Figure 3 shown.
[0030] In step S3, training the model requires both documents containing artifacts and their clear counterparts. Most large datasets only contain one or the other. Therefore, this patent creates a synthetic dataset of clean, real-world documents from the PubLayNet dataset, which is primarily used for document layout analysis tasks and features a variety of document structures, fonts, and sizes. A comparison image containing artifacts is then constructed by synthetically adding artifacts, including compression errors, pixelation errors in text, and noise.
[0031] While embodiments of the present invention have been shown and described, it will be appreciated by those skilled in the art that various changes, modifications, substitutions, and variations may be made to these embodiments without departing from the principles and spirit of the invention, and that the scope of the invention is defined by the appended claims and their equivalents.
Claims
1. A document artifact removal method based on an improved Transformer, characterized in that: The method comprises the following steps: S1. Introduce Swin Transformer into U-Net network to form SU-Net network; S2, replace the skip connection in the SU-Net network with a multi-head cross attention connection; S3, build a data set to train the improved SU-Net network; The operations of introducing Swin Transformer into U-Net to form SU-Net network include: In SU-Net, 3×3 convolution is first used to obtain shallow features of the input image, and then the U-Net network is used for feature extraction. The Swin Transform Block is used as the basic extraction module to replace the ordinary convolution layer in U-Net and obtain high-level semantic information, and then 3×3 convolution is used to restore the reconstructed image; When Swin Transformer is introduced into the U-Net network to form the SU-Net network, a double upsampling module is used. The double upsampling module combines bilinear interpolation and pixel rearrangement to avoid chessboard artifacts. In step S2, the jump connection refers to the jump connection in the original U-Net network. In the U-Net, the jump connection is realized by connecting the feature map of the encoder with the feature map of the corresponding layer of the decoder; When constructing a dataset to train the improved SU-Net network, the model was trained with documents containing both artifacts and their clear counterparts; Constructing a dataset When training the improved SU-Net network, a synthetic dataset is created. The clean real documents come from the PubLayNet dataset. The dataset is used for document layout analysis tasks and has a variety of document structures, fonts, and font sizes. Contrast images containing artifacts are constructed by synthesizing compression errors, pixelation errors in text, and noise.
