A multi-scale image restoration method, storage medium and terminal
By introducing multi-scale polarization self-attention mechanism and skip connection into the image repair network, combined with the multi-scale feature fusion module, the problem of poor image repair effect in the existing technology is solved, and efficient repair of images with missing large-scale information is achieved. .
Patent Information
- Application Number
- CN202210668883.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-06-14
- Publication Date
- 2024-09-03
- Estimated Expiration
- Not applicable · inactive patent
AI Technical Summary
Existing image repair methods based on convolutional neural networks have poor results when there is a large range of information missing, especially due to the inability to fully utilize the semantic and spatial information of the image due to skip connections and compressed dimension operations, resulting in poor repair effects.
A multi-scale polarized self-attention generative adversarial network is used. By embedding channel self-attention branches and spatial self-attention branches in the generator, combined with skip connections and multi-scale feature fusion modules, the network structure is optimized to improve image restoration performance.
It achieves efficient image restoration in the absence of large-scale information, reduces information loss, improves restoration accuracy and efficiency, and avoids pattern collapse.
Smart Images

Figure CN115018727B
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of image restoration, and in particular to a multi-scale image restoration method, a storage medium and a terminal. Background Art
[0002] At present, in many scenarios, images with large-scale missing information need to be repaired. Existing methods based on convolutional neural networks are ineffective in establishing long-distance regional correlations. Due to too many missing pixels, these methods cannot obtain pixel information of distant images, and the image restoration effect is poor.
[0003] Some methods improve the above problems by adding other global feature extraction modules to the network, but this will greatly increase the complexity of the model, consume huge computing resources, and the effect of repairing large-scale missing pixels is not good in some specific scenarios.
[0004] In addition, as generative networks (including generative adversarial networks and variational autoencoders (VAE)) are used in the field of image restoration, the restoration performance of such methods for images with large-scale information missing has been greatly improved. However, since these methods usually use skip connections and compressed dimension operations, they cannot fully utilize the rich semantic and spatial information of the original images, and the compressed dimension operations will lose certain image information, making large-scale information missing images that originally had poor restoration effects even more difficult to repair. Summary of the invention
[0005] The present invention provides a multi-scale image restoration method, a storage medium and a terminal to solve the technical problem that the original information of the image cannot be fully utilized due to skip connections and compression dimension operations in image restoration.
[0006] In order to solve the above problems, the present invention provides a multi-scale image restoration method, which comprises:
[0007] Step S 100 : Obtain the original real image and the corresponding binary defect mask, construct a dataset of images to be repaired and the corresponding original real image dataset, and divide the dataset of images to be repaired into a training set and a test set according to a preset ratio;
[0008] Step S 200 : Construct a multi-scale polarized self-attention generative adversarial network, which is composed of a generator G and a discriminator D, and embed a polarized self-attention mechanism module at different scales of the generator G. The polarized self-attention mechanism module includes a channel self-attention branch and a spatial self-attention branch, and the channel self-attention branch and the spatial self-attention branch are connected in parallel;
[0009] Step S 300: Set the network model hyperparameters, use the image training set to be repaired to train and model the multi-scale polarized self-attention mechanism to generate adversarial network models, and use the loss function to optimize the network structure parameters;
[0010] Step S 400 : The multi-scale polarized self-attention generative adversarial repair model is tested using a test set of images to be repaired, and the repair performance of the model is evaluated by calculating the evaluation index between the repaired image and the original real image.
[0011] Furthermore, in step S 100 In the method, obtaining the original real image and the corresponding binary defect mask specifically includes:
[0012] Step S 101 : Construct a missing pixel image dataset for image restoration from the image restoration dataset and the Mask dataset, and perform preliminary preprocessing on the image;
[0013] Step S 102 : The mask and the real image are multiplied by pixels to obtain a missing pixel image dataset, and the images in the dataset and the Mask mask are input into the generator of the model together.
[0014] Furthermore, in step S 200 In the invention, the generator is composed of an encoder and a decoder, a jump connection is added between the encoder and the decoder, a multi-scale feature fusion module is added to the jump connection, the encoder continuously extracts feature maps of different levels of the original image to obtain deep features of the original image; the multi-scale feature fusion module fuses feature maps of different sizes and provides them to the deconvolution layer of the decoder, and performs pixel prediction on the fused feature maps.
[0015] Furthermore, the multi-scale feature fusion module is internally composed of a convolutional layer branch and a deconvolutional layer branch.
[0016] The convolutional layer branch obtains a deeper feature map by convolving, normalizing and activating the input feature map.
[0017] The deconvolution layer branch obtains a feature map of a larger scale by performing two-layer deconvolution, normalization, and activation function activation on the input feature map;
[0018] The feature maps of the same size from these two branches are concatenated and fused to obtain an output feature map that is rich in spatial and semantic information.
[0019] Furthermore, in step S 200In the modeling process, the discriminator D adopts the adversarial loss function algorithm. During the adversarial training process, the sum of multiple loss functions is optimized to obtain a multi-scale polarized self-attention generation adversarial repair model.
[0020] Furthermore, in step S 300 In the method, the training and modeling of the multi-scale polarized self-attention mechanism generative adversarial network model using the training set of the image to be repaired specifically includes:
[0021] Inputting the image to be repaired and the corresponding mask image into the generator G at the same time, and extracting their features at the same time;
[0022] The generator G extracts the overall features of the original image from the image to be repaired, and generates a repaired image that is as similar to the real image as possible;
[0023] The discriminator D determines whether the input image data is a real image or a restored image generated by the generator G, and sends the loss result back to the generator G through gradient feedback. The generator G continues to generate an image with a better restoration effect according to the result;
[0024] After a large number of training iterations, the generator G generates images with better restoration effects.
[0025] Furthermore, the specific implementation of the pixel-level attention module includes:
[0026] Extract the foreground and background pixel blocks of the input feature map respectively, measure the similarity between the background and foreground pixel blocks, and perform pixel value matching by calculating the normalized inner product;
[0027] After the pixel block matching is completed, the activation function is used to calculate the weight to obtain the attention weight, and then the obtained attention weight is concatenated with the original input feature map;
[0028] The obtained concatenated feature map is input into the improved polarized self-attention mechanism module to obtain the output image.
[0029] Furthermore, the polarized self-attention mechanism module includes a channel self-attention branch and a spatial self-attention branch.
[0030] The specific implementation of the channel self-attention branch includes: inputting the input feature map into the channel self-attention branch layer, obtaining the channel self-attention weight after multi-layer convolution operation, and performing multiplication operation with the input feature map;
[0031] The specific implementation of the spatial self-attention branch includes: inputting the input feature map into the spatial self-attention branch layer, obtaining the spatial self-attention weight after pooling operation and multi-layer convolution operation, and performing multiplication operation with the input feature map;
[0032] The results of the channel self-attention branch and the spatial self-attention branch are fused to obtain the repaired output image of the polarized self-attention structure.
[0033] Furthermore, the loss function includes: adversarial loss function L adv , Perceptual loss function L perceptual , style loss function L style , total variation loss function L tv , hole loss function L hole And the validation loss function L valid ; Specifically:
[0034] The adversarial loss function is defined as:
[0035]
[0036] Where: D(·) represents the discrimination of the image in brackets, D(I gt ) represents the discrimination of the real image input to the discriminator, D(I pred ) indicates the discrimination of the repaired image input to the discriminator, and BCELoss(·) indicates the calculation of the binary cross entropy loss;
[0037] The perceptual loss function expression is:
[0038]
[0039] The style loss function expression is:
[0040]
[0041] The total variation loss function expression is:
[0042]
[0043] The hole loss function expression is:
[0044]
[0045] The verification loss function expression is:
[0046]
[0047] The total loss function expression is: L = α1L adv +α2L perceptual +α3L style +α4L tv +α5L hole +α6L valid
[0048] in: Respectively represent the i-th layer feature maps of the extracted real image and the repaired image, H i ,W i ,C i represents the height, width and number of channels of the feature map extracted to the i-th layer, |·|1 represents the calculation of the L1 norm, I represents the product of the feature map of the i-th layer of the real image and the repaired image and its transpose, respectively. x,y Represents the pixel value at position (x, y) in the image, I x+1,y Represents the pixel value at position (x+1, y) in the image, I x,y+1 represents the pixel value at position (x, y+1) in the image, E(·) represents the mean value, i, j, k represent the height, width and number of channels of the real image or the restored image respectively, Represent the pixel values of the hole areas of the real image and the repaired image respectively, Represent the pixel values of the valid areas of the real image and the repaired image respectively, and {α1, α2..., α6} represents the weight of each loss in the total loss function.
[0049] Furthermore, the evaluation indicators include: peak signal-to-noise ratio PSNR, structural similarity SSIM and L1 loss; specifically:
[0050] The peak signal-to-noise ratio PSNR function expression is:
[0051]
[0052]
[0053] The structural similarity SSIM function expression is:
[0054]
[0055] c1=(k1(2 N -1)) 2 ,c2=(k2(2 N -1)) 2 (twenty one)
[0056] The L1 loss function expression is:
[0057] L1Loss=L valid +L hole (twenty two)
[0058] Where: MSE(·) represents the mean square error, X(i,j) and Y(i,j) represent the pixel values at position (i,j) of the restored image and the real image respectively, N represents the image pixel represented by N bits of binary, μ x , μ y represent the means of x and y respectively, Represent the variance of x and y respectively, σ xy represents the covariance of x and y, c1 and c2 are two non-zero constants, k1 and k2 have default values of 0.01 and 0.03, L valid , Lh ole That is, the validation loss and hole loss during training.
[0059] A second object of the present invention is to provide a storage medium on which computer instructions are stored, and when the computer instructions are executed, the steps of the multi-scale image restoration method described above are executed.
[0060] The third object of the present invention is a terminal, comprising a memory and a processor, wherein the memory stores computer instructions that can be executed on the processor, and the processor executes the steps of the above-mentioned multi-scale image restoration method when running the computer instructions.
[0061] Compared with the prior art, the present invention has significant advantages and beneficial effects, which are specifically embodied in the following aspects:
[0062] 1. The present invention uses a generative adversarial network as the backbone network of the image restoration model, and adds a pixel-level attention module to the generator. The network obtains the internal connection of the image features to be restored by focusing on the attention of the missing area and the non-missing area, as well as the self-attention within the missing area, thereby achieving pixel-level fine restoration and providing an effective way to reconstruct images with missing information;
[0063] 2. The present invention adds a polarization attention mechanism to the pixel-level attention module in the image generation process to avoid excessive channel and spatial dimension compression operations, so that the original image information loss is small and it is conducive to restoration;
[0064] 3. The present invention adopts skip connection in the generator to make full use of the shallow spatial information and deep semantic information of the original image, enhance the expression and restoration efficiency of the high-level semantic information of the image, and avoid mode collapse;
[0065] 4. A multi-scale feature fusion module is added to the jump connection of the restoration model of the present invention, which can effectively combine the deep feature information of the original image at different levels, share the information to the back layer of the network through the jump connection, and improve the restoration accuracy of large-scale missing images. BRIEF DESCRIPTION OF THE DRAWINGS
[0066] Figure 1It is a program flow chart of a multi-scale image restoration method based on a polarized self-attention mechanism in an embodiment of the present invention;
[0067] Figure 2 This is a multi-scale image restoration framework diagram based on the polarization self-attention mechanism in an embodiment of the present invention;
[0068] Figure 3 This is a schematic diagram of an image restoration principle based on a generative adversarial network in an embodiment of the present invention;
[0069] Figure 4 It is a structural diagram of a multi-scale feature fusion method module in an embodiment of the present invention;
[0070] Figure 5 It is a structural diagram of a pixel-level attention module in an embodiment of the present invention;
[0071] Figure 6 2 is a structural diagram of the polarized self-attention mechanism module in an embodiment of the present invention. DETAILED DESCRIPTION
[0072] In order to make the above-mentioned objects, features and advantages of the present invention more obvious and easy to understand, specific embodiments of the present invention are described in detail below with reference to the accompanying drawings.
[0073] See also Figure 1 As shown, an embodiment of the present invention provides a multi-scale image restoration method, and the restoration method comprises the following steps:
[0074] Step S 100 : Obtain the original real image and the corresponding binary defect mask, construct a dataset of images to be repaired and the corresponding original real image dataset, and divide the dataset of images to be repaired into a training set and a test set according to a preset ratio.
[0075] The present invention selects the training data set of Paris StreetView to train the generator and discriminator in the model, and selects the test set in Paris StreetView to construct the test set required in the embodiment of the present invention to test the generalization performance of the model.
[0076] The Paris StreetView general dataset has been divided into training and test sets. It divides images into training and test sets in a certain ratio. The two parts do not contain the same images. The training set is used to train the image restoration model, and the test set is used to test the restoration effect of the trained image restoration model.
[0077] It should be noted that the real images contained in the dataset and the masks with different mask rates in the Mask dataset constitute a new training and testing dataset. The larger the mask rate, the more missing pixels in the image.
[0078] The data processing method in the multi-scale image restoration method is as follows:
[0079] First, the size of the images in the Paris StreetView dataset is not uniform, so the present invention readjusts the image size in the training dataset and the test dataset in Paris StreetView to 256*256;
[0080] Second, generate binary masks (Mask) of various mask rate types;
[0081] Third, the binary mask (Mask) is multiplied by the resized image in the training data set to generate the image to be repaired. The image to be repaired and the resized image (real image) are used as the input of the model; the binary mask (Mask) is multiplied by the resized image in the test data set to generate a test image. The test image can be used to test the generalization performance of the model.
[0082] For the training process, the original image and mask should be prepared first. The size of the original image and mask image should be no less than 256*256. For the original image and mask image, the size should be adjusted first, and the image size should be changed to 256*256 by appropriate cropping.
[0083] Step S 200 : A multi-scale polarized self-attention generative adversarial network is constructed, which consists of a generator G and a discriminator D, and a pixel-level attention layer is embedded at different scales of the generator G, wherein a polarized self-attention mechanism module is used to establish weight optimization, and the polarized self-attention mechanism module includes a channel self-attention branch and a spatial self-attention branch, and the channel self-attention branch and the spatial self-attention branch are connected in parallel.
[0084] Step S 300 : Set the network model hyperparameters, use the training set of the image to be repaired to train and model the multi-scale polarized self-attention mechanism to generate adversarial network models, and use six joint loss functions including adversarial loss, perceptual loss, style loss, total variation loss, hole loss and verification loss to optimize the network structure parameters;
[0085] Step S 400 : The multi-scale polarized self-attention generative adversarial inpainting model is tested on a test set of images to be inpainted, and the inpainting performance of the model is evaluated by calculating three evaluation indicators: peak signal-to-noise ratio (PSNR), structural similarity (SSIM), and L1 loss between the inpainted image and the original real image.
[0086] Specifically, in step S 200In the invention, the generator is composed of an encoder and a decoder, a jump connection is added between the encoder and the decoder, a multi-scale feature fusion module is added to the jump connection, the encoder continuously extracts feature maps of different levels of the original image to obtain deep features of the original image; the multi-scale feature fusion module fuses feature maps of different sizes and provides them to the deconvolution layer of the decoder, and performs pixel prediction on the fused feature maps.
[0087] See also Figure 2 As shown, the generative adversarial network consists of two parts: a generator G (Generator) and a discriminator D (Discriminator). The generator G consists of an encoder and a decoder, and the structures of the encoder and the decoder are basically symmetrical.
[0088] The encoder consists of 8 encoding feature extraction modules, and the encoding feature extraction module consists of an encoding convolution layer-normalization layer-activation function.
[0089] After each encoding convolution layer, batch normalization is performed and activated by an activation function. As the number of convolution layers increases, a large number of convolution operations are performed to continuously extract features of different levels of the original image and obtain the deep features of the original image. For example, the extracted features gradually evolve from low-level features based on color and texture to high-level abstract features based on image semantic information.
[0090] Therefore, in the encoder of the model, the first 8 convolutional layer structures are used for feature extraction. After each convolutional layer, the size of the feature map is halved until the size of the feature map is reduced to 1*1. Through the encoding operation, the input defective image is compressed into feature maps of different scales.
[0091] The decoder consists of 8 decoding feature mapping modules, 2 pixel-level attention modules and 2 multi-scale feature fusion modules, wherein the decoding feature mapping module consists of a deconvolution layer-normalization-activation function.
[0092] The decoder reconstructs the image through 8 deconvolution layers. After each deconvolution layer, the size of the feature map doubles until it is restored to the size of the input image (256*256).
[0093] The feature map obtained before each pixel-level attention module in the decoder is weighted and convolved. During the image restoration process, it is reconstructed with the real image through a joint loss and compared with the real image during the image reconstruction process, thereby gradually controlling the generation process of the image to be restored, thereby making the training process more stable.
[0094] The function of the generator G is to extract the overall features of the original image from the image to be repaired with missing pixels, and generate a repaired image that is as similar to the real image as possible;
[0095] The role of the discriminator D is to determine whether the input image data is a real image or a restored image generated by the generator, and send the result back to the generator through gradient feedback. The generator continues to generate images with better restoration effects based on the loss results.
[0096] Through the game between the generator G and the discriminator D, after a large number of training iterations, the image restoration effect generated by the generator G can be made very good.
[0097] See also Figure 2 As shown, in the embodiment of the present invention, between the first 8 convolutional layers and the last 8 deconvolutional layers, the 3rd and 4th convolutional layers are followed by an initialization module and a multi-scale feature fusion module for learning long-term dependencies within the feature map and obtaining important attention areas. In the last 8 deconvolutional layers, the 5th, 6th, and 7th deconvolutional layers are respectively followed by a pixel-level attention module to generate a better quality restoration image.
[0098] Therefore, the generator in the embodiment of the present invention uses multiple convolutional layers to extract deep and shallow features, and fuses feature maps of different sizes through jump connections and multi-scale feature fusion modules, and provides them to the corresponding deconvolution layer of the decoder D to perform pixel prediction on the fused feature maps.
[0099] See also Figure 2 As shown, in the embodiment of the present invention, the discriminator includes 5 feature discrimination modules, and the feature discrimination module is composed of a discrimination convolution layer-normalization-activation function.
[0100] Batch normalization operations are added after the convolutional layers of the generator G and the discriminator D to perform batch normalization on the feature maps after convolution to speed up network convergence.
[0101] It should be noted that the human attention mechanism is derived from intuition. It is a means for humans to use limited attention resources to quickly filter out high-value information from a large amount of information. The attention mechanism in deep learning draws on the human attention thinking mode and is widely used in various types of deep learning tasks such as natural language processing, image classification and speech recognition, and has achieved remarkable results.
[0102] See also Figure 2As shown, this example adds a pixel-level attention module between the 5th, 6th and 7th deconvolution layers of the decoder module. The polarized self-attention mechanism used in the pixel-level attention module includes a channel self-attention branch and a spatial self-attention branch. The channel self-attention branch and the spatial self-attention branch are connected in parallel. The generated feature map needs to pass through the channel self-attention branch and the spatial self-attention branch, so that the network model performs image restoration through two dimensions: feature information of known areas and self-attention within unknown areas, thereby achieving high-precision and high-efficiency reconstruction of the missing area of the image to be repaired.
[0103] See also Figure 5 As shown in Figure 2, the proposed model uses the attention mechanism in the pixel-level attention module.
[0104] The working principle of the pixel-level attention module is:
[0105] First, the foreground and background pixel blocks of the input feature map are extracted respectively, the similarity between the background and foreground pixel blocks is measured, and the pixel value matching is performed by calculating the normalized inner product.
[0106] (1) After the mask image enters the attention layer of the attention mechanism, the background area is first distinguished from the foreground area, and the background area is divided into multiple 3×3 patches.
[0107] (2) The 3×3 background patches are integrated into a 3×3 convolution kernel, and the corresponding convolution operation is performed on the foreground area to obtain the corresponding multiple reconstructed foregrounds.
[0108] (3) The similarity between the two is obtained by calculating the inner product value of each reconstructed foreground and the target foreground area.
[0109] Secondly, after the pixel block matching is completed, the activation function is used to calculate the weight to obtain the attention weight, and then the obtained attention weight is concatenated with the original input feature map.
[0110] (4) After normalization by the softmax function, the corresponding attention score of each background patch block in the foreground area is obtained.
[0111] Finally, the obtained concatenated feature map is input into the improved polarized self-attention module to obtain the output image.
[0112] (5) Using the obtained attention score as the weight, weighted superposition of each reconstructed foreground is performed to obtain the final reconstruction result of the foreground area with the background area information, which participates in the final image restoration process.
[0113] Through the above method, the missing pixel values can be repaired more finely.
[0114] Specifically, see Figure 6 As shown, in the embodiment of the present invention, the polarization self-attention mechanism module includes a channel self-attention branch and a spatial self-attention branch.
[0115] The specific implementation of the channel self-attention branch includes: inputting the input feature map into the channel self-attention branch layer, obtaining the channel self-attention weight after multi-layer convolution operation, and performing multiplication operation with the input feature map;
[0116] The specific implementation of the spatial self-attention branch includes: inputting the input feature map into the spatial self-attention branch layer, obtaining the spatial self-attention weight after pooling operation and multi-layer convolution operation, and performing multiplication operation with the input feature map;
[0117] The results of the channel self-attention branch and the spatial self-attention branch are fused to obtain the repaired output image of the polarized self-attention structure.
[0118] Therefore, the addition of the polarized self-attention mechanism is to solve the problem of information loss caused by too many dimensionality reduction operations in existing image restoration technologies. Compared with other attention methods, the polarized self-attention used in the embodiment of the present invention does not perform a large degree of compression in the spatial dimension and the channel dimension (maintaining the original size in the spatial dimension and half the size of the original channel in the channel dimension), and also maintains the complexity at a relatively small level, which can effectively reduce the information loss of the original image while reducing the complexity of the model, thereby improving the performance of image restoration.
[0119] Specifically, in the embodiment of the present invention, the multi-scale image restoration method uses a total of 6 loss functions for back propagation when constructing the model and performing model training, and continuously improves and optimizes the model to improve the image restoration result.
[0120] The six loss functions include: adversarial loss function L adv , Perceptual loss function L perceptual , style loss function L style , total variation loss function L tv , hole loss function L hole And the validation loss function L valid ; Specifically:
[0121] The adversarial loss function is defined as:
[0122]
[0123] Where: D(·) represents the discrimination of the image in brackets, D(I gt ) represents the discrimination of the real image input to the discriminator, D(I pred) indicates the discrimination of the repaired image input to the discriminator, and BCELoss(·) indicates the calculation of the binary cross entropy loss;
[0124] The perceptual loss function expression is:
[0125]
[0126] The style loss function expression is:
[0127]
[0128] The total variation loss function expression is:
[0129]
[0130] The hole loss function expression is:
[0131]
[0132] The verification loss function expression is:
[0133]
[0134] The total loss function expression is: L = α1L adv +α2L perceptual +α3L style +α4L tv +α5L hole +α6L valid
[0135] in: They represent the i-th layer feature maps of the real image and the repaired image extracted by the convolutional network, respectively.
[0136] H i ,W i ,C i represents the height, width and number of channels of the feature map extracted to the i-th layer, |·|1 represents the calculation of the L1 norm,
[0137] Respectively represent the product of the feature map of the i-th layer of the real image and the repaired image and its transpose,
[0138] I x,y Represents the pixel value at position (x, y) in the image, I x+1,y Represents the pixel value at position (x+1, y) in the image, I x,y+1 Represents the pixel value at position (x, y+1) in the image,
[0139] E(·) represents the mean value, i, j, k represent the height, width and number of channels of the real image or the restored image respectively,
[0140] Represent the pixel values of the hole areas of the real image and the repaired image respectively, Represent the pixel values of the valid areas of the real image and the repaired image respectively,
[0141] {α1, α2..., α6} represents the weight of each loss in the total loss function.
[0142] Specifically, in the embodiment of the present invention, three evaluation indicators are used to measure the restoration effect of the restored image, and the three evaluation indicators include: peak signal-to-noise ratio PSNR, structural similarity SSIM and L1 loss; specifically:
[0143] The peak signal-to-noise ratio PSNR function expression is:
[0144]
[0145]
[0146] The structural similarity SSIM function expression is:
[0147]
[0148] c1=(k1(2 N -1)) 2 ,c2=(k2(2 N -1)) 2 (10)
[0149] The L1 loss function expression is:
[0150] L1Loss=L valid +L hole (11)
[0151] Where: MSE(·) represents the mean square error, X(i,j) and Y(i,j) represent the pixel values at position (i,j) of the restored image and the real image respectively, and N represents the image pixel represented by N bits of binary.
[0152] μ x , μ y represent the means of x and y respectively,
[0153] represent the variance of x and y respectively,
[0154] σ xy represents the covariance of x and y,
[0155] c1 and c2 are two constants to avoid division by zero. The default values of k1 and k2 are 0.01 and 0.03.
[0156] L valid , Lh ole That is, the validation loss and hole loss during training.
[0157] Based on any of the above exemplary embodiments, another exemplary embodiment of the present invention provides a storage medium having computer instructions stored thereon, and the steps of the multi-scale image restoration method are executed when the computer instructions are executed.
[0158] Based on any of the above exemplary embodiments, another exemplary embodiment of the present invention provides a terminal, including a memory and a processor, wherein the memory stores computer instructions that can be executed on the processor, and the processor executes the steps of the multi-scale image restoration method when running the computer instructions.
[0159] Based on such understanding, the technical solution of this embodiment can essentially or contribute to the prior art or part of the technical solution can be embodied in the form of a software product, which is stored in a storage medium and includes a number of instructions for enabling the device to execute all or part of the steps of the method described in each embodiment of the present invention.
[0160] The aforementioned storage media include: U disk, mobile hard disk, read-only memory, random access memory, magnetic disk or optical disk and other media that can store program codes.
[0161] Although the disclosure is disclosed as above, the protection scope of the disclosure is not limited thereto. Those skilled in the art may make various changes and modifications without departing from the spirit and scope of the disclosure, and these changes and modifications will fall within the protection scope of the present invention.
Claims
1. A multi-scale image restoration method, It is characterized in that The repair method comprises: Step S 100 : Obtain the original real image and the corresponding binary defect mask, construct a dataset of images to be repaired and the corresponding dataset of original real images, and divide the dataset of images to be repaired into a training set and a test set according to a preset ratio; Step S 200 : Construct a multi-scale polarized self-attention generative adversarial network, which is composed of a generator G and a discriminator D, and embed a polarized self-attention mechanism module at different scales of the generator G. The polarized self-attention mechanism module includes a channel self-attention branch and a spatial self-attention branch, and the channel self-attention branch and the spatial self-attention branch are connected in parallel; The polarized self-attention mechanism module includes a channel self-attention branch and a spatial self-attention branch. The specific implementation of the channel self-attention branch includes: inputting the input feature map into the channel self-attention branch layer, obtaining the channel self-attention weight after multi-layer convolution operation, and performing multiplication operation with the input feature map; The specific implementation of the spatial self-attention branch includes: inputting the input feature map into the spatial self-attention branch layer, obtaining the spatial self-attention weight after pooling operation and multi-layer convolution operation, and performing multiplication operation with the input feature map; The results of the channel self-attention branch and the spatial self-attention branch are fused to obtain the repaired output image of the polarized self-attention structure; Step S 300 : Set the network model hyperparameters, use the image training set to be repaired to train and model the multi-scale polarized self-attention mechanism to generate adversarial network models, and use the loss function to optimize the network structure parameters; Step S 400 :The multi-scale polarized self-attention generative adversarial restoration model is tested using a test set of images to be restored, and the restoration performance of the model is evaluated by calculating the evaluation index between the restored image and the original real image; The loss function includes an adversarial loss function , Perceptual loss function , style loss function , total variation loss function , hole loss function And the validation loss function , specifically: The adversarial loss function is defined as: in: Indicates the identification of the image in brackets. Indicates the discrimination of the real image input to the discriminator. Indicates the discrimination of the repaired image input to the discriminator. Indicates the calculation of binary cross entropy loss; The perceptual loss function expression is: The style loss function expression is: The total variation loss function expression is: The hole loss function expression is: The verification loss function expression is: The total loss function expression is: ; in: , Represent the i-th layer feature maps of the extracted real image and the restored image respectively, , , Indicates the height, width and number of channels of the feature map extracted to the i-th layer. Indicates the calculation of L1 norm, , Respectively represent the product of the feature map of the i-th layer of the real image and the repaired image and its transpose, represents the pixel value at position (x, y) in the image, Represents the pixel value at position (x+1, y) in the image, Represents the pixel value at position (x, y+1) in the image, represents the mean, i, j, k represent the height, width and number of channels of the real image or the restored image respectively, , Represent the pixel values of the hole areas of the real image and the repaired image respectively, , Represent the pixel values of the valid areas of the real image and the repaired image respectively, { , ..., } represents the weight of each loss in the total loss function; The evaluation indicators include peak signal-to-noise ratio PSNR, structural similarity SSIM and L1 loss, specifically: Peak signal-to-noise ratio PSNR The function expression is: The L1 loss function expression is: Where: MSE(·) represents the mean square error, , Represent the pixel values of the restored image and the real image (i, j) respectively, N means that the image pixel is represented by N bits of binary. , represent the means of x and y respectively, , represent the variance of x and y respectively, represents the covariance of x and y, c 1 and c 2 are two non-zero constants, k 1 and k 2 The default values are 0.01 and 0.
03. 、 That is, the validation loss and hole loss during training.
2. The multi-scale image restoration method according to claim 1, It is characterized in that In step S 100 In the method, the obtaining of the original real image and the corresponding binary defect mask further comprises: Step S 101 : Construct a missing pixel image dataset for image restoration from the image restoration dataset and the Mask dataset, and perform preliminary preprocessing on the image; Step S 102 : The mask and the real image are multiplied by pixels to obtain a missing pixel image dataset, and the images in the dataset and the Mask mask are input into the generator of the model together.
3. The multi-scale image restoration method according to claim 1, It is characterized in that In step S 200 In the invention, the generator is composed of an encoder and a decoder, a jump connection is added between the encoder and the decoder, a multi-scale feature fusion module is added to the jump connection, the encoder continuously extracts feature maps of different levels of the original image to obtain deep features of the original image; the multi-scale feature fusion module fuses feature maps of different sizes and provides them to the deconvolution layer of the decoder, and performs pixel prediction on the fused feature maps.
4. The multi-scale image restoration method according to claim 3, It is characterized in that The multi-scale feature fusion module is composed of a convolutional layer branch and a deconvolutional layer branch. The convolutional layer branch obtains a deeper feature map by convolving, normalizing and activating the input feature map with an activation function; The deconvolution layer branch obtains a feature map of a larger scale by performing two-layer deconvolution, normalization, and activation function activation on the input feature map; The feature maps of the same size from these two branches are concatenated and fused to obtain an output feature map that is rich in spatial and semantic information.
5. The multi-scale image restoration method according to claim 1, It is characterized in that In step S 300 In the method, the training and modeling of the multi-scale polarized self-attention mechanism generative adversarial network model using the training set of the image to be repaired specifically includes: Inputting the image to be repaired and the corresponding mask image into the generator G at the same time, and extracting their features at the same time; The generator G extracts the overall features of the original image from the image to be repaired, and generates a repaired image that is as similar to the real image as possible; The discriminator D determines whether the input image data is a real image or a restored image generated by the generator G, and sends the loss result back to the generator G through gradient feedback. The generator G continues to generate an image with a better restoration effect according to the result; After a large number of training iterations, the generator G generates images with better restoration effects.
6. A storage medium having computer instructions stored thereon, Features: When the computer instructions are executed, the steps of the multi-scale image restoration method according to any one of claims 1 to 5 are executed.
7. A terminal comprising a memory and a processor, wherein the memory stores computer instructions executable on the processor, It is characterized in that When the processor runs the computer instructions, the steps of the multi-scale image restoration method described in any one of claims 1 to 5 are performed.
