# GAN-Based Image Dehazing for Intelligent Weld Shape Classification and Tracing Using Deep Learning
## 2 Methods
### Theoretical Background of YOLO Architecture
#### 2.3.2 YOLOv5 Architecture  
YOLOv5 is an improved deep learning model and is more efficient than YOLOv4 and Scaled YOLOv4. It uses three stages--model backbone, model neck and model head [41]--with a total of 283 layers. The major difference between YOLOv4 and YOLOv5 is that YOLOv5 uses focus layer and PANNet. The focus layer is introduced to reduce the number of layers and reduce its parameters, thereby reducing CUDA memory. This increases the training speed while minimally impacting mean average precision (mAP). The CSPDarkNet53 is used as the backbone layer which extracts the important features from the given input image, improving the processing time. Next, PANNet is used with the neck to generate feature pyramids so that the models have better generalization and scaling ability [42]. It also helps to identify the different sizes and scales for the same object. Finally, the head is same as the YOLOv3 and v4 versions, and is used to perform the detection with vectors of class probabilities, objectness scores, and bounding boxes [43]. The YOLOv5 architecture is shown in Figure 6. The final output of the abovementioned deep learning models is a vector of 13 \(\times\) 13 \(\times\) (5*3 + 8) predictors for each image, which is 13 \(\times\) 13 \(\times\) 23. In this work, the genetic algorithm (GA) is used to find the best parameters for training both YOLOv4 and YOLOv5 and, using these parameters, the model is trained for class and bounding box prediction. The parameters of the GA algorithm used for this work are discussed in Section 4.3. Finally, the performance of the YOLO algorithm is analysed with EfficientDet and Faster RCNN, which is a two-stage detector. The architecture used for comparison was Inceptionv2. The model was trained for 200 epochs with a batch size of 16 and a 416 \(\times\) 416 image size. The learning rate was chosen as 1e-4 with the SGD optimiser. The pretrained model weights based on COCO datasets were used so that the model could be trained with smaller batches of custom datasets. Next, L2 regularisation was used in faster RCNN because it penalises the cost function based on the squared mean of the coefficients so that the model does not overfit. The cost function is the sum of the squared error with the L2 regularisation term and the equation is as follows:  
\[cost=\sum_{i=0}^{n}\left(y_{i}-\sum_{j=0}^{M}x_{ij}w_{j}\right)^{2}+\times \sum_{j=0}^{M}w_{j}^{2} \tag{17}\]  
where \(x_{ij}\) is the input to the network; \(y_{i}\) is the output of the network; and \(w_{j}\) is the weight of the network.  
Additionally, a genetic algorithm with 100 generations, 0.9 mutation probability and a sigma value of 0.2 was implemented to find the optimal training hyperparameters of YOLOv4 and YOLOv5. This further improved the weld shape classification.  
The pseudocode for overall weld seam detection using different YOLO algorithms is given as follows Algorithm 1:  
Figure 6: YOLOv5 architecture for weld seam detection and tracing.  
```
Begin Input: weld images I_ weld, Bounding box coordinates x, y width B\({}_{w}\), height B\({}_{h}\) Output: Class probabilities P\({}_{c}\) and Predicted Bounding box coordinates Data partition: I_ weld = I_train (60%)+I_test (20%)+I_validation (20%) Initialize no of epochs N = 200 batch_size = 16 Resize the image to 416 \(\times\) 416 Generation = 100 Mutation_probability = 0.9 Sigma = 0.2 for i = 1 to generation for j = 1 to batch_size Load pretrained weights w Load yolo configuration files Run GA to obtain best hyperparameter values end for end for Training phase: for i = 1 to N Load optimized weights and biases Load optimized yolo training parameters from GA Perform training on I_train end for save checkpoint weights.ckpt Testingphase: for each videoframe do I_test = capture(videoframe) predict y = fPc, Bw, Bh, Bx, By No of predictions = 13 \(\times\) 13 \(\times\) (5*3 + c) Display class c and Pc end for end
```  
**Algorithm 1** Pseudocode of Weld Seam Detection using YOLO Algorithms