# Head Pose Detection for a Wearable Parrot-Inspired Robot Based on Deep Learning
## 3 Learning Model
### Training and Classification  
The head pose detection was performed in the classification phase. The convolutional neural networks (CNN) are made up of multiple convolutions and a pooling layer followed by one or more fully connected layers. A series of convolution and pooling processes in the hidden layer realizes extraction of translational and rotational invariant features from the input image. The advantage of CNN over other classification methods is its simplicity in training and possession of few parameters to consider while training. We used AlexNet CNN architecture trained on the images from our database for implementing the head pose identification system. The AlexNet method consists of five convolution layers, and two fully connected layers (Figure 7). In between, there are layers that do the max pooling. Table 3 shows the AlexNet architecture. Figure 6: Photographs of the wearer’s head poses, (**a**) Left, (**b**) Left Intermediate, (**c**) Right, (**d**) Right Intermediate, and (**e**) Straight. Figure 7: AlexNet method illustrations. The activation function used was the ReLU (Rectified Linear Unit) for the convolution layers,  
\[f(x)=\max(0;x) \tag{3}\]  
Besides, ReLU we used a softmax function at the fully connected layers before the output. The softmax function normalizes the outputs of each unit in the fully connected unit to range between 0 and 1 such that the sum of output will be unity. \[\sigma(z)_{j}=\frac{z^{ef}}{\sum_{k=1}^{k}e^{zk}} \tag{4}\]  
The network used had five outputs that corresponded to five different classes (head poses). Hence, the output neuron corresponding to the input image will be activated by the softmax function. The neural network architecture mentioned in Table 1 is represented as protocol buffer data. The protocol buffer language-neutral platform enables serialization of structured data in a faster and simple manner. Before training, the databases that consist of head-pose image sets were converted to a lightning memory mapped database (LMDB) format. The neural network was trained in CPU without GPU support. The learning of the network is performed in batch size of 128 using stochastic gradient descent (SGD). We have trained the network for 400 epochs at a learning rate of 0.0001. Figure 8 shows the learning rate vs. each epoch. The loss in the system was calculated by forward pass of the network. The figure shows loss in the training phase during each epoch in training. The mean image generated from the dataset is shown in Figure 9. \begin{table}
\begin{tabular}{c c c c} \hline \hline
**No.** & **Layer** & **Maps and Neurons** & **Kernel** \\ \hline
0 & Input & 3 Maps of 227 \(\times\) 227 & - \\
1 & Convolution & 96 Maps of 55 \(\times\) 55 neurons & \(11\times 11\) \\
2 & Max Pooling & 96 Maps of 27 \(\times\) 27 neurons & \(3\times 3\) \\
3 & Convolution & 256 Maps of 13 \(\times\) 13 neurons & \(5\times 5\) \\
4 & Max Pooling & 256 Maps of 13 \(\times\) 13 neurons & \(3\times 3\) \\
5 & Convolution & 384 Maps of 13 \(\times\) 13 neurons & \(3\times 3\) \\
6 & Convolution & 384 Maps of 13 \(\times\) 13 neurons & \(3\times 3\) \\
7 & Convolution & 256 Maps of 13 \(\times\) 13 neurons & \(3\times 3\) \\
8 & Max Pooling & 256 Maps of 6 \(\times\) 6 neurons & \(3\times 3\) \\
9 & Fully Connected & 4096 neurons & \(1\times 1\) \\
10 & Fully Connected & 4096 neurons & \(1\times 1\) \\ \hline \hline \end{tabular}
\end{table} 
Table 3: AlexNet architecture. Figure 8: Graph representing loss vs. number of epoch during the training of the neural network with a prepared database. The results were analyzed by determining the probability of obtaining the result if performance was simply random. For that purpose, data can be presented as a number of correct responses (i.e., turning the head in the same direction as the human) and number of incorrect responses (i.e., turning the head in the wrong direction). As there are five possible directions, the probability of getting the direction correct is 0.20.