# AI- and Deep Learning-Powered Driver Drowsiness Detection Method Using Facial Analysis
## 3 Proposed Methodology
### Model Equation of CNN and VGG16
#### 3.6.3 Fully Connected (Dense) Layers  
Equation (7) describes a fundamental calculation in neural networks, where the output of a neuron or node is established by adding a bias factor to the weighted sum of its inputs, followed by an activation function. This formula defines the processing of inputs by a neuron in a neural network, accounting for weights, bias, and the selected activation function.  
\[\text{Output}=\text{Activation}\left(\sum_{i=1}^{N}(\text{Weight}_{i}\times \text{Input}_{i})+\text{Bias}\right) \tag{7}\]  
Here, \"Output\" is the neuron's final product, or output. \"Activation\" refers to a function that contributes nonlinearity to the model, often a nonlinear function like the sigmoid or ReLU.  
Weight\({}_{i}\): This represents the weight associated with each input (Input\({}_{i}\)). When calculating the weighted sum, these weights indicate the relative relevance of each input.  
Input\({}_{i}\): The inputs in the neuron are represented by Input\({}_{i}\). These could be characteristics from the incoming data or values from preceding neurons in the network.  
Bias: A bias term is applied to the weighted total. It aids in changing the neuron's output.  
In the architecture of the CNN model, a sequential framework was built with numerous layers of convolution, max. pooling, a flattening layer, dropout functionality, and two dense layers. The architecture of the layers of the CNN model is presented in Figure 7. The first layer of convolution used ReLU as the activation function and comprised a total of 256 filters of the size \(3\times 3\) with a stride of 1. The pool size of the first max. pooling layer was \(2\times 2\). The subsequent convolutional layer had 128 three-by-three filters with ReLU activation. The pool size of the second max. pooling layer was equivalently \(2\times 2\). The third layer of convolution had \(64\,3\times 3\) filters with a ReLU activation function. The pool size of the third max. pooling layer was identically \(2\times 2\). The fourth convolutional layer had \(128\,3\times 3\) filters with the same activation function as ReLU. The max. pooling layer's number of filters was \(2\times 2\). The flattening layer transformed 3D feature maps into 1D feature vectors. To prevent overfitting, the dropout layer was used. The first dense layer had 64 neurons with ReLU activation functions, whereas the second dense layer contained four neurons with softmax activation functions [26; 27; 28; 29].  
The CNN model underwent training using the training and validation datasets for a total of 20 epochs. Categorical cross-entropy was implemented as the loss function, while the Adam optimizer was deployed. The results of the 20 epochs of training and validation showed a steady improvement in performance over the epochs, with an increasing accuracy and a decreasing loss. The CNN model achieved an accuracy of 95.80% for training and 96% with the validation set. Figure 8 shows the plot of loss vs. epochs for the validation  
Figure 7: The layered architecture of the CNN Model.  
and training dataset for the CNN model. Figure 9 shows the plot of accuracy vs. epochs for the validation and training dataset for the CNN model.  
The number of times a deep learning model will encounter the full training dataset during training depends on the number of epochs in the model. Up to a certain point, increasing the number of epochs can increase the model's accuracy. Consequently, determining the ideal number of epochs was essential for the model to operate at its best. To perform this, we kept track of the validation accuracy while training and then chose the number of epochs that produced the maximum validation accuracy without overfitting the model.  
Figure 8: Accuracy vs. epochs of CNN model.  
Figure 9: Loss vs. epochs of CNN Model.