HubAI
Overview
Quick Start
hubai-sdk and configure HUBAI_API_KEY as described in the HubAI SDK page, then run a conversion:Python
1import os
2
3from hubai_sdk import HubAIClient
4
5client = HubAIClient(api_key=os.getenv("HUBAI_API_KEY"))
6
7response = client.convert.RVC2(
8 path="path/to/model.onnx",
9 name="my-converted-model",
10)
11
12print(response.downloaded_path)Python API
HubAIClient.convert namespace. Use target-specific helpers such as convert.RVC2 and convert.RVC4 when the target is fixed.There is also a generic conversion entrypoint if you want to choose the target programmatically:Python
1from hubai_sdk.utils.types import Target
2
3response = client.convert.convert(
4 Target.RVC2,
5 path="path/to/model.onnx",
6 name="my-converted-model",
7)General Parameters
| argument | type | description |
|---|---|---|
path | str | The path to the model file. |
tool_version | str | None | The version of the conversion tool. |
quantization_mode | Literal["INT8_STANDARD", "INT8_ACCURACY_FOCUSED", "INT8_INT16_MIXED", "INT8_INT16_MIXED_ACCURACY_FOCUSED", "FP16_STANDARD", "FP32_STANDARD"] | Quantization or precision preset used by targets that support it, for example INT8_STANDARD or FP16_STANDARD. |
output_dir | str | None | The directory to save the converted model. If not specified, the model will be saved in the current working directory. |
YOLO Parameters
| argument | type | description |
|---|---|---|
yolo_input_shape | list[int] | None | The input shape of the YOLO model. |
yolo_version | str | None | Optional YOLO version override, for example "yolov8". If omitted, the backend attempts to detect the version automatically from the PyTorch model file. |
yolo_class_names | list[str] | None | The class names of the model. |
yolo_version explicitly for YOLO conversions. If it is omitted, the backend attempts to detect the version automatically. The PyTorch model file still needs to come from one of the supported YOLO versions.RVC2 Parameters
RVC2 conversion.| argument | type | description |
|---|---|---|
mo_args | list[str] | None | The arguments to pass to the model optimizer. |
compile_tool_args | list[str] | None | The arguments to pass to the BLOB compiler. |
compress_to_fp16 | bool | Whether to compress the model's weights to FP16 precision. Defaults to True. |
number_of_shaves | int | The number of shaves to use. Defaults to 8. |
superblob | bool | Whether to create a superblob. Defaults to True. Use False if you want legacy RVC2 blob conversion. |
RVC4 Parameters
RVC4 conversion.When converting for
RVC4, choose an SNPE version that matches your deployment environment. See the SNPE compatibility table in Conversion Troubleshooting.| argument | type | description |
|---|---|---|
snpe_onnx_to_dlc_args | list[str] | None | The arguments to pass to the snpe-onnx-to-dlc tool. |
snpe_dlc_quant_args | list[str] | None | The arguments to pass to the snpe-dlc-quant tool. |
snpe_dlc_graph_prepare_args | list[str] | None | The arguments to pass to the snpe-dlc-graph-prepare tool. |
use_per_channel_quantization | bool | Whether to use per-channel quantization. Defaults to True. |
use_per_row_quantization | bool | Whether to use per-row quantization. Defaults to False. |
htp_socs | list[str] | None | The list of HTP SoCs to use. |
name, model_id, variant_id, variant_version, and input_shape. For those workflows and the broader SDK surface, see the HubAI SDK page.CLI Reference
Command Line
1hubai login
2hubai convert RVC2 --path /path/to/model.onnx --name "my-model"hubai convert --help for the full list of options.Migration from BlobConverter
HubAI SDK, which are the supported paths going forward.blobconverter is still available and can be used for conversion, but we recommend HubAI SDK for new projects. The API is similar, but there are differences in parameter names and in how conversion is executed.blobconverter offers several functions for converting models from different frameworks, such as from_onnx, from_openvino, and from_tf. These functions are replaced by convert.RVC2 in HubAI SDK, which takes a single path argument pointing to the model input.The following table shows the mapping between the parameters of blobconverter and HubAI SDK.blobconverter | HubAI SDK | Notes |
|---|---|---|
model | path | The model file path. |
xml | path | The XML file path. Only for conversion from OpenVINO IR. |
bin | opts["input_bin"] | The BIN file path. Only for conversion from OpenVINO IR. |
version | tool_version | The version of the conversion tool. |
data_type | compress_to_fp16 | Use True for FP16-compressed weights and False otherwise. RVC2 does not use quantization_mode. |
shaves | number_of_shaves | The number of shaves to use. |
optimizer_params | mo_args | The arguments to pass to the model optimizer. |
compile_params | compile_tool_args | The arguments to pass to the BLOB compiler. |
HubAI SDK enables superblob, which is only supported on DepthAI v3. If you want to convert a model to the legacy RVC2 blob format, pass superblob=False to convert.RVC2.Simple Conversion
blobconverterPython
1import blobconverter
2
3blob = blobconverter.from_onnx(
4 model="resnet18.onnx",
5)HubAI SDKPython
1response = client.convert.RVC2(
2 path="resnet18.onnx",
3)
4
5blob = response.downloaded_pathConversion from OpenVINO IR
blobconverter examplePython
1import blobconverter
2
3blob = blobconverter.from_openvino(
4 xml="resnet18.xml",
5 bin="resnet18.bin",
6)HubAI SDK examplePython
1# When the XML and BIN files are at the same location,
2# only the XML needs to be specified.
3response = client.convert.RVC2(path="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_pathConversion from TFLite
HubAI online conversion does not support conversion from frozen PB files. Only TFLite files are supported.
blobconverter examplePython
1import blobconverter
2
3blob = blobconverter.from_tf(
4 frozen_pb="resnet18.tflite",
5)HubAI SDKPython
1response = client.convert.RVC2(
2 path="resnet18.tflite",
3)
4
5blob = response.downloaded_pathAdvanced Parameters
blobconverter.from_onnx with advanced parametersPython
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)HubAI SDKPython
1response = client.convert.RVC2(
2 path="resnet18.onnx",
3 tool_version="2021.4.0",
4 number_of_shaves=6,
5 mo_args=[
6 "mean_values=[127.5,127.5,127.5]",
7 "scale_values=[255,255,255]",
8 ],
9 compile_tool_args=["-ip", "U8"],
10)
11
12blob = response.downloaded_pathCaffe Conversion
Caffe framework is not supported.Migration from tools.luxonis.com
.pt file to an RVC2-compatible .superblob:Python
1import os
2
3from hubai_sdk import HubAIClient
4
5client = HubAIClient(api_key=os.getenv("HUBAI_API_KEY"))
6
7converted_model = client.convert.RVC2(
8 path="yolov6n.pt",
9 yolo_version="yolov6r4",
10).tar.xz bundle when the job finishes. For additional YOLO-specific flags, see the YOLO parameters section.