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, *, task: str = 'detect', 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 |
|---|---|---|---|
task
|
str
|
|
'detect'
|
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
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 | |
dfine.export.onnx.tensorrt_command ¶
tensorrt_command(onnx_file: str | Path, *, task: str = 'detect', 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. The
sem_seg graph has a single images input; detect/segment also take
orig_target_sizes (pass the matching task). Run the returned command where
trtexec (and OpenVINO's ovc <onnx_file> for OpenVINO) is installed — those
toolchains are not Python deps here.