# Vectorization of Floor Plans Based on EdgeGAN
## 3 Methods
### EdgeGAN  
EdgeGAN learns a map from the input FPs \(\mathbf{X}\) to the output \(\mathbf{Z}\), and \(\mathbf{Y}\) is the ground truth. The architecture of EdgeGAN is depicted in Figure 4. Two convolution layers, six Resnet blocks, and two deconvolution layers are connected in series with skip connect, which is a typical realization of U-Net [20] that has been used widely [27].  
Two special kernels are defined as  
\[\mathbf{K}_{1}=\left[\begin{array}{ccc}0&0&0\\ 1&1&1\\ 0&0&0\end{array}\right]\text{, and }\mathbf{K}_{2}=\left[\begin{array}{ccc}0&1&0\\ 0&1&0\\ 0&1&0\end{array}\right]\text{.}\]  
The generative loss  
and the discriminative loss function is defined as  
\[l_{D}=\frac{1}{N}\sum_{i=1}^{N}\underbrace{-\log D(\mathbf{X},\mathbf{Z})}_{D\_fake\_loss} \underbrace{-\log[1-D(\mathbf{X},\mathbf{Y})]}_{D\_real\_loss}, \tag{2}\]  
where \(N\) is the batch size and \(F(\mathbf{Y})\) is a filter function defined as  
\[F(\mathbf{Y})=clip(\text{maxpooling2D}(\mathbf{Y},\mathbf{K}_{1})+\text{ maxpooling2D}(\mathbf{Y},\mathbf{K}_{2}),0,1)\]  
In the loss functions, _G_BCE_loss_, _D_fake_loss_, and _D_real_loss_ are all binary cross-entropy (BCE) loss, _G_L1_loss_ and _G_filter_loss_ are L1 loss, and \(\lambda_{1}\) and \(\lambda_{2}\) are the weights for them. Those 3 BCE terms, which constitute the standard GAN loss and are designed for the maximin optimization problem  
\[\min_{G}\max_{D}\Big{\{}E_{\mathbf{Y}\sim P(\mathbf{Y})}[\log D(\mathbf{Y})]+E_{\mathbf{X}\sim P (\mathbf{X})}[\log(1-D(G(\mathbf{X})))]\Big{\}},\]  
guide the generator \(G\) to generate better PFM \(\mathbf{Z}\) and the discriminator to recognize the difference between the distribution of \(\mathbf{Z}\) and that of the ground truth \(\mathbf{Y}\). Additionally, _G_L1_loss_ provides pixel-level supervision information that is suitable for a pix2 pix task. _G_filter_loss_ is a new term that composes a self-supervised loss about \(\mathbf{Y}\). In \(F(\mathbf{Y})\), maxpooling2D\((\mathbf{A},\mathbf{K})\) composes a max-pooling operation with a kernel \(K\) on the input multichannel image \(\mathbf{A}\). With those two special kernels \(\mathbf{K}_{1}\) and \(\mathbf{K}_{2}\), the maxpooling2D can extract the horizontal and vertical lines, respectively, as illustrated in Figure 4(b),c. The horizontal and vertical maps are added then. As those elements of maxpooling2D\((\mathbf{Y},\mathbf{K}_{1})+\text{maxpooling2D}(\mathbf{Y},\mathbf{K}_{2})\) the intersections would be bigger 1, we designed a clip function to truncate it. With the clip function \(clip(A,a,b)\), elements of \(A\) smaller than \(a\) become \(a\), and elements larger than \(b\) become \(b\). The \(clip\) operation makes the filtered PFM still be a probability map. The adding and clipping operations combine those lines to a new PFM, in which many isolate points have been filtered, as illustrated in Figure 4(d).  
Figure 5: The self-supervising filter of EdgeGAN.  
With the self-supervised loss, the generator will learn to generate PFMs of higher quality. As \(K_{1}\) and \(K_{2}\) are designed for horizontal and vertical lines, it is not going to work for irregular walls.  
In each training batch, the generator and discriminator are updated alternatively. \(\lambda_{2}\) is set to 0 in the first several epochs to keep \(G\_11\_loss\) playing a leading role in the initial stage of training. When the PFM can be generated roughly, the self-supervising loss starts to come into play gradually.