## 4 Design and Optimization of the CNN Architecture  
### Data Quality and Interfaces  
A custom Convolutional Neural Network (CNN) designed to identify particle drag is the method of choice for this evaluation. These deep learning networks are specifically designed for image classification and offer a high degree of customization via the layered structure and tuning of hyperparameters. The design is optimized for portability, so it can be used on devices such as standard laptops, workstations, and Raspberry Pi. Seven datasets were generated using the proposed method described in Section 3, containing various types of defects such as part shifting, particle drag, and powder contamination on different manufactured part shapes and also including an additional defect called overheating. Overheating can be caused by the manual cover of the internal pyrometer and leads to uncontrolled fusion of the powder bed surface. Table 2 shows the datasets by characteristics.  
The data was automatically labelled by interfacing with the defect induction mechanism using GPIO pins on the Raspberry Pi and Arduino Mega, which control acquisition and induction, respectively. This allowed a lot of data to be labelled automatically without time-consuming sorting and the viewing of frames. The consolidated dataset was used for training purposes only. Evaluation results are derived exclusively from the test dataset. It was checked both manually and automatically using a custom function that the latter did not contain any duplicates found in the training data, so as not to bias the results. Figure 10 shows the applied interface structure with the communication, the data hierarchy, and the concept for automated labelling by signaling via the mechanical structure for defect generation.  
\begin{table}
\begin{tabular}{c c c c c} \hline \hline
**Dataset** & **Ok Frames** & **Defective Frames** & **Resolution** & **Defect Info** \\ \hline
1 & 16.506 & 4.827 & 480 \(\times\) 640 & Overheating \\
2 & 3.007 & n.a. & 480 \(\times\) 640 & Various defects \\
3 & 22.449 & 2.356 & 480 \(\times\) 640 & Various defects \\
4 & 24.823 & 388 & 960 \(\times\) 1280 & Various defects \\
5 & 40.609 & 1.044 & 960 \(\times\) 1280 & Various defects \\
6 & 79.563 & 3.400 & mixed & Consolidated \\
7 & 3.000 & 3.000 & mixed & Evaluation \\ \hline \hline \end{tabular}
\end{table}
Table 2: Datasets and characteristics.  
Figure 10: The applied interface structure with three main functional blocks to implement real-time defect detection. The Raspberry Pi implementation is responsible for capturing frames from the stream and automatically labelling them using an external signal. An RGB jpg image is then generated as output and sent to the developer PC. The data is then processed on the developer PC and the custom CNN model. The classification result and livestream are then displayed in real time via the web application.  
As can be clearly seen in Table 1, there is a large difference in the amount of data divided into classes. More precisely, this imbalance can lead to classification problems in the field of computer vision [77]. This phenomenon can be avoided via a method proposed by [PERSON] et al. [78], which uses a class-balanced loss by designing a reweighting scheme that uses the effective number of samples for each class to rebalance the loss, resulting in a class-balanced loss. By implementing an imbalance factor, the weights are adjusted based on the class imbalance, whereas a cross-entropy loss function does not address the unbalanced classes. Further steps are described in more detail in Section 4.3.