Export¶
Export the deploy-mode model + postprocessor as a single ONNX graph, plus a
trtexec command builder for TensorRT.
dfine.export.onnx.export_onnx ¶
export_onnx(model: Module, postprocessor: Module, file: str | Path, *, imgsz: int = 640, batch: int = 1, opset: int = 16, dynamic: bool = True, simplify: bool = False, check: bool = True, device: device | str = 'cpu') -> Path
Export model + postprocessor to an ONNX graph at file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
imgsz
|
int
|
square input resolution of the dummy input (match the model's |
640
|
batch
|
int
|
dummy batch size (a real value even when |
1
|
opset
|
int
|
ONNX opset (upstream uses 16). |
16
|
dynamic
|
bool
|
mark the batch dim |
True
|
simplify
|
bool
|
run |
False
|
check
|
bool
|
run |
True
|
device
|
device | str
|
device to trace on. |
'cpu'
|
Returns:
| Type | Description |
|---|---|
Path
|
The written |
Source code in dfine/export/onnx.py
dfine.export.onnx.tensorrt_command ¶
tensorrt_command(onnx_file: str | Path, *, imgsz: int = 640, fp16: bool = True, engine: str | None = None, max_batch: int = 32) -> str
Return the trtexec command to build a TensorRT engine from onnx_file.
The graph's batch dim is dynamic (H/W are fixed to the export resolution), so
TensorRT needs an optimization profile; this provides min/opt/max shapes at
imgsz (pass the same value you exported with) with batch 1..max_batch. Run
the returned command where trtexec (and OpenVINO's ovc <onnx_file> for
OpenVINO) is installed — those toolchains are not Python deps here.