The hb_verifier Tool

The hb_verifier tool is used to support performing cosine similarity comparisons of model-by-layer operator outputs. The tool supports performing comparisons between onnx models and between onnx model and hbir model.

The cosine similarity indicates the consistency between quantized models at different stages. As the cosine similarity gets closer to 1, it indicates that the outputs of the two quantized models being compared are closer to each other.

How to Use

hb_verifier -m ${onnx_model},${hbir_model} \ -i ${input_data}

Parameters

PARAMETERDESCRIPTION
-h, --helpDisplays help information and exits.
-m, --modelSpecifies the image to be used for inference testing, only *.npy files are supported.
There are two ways to add pictures to a multi-input model by passing parameters, and multiple images are separated by “,”:
  • input_name1:image1,input_name2:image2, …
  • image1,image2…
Attention:
  • Inputs need to include pre-processing operations, i.e., the configuration of color conversion/mean/scale etc. needs to be done externally when preparing the input. If there are no special requirements, it is sufficient to use the calibration data set as input.
  • The name order of the input images need to be the same as the actual input of the model.

Examples of Reference Usage

  1. Cosine similarity comparisons were performed between the ONNX model and the ONNX model.

Take the model optimization stage model optimized_float_model.onnx and the model calibration stage model calibrated_model.onnx as an example:

hb_verifier -m googlenet_optimized_float_model.onnx,googlenet_calibrated_model.onnx -i input.npy
  1. Cosine similarity comparisons were performed between the ONNX model and the HBIR model.

Take the model optimization stage model optimized_float_model.onnx and the model quantization stage fixed-point model quantized_model.bc as an example:

hb_verifier -m googlenet_optimized_float_model.onnx,googlenet_quantized_model.bc -i input.npy

Output Contents

The cosine similarity information for the compared models will be printed within the terminal, as shown in the example below:

+-----------------------------------+----------------------------+-------------------+ | NodeName | TensorName | ConsineSimilarity | +-----------------------------------+----------------------------+-------------------+ | Conv_0 | 365 | 0.999978 | | Relu_2 | 367 | 0.999976 | | MaxPool_3 | 368 | 0.999901 | | Conv_4 | 369 | 0.999112 | | Relu_6 | 371 | 0.999212 | | ... | ... | ... | | Conv_189 | 554 | 0.984707 | | Relu_191 | 556 | 0.989554 | | Concat_192 | 557 | 0.989221 | | GlobalAveragePool_193 | 558 | 0.995896 | | Gemm_195 | transposed_replaced_output | 0.995836 | | Gemm_195_transpose_output_reshape | output | 0.995836 | +-----------------------------------+----------------------------+-------------------+

Among them:

  • NodeName represents the name of the operator.
  • TensorName represents the Tensor name of the first output of the operator.
  • ConsineSimilarity represents the calculated cosine similarity.