Skip to content

Export

Use export to convert ReID models to TorchScript, ONNX, OpenVINO, TensorRT, native Core ML, or TFLite.

Format-specific Python packages are installed on first use when possible. TensorRT export also attempts to install nvidia-tensorrt, but the resulting wheel still needs a compatible CUDA/NVIDIA runtime.

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

Example

boxmot export --weights osnet_x0_25_msmt17.pt --include onnx

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 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 import BoxMOT

boxmot = BoxMOT(reid="osnet_x0_25_msmt17")
exported = boxmot.export(
    include=("onnx", "engine"),
    dynamic=True,
    batch_size=16,
    device="0",
)
print(exported.files)

reid = BoxMOT(reid="models/lmbn_n_duke.pt")
exported = reid.export(format="onnx")
embeddings = exported.embed(source="path/to/image.jpg")

apple_reid = BoxMOT(reid="runs/reid_train/exp/best.pt")
apple_export = apple_reid.export(
    format="coreml",
    coreml_batch_buckets=(1, 8, 16, 32),
)
print(apple_export.files["coreml"])

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:

boxmot export [OPTIONS]

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 CUDA device (e.g., '0', '0,1,2,3', or 'cpu') 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