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 themodelconverter.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.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" . |
api_key | str | None | The 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.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
Parameters specific to theRVC2
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 . |
RVC3 Parameters
Parameters specific to theRVC3
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
Parameters specific to theRVC4
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
You can use this API to also create newModel
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. Seemodelconverter hub --help
for the full list of options.Migration from BlobConverter
BlobConverter is our legacy library for converting models to the BLOB format usable withRVC2
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.blobconverter | modelconverter | 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. |
If you want to get the exported model in the .blob format instead of .superblob then set
superblob=False
.Simple Conversion
Simple ONNX conversion usingblobconverter
Python
1import blobconverter
2
3blob = blobconverter.from_onnx(
4 model="resnet18.onnx",
5)
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 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)
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
examplePython
1import blobconverter
2
3blob = blobconverter.from_openvino(
4 xml="resnet18.xml",
5 bin="resnet18.bin",
6)
modelconverter
examplePython
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
modelconverter
does not support conversion from frozen PB files, only TFLITE files are supported.blobconverter
Python
1import blobconverter
2
3blob = blobconverter.from_tf(
4 frozen_pb="resnet18.tflite",
5)
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 bymodelconverter
, 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)
.tar.xz
file with all the relevant files downloaded when the conversion finishes. Consider checking the YOLO parameters section for other available flags.