Export
Use export to convert ReID models to TorchScript, ONNX, OpenVINO, TensorRT,
native Core ML, or TFLite.
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 creates or reuses a fresh .onnx file next to the source weights before building the requested format.
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.
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.
Reusable exporter implementations live in boxmot.reid.exporters.backends.
Shared configuration, registry, and model preparation live in boxmot.reid.exporters.
CLI parsing, output naming, and workflow orchestration remain engine
concerns and are intentionally absent from the package root.
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
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 | Image size as H,W (e.g. 256,128) | 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 axes for ONNX/TensorRT export | 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 | Enable FP16 half-precision export (GPU only) | 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 |