Skip to content

Export

Use export to convert ReID models to deployment formats such as ONNX and TensorRT.

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.

Examples

Example

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

Export multiple formats:

boxmot export \
  --weights osnet_x0_25_msmt17.pt \
  --include engine \
  --dynamic

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)
print(exported.files)

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

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) /home/runner/work/boxmot/boxmot/models/osnet_x0_25_msmt17.pt
--half boolean Enable FP16 half-precision export (GPU only) False
--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, tflite ('onnx',)
--help boolean Show this message and exit. False