# Balanced Loss Function for Accurate Surface Defect Segmentation
## 3 Experiments  
### Experiment Settings  
Our experiments are performed on KolektorSDD2 [17], Severstad [18] and an original aluminum alloy surface defect dataset. KolektorSDD2 consists of 7094 images collected and annotated by the Kolektor Group on different items from a visual inspection system. The main challenge with KolektorSDD2 is that the defect is tiny and rare. The images are of size \(230\times 630\) pixels, but on average, the defect only contains 2.697% of all pixels. With a 1:9 positive/negative example ratio, the label imbalance problem is also challenging in KolektorSDD2. Several is a steel sheet defect dataset released by the Severstad company. It is made of 12,538 training images and 5476 test images with four defect types and \(1600\times 256\) resolution. Because the annotations for the test images are not officially released, we randomly split the training set into a 8727-image new training set and a 3811-image new test set, following the official splitting ratio. Defects are salient on the images, covering approximately 50% of the area on average, but the label imbalance between defect classes is large (see Table 2). We collect 830 high-resolution images of aluminum alloy surface for benchmarking segmentation models. The images are acquired from the laboratory where aluminum alloy samples are processed in different environmental conditions to observe and analyze the corrosion on an aluminum alloy surface. The alloy sample RGB images are captured by a normal digital camera indoors on a blue background surface. The environment light is controlled by hand to avoid over-illumination. The samples are cropped from the image to leave out the blue background (but unavoidably, some images contain small background regions at the corner). The surface defects are labeled by proficient material chemistry researchers using an image annotation software to fill the regions with surface defects. Four types of defect are annotated, including corrosion spot, corrosion product, corrosion pit and chemical denudation (see examples in Figure 6). The statistics about the defect labels are in Table 2.  
Figure 5: A flowchart of the balanced loss for segmentation that combines dynamical class weighting, truncated cross-entropy loss, and label confusion suppression. For the training of segmentation models, the images are further processed (cropping and resizing) as regularly sized \(512\times 512\) images. We split the dataset into a 600-image training set and a 230-image test set. Pixel-level and image-level label imbalance both exist in this dataset. The segmentation accuracy of models is evaluated by intersection-over-union (IoU). The image-wise class-specific IoU is computed for each defect type. The final class-specific IoU is the mean of image-wise class-specific IoU. We also report mean IoU (mIoU), which is the mean of all class-specific IoUs, as the overall metric of segmentation accuracy. To verify that the balanced loss is effective for any segmentation models, we perform experiments on several popular segmentation networks: fully convolutional network (FCN) [22], U-Net [23], SegNet [24], DeepLabV3 [25] and pyramid scene parsing network (PSPNet) [26]. The selected models are representatives of different segmentation model architectures that are widely employed for surface defect segmentation. FCN and PSPNet are fully convolutional architectures that use an upsampling layer to increase feature map resolution. SegNet and U-Net are typical encoder-decoder architectures that have multiple upsampling or deconvolution layers. DeepLabV3 features an atrous spatial pyramid pooling module that extracts feature pyramids by dilated convolutional. For FCN and SegNet, the VGG16 backbone [27] is employed as encoders; for DeepLabV3 and PSPNet, the backbone is ResNet-50 [28]; U-Net has the original eight-convolution encoder/decoder design, with deconvolutional layers for up-sampling.