# Detection of Bad Stapled Nails in Wooden Packages
## 3 Results  
The best model of the training process is selected when the loss is closer to the lowest point and the accuracy is more comparable to its maximum value, based on results shown in Figure 6. Table 1 shows model performances with the elements of the confidence matrix. The confidence matrices show that the model computes better results with the training data than with testing data since it is used to train the model. Considering the ability of the model to classify images of nails, the AlexNet network reports 0 in c\({}_{12}\) and c\({}_{21}\) elements of the confidence matrix with training data. The same model also has the highest statistics of all the networks in classifying nails with testing data. This is because the location of the nail is defined in the image, and classification is more straightforward. If results using CNN are compared with results using traditional computer vision algorithms, the best results are computed using CNN. Similar results of the classifier training and testing process are obtained for the remaining tested models. Usually, between zero to fifteen correct nails are classified as badly stapled, and between zero to twenty badly stapled are classified as valid, depending on the chosen model for the classifier. If traditional computer vision algorithms are used, 50% of the classifications are wrong. These results are expressed as precision and recall in Table 1. Precision is the number of correct classifications divided by the number of all classifications given for correct or badly stapled nails. The recall is the number of correct classifications divided by the number of classifications that should have been returned. Figure 7 shows Table 1 results graphically. Coefficients C\({}_{11}\) and C\({}_{22}\) should be closer to 1 and C\({}_{12}\) and C\({}_{21}\) closer to 0 to obtain a good classification performance. Columns of Figure 7 representing values of these coefficients for the AlexNet model satisfy this criterion. \begin{table}
\begin{tabular}{c c c c c c c} \hline \hline  & **Confidence** & \multicolumn{5}{c}{**SSD**} & \multicolumn{2}{c}{**FASTER-RCNN**} \\ \cline{3-8}  & **Matrix** & **Traditional CV** & **AlexNET** & **MOBILENET** & **RESNET** & **RESNET** & **INCEPITION** \\ \hline Training Data & C\({}_{11}\) & 0.5250 & 1 & 0.9750 & 0.9550 & 0.9450 & 0.9600 \\  & C\({}_{22}\) & 0.5300 & 1 & 0.9800 & 0.9300 & 0.9350 & 0.9400 \\  & C\({}_{12}\) & 0.4750 & 0 & 0.0250 & 0.0450 & 0.0550 & 0.0400 \\  & C\({}_{21}\) & 0.4700 & 0 & 0.0200 & 0.0700 & 0.0650 & 0.0600 \\ Testing Data & C\({}_{11}\) & 0.4500 & 0.9650 & 0.9500 & 0.9050 & 0.9250 & 0.9150 \\  & C\({}_{22}\) & 0.4550 & 0.9850 & 0.9550 & 0.9150 & 0.9200 & 0.9350 \\  & C\({}_{12}\) & 0.5500 & 0.0350 & 0.0500 & 0.0950 & 0.0750 & 0.0850 \\  & C\({}_{21}\) & 0.5450 & 0.0150 & 0.0450 & 0.0850 & 0.0800 & 0.0650 \\ Computing time (ms) & 321 & 923 & 1567 & 1675 & 2212 & 2190 \\ \hline \hline \end{tabular}
\end{table} 
Table 1: The accuracy and computing time of the classification system depend on the classification algorithm. Accuracy is measured with the confidence matrix parameters. AlexNet can classify all nails correctly and faster, but the user needs to define areas in the image where nails are. The column “Traditional CV” represents the results computed with the method described in the traditional computer vision section. From the point of view of the methods that do not need predefined ROIs to classify nails, the SSD MobileNet model obtains better performance with both well and badly stapled nails. Referring to computing time, substantial differences exist. Traditional computer vision algorithms are faster but do not obtain good results. AlexNet is the faster of the CNN models and obtains good performance. However, ROIs, where nails are, must be defined in the image to make the classification proper. If algorithms with no predefined ROIs are compared, they are all over 1 s of computing time, making them unsuitable for an in-line inspection of 60 crates per minute.