Table Of Contents
- Description
- How does this sample work?
- Prerequisites
- Running the sample
- Additional resources
- License
- Changelog
- Known issues
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.
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_PLUGINAPI. - 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.
- 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.
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
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
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.
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
The following resources provide a deeper understanding about PackNet network and importing a model into TensorRT using Python:
PackNet
- 3D Packing for Self-Supervised Monocular Depth Estimation
- TRI-ML Monocular Depth Estimation Repository
Parsers
Documentation
- Introduction To NVIDIA’s TensorRT Samples
- Working With TensorRT Using The Python API
- Importing A Model Using A Parser In Python
- NVIDIA’s TensorRT Documentation Library
For terms and conditions for use, reproduction, and distribution, see the TensorRT Software License Agreement documentation.
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
There are no known issues in this sample