Skip to content
Please note that GitHub no longer supports your web browser.

We recommend upgrading to the latest Google Chrome or Firefox.

Learn more
ONNX-TensorRT: TensorRT backend for ONNX
C++ Python CMake Dockerfile
Branch: master
Clone or download
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
docker Created Tar and Deb Based Dockerfile for ONNX-TensorRT (#256) Oct 25, 2019
onnx_tensorrt Update python tests with full dims support (#263) Sep 23, 2019
third_party Update onnx submodule to rel-1.5.0 (#285) Oct 15, 2019
.gitignore Initial code commit Apr 30, 2018
.gitmodules Update onnx submodule to rel-1.5.0 (#285) Oct 15, 2019
CMakeLists.txt Created Tar and Deb Based Dockerfile for ONNX-TensorRT (#256) Oct 25, 2019
ImporterContext.hpp Improving dynamic shape support (#281) Oct 11, 2019
LICENSE Initial code commit Apr 30, 2018
ModelImporter.cpp Simplifying logic for supportsModel and adds logic for handling shape… Nov 6, 2019
ModelImporter.hpp Improving dynamic shape support (#281) Oct 11, 2019
NvOnnxParser.cpp Initial code commit Apr 30, 2018
NvOnnxParser.h Created Tar and Deb Based Dockerfile for ONNX-TensorRT (#256) Oct 25, 2019
NvOnnxParserTypedefs.h Have supportsModel() return more verbose output about the true capabi… Apr 19, 2019
OnnxAttrs.cpp TensorRT 6.0 ONNX parser update with full-dims support (dynamic shape… Sep 16, 2019
OnnxAttrs.hpp TensorRT 6.0 ONNX parser update with full-dims support (dynamic shape… Sep 16, 2019
README.md Created Tar and Deb Based Dockerfile for ONNX-TensorRT (#256) Oct 25, 2019
ShapedWeights.cpp Updating INT64 -> INT32 casting logic (#299) Oct 24, 2019
ShapedWeights.hpp TensorRT 6.0 ONNX parser update with full-dims support (dynamic shape… Sep 16, 2019
Status.hpp TensorRT 6.0 ONNX parser update with full-dims support (dynamic shape… Sep 16, 2019
TensorOrWeights.hpp Refactor + improve handling of elwise broadcasting (#53) Oct 9, 2018
builtin_op_importers.cpp Bug fixes for argmin/argmax, maxglobalpooling and squeeze (#331) Nov 18, 2019
builtin_op_importers.hpp Initial code commit Apr 30, 2018
common.hpp Add support for new functions in TRT 5.0 NvOnnxParser.h (#113) Mar 7, 2019
contributing.md TensorRT 6.0 ONNX parser update with full-dims support (dynamic shape… Sep 16, 2019
getSupportedAPITest.cpp TensorRT 6.0 ONNX parser update with full-dims support (dynamic shape… Sep 16, 2019
libnvonnxparser.version Initial code commit Apr 30, 2018
main.cpp Full dims readme update (#255) Sep 20, 2019
nv_onnx_parser_bindings.i Initial code commit Apr 30, 2018
onnx2trt.hpp TensorRT 6.0 ONNX parser update with full-dims support (dynamic shape… Sep 16, 2019
onnx2trt_common.hpp TensorRT 6.0 ONNX parser update with full-dims support (dynamic shape… Sep 16, 2019
onnx2trt_runtime.hpp Initial code commit Apr 30, 2018
onnx2trt_utils.cpp Bug fixes for argmin/argmax, maxglobalpooling and squeeze (#331) Nov 18, 2019
onnx2trt_utils.hpp Adding dynamic split support (#326) Nov 8, 2019
onnx_backend_test.py TensorRT 6.0 ONNX parser update with full-dims support (dynamic shape… Sep 16, 2019
onnx_trt_backend.cpp TensorRT 6.0 ONNX parser update with full-dims support (dynamic shape… Sep 16, 2019
onnx_utils.hpp Avoid shuffle layer with scalar initializers when possible (#312) Oct 30, 2019
operators.md Update operator support (#270) Sep 26, 2019
serialize.hpp Initial code commit Apr 30, 2018
setup.py Created Tar and Deb Based Dockerfile for ONNX-TensorRT (#256) Oct 25, 2019
toposort.hpp Initial code commit Apr 30, 2018
trt_utils.hpp TensorRT 6.0 ONNX Parser Release Sep 16, 2019
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.

Supported TensorRT Versions

Development on the Master branch is for the latest version of TensorRT 6.0 with full-dimensions and dynamic shape support.

For version 6.0 without full-dimensions support, clone and build from the 6.0 branch

For version 5.1, clone and build from the 5.1 branch

For versions < 5.1, clone and build from the 5.0 branch

Full Dimensions + Dynamic Shapes

Building INetwork objects in full dimensions mode with dynamic shape support requires calling the following API:

C++

const auto explicitBatch = 1U << static_cast<uint32_t>(nvinfer1::NetworkDefinitionCreationFlag::kEXPLICIT_BATCH);
builder->createNetworkV2(explicitBatch)

Python

import tensorrt
explicit_batch = 1 << (int)(tensorrt.NetworkDefinitionCreationFlag.EXPLICIT_BATCH)
builder.create_network(explicit_batch)

For examples of usage of these APIs see:

Supported Operators

Current supported ONNX operators are found in the operator support matrix.

Installation

Dependencies

Building

For building on master, we recommend following the instructions on the master branch of TensorRT as there are new dependencies that were introduced to support these new features.

To build on older branches refer to their respective READMEs.

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

Python modules

Python bindings for the ONNX-TensorRT parser are packaged in the shipped .whl files. Install them with

pip install <tensorrt_install_dir>/python/tensorrt-6.0.1.5-cp27-none-linux_x86_64.whl

TensorRT 6.0 supports ONNX release 1.5.0. Install it with:

pip install onnx==1.5.0

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)

C++ library usage

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

NvOnnxParser.h

Important typedefs required for parsing ONNX models are declared in this header:

NvOnnxParserTypedefs.h

Docker image

Tar-Based TensorRT

Build the onnx_tensorrt Docker image using tar-based TensorRT by running:

git clone --recurse-submodules https://github.com/onnx/onnx-tensorrt.git
cd onnx-tensorrt
cp /path/to/TensorRT-6.0.*.tar.gz .
docker build -f docker/onnx-tensorrt-tar.Dockerfile --tag=onnx-tensorrt:6.0.6 .

Deb-Based TensorRT

Build the onnx_tensorrt Docker image using deb-based TensorRT by running:

git clone --recurse-submodules https://github.com/onnx/onnx-tensorrt.git
cd onnx-tensorrt
cp /path/to/nv-tensorrt-repo-ubuntu1x04-cudax.x-trt6.x.x.x-ga-yyyymmdd_1-1_amd64.deb .
docker build -f docker/onnx-tensorrt-deb.Dockerfile --tag=onnx-tensorrt:6.0.6 .

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.