# Camera-Based in-Process Quality Measurement of Hairpin Welding
## 3 Results  
We trained different models of the small SDU-Net architecture for each input data generation approach, _coaxial single_, _coaxial complete_, and _lateral complete_. All models were trained with a batch size of 6, an input of gray-scale images in the size of \(256\times 256\) pixels, and 500 steps per epoch. We used the Adam Optimizer and started the training process with a learning rate of 0.001. The learning rate was reduced by 5% after 3 epochs without any improvement until a learning rate of 0.000005 is reached. The training process was stopped when no further improvement has occurred in 20 consecutive epochs. This results in different long training times for the different models. The loss value and the accuracy of the different models can be seen in Table 1. To verify the results during training, we used validation data sets. These contained 3 images each for _coaxial complete_ and _lateral complete_ and 18 images for _coaxial single_, according to the small database. The validation data sets were also enlarged with strong use of data augmentation. After the training, we  
Figure 3: Gray-scale opening, (**a**) gray-scale image (**b**) process light (**c**) spatter (**d**) overlaid image with spatters colored in red and the process light in green. used a separate test data set, each containing 50 images with the corresponding ground truth image. Because the number of pixels per class is very unbalanced, and especially the less important background class contains the most pixels, we used the loss functions weighted dice coefficient loss (DL) and the categorical focal loss (FL) [25]. The network results are shown in Figure 4 and in Table 2.  
The advantage of focal loss is that no class weights have to be defined. The loss function, which is a dynamically scaled cross entropy (CE) loss, down-weights the contribution of easy examples and focuses on learning hard examples:  
\[FL(p_{t})=-\alpha(1-p_{t})^{\gamma}log(p_{t}) \tag{2}\]  
The two parameters \(\alpha\) and \(\gamma\) have to be defined. The parameter \(\alpha\) represents the balancing factor, while \(\gamma\) is the focusing parameter. The CE loss is multiplied by the factor \((1-p_{t})^{\gamma}\). This means that with the value \(\gamma=2\) and a prediction probability of 0.9, the multiplier would be 0.1\({}^{2}\), i.e., 0.01, making the FL in this case 100 times lower than the comparable CE loss. With a prediction probability of 0.968, the multiplier would be 0.001, making the FL already 1000 times lower. This gives less weight to the easier examples and creates a focus on the misclassified data sets. With \(\gamma=0\) the FL works analogously to the cross entropy. Here the values \(\alpha=0.25\) and \(\gamma=2\) were chosen. For comparison, we used the weighted dice coefficient loss, where the loss value is calculated for each class, weighted with the respective class weighting, and then added up. The class weights were calculated based on the pixel ratio of the respective class in the training images. The classes that contain only a few pixel values, such as the spatter class, must be weighted more heavily so they are considered appropriately during training. Since the values are calculated based on the number of pixels in the training data, these weights vary between the different input data sets. Besides training individual models for each input data approach, we also trained one model for the prediction of all data, the coaxial and lateral view, summed, and single images. Since the different data sets have the same classes and a similar appearance, one model approach is also possible. The advantage of this approach is that a higher variance of data can be covered in one model and therefore we do not need to define new models or parameters for each data type. To train the global model we used 14 images of each _coaxial_ and _lateral complete_ data set and 34 _coaxial single_ images. Another advantage is that additional classes can be added to the model. We have introduced a new class, which includes the cooling process of the welding bead.