# Product Image Generation Method Based on Morphological Optimization and Image Style Transfer
## 4 IST Model Based on GAN
### Building a Style Transfer Product Image Generation Model
#### 4.2.3 Loss Function  
Optimizing the loss function to enhance the authenticity of the discriminator results in a more realistic appearance of the generated car front face. In the context of synthesizing  
Figure 4: Structure of the CSC module. (1*1-Conv denotes a convolutional layer with kernel size \(1\times 1\).).  
Figure 5: Discriminator structure.  
car front faces, achieving maximum consistency between the generated faces and real car front faces is highly desirable. The loss function, also known as the Mean Absolute Error (MAE), measures the total sum of absolute differences between the target values and the estimated values. Furthermore, the loss function can also be designated as the Mean Square Error (MSE), which computes the sum of squared differences between the target values and the estimated values. According to the literature, utilizing loss functions instead of directly optimizing the GAN can mitigate the occurrence of blurry generated images. To ensure fidelity to the contour image, previous studies have employed \(L_{1}\) loss to reduce blurriness in the generated results and have introduced perceptual loss and style loss. Consequently, this research adopts \(L_{1}\) loss to calculate the image reconstruction loss between the generated car front face \(Y_{2}\) and the real car front face \(Y_{1}\):  
\[L_{c}=\left\|Y_{1}-Y_{2}\right\|_{1} \tag{15}\]  
In the equation, \(\|\cdot\|_{1}\) represent the \(L_{1}\) losses.  
We introduce the concepts of perceptual loss and style loss by leveraging the pre-trained VGG16 network to compute the activation feature maps for both the generated and real car front faces. Subsequently, we calculate the \(L_{1}\) distance between these feature maps. The representation of the perceptual loss is as follows:  
\[L_{\text{GZ}}=\sum_{i}\left\|\varphi_{i}(Y_{1})-\varphi_{i}(Y_{2})\right\|_{1} \tag{16}\]  
In the provided expression, the term \(\varphi_{i}\) signifies the feature map of the \(i\)-th layer within the pre-trained VGG16 model. By optimizing the perceptual loss function, the generated images of car fronts can maintain consistency with real car front images in the feature space. Furthermore, the style loss aids in generating car front images that align with real car front images in terms of color, texture, and other stylistic features. Specifically, the style loss computes the statistical discrepancy between the activation feature maps.  
\[L_{\text{FG}}=\sum_{i}\left\|\hat{C}_{j}^{\varphi}(Y_{1})-G_{j}^{\varphi}(Y_{ 2})\right\|_{1} \tag{17}\]  
In the formulation, \(G_{j}^{\varphi}\) is the basis for constructing the Gram matrix, utilizing the activation map \(\varphi_{j}\).  
To maintain consistency between the generated image and the contour map, an edge loss is incorporated to minimize the discrepancy in contour information between the generated car front-face image and the authentic real-world car front-face image.  
\[L_{BY}=\left\|HED(Y_{1})-HED(Y_{2})\right\|_{1} \tag{18}\]  
In the formulation, \(HED(.)\) represents the trained contour map extraction network.  
\[L=L_{ZS}+\lambda_{1}L_{\text{C}}+\lambda_{2}L_{\text{GZ}}+\lambda_{3}L_{\text {FG}}+\lambda_{4}L_{\text{BY}} \tag{19}\]  
In the given equation, \(\lambda_{1}\), \(\lambda_{2}\), \(\lambda_{3}\), and \(\lambda_{4}\) denote the respective weights assigned to the various losses.