# tkDNN **Repository Path**: int66/tkDNN ## Basic Information - **Project Name**: tkDNN - **Description**: Deep neural network library and toolkit to do high performace inference on NVIDIA jetson platforms - **Primary Language**: Unknown - **License**: GPL-2.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2020-06-12 - **Last Updated**: 2020-12-19 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # 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 and several discrete GPU. 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. Accepted paper @ IRC 2020, will soon been 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) ## 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