Export
Use export to convert ReID models to TorchScript, ONNX, OpenVINO, TensorRT,
native Core ML, or TFLite.
This command exports appearance encoders. The separate registered
export-edgetam command is unfinished: its implementation module is absent
from this checkout, so it cannot produce an EdgeTAM bundle. Use the supported
PyTorch workflows on the instance masks page.
Install format-specific dependencies explicitly before exporting, for example
with boxmot install --extra onnx. Exporters validate their requirements and
report missing packages. See Install dependencies for other
extras and TensorRT setup.
TensorRT and OpenVINO use ONNX as an intermediate. If you request only engine
or openvino, BoxMOT exports .onnx next to the source weights first. The
downstream exporter reuses it when its content and export contract match.
Core ML export is native and does not pass through ONNX Runtime. It produces an FP16 MLProgram bundle with static batch buckets (1, 8, 16, and 32 by default). The runtime pads or chunks arbitrary detection counts and lazily keeps one compiled package resident. Conversion workers have configurable time and RAM limits to prevent runaway Apple graph compilation.
Examples
--device follows the shared device selection rules.
Choose a device supported by the requested export format; TensorRT requires
CUDA, while the Core ML example below performs conversion on CPU.
Both tabs run the same export and parity-check workflow. The named OSNet
checkpoint can be downloaded on first use; replace runs/reid_train/exp/best.pt
with your own training output for the other examples. Python options use
underscores, and repeated --include values become a tuple.
Example
Export a transformer ReID model for Apple GPU/CPU inference:
boxmot export \
--weights runs/reid_train/exp/best.pt \
--include coreml \
--device cpu \
--coreml-batch-buckets 1,8,16,32 \
--coreml-minimum-deployment-target macOS15 \
--coreml-compute-units CPUAndGPU \
--coreml-timeout 600 \
--coreml-max-memory-gb 16
The output is best_coreml_model/. Pass that directory directly as
ReID weights. BOXMOT_COREML_MAX_LOADED_BUCKETS=1 is the safe default;
increasing it trades RAM for fewer bucket recompilations.
Export multiple formats:
boxmot export \
--weights osnet_x0_25_msmt17.pt \
--include onnx \
--include engine \
--dynamic \
--batch-size 16 \
--device 0
Export calibrated TFLite int8 using representative ReID crops:
boxmot export \
--weights runs/reid_train/exp/best.pt \
--include tflite \
--tflite-quantize static \
--tflite-calibration-data datasets/reid/Market-1501-v15.09.15/bounding_box_train \
--tflite-calibration-samples 512 \
--tflite-calibration-seed 0 \
--tflite-calibration-update minmax \
--tflite-static-activation-bits 16
Static TFLite uses int8 weights. The default --tflite-static-activation-bits 16
preserves ReID embedding parity better but can be slower on CPU; use 8 only
for strict int8 activation ablations.
from boxmot.engine.commands.reid.export import main as export_reid
if __name__ == "__main__":
result = export_reid(
weights="osnet_x0_25_msmt17.pt",
include=("onnx",),
)
print(result.files)
Export a transformer ReID model for Apple GPU/CPU inference:
from boxmot.engine.commands.reid.export import main as export_reid
if __name__ == "__main__":
result = export_reid(
weights="runs/reid_train/exp/best.pt",
include=("coreml",),
device="cpu",
coreml_batch_buckets=(1, 8, 16, 32),
coreml_minimum_deployment_target="macOS15",
coreml_compute_units="CPUAndGPU",
coreml_timeout=600,
coreml_max_memory_gb=16,
)
print(result.files)
The output is best_coreml_model/. Pass that directory directly as
ReID weights. BOXMOT_COREML_MAX_LOADED_BUCKETS=1 is the safe default;
increasing it trades RAM for fewer bucket recompilations.
Export multiple formats:
from boxmot.engine.commands.reid.export import main as export_reid
if __name__ == "__main__":
result = export_reid(
weights="osnet_x0_25_msmt17.pt",
include=("onnx", "engine"),
dynamic=True,
batch_size=16,
device="cuda:0",
)
print(result.files)
Export calibrated TFLite int8 using representative ReID crops:
from boxmot.engine.commands.reid.export import main as export_reid
if __name__ == "__main__":
result = export_reid(
weights="runs/reid_train/exp/best.pt",
include=("tflite",),
tflite_quantize="static",
tflite_calibration_data=(
"datasets/reid/Market-1501-v15.09.15/bounding_box_train"
),
tflite_calibration_samples=512,
tflite_calibration_seed=0,
tflite_calibration_update="minmax",
tflite_static_activation_bits=16,
)
print(result.files)
Static TFLite uses int8 weights. The default
tflite_static_activation_bits=16 preserves ReID embedding parity
better but can be slower on CPU; use 8 only for strict int8
activation ablations.
Typical use cases
- deploy a ReID backbone outside BoxMOT
- prepare ReID models for inference benchmarks
- build an optimized runtime for a tracker that uses appearance features
Shapes and artifacts
Exports use a fixed RGB crop in height-width order, taken from checkpoint model
metadata or the registered backbone default. Vehicle checkpoints identified by
veri or vehicleid use 256x256. The current implementation replaces the
parsed --imgsz value with this resolved size; that flag does not override the
export crop.
--dynamic makes the batch dimension variable for ONNX and OpenVINO while
keeping the crop dimensions fixed. For TensorRT, --batch-size sets the maximum
dynamic batch; use a value larger than one. TFLite attempts a dynamic batch and
falls back to static when conversion cannot support it. Core ML uses its
explicit bucket list independently of --dynamic.
Files are written beside the source checkpoint:
| Format | Output for best.pt |
|---|---|
| TorchScript | best.torchscript |
| ONNX | best.onnx |
| OpenVINO | best_openvino_model/ with XML and BIN files |
| TensorRT | best.engine |
| Core ML | best_coreml_model/ with its manifest and batch packages |
| TFLite | best.tflite; quantized exports also retain best.float.tflite |
Keep generated metadata sidecars with the exported artifacts. For example,
use boxmot track --source video.mp4 --detector yolo26n --tracker botsort
--reid runs/reid_train/exp/best.onnx after exporting that checkpoint.
Validate the result
BoxMOT compares supported exports with the PyTorch model on deterministic synthetic input and reports numerical error and embedding cosine similarity. This check is informational: a failed check does not undo the exported file or fail the command. TensorRT parity is skipped by this workflow. Validate retrieval quality and end-to-end tracking on your target runtime and device, especially after quantization; a conversion check is not a dataset evaluation.
TFLite calibration uses ReID crops, with preprocessing selected independently
by --tflite-calibration-preprocess. Match it to training/inference (resize
or resize_pad) and use representative images from your training data.
CLI Arguments
boxmot export
Export ReID models
Usage:
Options:
| Name | Type | Description | Default |
|---|---|---|---|
--batch-size |
integer | Batch size for export | 1 |
--imgsz, --img, --img-size |
text | Parsed H,W value; current export uses the checkpoint or registered model crop instead. | 256,128 |
--device |
text | One device: cpu, mps, cuda:N, or N (e.g. 0). GPU lists are not supported. | cpu |
--optimize |
boolean | Optimize TorchScript for mobile (CPU export only) | False |
--dynamic |
boolean | Enable dynamic batch for ONNX, TensorRT, and OpenVINO; attempt it for TFLite. Crop size stays fixed. | False |
--simplify |
boolean | Simplify ONNX model | False |
--opset |
integer | ONNX opset version | 17 |
--workspace |
integer | TensorRT workspace size (GB) | 4 |
--verbose |
boolean | Enable verbose logging for TensorRT | False |
--weights |
Path | Path to the model weights (.pt file) | osnet_x0_25_msmt17 |
--half |
boolean | Request FP16 export; ONNX graph conversion also supports CPU. TensorRT requires CUDA. | False |
--coreml-batch-buckets |
text | Static MLProgram batch buckets; values above 32 are rejected | 1,8,16,32 |
--coreml-minimum-deployment-target |
choice (macOS12 | macOS13 | macOS14 | macOS15 | macOS26) |
Minimum macOS target; macOS15 enables native SDPA | macOS15 |
--coreml-compute-units |
choice (ALL | CPUAndGPU | CPUAndNeuralEngine | CPUOnly) |
CoreML compute units used when compiling MLPrograms | CPUAndGPU |
--coreml-timeout |
float range (1.0 and above) |
Per-bucket CoreML conversion timeout in seconds | 600.0 |
--coreml-max-memory-gb |
float range (1.0 and above) |
Per-bucket CoreML conversion process memory limit | 16.0 |
--tflite-quantize |
choice (none | weight | dynamic | static) |
Post-quantize TFLite export: weight=int8 weights with float compute, dynamic=int8 dynamic range, static=int8 weights with calibrated activations | none |
--tflite-calibration-data |
Path | Image, image-list .txt, or directory of ReID crops for TFLite static calibration | None |
--tflite-calibration-samples |
integer | Maximum number of calibration images for TFLite static export | 256 |
--tflite-calibration-preprocess |
choice (resize | resize_pad) |
Crop preprocessing for TFLite static calibration images | resize |
--tflite-calibration-seed |
integer | Seed for nested directory sampling in TFLite static calibration | 0 |
--tflite-calibration-update |
choice (minmax | moving_average) |
Activation range update rule for TFLite static calibration | minmax |
--tflite-static-activation-bits |
integer | Activation precision for TFLite static quantization; weights remain int8 | 16 |
--include |
text | Export formats to include. Options: torchscript, onnx, openvino, engine, coreml, tflite | ('onnx',) |
--help |
boolean | Show this message and exit. | False |