# Detection of Helmet Use in Motorcycle Drivers Using Convolutional Neural Network
## 2 Materials and Methods
### Model Generation and Validation
\begin{table}
\begin{tabular}{c c c} \hline \hline
**Type** & **Patch Size/Stride** & **Input Size** \\ \hline conv & \(3\times 3/2\) & \(299\times 299\times 3\) \\ conv & \(3\times 3/1\) & \(149\times 149\times 32\) \\ conv padded & \(3\times 3/1\) & \(147\times 147\times 32\) \\ pool & \(3\times 3/2\) & \(147\times 147\times 64\) \\ conv & \(3\times 3/1\) & \(73\times 73\times 64\) \\ conv & \(3\times 3/2\) & \(71\times 71\times 80\) \\ conv & \(3\times 3/1\) & \(35\times 35\) 192 \\
3 \(\times\) Inception & Filter concat 1 & \(35\times 35\times 288\) \\
5 \(\times\) Inception & Filter concat 2 & \(17\times 17\times 768\) \\
2 \(\times\) Inception & Filter concat 3 & \(8\times 8\times 1280\) \\ pool & \(8\times 8\) & \(8\times 8\times 1280\) \\ linear & logits & \(1\times 1\times 2048\) \\ softmax & classifier & \(1\times 1\times 1000\) \\ \hline \hline \end{tabular}
\end{table} 
Table 2: Inception V3 architecture. Where filter concat 1 each 5 \(\times\) 5 convolution is replaced by two 3 \(\times\) 3 convolution, filter concat 2 after the factorization of n \(\times\) n convolutions and filter concat 3 expanded the filter bank outputs. Figure 4: High level diagram of Inception V3. As mentioned in the above definition, partial reuse of the network means that for the experiment the last layer will be modified to obtain two possible output results (with helmet and without helmet) through sigmoid Equation (3), where the input is any value between negative infinity and positive infinity number and the output can only have values between zero and one. \[\Phi(z)=\frac{1}{1+e^{-z}} \tag{3}\]  
This last layer will be trained by back propagation algorithm, which can be broken down into four steps: (1) Feed-forward computation, (2) Back propagation to the output layer, (3) Back propagation to the hidden layer, (4) Weight updates [42]. The adjust of weight parameter will use the cross-entropy cost function, where the error between the given output of the last layer and the real value of the given example is calculated. The Formula of cross-entropy loss is shown in the Equation (4),  
\[Crosentropy=-[x\log(y)+(1-x)\log(1-y)] \tag{4}\]  
where \"\(x\)\" is the actual value and \"\(y\)\" is the predicted value. For this experimentation, Tensorflow's Adam optimizer will be used with a learning rate of 0.01. This is an algorithm for first-order gradient-based optimization of stochastic objective functions, which is based on adaptive estimates of lower-order moments, and generally performs well in situations where problems address large amounts of data or parameters [43]. For each training epoch, a batch size of 200 images sufficient to improve model performance was handled. The retraining script will output a \".pb\" file with the new modified classification model, and a \".txt\" file containing the new classes (\"with helmet\" and \"without helmet\"). Both files are in a format that Python can read. This part of the InceptionV3 retraining is based on the work published by Tensorflow [44]. In the test phase a new script will use the re-trained model to generate helmet usage predictions on the set of test images, and five different metrics: accuracy, sensitivity, specificity, Area Under the Curve (AUC) and Precision will measure the performance of the model detecting helmeted and unhelmeted drivers. All this evaluation metrics are based on a table called Confusion matrix, where the rows represents the actual values, and the columns the predicted values [45]. An example of two-class confusion matrix is shown in Figure 6.  
Figure 5: Sketch map of network-based deep transfer learning. TN refers to true negative results, TP to true positive results, FN refers to false negative results, and FP is the abbreviation of false positive results.