## 2 Materials and Methods
### Large Mask Inpainting--LaMa
#### 2.2.2 Loss Function  
Loss functions are a solution to image transformation problems, where the input image is transformed into an output image from a pre-trained base network \(\phi(\cdot)\). LaMa focuses on understanding the global structure of the network layers and using a base network with rapidly growing receptive fields. Thus, the receptive field perceptual loss (_HRF PL_) uses a high receptive field base model \(\phi_{HRF}(\cdot)\) given by Equation (1).  
LaMa focus is shifted toward the understanding of the global structure, and it also uses a base network with rapidly growing receptive fields. This high receptive field perceptual loss (_HRF PL_) operates with a high receptive field base model \(\phi_{HRF}(\cdot)\) given by Equation (1).  
\[\mathcal{L}_{HRFPL}(x,\hat{x})=\mathcal{M}([\phi_{HRF}(x)-\phi_{HRF}(\hat{x})] ^{2}) \tag{1}\]  
where \([\cdot-\cdot]^{2}\) is an operation that uses elements continuously, and \(\mathcal{M}\) is the average sequential operation of two phases (average between layers of the inner layers). Therefore, \(\phi_{HRF}(x)\) is implemented using Fourier.  
Figure 3: The scheme of the method for large-mask inpainting (LaMa).  
In search of as much detail as possible, in order to have a natural effect when reconstructing images using the _Inpainting_\(f_{\theta}(x^{{}^{\prime}})\) model, these networks use adversarial loss, i.e., they not only learn the mapping from an input image to an output image, but also learn a loss function to train this mapping. A discriminator \(D_{\varepsilon}(\cdot)\) operates on local levels of the _patches_ of the images, and determines the _patches_ that are real and false, where the _patches_ considered false are those that have an intersection with a masked area. Due to the supervised perceptual loss of the HRF, the generator rapidly learns to copy the known parts of the input image, which are labeled as \"real\" parts. Thus, the non-saturating adversarial loss is measured by Equations (2)-(4)  
\[\mathcal{L}_{D}=-E_{x}[logD_{\varepsilon}(x)]-E_{x,m}[logD_{\varepsilon}(\hat {x})\odot m]-E_{x,m}[log(1-D_{\varepsilon}(\hat{x}))\odot(1-m)] \tag{2}\]  
\[\mathcal{L}_{G}=-E_{x,m}[logD_{\varepsilon}(\hat{x})] \tag{3}\]  
\[L_{Adv}=sg_{\theta}(\mathcal{L}_{D})+sg_{\varepsilon}(\mathcal{L}_{G})\to min _{\theta,\varepsilon} \tag{4}\]  
where \(x\) is a sample from the dataset, \(m\) is a synthetically generated mask, \(\hat{x}=f_{\theta}(x^{{}^{\prime}})\) is the _inpainting_ consequence for the \(x^{{}^{\prime}}=stack(x\odot m,m)\), \(sg_{var}\) stops the gradients and \(L_{Adv}\) is the joint loss to optimize.  
The LaMa network uses differentiable training models that penalize the degree of infinitesimal change effects in the predictions. For the final loss, \(R_{1}=E_{x}\|\
abla D_{\varepsilon}(x)\|^{2}\) is used as a perceptual loss based on the discriminator; there is a perceptual loss in the characteristics of the discriminating network \(\mathcal{L}_{DiscPL}\), which is known to stabilize the training. The final loss function for the inpainting system is the weighted sum of the losses discussed, given by Equation (5).  
\[\mathcal{L}_{final}=\kappa L_{Adv}+\alpha\mathcal{L}_{HRFPL}+\beta\mathcal{L} _{DiscPL}+\gamma R_{1} \tag{5}\]  
where \(L_{Adv}\) and \(\mathcal{L}_{DiscPL}\) are responsible for generating local details with natural aspects, while \(\mathcal{L}_{DiscPL}\) is responsible for the supervised signal and the consistency of the global structure.