## 3 Results
### Transfer Learning  
CNN is a deep learning technique that performs classification by identifying features or patterns. Larger datasets result in easier pattern and feature extraction, as well as high levels of accuracy. The coated bolts used in this study, however, had significantly lower defect data compared to non-defect data. Consequently, to achieve high detection performance from the limited sample data, we also applied a transfer learning algorithm [20]. Transfer learning is a method in which weighted values, previously learned using a specific large dataset, are applied to other target datasets to extract and classify certain features and patterns. As previously learned weighted values are used, the learning time is reduced and prediction accuracy is improved. ImageNet [21] and CIFAR [22] are examples of previously learned image datasets.  
Although datasets related to coated bolt images do not exist, studies using datasets of manufactured goods defect classification [23] and medical devices [24] have reported that ImageNet could be applicable even though it is dissimilar. However, when using previously learned weighted values, similarities have to be considered and adjustments made to different situations to produce an accurate model. Considering that the dataset was small and the similarities with ImageNet were few for the coated bolts used in this study, the convoluted layer was frozen and only the classification layer was learned. For the classification layer, a fully connected layer was used to consider the VGG16 structure. The learning accuracy was 95%, which was lower than that of the previous model, however, the learning time was half that of the previous model.  
Figure 7: Visualization using Grad-CAM (**left**) and improved defect detection using the ROI method (**right**).  
As the data weights used in the current study differed, the accuracy could have been lower than when all the layers are learned. Accordingly, to improve the performance, blocks 1-4 were frozen, and the learning process for the last convoluted layer was conducted with the classification layer for fine tuning (Figure 4). In this instance, the learning rate was set at 0.0001; a stable learning speed was maintained through epoch 50, and the gradient was sufficient to prevent the weighted value from being disrupted. The accuracy of the learning model increased from 1% to 98%, and the performance of the model was evaluated using 132 data images.  
Using the confusion matrix, frequently used as an evaluation index for models, results were inferred and then compared with the actual results to check the accuracy. True positive (_TP_) refers to cases in which the results inferred from the learning model align with the actual non-defective results; true negative (_TN_) refers to cases in which the learning model results align with the actual defective results. When the inferred results differed from the actual results, each case was either denoted false positive (_FP_) or false negative (_FN_). Based on the confusion matrix, Equations (5)-(7) were utilized to obtain the precision, recall, and F1-score [25], where the subscripts NG and OK denote defective and non-defective, respectively. Table 2 shows that an accuracy of 97% was achieved in the performance evaluation test.  
\[Precision_{\text{OK}}=\frac{TP}{TP+FP},\ \ Precision_{\text{NG}}=\frac{FN}{ FN+TN} \tag{5}\]  
\[Recall_{\text{OK}}=\frac{TP}{TP+FN},\ \ Recall_{\text{NG}}=\frac{TN}{FP+TN} \tag{6}\]  
\[F1-score_{\text{OK}}=2\times\frac{Precision_{\text{OK}}\times Recall_{\text{OK}} }{Precision_{\text{OK}}+Recall_{\text{OK}}},\]  
\[F1-score_{\text{NG}}=2\times\frac{Precision_{\text{OK}}\times Recall_{\text{OK }}}{Precision_{\text{OK}}+Recall_{\text{NG}}} \tag{7}\]