During the model quantized compilation, the hb_compile tool generates intermediate stage onnx models as well as hbm model that can be used for on-board deployment based on the specific information in the configuration file.
The hb_compile provides two modes when doing the model quantized compilation, fast performance evaluation mode (with fast-perf turned on) and traditional model conversion compilation mode (without fast-perf turned on).

The fast performance evaluation mode, when turned on, will generate the hbm model that can have the highest performance when running on the board side during the conversion process, and the tool internally performs the following operations:
| Parameter Name | Parameter Description |
-h, --help | Show help information and exit. |
-c, --config | Configuration file for the model compilation, in YAML format. |
--fast-perf | Turn on fast-perf, which will generate the hbm model that can have the highest performance when running on the board side during the conversion process,
so that you can easily use it for the model performance evaluation later.
-i, --input-shape, Optional parameter that specifies the shape of the input node of the model.
When using hb_compile for model quantized compilation, this configuration only takes effect when fast-perf is turned on currently.
It is used in the following way:
For the non-dynamic input model, --input-shape can be left unconfigured and the tool will automatically read the size information from the model file.For the dynamic input model:
|
--skip | If you don't focus on the compile process and its output during the accuracy debugging stage, you can use this parameter configuration as compile to skip the compilation stage. |
The log file generated by the compilation will be stored in the directory where the command is executed under the default name hb_compile.log.
If you want to use the fast performance evaluation mode (i.e., turn on fast-perf), the reference command is as follows:
-config parameter as the tool uses the built-in high-performance configuration in this mode.--input-shape parameter configuration only works in fast performance evaluation mode (i.e. fast-perf is turned on).If you want to use the traditional model conversion compilation mode (without fast-perf enabled), you can refer to the following command:
The configuration file mainly contains model parameters, input information parameters, calibration parameters, compilation parameters. All parameter groups must exist in your configuration file. Parameters can be divided into the optional and the mandatory, while the optional parameters can be left unconfigured.
The following is the specific parameter information, the parameters will be more, we follow the order of the parameter group to introduce. Required/Optional indicates whether this parameter must be specified in the Yaml file.
| Parameter Name | Parameter Description | Required/Optional |
prototxt | PURPOSE: This parameter specifies the prototxt filename of the floating-point Caffe model. | Caffe module required |
caffe_model | PURPOSE: This parameter specifies the caffemodel filename of the floating-point Caffe model. | Caffe module required |
onnx_model | PURPOSE: This parameter specifies the onnx filename of the floating-point ONNX model. | ONNX module required |
march | PURPOSE: This parameter specifies the platform architecture to run the board-side deployable model. | required |
output_model_file_prefix | PURPOSE: This parameter specifies the prefix of the board-side deployable model filename. | optional |
working_dir | PURPOSE: This parameter specifies the directory to save the conversion results. | optional |
output_nodes | PURPOSE: This parameter specifies model output node(s). | optional |
remove_node_type | PURPOSE: This parameter sets the type of the deleted node. Attention: After setting this parameter, we will match the deletable nodes of the model according to your configuration. If the node type you configured to be deleted meets the deletion conditions, it will be deleted and this process will be repeated until the deletable nodes can not be matched with the configured node type. | optional |
remove_node_name | PURPOSE: This parameter sets the name of the deleted node. Attention: After setting this parameter, we will match the deletable nodes of the model according to your configuration. If the node name you configured to be deleted meets the deletion conditions, it will be deleted and this process will be repeated until the deletable nodes can not be matched with the configured node name. | optional |
debug_mode | PURPOSE: Set debugging parameters for accuracy analysis.
Attention: It is not supported to configure input_source to be resizer after setting dump_all_layers_output. | optional |
| Parameter Name | Parameter Description | Required/Optional |
input_name | PURPOSE: This parameter specifies the input node names of the original floating-point model. | Dynamic input: required Non-Dynamic input: Optional for single input Required for multiple inputs |
input_type_train | PURPOSE: This parameter specifies the input data type of the original floating-point model. | optional |
input_type_rt | PURPOSE: This parameter specifies the input data format that the board-side deployable model obtained after conversion must match. Attention: When | optional |
input_layout_train | PURPOSE: This parameter specifies the input data layout of the original floating-point model. | Required for model with non-featuremap input Ineffective for model with featuremap input, so no configuration is needed |
input_space_and_range | PURPOSE: This parameter specifies special data formats.
Attention: You don't need to configure this parameter without explicit requirements. | optional |
input_shape | PURPOSE: This parameter specifies the input data size of the original floating-point model. | Dynamic input: required Non-Dynamic input: optional |
input_batch | PURPOSE: This parameter specifies the input data batch size that the board-side deployable model obtained after conversion must match. Attention:
| optional |
separate_batch | PURPOSE: This parameter specifies whether to enable the separated batch mode. | optional |
separate_name | PURPOSE: When separated batch mode is not enabled, the parameter specifies the split node names. | optional |
mean_value | PURPOSE: This parameter specifies the mean value to be subtracted by the pre-processing method. | optional |
scale_value | PURPOSE: This parameter specifies the scale factor of the pre-processing method. | optional |
std_value | PURPOSE: This parameter specifies the std factor of the pre-processing method. | optional |
input_type_rt/input_type_train additional description
The camera captured data are usually in NV12 format. Therefore, if you use the RGB (NCHW) format in the model training and expect the model to process NV12 data efficiently, then you will need to configure as follow:
In addition to converting the input data to NV12, you can also use different RGB-orders in the training and runtime infer.
The tool will automatically add data conversion nodes according to the data formats specified by the input_type_rt and input_type_train.
Not any type combination is needed, in order to avoid your misuse, we only open some fixed type combinations in the following table
(Y for supported image types, while N for unsupported image types. The first row of the table is the data types supported in input_type_rt and the first column is the data types supported in input_type_train.):
| input_type_train \ input_type_rt | nv12 | yuv444 | rgb | bgr | gray | featuremap |
|---|---|---|---|---|---|---|
| yuv444 | Y | Y | N | N | N | N |
| rgb | Y | Y | Y | Y | N | N |
| bgr | Y | Y | Y | Y | N | N |
| gray | N | N | N | N | Y | N |
| featuremap | N | N | N | N | N | Y |
To meet the requirements of Horizon ASICs on input data type and reduce the inference costs,
when input_type_rt is of the RGB(NHWC/NCHW)/BGR(NHWC/NCHW) type, the input data type of the models converted by using the conversion tool will all be int8.
That is, for regular image formats, pixel values should be subtracted by 128, which has already been done by the API and you do not need to do it again.
In the final hbm model obtained from the conversion, the conversion from input_type_rt to input_type_train is an internal process.
You only need to focus on the data format of input_type_rt.
It is of vital importance to understand the requirement of the input_type_rt when preparing the inference data for embedded applications,
please refer to the following explanations to each format of the input_type_rt.
bt601_video of the input_space_and_range.
Compared with typical NV12 format, its value range has changed from [0,255] to [16,235].
Each value is still represented as UINT8. Note that bt601_video is supported configuring via input_space_and_range only when input_type_train is bgr or rgb.The above input_type_rt and input_type_train are integrated into the toolchain processing procedure.
If you are very sure that no format conversion is required, then set the two input_type to be the same,
so that the same input_type will perform the processing in a straight-through way and will not affect the actual execution performance of the model.
Similarly, data pre-processing also is also integrated into the process.
If you don't need to do any pre-processing, just do not specify mean_value, scale_value and std_value, which will not affect the actual execution performance of the model.
If you specify the input_type_rt and input_type_train to different values(each being rgb/bgr/yuv444), or if you set preprocessing-related parameters such as mean_value, scale_value, and std_value,
the tool will internally insert the preprocessing node during the model conversion and compilation process.
The preprocessing node only supports NHWC input. Therefore, if the data layout of the original input model is NCHW, the data layout of the HBIR and HBM models will be changed to NHWC.
This change does not affect the performance and accuracy of the model.
| Parameter Name | Parameter Description | Required/Optional |
cal_data_dir | PURPOSE: This parameter specifies the directory to save the calibration samples. Attention: When the | optional |
quant_config | PURPOSE: The S100 platform supports flexible configuration of various quantization parameters,
you can use these parameters to configure the computational accuracy of the operator in the model,
algorithms used in the calibration and search methods for calibration parameters.
| optional |
| Parameter Name | Parameter Description | Required/Optional |
compile_mode | PURPOSE: This parameter specifies compilation strategies. | optional |
balance_factor | PURPOSE: This parameter specifies the balance ratio when the compile_mode is specified as balance.
| compile_mode specified as balance: required |
core_num | PURPOSE: This parameter specifies the number of cores to run model. | optional |
optimize_level | PURPOSE: This parameter specifies the model optimization levels. | optional |
input_source | PURPOSE: This parameter specifies the input source of dev board hbm models.
The ddr indicates that the data comes from memory.
pyramid and resizer indicates the fixed hardware from the processor.This parameter is a bit special, e.g., if the model input name is data and the data source is memory (ddr), then this parameter should be configured as {"data": "ddr"}.FOR EXAMPLE: | optional |
max_time_per_fc | PURPOSE: This parameter specifies the maximum continuous execution time (by μs) of model's each function call. Attention:
| optional |
jobs | PURPOSE: This parameter sets the number of processes when compiling the hbm model. | optional |
advice | PURPOSE: This parameter is used to indicate the predicted increase in elapsed time in microseconds after the model is compiled. | optional |
cache_path | PURPOSE:
This parameter is used to configure the path for the compilation cache. | optional |
cache_mode | PURPOSE: This parameter is used to set the compilation cache mode.
| optional |
extra_params | PURPOSE: This parameter provides additional flexible configuration of some model compilation related parameters.
Attention: The
| optional |
You can specify the parameters like this: param_name: 'param_value', while multiple values can be separated by ';': param_name: 'param_value1;param_value2;param_value3'.
To avoid parameter sequence problems, You are strongly suggested to specify the parameters(such as input_shape etc.) explicitly when there are multi-input models.
Please note that, if set input_type_rt to nv12 , an odd number cannot appear in the input size of model.
The Resnet50 model is used as a sample here, a complete configuration file template is shown as below:
Below configuration file is only for display, in an actual configuration file of a model,
needs to be determined based on the original floating point model type you passed in, the caffe_model and onnx_model parameters are not coexisting.
For Caffe model, pass caffe_model + prototxt; for Onnx model, pass onnx_model.
That is, caffe_model + prototxt or onnx_model , you need to choose one of the two when configuring.