## 4 Predicting the Porosity in Selective Laser Melting Parts
### Predicting the Porosity Using RCNN and BA-RCNN
#### 4.2.1 RCNN and BA-RCNN Architecture  
The CNN architecture for predicting the percent of porosity is composed of 22 layers with one input layer, five convolutional layers, five rectified linear unit layers, five batch normalization layers, four average pooling layers, one fully connected layer, and one regression layer. The input layer is represented by a matrix with height by width size (650 \(\times\) 630). It contains pixel brightness values between 0 for black regions to 255 for white regions. The convolutional layers contain filters represented by weight matrix slide along the pixel brightness matrix using a special dot product to create a feature map matrix [30]. The rectified linear unit layer comes after each convolutional layer to increase the effectiveness and speed of the training by maintaining positive values and mapping negative values to zero [31]. In addition, the batch normalization layer comes after each convolutional layer as a supplement layer mitigating the overfitting risk [32]. Pooling layers are used between the convolutional layers for output dimensionality reduction [33] without losing the important image features, which helps in minimizing the computational time. Regression and fully connected layers are the output layers that show the predicted percentage of pores. The normal number of convolutional layers to start is between two to three layers with a filter size of 3 \(\times\) 3 or 5 \(\times\) 5 as advised in [31], CNN was designed with five convolutional layers with four average pooling layers in between, with the number of filters ranging between 8 for the first layer and 128 for the last one. Each layer has twice the number of filters of the previous layer [34]. The filter size is 5 \(\times\) 5, the section depth is 3, and the padding that detects the image edges is set as'same', so the padding size is automatically calculated at the training time, producing output size equivalent to input size when the stride (number of pixel shift) is one. The pooling type is 'average' which takes the average presence of the feature, while the max pooling layer takes the most activated feature, so the average pooling is used with light background and max pooling is better with dark background [35], the default size of pooling layer is 2 \(\times\) 2 [30], but it yielded high computational cost since the image input size is big (650 \(\times\) 630). The size was changed to 4 \(\times\) 4 with a stride value of 4 to minimize the training time. CNN was trained using SGDM, which is the most common training algorithm [32]. The default values for this algorithm are an initial learning rate of 0.01, a momentum of 0.9, a regularization of 1 \(\times\) 10\({}^{-4}\), and the maximum number of epochs is 20, as presented in [36]. After applying some experiments and monitoring the validation accuracy, the momentum was changed to 0.8, and with regularization became 1 \(\times\) 10\({}^{-10}\). The RCNN algorithm will train the artificial porosity images of the SLM part to predict the percent of porosity without the need for subjective difficult threshold determination to convert the single slice to a binary image, as mentioned in [21]. The hybrid algorithm (BA-RCNN) uses BA to optimize the parameter values for section depth that controls the network depth, the initial learning rate that is used for features learning, the momentum that performs the hyperparameters update and regularization that prevents overfitting [37] to reach the minimum prediction error on the validation set. The BA consists of global and local searches. The global search is done by the scout bees that evaluate random positions based on the fitness value. In the local search, the best sites are selected, and the remaining sites are abandoned. The intense search is done to select the elite sites, which are the best among the best sites selected in the local search.