# Automatic Metallic Surface Defect Detection and Recognition with Convolutional Neural Networks
## 5 Experiments
### Experimental Setup  
Dataset Description: The dataset of metallic defect images is provided from a production line of a flat metal component using an industrial microscope. All of the components are inspected by an expert examiner in advance, and labeled with the defective region and its category. In an actual industrial production line, the number of defect images is extremely small. Moreover, a large amount of cost \begin{table}
\begin{tabular}{c c c c c} \hline \hline
**Layers** & **Kernel Size** & **Stride** & **Padding** & **Output Size** \\ \hline Input & - & - & - & 227 \(\times\) 227 \\ \hline Cov1 & \(11\times 11\) & 4 & 0 & 55 \(\times\) 55 \(\times\) 96 \\ Pool1 & \(3\times 3\) & 2 & 0 & 27 \(\times\) 27 \(\times\) 96 \\ Cov2 & \(5\times 5\) & 1 & 0 & 23 \(\times\) 23 \(\times\) 128 \\ Pool2 & \(3\times 3\) & 2 & 0 & 11 \(\times\) 11 \(\times\) 128 \\ Cov3-1 & \(3\times 3\) & 1 & 1 & 11 \(\times\) 11 \(\times\) 256 \\ Cov3-2 & \(3\times 3\) & 1 & 1 & 11 \(\times\) 11 \(\times\) 256 \\ Cov3-3 & \(3\times 3\) & 1 & 1 & 11 \(\times\) 11 \(\times\) 128 \\ Pool3 & \(3\times 3\) & 2 & 0 & 5 \(\times\) 5 \(\times\) 128 \\ FC1 & 1000 & - & - & - \\ FC2 & 256 & - & - & - \\ \hline \hline \end{tabular}
\end{table} 
Table 2: Structural configuration of the compact CNN. Figure 5: The architecture of a compact convolutional neural network (CNN). and manual work is required to acquire and label defect images. Finally, we collected a total of 50 images as the defect dataset, 30 of which were randomly selected as training sets, and the remaining images were used as test sets. For the segmentation task, all of the samples had their own label image. The label image was a binary image that has the same size as the original image. As shown in Figure 3, the gray value of the black pixel in the label image was 0, which represented the defect region, and the gray value of the white pixel was 255, which represented the background. However, the small size of the dataset was not enough to train a deep learning network. In order to train a suitable network, some data augmentation strategies were introduced, mainly including random rotation, translation, zoom, shear, and elastic transformation [43]. The above operations significantly increased the size of training sets, bringing the number of training sets up to 3000. For the classification task, all of the defect images were cropped out of the original images. The classification dataset contained 432 images, which included damage spots, glue marks, dust, and fibers. In the classification task, 70% of these images were used for training and 30% were used for testing. Implementation Details: The inspection experiment system was developed using Python 3.6.2, and its deep learning computing platforms used TensorFlow [44]. The following results were obtained by a server whose CPU was Intel Core i7 and graphic processing unit (GPU) was NVIDIA GTX-1080 ti with 11 GB of video memory. Aiming at training CASAE, the first AE network was trained for 30 epochs with a learning rate of 0.0001. The second network was trained for 20 epochs with the same learning rate. The batch size for both AE networks was 2. For the training of the compact CNN, we initialized the weight of each layer using a Gaussian distribution with a zero mean and a standard deviation of 0.001. The batch size was set to eight for a total of 30,000 iterations. The initial learning rate was set to 0.001. The momentum was 0.9 and the weight decay was 5 \(\times\) 10\({}^{-5}\). In the threshold module, we used 100 as the threshold \(G_{s}\) to refine the defects in our experiment. In order to evaluate the inspection result and enable comparison with other methods, we adopted the intersection-over-union (IoU) and accuracy in order to quantitatively evaluate the performance of the two sub-tasks, respectively. For the segmentation task, IoU was defined as:  
\[IoU(G_{T},P_{M})=\frac{Area(G_{T}\cap P_{M})}{Area(G_{T}\cup P_{M})} \tag{3}\]  
where \(G_{T}\) is the ground truth mask and \(P_{M}\) is the predicted mask.