forked from dusty-nv/jetson-inference
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
49 changed files
with
8,918 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
|
||
cmake_minimum_required(VERSION 2.8) | ||
project(jetson-inference) | ||
|
||
|
||
# setup GIE | ||
set(GIE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../GIE" CACHE FILEPATH "Path to GPU Inference Engine") | ||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") # -std=gnu++11 | ||
|
||
set(BUILD_DEPS "YES" CACHE BOOL "If YES, will install dependencies into sandbox. Automatically reset to NO after dependencies are installed.") | ||
|
||
|
||
# if this is the first time running cmake, perform pre-build dependency install script (or if the user manually triggers re-building the dependencies) | ||
if( ${BUILD_DEPS} ) | ||
message("Launching pre-build dependency installer script...") | ||
|
||
execute_process(COMMAND sh ../CMakePreBuild.sh | ||
WORKING_DIRECTORY ${PROJECT_BINARY_DIR} | ||
RESULT_VARIABLE PREBUILD_SCRIPT_RESULT) | ||
|
||
set(BUILD_DEPS "NO" CACHE BOOL "If YES, will install dependencies into sandbox. Automatically reset to NO after dependencies are installed." FORCE) | ||
message("Finished installing dependencies") | ||
endif() | ||
|
||
|
||
# Qt4 is used to load images (installed by ubuntu-desktop) | ||
find_package(Qt4 REQUIRED) | ||
include(${QT_USE_FILE}) | ||
add_definitions(${QT_DEFINITIONS}) | ||
|
||
|
||
# setup CUDA | ||
find_package(CUDA) | ||
|
||
set( | ||
CUDA_NVCC_FLAGS | ||
${CUDA_NVCC_FLAGS}; | ||
-std=c++11 -O3 -gencode arch=compute_53,code=sm_53 | ||
) | ||
|
||
|
||
# setup project output paths | ||
set(PROJECT_OUTPUT_DIR ${PROJECT_BINARY_DIR}/${CMAKE_SYSTEM_PROCESSOR}) | ||
set(PROJECT_INCLUDE_DIR ${PROJECT_OUTPUT_DIR}/include) | ||
|
||
file(MAKE_DIRECTORY ${PROJECT_INCLUDE_DIR}) | ||
file(MAKE_DIRECTORY ${PROJECT_OUTPUT_DIR}/bin) | ||
|
||
message("-- system arch: ${CMAKE_SYSTEM_PROCESSOR}") | ||
message("-- output path: ${PROJECT_OUTPUT_DIR}") | ||
|
||
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_OUTPUT_DIR}/bin) | ||
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_OUTPUT_DIR}/lib) | ||
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_OUTPUT_DIR}/lib) | ||
|
||
|
||
# build C/C++ interface | ||
include_directories(${PROJECT_INCLUDE_DIR} ${GIE_PATH}/include) | ||
include_directories(/usr/include/gstreamer-1.0 /usr/include/glib-2.0 /usr/include/libxml2 /usr/lib/aarch64-linux-gnu/glib-2.0/include/) | ||
link_directories(${GIE_PATH}/lib) | ||
|
||
file(GLOB inferenceSources *.cpp *.cu camera/*.cpp cuda/*.cu display/*.cpp) | ||
file(GLOB inferenceIncludes *.h camera/*.h cuda/*.h display/*.h) | ||
|
||
cuda_add_library(jetson-inference SHARED ${inferenceSources}) | ||
target_link_libraries(jetson-inference nvcaffe_parser nvinfer Qt4::QtGui GL GLEW gstreamer-1.0 gstapp-1.0) # gstreamer-0.10 gstbase-0.10 gstapp-0.10 | ||
|
||
# transfer all headers to the include directory | ||
foreach(include ${inferenceIncludes}) | ||
message("-- Copying ${include}") | ||
configure_file(${include} ${PROJECT_INCLUDE_DIR} COPYONLY) | ||
endforeach() | ||
|
||
# copy network data | ||
file(GLOB networkData ${PROJECT_SOURCE_DIR}/data/networks/* ${PROJECT_SOURCE_DIR}/data/images/*) | ||
|
||
foreach(include ${networkData}) | ||
message("-- Copying ${include}") | ||
configure_file(${include} ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} COPYONLY) | ||
endforeach() | ||
|
||
# build samples & tools | ||
add_subdirectory(imagenet-console) | ||
add_subdirectory(imagenet-camera) | ||
add_subdirectory(camera/gst-camera) | ||
add_subdirectory(camera/v4l2-console) | ||
add_subdirectory(camera/v4l2-display) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#!/usr/bin/env bash | ||
# this script is automatically run from CMakeLists.txt | ||
|
||
BUILD_ROOT=$PWD | ||
TORCH_PREFIX=$PWD/torch | ||
|
||
echo "[Pre-build] dependency installer script running..." | ||
echo "[Pre-build] build root directory: $BUILD_ROOT" | ||
|
||
|
||
sudo apt-get update | ||
sudo apt-get install -y qt4-dev-tools libglew-dev glew-utils libgstreamer1.0-dev | ||
# libgstreamer0.10-0-dev libgstreamer-plugins-base0.10-dev libxml2-dev | ||
sudo apt-get update | ||
|
||
|
||
# libgstreamer-plugins-base1.0-dev | ||
|
||
sudo rm /usr/lib/aarch64-linux-gnu/libGL.so | ||
sudo ln -s /usr/lib/aarch64-linux-gnu/tegra/libGL.so /usr/lib/aarch64-linux-gnu/libGL.so | ||
|
||
|
||
wget http://dl.caffe.berkeleyvision.org/bvlc_alexnet.caffemodel | ||
mv bvlc_alexnet.caffemodel ../data/networks | ||
|
||
wget http://dl.caffe.berkeleyvision.org/bvlc_googlenet.caffemodel | ||
mv bvlc_googlenet.caffemodel ../data/networks |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,216 @@ | ||
# jetson-inference | ||
Guide to deploying deep-learning inference networks and end-to-end object recognition tutorial for NVIDIA Jetson TX1. | ||
Welcome to NVIDIA's deep learning inference workshop and end-to-end object recognition library for Jetson TX1. | ||
|
||
|
||
![Alt text](https://a70ad2d16996820e6285-3c315462976343d903d5b3a03b69072d.ssl.cf2.rackcdn.com/0e7182cddd632abe6832849776204911) | ||
|
||
|
||
### Table of Contents | ||
|
||
* [Table of Contents](#table-of-contents) | ||
* [Introduction](#introduction) | ||
* [Training](#training) | ||
* [DIGITS](#digits) | ||
* [Inference](#inference) | ||
* [Building nvcaffe](#building-nvcaffe) | ||
* [Installing GPU Inference Engine](#installing-gpu-inference-engine) | ||
|
||
> **note**: this branch of the tutorial uses | ||
> JetPack 2.2 / L4T R24.1 aarch64. | ||
### Introduction | ||
|
||
*Deep-learning* networks typically have two primary phases of development: **training** and **inference** | ||
|
||
#### Training | ||
During the training phase, the network learns from a large dataset of labeled examples. The weights of the neural network become optimized to recognize the patterns contained within the training dataset. Deep neural networks have many layers of neurons connected togethers. Deeper networks take increasingly longer to train and evaluate, but are ultimately able to encode more intelligence within them. | ||
|
||
![Alt text](https://a70ad2d16996820e6285-3c315462976343d903d5b3a03b69072d.ssl.cf2.rackcdn.com/fd4ba9e7e68b76fc41c8312856c7d0ad) | ||
|
||
Throughout training, the network's inference performance is tested and refined using trial dataset. Like the training dataset, the trial dataset is labeled with ground-truth so the network's accuracy can be evaluated, but was not included in the training dataset. The network continues to train iteratively until it reaches a certain level of accuracy set by the user. | ||
|
||
Due to the size of the datasets and deep inference networks, training is typically very resource-intensive and can take weeks or months on traditional compute architectures. However, using GPUs vastly accellerates the process down to days or hours. | ||
|
||
##### DIGITS | ||
|
||
Using [DIGITS](https://developer.nvidia.com/digits), anyone can easily get started and interactively train their networks with GPU acceleration. <br />DIGITS is an open-source project contributed by NVIDIA, located here: https://github.com/NVIDIA/DIGITS. | ||
|
||
This tutorial will use DIGITS and Jetson TX1 together for training and deploying deep-learning networks, <br />refered to as the DIGITS workflow: | ||
|
||
![Alt text](https://a70ad2d16996820e6285-3c315462976343d903d5b3a03b69072d.ssl.cf2.rackcdn.com/90bde1f85a952157b914f75a9f8739c2) | ||
|
||
|
||
#### Inference | ||
Using it's trained weights, the network evaluates live data at runtime. Called inference, the network predicts and applies reasoning based off the examples it learned. Due to the depth of deep learning networks, inference requires significant compute resources to process in realtime on imagery and other sensor data. However, using NVIDIA's GPU Inference Engine which uses Jetson's integrated NVIDIA GPU, inference can be deployed onboard embedded platforms. Applications in robotics like picking, autonomous navigation, agriculture, and industrial inspection have many uses for deploying deep inference, including: | ||
|
||
- Image recognition | ||
- Object detection | ||
- Segmentation | ||
- Image registration (homography estimation) | ||
- Depth from raw stereo | ||
- Signal analytics | ||
- Others? | ||
|
||
|
||
## Building nvcaffe | ||
|
||
A special branch of caffe is used on TX1 which includes support for FP16.<br /> | ||
The code is released in NVIDIA's caffe repo in the experimental/fp16 branch, located here: | ||
> https://github.com/nvidia/caffe/tree/experimental/fp16 | ||
#### 1. Installing Dependencies | ||
|
||
``` bash | ||
$ sudo apt-get install protobuf-compiler libprotobuf-dev cmake git libboost-thread1.55-dev libgflags-dev libgoogle-glog-dev libhdf5-dev libatlas-dev libatlas-base-dev libatlas3-base liblmdb-dev libleveldb-dev | ||
``` | ||
|
||
The Snappy package needs a symbolic link created for Caffe to link correctly: | ||
|
||
``` bash | ||
$ sudo ln -s /usr/lib/libsnappy.so.1 /usr/lib/libsnappy.so | ||
$ sudo ldconfig | ||
``` | ||
|
||
#### 2. Clone nvcaffe fp16 branch | ||
|
||
``` bash | ||
$ git clone -b experimental/fp16 https://github.com/NVIDIA/caffe | ||
``` | ||
|
||
This will checkout the repo to a local directory called `caffe` on your Jetson. | ||
|
||
#### 3. Setup build options | ||
|
||
``` bash | ||
$ cd caffe | ||
$ cp Makefile.config.example Makefile.config | ||
``` | ||
|
||
###### Enable FP16: | ||
|
||
``` bash | ||
$ sed -i 's/# NATIVE_FP16/NATIVE_FP16/g' Makefile.config | ||
``` | ||
|
||
###### Enable cuDNN: | ||
|
||
``` bash | ||
$ sed -i 's/# USE_CUDNN/USE_CUDNN/g' Makefile.config | ||
``` | ||
|
||
###### Enable compute_53/sm_53: | ||
|
||
``` bash | ||
$ sed -i 's/-gencode arch=compute_50,code=compute_50/-gencode arch=compute_53,code=sm_53 -gencode arch=compute_53,code=compute_53/g' Makefile.config | ||
``` | ||
|
||
#### 4. Compiling nvcaffe | ||
|
||
``` bash | ||
$ make all | ||
$ make test | ||
``` | ||
|
||
#### 5. Testing nvcaffe | ||
|
||
``` bash | ||
$ make runtest | ||
``` | ||
|
||
## Installing GPU Inference Engine | ||
|
||
NVIDIA's [GPU Inference Engine](https://developer.nvidia.com/gie) (GIE) is an optimized backend for evaluating deep inference networks in prototxt format. | ||
|
||
#### 1. Package contents | ||
|
||
First, unzip the archive: | ||
``` | ||
$ tar -zxvf gie.aarch64-cuda7.0-1.0-ea.tar.gz | ||
``` | ||
|
||
The directory structure is as follows: | ||
``` | ||
|-GIE | ||
| \bin where the samples are built to | ||
| \data sample network model / prototxt's | ||
| \doc API documentation and User Guide | ||
| \include | ||
| \lib | ||
| \samples | ||
``` | ||
|
||
#### 2. Remove packaged cuDNN | ||
|
||
If you flashed your Jetson TX1 with JetPack or already have cuDNN installed, remove the version of cuDNN that comes with GIE: | ||
|
||
``` | ||
$ cd GIE/lib | ||
$ rm libcudnn* | ||
$ cd ../../ | ||
``` | ||
|
||
#### 3. Build samples | ||
|
||
```` | ||
$ cd GIE/samples/sampleMNIST | ||
$ make TARGET=tx1 | ||
Compiling: sampleMNIST.cpp | ||
Linking: ../../bin/sample_mnist_debug | ||
Compiling: sampleMNIST.cpp | ||
Linking: ../../bin/sample_mnist | ||
$ cd ../sampleGoogleNet | ||
$ make TARGET=tx1 | ||
Compiling: sampleGoogleNet.cpp | ||
Linking: ../../bin/sample_googlenet_debug | ||
Compiling: sampleGoogleNet.cpp | ||
Linking: ../../bin/sample_googlenet | ||
$ cd ../../../ | ||
```` | ||
|
||
#### 4. Running samples | ||
|
||
```` | ||
$ cd GIE/bin | ||
$ ./sample_mnist | ||
@@@@@@@@@@@@@@@@@@@@@@@@@@@@ | ||
@@@@@@@@@@@@@@@@@@@@@@@@@@@@ | ||
@@@@@@@@@@@@@@@@@@@@@@@@@@@@ | ||
@@@@@@@@@@@@@@@@@@@@@@@@@@@@ | ||
@@@@@@@@@@@@@@@@@@@@@@@@@@@@ | ||
@@@@@@@@@@@@@@@@@@@@@@@@@@@@ | ||
@@@@@@@@@%+-: =@@@@@@@@@@@@ | ||
@@@@@@@%= -@@@**@@@@@@@ | ||
@@@@@@@ :%#@-#@@@. #@@@@@@ | ||
@@@@@@* +@@@@:*@@@ *@@@@@@ | ||
@@@@@@# +@@@@ @@@% @@@@@@@ | ||
@@@@@@@. :%@@.@@@. *@@@@@@@ | ||
@@@@@@@@- =@@@@. -@@@@@@@@ | ||
@@@@@@@@@%: +@- :@@@@@@@@@ | ||
@@@@@@@@@@@%. : -@@@@@@@@@@ | ||
@@@@@@@@@@@@@+ #@@@@@@@@@@ | ||
@@@@@@@@@@@@@@+ :@@@@@@@@@@ | ||
@@@@@@@@@@@@@@+ *@@@@@@@@@ | ||
@@@@@@@@@@@@@@: = @@@@@@@@@ | ||
@@@@@@@@@@@@@@ :@ @@@@@@@@@ | ||
@@@@@@@@@@@@@@ -@ @@@@@@@@@ | ||
@@@@@@@@@@@@@# +@ @@@@@@@@@ | ||
@@@@@@@@@@@@@* ++ @@@@@@@@@ | ||
@@@@@@@@@@@@@* *@@@@@@@@@ | ||
@@@@@@@@@@@@@# =@@@@@@@@@@ | ||
@@@@@@@@@@@@@@. +@@@@@@@@@@@ | ||
@@@@@@@@@@@@@@@@@@@@@@@@@@@@ | ||
@@@@@@@@@@@@@@@@@@@@@@@@@@@@ | ||
0: | ||
1: | ||
2: | ||
3: | ||
4: | ||
5: | ||
6: | ||
7: | ||
8: ********** | ||
9: | ||
```` | ||
The MNIST sample randomly selects an image of a numeral 0-9, which is then classified with the MNIST network using GIE. In this example, the network correctly recognized the image as #8. | ||
|
Oops, something went wrong.