HubAI
Overview
Quick Start
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
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
| argument | type | description |
|---|---|---|
path | str | The path to the model file. |
tool_version | str | None | The version of the conversion tool. |
target_precision | Literal["FP32", "FP16", "INT8"] | The precision of the model. Defaults to "INT8". |
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 | YOLO version. |
yolo_class_names | list[str] | None | The class names of the model. |
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. |
RVC3 Parameters
RVC3 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. |
pot_target_device | Literal["VPU", "ANY"] | The target device for the post-training optimization. Defaults to "VPU". |
RVC4 Parameters
RVC4 conversion.| 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. |
Model Parameters
Model resources on HubAI. Please refer here for the detailed overview of all available parameters.CLI Reference
hubai convert --help for the full list of options.Migration from BlobConverter
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.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 | target_precision | The precision of the model. |
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 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
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("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.blobconverterPython
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)
5
6blob = 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
14)HubAI SDKPython
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_pathCaffe Conversion
Caffe framework is not supported.Migration from tools.luxonis.com
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).tar.xz file with all the relevant files downloaded when the conversion finishes. Consider checking the YOLO parameters section for other available flags.