# Generative Adversarial Network for Overcoming Occlusion in Images: A Survey
## 6 Loss Functions  
In GAN, the generator \(G\) and the discriminator \(D\) play against each other in a two-player mini-max game until they reach Nash equilibrium through a gradient-based optimization method. The gradient of the loss value indicates the learning performance of the network. The loss value is calculated via a loss (objective) function. In fact, defining a loss function is one the fundamental elements of designing GAN. Consequently, numerous objective functions have been proposed to stabilize and regularize GAN. The following losses are the most common ones used in training GAN for amodal completion. 1. **Adversarial Loss**: The loss function used in training GAN is known as an adversarial loss. It measures the distance between the distribution of the generated sample and the real sample. Each of \(G\) and \(D\) have their dedicated loss function which together form the adversarial loss, as shown in Equation (1). However, \(G\) is trained as the term that reflects the distribution of the generated data (\(\mathbb{E}_{z\sim p_{z}(z)}[log(1-D(G(z)))]\)). Extensions to the original loss function are the conditional loss and the Wasserstein loss defined in CGAN and WGAN, respectively. 2. **Content Loss**: In image generation, content loss [138] measures the difference between the content representation of the real and the generated images, to make them more similar in terms of perceptual content. If \(p\) and \(x\) are the original and the generated images, and \(p^{l}\) and \(X^{l}\) are their respective representations in layer \(l\), the content loss is calculated as \[\mathcal{L}_{content}(p,x,l)=\frac{1}{2}\sum_{i,j}(F^{l}_{ij}-P^{l}_{ij})^{2}\] (3)
3. **Reconstruction Loss**: The key idea behind reconstruction loss proposed by [PERSON] et al. [139] is to benefit from the visual features learned by \(D\) from the training data. The extracted features from the real data by \(D\) are fed to \(G\) to regenerate real data. By adding reconstruction loss to the GAN's loss function, \(G\) is encouraged to reconstruct from the features of \(D\), which brings \(G\) closer to the configurations of the real data. The reconstruction loss equation is as follows: \[\mathcal{L}_{X}^{\phi,\theta}=\mathbb{E}_{x\sim p_{x}}[\|G^{\theta}(D_{F}^{ \theta}(X))-X\|_{1}]\] (4) where \(D_{F}^{\theta}\) is a part of the discriminator which encodes the data to features, and \(G^{\theta}\) decodes the features to the training data. 4. **Style Loss**: The style loss, originally designed for image style transfer by [PERSON] et al. [138], is defined to ensure that the style representation of the generated image matches that of the input style image. It depends on the feature correlation between the feature maps, given by the Gram matrix (\(G^{l}\)). Let \(a\) and \(x\) be the original image and the generated image, respectively, and \(A^{l}\) and \(G^{l}\) their corresponding style representation in layer \(l\). The style loss is computed by the element-wise mean square difference between \(A^{l}\) and \(G^{l}\), \[\mathcal{L}_{style}(a,x)=\sum_{l=0}^{L}w_{l}\frac{1}{4N_{l}^{2}M_{l}^{2}}\sum_ {i,j}(G^{l}_{ij}-A^{l}_{ij})^{2}\] (5) where \(w^{l}\) is the weighting factor of each layer, and \(N\) and \(M\) represent the number and the size of the feature maps, respectively. 5. **\(\mathcal{L}_{1}\) and \(\mathcal{L}_{2}\) Loss**: \(\mathcal{L}_{1}\) loss function is the absolute difference between the ground-truth and the generated image. On the other hand, \(\mathcal{L}_{2}\) loss is the squared difference between the actual and the generated data. When used alone, these loss functions lead to blurred results [140]. However, when combined with other loss functions, they can improve the quality of the generated images, especially \(\mathcal{L}_{1}\) loss. The generator is encouraged to not only fool the discriminator but also to be closer to the real data in \(\mathcal{L}_{1}\) or \(\mathcal{L}_{2}\) sense. Although these losses cannot capture high-frequency details, theyaccurately capture low frequencies.