# A Method of Enhancing Silk Digital Printing Color Prediction through Pix2 Pix GAN-Based Approaches
## 2 Materials and Methods
### Deep Learning Method Pix2 Pix GAN  
Pix2 Pix GAN is an image-to-image translation model based on Conditional Generative Adversarial Networks (CGAN), and it can be used for various tasks, including colorization. Compared to other methods, Pix2 Pix GAN has obvious advantages in colorization, generating high-quality color images, capturing more details, and creating more realistic images, better restoring fabric surface style features [18]. Also, because it can handle non-linear relationships, it can learn complex color mappings. In different image-to-image translation models, the Pix2 Pix model is based on CGAN, involving constraints guiding appearance transfer, which includes two modules: Generator G and Discriminator D. The network is based on a conditional generative adversarial network based on a U-Net [19] Generator and a Patch GAN Discriminator. The conditional adversarial loss function of GAN is defined as follows: Suppose x is the input of G (here are the PANTOME color blocks), y is the actual printed silk fabric image, and z is random noise; x and z are input into G to generate image G(x). Then, G(x) and x are merged along the channel dimension as input to D to obtain the predicted probability, which represents whether the input is a pair of real images. The range of predicted probability is 0 to 1, with 0 indicating fake images and 1 indicating real images. When x and y are input into D, the predicted probability is close to or equal to 1. G's training goal is to generate images that cannot be distinguished by adversarial training D, while D is trained to detect the falseness of the generated images as much as possible. For CGAN, the objective function formula of the conditional adversarial loss is as follows, in Equation (4). \[min_{G}max_{D}V(D,G)=E_{x\sim p_{\text{fat}}(x)}[\log D(x)]+E_{z\sim p_{z}(z)}[ \log(1-D(G(z)))] \tag{4}\]  
where:  
\(min_{G}\): Represents the minimization operation for the generator (Generator), aiming to make the generator's output closer to real samples. \(max_{D}\): Represents the maximization operation for the discriminator (Discriminator), aiming to enable the discriminator to accurately distinguish between generated samples and real samples. \(V(D,G)\): Represents the adversarial loss function (Adversarial Loss), indicating the competitive relationship between the generator and the discriminator, where D and G represent the parameters of the discriminator and the generator, respectively. \(E_{x\sim p_{\text{fat}}(x)}[\log D(x)]\): Represents the expectation of the logarithm probability of the discriminator D correctly classifying a sample x drawn from the real sample distribution. \(E_{z\sim p_{z}(z)}[\log(1-D(G(z)))]\): Represents the expectation of the logarithm probability of the discriminator D incorrectly classifying a sample generated by the generator G from a randomly sampled noise vector z from the latent space. Using PyTorch Lightning to build and train the model, two RTX3090 graphics cards were used, and the training time was about one day, with 1000 epochs of training rounds. 1. Defining the loss function: The generator uses a loss function composed of two parts, L1 loss and adversarial loss, while the discriminator uses a loss function composed of two parts, real image loss and generated image loss. 2. Compiling the model: Compile the model based on the defined loss function and optimizer (Adam optimizer is used in this experiment) and set hyperparameters such as learning rate and batch size. 3. Training the model: Use the prepared training dataset for multiple iterations of training, continuously updating the parameters of the generator and discriminator, so that the generator can produce more realistic and conditionally constrained target images. 4. Evaluating the model: Use the prepared testing dataset to evaluate the trained model and evaluate the difference between the generated images and the real images using metrics such as PSNR and SSIM. 5.