Simplicity Machine Learning Converter#

Overview#

The Converter is part of the Simplicity Machine Learning suite of tools. It converts PyTorch and ONNX models into TensorFlow Lite (.tflite) format for deployment on Silicon Labs embedded devices. The Silicon Labs ML toolchain currently consumes .tflite models; this tool bridges common training workflows (PyTorch, ONNX) without requiring a separate runtime.

The converter enables you to:

  • Convert PyTorch models (.pt, .pth) to .tflite using litert-torch

  • Convert ONNX models (.onnx) to .tflite using onnx2tf

  • Optionally generate conversion metadata (manifest.json) and a diagnostic log (conversion.log when --log-level info or debug)

  • Use the same conversion engine from the Simplicity Machine Learning GUI and CLI (sml convert)

The tool is available as:

  • A graphical interface (GUI) — the Converter is integrated into the Simplicity Machine Learning application GUI.

  • A command-line interface (CLI) called sml convert.

NOTE: The Converter (sml convert) is only available in Simplicity Machine Learning (or sml on the CLI) version 1.1.0-beta or later. If you installed an older Simplicity Machine Learning (GUI) or (CLI) package before this release, upgrade through Simplicity Installer or SLT so the Converter functionality on the GUI and sml convert command on the CLI are available.

Scope of This Tool#

This documentation is written primarily for embedded and ML engineers who have trained or exported a model in PyTorch or ONNX and need a .tflite file for Silicon Labs projects.

To work with trained models, you must have familiarity with ML concepts to run conversion and interpret validation results.

NOTE: The converter does not train models or measure on-device execution performance.

NOTE: PyTorch conversion requires Linux, WSL2 (on Windows), or MacOS and Python 3.12. See Limitations for platform and environment constraints.

Key Concepts and Terminology#

Term

Description

LiteRT

Google's edge inference stack (formerly TensorFlow Lite)

TFLite / .tflite

Serialized LiteRT model format used by Silicon Labs tooling

PyTorch model

A trained model saved as .pt or .pth

ONNX model

Framework-agnostic model in .onnx format

Representative dataset

Preprocessed sample inputs used for full-INT8 quantization

input_shape

Fixed dimensions for the model input tensor (required for PyTorch conversion)

manifest.json

Optional metadata file describing the conversion run

Supported Input and Output#

Input Models#

Format

Extension

Note

PyTorch

.pt, .pth

Must contain a full nn.Module (not state-dict-only) or an Ultralytics YOLO checkpoint. --input-shape required

ONNX

.onnx

Self-contained file (no external weight files). --input-shape required only if inputs have dynamic dimensions

Format detection uses file extensions (.pt, .pth, .onnx). Invalid content is reported when the model is loaded.

Output artifacts#

Artifact

Required

Description

model.tflite

Yes

Primary output; path defaults from the source filename in the current working directory unless --output is set (CLI)

manifest.json

No

Conversion metadata when --save-manifest (CLI)

conversion.log

No

Diagnostic trace when --log-level info or debug(CLI)

Usage#

sml convert --help
Usage: sml convert <input_model> [options]

Convert PyTorch or ONNX model to TFLite format.

Arguments:
  input_model                 Input model file path (.pt, .pth, .onnx)

Options:
  -o, --output PATH           Output .tflite path (auto-generated if omitted)
  --input-shape SHAPE         Input shape for PyTorch (e.g. 1,3,224,224); required for .pt/.pth
  --quantize MODE             Quantization mode: dynamic_int8 or full_int8; omit for float32
  --calibration-data PATH     Calibration data (`.npy` for one input or `.npz` for multiple inputs); required for full_int8
  --pytorch-backend NAME      PyTorch conversion backend: litert (default) or ultralytics
  --save-manifest             Generate manifest.json
  --log-level <level>         Logging verbosity: error|warning|info|debug
                              (default: error; info and debug write conversion.log)
  -v, --verbose               Verbose output
  -h, --help                  Show help

Examples:

# PyTorch — input shape required
sml convert model.pt --input-shape 1,3,224,224

# ONNX — custom output path
sml convert model.onnx --output output/model.tflite

# Full-INT8 quantization
sml convert model.pt --input-shape 1,3,224,224 --quantize full_int8 --calibration-data calibration_data.npy --output output/model_full_int8.tflite

# With optional artifacts
sml convert model.pt --input-shape 1,3,224,224 --save-manifest --log-level info

NOTE:

The converter produces a float32 .tflite model by default. Full-INT8 quantization requires --quantize full_int8 and --calibration-data. Calibration data must contain preprocessed model inputs, not labels. A full-INT8 model has INT8 input and output tensors.

Calibration Data for Full INT8#

Calibration data is a set of representative, preprocessed model input samples stored in binary NumPy files: .npy stores one array and .npz stores named arrays. Include only input tensor values. Do not include labels, image files, or filenames. Use numpy.load() to inspect these files.

For a single-input model, provide a .npy file that contains an array with shape [N, ...], where N is the number of representative samples. The dimensions after N must match the input layout of the converted TFLite model.

For example:

import numpy as np

# ONNX models converted through onnx2tf commonly use NHWC layout.
# N representative 224 x 224 RGB images:
calibration_data = np.stack(preprocessed_images).astype(np.float32)
# Example shape: (N, 224, 224, 3)

np.save("calibration_data.npy", calibration_data)

Use the same resizing, channel order, normalization, and scaling as inference. PyTorch models converted through LiteRT commonly use channels-first layout, for example [N, 3, 224, 224].

For a multi-input model, provide a .npz file with one array for each input. All arrays must have the same number of samples N. The keys must match the input names of converted TFLite model. For example:

np.savez(
    "calibration_data.npz",
    input_a=input_a_samples,
    input_b=input_b_samples,
)
with np.load("calibration_data.npz") as loaded:
    print(loaded.files)
    print(loaded["input_a"].shape, loaded["input_a"].dtype)
    print(loaded["input_b"].shape, loaded["input_b"].dtype)
# Output:
# ['input_a', 'input_b']
# (N, 4) float32
# (N, 4) float32

Replace input_a and input_b with the converted TFLite model input names.

Converting a Model from the GUI#

Install Simplicity Machine Learning (GUI) version 1.1.0-beta or later (see Installation).

Launch Simplicity Machine Learning#

  1. Launch from Simplicity Studio v6:

    1. Open Simplicity Studio and navigate to the Tools tab on the left panel.

    2. Hover on Simplicity Machine Learning and click the Play icon that appears on the right side.

  2. Or, launch from the command line:

    slt launch sml
  3. Open the Convert tab in the application.

Convert a PyTorch Model (.pt / .pth)#

  1. Click Browse and select your PyTorch model file (.pt or .pth). A file-selection dialog opens for supported model types.

    Browse for PyTorch modelBrowse for PyTorch model

  2. The tool detects the PyTorch format from the file extension. Enter input shape (for example, 1,3,224,224) — this field is required for PyTorch models.

    PyTorch model with input shapePyTorch model with input shape

  3. Select a Quantization mode, and then select Full INT8 to create a full-INT8 model.

  4. Select Browse next to Calibration Data and select the representative calibration-data file (.npy or .npz).

  5. Click Convert and wait while conversion runs. Progress and status updates appear in the UI.

    PyTorch conversion in progressPyTorch conversion in progress

  6. When conversion completes, download or save the generated .tflite file.

Convert an ONNX Model (.onnx)#

  1. Click Browse and select your ONNX model file (.onnx).

    Browse for ONNX modelBrowse for ONNX model

  2. For ONNX models with fixed input shapes, input shape is not required. The Convert control is available once the model file is selected.

    ONNX model ready to convertONNX model ready to convert

  3. Select a Quantization mode, and then select Full INT8 to create a full-INT8 model.

  4. Select Browse next to Calibration Data and select the representative calibration-data file (.npy or .npz).

  5. Click Convert and wait for conversion to finish.

  6. Download or save the generated .tflite file.

Optional Artifacts#

manifest.json#

When you pass --save-manifest on the CLI , the converter writes a manifest.json file next to the output .tflite. Use this optional file to audit a conversion in development or CI: it records what was converted, how long it took, and whether any warnings or errors occurred.

The file includes:

  • conversion — source and output paths, detected format, converter version, and duration

  • model_info — input and output tensor shapes

  • file_info — source and output file sizes and compression ratio

  • warnings and errors — messages collected during the run (empty when none)

Example structure:

{
  "version": "1.0",
  "conversion": {
    "source_model": "/path/to/model.onnx",
    "source_format": "onnx",
    "output_model": "/path/to/model.tflite",
    "converter_version": "1.0.0",
    "duration_seconds": 12.5
  },
  "model_info": {
    "input_shapes": { "input": [1, 224, 224, 3] },
    "output_shapes": { "output": [1, 1000] }
  },
  "file_info": {
    "source_size_bytes": 5242880,
    "output_size_bytes": 2621440,
    "compression_ratio": 2.0
  },
  "warnings": [],
  "errors": []
}

Validating Converted Models#

A conversion is valid when the .tflite model produces functionally equivalent outputs to the source model for representative inputs.

Validation criteria:

  • Output similarity — converted outputs match source outputs within tolerance (for example, cosine similarity ≥ 0.99, numerical error < 5%)

  • Structural integrity — the .tflite file loads successfully and tensor shapes match expectations

Compare source and converted models using the same test inputs before deploying to hardware. Numerical parity is not bit-exact; small drift (for example, relative tolerance rtol≈1e-3) is normal.

Limitations#

Environment and Platform#

  • Python 3.12 only (>=3.12,<3.13); Python 3.11 and 3.13+ are not supported.

  • Linux, WSL2 or MacOS is required for PyTorch conversion (litert_torch).

  • CPU-only conversion; GPU conversion is not supported.

  • Native Windows PyTorch conversion is generally not supported for this stack. Prefer Linux ,WSL2 or MacOS. See litert-torch#968.

Input formats and models#

  • Supported inputs are PyTorch (.pt, .pth) and ONNX (.onnx) only.

  • PyTorch files must contain a full nn.Module (torch.save(model) or a dict with a "model" key). State-dict-only files are rejected. Ultralytics YOLO .pt and .pth checkpoints are also supported.

  • input_shape is required for PyTorch conversion (for example, 1,3,224,224).

  • The PyTorch path supports a single input tensor only.

  • ONNX models must be self-contained (no external weight files).

  • For ONNX models with dynamic input dimensions, provide input_shape (multi-input: name1:d1,d2;name2:...).

Conversion Behavior#

  • The converter produces a float32 .tflite model by default. Use --quantize full_int8 with calibration data to generate a full-INT8 model.

  • Ultralytics YOLO .pt and .pth checkpoints are detected automatically and converted through the Ultralytics backend. Provide an input pattern, such as 1,3,640,640.

  • A few PyTorch or ONNX operators are not supported. Unsupported operators fail with diagnostic messages.

  • Models with data-dependent control flow, .item() / .tolist() in the forward path, or multiple non-tensor inputs may fail during torch.export.

  • ONNX output file size may differ from the source ONNX file due to graph layout changes (NCHW → NHWC) and FlatBuffer encoding.

Summary#

The Silicon Labs sml convert command converts supported PyTorch and ONNX models to .tflite format. Validate outputs before deployment and use optional manifest.json to audit conversions in development and CI.

Troubleshooting#

sml convert not found or Convert tab missing

You may have an older Simplicity Machine Learning package installed. The converter requires version 1.1.0-beta or later. Check your version with sml --version, then upgrade Simplicity Machine Learning (GUI) and/or (CLI) through Simplicity Installer or by re-running slt install sml / slt install sml-cli.

Input file not found

Verify the path to .pt, .pth, or .onnx is correct and readable.

Unsupported file extension

Only .pt, .pth, and .onnx are accepted. Rename or re-export the model in a supported format.

PyTorch: missing or invalid input shape

Provide --input-shape on the CLI with batch, channels, height, and width (for example, 1,3,224,224). The tool may infer shape from the saved model in some cases; if inference fails, set it explicitly.

PyTorch: state-dict-only file

Instantiate the model architecture, load the state dict, and save the full nn.Module before converting.

PyTorch conversion fails during tracing

Ensure the model is in evaluation mode, uses float32 weights, and avoids data-dependent control flow. See LiteRT PyTorch conversion.

ONNX conversion fails operator validation

Check operator support and model structure. Ensure the ONNX file is self-contained.

Outputs differ significantly from the source model

Re-run validation with representative inputs. A small numerical drift is expected.

Full-INT8 quantization fails

Use --quantize full_int8 together with --calibration-data. The calibration file must be non-empty and contain preprocessed representative inputs in .npy or .npz format.

Platform or Python version errors

Use Python 3.12 on Linux, WSL2 or MacOS for PyTorch conversion. Do not rely on native Windows for the PyTorch path.

References#