Getting started: Python and ML developers¶
This page turns a PyTorch model into a bundle that any Flutter app can load.
Install¶
doctor lists which optional packages are installed and what to add for each feature.
Export¶
This writes dist/mobilenet_v3_small/:
| File | What it is |
|---|---|
modelport.json |
The manifest: inputs, preprocessing, outputs, labels, files, checksums |
onnx-fp32/model.onnx |
ONNX variant |
executorch-xnnpack-fp32/model.pte |
ExecuTorch variant |
labels.txt |
Class names |
golden/*.bin |
A saved input and PyTorch's output for it |
Sources can also be Hugging Face models (hf:facebook/deit-tiny-patch16-224) or your own code (file:my_model.py:build). See the CLI reference.
Make smaller variants¶
Each new variant is measured against PyTorch and gets a matching tolerance. See Smaller models.
Verify¶
variant ┃ output ┃ max diff ┃ cosine ┃ top-1 ┃ result
━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━╇━━━━━━━━━━╇━━━━━━━━━━╇━━━━━━━╇━━━━━━━━
onnx-fp32 │ logits │ 3.34e-05 │ 1.000000 │ same │ pass
executorch-xnnpack-fp32 │ logits │ 3.34e-05 │ 1.000000 │ same │ pass
onnx-fp16 │ logits │ 1.05e-01 │ 0.999952 │ same │ pass
onnx-int8 │ logits │ 1.27e-01 │ 0.999933 │ same │ pass
Publish¶
Needs the gh CLI, logged in. Apps load
https://github.com/you/models/releases/download/v1/mobilenet_v3_small.json.
Use it from Dart with types¶
This writes a class whose inputs and outputs are named fields, so a typo in a tensor name is a compile error.