MCPcopy
hub / github.com/OpenPPL/ppq / setDynamicRange

Function setDynamicRange

ppq/utils/write_qparams_caffe2trt.py:25–52  ·  view source on GitHub ↗

Sets ranges for network layers.

(network, json_file)

Source from the content-addressed store, hash-verified

23 return data
24
25def setDynamicRange(network, json_file):
26 """Sets ranges for network layers."""
27 quant_param_json = json_load(json_file)
28 act_quant = quant_param_json["act_quant_info"]
29
30 for i in range(network.num_inputs):
31 input_tensor = network.get_input(i)
32 if act_quant.__contains__(input_tensor.name):
33 print(input_tensor.name)
34 value = act_quant[input_tensor.name]
35 tensor_max = abs(value)
36 tensor_min = -abs(value)
37 input_tensor.dynamic_range = (tensor_min, tensor_max)
38
39 for i in range(network.num_layers):
40 layer = network.get_layer(i)
41
42 for output_index in range(layer.num_outputs):
43 tensor = layer.get_output(output_index)
44
45 if act_quant.__contains__(tensor.name):
46 print("\033[1;32mWrite quantization parameters:%s\033[0m" % tensor.name)
47 value = act_quant[tensor.name]
48 tensor_max = abs(value)
49 tensor_min = -abs(value)
50 tensor.dynamic_range = (tensor_min, tensor_max)
51 else:
52 print("\033[1;31mNo quantization parameters are written: %s\033[0m" % tensor.name)
53
54
55def build_int8_engine(deploy_file, model_file, json_file, engine_file):

Callers 1

build_int8_engineFunction · 0.70

Calls 2

__contains__Method · 0.80
json_loadFunction · 0.70

Tested by

no test coverage detected