Sets ranges for network layers.
(network, json_file)
| 16 | return data |
| 17 | |
| 18 | def setDynamicRange(network, json_file): |
| 19 | """Sets ranges for network layers.""" |
| 20 | quant_param_json = json_load(json_file) |
| 21 | act_quant = quant_param_json["act_quant_info"] |
| 22 | |
| 23 | for i in range(network.num_inputs): |
| 24 | input_tensor = network.get_input(i) |
| 25 | if act_quant.__contains__(input_tensor.name): |
| 26 | value = act_quant[input_tensor.name] |
| 27 | tensor_max = abs(value) |
| 28 | tensor_min = -abs(value) |
| 29 | input_tensor.dynamic_range = (tensor_min, tensor_max) |
| 30 | |
| 31 | |
| 32 | for i in range(network.num_layers): |
| 33 | layer = network.get_layer(i) |
| 34 | |
| 35 | for output_index in range(layer.num_outputs): |
| 36 | tensor = layer.get_output(output_index) |
| 37 | |
| 38 | if act_quant.__contains__(tensor.name): |
| 39 | value = act_quant[tensor.name] |
| 40 | tensor_max = abs(value) |
| 41 | tensor_min = -abs(value) |
| 42 | tensor.dynamic_range = (tensor_min, tensor_max) |
| 43 | else: |
| 44 | print("\033[1;32m%s\033[0m" % tensor.name) |
| 45 | |
| 46 | |
| 47 | def build_engine(onnx_file, json_file, engine_file): |
no test coverage detected