Small end-to-end programs demonstrating how to load and run models with
tract. Most use the high-level tract facade; a few still
sit on the lower-level framework crates (tract-tensorflow,
tract-tflite) and are flagged below.
Simple vision pipelines: load a model, feed a pre-processed image tensor, print the top class. Useful entry points when you're just kicking tract's tires.
| Example | Model source | Notes |
|---|---|---|
onnx-mobilenet-v2 |
ONNX | MobileNet v2. Second binary dyn-shape demonstrates symbolic batch dim and runtime shape dispatch. |
nnef-mobilenet-v2 |
NNEF | Same model, pre-compiled to NNEF. Faster load, smaller artifact. |
nnef-dump-mobilenet-v2 |
TF → NNEF | Shows how to tract … dump --nnef a TF model and then run the NNEF. |
pytorch-resnet |
PyTorch → ONNX | ResNet classification with ndarray broadcasting for per-channel normalisation. |
keras-tract-tf2 |
Keras → ONNX | Numeric equivalence check: runs the same inputs through the ONNX model and compares to .npz reference outputs. |
| Example | What it shows |
|---|---|
face_detection_yolov8onnx_example |
YOLOv8-face ONNX model, letterbox pre-processing, bounding-box decoding. |
face_similarity_arcface_onnx |
Two-stage pipeline: YOLOv8-face for detection, ArcFace for embedding, cosine similarity between two images. |
| Example | What it shows |
|---|---|
pytorch-albert-v2 |
ALBERT masked-LM token completion; demonstrates tract's tokenizer integration and tuple-argument run(...). |
causal_llm |
Reusable crate + CLI + OpenAI-compatible HTTP server for NNEF-packaged causal LLMs (Llama-style). Exercises KV-cache unfolding, prompt chunking, repeat-penalty sampling, state freeze/truncate. |
NVIDIA NeMo RNN-Transducer-style ASR pipelines: preprocessor + encoder + decoder + joint network driven as four separate tract models.
| Example | What it shows |
|---|---|
nemo-parakeet-asr |
Parakeet offline ASR on a WAV file; showcases tract::nnef() loading and CPU/GPU runtime selection. |
nemo-nemotron-asr |
Nemotron ASR with a transformers_detect_all transform pass and a patch transform to prune a variable-length input. |
End-to-end text-to-image pipelines with CLIP / T5 text encoders,
transformer / UNet backbones, and VAE decoders. All three pick the best
available runtime (cuda → metal → cpu).
| Example | What it shows |
|---|---|
stable-diffusion |
SD 1.5 txt2img; Euler scheduler built from scratch, classifier-free guidance, 512×512 output. |
stable-diffusion-xl |
SDXL 1.0 txt2img; two text encoders, pooled + hidden-state embeddings, time_ids, 1024×1024 output. |
stable-diffusion-3 |
SD 3 Medium txt2img; MMDiT transformer backbone, optional T5-XXL text encoder, flow-matching scheduler. |
Examples that consume or produce ndarray::ArrayD values call
tract::impl_ndarray_interop!() at their crate root. The macro expands in
the caller's scope, so the ndarray version used is whichever one the
example declares in its Cargo.toml — tract itself no longer re-exports
ndarray. See the macro's rustdoc or onnx-mobilenet-v2/src/main.rs for
the basic pattern.
TensorFlow and TFLite are legacy formats as far as tract is concerned:
the tract-tensorflow and tract-tflite crates are still maintained for
existing users but the tract facade intentionally doesn't expose them,
and that isn't expected to change. Prefer ONNX or NNEF for new work.
| Example | Model source | Notes |
|---|---|---|
tensorflow-mobilenet-v2 |
TensorFlow .pb |
Uses tract-tensorflow directly. |
tflite-mobilenet-v3 |
TFLite | Uses tract-tflite directly. |