The hrt_model_exec Tool Introduction
Tool Introduction
hrt_model_exec is a model execution tool that can evaluate the inference performance of the model and get the model information directly on the development board.
On one hand, it allows you to get a realistic understanding of the model's real performance; On the other hand, it also helps you to learn the speed limit that the model can achieve, which is useful information in application tuning.
hrt_model_exec tool source code is located in the samples/ucp_tutorial/tools/hrt_model_exec path of the horizon_j6_open_explorer publication. The structure is as follows:
hrt_model_exec provides three types of functions including model inference infer, model performance analysis perf and viewing model information model_info, respectively, as shown in the following table:
The tool can view the tool's dnn prediction library version number with the -v or --version commands.
Parameters Description
After setting the profile_path parameter and the tool runs normally, profiler.log and profiler.csv files will be generated. The files include the following parameters:
-
ucp_version:UCP and HBRT version.
-
perf_result:Record perf results.
- running_condition:Operating environment information.
- model_latency: Model node time consumption statistics.
- processor_latency:Model processor time consumption statistics.
- task_latency:Model task time-consuming statistics.
Usage Instructions
This tool provides three types of functions: model information acquisition, single-frame inference function, and multi-frame performance evaluation.
Run hrt_model_exec, hrt_model_exec -h, or hrt_model_exec --help for tool usage details.
model_info
Overview
This parameter is used to get the model information, supporting both QAT and PTQ models. This parameter is used together with model_file to get detailed information about the model, including model input and output information hbDNNTensorProperties.
If model_name is not specified, all the models in the model are outputted. If model_name is specified, only the information of the corresponding model is outputted.
Example
- Single Model
- Multi-model (output all model information)
- Multi-model - pack model (output specified model information)
infer
Overview
This parameter is used for model inference, where the input images are defined by user and one frame is inferred.
This parameter should be used together with input_file to specify the input image path, and the tool resizes the image according to the model information and organizes the model input information.
The program runs a single frame of data in a single thread and outputs the time of the model execution.
Sample
- Single Model
- Multi-model
Optional Parameters
You can use the following parameters based on your scenario:
core_id、input_img_properties、input_valid_shape 、input_stride 、frame_count、dump_intermediate、enable_dump、dump_precision、dequantize_process、remove_padding_process、dump_format、dump_txt_axis、enable_cls_post_process、dump_path.
For parameter usage instructions, please refer to the Parameters Description section.
perf
Overview
This parameter is used to test the model performance.
In this mode, you does not need to input data, and the program automatically constructs the input tensor according to the model, and the tensor data are random numbers.
By default, the program runs 200 frames of data in a single thread. When perf_time is specified, frame_count is disabled, and the program will run for the specified period of time and then exit.
Outputs the latency and the frame rate of the model. The program prints the performance information every 200 frames: max, min, and average values of latency. If < 200 frames, prints once before the programs ends.
The program finally outputs the running-related data, including number of program threads, number of frames, total model inference time, average latency of model inference, and frame rate.
Sample
- Single Model
- Multi-model
Optional Parameters
You can use the following parameters based on your scenario:
core_id、input_file 、input_img_properties、input_valid_shape、input_stride、frame_count、dump_intermediate、 perf_time、 thread_num、profile_path.
For parameter usage instructions, please refer to the Parameters Description section.
Multi-input Model Description
The tool infer supports inference for multiple input models, supporting image input, binary file input, and text file input, with input data separated by commas.
The model input information can be viewed via model_info.
Example:
Dynamic input instructions
If the model input is dynamic, you need to use the input_valid_shape and input_stride parameters to complete the dynamic information according to the actual input situation. You can choose to specify the parameters in the following two ways:
-
Only give the
validShapeorstrideinformation of the dynamic input. -
Give the
validShapeorstrideinformation of all inputs. The information of non-dynamic inputs must be consistent with the model information.
The tool will automatically complete the dynamic input information to the maximum extent, which is convenient for you to perform performance evaluation more easily. You can choose whether to let the tool automatically complete it according to the actual situation.
-
If the input
strideis dynamic andvalidShapeis fixed, you can not specify theinput_strideparameter. The tool will automatically complete it according to the minimum alignment rule and print the alignment information. -
If both
validShapeandstrideare dynamic:-
If the input is a picture type, you need to specify the color space information of the picture
input_img_properties, and the other parameters can be left unspecified. The tool will fill in theinput_valid_shapeandinput_strideinformation according to the size of the picture. -
If the input is a type other than a picture or is not specified, you need to set the
input_valid_shapeinformation, and theinput_strideinformation will be automatically filled in and printed.
-
Taking the model in the Dynamic Input Introduction section as an example, you can run the model with the following command:
Image type input instructions
When input_file is given an image input, you need to use the input_img_properties parameter to specify which color space of the image you want to use as input to the model. Currently, only Y and UV color spaces are supported.
Tool operation instructions
Build
There is a pre-configured compilation script build.sh in the ucp_tutorial/tools/hrt_model_exec directory. The options -a x86 and -a aarch64 support two compilation modes respectively. You can use this script and specify the compilation options for compilation.
In addition, the directory also contains two compilation scripts, build_aarch64.sh and build_x86.sh, which correspond to two compilation options respectively. Compiling with these two scripts is equivalent to using the build.sh script and specifying the compilation options.
Execute
After building board-side hrt_model_exec tools, the output_shared_J6_aarch64 folder will be generated.
You can use this tool by copying the folder to the board environment and executing output_shared_J6_aarch64/script/run_hrt_model_exec.sh.
After building x86-side hrt_model_exec tools, the output_shared_J6_x86 folder will be generated.
You can use this tool on the x86 environment and executing output_shared_J6_x86/script_x86/run_hrt_model_exec.sh.
The run_hrt_model_exec.sh script is divided into two parts: setting environment variables and getting model information and inferring the model.
Before running, you need to modify the corresponding parameters of run_hrt_model_exec.sh to ensure that the model and input files are correct. You can also use other parameters flexibly to use more functions.
FAQ
How are Latency and FPS data calculated?
Latency refers to the average time spent by a single-process inference model. It focuses on the average time it takes to infer one frame when resources are sufficient. This is reflected in the statistics of single-core and single-thread running on the board. The pseudo code of the statistical method is as follows:
FPS refers to the average number of frames per second of model inference performed by multiple processes at the same time, which focuses on the throughput of the model when fully utilizing the resources.
In on-board running situation, it is represented as single-core and multi-threaded. The statistical method is to perform the model inference by initiating multiple threads at the same time and calculate the total number of frames of the inference in average 1 second.
Why is the FPS estimated by Latency inconsistent with the FPS measured by the tool?
Latency and FPS are different in statistical scenarios. Latency is single-process (single-core, single-thread) inference, and FPS is multi-process (single-core, multi-thread) inference,
so the calculation is different. If the number of processes (threads) is set to 1 when counting the FPS, then the FPS estimated by Latency is consistent with the measured one.
How to deal with out of memory during Perf?
When prompted to be out of memory, you can solve it in the following ways:
-
Reduce the value of
thread_numto reduce parallelism and reduce memory usage. -
Optimize the model to reduce the model's memory usage.
