Post-Training INT8 Quantization -> TensorRT Calibration Table

Hello everyone,
I am using Python3 + Tensorflow 1.12 + TensorRT 3.0.2 in order to quantize a DNN for object detection.

The quantization work fine for me. However, I want to generate and read the calibration table in order to understand if my calibration dataset is good enough or not.
I want to ask also if I can generate the histograms of activation as shown in these slides?
http://on-demand.gputechconf.com/gtc/2017/presentation/s7310-8-bit-inference-with-tensorrt.pdf

I found the following python code in NVIDIA tutorial to extract the TensorRT calibration table after the calibration is done: https://docs.nvidia.com/deeplearning/frameworks/tf-trt-user-guide/index.html#post-train

for n in trt_graph.node:
if n.op == “TRTEngineOp”:
print(“Node: %s, %s” % (n.op, n.name.replace("/", “")))
with tf.gfile.GFile("%s.calib_table" % (n.name.replace("/", "
”)), ‘wb’) as f:
f.write(n.attr[“calibration_data”].s)

This code generates a file for each node in the trt_graph. I get something like this:

Up_sample_6/conv2d_25/Relu: 3f556f06
InputPH_1: 3e0324b6
Up_sample_6/conv2d_26/Relu: 3eee7366
OutputPH_0: 3e59daba
Up_sample_6/conv2d_27/Relu: 3dc77c91
InputPH_0: 3f41b751

Thank you in advance,
Fares Charfi
Can you please explain these files and how to read these files?

Hello,

Can you please read the questions and answer?
1 month now since I posted this question!

nobody will reply, give up.

: value corresponds to the floating point activation scales determined during calibration for each tensor in the network.

For example, considering HEX value as big endian:
CalibrationTable
Up_sample_6/conv2d_25/Relu: 3f556f06
scaleFactor:
0.833725333
maxRange
1.199 (1/0.833725333)

Thanks

Hello @SunilJB
I think for the max range calculation we have to do the following:

CalibrationTable
Up_sample_6/conv2d_25/Relu: 3f556f06
scaleFactor:
0.833725333
maxRange
127 * 0.833725333 (and not )

Because, scale = max_range/127

Thanks
Fares

Thank you for correcting me.
Here, 1.0/scaleFactor means one unit of float point can present in the int8 domain.
Int8 = abs(float/scale factor)
If the int8 abs(value) > 128, it will be truncated.

Thanks

1 Like

Hello @SunilJB,

Thanks for your answer.
Why is it: Int8 = abs(float/scale_range) but not Int8= float/scale_range ?
Why do we need the absolute value?

Thanks

Int8 quantization is symmetric. So we just need to quantize the absolute value.

Thanks

1 Like