# tkDNN tkDNN is a Deep Neural Network library built with cuDNN and tensorRT primitives, specifically thought to work on NVIDIA Jetson Boards. It has been tested on TK1(branch cudnn2), TX1, TX2, AGX Xavier, Nano and several discrete GPUs. The main goal of this project is to exploit NVIDIA boards as much as possible to obtain the best inference performance. It does not allow training. If you use tkDNN in your research, please cite one of the following papers. For use in commercial solutions, write at gattifrancesco@hotmail.it and micaela.verucchi@unimore.it or refer to https://hipert.unimore.it/ . ``` Accepted paper @ IRC 2020, will soon be published. M. Verucchi, L. Bartoli, F. Bagni, F. Gatti, P. Burgio and M. Bertogna, "Real-Time clustering and LiDAR-camera fusion on embedded platforms for self-driving cars", in proceedings in IEEE Robotic Computing (2020) Accepted paper @ ETFA 2020, will soon be published. M. Verucchi, G. Brilli, D. Sapienza, M. Verasani, M. Arena, F. Gatti, A. Capotondi, R. Cavicchioli, M. Bertogna, M. Solieri "A Systematic Assessment of Embedded Neural Networks for Object Detection", in IEEE International Conference on Emerging Technologies and Factory Automation (2020) ``` ## Results Inference FPS of yolov4 with tkDNN, average of 1200 images with the same dimesion as the input size, on * RTX 2080Ti (CUDA 10.2, TensorRT 7.0.0, Cudnn 7.6.5); * Xavier AGX, Jetpack 4.3 (CUDA 10.0, CUDNN 7.6.3, tensorrt 6.0.1 ); * Tx2, Jetpack 4.2 (CUDA 10.0, CUDNN 7.3.1, tensorrt 5.0.6 ); * Jetson Nano, Jetpack 4.4 (CUDA 10.2, CUDNN 8.0.0, tensorrt 7.1.0 ). | Platform | Network | FP32, B=1 | FP32, B=4 | FP16, B=1 | FP16, B=4 | INT8, B=1 | INT8, B=4 | | :------: | :-----: | :-----: | :-----: | :-----: | :-----: | :-----: | :-----: | | RTX 2080Ti | yolo4 320 | 118,59 |237,31 | 207,81 | 443,32 | 262,37 | 530,93 | | RTX 2080Ti | yolo4 416 | 104,81 |162,86 | 169,06 | 293,78 | 206,93 | 353,26 | | RTX 2080Ti | yolo4 512 | 92,98 |132,43 | 140,36 | 215,17 | 165,35 | 254,96 | | RTX 2080Ti | yolo4 608 | 63,77 |81,53 | 111,39 | 152,89 | 127,79 | 184,72 | | AGX Xavier | yolo4 320 | 26,78 |32,05 | 57,14 | 79,05 | 73,15 | 97,56 | | AGX Xavier | yolo4 416 | 19,96 |21,52 | 41,01 | 49,00 | 50,81 | 60,61 | | AGX Xavier | yolo4 512 | 16,58 |16,98 | 31,12 | 33,84 | 37,82 | 41,28 | | AGX Xavier | yolo4 608 | 9,45 |10,13 | 21,92 | 23,36 | 27,05 | 28,93 | | Tx2 | yolo4 320 | 11,18 | 12,07 | 15,32 | 16,31 | - | - | | Tx2 | yolo4 416 | 7,30 | 7,58 | 9,45 | 9,90 | - | - | | Tx2 | yolo4 512 | 5,96 | 5,95 | 7,22 | 7,23 | - | - | | Tx2 | yolo4 608 | 3,63 | 3,65 | 4,67 | 4,70 | - | - | | Nano | yolo4 320 | 4,23 | 4,55 | 6,14 | 6,53 | - | - | | Nano | yolo4 416 | 2,88 | 3,00 | 3,90 | 4,04 | - | - | | Nano | yolo4 512 | 2,32 | 2,34 | 3,02 | 3,04 | - | - | | Nano | yolo4 608 | 1,40 | 1,41 | 1,92 | 1,93 | - | - | ## Index - [tkDNN](#tkdnn) - [Index](#index) - [Dependencies](#dependencies) - [About OpenCV](#about-opencv) - [How to compile this repo](#how-to-compile-this-repo) - [Workflow](#workflow) - [How to export weights](#how-to-export-weights) - [1)Export weights from darknet](#1export-weights-from-darknet) - [2)Export weights for DLA34 and ResNet101](#2export-weights-for-dla34-and-resnet101) - [3)Export weights for CenterNet](#3export-weights-for-centernet) - [4)Export weights for MobileNetSSD](#4export-weights-for-mobilenetssd) - [Run the demo](#run-the-demo) - [FP16 inference](#fp16-inference) - [INT8 inference](#int8-inference) - [mAP demo](#map-demo) - [Existing tests and supported networks](#existing-tests-and-supported-networks) - [References](#references) ## Dependencies This branch works on every NVIDIA GPU that supports the dependencies: * CUDA 10.0 * CUDNN 7.603 * TENSORRT 6.01 * OPENCV 3.4 * yaml-cpp 0.5.2 (sudo apt install libyaml-cpp-dev) ## About OpenCV To compile and install OpenCV4 with contrib us the script ```install_OpenCV4.sh```. It will download and compile OpenCV in Download folder. ``` bash scripts/install_OpenCV4.sh ``` When using openCV not compiled with contrib, comment the definition of OPENCV_CUDACONTRIBCONTRIB in include/tkDNN/DetectionNN.h. When commented, the preprocessing of the networks is computed on the CPU, otherwise on the GPU. In the latter case some milliseconds are saved in the end-to-end latency. ## How to compile this repo Build with cmake. If using Ubuntu 18.04 a new version of cmake is needed (3.15 or above). ``` git clone https://github.com/ceccocats/tkDNN cd tkDNN mkdir build cd build cmake .. make ``` ## Workflow Steps needed to do inference on tkDNN with a custom neural network. * Build and train a NN model with your favorite framework. * Export weights and bias for each layer and save them in a binary file (one for layer). * Export outputs for each layer and save them in a binary file (one for layer). * Create a new test and define the network, layer by layer using the weights extracted and the output to check the results. * Do inference. ## How to export weights Weights are essential for any network to run inference. For each test a folder organized as follow is needed (in the build folder): ``` test_nn |---- layers/ (folder containing a binary file for each layer with the corresponding wieghts and bias) |---- debug/ (folder containing a binary file for each layer with the corresponding outputs) ``` Therefore, once the weights have been exported, the folders layers and debug should be placed in the corresponding test. ### 1)Export weights from darknet To export weights for NNs that are defined in darknet framework, use [this](https://git.hipert.unimore.it/fgatti/darknet.git) fork of darknet and follow these steps to obtain a correct debug and layers folder, ready for tkDNN. ``` git clone https://git.hipert.unimore.it/fgatti/darknet.git cd darknet make mkdir layers debug ./darknet export layers ``` N.b. Use compilation with CPU (leave GPU=0 in Makefile) if you also want debug. ### 2)Export weights for DLA34 and ResNet101 To get weights and outputs needed to run the tests dla34 and resnet101 use the Python script and the Anaconda environment included in the repository. Create Anaconda environment and activate it: ``` conda env create -f file_name.yml source activate env_name python