Ancient book text restoration method and system based on dual generative adversarial networks

Through the ancient book text repair method based on the dual generative adversarial network, using coarse-grained and fine-grained repair networks, the problems of slow repair speed and insufficient feature extraction capabilities in the existing technology are solved, and efficient and accurate ancient book text repair is achieved, expanding The receptive field range is increased and the repair efficiency is improved.

CN116665217BInactive Publication Date: 2024-09-24SUZHOU UNIV
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202310511259.1
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2023-05-08
Publication Date
2024-09-24
Estimated Expiration
Not applicable · inactive patent

AI Technical Summary

Technical Problem

The existing technology has problems such as slow repair speed, high labor cost, small receptive field range, and low feature extraction ability in ancient book text restoration. In particular, problems such as stroke discontinuity and structural distortion are prone to occur when a large area is damaged.

Method used

A method based on dual generative adversarial networks is used to construct a coarse repair network and a fine repair network. Through the coarse-grained and fine-grained repair processes, the receptive field range is expanded and the repair accuracy and efficiency are improved. Specific steps include building generative adversarial networks with different convolution structures, training coarse repair networks and fine repair networks, and using pixel loss, adversarial loss, style loss and content loss for training to achieve efficient text repair.

Benefits of technology

It effectively solves the problems of distortion, structural inaccuracy, and discontinuous strokes in the repair results, improves the accuracy and efficiency of the repair, makes the repair process easier, and significantly improves the repair effect of ancient book characters.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN116665217B
    Figure CN116665217B
Patent Text Reader

Abstract

The present invention relates to the field of image generation technology, and discloses a method and system for repairing ancient text based on a dual generative adversarial network. The method comprises: constructing a dual generative adversarial network including a coarse repair network and a fine repair network, obtaining a real text image, and generating a training set; inputting the training set into the generator of the coarse repair network to generate a coarse-grained text image and training the coarse repair network, inputting the coarse-grained text image and the real text image into a discriminator for discrimination; fixing the parameters of the coarse repair network, inputting the coarse-grained text image into the generator of the fine repair network to generate a fine-grained text image and training the fine repair network, inputting the fine-grained text image and the real text into the discriminator for discrimination; inputting the text image to be repaired into the trained dual generative adversarial network to complete the repair of the text; and the system comprises a module for implementing each step. The present invention can expand the range of the receptive field, make the repair process easier, and improve the repair accuracy and efficiency.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of image generation technology, and in particular to an ancient book text restoration method and system based on a dual generative adversarial network. Background Art

[0002] Words record the development of Chinese civilization, and studying words can help us study social history and culture. At present, many ancient books have been damaged due to a long period of time, and it takes a lot of manpower to restore them. In addition, using physical storage for ancient books and texts will also bring many problems, such as damage to ancient books due to moisture, human factors and other factors. Using physical storage requires a high price, increases maintenance costs, and is not conducive to dissemination. Therefore, at this stage, more and more digital methods are used to preserve ancient books and texts, and computer technology is used to restore damaged texts.

[0003] Generative Adversarial Network (GAN) is a type of generative model, consisting of a generator and a discriminator. GAN is widely used in fields such as image generation, and its core idea is "zero-sum game". The optimization of GAN can be defined as:

[0004]

[0005] Where z is the input random noise, p z is the distribution generated by the generator, G is the generator, and G(z) is generated according to the input noise z, p data is the distribution of real data. D is the discriminator, which judges the real data as true and the data generated by the generator as false. The model framework of GAN is as follows: Figure 1 shown.

[0006] Most of the methods for restoring and repairing ancient texts in the prior art use manual methods or image repair models. Manual methods have some disadvantages such as slow repair speed and high labor costs. After the ancient texts are digitized into images, they can be repaired using professional software such as PhotoShop, but there are also some problems: professional talents need to be trained, the staff need to have good text and calligraphy literacy, and the repair efficiency is not high. The shortcomings of the existing image repair model are: the receptive field is small and the ability to extract features is not high; when the ancient text is damaged over a large area, problems such as discontinuous strokes and structural distortion will occur. Summary of the invention

[0007] To this end, the technical problem to be solved by the present invention is to overcome the shortcomings of the prior art and provide an ancient book text restoration method and system based on a dual generative adversarial network, which can expand the receptive field range, make the restoration process easier, and improve the restoration accuracy and efficiency.

[0008] In order to solve the above technical problems, the present invention provides an ancient book text restoration method based on a dual generative adversarial network, comprising:

[0009] Constructing a dual generative adversarial network including a coarse repair network and a fine repair network, wherein the coarse repair network and the fine repair network are generative adversarial networks with different convolutional structures;

[0010] Get real text images, generate text images with different font styles and divide them into training sets and test sets;

[0011] Inputting the training set into the generator of the coarse repair network to generate a coarse-grained text image and train the coarse repair network; inputting the coarse-grained text image and the real text image into the discriminator of the coarse repair network for discrimination;

[0012] Fix the parameters of the coarse repair network, input the coarse-grained text image into the generator of the fine repair network, generate a fine-grained text image and train the fine repair network; input the fine-grained text image and the real text into the discriminator of the fine repair network for discrimination;

[0013] Obtain a text image to be repaired, input the text image to be repaired into the generator of the trained coarse repair network, and input the generated result into the generator of the trained fine repair network to complete the repair of the text.

[0014] In one embodiment of the present invention, the coarse repair network includes a downsampling layer, a bottleneck layer and an upsampling layer.

[0015] The downsampling layer includes multiple layers of convolutions with the same step size and convolution kernel size, the bottleneck layer includes multiple layers of dilation rate increasing layer by layer, and the upsampling layer includes multiple layers of transposed convolutions.

[0016] In one embodiment of the present invention, the downsampling layer includes three layers of convolution with a step size of 2 and a convolution kernel size of 4, and the bottleneck layer is formed by superimposing four layers of dilation convolution with expansion rates of 2, 4, 8, and 16.

[0017] In one embodiment of the present invention, the fine inpainting network includes a downsampling layer, a dilated convolution layer, a residual block layer and an upsampling layer.

[0018] The downsampling layer includes multiple layers of multi-scale residual gate convolution modules, the dilated convolution layer includes multiple layers of dilated convolutions with increasing dilation rates layer by layer, the residual block layer includes multiple residual blocks, and the upsampling layer includes multiple layers of transposed convolutions.

[0019] In one embodiment of the present invention, the downsampling layer includes three layers of multi-scale residual gated convolution modules, and the residual block layer includes twelve residual blocks.

[0020] In one embodiment of the present invention, the input features are divided into two paths after entering the multi-scale residual gate convolution module.

[0021] After passing through one layer of convolution, one path is divided into two paths. One path enters the splicing layer after passing through one layer of convolution, and the other path enters the splicing layer after passing through two layers of convolution.

[0022] The other path is divided into two paths after two layers of convolution. The two paths enter the concatenation layer after convolutions of different scales.

[0023] The concatenation layer concatenates the incoming features by channel and concatenates them with the input features to obtain the output features of the multi-scale residual gate convolution module.

[0024] In one embodiment of the present invention, the loss function of the coarse restoration network includes pixel loss and adversarial loss.

[0025] The pixel loss I rec,1 for:

[0026] I rec,1 =||I gt -I pred,1 || 1 ,

[0027] Among them, I gt is the original image, I pred,1 Generated image for the coarse inpainting network generator,|||| 1 represents the L1 norm;

[0028] The adversarial loss ζ adv,1 for:

[0029]

[0030] Among them, p gen,1 The data distribution of images generated by the coarse inpainting network, p data is the data distribution of the original image, G 1 , D 1 are the generator and discriminator of the coarse repair network, represents the expectation of the distribution of real text image data, represents the expected distribution of coarse-grained text image data, D1 (I gt ) represents the result of the real text image input discriminator, D 1 (I pred,1 ) represents the result of the coarse-grained text image input discriminator.

[0031] In one embodiment of the present invention, the loss function of the fine restoration network includes pixel loss, adversarial loss, style loss, and content loss.

[0032] The pixel loss I rec,2 for:

[0033] I rec,2 =||I gt -I pred,2 || 1 ,

[0034] Among them, I gt is the original image, I pred,2 is the generated image of the fine inpainting network,|||| 1 represents the L1 norm;

[0035] The adversarial loss ζ adv,2 for:

[0036]

[0037] Among them, p gen,2 The data distribution of images generated by the fine-grained inpainting network, G 2 , D 2 are the generator and discriminator of the fine repair network, represents the expectation of the distribution of real text image data, represents the expectation of the distribution of fine-grained text image data, D 2 (I gt ) represents the result of the real text image input discriminator, D 2 (I pred,2 ) represents the result of the fine-grained text image input discriminator;

[0038] The style loss ζ sty for:

[0039]

[0040] Among them, C l is the number of channels, M Gram is a matrix used to measure feature correlation, N represents the number of pixels, M Gram (I gt ) represents the matrix of the real text image correlation, M Gram (I pred,2) represents the matrix of fine-grained text-image correlation;

[0041] The content loss con for:

[0042]

[0043] Among them, ψ l represents the lth layer of the VGG network, ψ l (I gt ) represents the output of the real text image in the lth layer of the VGG network, ψ l (I pred,2 ) represents the output of the fine-grained text image in the lth layer of the VGG network;

[0044] The total loss of the fine repair network ζ G,2 for:

[0045] ζ G,2 =I rec,2 +a 1 ζ adv,2 +a 2 ζ sty +a 3 ζ con , where a 1 、a 2 、a 3 is the weight.

[0046] In one embodiment of the present invention, during the training phase, a random mask is used to process defects in a text image; during the testing phase, a hand-drawn mask is used to randomly block out features of the text to be repaired.

[0047] The present invention also provides an ancient book text restoration system based on a dual generative adversarial network, comprising:

[0048] A network construction module, used to construct a dual generative adversarial network including a coarse repair network and a fine repair network, wherein the coarse repair network and the fine repair network are generative adversarial networks with different convolutional structures;

[0049] A data acquisition module is used to acquire real text images, generate text images with different font styles and divide them into training sets and test sets;

[0050] A coarse repair network training module, used for inputting a training set into a generator of the coarse repair network, generating a coarse-grained text image and training the coarse repair network; inputting the coarse-grained text image and a real text image into a discriminator of the coarse repair network for discrimination;

[0051] A fine repair network training module, used to fix the parameters of the coarse repair network, input the coarse-grained text image into the generator of the fine repair network, generate a fine-grained text image and train the fine repair network; input the fine-grained text image and real text into the discriminator of the fine repair network for discrimination;

[0052] The repair module is used to obtain the text image to be repaired, input the text image to be repaired into the generator of the trained coarse repair network, and input the generated result into the generator of the trained fine repair network to complete the repair of the text.

[0053] The above technical solution of the present invention has the following advantages compared with the prior art:

[0054] The present invention utilizes a dual generative adversarial network including a coarse repair network and a fine repair network to repair ancient texts, and divides the repair process into two stages, coarse-grained and fine-grained. Compared with the traditional one-stage model, it effectively expands the receptive field range, solves the problems of distorted repair results, inaccurate structure, discontinuous strokes, etc. in existing repair methods, and makes the repair process easier, improving the accuracy and efficiency of repair. BRIEF DESCRIPTION OF THE DRAWINGS

[0055] In order to make the content of the present invention more clearly understood, the present invention is further described in detail below according to specific embodiments of the present invention in conjunction with the accompanying drawings, wherein:

[0056] Figure 1 It is a model framework diagram of the generative adversarial network.

[0057] Figure 2 is a flow chart of the method of the present invention.

[0058] Figure 3 It is a repair model diagram of the dual generative adversarial network in the present invention.

[0059] Figure 4 Schematic diagram of the multi-scale residual gate convolution module in the present invention.

[0060] Figure 5 is a parameter diagram of the discriminator in an embodiment of the present invention.

[0061] Figure 6 4 is a diagram of the generation process of a random mask in an embodiment of the present invention.

[0062] Figure 7 3 is a comparison diagram of text repair results using the method of the present invention in an embodiment of the present invention. DETAILED DESCRIPTION

[0063] The present invention is further described below in conjunction with the accompanying drawings and specific embodiments so that those skilled in the art can better understand the present invention and implement it, but the embodiments are not intended to limit the present invention.

[0064] This paper uses artificial intelligence technology and proposes a new ancient book text restoration method based on a dual generative adversarial network. This method uses a dual generative adversarial network model to repair ancient book text, which is divided into two stages: (1) inputting the damaged text into a coarse repair network to generate a coarse-grained text image; (2) inputting the coarse-grained text image into a fine repair network to generate the final repaired text image.

[0065] Embodiment 1

[0066] Reference Figure 2 As shown, the present invention discloses an ancient book text restoration method based on a dual generative adversarial network, comprising the following steps:

[0067] S1: Construct a dual generative adversarial network including a coarse repair network and a fine repair network, wherein the coarse repair network and the fine repair network are generative adversarial networks with different convolutional structures.

[0068] like Figure 3 As shown, the coarse repair network includes a downsampling layer, a bottleneck layer and an upsampling layer. The downsampling layer includes multiple layers of convolution (GC) with the same step size and convolution kernel size, the bottleneck layer includes multiple layers of dilated convolution (DilConv) with increasing dilation rate layer by layer, and the upsampling layer includes multiple layers of transposed convolution (TC). In this embodiment, the downsampling layer includes three layers of convolution with a step size of 2 and a convolution kernel size of 4, which will reduce the input image resolution to 32×32; the advantage of gate convolution is that it dynamically screens features, so it can better distinguish between missing areas and non-missing areas and avoid interference from redundant features. The bottleneck layer is formed by superimposing four layers of dilated convolution with dilation rates of 2, 4, 8, and 16, which can significantly increase the receptive field of the network and help maintain the overall consistency of the repaired text. The upsampling layer includes three layers of transposed convolution to restore the features to the initial resolution size.

[0069] The fine repair network includes a downsampling layer, a hole convolution layer, a residual block layer and an upsampling layer. The downsampling layer includes a multi-layer multi-scale residual gate convolution module (RGC), the hole convolution layer includes a multi-layer hole convolution (DilConv) with increasing expansion rate layer by layer, the residual block layer includes a plurality of residual blocks (ResBlock), and the upsampling layer includes a multi-layer transposed convolution (TC). In this embodiment, the downsampling layer includes three layers of multi-scale residual gate convolution modules, and the introduction of residual connections can alleviate the problem of gradient disappearance. The residual block layer includes twelve residual blocks, which are used to deepen the network depth, extract more features, and enhance the network's repair ability. The specific structure of the hole convolution layer and the upsampling layer is consistent with the coarse repair network.

[0070] like Figure 4 As shown, the input features are divided into two paths after entering the multi-scale residual gate convolution module. One path is divided into two paths after passing through a layer of convolution, wherein one path enters the splicing layer after passing through one layer of convolution, and the other path enters the splicing layer after passing through two layers of convolution; the other path is divided into two paths after passing through two layers of convolution, wherein the two paths enter the splicing layer after passing through convolutions of different scales respectively; the splicing layer splices the incoming features by channel and then splices them with the input features to obtain the output features of the multi-scale residual gate convolution module. The multi-scale residual gate convolution module includes gate convolutions of different scales, which are used to improve the network's ability to capture long-term information.

[0071] The loss function of the coarse restoration network includes pixel loss and adversarial loss:

[0072] The pixel loss I rec,1 for:

[0073] I rec,1 =||I gt -I pred,1 || 1 ,

[0074] Among them, I gt is the original image, I pred,1 Generated image for the coarse inpainting network generator,|||| 1 represents the L1 norm;

[0075] The adversarial loss ζ adv,1 for:

[0076]

[0077] Among them, p gen,1 The data distribution of images generated by the coarse inpainting network, p data is the data distribution of the original image, G 1 , D 1 are the generator and discriminator of the coarse repair network, represents the expectation of the distribution of real text image data, represents the expected distribution of coarse-grained text image data, D 1 (I gt ) represents the result of the real text image input discriminator, D 1 (I pred,1 ) represents the result of the coarse-grained text image input discriminator.

[0078] The loss function of the fine restoration network includes pixel loss, adversarial loss, style loss, and content loss:

[0079] The pixel loss I rec,2 for:

[0080] I rec,2 =||I gt -I pred,2 || 1 ,

[0081] Among them, I gt is the original image, I pred,2 is the generated image of the fine inpainting network,|||| 1 represents the L1 norm;

[0082] The adversarial loss ζ adv,2 for:

[0083]

[0084] Among them, p gen,2 The data distribution of images generated by the fine-grained inpainting network, G 2 , D 2 are the generator and discriminator of the fine repair network, represents the expectation of the distribution of real text image data, represents the expectation of the distribution of fine-grained text image data, D 2 (I gt ) represents the result of the real text image input discriminator, D 2 (I pred,2 ) represents the result of the fine-grained text image input discriminator;

[0085] The style loss ζ sty for:

[0086]

[0087] Among them, C l is the number of channels, M Gram is a matrix used to measure feature correlation. In this embodiment, M Gram is the similarity matrix between pixels, N represents the number of pixels, M Gram (Igt ) represents the matrix of the real text image correlation, M Gram (I pred,2 ) represents the matrix of fine-grained text-image correlation;

[0088] The content loss con for:

[0089]

[0090] Among them, ψ l represents the lth layer of the VGG network, ψ l (I gt ) represents the output of the real text image in the lth layer of the VGG network, ψ l (I pred,2 ) represents the output of the fine-grained text image in the lth layer of the VGG network.

[0091] The total loss of the fine repair network ζ G,2 for:

[0092] ζ G,2 =I rec,2 +a 1 ζ adv,2 +a 2 ζ sty +a 3 ζ con ,

[0093] Among them, a 1 、a 2 、a 3 is the weight.

[0094] In this embodiment G,2 =I rec,2 +0.0002ζ adv,2 +10ζ sty +1ζ con .

[0095] S2: Get real text images, generate text images with different font styles and divide them into training set and test set; the method of generating text images with different font styles in this embodiment is: generate fonts using TTF font files, use Python's PIL library for font generation, TTF font files are not limited to Lishu, Xiaozhuan, Songti, Fangsong, etc.; for each font, query the commonly used Chinese character table (3000 characters) to generate text images with different font styles for each commonly used Chinese character. Randomly select 1 / 10 as the test set, and the rest as the test set.

[0096] S3: Initialize the weight parameters of the coarse repair network, input the training set into the generator of the coarse repair network, generate a coarse-grained text image and train the coarse repair network; input the coarse-grained text image and the real text image into the discriminator of the coarse repair network for discrimination; In this embodiment, the Adam optimizer is used to optimize the coarse repair generative adversarial network, and the parameters of the Adam optimizer are: the learning rate is 0.0002, and the others are fixed.

[0097] S4: Initialize the weight parameters of the fine repair network. In this embodiment, the discriminator parameters of the dual generative adversarial network are as follows: Figure 5 The parameters of the coarse repair network are fixed, the coarse-grained text image of the coarse repair network is input into the generator of the fine repair network, a fine-grained text image (final repair result) is generated and the fine repair network is trained; the fine-grained text image and the real text are input into the discriminator of the fine repair network for discrimination; in this embodiment, the Adam optimizer is used to optimize the fine repair generative adversarial network, and the parameters of the Adam optimizer are: the learning rate is 0.0002, and the others are fixed.

[0098] S5: Use the test set to test the trained dual generative adversarial network, obtain the text image to be repaired, and obtain the text image to be repaired by using the target detection model to extract the text in the real ancient book and process it into an image format. Input the text image to be repaired into the generator of the trained coarse repair network, and input the generated result into the generator of the trained fine repair network to complete the repair of the text.

[0099] In the training stage, a random mask is used to process the defects of the text image. The random mask generation method in this embodiment is shown in Figure 6 ; During the testing phase, hand-drawn masks are used to randomly block out the features of the text to be repaired.

[0100] Embodiment 2

[0101] The present invention also discloses an ancient book text restoration system based on a dual generative adversarial network, comprising:

[0102] A network construction module, used to construct a dual generative adversarial network including a coarse repair network and a fine repair network, wherein the coarse repair network and the fine repair network are generative adversarial networks with different convolutional structures;

[0103] A data acquisition module is used to acquire real text images, generate text images with different font styles and divide them into training sets and test sets;

[0104] A coarse repair network training module, used for inputting a training set into a generator of the coarse repair network, generating a coarse-grained text image and training the coarse repair network; inputting the coarse-grained text image and a real text image into a discriminator of the coarse repair network for discrimination;

[0105] A fine repair network training module, used to fix the parameters of the coarse repair network, input the coarse-grained text image into the generator of the fine repair network, generate a fine-grained text image and train the fine repair network; input the fine-grained text image and real text into the discriminator of the fine repair network for discrimination;

[0106] The repair module is used to obtain the text image to be repaired, input the text image to be repaired into the generator of the trained coarse repair network, and input the generated result into the generator of the trained fine repair network to complete the repair of the text.

[0107] Compared with the existing technology, the present invention uses a dual generative adversarial network including a coarse repair network and a fine repair network to repair ancient texts, and divides the repair process into two stages, coarse-grained and fine-grained. Compared with the traditional one-stage model, it effectively expands the receptive field range, solves the problems of distorted repair results, inaccurate structure, discontinuous strokes, etc. in existing repair methods, and makes the repair process easier, improving the accuracy and efficiency of repair.

[0108] In order to further demonstrate the beneficial effects of the present invention, the method of the present invention and the methods in the prior art Shift-Net (see the document “Yan Z, Li X, Li M, et al. Shift-net: Image inpainting via deepfeature rearrangement [A]. Proceedings of the European conference on computervision [C]. Munich: Springer, 2018: 1-17”), GMCNN (see the document “Wang Y, Tao X, Qi X, et al. Image inpainting via generative multi-column convolutional neural networks [J]. Advances in neural information processing systems, 2018, 31”) and GC (see the document “Yu J, Lin Z, Yang J, et al. Free-form image inpainting with gated convolution [A]. Proceedings of the IEEE / CVF international conference on computer vision [C]. Long Beach:IEEE, 2019:4471-4480”) to conduct text restoration experiments, and use the evaluation indicators PSNR, SSIM and FID scores to evaluate the restored text. The experimental evaluation results are shown in Table 1. Figure 7 shown.

[0109] Table 1 Comparison of text repair experimental results

[0110]

[0111] From the results in Table 1, it can be seen that the present invention has achieved the best values ​​in terms of PSNR, SSIM, and FID. Figure 7 It can be seen that compared with other methods, the strokes and writing style of the repaired text in the present invention are better maintained, which proves that the repair process of the present invention is easier and can improve the accuracy and efficiency of the repair.

[0112] Those skilled in the art will appreciate that the embodiments of the present application may be provided as methods, systems, or computer program products. Therefore, the present application may adopt the form of a complete hardware embodiment, a complete software embodiment, or an embodiment in combination with software and hardware. Moreover, the present application may adopt the form of a computer program product implemented in one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) that include computer-usable program code.

[0113] The present application is described with reference to the flowcharts and / or block diagrams of the methods, devices (systems), and computer program products according to the embodiments of the present application. It should be understood that each process and / or box in the flowchart and / or block diagram, as well as the combination of the processes and / or boxes in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to generate a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.

[0114] These computer program instructions may also be stored in a computer-readable memory capable of directing a computer or other programmable data processing device to operate in a specific manner, so that the instructions stored in the computer-readable memory produce an article of manufacture comprising an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.

[0115] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operating steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing instructions for implementing the process. Figure 1 A process or multiple processes and / or boxes Figure 1 The steps for the functions specified in one or more boxes.

[0116] Obviously, the above embodiments are merely examples for clear explanation and are not intended to limit the implementation methods. For those skilled in the art, other different forms of changes or modifications can be made based on the above description. It is not necessary and impossible to list all the implementation methods here. The obvious changes or modifications derived from these are still within the protection scope of the invention.

Claims

1. A method for restoring ancient text based on dual generative adversarial networks, characterized in that: include: Constructing a dual generative adversarial network including a coarse repair network and a fine repair network, wherein the coarse repair network and the fine repair network are generative adversarial networks with different convolutional structures; Get real text images, generate text images with different font styles and divide them into training sets and test sets; Inputting the training set into the generator of the coarse repair network to generate a coarse-grained text image and train the coarse repair network; Inputting the coarse-grained text image and the real text image into the discriminator of the coarse restoration network for discrimination; Fixing the parameters of the coarse repair network, inputting the coarse-grained text image into the generator of the fine repair network, generating a fine-grained text image and training the fine repair network; Inputting the fine-grained text image and the real text into the discriminator of the fine restoration network for discrimination; Obtain a text image to be repaired, input the text image to be repaired into the generator of the trained coarse repair network, and input the generated result into the generator of the trained fine repair network to complete the repair of the text; The fine repair network includes a downsampling layer, a dilated convolution layer, a residual block layer and an upsampling layer, wherein the downsampling layer includes a multi-layer multi-scale residual gate convolution module, the dilated convolution layer includes a multi-layer dilated convolution with increasing dilation rate layer by layer, the residual block layer includes a plurality of residual blocks, and the upsampling layer includes a multi-layer transposed convolution; After the input features enter the multi-scale residual gate convolution module, they are divided into two paths. One path is divided into two paths after passing through one layer of convolution, wherein one path enters the splicing layer after passing through one layer of convolution, and the other path enters the splicing layer after passing through two layers of convolution; the other path is divided into two paths after passing through two layers of convolution, wherein the two paths enter the splicing layer after passing through convolutions of different scales respectively; the splicing layer splices the incoming features by channel and then splices them with the input features to obtain the output features of the multi-scale residual gate convolution module.

2. The ancient book text restoration method based on dual generative adversarial networks according to claim 1 is characterized by: The coarse restoration network includes a downsampling layer, a bottleneck layer and an upsampling layer. The downsampling layer includes multiple layers of convolutions with the same step size and convolution kernel size, the bottleneck layer includes multiple layers of dilation rate increasing layer by layer, and the upsampling layer includes multiple layers of transposed convolutions.

3. The ancient book text restoration method based on dual generative adversarial networks according to claim 2 is characterized by: The downsampling layer includes three layers of convolution with a step size of 2 and a convolution kernel size of 4, and the bottleneck layer is formed by superimposing four layers of dilation convolution with expansion rates of 2, 4, 8, and 16.

4. The ancient book text restoration method based on dual generative adversarial networks according to claim 1 is characterized by: The downsampling layer includes three layers of multi-scale residual gate convolution modules, and the residual block layer includes twelve residual blocks.

5. The ancient book text restoration method based on dual generative adversarial networks according to claim 1 is characterized by: The loss function of the rough restoration network includes pixel loss and adversarial loss. The pixel loss I rec,1 for: I rec,1 =||I gt -I pred,1 ||1, Among them, I gt is the original image, I pred,1 is the generated image of the coarse restoration network generator, || ||1 represents the L1 norm; The adversarial loss ξ adv,1 for: Among them, p gen,1 The data distribution of images generated by the coarse inpainting network, p data is the data distribution of the original image, D1 is the discriminator of the rough repair network, represents the expectation of the distribution of real text image data, represents the expected distribution of coarse-grained text image data, D1(I gt ) represents the result of the real text image input discriminator, D1(I pred,1 ) represents the result of the coarse-grained text image input discriminator.

6. The ancient book text restoration method based on dual generative adversarial networks according to claim 1 is characterized by: The loss functions of the fine restoration network include pixel loss, adversarial loss, style loss, and content loss. The pixel loss I rec,2 for: I rec,2 =||I gt -I pred,2 ||1, Among them, I gt is the original image, I pred,2 is the generated image of the fine-grained inpainting network, || ||1 represents the L1 norm; The adversarial loss ξ adv,2 for: Among them, p gen,2 is the data distribution of the image generated by the fine repair network, D2 is the discriminator of the fine repair network, represents the expectation of the distribution of real text image data, represents the expected distribution of fine-grained text image data, D2(I gt ) represents the result of the real text image input discriminator, D2(I pred,2 ) represents the result of the fine-grained text image input discriminator; The style loss ξ sty for: Among them, C l is the number of channels, M Gram is a matrix used to measure feature correlation, N represents the number of pixels, M Gram (I gt ) represents the matrix of the real text image correlation, M Gram (I pred,2 ) represents the matrix of fine-grained text-image correlation; The content loss ξ con for: Among them, ψ l represents the lth layer of the VGG network, ψ l (I gt ) represents the output of the real text image in the lth layer of the VGG network, ψ l (I pred,2 ) represents the output of the fine-grained text image in the lth layer of the VGG network; The total loss of the fine repair network ζ G,2 for: g G,2 =I rec,2 +a1ξ adv,2 +a2z sty +a3ζ con , Among them, a1, a2, and a3 are weights.

7. The ancient book text restoration method based on dual generative adversarial networks according to claim 1 is characterized by: During the training phase, random masks are used to handle text image defects; During the testing phase, hand-drawn masks are used to randomly block out the features of the text to be repaired.

8. An ancient book text restoration system based on dual generative adversarial networks, characterized in that: include: A network construction module, used to construct a dual generative adversarial network including a coarse repair network and a fine repair network, wherein the coarse repair network and the fine repair network are generative adversarial networks with different convolutional structures; A data acquisition module is used to acquire real text images, generate text images with different font styles and divide them into training sets and test sets; A coarse repair network training module, used for inputting a training set into a generator of the coarse repair network, generating a coarse-grained text image and training the coarse repair network; Inputting the coarse-grained text image and the real text image into the discriminator of the coarse restoration network for discrimination; A fine repair network training module, used to fix the parameters of the coarse repair network, input the coarse-grained text image into the generator of the fine repair network, generate a fine-grained text image and train the fine repair network; Inputting the fine-grained text image and the real text into the discriminator of the fine restoration network for discrimination; A repair module is used to obtain a text image to be repaired, input the text image to be repaired into the generator of the trained coarse repair network, and input the generated result into the generator of the trained fine repair network to complete the repair of the text; The fine repair network includes a downsampling layer, a dilated convolution layer, a residual block layer and an upsampling layer, wherein the downsampling layer includes a multi-layer multi-scale residual gate convolution module, the dilated convolution layer includes a multi-layer dilated convolution with increasing dilation rate layer by layer, the residual block layer includes a plurality of residual blocks, and the upsampling layer includes a multi-layer transposed convolution; After the input features enter the multi-scale residual gate convolution module, they are divided into two paths. One path is divided into two paths after passing through one layer of convolution, wherein one path enters the splicing layer after passing through one layer of convolution, and the other path enters the splicing layer after passing through two layers of convolution; the other path is divided into two paths after passing through two layers of convolution, wherein the two paths enter the splicing layer after passing through convolutions of different scales respectively; the splicing layer splices the incoming features by channel and then splices them with the input features to obtain the output features of the multi-scale residual gate convolution module.