# CNN-Based Defect Inspection for Injection Molding Using Edge Computing and Industrial IoT Systems
## 4 Experiment and Result Analysis
### Experiment and Results  
In this paper, in order to verify the system, we obtained data from a small and a medium-sized business plant in the Republic of Korea. The company is producing female products, that is, tampons. The tampon applicator is one of the products produced by injection molding. In the current inspection process, the worker manually inspects the product. We used 20% of the training data as validation data during training. We collected data for the introduction of the smart factory, as summarized in Table 4. Before the training process of the model, we used the data augmentation technique. Sample images of the product are shown as Figure 6.  
\begin{table}
\begin{tabular}{c c c} \hline \hline  & **Normal** & **Defect** \\ \hline Training Data & 1714 & 200 \\ Validation Data & 316 & 100 \\ Test Data & 198 & 55 \\ \hline \hline \end{tabular}
\end{table}
Table 4: Dataset of Proposed Model.  
Figure 6: Sample Images of Product: Defect (**left**) and OK (**right**).  
Next, we experimented to optimize the built-in basic model. The first experiment was to increase the training data, the second was to alleviate the data imbalance in the test data, and the final one was to set the optimal threshold. First, we doubled the training data. Currently, we have increased the performance of the model by adding data obtained from the factory we are testing. Then, by adding abnormal data from the test data, the problem of imbalance between normal and abnormal data was solved to some extent. This is summarized in Table 6.  
\begin{table}
\begin{tabular}{c c c} \hline \hline  & **Normal** & **Defect** \\ \hline Training Data & 3428 & 400 \\ Validation Data & 632 & 200 \\ Test Data & 198 & 100 \\ \hline \hline \end{tabular}
\end{table}
Table 6: Dataset of Case Model.  
Figure 8: Confusion Matrix of Proposed Model.  
Figure 9: ROC Curve of Proposed Model.  
Figure 10 shows the results of the learning history of accuracy and loss in the training process. It can be seen that the training proceeds stably. This is thought to be due to the increase in training data. In addition, the model does not become an early stopping, and the validation loss continues to decrease as training progresses, so the training proceeds until the epoch reaches 50.  
Table 7 summarizes the case model's Precision, Recall, and F1-score values. We initially set the threshold to 0.5 in the softmax classification. However, when the threshold was set like this, defect data were judged to be normal in many cases. We found that the optimal threshold was 0.35 through repeated experiments. Figure 11 shows the results of the confusion matrix for the case model. Compared to the existing model, the F1 score increased from 0.9091 to 0.9262, and the prediction of actual defects is much better. The MCC score increased from 0.7311 to 0.8391, and the ROC AUC increased from 0.853 to 0.927, as shown in Figure 12.  
\begin{table}
\begin{tabular}{c c c c} \hline \hline  & **Precision** & **Recall** & **F1-Score** \\ \hline Normal & 0.9632 & 0.9242 & 0.9433 \\ Defect & 0.8611 & 0.9300 & 0.8942 \\ \hline Accuracy & & & 0.9262 \\ Macro Average & 0.9121 & 0.9271 & 0.9188 \\ Weighted Average & 0.9289 & 0.9262 & 0.9268 \\ \hline \hline \end{tabular}
\end{table}
Table 7: Results of Case Model.  
Figure 10: Learning History of Case Model.