# Detection of Defects on Metal Surfaces Based on Deep Learning
## 3 Experimental Results
### Experimental Results  
In this study, Google Colab, and a computer with an Apple M2 processor and 8 GB of RAM were used. In the experiments, a pre-trained MobileNetV2 model was used. Since the goal was to achieve higher accuracy in a shorter time, the number of epochs was set to 30. During the experiments, the images were first converted to grayscale. The grayscale images were then subjected to closing and opening morphological operations in sequence. Figure 3 shows examples of images after the processing steps. \begin{table}
\begin{tabular}{c c} \hline \hline
**Image Processing Technique** & **Accuracy (\%)** \\ \hline GCPOM & 80 \\ MGH & 70 \\ PKO & 68 \\ O & 75 \\ MO & 83 \\ MGO & 85 \\ MGPO & 87 \\ \hline \hline \end{tabular}
\end{table} 
Table 1: Accuracy of Different Image Processing Techniques. \begin{table}
\begin{tabular}{c c c} \hline \hline
**Dataset** & **Data Size (MB)** & **Image Size** \\ \hline G-NEU & 37.8 & 200 \(\times\) 200 \\ MGPO & 26.2 & 200 \(\times\) 200 \\ \hline \hline \end{tabular}
\end{table} 
Table 2: Image and Data Sizes of the Datasets. In order to minimize noise in the resulting images, Gaussian blur was applied. This process helped to remove details that could hinder defect detection in the images. PCA was applied to achieve the objectives of reducing data size, increasing training efficiency, and using resources more effectively. An 80% threshold value was set for this purpose. Otsu thresholding was performed to ensure that defect detection in the images processed with PCA was conducted without relying on background differences and to extract a pattern specific to the defect. This process resulted in the extraction of a pattern for the defect classes and a reduction in data size. Example images resulting from the MGPO process are shown in Figure 4.  
The MobileNetV2 model was trained using both datasets with a total of 30 epochs. In both datasets, 80% of the images were used for training and 20% for testing. The confusion matrix allows us to evaluate the performance of a model across different classes. It provides insight into the relationships between the classes in the model. The matrix includes values for true positives (TP), true negatives (TN), false positives (FP), and false negatives (FN). The confusion matrices for the models are shown in Figure 5.  
A classification that will be considered successful across all classes has been performed. A low number of epochs was used in the model training, and the data sizes of the images were reduced compared to their original state. Figure 4: Images After the MGPO Process. Figure 3: Defective images after morphological operations. The accuracy value indicates the ratio of correctly predicted instances to all predictions. Precision reflects the accuracy of a model's predictions and is calculated as the ratio of true positive predictions to all positive predictions. The recall value shows how many of the actual positives were correctly classified. The F1 score is calculated as the harmonic mean of precision and recall values. The mean Average Precision (mAP) is computed by taking the average accuracy across all classes, representing the overall performance of the model. \[\text{Accuracy}=\frac{TP+TN}{TP+TN+FP+FN} \tag{6}\]  
\[\text{Precision}=\frac{TP}{TP+FP} \tag{7}\]  
\[\text{Recall}=\frac{TP}{TP+FN} \tag{8}\]  
\[\text{F1 Score}=\frac{2\cdot\text{Precision}\cdot\text{Recall}}{\text{ Precision}+\text{Recall}} \tag{9}\]  
Efficiency is calculated as the ratio of model accuracy to power consumption. This allows for the evaluation of the energy efficiency of the trained model. \[\text{Efficiency}=\frac{\text{Model Accuracy (\%)}}{\text{Energy Consumption (kWh)}} \tag{10}\]  
Table 2 shows the efficiencies of the MGPO and G-NEU datasets. It has been observed that the efficiency of the MGPO dataset is nearly the same. In the G-NEU dataset, the separation of defects is not only based on the features of the defects but also influenced by the fact that the defect classes have different backgrounds. Therefore, the accuracy appears higher.