ON THIS PAGE

  • HubAI
  • Overview
  • Quick Start
  • Python API
  • General Parameters
  • YOLO Parameters
  • RVC2 Parameters
  • RVC3 Parameters
  • RVC4 Parameters
  • Model Parameters
  • CLI Reference
  • Migration from BlobConverter
  • Simple Conversion
  • Advanced Parameters
  • Conversion from OpenVINO IR
  • Conversion from
  • Migration from tools.luxonis.com

HubAI

Overview

HubAI utilizes ModelConverter in the cloud. It's a convenient way to convert your model to any RVC compiled format of the platform you aim to utilize. Please consult to the HubAI Conversion guidelines for more information.If you want to use the Python API instead for online conversion directly using the Modelconverter package see the instructions below.

Quick Start

In order to use the online conversion, you first need to obtain an API key from HubAI. You can do this by signing up for a free account and generating an API key in the settings.Once you have the API key, you can run the conversion using the following code:
Python
1from modelconverter.hub import convert
2
3converted_model = convert.RVC2("path/to/model.onnx", api_key=api_key)

Python API

The Python API for the online conversion is available under the modelconverter.hub.convert namespace. Specific conversion functions for individual targets (RVC2, RVC4, etc.) are accessible from the convert namespace under the target name, for example convert.RVC2, convert.RVC4.The conversion function takes a number of parameters to specify the model and the conversion options. Here we list the main ones to get you started, but consider checking out the full API documentation.

General Parameters

General parameters applicable to all conversion functions.
argumenttypedescription
pathstrThe path to the model file.
tool_versionstr | NoneThe version of the conversion tool.
target_precisionLiteral["FP32", "FP16", "INT8"]The precision of the model. Defaults to "INT8".
api_keystr | NoneThe API key for HubAI. It will take precedence over the environment.

YOLO Parameters

These parameters are only relevant if you're converting a YOLO model.
argumenttypedescription
yolo_input_shapelist[int] | NoneThe input shape of the YOLO model.
yolo_versionstr | NoneYOLO version.
yolo_class_nameslist[str] | NoneThe class names of the model.
Check out the list of all yolo versions here.

RVC2 Parameters

Parameters specific to the RVC2 conversion.
argumenttypedescription
mo_argslist[str] | NoneThe arguments to pass to the model optimizer.
compile_tool_argslist[str] | NoneThe arguments to pass to the BLOB compiler.
compress_to_fp16boolWhether to compress the model's weights to FP16 precision. Defaults to True.
number_of_shavesintThe number of shaves to use. Defaults to 8.
superblobboolWhether to create a superblob. Defaults to True.

RVC3 Parameters

Parameters specific to the RVC3 conversion.
argumenttypedescription
mo_argslist[str] | NoneThe arguments to pass to the model optimizer.
compile_tool_argslist[str] | NoneThe arguments to pass to the BLOB compiler.
compress_to_fp16boolWhether to compress the model's weights to FP16 precision. Defaults to True.
pot_target_deviceLiteral["VPU", "ANY"]The target device for the post-training optimization. Defaults to "VPU".

RVC4 Parameters

Parameters specific to the RVC4 conversion.
argumenttypedescription
snpe_onnx_to_dlc_argslist[str] | NoneThe arguments to pass to the snpe-onnx-to-dlc tool.
snpe_dlc_quant_argslist[str] | NoneThe arguments to pass to the snpe-dlc-quant tool.
snpe_dlc_graph_prepare_argslist[str] | NoneThe arguments to pass to the snpe-dlc-graph-prepare tool.
use_per_channel_quantizationboolWhether to use per-channel quantization. Defaults to True.
use_per_row_quantizationboolWhether to use per-row quantization. Defaults to False.
htp_socslist[str] | NoneThe list of HTP SoCs to use.

Model Parameters

You can use this API to also create new Model resources on HubAI. Please refer here for the detailed overview of all available parameters.

CLI Reference

The conversion can also be done using the command line interface. See modelconverter hub --help for the full list of options.

Migration from BlobConverter

BlobConverter is our legacy library for converting models to the BLOB format usable with RVC2 and RVC3 devices. This library is being replaced by modelconverter, which will eventually become the only supported way of converting models in the future.blobconverter is still available and can be used for conversion, but we recommend using modelconverter for new projects. The API of modelconverter is similar to that of blobconverter, but there are some differences in the parameters and the way the conversion is done.blobconverter offers several functions for converting models from different frameworks, such as from_onnx, from_openvino, and from_tf. These functions are now replaced by the convert.RVC2 (or convert.RVC3) function in modelconverter, which takes a single argument path that specifies the path to the model file.The following table shows the mapping between the parameters of blobconverter and modelconverter. The parameters are grouped by their purpose. The first column shows the parameters of blobconverter, the second column shows the equivalent parameters in modelconverter, and the third column contains additional notes.
blobconvertermodelconverterNotes
modelpathThe model file path.
xmlpathThe XML file path. Only for conversion from OpenVINO IR
binopts["input_bin"]The BIN file path. Only for conversion from OpenVINO IR.
versiontool_versionThe version of the conversion tool.
data_typetarget_precisionThe precision of the model.
shavesnumber_of_shavesThe number of shaves to use.
optimizer_paramsmo_argsThe arguments to pass to the model optimizer.
compile_paramscompile_tool_argsThe arguments to pass to the BLOB compiler.

Simple Conversion

Simple ONNX conversion using blobconverter
Python
1import blobconverter
2
3blob = blobconverter.from_onnx(
4    model="resnet18.onnx",
5)
Equivalent code using modelconverter.hub.convert.RVC2
Python
1from modelconverter.hub import convert
2
3blob = convert.RVC2(
4    path="resnet18.onnx",
5)

Advanced Parameters

blobconverter.from_onnx with advanced parameters
Python
1import blobconverter
2
3blob = blobconverter.from_onnx(
4    model="resnet18.onnx",
5    data_type="FP16",
6    version="2021.4",
7    shaves=6,
8    optimizer_params=[
9        "--mean_values=[127.5,127.5,127.5]",
10        "--scale_values=[255,255,255]",
11 ],
12    compile_params=["-ip U8"],
13
14)
Equivalent code using modelconverter
Python
1from modelconverter.hub import convert
2
3blob = convert.RVC2(
4    path="resnet18.onnx",
5    target_precision="FP16",
6    tool_version="2021.4.0",
7    number_of_shaves=6,
8    mo_args=[
9        "mean_values=[127.5,127.5,127.5]",
10        "scale_values=[255,255,255]"
11 ],
12    compile_tool_args=["-ip", "U8"],
13)

Conversion from OpenVINO IR

blobconverter example
Python
1import blobconverter
2
3blob = blobconverter.from_openvino(
4    xml="resnet18.xml",
5    bin="resnet18.bin",
6)
modelconverter example
Python
1from modelconverter.hub import convert
2
3# When the XML and BIN files are at the same location,
4# only the XML needs to be specified
5blob = convert.RVC2("resnet18.xml")
6
7# Otherwise, the BIN file can be specified using
8# the `opts` parameter
9blob = convert.RVC2(
10    path="resnet18.xml",
11    opts={
12        "input_bin": "resnet18.bin",
13 }
14)

Conversion from tflite

blobconverter
Python
1import blobconverter
2
3blob = blobconverter.from_tf(
4    frozen_pb="resnet18.tflite",
5)
Equivalent code using modelconverter.hub.convert.RVC2
Python
1from modelconverter.hub import convert
2
3blob = convert.RVC2(
4    path="resnet18.tflite",
5
6)

Migration from tools.luxonis.com

Tools web app hosted on tools.luxonis.com is our legacy application for easily converting YOLO based object detection models. This is now being replaced by modelconverter, which will eventually become the only supported way of converting models in the future.Compared to the web application, modelconverter also adds support for converting instance segmentation, pose, oriented detection, and classification YOLOs (check out the full list of supported models here).Here is an example of how to easily convert an existing .pth file to a RVC2 compatible .superblob format.
Python
1from modelconverter.hub import convert
2
3converted_model = convert.RVC2("yolov6n.pt", yolo_version="yolov6r4", api_key=api_key)
This will use our Hub cloud service to make a conversion, and you'll get a .tar.xz file with all the relevant files downloaded when the conversion finishes. Consider checking the YOLO parameters section for other available flags.