Sets ranges for network layers.
(network, json_file: str)
| 183 | |
| 184 | |
| 185 | def setDynamicRange(network, json_file: str): |
| 186 | """Sets ranges for network layers.""" |
| 187 | with open(json_file) as file: |
| 188 | quant_param_json = json.load(file) |
| 189 | act_quant = quant_param_json["act_quant_info"] |
| 190 | |
| 191 | for i in range(network.num_inputs): |
| 192 | input_tensor = network.get_input(i) |
| 193 | if act_quant.__contains__(input_tensor.name): |
| 194 | value = act_quant[input_tensor.name] |
| 195 | tensor_max = abs(value) |
| 196 | tensor_min = -abs(value) |
| 197 | input_tensor.dynamic_range = (tensor_min, tensor_max) |
| 198 | |
| 199 | for i in range(network.num_layers): |
| 200 | layer = network.get_layer(i) |
| 201 | |
| 202 | for output_index in range(layer.num_outputs): |
| 203 | tensor = layer.get_output(output_index) |
| 204 | |
| 205 | if act_quant.__contains__(tensor.name): |
| 206 | value = act_quant[tensor.name] |
| 207 | tensor_max = abs(value) |
| 208 | tensor_min = -abs(value) |
| 209 | tensor.dynamic_range = (tensor_min, tensor_max) |
| 210 | |
| 211 | |
| 212 | def build_engine( |
no test coverage detected