## 4 Design and Optimization of the CNN Architecture
### Model Architecture  
The data preprocessing involves the removal of corrupt images and the loading of the data as a data set object using a directory function. This provided a quick way to ingest new data without a custom pipeline. The basic model used in this study adopts a training, testing, and validation split of 6:2. The input image shape is 480 \(\times\) 640 pixels, with three channels following the RGB color chart. At the beginning of the model architecture, there is a Conv2D layer with a set of 32 filters. These filters are 3 \(\times\) 3 in size and a convolution of stride 1, which acts as a feature identifier. Stride indicates how many steps are moved in each step of the convolution. This layer uses the ReLU activation function to introduce non-linearity, which is critical for handling real-world non-linear data. Following the Conv2D layer, a max-pooling operation is implemented for 2D spatial data for non-linear down-sampling, which divides the image into non-overlapping rectangles and outputs the maximum value for each sub-region, reducing the resolution of the feature map to simplify the computation and minimize overfitting. The model uses two more such pairs of layers, containing a series of 64 filters in the Conv2D section. These layers are used to recognize higher-level features, such as shapes or defined objects, via progressive learning and abstraction. A transformation of the pooled feature map is performed via a flattening layer after abstraction. The single column output of the transformation is then transferred to the final fully connected layers. High-level inference on the extracted features is then performed via a subsequent dense layer of 256 neurons using a ReLU activation function. Softmax activation is used by the final dense layer of the basic model to produce a two-class probability distribution indicating the model's prediction of the input image. Figure 11 shows the design of the basic model architecture, which was then used as the basis for further adaptation. As mentioned in Section 4.1, the class imbalance was tackled using the \"Class-Balanced Loss\" by [PERSON] et al. [78]. Based on cross-entropy, this proposed loss function quantifies the performance of a model architecture that outputs the probabilities between two values (0/1). It can be used for both multi-class and binary classification. It shows an increase when the predicted probability deviates from the actual label [81]. If there is an imbalance, the classes are treated in the same way, which can lead to overfitting on the output. The weighted cross-entropy (WCE) used in the proposed method is calculated by applying these weights to the cross-entropy, a widely used loss function in classification problems that does not take into account the probabilistic distribution [82]. The required scalar value of the WCE loss is obtained by calculating the mean of the elements across the tensor's dimensions. A study by [PERSON] [83] identified the learning rate as a critical hyperparameter to be iteratively adjusted in deep neural networks to improve the model performance. The technique of \"cyclic learning rates\" describes a process where one starts with a lower learning rate that increases exponentially with each batch. The final iteration of the model trains an edge detection model using a Sobel filter. The idea was to explicitly detect grooves in the powder bed, i.e., sharp edges. Since defects such as part displacement or particle drag leave ridges in the powder bed, this approach produces a classification. Figure 12 shows the original image of a simulated defect and the image after Sobel filtering. Figure 11: The basic model architecture of the CNN starts with a Conv2D convolutional layer using 32 filters and the ReLu activation function, followed by a MaxPooling2D layer for non-linear down sampling. This is followed by two more such layer pairs and a flattening layer to transform the pooled feature map.