Skip to content

Latest commit

 

History

History

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 

README.md

TensorRT Inference of ONNX models with custom layers.

Table Of Contents

Description

This sample, samplePackNet, is a Python sample which uses TensorRT to perform inference with PackNet network. PackNet is a self-supervised monocular depth estimation network used in autonomous driving.

How does this sample work?

This sample converts the Pytorch graph into ONNX and uses ONNX-parser included in TensorRT to parse the ONNX graph. The sample also demonstrates

  • Use of custom layers (plugins) in ONNX graph. These plugins would be automatically registered in TensorRT by using REGISTER_TENSORRT_PLUGIN API.
  • Use of ONNX-graphsurgeon (ONNX-GS) API to modify layers or subgraphs in the ONNX graph. For this network, we transform Group Normalization, upsample and pad layers to remove unnecessary nodes for inference with TensorRT.

Prerequisites

  1. Upgrade pip version and install the sample dependencies.
    pip3 install --upgrade pip
    pip3 install -r requirements.txt

On PowerPC systems, you will need to manually install PyTorch using IBM's PowerAI.

Running the sample

Preparing packnet

Clone the packnet repository and update PYTHONPATH.

git clone https://github.com/TRI-ML/packnet-sfm.git packnet-sfm
pushd packnet-sfm && git checkout tags/v0.1.2 && popd
export PYTHONPATH=$PWD/packnet-sfm # Note on Windows, the export command is: set PYTHONPATH=%cd%\packnet-sfm

Conversion to ONNX

Run the following command to convert the Packnet pytorch network to ONNX graph. This step also includes handling custom layers (Group Normalization) and using ONNX-GS to modify upsample and pad layers.

python3 convert_to_onnx.py --output model.onnx

Inference with TensorRT

Once the ONNX graph is generated, use trtexec tool (located in bin directory of TensorRT package) to perform inference on a random input image.

trtexec --onnx=model.onnx

Please refer to trtexec tool for more commandline options.

Sample --help options

To see the full list of available options and their descriptions, use the -h or --help command line option. For example:

convert_to_onnx.py -h

Additional resources

The following resources provide a deeper understanding about PackNet network and importing a model into TensorRT using Python:

PackNet

Parsers

Documentation

License

For terms and conditions for use, reproduction, and distribution, see the TensorRT Software License Agreement documentation.

Changelog

August 2025:

  • Removed support for Python versions < 3.10.

August 2023:

  • Update ONNX version support to 1.14.0
  • Removed support for Python versions < 3.8. August 2021: Update sample to work with latest torch version June 2020: Initial release of this sample

Known issues

There are no known issues in this sample