# An Improved GAN-Based Image Restoration Method for Imaging Logging Images
## 4 Training the Improved GAN Model
### Loss Function
Style loss: Style loss is a loss function that measures the similarity in style between two images and is used to guide the learning of image restoration so that the generated content has a detailed local texture [24]. The style loss pass is calculated based on the GramMatrix between the features of the image at different levels in the feature extractor, which measures the difference between the original image and the restored image at different levels of features. An analysis of the feature map shows that the values at each position on the feature map are calculated using the convolution layer for a fixed position on the image, while for the positions in the Gram Matrix, the values are obtained by inner-producing the two feature maps. The Gram Matrix therefore provides a good representation of the style of the image by showing the correlation between two features, such as which two features appear at the same time and which two features are swapped. Assuming that the size of the Fi feature map is \(H^{i}\times W^{i}\times C^{i}\), the style loss can be defined as the following equation. \[L_{s}=\frac{1}{N}{\sum_{i=1}^{N}}\frac{1}{C_{i}\times C_{i}}\times\left\|F^{i }(I^{t})(F^{i}(I^{t}))^{T}-F^{i}(I^{g})(F^{i}(I^{g}))^{T}\right\|^{2} \tag{15}\]  
Adversarial loss: Adversarial loss has been widely used in image generation and low-level vision to improve the visual quality of generated images. Therefore, in order to better learn the data distribution of real images, the parameters of the generative and discriminative networks are continuously iteratively updated through adversarial training between the generative network and the global and local discriminative networks to improve the visual performance of the restored images. The adversarial loss in this paper sets the adversarial loss \(L_{global}\) for the global discriminant network and \(L_{local}\) for the local discriminant network, and weighs the bias of the two using a constant factor. The calculation formula is shown below:  
\[L_{adv}=\frac{1}{2}(0.7L_{global}+0.3L_{local}) \tag{16}\]  
where the global adversarial loss \(L_{global}\) and the local adversarial loss \(L_{local}\) are calculated as shown below. \[L_{global}=\min_{G}\max_{D}E_{H^{t}}\left[\log D_{g}\big{(}I^{t}\big{)} \right]+E_{IS}\left|1-\log D_{g}\Big{(}G\Big{(}I^{in},M_{in}\Big{)}\Big{)}\right| \tag{17}\]  
\[L_{local}=\min_{G}\max_{D}E_{H^{t}}\left[\log D_{in}\big{(}I^{t}\odot M_{in} \big{)}\right]+E_{IS}\left|1-\log D_{m}\Big{(}G\Big{(}I^{in},M_{in}\Big{)} \odot M_{in}\Big{)}\right| \tag{18}\]  
In the above equation, the image to be repaired is represented by the \(I^{in}\), the \(D_{g}\) represents the complete image input into the global discriminative network, and the \(D_{m}\) represents the image with missing regions input into the local discriminative network. Total loss: Based on the above loss function, the total loss function of the model can be expressed by the following equation. \[L=\lambda_{1}L_{v}+\lambda_{2}L_{h}+\lambda_{3}L_{prec}+\lambda_{4}L_{s}+ \lambda_{5}L_{adv} \tag{19}\]  
In the above equation, the parameters \(\lambda_{1}\), \(\lambda_{2}\), \(\lambda_{3}\), \(\lambda_{4}\), and \(\lambda_{5}\) are not fixed values and need to be determined based on experimental tests. This paper sets them empirically as follows: \(\lambda_{1}\) = 1.0, \(\lambda_{2}\) = 3.0, \(\lambda_{3}\) = 0.02, \(\lambda_{4}\) = 120, and \(\lambda_{5}\) = 0.1. In this paper, we design a model of an imaging logging image restoration algorithm based on improved GAN and introduce different types of loss functions to guide the model training. Among them, \(\lambda_{4}\) = 120 is the weight used for style loss, while other loss functions (e.g., content loss, perceptual loss, and adversarial loss) are set with relatively small weights. Such a setting is the result of several experimental validations and aims to better balance the impact of different loss functions in model training. The larger weight of \(\lambda_{4}\) = 120 is set out to emphasise the importance of the style loss.