# GAN-Based Image Dehazing for Intelligent Weld Shape Classification and Tracing Using Deep Learning
## 2 Methods
### Dehazing Techniques for Weld Fume Removal
#### 2.2.3 Knowledge Adaption Branch Using ImageNet and Res2 Net
\begin{table}
\begin{tabular}{l l l} \hline \hline
**Layer** & **Details** & **Output Size** \\ \hline Input & Weld Images & \(572\times 572\times 3\) \\  & 3 Conv Layers \(3\times 3\times 64\) & \(566\times 566\) \\ Res2 Net\_1 & \(3\times 3\times 128\); \(3\times 3\times 256\) & \(566\times 566\) \\  & 3 Conv Layers \(3\times 3\times 64\) & \(281\times 281\) \\ Res2 Net\_2 & \(3\times 3\times 128\); \(3\times 3\times 256\) & \(134\times 134\) \\ Attention Module\_0 & \(3\times 3\) & \(1024\times 1024\) \\ Pixel Shuffle & Upscale factor = 2 & \(256\times 256\) \\ Attention Module\_1 & \(3\times 3\) & \(256\times 256\) \\ Upsampling\_1 & \(2\times 2\); concat with Res2 Net\_2 & \\ Pixel Shuffle & Upscale factor = 2 & \\ Attention Module\_2 & \(3\times 3\) & \(192\times 192\) \\ Upsampling\_2 & \(2\times 2\); concat with Res2 Net\_1 & \\ Pixel Shuffle & Upscale factor = 2 & \\ Attention Module\_3 & \(3\times 3\) & \(112\times 112\) \\ Upsampling\_3 & \(2\times 2\); concat with Input layer & \\ Pixel Shuffle & Upscale factor = 2 & \\ Attention Module\_4 & \(3\times 3\) & \(44\times 44\) \\ Conv\_1 & \(3\times 3\times 44\) & \(44\times 44\) \\ Conv\_2 & \(3\times 3\times 44\) & \(28\times 28\) \\ \hline \hline \end{tabular}
\end{table} 
Table 3: Knowledge adaption architecture using Res2 Net. During the entire training period, total loss is nothing but the sum of smooth loss, perpetual loss, multi-scale structural similarity index measure (_MS-SSIM_) loss, and adversarial loss. \[L_{total}=L_{smooth}+\alpha L_{MS-SSIM}+\beta L_{perpetual}+\gamma L_{adv} \tag{3}\]  
where \(\alpha\) = 0.2, \(\beta\) = 0.001, and \(\gamma\) = 0.005. The details of loss functions are referenced in [30]. The two most important metrics are used to measure the performance of GAN output (dehazed image), namely, peak signal-to-noise ratio (_PSNR_) and _SSIM_[30]. The equations of _PSNR_ and _SSIM_ are as follows:  
\[PSNR=10\log_{10}\frac{(max_{I})^{2}}{MSE} \tag{4}\]  
\[MSE=\frac{1}{mn}\sum_{i=0}^{m-1}\sum_{j=0}^{n-1}||I(i,j)-K(i,j)||^{2} \tag{5}\]  
The _SSIM_[31] measures image similarity by calculating luminance, contrast, and structure. The luminance function, contrast function, and structure function can be expressed as follows:  
\[l(x,y)=\frac{2\mu_{x}\mu_{y}+c_{1}}{\mu_{x}^{2}+\mu_{y}^{2}+c_{1}} \tag{6}\]  
\[c(x,y)=\frac{2\sigma_{x}\sigma_{y}+c_{2}}{\sigma_{x}^{2}+\sigma_{y}^{2}+c_{2}} \tag{7}\]  
\[s(x,y)=\frac{\sigma_{xy}+c_{3}}{\sigma_{xy}+c_{3}} \tag{8}\]  
Using the above three equations, _SSIM_ is calculated as follows:  
\[SSIM(x,y)=[l(x,y)]^{\alpha}[c(x,y)]^{\beta}[s(x,y)]^{\gamma} \tag{9}\]  
where \(\alpha=\beta=\gamma=1;c1=\left(k_{1}L^{2}\right);c2=\left(k_{2}L^{2}\right);k _{1}=0.01\); and \(k_{2}=0.03\). The GAN network was trained with 674 samples using Tesla P-100 GPU cards with pytorch as a deep learning framework. The Adam optimizer was used with a learning rate of \(1\times 10^{-4}\), and it was trained for 3000 epochs. The GAN performance was compared with the DCP method. The dehazed images were sent to the deep learning model for classification. \begin{table}
\begin{tabular}{l l l} \hline \hline
**Layer** & **Details** & **Output Size** \\ \hline Conv\_4 & \(3\times 3\times 64\); padding = 1 & 128 \(\times\) 128 \\  & Leaky ReLU; stride = 2 & 128 \(\times\) 128 \\ Conv\_5 & \(3\times 3\times 128\); padding = 1 & 256 \(\times\) 256 \\ Conv\_6 & Leaky ReLU & 256 \(\times\) 256 \\ Conv\_7 & \(3\times 3\times 256\); padding = 1 & 512 \(\times\) 512 \\ Conv\_8 & \(3\times 3\times 512\); padding = 1 & 512 \(\times\) 512 \\  & Leaky ReLU; stride = 2 & 512 \(\times\) 512 \\ Conv\_9 & \(1\times 1\times 512\) & 1024 \(\times\) 1024 \\ Conv\_10 & Leaky ReLU & 1\(\times\) 1 \\ \hline \hline \end{tabular}
\end{table} 
Table 4: _Cont._