# An Improved GAN-Based Image Restoration Method for Imaging Logging Images
## 4 Training the Improved GAN Model
### Training Model  
Combining real imaging log images from a total of eight horizontal wells in the Daqing and Dagang Oilfields, a dataset of imaging log images with mask regions and corresponding mask binary images was created after data pre-processing. The dataset was divided into a training set (20,000 images), a validation set (2500 images), and a test set (2500 images) according to a ratio of 8:1:1.  
The improved GAN network model for imaging logging image restoration experiments was implemented using a 64-bit Windows 10 operating system, the Python 3.7 programming language, torch 1.9 (cuda11) and torchvision 0.10.0, and a 16G NVIDIA GeForce GTX 1650 Ti graphics card (NVIDIA, Santa Clara, CA, USA) to speed up the training process. The initial learning rate of the repair network was set to 0.0005, the initial learning rate of the discriminative network was set to 0.00001, and the number of training rounds was set to 200 epochs. The training flow of the improved GAN model algorithm is shown in Algorithm 2.  
```
1. set the number of training rounds \(e\), the total amount of training data \(n\) and batc size \(b\)
2. for i = 1 to \(e\) do:
3. for j = 1 to \(n/b\) do:
4.  inputting a single batch of \(b\) defective images and the corresponding mask images into the generative network
5.  training of generative networks:
6.  calculation of content loss \(L_{v}\) and \(L_{h}\), perceptual loss \(L_{prep}\), windage loss \(L_{s}\);
7.  updating the G-weight parameters of the generating network using the four loss functions \(L_{h}\), \(L_{v}\), \(L_{app}\) and \(L_{s}\) training
8.  training discriminative networks
9.  input of the restored \(b\) images and the original images into the discriminatory network;
10.  comparing the restored image with the real image and calculating the adversarial loss \(L_{adv}\);
11.  update the weight parameters of the global discriminant network \(D_{g}\) and the local discriminant network \(D_{l}\) with \(L_{adv}\)
12.  improved overall GAN
13.  joint training of the generative and discriminative networks using the total loss function L
14.  end
15. end
```  
**Algorithm 2** Improved GAN model algorithm training process  
During the training of the model, the generative network is trained to repair the image to fool the discriminator network, and the global and local discriminators are trained to identify whether the input image is repaired by the generative network or is the real one. First, the pre-processing stage generates a defective image and corresponding mask image that matches the real imaging logging image defect; it sets the number of training rounds \(e\), the total training data volume \(n\), and the batch processing volume \(b\); then the model iterates through round \(e\), updating the parameters in each round with \(n/b\) cycles. In each cycle, the training is optimised in three steps. (I) Calculate content loss \(L_{h}\) and \(L_{v}\), perceptual loss \(L_{prep}\), and style loss \(L_{style}\), and use them to update the weight parameters of the generative network through back-propagation training. (II) Fix the parameters of the generative network, obtain the adversarial loss based on the error between the restored image and the original image, and update the weight parameters of the global and local discriminative networks by training with the adversarial loss alone. (III) Train the overall model built in this paper using the total loss function. This is conducted for several iterations of updates until the network stabilises and the final model is obtained.