# tkDNN tkDNN is a Deep Neural Network library built with cuDNN and tensorRT primitives, specifically thought to work on NVIDIA Embedded Boards. It has been tested on TK1, 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. ## Index * [Dependencies](#dependencies) * [How to compile this repo](#how-to-compile-this-repo) * [Workflow](#workflow) * [How to export weights](#how-to-export-weights) * [Run the demo](#run-the-demo) * [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 4.1 * yaml-cpp 0.5.2 (sudo apt install libyaml-cpp-dev) ## How to compile this repo Build with cmake. If using Ubuntu 18.04 a new version of cmake is needed (1.15 or above). ``` git clone https://github.com/ceccocats/tkDNN git cd tkDNN git checkout cnet mkdir build cd build cmake .. # use -DTEST_DATA=False to skip dataset download make ``` If TEST_DATA is not set to False, weights needed to run some tests will be automatically downloaded. ## 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: ``` test_nn |---- test_nn.cpp (nn definition in tkDNN) |---- 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://github.com/ceccocats/darknet) fork of darknet and follow these steps to obtain a correct debug and layers folder, ready for tkDNN. ``` git clone https://github.com/ceccocats/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