# Customized Convolutional Neural Networks Technology for Machined Product Inspection
## 4 Experimental Results
### Visualizing Convolutional Networks  
Although we know that the usage of CNN is more accurate than the human eye in image recognition, we cannot easily know what the neural network performs during the process of the convolution operation. Heuristically, the characteristics of the picture to be diagnosed by the neural network are like a black box. We only know the input dataset with known training features and the output result without knowing the abstract key features. Therefore, in addition to using the neural network to identify the defects, in this research, Grad-CAM [30] was used to connect the last layer of the neural network to show the neural network identification result with visualization for validating the status of the original OK or NG pictures.  
The approach of Class Activation Mapping (CAM) [31] is very straightforward. For example, in the NG image, each feature map generated by the convolutional layer of the last layer will become a pixel after GAP (Global Average Pooling). Multiply the pixel array after GAP by the weight w; the larger the value of the weight w, the greater the influence of the image represented by the pixel. After the function of Softmax, it can be determined that NG is the maximum value of the classification. By multiplying the pixels of the entire feature map by the weight w and then superimposing them, we can focus on different regions according to the importance of each feature map. The larger the weight w corresponding to the classification, the greater the influence of the feature map; on the contrary, the less important the feature maps with the weight closer to 0. Therefore, if the convolutional neural network model designed in this experiment does not use GAP after  
\begin{table}
\begin{tabular}{c c c} \hline \hline
**Model** & **Customized CNN** & **VGG19** \\ \hline First prediction time (s) & 0.953 & 0.889 \\ Second prediction time (s) & 0.343 & 0.315 \\ Third prediction time (s) & 0.307 & 0.270 \\ Fourth prediction time (s) & 0.246 & 0.202 \\ Fifth prediction time (s) & 0.318 & 0.281 \\ Average time (s) & 0.433 & 0.391 \\ \hline \hline \end{tabular}
\end{table}
Table 5: Prediction times of the Customized CNN and VGG19 models.  
the convolutional layer of the last layer, the architecture of the model must be modified and retrained. For the Grad-CAM used this time, no matter what kind of neural network the model used, after the convolutional layer, the aim of CAM could be implemented without modifying the model. The Grad-CAM-visualized results are shown in Figure 9, where Figure 9(a1-c2) are the three images randomly sampled after the last layer of convolution. For example, Figure 9(a1) is the original feature map, while Figure 9(a2) is the image immediately after inputting Figure 9(a1) into the Grad-CAM software. It can be found that Figure 9(a2) exhibited the obvious defect area from Figure 9(a1) and then marked it in red. All three visualized convolutional neural networks resulted in NG in Figure 9(a1-c1). The color bar indicates the strength of the weighting result via the Grad-CAM. The red part illustrates the characteristic features for the NG metal part with defects and scratches.