# Real-Time Facial Emotion Recognition Framework for Employees of Organizations Using Raspberry-Pi
## 3 Proposed Methodology
### Face Encoding  
The next important step is to extract the features from the exactly centered image. The best way to get the unique features of any facial image is to measure the face. The dimensions of each face are different. The main challenge is about which measurement plays a vital role in recognition of captured image. This task can be difficult to achieve if performed with the traditional method of feature extraction. To achieve accuracy and raise the speed, a deep network is trained as machines have been proven to be better than humans when it comes to prediction. Training a deep network requires a lot of computation and power from a system. So, we used a pre-trained network which is provided by OpenFace [20]. Now, we just give the input and the Deep network that measures the 128 measurements for each face instead of single face; the network has been trained on 3 facial images at an instant as shown in Figure 3. This is achieved by training the first image (Image anchor) of person with a second image (positive) of the same person, with a completely different image (Image negative) of another person, as shown in Figure 4. The main purpose is to have the image anchor closer to image positive, as compared to any other image, called image negative. The selection of a triplet to carry out 128 measurements  
Figure 2: (**a**) Face detection using Histogram of Oriented Gradients (HOG) and (**b**) Face is aligned in real time using ensemble of regression trees algorithm.  
is important. Machine learning experts call these measurements of every individual face \"embedding\". Training on face embedding using a large set of images called dataset will improve the accuracy and decrease the error rate eventually. This process requires huge CPU power and lot of time. To understand triplet loss, consider the representation as \(f(y)=I^{s}\) which is representing an image \(y\) into s-dimensional Euclidean space. We oblige this implanting to live on the s-dimensional hypersphere. \(f(y)_{2}=1\). As shown in Figure 2(a), the main aim is to achieve minimum distance between \(y_{j}^{m}\) (Anchor) of a specific person with all the other images \(y_{j}^{p}\)(Positive) of the same person as compared to the image of any other person \(y_{l}^{n}\)(Negative).  
So, we want to have the following:  
\[\|y_{j}^{m}-y_{j}^{p}\|_{2}^{2}+\beta\|y_{j}^{m}-y_{j}^{n}\|_{2}^{2}\forall \left(y_{j}^{m},y_{j}^{n},y_{j}^{p}\right)\in\zeta \tag{1}\]  
where \(\beta\) is the enforced margin between negative and positive pair of images and \(\zeta\) is the set of all the possible triplets and has numbers equal to number \(P\).  
\[\sum_{j}^{p}\left[\|f(y)_{j}^{m}-f(y)_{j}^{p}\|_{2}^{2}-\|f(y_{j}^{m})-f(y_{j} ^{n})\|_{2}^{2}+\beta\right]_{+} \tag{2}\]  
Figure 4: Network training flow for M unique images [Adapted from 5].  
Figure 3: Generation of 128-dimensional data from triplet.  
Generation of multiple triplets will help to overcome the issue faced in Equation (1) and selection of suitable and complex triplets will result in the improvement of the deep learning model.