SkillAgentSearch skills...

Tensorrtx

Implementation of popular deep learning networks with TensorRT network definition API

Install / Use

/learn @wang-xinyu/Tensorrtx

README

TensorRTx

TensorRTx aims to implement popular deep learning networks with TensorRT network definition API.

Why don't we use a parser (ONNX parser, UFF parser, caffe parser, etc), but use complex APIs to build a network from scratch? I have summarized the advantages in the following aspects.

  • Flexible, easy to modify the network, add/delete a layer or input/output tensor, replace a layer, merge layers, integrate preprocessing and postprocessing into network, etc.
  • Debuggable, construct the entire network in an incremental development manner, easy to get middle layer results.
  • Educational, learn about the network structure during this development, rather than treating everything as a black box.

The basic workflow of TensorRTx is:

  1. Get the trained models from pytorch, mxnet or tensorflow, etc. Some pytorch models can be found in my repo pytorchx, the remaining are from popular open-source repos.
  2. Export the weights to a plain text file -- .wts file.
  3. Load weights in TensorRT, define the network, build a TensorRT engine.
  4. Load the TensorRT engine and run inference.

News

Tutorials

Test Environment

  1. (NOT recommended) TensorRT 7.x
  2. (Recommended)TensorRT 8.x
  3. (NOT recommended) TensorRT 10.x

Note

  1. For history reason, some of the models are limited to specific TensorRT version, please check the README.md or code for the model you want to use.
  2. Currently, TensorRT 8.x has better compatibility and the most of the features supported.

How to run

Note: this project support to build each network by the CMakeLists.txt in its subfolder, or you can build them together by the CMakeLists.txt on top of this project.

  • General procedures before building and running:
# 1. generate xxx.wts from https://github.com/wang-xinyu/pytorchx/tree/master/lenet
# ...

# 2. put xxx.wts on top of this folder
# ...
  • (Option 1) To build a single subproject in this project, do:
## enter the subfolder
cd tensorrtx/xxx

## configure & build
cmake -S . -B build
make -C build
  • (Option 2) To build many subprojects, firstly, in the top CMakeLists.txt, uncomment the project you don't want to build or not suppoted by your TensorRT version, e.g., you cannot build subprojects in ${TensorRT_8_Targets} if your TensorRT is 7.x. Then:
## enter the top of this project
cd tensorrtx

## configure & build
# you may use "Ninja" rather than "make" to significantly boost the build speed
cmake -G Ninja -S . -B build
ninja -C build

WARNING: This part is still under development, most subprojects are not adapted yet.

  • run the generated executable, e.g.:
# serialize model to plan file i.e. 'xxx.engine'
build/xxx -s

# deserialize plan file and run inference
build/xxx -d

# (Optional) check if the output is same as pytorchx/lenet
# ...

# (Optional) customize the project
# ...

For more details, each subfolder may contain a README.md inside, which explains more.

Models

Following models are implemented.

| Name | Description | | ---------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | mlp | the very basic model for starters, properly documented | | lenet | the simplest, as a "hello world" of this project | | alexnet | easy to implement, all layers are supported in tensorrt | | googlenet | GoogLeNet (Inception v1) | | inception | Inception v3, v4 | | mnasnet | MNASNet with depth multiplier of 0.5 from the paper | | mobilenet | MobileNet v2, v3-small, v3-large | | resnet | resnet-18, resnet-50 and resnext50-32x4d are implemented | | senet | se-resnet50 | | shufflenet | ShuffleNet v2 with 0.5x output channels | | squeezenet | SqueezeNet 1.1 model

Related Skills

View on GitHub
GitHub Stars7.7k
CategoryEducation
Updated1h ago
Forks1.9k

Languages

C++

Security Score

100/100

Audited on Mar 27, 2026

No findings