Skip to content
ONNX-TensorRT: TensorRT backend for ONNX
C++ Python CMake Dockerfile
Branch: v5.0
View #293
Clone or download
#293 Compare This branch is 1 commit ahead, 73 commits behind master.
kevinch-nv Merge latest master to v5.0 (#176)
* Adding support for INT64 weights by downcasting them to INT32 if possible (#146)

* Have supportsModel() return more verbose output about the true capability of graph support in the parser (#151)

* WIP for updating getcompatibility

* WIP

* Adding parse() in supportsModel() for more rigorous checking

* Cleaning up code

* Added functionality to see if each subgraph is actually supported

* Added better messaging

* Added some more checks to supportsModel()

* Deleting getSupportedAPITest binary (#155)

* Fixing capability logic (#156)

* Adding broadcasting support for elementwise operations (#158)

* Fixing typo in broadcasting assertion (#160)

* Add supportsModel() check for inputs of the graph (#163)

* Have SupportsModel() catch unsupported inputs

* Updating commnets

* Initial commit (#164)

* Updating transpose to support reshape ops (#165)

* Fix typo (#166)

* Remove INT64 support for input types (#168)

* Initial commit (#170)

* Value initialize weights (#172)
Latest commit 3aa0a1c May 17, 2019
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
onnx_tensorrt Disable all unsupported python unit tests. (#132) Mar 8, 2019
third_party ONNX changed to use int32_t to store data type (#86) Dec 8, 2018
.gitignore Initial code commit Apr 30, 2018
.gitmodules Initial code commit Apr 30, 2018
CMakeLists.txt Update CMakeLists.txt (#143) Apr 1, 2019
Dockerfile Minor whitespace cleanup in Dockerfile May 26, 2018
FancyActivation.cu Initial code commit Apr 30, 2018
FancyActivation.hpp Revert "Fix compilation with TensorRT 5 RC (#55)" (#69) Nov 11, 2018
ImporterContext.hpp Fix crash due to missing opset field in old models (#41) Aug 11, 2018
InstanceNormalization.cpp Enable compiler warnings and fix some May 24, 2018
InstanceNormalization.hpp Revert "Fix compilation with TensorRT 5 RC (#55)" (#69) Nov 11, 2018
LICENSE Initial code commit Apr 30, 2018
ModelImporter.cpp Merge latest master to v5.0 (#176) May 16, 2019
ModelImporter.hpp Add support for new functions in TRT 5.0 NvOnnxParser.h (#113) Mar 7, 2019
NvOnnxParser.cpp Initial code commit Apr 30, 2018
NvOnnxParser.h Add support for new functions in TRT 5.0 NvOnnxParser.h (#113) Mar 7, 2019
NvOnnxParserRuntime.cpp Initial code commit Apr 30, 2018
NvOnnxParserRuntime.h Initial code commit Apr 30, 2018
NvOnnxParserTypedefs.h Merge latest master to v5.0 (#176) May 16, 2019
OnnxAttrs.cpp Support vector-of-float attribute type May 12, 2018
OnnxAttrs.hpp Update onnx submodule and fix compiler warnings (#70) Nov 11, 2018
PluginFactory.cpp wrap plugins for correct serialization (#140) Apr 3, 2019
PluginFactory.hpp Initial code commit Apr 30, 2018
README.md Adding ability for user-defined GPU_ARCHS. (#138) Mar 25, 2019
ResizeNearest.cu Initial code commit Apr 30, 2018
ResizeNearest.hpp Revert "Fix compilation with TensorRT 5 RC (#55)" (#69) Nov 11, 2018
ShapedWeights.cpp Merge latest master to v5.0 (#176) May 16, 2019
ShapedWeights.hpp Merge latest master to v5.0 (#176) May 16, 2019
Split.cu Initial code commit Apr 30, 2018
Split.hpp Revert "Fix compilation with TensorRT 5 RC (#55)" (#69) Nov 11, 2018
Status.hpp Merge latest master to v5.0 (#176) May 16, 2019
TensorOrWeights.hpp Refactor + improve handling of elwise broadcasting (#53) Oct 9, 2018
builtin_op_importers.cpp Merge latest master to v5.0 (#176) May 16, 2019
builtin_op_importers.hpp Initial code commit Apr 30, 2018
builtin_plugins.cpp Fix plugins not being registered in Release build May 2, 2018
builtin_plugins.hpp Initial code commit Apr 30, 2018
common.hpp Add support for new functions in TRT 5.0 NvOnnxParser.h (#113) Mar 7, 2019
getSupportedAPITest.cpp Merge latest master to v5.0 (#176) May 16, 2019
libnvonnxparser.version Initial code commit Apr 30, 2018
libnvonnxparser_runtime.version Initial code commit Apr 30, 2018
main.cpp Add support for new functions in TRT 5.0 NvOnnxParser.h (#113) Mar 7, 2019
nv_onnx_parser_bindings.i Initial code commit Apr 30, 2018
nv_onnx_runtime_bindings.i Initial code commit Apr 30, 2018
onnx2trt.hpp Update onnx submodule and fix compiler warnings (#70) Nov 11, 2018
onnx2trt_common.hpp
onnx2trt_runtime.hpp Initial code commit Apr 30, 2018
onnx2trt_utils.cpp Fix some opset 7 issues (#47) Sep 18, 2018
onnx2trt_utils.hpp Merge latest master to v5.0 (#176) May 16, 2019
onnx_backend_test.py Remove debug print and clean up regex for backend test (#133) Mar 8, 2019
onnx_trt_backend.cpp Add support for new functions in TRT 5.0 NvOnnxParser.h (#113) Mar 7, 2019
onnx_utils.hpp Update onnx submodule and fix compiler warnings (#70) Nov 11, 2018
plugin.cpp WAR an issue with some NvPlugins in TRT3 May 26, 2018
plugin.hpp Revert "Fix compilation with TensorRT 5 RC (#55)" (#69) Nov 11, 2018
plugin_common.hpp Initial code commit Apr 30, 2018
serialize.hpp Initial code commit Apr 30, 2018
setup.py Add pycuda dependency to setup.py (#49) Sep 11, 2018
toposort.hpp Initial code commit Apr 30, 2018
trt_utils.hpp Fix some opset 7 issues (#47) Sep 18, 2018
utils.hpp Initial code commit Apr 30, 2018

README.md

TensorRT backend for ONNX

Parses ONNX models for execution with TensorRT.

See also the TensorRT documentation.

ONNX Python backend usage

The TensorRT backend for ONNX can be used in Python as follows:

import onnx
import onnx_tensorrt.backend as backend
import numpy as np

model = onnx.load("/path/to/model.onnx")
engine = backend.prepare(model, device='CUDA:1')
input_data = np.random.random(size=(32, 3, 224, 224)).astype(np.float32)
output_data = engine.run(input_data)[0]
print(output_data)
print(output_data.shape)

Executable usage

ONNX models can be converted to serialized TensorRT engines using the onnx2trt executable:

onnx2trt my_model.onnx -o my_engine.trt

ONNX models can also be converted to human-readable text:

onnx2trt my_model.onnx -t my_model.onnx.txt

See more usage information by running:

onnx2trt -h

C++ library usage

The model parser library, libnvonnxparser.so, has a C++ API declared in this header:

NvOnnxParser.h

TensorRT engines built using this parser must use the plugin factory provided in libnvonnxparser_runtime.so, which has a C++ API declared in this header:

NvOnnxParserRuntime.h

Installation

Dependencies

Download the code

Clone the code from GitHub.

git clone --recursive https://github.com/onnx/onnx-tensorrt.git

Executable and libraries

Suppose your TensorRT library is located at /opt/tensorrt. Build the onnx2trt executable and the libnvonnxparser* libraries using CMake. Note that onnx-tensorrt will by default tell the CUDA compiler generate code for the latest SM version. If you are using a GPU with a lower SM version you can specify which SMs to build for by using the optional -DGPU_ARCHS flag. For example, if you are running TensorRT on an older Pascal card such as a GTX 1080, you can specify -DGPU_ARCHS="61" to generate CUDA code specifically for your card.

See here for finding what maximum compute capability your specific GPU supports.

mkdir build
cd build
cmake .. -DTENSORRT_ROOT=/opt/tensorrt
OR
cmake .. -DTENSORRT_ROOT=/opt/tensorrt -DGPU_ARCHS="61"
make -j8
sudo make install

Python modules

Python bindings for the ONNX-TensorRT parser in TensorRT versions >= 5.0 are packaged in the shipped .whl files. No extra install is necessary.

For earlier versions of TensorRT, the Python wrappers are built using SWIG. Build the Python wrappers and modules by running:

python setup.py build
sudo python setup.py install

Docker image

Build the onnx_tensorrt Docker image by running:

cp /path/to/TensorRT-3.0.*.tar.gz .
docker build -t onnx_tensorrt .

Tests

After installation (or inside the Docker container), ONNX backend tests can be run as follows:

Real model tests only:

python onnx_backend_test.py OnnxBackendRealModelTest

All tests:

python onnx_backend_test.py

You can use -v flag to make output more verbose.

Pre-trained models

Pre-trained models in ONNX format can be found at the ONNX Model Zoo

You can’t perform that action at this time.