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
  • Conversion from OpenVINO IR
  • Conversion from TFLite
  • Advanced Parameters
  • 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.To perform the conversion directly in Python using the HubAI SDK package, refer to the instructions below.For installation and more information about the HubAI SDK, please refer to the HubAI SDK documentation.

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 team settings.Once you have the API key, you can run the conversion using the following code:
Python
1from hubai_sdk import HubAIClient
2
3client = HubAIClient(api_key=api_key)
4
5converted_model = client.convert.RVC2("path/to/model.onnx")

Python API

The Python API for the online conversion is available under the HubAIClient.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".
output_dirstr | NoneThe directory to save the converted model. If not specified, the model will be saved in the current working directory.

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. Use False if you want legacy RVC2 blob conversion.

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 hubai convert --help for the full list of options.

Migration from BlobConverter

BlobConverter is our previous library for converting models to the BLOB format usable with RVC2 and RVC3 devices. This library is being replaced by modelconverter and HubAI SDK, which 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 HubAI SDK for new projects. The API of HUBAI SDK 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 HubAI SDK, 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 HUBAI SDK. The parameters are grouped by their purpose. The first column shows the parameters of blobconverter, the second column shows the equivalent parameters in HubAI SDK, and the third column contains additional notes.
blobconverterHubAI SDKNotes
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.
By default, HubAI SDK has superblob enabled which is only supported on DepthAI v3. If you want to convert a model to legacy RVC2 format (blob), you can pass superblob=False to the convert.RVC2 function.

Simple Conversion

Simple ONNX conversion using blobconverter
Python
1import blobconverter
2
3blob = blobconverter.from_onnx(
4    model="resnet18.onnx",
5)
Equivalent code using HubAI SDK
Python
1response = client.convert.RVC2(
2    path="resnet18.onnx",
3)
4
5blob = response.downloaded_path

Conversion from OpenVINO IR

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

Conversion from TFLite

blobconverter
Python
1import blobconverter
2
3blob = blobconverter.from_tf(
4    frozen_pb="resnet18.tflite",
5)
Equivalent code using HubAI SDK
Python
1response = client.convert.RVC2(
2    path="resnet18.tflite",
3
4)
5
6blob = response.downloaded_path

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 HubAI SDK
Python
1response = client.convert.RVC2(
2    path="resnet18.onnx",
3    target_precision="FP16",
4    tool_version="2021.4.0",
5    number_of_shaves=6,
6    mo_args=[
7        "mean_values=[127.5,127.5,127.5]",
8        "scale_values=[255,255,255]"
9    ],
10    compile_tool_args=["-ip", "U8"],
11)
12
13blob = response.downloaded_path

Caffe Conversion

Conversion from the Caffe framework is not supported.

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 HubAI online conversion, which will eventually become the only supported way of converting models in the future.Compared to the web application, HubAI online conversion 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 hubai_sdk import HubAIClient
2
3client = HubAIClient(api_key=api_key)
4
5converted_model = client.convert.RVC2(
6    path="yolov6n.pt",
7    yolo_version="yolov6r4",
8)
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.