tensorrt_exporter
sleap_nn.export.exporters.tensorrt_exporter
¶
TensorRT export utilities.
Functions:
| Name | Description |
|---|---|
export_to_tensorrt |
Export a PyTorch model to TensorRT format. |
export_to_tensorrt(model, save_path, input_shape=(1, 1, 512, 512), input_dtype=torch.uint8, precision='fp16', min_shape=None, opt_shape=None, max_shape=None, workspace_size=2 << 30, method='onnx', verbose=True)
¶
Export a PyTorch model to TensorRT format.
This function supports multiple compilation methods: - "onnx": Exports to ONNX first, then compiles with TensorRT (most reliable) - "jit": Uses torch.jit.trace + torch_tensorrt.compile (alternative)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
Module
|
The PyTorch model to export (typically an ONNX wrapper). |
required |
save_path
|
str | Path
|
Path to save the TensorRT engine (.trt file). |
required |
input_shape
|
Tuple[int, int, int, int]
|
(B, C, H, W) optimal input tensor shape. |
(1, 1, 512, 512)
|
input_dtype
|
dtype
|
Input tensor dtype (torch.uint8 or torch.float32). |
uint8
|
precision
|
str
|
Model precision - "fp32" or "fp16". |
'fp16'
|
min_shape
|
Optional[Tuple[int, int, int, int]]
|
Minimum input shape for dynamic shapes (default: batch=1, H/W halved). |
None
|
opt_shape
|
Optional[Tuple[int, int, int, int]]
|
Optimal input shape (default: same as input_shape). |
None
|
max_shape
|
Optional[Tuple[int, int, int, int]]
|
Maximum input shape (default: batch=16, H/W doubled). |
None
|
workspace_size
|
int
|
TensorRT workspace size in bytes (default 2GB). |
2 << 30
|
method
|
str
|
Compilation method - "onnx" or "jit". |
'onnx'
|
verbose
|
bool
|
Print export info. |
True
|
Returns:
| Type | Description |
|---|---|
Path
|
Path to the exported TensorRT engine. |
Note
TensorRT models are NOT cross-platform. The exported model will only work on the same GPU architecture and TensorRT version used for export.