Image restoration method, device, equipment and readable storage medium based on edge prior and attention mechanism
By combining edge priors and attention mechanisms in image repair, using the Transformer architecture of axial attention and standard self-attention to predict edge contours, and synthesizing texture details through a multi-scale fusion attention module, we solve the major problems in the existing technology. Hole image repair results in structural distortion and texture blurring problems, achieving high-quality image repair and reducing computational costs.
Patent Information
- Application Number
- CN202311365706.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-10-20
- Publication Date
- 2024-09-03
- Estimated Expiration
- 2043-10-20
AI Technical Summary
When existing image repair methods based on deep learning face missing images with large holes, the repair results often suffer from structural distortion and texture blur, and the model training and inference processes have high computational and storage costs.
An image repair method (EPAM) that combines edge prior and attention mechanism is proposed. It predicts reasonable edge contours by using the Transformer architecture that combines axial attention and standard self-attention in the edge prediction stage, and performs image repair during image repair. In this stage, the multi-scale fusion attention module is used to synthesize texture details, decompose structure prediction and texture generation, and improve the representation ability and repair quality of the model.
It significantly improves the quality of image restoration, achieves more accurate edge prediction and texture detail reconstruction, reduces model complexity, improves qualitative and quantitative evaluation results, and has advantages in the number of parameters and computational cost.
Smart Images

Figure CN118014894B
Abstract
Description
Technical Field
[0001] The present invention relates to the field of image restoration technology, and in particular to an image restoration method, device, equipment and readable storage medium based on the combination of edge prior and attention mechanism. Background Art
[0002] Image inpainting is a challenging computer vision task that aims to construct visually attractive and semantically plausible content for missing areas. It has a wide range of real-world applications, such as repairing damaged photos, removing unwanted objects, and super-resolution. Initially, traditional diffusion-based methods mainly diffuse pixel information gradually around the damaged area in the image and synthesize new textures to fill the holes. Such methods are suitable for repairing small-sized damaged areas such as cracks. As the damaged area becomes larger, the repair results will be too blurred. In addition, the pioneering sample-based method synthesizes textures by searching for matching similar sample blocks in the undamaged area of the image and copying them to the corresponding positions. Such methods often produce high-quality textures, but may repair incorrect structures and semantics.
[0003] With the booming development of deep learning in image processing tasks, researchers at home and abroad have introduced different deep learning techniques to solve these problems. The method based on convolutional neural networks (CNNs) follows the adversarial idea of encoder-decoder architecture and generative adversarial networks (GANs) to reconstruct the missing area by learning high-level semantic features. However, the local inductive bias and limited receptive field of convolution operations make it difficult for the model to learn globally semantically consistent textures. The method uses the attention mechanism to find the feature blocks most similar to the masked area in the feature space of the known area to achieve long-distance feature block matching, but for images with large missing areas, the attention mechanism cannot provide enough information for repair, so that some of the repair results have blurred texture details and many artifacts. Compared with the CNN-based method, the Transformer-based solution uses the transformer's excellent long-range correlation and global feature extraction capabilities to reconstruct low-resolution images, and then provides them to the CNN-based upsampler to restore texture details. However, the above methods ignore the importance of the overall image structure, resulting in inconsistent boundaries and semantic loss in the results. At the same time, the model training and inference process also have high computational and storage costs. In addition, some methods use edge, gradient or semantic information for structural restoration. For example, Nazeri et al. use the Canny operator to extract edge information of the defective area, and the fine network uses the reconstructed edge map as structural information to continuously guide content restoration, which improves the restoration effect of structural details to a certain extent. Differently, in order to solve the problem of overlapping holes and foreground objects, Xiong et al. use the predicted foreground contour to guide image completion, thereby ensuring the rationality of image content filling. However, the above-mentioned structural constraint-based restoration methods have certain limitations, mainly ignoring two important factors: 1. Due to the spatial invariance and local inductive priors of convolutional neural networks, they perform poorly in understanding global structures, resulting in poor edge restoration effects. 2. Many factors affect the success of texture synthesis in image restoration. In addition to paying attention to structural details, it is also important for the model to effectively use long-range features to capture rich contextual information.
[0004] Many methods assist image restoration by adding prior knowledge of image structure, showing more detailed and reasonable results. Liao et al. improved on CE and proposed an edge-aware context encoder to predict image edge structure to promote the learning of scene structure and context, but there are significant blurs and artifacts around the repaired defective area. Cao et al. used the encoder-decoder structure to learn a sketch tensor space composed of edges, lines, and connection points, and introduced gated convolution and attention modules to improve local details under cost-saving conditions, but this design is not suitable for structural restoration of scenes such as faces. In addition, some methods combine image structure and texture details to guide image completion. Liao et al. designed a semantic segmentation guidance and evaluation mechanism to interact to iteratively update semantic information and repair images, but it is difficult to obtain accurate semantic information for images with complex backgrounds. Guo et al. shared information between the two branches of texture generation and structure prediction, and further enhanced global consistency by fusing the attention module with learnable parameters. However, this coupled method often lacks clear structural details when restoring natural images with irregular defects. Specifically, the above-mentioned image restoration methods based on structural constraints ignore the positive influence of long-distance features when dealing with large-area irregular defects. Once the reconstructed structure is missing or wrong, the repair effect will be significantly deteriorated.
[0005] In view of this, although deep learning-based image restoration methods have made great progress in the reconstruction of damaged areas, when faced with missing images with large holes, the restoration results often have problems with structural distortion and blurred textures. Therefore, it is necessary to propose a new idea and solution to solve the above problems.
[0006] For the specific contents of the above public documents, please refer to the following references.
[0007] [1] Z.Wan, B.Zhang, D.Chen, P.Zhang, D.Chen et al., "Bringing old photosback to life," in Proc.of the IEEE / CVF Conf.on Computer Vision and PatternRecognition, Seattle, WA, USA, pp.2747-2757, 2020.
[0008] [2]C.Barnes,E.Shechtman,A.Finkelstein and D.B.Goldman,“PatchMatch:Arandomized correspondence algorithm for structural image editing,”ACMTrans.Graph.,vol.28,no.3,pp.24:1-24:11,2009.
[0009] [3]F.Yang,H.Yang,J.Fu,H.Lu and B.Guo,“Learning texture transformernetwork for image super-resolution,”in Proc.of the IEEE / CVF Conf.on ComputerVision and Pattern Recognition,Seattle,WA,USA,pp.5791-5800,2020.
[0010] [4]M.Bertalmio,G.Sapiro,V.Caselles,and C.Ballester,“Imageinpainting,”in Proc.of the 27th annual conf.on Computer graphics andinteractive techniques,New York,NY,USA,pp.417-424,2000.
[0011] [5]T.F.Chan and J.Shen,“Nontexture inpainting by curvature-drivendiffusions,”Journal of visual communication and image representation,vol.12,no.4,pp.436-449,2001.
[0012] [6]N.Komodakis and G.Tziritas,“Image completion using efficientbelief propagation via priority scheduling and dynamic pruning,”IEEETransactions on Image Processing,vol.16,no.11,pp.2649-2661,2007.
[0013] [7]A.Criminisi,P.Pérez and K.Toyama,“Region filling and objectremoval by exemplar-based image inpainting,”IEEE Transactions on imageprocessing,vol.13,no.9,pp.1200-1212,2004.
[0014] [8]D.Pathak,P.Krahenbuhl,J.Donahue,T.Darrell and A.A.Efros,“Contextencoders:Feature learning by inpainting,”in Proc.of the IEEE Conf.on ComputerVision and Pattern Recognition,Las Vegas,NV,USA,pp.2536-2544,2016.
[0015] [9]S.Iizuka,E.Simo-Serra and H.Ishikawa,“Globally and locallyconsistent image completion,”ACM Trans.Graph.,vol.36,no.4,pp.107:1–107:14,2017.
[0016]
[10] Y.Wang,X.Tao,X.Qi,X.Shen and J.Jia,“Image inpainting viagenerative multi-column convolutional neural networks,”in Proc.of Advances inNeural Information Processing Systems,Montréal,QC,Canada,pp.331–340,2018.
[0017]
[11] I.Goodfellow,J.Pouget-Abadie,M.Mirza,B.Xu and D.Warde-Farley,“Generative adversarial nets,”in Proc.of Advances in Neural InformationProcessing Systems,Montreal,QC,Canada,pp.2676–2680,2014.
[0018]
[12] J.Yu,Z.Lin,J.Yang,X.Shen,X.Lu et al.,“Generative image inpaintingwith contextual attention,”in Proc.of the IEEE conf.on Computer Vision andPattern Recognition,Salt Lake City,UT,USA,pp.5505-5514,2018.
[0019]
[13] M.C.Sagong,Y.G.Shin,S.W.Kim,S.Park and S.J.Ko,“Pepsi:Fast imageinpainting with parallel decoding network,”in Proc.of the IEEE Conf.onComputer Vision and Pattern Recognition,Long Beach,CA,USA,pp.11360-11368,2019.
[0020]
[14] Z.Wan,J.Zhang,D.Chen and J.Liao,“High-fidelity pluralistic imagecompletion with transformers,”in Proc.of the IEEE / CVF InternationalConference on Computer Vision,Montreal,QC,Canada,pp.4692-4701,2021.
[0021]
[15] Y.Yu,F.Zhan,R.Wu,J.Pan and K.Cui,“Diverse image inpainting withbidirectional and autoregressive transformers,”in Proc.of the 29th ACMInternational Conf.on Multimedia,Chengdu,Sichuan,China,pp.69-78,2021.
[0022]
[16] X.Guo,H.Yang and D.Huang,“Image inpainting via conditionaltexture and structure dual generation,”in Proc.of the IEEE / CVF InternationalConference on Computer Vision,Montreal,QC,Canada,pp.14134-14143,2021.
[0023]
[17] J.Yang,Z.Qi,and Y.Shi,“Learning to incorporate structureknowledge for image inpainting,”in Proc.of the AAAI Conference on ArtificialIntelligence,New York,NY,USA,pp.12605–12612,2020.
[0024]
[18] Y.Song,C.Yang,Y.Shen,P.Wang Q.Huang et al.,“Spg-net:Segmentationprediction and guidance network for image inpainting,”arXiv:1805.03356,2016.[Online].Available:https: / / arxiv.org / abs / 1805.03356.
[0025]
[19] L.Liao,J.Xiao,Z.Wang,C.W.Lin and S.I.Satoh,“Guidance andevaluation:Semantic-aware image inpainting for mixed scenes,”in Proc.ofEuropean Conference on Computer Vision,Glasgow,Scotland,UK,pp.683-700,2020.
[0026]
[20] K.Nazeri,E.Ng,T.Joseph,F.Z.Qureshi and M.Ebrahimi,“Edgeconnect:Generative image inpainting with adversarial edge learning,”arXiv:1901.00212,2019.[Online].Available:http: / / arxiv.org / abs / 1901.00212.
[0027]
[21] W.Xiong,J.Yu,Z.Lin,J.Yang,X.Lu et al.,“Foreground-aware imageinpainting,”in Proc.of the IEEE / CVF International Conference on ComputerVision,Long Beach,CA,USA,pp.5840–5848,2019.
[0028]
[22] Z. Liu, P. Luo, X. Wang and X. Tang. “Deep learning face attributes in the wild,” in Proc. of the IEEE international conference on computer vision, Santiago, Chile, pp. 3730 - 3738, 2015.
[0029]
[23] R. and R. “Spatial pattern templates for recognition of objects with regular structure,” in Proc. of German Conference on Pattern Recognition, Saarbrücken, Germany, pp. 364 - 374, 2013.
[0030]
[24] B. Zhou, A. Lapedriza, A. Khosla, A. Oliva and A. Torralba, “Places: A 10 million image database for scene recognition,” IEEE Transactions on Pattern Analysis and Machine Intelligence, vol. 40, no. 6, pp. 1452–1464, 2018.
[0031]
[25] L. Liao, R. Hu, J. Xiao and Z. Wang, “Edge - aware context encoder for image inpainting,” in Proc. of 2018 IEEE International conference on acoustics, speech and signal processing, Calgary, AB, Canada, pp. 3156 - 3160, 2018. Summary of the Invention
[0032] In response to the above technical problems, this application aims to introduce an edge prediction module in the edge restoration stage, and an image restoration method (EPAM) that combines edge priors with an attention mechanism. This method divides the restoration task into two stages: edge prediction and image restoration, and uses multi-level long-range features to enhance local pixel continuity, significantly improving the image restoration quality.
[0033] When the new idea was first proposed, the entire team of the inventors started to study the framework of the Transformer itself. The Transformer was originally proposed as a sequence-to-sequence model for machine translation tasks, and was later improved and applied to computer vision tasks such as object detection, video processing, and image processing
[28] . In recent years, the excellent performance of the Transformer model has attracted researchers to use it to deal with image restoration problems. Wan et al. first used the Transformer for image restoration, using bidirectional attention and a masked language model objective similar to BERT to achieve low-resolution image diversity appearance reconstruction. Zheng et al. designed a content reasoning model of a mask-aware Transformer, which uses a restrictive convolutional neural network module to extract tokens. The Transformer encoder uses a replacement weighted self-attention layer to capture the global context, reducing the dominance of proximity that leads to semantically incoherent results. However, this method cannot understand and imagine high-level semantic content. The above-mentioned Transformer-based methods are mainly used for image reconstruction to obtain low-resolution restoration images, and such methods have the problem of long reasoning time.
[0034] It should be noted that, based on the analysis of the disclosed related technologies by the above inventors, it is concluded that for the problem of structural reconstruction, compared with smooth images and semantic images, edge maps can not only provide accurate structural information of images, but also have stronger resistance to interference factors such as noise.
[0035] Therefore, the inventors tried to propose a novel TEP module, which uses the ability of transformer to reconstruct the overall edge structure of the image, overcome the problems brought by the CNN method, and obtain better edge prediction performance. In addition, in order to solve the problem of artifacts such as lack of prominent texture details and inconsistent boundaries in the restoration results, the present application designed an MFA module, which can enhance the texture reasoning ability on the one hand, and independently synthesize new content by mining different levels of long-distance features in areas lacking structural information on the other hand. In general, the EPAM model predicts the structure and generates texture of the image by decoupling, which improves the representation ability of the model and ensures the consistency of the overall structure and detailed texture of the restored image.
[0036] It is worth noting that based on the above analysis and the proposal of new ideas, the inventors finally conducted the final design research of the scheme from two main lines and proposed an image restoration framework (EPAM) that combines edge priors with attention mechanisms. Inspired by the excellent performance of transformers in the field of computer vision, this application uses the transformer architecture to predict the edge structure of the defective area with excellent performance. Subsequently, in the image restoration stage, this application uses effective edge structures to constrain image content and reconstruct images with reasonable vision and clear texture.
[0037] Based on this, the present invention finally designs the following specific technical solutions:
[0038] More specifically, the first aspect of the present invention provides an image restoration method based on the combination of edge prior and attention mechanism, including an edge prediction stage and an image restoration stage; wherein,
[0039] Edge prediction stage
[0040] Obtain grayscale defective images and incomplete edge information, predict reasonable edge contours in the defective area through a transformer architecture that combines axial attention with standard self-attention, and obtain an edge prediction map;
[0041] Image inpainting stage
[0042] The edge prediction map is used as the structural prior and combined with the defective RGB image. The texture details are synthesized in the local closed area surrounded by the edge through a multi-scale fusion attention module to complete the image restoration.
[0043] As a specific implementation of the method of the first aspect of the present invention, the edge prediction stage is implemented by an edge prediction network; the image restoration stage is implemented by an image restoration network; wherein,
[0044] The edge prediction network includes an edge generator G1 and an edge discriminator D1. G1(·) represents the edge generator operation, and the edge prediction graph is expressed as:
[0045]
[0046] The image inpainting network includes an image generator G2 and an image discriminator D2. G2(·) represents the operation of the image generator, and the predicted image is expressed as:
[0047]
[0048] Get repaired output with the same size as the original:
[0049]
[0050] In the formula, It , I gs and E t Represent the original image, the corresponding grayscale image, and the edge structure image respectively; the incomplete image is represented as The grayscale representation of the incomplete image is The defect edge is represented as where represents the element-by-element product operation; E comp Represents the synthesized edge prediction map.
[0051] In the above technical scheme, in order to concretize the technical means of studying edge restoration, it is specifically defined that the edge generator is based on the autoencoder structure, and the edge prediction map is completed through the decoding stage of encoder data compression of given image features, the feature reconstruction stage of bottleneck layer feature reconstruction and the decoding stage of decoder decompression.
[0052] As a specific implementation, the encoding stage, feature reconstruction stage and decoding stage respectively include the following steps:
[0053] In the encoding stage, the encoder first uses a 7×7 convolution with a reflection padding parameter of 3 and a stride of 1 to obtain features, adjusts the given image features to a size of 256×256×64, and then obtains a shallow output feature of size 32×32×256 through three consecutive layers of convolution with a stride of 2 and a convolution kernel size of 4×4;
[0054] In the feature reconstruction stage, eight transformer structures based on the axial attention mechanism are stacked to form an information bottleneck layer to enhance the representation ability of feature information and the capture ability of global structural information, complement the missing edge information, and obtain a reconstructed feature with a dimension of 32×32×256;
[0055] In the decoding stage, three transposed convolutions with a kernel size of 4×4, a zero padding operation of 1, and a stride of 2 are used to upsample the features to 256×256×64, and then a convolution with a kernel size of 7×7, a reflection padding parameter of 3, and a stride of 1 is used to adjust the output to 256×256×1 to obtain the edge prediction map.
[0056] Furthermore, the edge discriminator includes a convolution stage and a sample output stage, wherein:
[0057] In the convolution stage, the PatchGAN architecture is selected, which consists of 5 layers of convolution with strides of 2, 2, 2, 1, 1 and a convolution kernel size of 4×4;
[0058] In the sample output stage, the input image is calculated into a single-channel feature map of size 30×30 through 5 layers of convolution operations. The Sigmod function is used to map the output to a scalar in the range of [0,1], which effectively distinguishes the true and false of the input sample and obtains the edge repair result.
[0059] More specifically, the second aspect of the present invention provides a product, specifically an image restoration device based on the combination of edge prior and attention mechanism, including an edge prediction module and an image restoration module, wherein:
[0060] The edge restoration module is used to obtain grayscale defective images and incomplete edge information, and predict reasonable edge contours in the defective area through a transformer architecture that combines axial attention with standard self-attention to obtain an edge prediction map;
[0061] The image inpainting module is used to use the edge prediction map as the structural prior, combined with the defective RGB image, and synthesize texture details in the local closed area surrounded by the edge through a multi-scale fusion attention module to complete the image inpainting.
[0062] As a specific implementation of the product of the second aspect, the edge prediction module includes:
[0063] The encoding unit first obtains features by using a 7×7 convolution with a reflection padding parameter of 3 and a stride of 1 through the encoder, which adjusts the given image features to a size of 256×256×64, and then obtains shallow output features of size 32×32×256 through three consecutive layers of convolution with a stride of 2 and a convolution kernel size of 4×4;
[0064] The feature reconstruction unit selects and stacks eight transformer structures based on the axial attention mechanism to form an information bottleneck layer, which enhances the representation ability of feature information and the capture ability of global structural information, completes the missing edge information, and obtains the reconstructed features with a dimension of 32×32×256;
[0065] In the decoding stage, the features are upsampled to 256×256×64 by using three transposed convolutions with a kernel size of 4×4, a zero padding operation of 1, and a stride of 2, and then the output is adjusted to 256×256×1 by using one convolution with a kernel size of 7×7, a reflection padding parameter of 3, and a stride of 1 to obtain the edge prediction map.
[0066] In the above technical solution, the edge prediction module also includes:
[0067] The convolution unit, based on PatchGAN architecture, consists of 5 layers of convolution, with strides of 2, 2, 2, 1, 1, and a convolution kernel size of 4×4;
[0068] The sample output unit calculates the input image into a single-channel feature map of size 30×30 through the above 5-layer convolution operation, and uses the Sigmod function to map the output to a scalar in the range of [0,1], which effectively distinguishes the true and false of the input sample and obtains the edge repair result.
[0069] More specifically, the third aspect of the present invention provides an image restoration device, comprising at least one processor and a memory, characterized in that computer instructions are stored in the memory, and the processor is used to run the computer instructions stored in the memory to implement the steps of the image restoration method combining the edge prior and the attention mechanism as described above.
[0070] More specifically, the fourth aspect of the present invention provides a computer program stored on a computer-readable recording medium, wherein the computer program is used to execute the steps of the image restoration method combining edge prior with attention mechanism as described above.
[0071] Compared with the prior art, the present invention has at least the following technical effects:
[0072] In summary, the contributions of this application are summarized as follows:
[0073] (1) In the edge prediction network, this application proposes an efficient Transformer-based edge prediction (TEP) module. It is worth noting that the existing CNN-based methods are difficult to accurately extract the edges of the incomplete parts. The TEP module of this application can achieve more accurate and comprehensive structural recovery. In the TEP module, this application also uses axial attention with relative position encoding to improve the ability of position perception, while significantly reducing the model complexity of the edge prediction network, and balancing the relationship between performance and efficiency.
[0074] (2) In the image restoration network, this application designs a multi-scale fusion attention (MFA) module. Specifically, this module aggregates contextual feature information at different levels by using dilated convolutions of different ratios, and applies an efficient channel attention mechanism to reduce the impact of redundant features. In addition, an attention transfer network is introduced to enable the model to fully fuse shallow texture details and deep semantic features, thereby avoiding unreasonable or contradictory areas in the generated image. Finally, the image restoration network is able to complete the reconstruction of texture details under the guidance of edge structures.
[0075] (3) This application conducts comparative experiments on the EPAM model and existing advanced methods. Experimental results on the Celeba, Facade, and Places2 datasets show that the EPAM model presents competitive restoration results in both qualitative and quantitative evaluation. BRIEF DESCRIPTION OF THE DRAWINGS
[0076] Figure 1 It is the overall network structure. The upper part is the edge prediction network, and the lower part is the image restoration network.
[0077] Figure 2 This is the architecture diagram of the transformer-based edge prediction module.
[0078] Figure 3 Comparison diagram of the differences between unidirectional, bidirectional, and axial attention.
[0079] Figure 4 The architecture diagram of the multi-scale fusion attention module.
[0080] Figure 5 This is the two-stage training loss diagram of the EPAM model.
[0081] Figure 6 Qualitative comparison results of repairing irregular holes and central regular holes on the Facade dataset.
[0082] Figure 7 Qualitative comparison results for repairing irregular holes on the Places2 dataset.
[0083] Figure 8 Figure 2 is a visual comparison of the proposed method with other structure-based methods on the CelebA, Facade and Places2 datasets: (a) the input damaged image; (b), (c), (d) are the edge structures generated by EC, CTSDG and the method of this application, respectively; (e), (f), (g) are the corresponding restoration effects of EC, CTSDG and the method of this application, respectively; and (h) Ground-Truth.
[0084] Fig. 9 is the attention score matrix of ATN at different scales.
[0085] Fig.10 It is the characteristic diagram of ATN.
[0086] Fig.11 For the analysis of different configurations of the method proposed in this application.
[0087] Fig.12 Accuracy and precision curves with and without Axial attention. DETAILED DESCRIPTION
[0088] In order to enable those skilled in the art to better understand the solutions of the present invention, the technical solutions in the embodiments of the present invention are described clearly and completely below. Obviously, the described embodiments are only embodiments of a part of the present invention, not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work should fall within the scope of protection of the present invention.
[0089] Based on the current research theory analysis, this paper proposes a new image restoration framework
[0090] This application proposes an image restoration model that combines structural priors and attention mechanisms. The overall model architecture is as follows: Figure 1 As shown in Figure 2, the proposed EPAM consists of two sub-networks. The upper part is the edge prediction network, and the lower part is the image restoration network.
[0091] As can be seen from the figure, the model consists of two generative adversarial networks connected in series;
[0092] The output of the first-stage generator is used as the input of the second-stage generator, and the two-stage network as a whole constitutes an end-to-end restoration model. In the first stage, the edge prediction network uses the grayscale defective image and incomplete edge information to predict a reasonable edge contour in the defective area. Subsequently, the second stage uses the edge prediction map as a structural prior and combines it with the defective RGB image to synthesize appropriate texture details in the local closed area surrounded by the edge. Finally, the restoration task is completed.
[0093] In the edge prediction stage, the autoencoder is used as the generator of the edge prediction network, and the PatchGAN architecture is used as the discriminator of the network. Since it is difficult for convolutional neural networks to obtain long-distance information, only using the surrounding pixel information to reconstruct the defective area will make it difficult to restore the structural information in the center of the missing area. In order to solve this problem, the present application proposes a TEP module and embeds it into the information bottleneck part of the autoencoder. It is worth noting that the TEP module does not use deeply stacked convolutional layers, but uses a Transformer-based architecture to create equal flow opportunities for all visible pixels to obtain an expressive global structure. In addition, the present application introduces relative position encoding and axial attention blocks in the TEP module to improve spatial relationships and reduce memory overhead. In the image restoration stage, a multi-scale fusion attention (MFA) module is proposed to address the problems of color difference, blur and boundary distortion in the images after restoration based on the existing attention mechanism-based model. The present application introduces the serialized MFA module after the encoder. The MFA module captures the deep features of different receptive fields by using dilated convolutions with different expansion rates, thereby better integrating the overall context information with the local detail information. Then, this application constructs an Attention Transfer Network (ATN) on feature maps of four different scales to enhance local pixel continuity, capture long-range dependencies, and significantly improve the image restoration quality.
[0094] The edge prediction network consists of a generator G1 and a discriminator D1. Similarly, the image restoration network consists of a generator G2 and a discriminator D2. t , I gs and E t Represent the original image, the corresponding grayscale image, and the edge structure image respectively. M In , the value 1 represents the pixel in the hole area, and the value 0 represents the pixel in other areas. Then, the incomplete image is represented as The grayscale representation of the incomplete image is The defect edge is represented as where represents the element-by-element product operation. G1(·) is used to represent the edge generator operation, and the edge prediction graph is expressed as:
[0095]
[0096] Among them, E comp Denote the synthesized edge prediction map, and use G2(·) to represent the operation of the image generator. The predicted image is expressed as:
[0097]
[0098] Finally, we get the repaired output with the same size as the original:
[0099]
[0100] The following focuses on the specific design process of the two stages
[0101] 1. In view of the design ideas of the above two stages, this application first designs the architecture of the edge prediction stage, as follows:
[0102] 1) Design of edge prediction module based on transformer
[0103] The Transformer architecture was originally used to solve natural language processing (NLP) tasks. The architecture is completely based on self-attention and can directly model longer-distance dependencies between input sequences. Recently, researchers have applied it to computer vision tasks and achieved remarkable results. Inspired by ViT, this application introduces the transformer decoder in the TEP module and then reconstructs edge information based on the shallow features output by the encoder.
[0104] like Figure 2 As shown, let the height H, width W, and number of channels C be represents the input feature of the TEP module, with a specific size of 32×32×256. First, the View operation is used to reshape the input, and we get (D=H×W), the processed input The embedded position code PE is then input into the Transformer Decoder to obtain the output feature Y after position coding:
[0105]
[0106] In order to significantly reduce the consumption of the self-attention layer in feature map calculation and storage, this application uses both the axial attention module and the standard attention module in the TEP module.
[0107] It should be noted that the axial attention module can be implemented by adjusting the shape of the tensor on the width and height axes and then processing them with dot-product-based self-attention respectively.
[0108] like Figure 3 As shown in Figure 1, unidirectional attention only focuses on the context constraints before the token. Although bidirectional attention can focus on all positions before and after the token, the computational complexity is O(n 2 ). Axial attention can focus on the available context of the token in both rows and columns (i.e., focus on the available information before and after the token), making the model more efficient. In addition, the computational complexity of axial attention is low, only
[0109] Therefore, in order to stabilize the training, this application uses layer normalization techniques before the feature Y is input into the axial attention module. In addition, a learnable relative position encoding (RPE) is provided for the module to improve the spatial relationship and improve the accuracy and effect of restoration. The axial attention score based on the width axis and the height axis can be expressed as
[0110]
[0111] Among them, y hi ,y hj W represents the feature vectors of the i-th and j-th columns of the height axis of feature Y respectively. wq ,W wk ,W hq ,W hk is the weight matrix of query and key in width and height axis; represents the relative position encoding matrix between width axes i and j, Represents the relative position encoding matrix between height axes i and j. This is to make the gradient more stable during back propagation. Then, the attention weight is obtained through Softmax operation. This process is expressed as:
[0112]
[0113] Then, The layers are normalized to standard normal distribution to speed up the training and convergence of the model, and then sent to the feedforward network for operation. Residual connections are added to prevent network degradation while making the matrix operation dimension consistent. This process is expressed as:
[0114]
[0115] Among them, MLP and LN represent multi-layer perceptron and layer normalization respectively. MLP consists of two linear mapping layers FC, an activation function and a residual dropout layer. The first FC converts the D-dimensional features into 4D-dimensional features, and then the second FC converts it back to D-dimensional features. GELU is used as the nonlinear activation function in the middle, and the residual dropout layer is used for regularization to prevent overfitting.
[0116] In addition, this application also uses the standard attention module Attention norm To learn the global correlation, repeat the process of formula (7) to get the final output
[0117]
[0118]
[0119] 2) Edge generator and discriminator design
[0120] The edge generator is based on the autoencoder structure, which The edge prediction is completed by performing the process of encoder data compression, bottleneck layer feature reconstruction and decoder decompression. It is divided into three stages: encoding stage, feature reconstruction stage and decoding stage:
[0121] In the encoding stage, the encoder first uses a 7×7 convolution with a reflection padding parameter of 3 and a stride of 1 to obtain rich features. Then, through three consecutive layers of convolution with a stride of 2 and a convolution kernel size of 4×4, a shallow feature of size 32×32×256 is obtained. Different from patch-based embedding methods, the above convolution operation injects beneficial convolutional inductive bias into the TEP module.
[0122] The bottleneck layer does not use a convolution-based residual block, but chooses to stack eight transformer-based TEP modules to form an information bottleneck layer to enhance the representation ability of feature information and the ability to capture global structural information, thereby completing the missing edge information. Unlike convolution, the self-attention mechanism can capture non-local information from the entire feature map. However, the amount of calculation for similarity calculation is very large. Therefore, in the TEP module, the alternating use of axial attention layers and standard attention layers ensures that the generator uses global context information to complete the image edges that conform to the overall semantics, while taking into account the performance and parameter amount of the Transformer. In addition, by calculating attention separately on the height and width axes, the axial attention layer can obtain multi-directional features to enhance the directional perception of the feature map. After passing through the bottleneck layer, a reconstructed feature with a dimension of 32×32×256 is obtained.
[0123] The features are upsampled to 256×256×64 by using three transposed convolutions with kernel size of 4×4, zero padding operation of 1, and stride of 2, and then the output is adjusted to 256×256×1 by one convolution with kernel size of 7×7, reflection padding parameter of 3, and stride of 1 to obtain the predicted complete edge map. In addition, each convolution layer of the edge generator uses instance normalization to accelerate model convergence and improve the nonlinear expression of the feature extraction module. At the same time, a ReLU activation function is followed by each convolution layer to reduce the gradient disappearance phenomenon.
[0124] In order to improve the network's attention to local details during training, this application selects the PatchGAN architecture as the basic framework of the edge discriminator. The structure consists of 5 layers of convolution, with strides of 2, 2, 2, 1, 1, and a convolution kernel size of 4×4. Spectral normalization and Leaky-ReLU activation function are performed after each layer of convolution. After 5 layers of convolution operations, the input image is calculated into a single-channel feature map of size 30×30. Finally, the Sigmod function is used to map the output to a scalar in the range of [0,1], which effectively distinguishes the true and false input samples and promotes the network to generate high-quality restoration results.
[0125] 2. Based on the design ideas of the above two stages, this application then designs the architecture of the image repair stage, as follows:
[0126] 1) Multi-scale fusion attention module
[0127] In the texture synthesis stage, existing methods usually use convolutional layer stacking to extract shallow details to high-level semantic feature information. However, as the shallow rich spatial structure information and texture details are extracted serially with fixed-size convolution kernels, different degrees of feature loss will occur, aggravating the inconsistency of global context information and being unfavorable for capturing global structure information from distant pixels.
[0128] To address this problem, the MFA module first uses different dilation factors to perform convolution operations on the input features to extract information of different scales in parallel, then scales the features of each scale and inputs them into the ATN module to achieve information transmission between features at different levels, helping the model to better understand the details and structures in the image and improve the quality and accuracy of restoration.
[0129] In addition, the use of efficient channel attention and pixel attention enables the model to selectively focus on important channels and pixels, thereby reducing unnecessary calculations and parameters. Residual structures and skip connections help avoid gradient explosion and network convergence difficulties. Figure 4 .
[0130] Specifically, this application first uses a 1×1 convolution operation to transform the input feature F of the MFA module in The dimension of is changed from 64×64×256 to 64×64×64, and the transformed input feature is expressed as:
[0131]
[0132] Among them, f 1×1 (·) represents a 1×1 convolution operation, τ represents instance normalization and ReLU activation function. Parallel dilated convolution is used to extract multi-level features. The expansion rates Ri are 8, 4, 2 and 1, respectively (i = 1, 2, 3, 4). Convolutions with smaller expansion rates can better perceive texture and position information, while convolutions with larger expansion rates can perceive high-level, global feature information. Then, the efficient channel attention module (ECA) is introduced to effectively capture the information of cross-channel interactions and reduce the influence of redundant features. The calculation formula can be expressed as:
[0133]
[0134] Among them, ECA(·) represents an efficient channel attention operation, represents a 3×3 convolution operation with a dilation rate of Ri. Since deep feature maps are usually more compact, the features of each layer are scaled. Figure 4 As shown, the scaling factors Si are 1 / 8, 1 / 4, 1 / 2, and 1. The scaling process is defined as follows:
[0135]
[0136] in represents the bilinear interpolation downsampling operation with a scaling factor of Si. Then, the attention transfer network (ATN)
[33] is introduced to guide the completion of low-level features layer by layer using high-level features, so that the completed content has reasonable semantics and clear texture. The specific operation can be expressed as:
[0137]
[0138] where ATN(·) represents the attention transfer operation, is the feature map reconstructed by the ATN of the i-th layer. This application constructs a local residual connection for the feature map reconstructed by the last ATN to reduce information loss:
[0139]
[0140] Among them, PA(·) represents the pixel attention operation. In addition, in order to ensure the consistency of local context feature information, this application uses skip connections and 3×3 convolution operations to connect multi-level features of the same size. Fusion into a feature map of size 64×64×128 Finally, the feature map and Fusion output:
[0141]
[0142] 2) Design of image generator and discriminator
[0143] The image generator is improved on the basis of the autoencoder. Since the bottleneck layer does not use the transformer structure, the input of large-sized feature maps into the bottleneck layer will not lead to excessive computational complexity, so the encoder only downsamples to a feature map dimension of 64×64×256.
[0144] In order to synthesize realistic textures in different regions, the bottleneck layer uses a stack of 4 MFAs instead of fully connected layers. Through the interaction of layered dilated convolutions and attention transfer strategies, the generator is able to independently synthesize semantically correct new content in the absence of local edge information.
[0145] Apart from this, the image generator and the corresponding parts of the edge generator have the same network structure and parameter settings.
[0146] It should be emphasized that the image discriminator structure is similar to that of the edge prediction discriminator. The discriminator still uses a 70×70 PatchGAN discriminator network, which consists of 5 layers of convolution with a convolution kernel size of 4×4.
[0147] The discriminator network performs spectral normalization and Leaky-ReLU activation function processing after each convolution operation. The output of the last layer is a two-dimensional matrix of size N×N, where each element in the two-dimensional matrix corresponds to the true or false value of a 70×70 area block, and the average value of all elements is used as the output value of the discriminator. Compared with the traditional GAN discriminator, the PatchGan discriminator judges the authenticity of each patch. This approach can pay more attention to texture details, thereby improving the quality of generated images.
[0148] 3. Design of loss function
[0149] 1) Loss of edge prediction network
[0150] The edge prediction network uses a joint loss for model training, including adversarial loss and feature matching loss, to obtain a clear and realistic edge prediction map. Specifically, adversarial loss The expression can be written as:
[0151]
[0152] Where E is the mathematical expectation and D1 is the discriminator function. Feature matching loss L fm The quality of the generated edge is evaluated by measuring the Euclidean distance between the predicted edge and the original edge in the feature space, which can be defined as:
[0153]
[0154] Among them, S represents the total number of layers of D1, is the activation map of the kth layer of D1, N k for The number of elements in ||·|| represents the calculation of the Euclidean distance. The joint loss L of the edge prediction network E Expressed as:
[0155]
[0156] The loss weight in the formula and α fm are the weights of adversarial loss and feature matching loss respectively. Based on the parameter setting of ICT, in all experiments of this application and λ fm Will be set to: 1 and 15 respectively.
[0157] 2) Loss of image restoration network
[0158] In order to make the image restoration results have reasonable semantic content, consistent structure, and clear texture, this paper uses various loss functions including adversarial loss, perceptual loss, style loss, and reconstruction loss to train the image restoration network. Expressed as:
[0159]
[0160] Next, this application uses the pre-trained VGG-19 network to convert the difference between the pixel values of the generated image and the real image into the difference in feature space in order to better preserve the high-level semantic information of the image. perc Defined as:
[0161]
[0162] Among them, M k represents the feature map size of the kth layer, Represents the feature representation of the kth layer in the loss network.
[0163] Style loss usually uses the Gram matrix (gram) to calculate the difference in feature maps, expressing the correlation of style features on different channels, so that the restored image is closer to the style of the reference image. style It can be expressed as:
[0164]
[0165] in yes Constructed Gram matrix. Reconstruction loss L rec By using L1 loss, the output result I pred and the real image I tThe sum of the absolute differences is minimized to ensure that the overall outline of the result is basically consistent with the target. The specific calculation process is shown in the following formula:
[0166] L rec =||I pred -I t ||1 (22)
[0167] The overall loss L of the second stage network C Expressed as:
[0168]
[0169] Based on the work of ICT and the experimental tests of this paper, this application sets the loss weights as: α perc =0.1, α style =200 and α rec =0.5.
[0170] Experimental case analysis
[0171] 1) Experimental Dataset
[0172] This application was trained and evaluated on three public datasets: Celeba, Facade, and Places. The CelebA dataset contains 202,599 celebrity face images, which is widely used in face-related computer vision training and testing experiments. This application selected approximately 180k images for training and 20k images for testing. For Places2, which contains many unique scene categories such as restaurants, beaches, courtyards, valleys, etc., this application randomly selected approximately 225k images from 50 categories for training and 25k images for testing. The Facade dataset focuses on highly structured exterior walls in different cities around the world.
[0173] Among them, this application uses 556 images for training, and the other images are used for testing. In terms of irregular masks, Liu et al. proposed a test set of irregular mask datasets, which contains 12,000 masks and a total of 6 holes of different areas.
[0174] During the experiment, we randomly used mask test sets with different scale ranges to mask the images, and all images and irregular masks were resized to 256×256 pixels.
[0175] 2) Experimental content
[0176] The hardware configuration of this experiment is a single Intel(R) Core i7-11700 CPU, a single NVIDIA GeForce RTX3090 24GB GPU, 64.0GB RAM, and the software environment is Windows 10, Pytorch v1.7.0, CUDA v11.0. Both phases of the network are trained using the Adam optimizer (β1 = 0.0, β2 = 0.9), with a batch size of 8, and the initial learning rates of the generator G1, G2 and the discriminator D1, D2 are 1×10 -4 and 1×10 -5 In addition, the hyperparameters of the TEP module of the edge prediction network are set to Multi-HeadAttention 8 and the embedding dimension 256.
[0177] The training of the EPAM model is divided into three steps:
[0178] First, this application uses grayscale images and edge binary images as training samples to train G1. After the loss of G1 is balanced, this application adjusts the learning rate to 1×10 -5 Continue training the generator until the model converges, producing predicted edges.
[0179] Secondly, this application uses the edge information of the complete image detected by the Canny operator and the damaged image synthesis as the input of G2, and trains G2 alone. After the loss of the image generator is balanced, this application reduces the learning rate to 1×10 -5 Continue training until convergence.
[0180] Finally, this application cascades G1 and G2, removes the edge discriminator D1, and uses 1×10 -6 The generators G1 and G2 are trained end-to-end with a learning rate of until the model converges.
[0181] Reference Figure 5 , shows the training loss graph of the model proposed in this application on the Places2 dataset. During the entire training period, this application samples the loss value of the latest batch of data every 5000 iterations, and both stages of the network are iterated 2 million times.
[0182] In the experiment, since the span of each loss value in the network is large, this application enlarges the red area of the curve graph to obtain a better visualization effect.
[0183] Figure 5(a) shows the changing trends of different loss functions during the edge prediction network training process. The adversarial loss of G1 fluctuates in the range of (0.5, 1.7), and the adversarial loss of D1 fluctuates around (0.45, 0.75), which shows that G1 and D1 continue to perform adversarial training and then tend to stabilize. As the number of iterations increases, the feature matching loss stabilizes the training by constraining the output of the intermediate layer of the discriminator.
[0184] Figure 5 In (b), the reconstruction loss, perceptual loss, and style loss gradually decrease as the training progresses. This indicates that the gap between the generated samples and the real samples at the feature map or pixel level is narrowing, and the quality of the generated samples is gradually improving.
[0185] 3) Experimental results analysis
[0186] In order to evaluate the effectiveness of the EPAM model, this application quantitatively evaluates and qualitatively compares the proposed EPAM model with the following advanced restoration algorithms: EC, CTSDG, ICT, MAT, and PUT. In order to demonstrate the generalization of the proposed method, this application randomly uses irregular masks, central rectangular masks, and manually annotated masks to conduct occlusion experiments on samples in the qualitative comparison.
[0187] In addition, this application also conducts extensive quantitative comparisons, ablation studies, and visualization analyses to demonstrate the effectiveness of TEP and MFA.
[0188] 3.1) Quantitative analysis process and results
[0189] In order to objectively and comprehensively analyze the performance of the proposed method and other methods, this application uses four commonly used indicators to evaluate the restoration results. Peak signal-to-noise ratio (PSNR) is a commonly used objective measurement method for image quality, but the quality of the evaluation results is different from the perception of the human eye. Structural similarity (SSIM) uses three factors that conform to human perception to evaluate the similarity between images, namely brightness, contrast, and structure. The window size used in the calculation is 51.
[0190] Furthermore, learning perceptual patch similarity (LPIPS) quantifies the differences between images from a perceptual perspective, better reflecting human perception and understanding of images. The mean absolute error (MAE) refers to the average of the absolute errors between two values. On datasets with irregular mask ratios of 20-40%, 40-60%, and random, this application compares the evaluation scores of this application's method with those of advanced methods.
[0191] As shown in Table 1, on the Celeba dataset, the model of this application achieves the best results in both PSNR and SSIM. Only in some cases, LIPIPS and MAE are not ranked in the top two. This is because when using dilated convolutions with different dilation factors to obtain multi-scale context information and long-distance feature information of defective images, too many zero-filling operations of dilated convolutions cause certain edge artifacts in the repaired image, which has a certain impact on the indicators.
[0192] What needs money to be emphasized is that, unlike other indicators, LPIPS compares the Euclidean distance between the feature representations obtained by repairing the image and the real image in certain intermediate layers of the deep neural network. There may be some similarities that cannot be captured by LPIPS, which will cause deviations at the indicator level. In the Facade dataset, the first two indicators of the algorithm of this application are much higher than those of other algorithms, which shows that the algorithm of this application is more conducive to repairing fine structural details in images when facing highly structured objects. On the Places2 dataset, although both PUT and MAT are implemented using the transformer architecture, the performance of the method of this application is comprehensively superior in various indicators.
[0193] It can be seen that the transformer-based edge prediction strategy and multi-scale fusion attention strategy proposed in this application have a significant effect on improving model performance.
[0194] Table 1 Comparison results of methods on Celeba, Facade and Places2 datasets with different mask ratios
[0195]
[0196] Objective quantitative comparison results of the method of this application with EC, CTSDG, ICT, MAT, and PUT. (↓ represents the lower the value, the better, ↑ represents the higher the value, the better).
[0197] 3.2) Qualitative comparison of process and results
[0198] This application evaluates and compares the EPAM model with existing methods on the Celeba dataset containing face images with similar semantics.
[0199] EC is a structure-first-texture restoration method. From the EC results, it can be seen that if the structure prediction in the previous step is incomplete, the detail restoration in the next step will be affected.
[0200] For example, the edges of the eyes and lips of the characters are not sharp enough and the texture is not clear. CTSDG constrains texture and structure to each other, but this method does not have a good balance between texture and structure generation, resulting in local boundary artifacts.
[0201] For example, the mouth of a face image is distorted or missing, and the eyes are not natural enough. ICT uses Transformer to reconstruct visual priors and then uses conventional CNN to fill in texture details, but after large-scale downsampling, important information is lost, resulting in the lack of important semantic information in the generated results.
[0202] For example, the repaired eyes are missing or deformed. MAT uses a mask-aware mechanism to process large areas of missing images, but the processing effect is not ideal for small missing areas in the image. For example, the eyes are asymmetrical and inconsistent in size. PUT uses a non-quantized Transformer design to improve image quality, but does not fully understand semantic features.
[0203] For example: the repaired eyeball is not in harmony with the face.
[0204] Compared with the above methods, the method of the present application is more powerful in understanding global semantics and maintaining more realistic texture details, and can generate face images with consistent structure and color.
[0205] like Figure 6 The application intuitively analyzes the effect of the method of the application on the Facade dataset. When EC faces large-scale rectangular defects, the windows of the building will be missing and the restoration results will have obvious color differences. From the visualization results of CTSDG, it can be seen that this method cannot handle larger holes, which will cause the loss of basic components and image distortion. ICT restores the obscured area at the pixel level, but fails to capture the global structural semantics well.
[0206] For example: Figure 6 The windows and their surrounding contours in the first and second rows of (d) are irregular. MAT reconstructs structure and texture using long-range context, but Figure 6 The mask area reconstructed in the second row of (e) has inconsistent colors and unreasonable semantic objects. The image synthesized by PUT ( Figure 6 (f)) seems to produce reasonable results, but in fact there are obvious artificial traces. In contrast, the model proposed in this application can not only infer reasonable structural semantic information, but also effectively alleviate the mesh artifacts and texture information loss in local areas, thus improving the perceptual quality.
[0207] For example, in Figure 6 In the first and second rows of (g), the window edges restored by the method of the present application are clear and have good visual effects. In addition, the small windows predicted by the mask area in the third row are arranged neatly and have reasonable semantics.
[0208] exist Figure 7In this paper, the proposed model is further evaluated on the places2 dataset containing images with different semantics. In this challenging scenario, the structure-texture based methods EC and CTSDG cannot understand the global context well, resulting in unreasonable completion.
[0209] In contrast, methods using the Transformer architecture (ICT, MAT, PUT) can improve the ability to capture global context information, thereby handling complex image restoration tasks. Since the global structural information is not constrained, there are problems such as inconsistent boundaries and missing semantics in the restoration results.
[0210] like Figure 7 As shown in column 6, the reconstructed target structure in the occluded region is incoherent.
[0211] Compared with the above methods, the method of this application designs a Transformer-based structural restoration module, which can reconstruct the correct semantic content. Based on accurate appearance prior, the attention transfer strategy applied layer by layer to the MFA module effectively combines shallow detail texture information and deep structural semantic information, alleviates the loss of long-distance features in the deep network, and effectively enhances the consistency of global and local features of the image.
[0212] For example: Figure 7 Rows 1-4 in (g) generate high-quality texture and structural details in the missing areas.
[0213] To further demonstrate the effectiveness of the proposed method, the trained model is compared with similar restoration schemes (EC and CTSDG).
[0214] This application is Figure 8 The edge results of EC, CTSDG and the method of this application in the Celeba, Facade and Places2 datasets and the final restoration results are shown in Figure 2. As can be seen from the second and third columns, the edge priors reconstructed by these restoration methods do not correctly predict the semantic contours of building windows, drum washing machine doors, etc.
[0215] Similarly, from the restoration results in columns 5 and 6, we can see that although the color details are similar, the overall structure cannot show the characteristics of the original image. In general, the EC and CTSDG models cannot restore reasonable images such as buildings and faces based on the biased edge prior.
[0216] In contrast, the method of this application introduces relative position encoding and self-attention mechanism, which enhances the ability to extract edge features and restores the core edge information ( Figure 8 (d)), and is able to recover the object boundary that matches the scene semantics in the central area of a large-scale mask.
[0217] In addition, if Figure 8 As shown in the seventh column of , the restoration output texture obtained by the proposed method is more delicate and the visual experience is more realistic. In addition, when the local edge prior information is insufficient, the MFA module will also fuse the global context features and shallow features to guide the model to synthesize novel content ( Figure 8 (g) The grid structure in the right door of row 6).
[0218] 4) Visualize the analysis process and results
[0219] To demonstrate the effectiveness of the TEP module in applying position-sensitive axial attention, we visualize the attention weights of the axial attention layer on the CelebA dataset.
[0220] like Fig.10 As shown, this application selects block 2 of the TEP module and performs heat map visualization on the 8 heads of column (height axis) and row (width axis) attention respectively.
[0221] In order to more clearly show the focus of each head, this application enlarges the Attention Map with a pixel size of 32×32 to 256×256, and then superimposes it with the original image to obtain the attention weight heat map. This application notes that some heads learn to focus on relatively local areas, while others focus on distant contexts.
[0222] For example, in the column-wise attention of this application, column heads 1, 5, and 6 focus on relatively local areas of the head, and column heads 2, 3, and 8 cover the entire image. In the row-wise attention of this application, row heads 1, 2, and 3 are associated with local semantic concepts such as eyes, mouth, and nose of the face. Rowheads 4, 5, and 7 focus more on long-range row-wise contextual relationships.
[0223] In order to verify the effectiveness of the ATN structure applied to the MFA module, this application visualizes the attention score heat map of ATN at different scales. Specifically, It represents the ATN attention score heat map with a resolution of 8×8 in the i-th block of the MFA module. The visualization results are as follows Fig. 9 shown.
[0224] In this experiment, columns 2 to 4 show different attention score matrices from deep to shallow, realizing attention from point to local, and then gradually expanding to local to global areas. This can effectively enhance the consistency of contextual features and improve the model's ability to process features of different scales.
[0225] Secondly, this application visualizes some ATN feature graphs of the MFA module, specifically, It represents the ATN feature map of the size of 64×64 of the kth block of the MFA module. Fig.10 As shown in columns 2 to 5, the MFA module obtains a feature map with multi-level semantic information by applying an attention transfer strategy, reducing information loss or confusion caused by feature scale changes. The feature map is gradually reconstructed and optimized from the first block to the fourth block.
[0226] 5) Study on ablation experiment process
[0227] This application conducts comprehensive ablation experiments based on the Facade dataset to analyze the qualitative and quantitative differences between the different components of the model proposed in this application.
[0228] like Figure 6 As shown in Table 3. This application tried different network combinations. These experiments include: (b) removing the entire TEP module and MFA module, and replacing them with residual blocks from EC (-TER-MFA), (c) removing the entire TEP module and replacing it with 8 residual blocks (-TER), (d) removing only the Axial-attention in the TEP module (-AA), (e) removing the MFA module and replacing it with 4 residual blocks (-MFA), (f) applying the complete TEP module and MFA module (+TER+MFA), that is, the network structure proposed in this application.
[0229] like Fig.10 As shown in column (c) of , since the network composed of residual blocks lacks understanding and analysis of the global structure, it is difficult for this component to correctly predict the edge information of the window in the center area of the large mask. Fig.10 As can be seen from column (d), when faced with large irregular masks, the edge prediction network with only self-attention does not explicitly encode position information, which limits the model's ability to model the local structure of the image and leads to poor restoration results.
[0230] It can be seen that the image restoration network in this paper introduces the MFA module to enhance the correlation of multi-level features and balance the attention to visual content and generated content, thereby realistically restoring the texture details and color information of the damaged area.
[0231] like Fig.10 As shown in columns (e) and (f) of , under the premise of consistent edge priors, the synthetic image obtained without applying the MFA module has the problem of inconsistent wall color information inside and outside the hole. However, the visual effect inside and outside the hole obtained by the present application is more natural, and the area of texture blur is minimal.
[0232] In order to make the comparison of the ablation experiment more specific, a quantitative comparison of the models composed of different components under the indicators PSNR, SSIM, LPIPS and MAE is given in Table 2. From the comparison of the 3rd, 4th and 6th rows of Table 2, it can be seen that the fusion of axial attention and self-attention can significantly improve the performance of the model.
[0233] In addition, Fig.11 In the figure, this application also shows the accuracy and precision curves with and without axial attention. The red curve (using axial attention) has better performance. In the restoration network, this application attempts to use the MFA module to draw on long-distance features at different levels to extract contextual information in the input feature map. The quantitative results in row 6 of Table 2 are significantly better than the results of the residual block (row 5 of Table 2), which shows that the MFA module can help the image restoration generator learn more effective image feature information, thereby improving the model texture synthesis effect.
[0234] Table 2. Quantitative ablation analysis of the proposed method on the Facade dataset
[0235]
[0236] 6) Model complexity experimental process and analysis
[0237] For the computational complexity analysis of the model, this application compares the EPAM model with other methods in terms of total number of parameters, memory consumption, and test time. "Total params" refers to the number of all parameters in the model, including trainable and non-trainable parameters. "Total memory" refers to the amount of video memory space required during model testing. "Runtime" refers to the time it takes to repair a single image.
[0238] It can be clearly seen from Table 3 that the method proposed in this application has the least number of parameters and the lowest video memory cost compared to other methods (ICT, MAT, PUT) that apply the transformer architecture. When repairing a single image, the method proposed in this application also takes less time than all the comparison methods.
[0239] Table 3. Complexity analysis of different models. The lower the value, the better.
[0240]
[0241] It can be seen from the main ideas of the above inventors' research that recent image restoration methods based on deep learning have made great progress in the reconstruction of damaged areas. However, when faced with missing images with large holes, the restoration results often have problems with structural distortion and blurred texture. In this context, this application combines the advantages of transformers and convolutions, and proposes an image restoration method (EPAM) that combines edge priors with an attention mechanism. This method divides the restoration task into two stages: edge prediction and image restoration.
[0242] Specifically, in the edge prediction stage, this application designs a transformer architecture that combines axial attention with standard self-attention, which enhances the ability to extract global structural features and position perception, balances the complexity of self-attention operations, and thus achieves accurate prediction of the edge structure of the defective area. Subsequently, in the image restoration stage, this application proposes a multi-scale fusion attention module that makes full use of multi-level long-distance features, enhances local pixel continuity, and significantly improves the quality of image restoration.
[0243] This application conducts comparative experiments on multiple datasets including CelebA, Places2, and Facade. Quantitative experiments show that the proposed method improves the PSNR and SSIM indicators by 1.141-3.234db and 0.083-0.235 respectively, and decreases the LPIPS and MAE indicators by 0.0347-0.1753 and 0.0104-0.0402 respectively compared with other methods. Qualitative results show that the method of this application can reconstruct images with complete structural information and clear texture details. In addition, the model of this application performs well in terms of the number of parameters, memory cost, and test time.
[0244] The present invention has been described above in conjunction with specific embodiments, but it should be clear to those skilled in the art that these descriptions are exemplary and are not intended to limit the scope of protection of the present invention. Those skilled in the art may make various modifications and variations to the present invention based on the spirit and principles of the present invention, and these modifications and variations are also within the scope of the present invention.
[0245] Other prior art references
[0246]
[26] C.CAO and Y.FU,“Learning a sketch tensor space for imageinpainting of man-made scenes,”in Proc.of the IEEE / CVF InternationalConference on Computer Vision,Montreal,QC,Canada,pp.14509-14518,2021.
[27] A.Vaswani,N.Shazeer,N.Parmar,J.Uszkoreit,L.Jones et al.,“Attention is all youneed,”in Proc.of Advances in Neural Information Processing Systems,LongBeach,CA,USA,pp.5998—6008,2017.
[0247]
[28] H.Chen,Y.Wang,T.Guo,C.Xu,Y.Deng et al.,“Pre-trained imageprocessing transformer,”in Proc.of the IEEE / CVF Conf.on Computer Vision andPattern Recognition,Nashville,TN,USA,pp.12299-12310,2021.
[0248]
[29] J.Devlin,M.W.Chang,K.Lee andK.Toutanova,“Bert:Pre-training ofdeep bidirectional transformers for languageunderstanding,”arXiv:1810.04805,2018.[Online].Available:https: / / arxiv.org / abs / 1810.04805.
[0249]
[30] C.Zheng,T.J.Cham,J.Cai and D.Phung,“Bridging global contextinteractions for high-fidelity image completion,”in Proc.of the IEEE / CVFConf.on Computer Vision and Pattern Recognition,New Orleans,LA,USA,pp.11512-11522,2022.
[0250]
[31] C.Raffel,N.Shazeer,A.Roberts,K.Lee,S.Narang et al.,“Exploring thelimits of transfer learning with a unified text-to-text transformer,”TheJournal of Machine Learning Research,vol.21,no.1,pp.5485-5551,2020.
[0251]
[32] J.Ho,N.Kalchbrenner,D.Weissenborn and T.Salimans,“Axial attentionin multidimensional transformers,”arXiv:1912.12180,2019.[Online].Available:https: / / arxiv.org / abs / 1912.12180.
[0252]
[33] Y.Zeng,J.Fu,H.Chao andB.Guo,“Learning pyramid-context encodernetwork for high-quality image inpainting,”in Proc.of the IEEE / CVF Conf.onComputer Vision and Pattern Recognition,Long Beach,CA,USA,pp.1486–1494,2019.
[0253]
[34] A.Dosovitskiy,L.Beyer,A.Kolesnikov,D.Weissenborn,X.Zhai,et al.,“An image is worth 16x16 words:Transformers for image recognition at scale,”arXiv:2010.11929,2020.[Online].Available:https: / / arxiv.org / abs / 2010.11929.
[0254]
[35] J.L.Ba,J.R.Kiros and G.E.Hinton,“Layer normalization,”arXivpreprint arXiv:1607.06450,2016.[Online].Available:https: / / arxiv.org / abs / 1607.06450.
[0255]
[36] P.Isola,J.Y.Zhu,T.Zhou and A.A.Efros.“Image-to-image translationwith conditional adversarial networks,”in Proc.of the IEEE Conf.on ComputerVision and Pattern Recognition,Honolulu,HI,USA,pp.1125-1134,2017.
[0256]
[37] M.S.M.Sajjadi,B.Scholkopf and M.Hirsch,“EnhanceNet:Single imagesuper-resolution through automated texture synthesis,”in Proc.of the IEEEInt.Conference on Computer Vision,Venice,Italy,pp.4491–4500,2017.
[0257]
[38] Q.Wang,B.Wu,P.Zhu,P.Li,W.Zuo et al.,“ECA-Net:Efficient channelattention for deep convolutional neural networks,”in Proc.of the IEEE / CVFConf.on Computer Vision and Pattern Recognition,Seattle,WA,USA,pp.11534–11542,2020.
[0258]
[39] M.Chen,S.Zang,Z.Ai,J.Chi,G.Yang,et al.,“RFA-Net:Residual featureattention network for fine-grained image inpainting,”Engineering Applicationsof Artificial Intelligence,vol.119,no.2023,pp.105814:1-105814:10,2023.
[0259]
[40] T.C.Wang,M.Y.Liu,J.Y.Zhu,A.Tao,J.Kautz et al.,“High-resolutionimage synthesis and semantic manipulation with conditional gans,”in Proc.ofthe IEEE Conf.on Computer Vision and Pattern Recognition,Salt Lake City,UT,USA,pp.8798-8807,2018.
[0260]
[41] J.Johnson,A.Alahi and L.Fei-Fei,“Perceptual losses for real-timestyle transfer and super-resolution,”in Proc.of European Conference onComputer Vision,Amsterdam,the Netherlands,pp.694-711,2016.
[0261]
[42] L.A.Gatys,A.S.Ecker and M.Bethge,“Image style transfer usingconvolutional neural networks,”in Proc.of the IEEE Conf.on Computer Visionand Pattern Recognition,Las Vegas,NV,USA,pp.2414-2423,2016.
[0262]
[43] K.Simonyan and A.Zisserman,“Very deep convolutional networks forlarge-scale image recognition,”arXiv:1409.1556,2014.[Online].Available:https: / / arxiv.org / abs / 1409.1556.
[0263]
[44] G.Liu,F.A.Reda,K.J.Shih,T.C.Wang,A.Tao et al.,“Image inpaintingfor irregular holes using partial convolutions,”in Proc.of EuropeanConference on Computer Vision,Munich,Germany,pp.85–100,2018.
[0264]
[45] W.Li,Z.Lin,K.Zhou,L.Qi,Y.Wang et al.,“MAT:Mask-Aware Transformerfor Large Hole ImageInpainting,”in Proc.ofthe IEEE / CVF Conf.on ComputerVision and Pattern Recognition,New Orleans,LA,
[0265] USA,pp.10758-10768,2022.
[0266]
[46] Q.Liu,Z.Tan,D.Chen,Q.Chu,X.Dai et al.,“Reduce information loss intransformers for pluralisticimage inpainting,”in Proc.ofthe IEEE / CVF Conf.onComputer Vision andPattern Recognition,New Orleans,LA,USA,pp.11347-11357,2022.
[0267] R.Zhang,P.Isola,A.A.Efros,E.Shechtman and O.Wang,“The unreasonableeffectiveness ofdeep features as aperceptual metric,”in Proc.ofthe IEEEConf.on Computer Vision andPattern Recognition,Salt Lake City,UT,USA,pp.586-595,2018.
Claims
1. An image restoration method based on edge prior combined with attention mechanism, characterized by: It includes edge prediction stage and image repair stage; among them, Edge prediction stage Obtain grayscale defective images and incomplete edge information, predict reasonable edge contours in the defective area through a transformer architecture that combines axial attention with standard self-attention, and obtain an edge prediction map; The edge prediction stage is implemented through the edge prediction network; the image restoration stage is implemented through the image restoration network; among them, The edge prediction network includes an edge generator and edge discriminator ,by represents the edge generator operation, then the edge prediction graph is expressed as: The image inpainting network consists of an image generator and image discriminator ,use Representing the operation of the image generator, the predicted image is represented as: Get repaired output with the same size as the original: In the formula, , and Represent the original image, the corresponding grayscale image, and the edge structure image respectively; the incomplete image is represented as , the grayscale representation of the incomplete image is , the defect edge is expressed as ,in Represents an element-by-element product operation; Representing a synthesized edge prediction map; Image inpainting stage The edge prediction map is used as the structural prior and combined with the defective RGB image. The texture details are synthesized in the local closed area surrounded by the edge through a multi-scale fusion attention module to complete the image restoration.
2. The method according to claim 1, characterized in that: The edge generator is based on an autoencoder structure, and completes an edge prediction graph through a decoding stage of encoder data compression, a feature reconstruction stage of bottleneck layer feature reconstruction, and a decoding stage of decoder decompression for a given image feature.
3. The method according to claim 2, characterized in that: The encoding stage, feature reconstruction stage and decoding stage respectively include the following steps: In the encoding stage, the encoder first uses a 7×7 convolution with a reflection padding parameter of 3 and a stride of 1 to obtain features, adjusts the given image features to a size of 256×256×64, and then obtains a shallow output feature of size 32×32×256 through three consecutive layers of convolution with a stride of 2 and a convolution kernel size of 4×4; In the feature reconstruction stage, eight transformer structures based on the axial attention mechanism are stacked to form an information bottleneck layer to enhance the representation ability of feature information and the capture ability of global structural information, complement the missing edge information, and obtain a reconstructed feature with a dimension of 32×32×256; In the decoding stage, three transposed convolutions with a kernel size of 4×4, a zero padding operation of 1, and a stride of 2 are used to upsample the features to 256×256×64, and then a convolution with a kernel size of 7×7, a reflection padding parameter of 3, and a stride of 1 is used to adjust the output to 256×256×1 to obtain the edge prediction map.
4. The method according to claim 3, characterized in that The edge discriminator includes a convolution stage and a sample output stage, wherein: In the convolution stage, the PatchGAN architecture is selected, which consists of 5 layers of convolution with strides of 2, 2, 2, 1, 1 and a convolution kernel size of 4×4; In the sample output stage, the input image is calculated into a single-channel feature map of size 30×30 through 5 layers of convolution operations. The Sigmod function is used to map the output to a scalar in the range of [0,1], which effectively distinguishes the true and false of the input sample and obtains the edge repair result.
5. An image restoration device based on edge prior combined with attention mechanism, used to execute the method according to any one of claims 1 to 4, characterized in that: It includes edge prediction module and image restoration module, where: The edge restoration module is used to obtain grayscale defective images and incomplete edge information, and predict reasonable edge contours in the defective area through a transformer architecture that combines axial attention with standard self-attention to obtain an edge prediction map; The image inpainting module is used to use the edge prediction map as the structural prior, combined with the defective RGB image, and synthesize texture details in the local closed area surrounded by the edge through a multi-scale fusion attention module to complete the image inpainting.
6. The device according to claim 5, characterized in that The edge prediction module comprises: The encoding unit first obtains features by using a 7×7 convolution with a reflection padding parameter of 3 and a stride of 1 through the encoder, which adjusts the given image features to a size of 256×256×64, and then obtains shallow output features of size 32×32×256 through three consecutive layers of convolution with a stride of 2 and a convolution kernel size of 4×4; The feature reconstruction unit selects and stacks eight transformer structures based on the axial attention mechanism to form an information bottleneck layer, which enhances the representation ability of feature information and the capture ability of global structural information, completes the missing edge information, and obtains the reconstructed features with a dimension of 32×32×256; In the decoding stage, the features are upsampled to 256×256×64 by using three transposed convolutions with a kernel size of 4×4, a zero padding operation of 1, and a stride of 2, and then the output is adjusted to 256×256×1 by using one convolution with a kernel size of 7×7, a reflection padding parameter of 3, and a stride of 1 to obtain the edge prediction map.
7. The device according to claim 6, characterized in that The edge prediction module also includes: The convolution unit, based on PatchGAN architecture, consists of 5 layers of convolution, with strides of 2, 2, 2, 1, 1, and a convolution kernel size of 4×4; The sample output unit calculates the input image into a single-channel feature map of size 30×30 through the above 5-layer convolution operation, and uses the Sigmod function to map the output to a scalar in the range of [0,1], which effectively distinguishes the true and false of the input sample and obtains the edge repair result.
8. An image restoration device, comprising at least one processor and a memory, characterized in that: Computer instructions are stored in the memory, and the processor is used to execute the computer instructions stored in the memory to implement the steps of the image restoration method combining edge prior and attention mechanism as described in any one of claims 1-4.
9. A computer-readable storage medium having a computer program stored thereon, wherein the computer program is used to execute the steps of the image restoration method combining edge prior and attention mechanism as described in any one of claims 1 to 4.
