
Your First F1 Car: Building a TensorRT Engine with xinfer-cli
Welcome! This guide will show you the power of the `xInfer` toolkit by walking you through its most important workflow: building a TensorRT engine. This process takes a flexible, framework-agnostic model and compiles it into a hardware-specific, high-performance binary.
Prerequisites
- You have successfully installed xInfer.
- You have an ONNX model file. For this guide, we'll use a pre-trained ResNet-50.
Step 1: Get the ONNX Model
First, let's download a standard ResNet-50 model from the ONNX Model Zoo.
wget https://github.com/onnx/models/raw/main/vision/classification/resnet/model/resnet50-v2-7.onnx -O resnet50.onnx
Step 2: Build the FP16 Engine
This is where the magic happens. We will use the xinfer-cli tool to build an engine optimized for FP16 precision, which is perfect for modern NVIDIA GPUs.
# Navigate to your xinfer/build/tools/xinfer-cli directory
./xinfer-cli --build \
--onnx ../../../resnet50.onnx \
--save_engine resnet50_fp16.engine \
--fp16 \
--batch 16
Let's break down that command:
--build: Specifies the build command.--onnx: The path to our input ONNX file.--save_engine: The path for our final, optimized output file.--fp16: Enables fast FP16 precision.--batch 16: Optimizes the engine for a maximum batch size of 16.
After a few moments, you will have a new file: resnet50_fp16.engine. This file is all you need to deploy your model.
Step 3: Benchmark Your New Engine
How fast is it? Let's use xinfer-cli again to run a quick performance benchmark.
./xinfer-cli --benchmark \
--engine resnet50_fp16.engine \
--batch 16 \
--iterations 500
You will see the final throughput and latency numbers for your model, running at maximum speed on your specific GPU.
Next Steps
Congratulations! You have successfully built and benchmarked your first high-performance AI engine. You are now ready to use this engine in a real C++ application.
Check out our Quickstart Guide to see how to load this engine with the xInfer::zoo::ImageClassifier and run inference in just a few lines of code.
.png)




