## 5 Experimental Setup
### Tensorflow Model Optimization for TensorRT  
The real-time execution of deep learning neural networks on edge devices is a crucial factor for enabling many application areas. However, given the limited memory, computing resources, and power of these devices, it is necessary to optimize these networks for embedded applications. The subsequent stage of this project focused on transforming the embedded model into a format that is compatible with TensorRT. This was achieved by exporting the Tensorflow file with the \".pb\" extension to the \".ONNX\" format, followed by creating an \".engine\" file from this format that could be executed on the Jetson Nano, with the TensorRT framework. For this process, we applied the Python codes in the \"TensorRT\" library [68] on NVIDIA's Github website.  
TensorRT provides support for three types of precision: single precision (FP32), half precision floating point (FP16), and eight-bit signed integer (INT8). The application of INT8 quantization has gained popularity in several machine learning frameworks as it generates a four-fold reduction in data storage requirements, thus reducing the memory  
Figure 16: Comparison: Before vs. after using custom anchor boxes.  
necessary to store all the weights and activations in the neural network. To achieve the eight-bit representation of the floating-point tensor (FP32 or float32) (Formula (7)), a scale factor (Formula (8)) is used, mapping the dynamic range of the tensor to the \([-128;127]\) interval [69].  
\[\mathrm{x_{q}}=\mathrm{Clip}\left(\mathrm{Round}\left(\frac{\mathrm{x_{f}}}{ \mathrm{scale}}\right)\right), \tag{7}\]  
* \(x_{f}\) :Single-precision floating-point (FP32) tensor;
* \(x_{q}\) : INT8 representation of FP32 tensor;
* Round(): A function that rounds rational numbers to integers;
* Clip(): A function that clips outliers that fall outside the \([-128;127]\) interval.  
\[\mathrm{scale}=(2*\mathrm{a_{max}})/256, \tag{8}\]  
\[\mathrm{a_{max}}=\mathrm{max}(\mathrm{abs}(\mathrm{x_{f}})) \tag{9}\]  
To ensure no degradation in performance, the FP32 model is evaluated with a small dataset representative of the task's real input data, and statistics on the interlayer activation distributions are collected. This process is \"calibration\" [69] and the representative dataset used is the \"calibration dataset\".  
In this study, the calibration dataset comprised 320 images captured during the daytime and 272 images captured during the nighttime. To evaluate the model's precision and recall for IoU = 0.5, we utilized the same test dataset as in the previous sections. The results indicated an average precision of 98.45% for daytime images and 100% for nighttime images, and an average recall of 87.59% for daytime images and 90.68% for nighttime images.  
After the optimization process using TensorRT (8.2.1), we observed an improvement in the sensitivity during validation on the test images as compared to the results obtained previously, as demonstrated in Figure 17.  
Figure 17: Comparison: Before vs. after optimization to TensorRT.  
The use of higher-resolution input images significantly mitigated information loss, resulting in enhanced detection capabilities for smaller objects including a distant road sign. The implementation of data augmentation and customized anchor boxes led to improvements in both average precision (AP) and average recall (AR) metrics, surpassing the values obtained with the previous architecture, as illustrated in Figure 18.