Skip to contents

yolo_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 .engine files. Use the engine from Python/Ultralytics or other TensorRT runtimes. To use TensorRT from pliman itself, keep the .onnx model and select the TensorRT execution provider with pliman_gpu_provider() ("tensorrt"), which builds and caches its own engines.

  • With half = TRUE the 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 .pt weights file or .onnx model, or the name of an installed model in pliman_model_dir().

output

Optional destination path for the exported .engine file. If NULL (default), places the .engine in pliman_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 to 0.

workspace

Integer. TensorRT builder workspace memory in GB. Defaults to 4.

verbose

Logical. Show compilation progress. Defaults to TRUE.

Value

The file path to the compiled .engine file.

Examples

if (FALSE) { # interactive()
library(pliman)

# Compile YOLO to TensorRT engine (requires NVIDIA GPU & tensorrt package)
engine <- yolo_export_engine("yolo26n.pt", half = TRUE)
}