# CNN-Based Defect Inspection for Injection Molding Using Edge Computing and Industrial IoT Systems
## 3 CNN-Based Defect Inspection for Injection Molding
### Defect Detection  
Deep learning builds up many concealed layers to increase the parameters to increase the model's expressiveness. Training many parameters properly requires a huge number of training data. However, extracting enough data from the actual working conditions is not easy. In addition, data should be diverse enough to maintain high quality and reflect reality. Using deep-learning models that do not have sufficient training data to train parameters usually results in underfitting problems. Therefore, data augmentation [47, 48] allows us to increase the absolute number of data even in small data set regions, thereby applying artificial changes to the data to obtain new data. Data augmentation can handle unexplored inputs and improve the generalization of deep-learning models. An important point about data augmentation is meeting domain knowledge to maintain existing labels when creating new data. It also does not change the data label because of minor changes. Data augmentation is often used in images, but data augmentation is applied to time-series data.  
In this paper, we have used three data augmentation techniques, all of which were based on the fact that a slight change in the action point can keep the label. First, a Resize and Rescaling technique changes the size of the image. Second, we propose a system that can inspect all product sides, not flat-image product inspection. Some frameworks do not provide a function for vertical flips, but a vertical flip is equivalent to rotating an image by 180 degrees and then doing a horizontal flip. Finally, image dimensions may not be preserved after rotation. Rotating the image by finer angles will also change the final image size.  
For the detection of defects on molding products, we propose a novel CNN architecture. The data extracted by means of the vision sensor arrives as input to the inspection model in two dimensions. Image data are processed in grayscale. The architecture of the proposed CNN architecture for defect detection is shown in Figure 3. Data that were rescaled were of size \(300\times 300\). The input data were fed into a layer with three differently sized convolution kernels. The first convolutional layer had a \(7\times 7\) convolutional kernel. The second and third convolutional layers each had a \(3\times 3\) convolutional kernel. The max-pooling layer is behind each convolutional layer and is \(2\times 2\). After passing through the three convolutional layers and the maxpooling layer, data enter the flattened layer. They are then compressed by means of the Dense Layer. To avoid overfitting, we applied the dropout technique and set the dropout rate to 0.2. After that, the architecture would be completed with a softmax layer at the end for defect detection. Table 2 summarizes the architecture of the CNN model used in the paper.  
\begin{table}
\begin{tabular}{c c c} \hline \hline  & **Input** & **Output** \\ \hline Algorithm 1 & Raw image & Cropped image \\ Algorithm 2 & Cropped image & The number of cell that is defect \\ Algorithm 3 & The number of cell that is defect & Time from \(n\)-th cell to discharge \\ \hline \hline \end{tabular}
\end{table}
Table 1: Algorithms performed in Edge Box.  
Figure 3: Proposed Architecture for Defect Detection.