# Balanced Loss Function for Accurate Surface Defect Segmentation
## 4 Conclusions  
In this paper, we investigate and address the loss imbalance problem, which is one of the central problems with surface defect segmentation. We propose a balanced loss function which unifies three techniques, dynamical class weighting, truncated cross-entropy loss and label confusion suppression, to tackle the loss imbalance caused by imbalanced labels, easy-hard examples, and boundary points, respectively. In comparison with other counterpart loss functions, our experiment result shows the advantage of the balanced loss on the surface defect segmentation mean IoU, which surpasses other baselines by 5% to 30%.  
However, the loss imbalance problem is inherent with DCNN segmentation models with pixel-wise dense predictions. The balanced loss function is only a domain-specific mitigation technique in surface defect segmentation. A generic solution to the loss imbalance problem will need further research in other semantic segmentation tasks, especially other causes of the loss imbalance problem, as well as improvements on the modeling paradigm  
\begin{table}
\begin{tabular}{c c c c c} \hline \hline \multirow{2}{*}{**Truncated CE \(\Delta\epsilon\)**} & \multicolumn{4}{c}{\(\beta\) **Class Weighting**} \\ \cline{2-5}  & **0.0** & **0.9** & **0.99** & **0.999** \\ \hline
0.1 & 0.63 & 0.72 & 0.80 & 0.76 \\
0.2 & 0.70 & 0.78 & 0.82 & 0.79 \\
0.3 & 0.68 & 0.75 & 0.81 & 0.76 \\
0.4 & 0.68 & 0.73 & 0.79 & 0.75 \\
0.5 & 0.65 & 0.65 & 0.70 & 0.68 \\ \hline \hline \end{tabular}
\end{table}
Table 6: Mean IoU of U-Net trained on aluminum alloy surface defect dataset with varying truncated cross-entropy loss thresholds \(\Delta\epsilon\) and class weighting factor \(\beta\).  
\begin{table}
\begin{tabular}{c c c c c c} \hline \hline
**Method** & **Spot** & **Pit** & **Product** & **Denudation** & **mIOU** \\ \hline CE & 0.45 & 0.41 & 0.71 & 0.88 & 0.61 \\ WCE & 0.43 & 0.46 & 0.73 & 0.87 & 0.64 \\ Focal (\(\beta=2\)) & 0.57 & 0.62 & 0.72 & 0.90 & 0.70 \\ Focal (\(\beta=4\)) & 0.53 & 0.59 & 0.70 & 0.90 & 0.68 \\ Dice & 0.57 & 0.62 & 0.80 & 0.89 & 0.72 \\ \hline Balanced (ours) & 0.69 & 0.80 & 0.87 & 0.91 & 0.82 \\ \hline \hline \end{tabular}
\end{table}
Table 5: Class-wise IoU and mIoU of U-Net trained on aluminum alloy surface defect dataset with different loss functions.  
and the optimization algorithm. A possible way to improve the loss function is to unify the merits of the balanced loss and region-based loss, such as Dice loss and Lovasz loss.  
Data curation, C.S.; methodology, Z.X., C.S., Y.F., J.Z. and D.C.; software, Z.X. and D.C.; validation, Z.X. and C.S.; writing, Z.X., C.S., Y.F., J.Z. and D.C. All authors have read and agreed to the published version of the manuscript.  
This research was funded by Southwest Technology and Engineering Research Institute Cooperation Grant (HDHDW5902010301) and the National Natural Science Foundation of China (61673085).  
Not applicable.  
Data Availability Statement:Dataset KolektorSDD2 is openly available in publication Mixed supervision for surface-defect detection: from weakly to fully supervised learning at [[https://doi.org/10.1016/j.compind.2021.103459](https://doi.org/10.1016/j.compind.2021.103459)]([https://doi.org/10.1016/j.compind.2021.103459](https://doi.org/10.1016/j.compind.2021.103459)), reference number [17]. Publicly available dataset Severstal can be found here: [[https://www.kaggle.com/c/severstal-steel-defect-detection](https://www.kaggle.com/c/severstal-steel-defect-detection)]([https://www.kaggle.com/c/severstal-steel-defect-detection](https://www.kaggle.com/c/severstal-steel-defect-detection)), accessed on 1 October 2022. The dataset Aluminum Alloy Surface Defect in this study is available on request from the corresponding author. The data are not publicly available due to privacy.  
The authors declare no conflict of interest.