MCPcopy Create free account
hub / github.com/XiaoMi/mace / quantize

Function quantize

tools/python/quantize/quantize_util.py:223–238  ·  view source on GitHub ↗
(data, device, non_zero)

Source from the content-addressed store, hash-verified

221
222
223def quantize(data, device, non_zero):
224 np_data = np.array(data).astype(float)
225 in_min = np_data.min()
226 in_max = np_data.max()
227 scale, zero, out_min, out_max = adjust_range(in_min, in_max, device,
228 non_zero=non_zero)
229 output = np.clip((np.round(zero + np_data / scale).astype(np.int32)),
230 0, 255)
231
232 quantized_data = QuantizedData()
233 quantized_data.data = output
234 quantized_data.scale = scale
235 quantized_data.zero = zero
236 quantized_data.minval = out_min
237 quantized_data.maxval = out_max
238 return quantized_data
239
240
241# only support int16 symmetric quantization.

Callers

nothing calls this directly

Calls 3

adjust_rangeFunction · 0.85
QuantizedDataClass · 0.85
roundMethod · 0.80

Tested by

no test coverage detected