From 6e555678cfe49dd1234522f6a9bc556277c9340d Mon Sep 17 00:00:00 2001 From: mohit Date: Wed, 30 Jun 2021 11:39:48 +0530 Subject: [PATCH] readme update --- README.md | 572 ++++++++++++------------------------------------------ 1 file changed, 126 insertions(+), 446 deletions(-) diff --git a/README.md b/README.md index 2325eb5..f64709d 100644 --- a/README.md +++ b/README.md @@ -1,468 +1,148 @@ -# 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. +# Steps to build docker image +## Docker +Docker version 19.03 will be required. -If you use tkDNN in your research, please cite the [following paper](https://ieeexplore.ieee.org/stamp/stamp.jsp?arnumber=9212130&casa_token=sQTJXi7tJNoAAAAA:BguH9xCIY48MxbtDS3LXzIXzO-9sWArm7Hd7y7BwaLmqRuM_Gx8bOYizFPNMNtpo5K0kB-P-). For use in commercial solutions, write at gattifrancesco@hotmail.it and micaela.verucchi@unimore.it or refer to https://hipert.unimore.it/ . - +## For running with GPU +### NVIDIA Drivers +This drivers should be installed in the host system. +### For Ubuntu: ``` -@inproceedings{verucchi2020systematic, - title={A Systematic Assessment of Embedded Neural Networks for Object Detection}, - author={Verucchi, Micaela and Brilli, Gianluca and Sapienza, Davide and Verasani, Mattia and Arena, Marco and Gatti, Francesco and Capotondi, Alessandro and Cavicchioli, Roberto and Bertogna, Marko and Solieri, Marco}, - booktitle={2020 25th IEEE International Conference on Emerging Technologies and Factory Automation (ETFA)}, - volume={1}, - pages={937--944}, - year={2020}, - organization={IEEE} +$ sudo apt-get install linux-headers-$(uname -r) gcc g++ make +$ wget http://in.download.nvidia.com/tesla/418.67/NVIDIA-Linux-x86_64-418.67.run +$ chmod 777 NVIDIA-Linux-x86_64-418.67.run +$ bash NVIDIA-Linux-x86_64-418.67.run +``` + +### For CentOS +``` +$ sudo yum -y install kernel-devel-$(uname -r) kernel-header-$(uname -r) gcc make +$ wget http://in.download.nvidia.com/tesla/418.67/NVIDIA-Linux-x86_64-418.67.run +$ chmod 777 NVIDIA-Linux-x86_64-418.67.run +$ bash NVIDIA-Linux-x86_64-418.67.run +``` + +### NVIDIA Container Toolkit +This toolkit should be installed in the host system. +### For Ubuntu +``` +$ distribution=$(. /etc/os-release;echo $ID$VERSION_ID) +$ curl -s -L https://nvidia.github.io/nvidia-docker/gpgkey | sudo apt-key add - +$ curl -s -L https://nvidia.github.io/nvidia-docker/$distribution/nvidia-docker.list | sudo tee /etc/apt/sources.list.d/nvidia-docker.list + +$ sudo apt-get update && sudo apt-get install -y nvidia-container-toolkit +$ sudo systemctl restart docker +``` + +### For CentOS +``` +$ distribution=$(. /etc/os-release;echo $ID$VERSION_ID) +$ curl -s -L https://nvidia.github.io/nvidia-docker/$distribution/nvidia-docker.repo | sudo tee /etc/yum.repos.d/nvidia-docker.repo + +$ sudo yum install -y nvidia-container-toolkit +$ sudo systemctl restart docker +``` + +### Building docker image + +* Go to ``TKDNN/`` then run following command. + ```$ docker build -t baggageai:server -f docker/Dockerfile .``` + #### Note: +1. have to copy weights into a TKDNN/config/ (tkdnn converted weights) current support api (fp32X4 and fp16X1) +2. setup number of classes accrding to weights in TKDNN/config/config.yml +3. give path of this weights into handler.cpp line number 117-121. + +### Run docker image +``` +$ docker run --gpus all -p 8080:8080 -d +``` +Now server will be started in the container. You can check server is running or not using ``docker ps`` + + + + +### Run docker image +``` +$ docker run -p 8080:8080 -d +``` + + +# Using docker-compose file +## Docker Compose +Install docker-compose version 1.24.1 +[https://docs.docker.com/compose/install/](https://docs.docker.com/compose/install/) + +## Create Volume +Create a volume named ``BAI_logs`` using following command: +``` +$ docker volume create BAI_logs +``` +Change permission of the directory of docker volume, so that logs can be written to that directory. +``` +$ cd /var/lib/docker/volumes/BAI_logs +$ chmod 757 _data/ +``` +``` +## For running with GPU +Install nvidia-container-runtime: +``` +$ curl -s -L https://nvidia.github.io/nvidia-container-runtime/gpgkey | \ + sudo apt-key add - +$ distribution=$(. /etc/os-release;echo $ID$VERSION_ID) +$ curl -s -L https://nvidia.github.io/nvidia-container-runtime/$distribution/nvidia-container-runtime.list | \ + sudo tee /etc/apt/sources.list.d/nvidia-container-runtime.list +$ sudo apt-get update +$ sudo apt-get install nvidia-container-runtime +``` + +Add nvidia runtime in ``/etc/docker/daemon.json `` +``` +{ + "runtimes": { + "nvidia": { + "path": "/usr/bin/nvidia-container-runtime", + "runtimeArgs": [] + } + }, + "default-runtime": "nvidia" + } ``` +After editing changes restart the docker. +``systemctl restart docker `` -## FPS Results -Inference FPS of yolov4 with tkDNN, average of 1200 images with the same dimension 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 ); - * Xavier NX, Jetpack 4.4 (CUDA 10.2, CUDNN 8.0.0, tensorrt 7.1.0 ). - * 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 | -| Xavier NX | yolo4 320 | 14.56 | 16.25 | 30.14 | 41.15 | 42.13 | 53.42 | -| Xavier NX | yolo4 416 | 10.02 | 10.60 | 22.43 | 25.59 | 29.08 | 32.94 | -| Xavier NX | yolo4 512 | 8.10 | 8.32 | 15.78 | 17.13 | 20.51 | 22.46 | -| Xavier NX | yolo4 608 | 5.26 | 5.18 | 11.54 | 12.06 | 15.09 | 15.82 | -| 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 | - | - | - -## MAP Results -Results for COCO val 2017 (5k images), on RTX 2080Ti, with conf threshold=0.001 - -| | CodaLab | CodaLab | CodaLab | CodaLab | tkDNN map | tkDNN map | -| -------------------- | :-----------: | :-------: | :-----------: | :---------: | :-----------: | :-------: | -| | **tkDNN** | **tkDNN** | **darknet** | **darknet** | **tkDNN** | **tkDNN** | -| | MAP(0.5:0.95) | AP50 | MAP(0.5:0.95) | AP50 | MAP(0.5:0.95) | AP50 | -| Yolov3 (416x416) | 0.381 | 0.675 | 0.380 | 0.675 | 0.372 | 0.663 | -| yolov4 (416x416) | 0.468 | 0.705 | 0.471 | 0.710 | 0.459 | 0.695 | -| yolov3tiny (416x416) | 0.096 | 0.202 | 0.096 | 0.201 | 0.093 | 0.198 | -| yolov4tiny (416x416) | 0.202 | 0.400 | 0.201 | 0.400 | 0.197 | 0.395 | -| Cnet-dla34 (512x512) | 0.366 | 0.543 | \- | \- | 0.361 | 0.535 | -| mv2SSD (512x512) | 0.226 | 0.381 | \- | \- | 0.223 | 0.378 | - -## 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) - - [tkDNN on Windows 10 (experimental)](#tkdnn-on-windows-10-experimental) - - [Dependencies-Windows](#dependencies-windows) - - [Compiling tkDNN on Windows](#compiling-tkdnn-on-windows) - - [Run the demo on Windows](#run-the-demo-on-windows) - - [FP16 inference windows](#fp16-inference-windows) - - [INT8 inference windows](#int8-inference-windows) - - [Known issues with tkDNN on Windows](#known-issues-with-tkdnn-on-windows) - - - - - -## 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. +Go to ``BaggageAI-Darknet-API/baggageai/dist/server/with-gpu`` and run: ``` -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 +$ docker-compose up -d ``` -## 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. +## Running containers in stack +First of all initialize a swarm. +``` +$ docker swarm init +``` +You can add a worker node using ``docker swarm join`` command displayed on terminal. -## 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): +Check the statsus using ``` - 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