ModelConverter - Compilation Library


Convert your ONNX, OpenVINO IR and TensorFlow Lite models to a format compatible with any generation of Luxonis camera using the Model Compilation Library.
ModelConverter is in an experimental public beta stage. Some parts might change in the future.
For complete CLI and Python API documentation, see the
ModelConverter documentation and API reference.
Table of Contents
- Installation
- Configuration
- YAML Configuration File
- NN Archive Configuration File
- Online Usage
- Local Usage
- Official Docker Images
- Build Instructions
- Prerequisites
- Building the Images
- Local Image Tagging and CLI Usage
- GPU Support
- Inputs, Outputs and the Cache
- Managing the cache
- Migrating from
shared_with_container
- Running ModelConverter
- Available CLI Options
- Handling Large ONNX Files (Exceeding 2GB)
- Examples
- Multi-Stage Conversion
- Interactive Mode
- Calibration Data
- Inference
- Benchmarking
- [RVC4] DLC model analysis
Installation
The easiest way to use ModelConverter is to use the modelconverter CLI.
The CLI is available on PyPI and can be installed using pip.
pip install modelconv
Run modelconverter --help to see the available commands and options.
Configuration
There are two main ways to configure the conversion process:
- NN Archive:
You can use an NN Archive as input. An NN Archive includes a
config.json file and a model in one of the supported formats: ONNX (.onnx), OpenVINO IR (.xml and .bin), or TensorFlow Lite (.tflite). The config.json file follows a specific configuration format as described under the Configuration section.
- YAML Configuration File (Legacy):
An alternative way to configure the conversion is through a YAML configuration file. For reference, you can check defaults.yaml and other examples located in the configs directory.
Modifying Settings with Command-Line Arguments:
In addition to these two configuration methods, you have the flexibility to override specific settings directly via command-line arguments. By supplying key-value pairs in the CLI, you can adjust particular settings without explicitly altering the config files (YAML or NN Archive). For further details, refer to the Examples section.
In the conversion process, you have options to control the color encoding format in both the YAML configuration file and the NN Archive configuration. Here’s a breakdown of each available flag:
YAML Configuration File
The encoding flag in the YAML configuration file specifies the format that the ONNX model expects (from), and the format that DepthAI will use at runtime (to). It allows you to specify color encoding as follows:
-
Single-Value encoding:
Setting encoding to a single value, such as "RGB", "BGR", "GRAY", or "NONE", will automatically apply this setting to both encoding.from and encoding.to. For example, encoding: RGB sets both encoding.from and encoding.to to "RGB" internally.
-
Multi-Value encoding.from and encoding.to:
Alternatively, you can explicitly set encoding.from and encoding.to to different values. For example:
encoding:
from: RGB
to: BGR
This configuration indicates that the ONNX model expects inputs in RGB format, and the converter will transform the input data to BGR format for DepthAI execution.
[!NOTE]
When encoding is omitted, inputs with a known batched image shape and layout (NCHW or NHWC, with one or three channels) receive image defaults: RGB to BGR, or GRAY for a single channel. Inputs with a known non-image shape or layout default to NONE. A batchless CHW or HWC input is ambiguous and is therefore treated as raw by default; set encoding explicitly if it represents an image. When shape or layout metadata is unavailable, the legacy RGB to BGR default is retained.
[!NOTE]
Certain options can be set globally, applying to all inputs of the model, or per input. If specified per input, these settings will override the global configuration for that input alone. The options that support this flexibility include scale_values, mean_values, encoding, data_type, shape, and layout.
[!NOTE]
A single mean_values or scale_values value is broadcast to every channel. A list must contain either one value to broadcast or one value per channel, and scale values must be non-zero. ONNX preprocessing embedding currently supports NCHW and NHWC inputs.
[!IMPORTANT]
Use RGB, BGR, or GRAY encoding only when the input channels represent an image. Packed tensors, feature maps, and other non-image inputs, including tensors with nonstandard channel counts, must use encoding: NONE, which makes them raw tensor inputs rather than DepthAI image inputs.
NN Archive Configuration File
In the NN Archive configuration, there are two flags related to color encoding control:
-
dai_type:
Provides comprehensive control over the input type, including both color encoding (e.g., RGB, BGR, GRAY) and memory layout (planar NCHW vs. interleaved NHWC). The value of this flag should always reflect what the original ONNX model expects (not what DepthAI will generate at runtime). \
For example:
-
If the ONNX model was trained with RGB planar inputs, use:
"dai_type": "RGB888p"
-
If the ONNX model was trained with BGR interleaved inputs, use:
"dai_type": "BGR888i"
[!NOTE]
You can check the enum Type in the DepthAI API documentation for all possible values of dai_type.
-
reverse_channels (Deprecated):
A simpler flag controlling only channel order:
True: Assumes the ONNX model expects RGB inputs. Since DepthAI always generates BGR images, the converter will insert extra ONNX nodes to swap the channels.
False: Assumes the ONNX model expects BGR inputs. No channel reordering is performed.
This flag is deprecated and will be replaced by the dai_type flag in future versions.
-
interleaved_to_planar (Deprecated):
A legacy NN Archive flag that described whether input data was interleaved (NHWC) or planar (NCHW). ModelConverter preserves the archive's declared layout; use dai_type for current archives.
The flag is retained for compatibility and emits a deprecation warning, but it does not override layout.
This flag is deprecated and will be replaced by the dai_type flag in future versions.
[!NOTE]
If neither dai_type nor reverse_channels are provided, the input to the model is considered to be "RGB".
[!NOTE]
If both dai_type and reverse_channels are provided, the converter will give priority to dai_type.
[!IMPORTANT]
Provide mean/scale values in the original color format used during model training (e.g., RGB or BGR). Any necessary channel permutation is handled internally. Do not reorder values manually.
Online Usage
You can run model conversion directly in the cloud using our HubAI SDK, either with Python or using the CLI.
Local Usage
If you prefer not to share your models with the cloud, you can run the conversion locally.
Official Docker Images
We provide official Docker images for RVC2, RVC3 and RVC4 platforms.
Images for Hailo need to be built manually, as described in the Build Instructions section.
The following images are available on Luxonis GitHub Container Registry:
RVC2
ghcr.io/luxonis/modelconverter-rvc2:2021.4.0-latest
ghcr.io/luxonis/modelconverter-rvc2:2022.3.0-latest
RVC3
ghcr.io/luxonis/modelconverter-rvc3:2022.3.0-latest
RVC4
ghcr.io/luxonis/modelconverter-rvc4:2.32.6-latest
ghcr.io/luxonis/modelconverter-rvc4:2.41.0-latest
Using these prebuilt official images is the recommended way to get started with local conversions. Running a command like the one below will automatically download the latest versions of the default images:
modelconverter convert rvc4 --path <config_or_archive>
or if you want specific publicly available tool version:
modelconverter convert rvc4 --tool-version 2.41.0 --path <config_or_archive>
Build Instructions
[!NOTE]
Build locally only when the official Docker images do not meet your requirements.
Prerequisites
In local mode, ModelConverter requires docker to be installed on your system.
It is recommended to use Ubuntu OS for the best compatibility.
On Windows or MacOS, it is recommended to install docker using the Docker Desktop.
Otherwise, follow the installation instructions for your OS from the official website.
In order for the images to be built successfully, you need to download additional packages depending on the selected platform and the desired version of the underlying conversion tools.
RVC2
Requires openvino-<version>.tar.gz to be present in docker/extra_packages/.
You only need to rename the archive to either openvino-2022.3.0.tar.gz or openvino-2021.4.0.tar.gz and place it in the docker/extra_packages directory.
RVC3
Only the version 2022.3.0 of OpenVino is supported for RVC3. Follow the same instructions as for RVC2 to use the correct archive.
RVC4
Requires snpe-<version>.zip archive to be present in docker/extra_packages. When building locally via the CLI, the tool will attempt to download the archive automatically if it is missing, but only when a full SNPE build version is provided (e.g. 2.41.0.251128) and that version exists in the Qualcomm catalog. If you pass only the short version (e.g. 2.41.0), the CLI expects either the image or archive to already be present. After the first download though you can use the local image with the short or long version.
You can also download different SNPE versions manually from here. After downloading, rename the archive according to the version number and place it in the docker/extra_packages directory.
Example (auto-download only on first build, afterwards available as 2.41.0.251128 or 2.41.0 ):
modelconverter convert rvc4 --tool-version 2.41.0.251128 --path <config_or_archive>
Example (short version, assumes archive or image already present):
# Place the archive ahead of time (or run the command above beforehand):
# docker/extra_packages/snpe-2.41.0.zip
modelconverter convert rvc4 --tool-version 2.41.0 --path <config_or_archive>
HAILO
Requires hailo_ai_sw_suite_<version>:1 docker image to be present on the system. You can obtain the image by following the instructions on Hailo website.
After you obtain the image, you need to rename it to hailo_ai_sw_suite_<version>:1 using docker tag <old_name> hailo_ai_sw_suite_<version>:1.
Building the Images
This section is optional if you are using the modelconverter CLI, as it will automatically build the images for you.
In other cases, navigate to the root directory of the repository and run the following command:
docker build -f docker/$PLATFORM/Dockerfile \
-t luxonis/modelconverter-$PLATFORM:<tool-version>-latest .
If you want to build the image with a different version of the underlying conversion tools than is the default one, you also need to pass the --build-arg flag with the desired version. For example, to build the RVC2 image with 2021.4.0, use:
docker build -f docker/rvc2/Dockerfile \
-t luxonis/modelconverter-rvc2:2021.4.0-latest \
--build-arg VERSION=2021.4.0 .
[!NOTE]
When the --build-arg flag is not provided, the Dockerfiles (docker/<platform>/Dockerfile) fall back to their built-in default tool versions:
- RVC2:
2022.3.0
- RVC4:
2.41.0
Local Image Tagging and CLI Usage
When using locally built Docker images with the modelconverter CLI, there are two supported ways to make sure the CLI uses the correct image. Both approaches are valid and can be chosen based on your workflow.
By default, the CLI looks for images using the following tag pattern:
- RVC2:
luxonis/modelconverter-rvc2:<tool-version>-latest
- RVC4:
luxonis/modelconverter-rvc4:<tool-version>-latest
Where <tool-version> is the value provided via the --tool-version CLI argument.
If you build images with a custom tag (for example, luxonis/modelconverter-rvc2:my-custom-tag), the CLI will not detect them automatically and will instead try to pull the image with the default tag from the registry. You can still use custom-tagged images, but you must explicitly specify them using --image/docker-image, as described in Option 2 below.
Option 1: Version-Matched Image Tagging
In this approach, you tag your locally built images using the <version>-latest scheme so that they are automatically discovered by the CLI when --tool-version is provided.
Example for RVC2 with OpenVINO 2021.4.0:
docker build -f docker/rvc2/Dockerfile \
-t luxonis/modelconverter-rvc2:2021.4.0-latest \
--build-arg VERSION=2021.4.0 .
Then run the CLI with:
modelconverter convert rvc2 --tool-version 2021.4.0 --path <config_or_archive>
This option works well if you want your locally built images to behave exactly like the official images expected by the CLI.
Option 2: Explicit Image Selection via --image/docker-image
Alternatively, you can explicitly tell the CLI which Docker image to use via the --image/docker-image option.
--image/docker-image accepts the full Docker image name.
- If the value includes a tag (for example
luxonis/modelconverter-rvc4:my-custom-tag), it is used exactly as provided.
- If the value does not include a tag, the CLI uses the image name as provided and appends a tag constructed using the existing logic based on the
--tool-version (i.e. <tool-version>-latest or <tool-version>-dev).
- When
--image/docker-image is provided with an explicit tag, it takes precedence over --tool-version, which is ignored.
This option removes the need to re-tag locally built images and is recommended when working with custom images or non-standard tagging schemes.
Example using a fully specified image name:
modelconverter convert rvc4 \
--image luxonis/modelconverter-rvc4:my-custom-tag \
--path <config_or_archive>