# Emotion Detection Using Facial Expression Involving Occlusions and Tilt
## 3 Materials and Methods
### Preprocessing Dataset  
In the preprocessing phase, the image is changed into a format that is appropriate for the CNN model. Preprocessing is dived into four main steps: detecting the face, cropping it, flipping it vertically, and making samples of different angles OpenCV [33] is used for preprocessing  
In the first step, the image is converted into grayscale which converts 3-channel RGB image into 1 channel. To detect the face, Viola-Jones [34] is used with a Haar-like feature by using pre-trained cascades of frontal face files provided by OpenCV, which returns the face area. The face area is cropped and re-sized to 32 \(\times\) 32 and is vertically flipped. A copy of it is then made. This step doubles the number of images which are then converted into  
\begin{table}
\begin{tabular}{c c c} \hline \hline
**Detail** & **CK+** & **JAFFE** \\ \hline Subject & 123 & 10 \\ Posed emotions & 8 & 7 \\ Total samples & 9591 & 213 \\ \hline \hline \end{tabular}
\end{table}
Table 2: Number of subjects and number of emotions in each database.  
\begin{table}
\begin{tabular}{c c c c c} \hline \hline
**Emotion** & **Original** & **CK + Removing Duplicates** & **JAFFE** & **Total** \\ \hline Angry & 1280 & 616 & 30 & 646 \\ Disgust & 1446 & 872 & 29 & 901 \\ Fear & 825 & 494 & 32 & 526 \\ Happy & 2187 & 1320 & 31 & 1351 \\ Neutral & 444 & 994 & 30 & 1024 \\ Sad & 1671 & 1080 & 31 & 1111 \\ Surprise & 1730 & 986 & 30 & 1016 \\ Total & 9583 & 6362 & 213 & 6575 \\ \hline \hline \end{tabular}
\end{table}
Table 3: Number of images according to the emotions in CK+ and JAFFE database original and after removing duplicates.  
7 different angles (\(-45\), \(-30\), \(-15\), \(0\), \(15\), \(30\), \(45\)). This helps generate a large amount of image data and provides more samples to train and test. Moreover, it makes the model train at different angles as well. This process is applied in both the training set and the testing set. It makes our model more powerful and precise in detecting emotions from different angles.  
CNN is well-suited for pattern classification problems. CNN is very similar to a neural network, where neurons, activation functions, weights, and learning rates are the same as a neural network. The key difference is in its structural design, as CNN takes images as input. It is specially designed to deal with 2-dimensional data [35; 38]. In every CNN model, it is essential to set some hyperparameters, such as learning rates, regulation function value, filter sizes, size of the feature map, and the number of hidden neurons. All the performance of the CNN is based on these parameters and the arrangement of layers. The computation of this layer is performed by sliding a window called a filter over the original image by one pixel called stride. This process executes pixel-wise multiplication and adds up to form the result of integers, which shape individual components of the resulting matrix. The output is called a feature map, convoluted map, or activation map. The value of feature maps depends on the values of filters, as different filters generate different feature maps. We just have to initialize the parameters before the training. Following are some parameters related to different convolutional layers.  
Hyperparameters are the values that should be set for training. In the current study, batch size, learning rate, weights, biases, hidden neurons, input shape, output values at each layer, etc., are hyperparameters. In this list, some are crucial, such as learning rate and hidden neurons. The batch size used is 'None' because dynamical allocation is preferably desired. For regulation, the dropout function is used only once after the fully connected layer's value is 0.8, and the number of hidden neurons is 1024. The learning rate of the proposed is set to 0.0001 as mentioned in Table 4.