
Export YOLO Model to NVIDIA TensorRT Engine (.engine)
Source:R/utils_yolo_quantize.R
yolo_export_engine.Rdyolo_export_engine() compiles a YOLO model (.pt or .onnx) into an NVIDIA TensorRT
optimized .engine binary using half-precision (FP16) or single-precision (FP32).
Important Notes on TensorRT Engines:
TensorRT engines are machine-specific binaries tied to the exact GPU hardware, CUDA version, and TensorRT runtime on which they were compiled. They cannot be shared across different machines or uploaded to Hugging Face.
Compiling a TensorRT engine requires an NVIDIA GPU, NVIDIA drivers, CUDA, and the tensorrt Python package (
pip install tensorrt).For a portable, half-size model that runs on any machine without TensorRT, use
yolo_export_fp16(), which runs natively in pliman via DirectML.pliman's own inference functions (
image_detect_dl(),video_detect_dl(), ...) run ONNX models through ONNX Runtime and cannot execute.enginefiles. Use the engine from Python/Ultralytics or other TensorRT runtimes. To use TensorRT from pliman itself, keep the.onnxmodel and select the TensorRT execution provider withpliman_gpu_provider()("tensorrt"), which builds and caches its own engines.With
half = TRUEthe speed-up depends on GPUs with native FP16 throughput (NVIDIA Tensor Cores, RTX 20xx and newer). On GPUs without fast FP16 (e.g. GTX 10xx/16xx) the gain can be small or negative.
Usage
yolo_export_engine(
model,
output = NULL,
half = TRUE,
imgsz = 640,
dynamic = FALSE,
device = 0,
workspace = 4,
verbose = TRUE
)Arguments
- model
Character string. File path to a
.ptweights file or.onnxmodel, or the name of an installed model inpliman_model_dir().- output
Optional destination path for the exported
.enginefile. IfNULL(default), places the.engineinpliman_model_dir().- half
Logical. Enable FP16 half-precision in TensorRT engine. Defaults to
TRUE.- imgsz
Integer or vector of two integers. Input image resolution. Defaults to
640.- dynamic
Logical. Enable dynamic input axes. Defaults to
FALSE.- device
Integer. GPU device ordinal (e.g.
0). Defaults to0.- workspace
Integer. TensorRT builder workspace memory in GB. Defaults to
4.- verbose
Logical. Show compilation progress. Defaults to
TRUE.