MCPcopy Create free account
hub / github.com/tensorflow/tfjs-examples / dequantize

Function dequantize

quantization/draw_quantization.py:54–77  ·  view source on GitHub ↗

Simulate weight de-quantization. Args: w: (a numpy.ndarray) The weight to be quantized. bits: (int) number of bits used for the quantization: 8 or 16. Returns: A tuple with three elements: w_quantized: the quantized version of w, represented as an uint8- or uint16-

(w_quantized, w_min, w_max)

Source from the content-addressed store, hash-verified

52
53
54def dequantize(w_quantized, w_min, w_max):
55 """
56 Simulate weight de-quantization.
57
58 Args:
59 w: (a numpy.ndarray) The weight to be quantized.
60 bits: (int) number of bits used for the quantization: 8 or 16.
61
62 Returns:
63 A tuple with three elements:
64 w_quantized: the quantized version of w, represented as an uint8-
65 or uint16-type numpy.ndarray.
66 w_min: Minimum value of w, required for dequantization.
67 w_max: Maximum value of w, required for dequantization.
68 """
69 if w_quantized.dtype == np.uint8:
70 bits = 8
71 elif w_quantized.dtype == np.uint16:
72 bits = 16
73 else:
74 raise ValueError(
75 'Unsupported dtype in quantized values: %s' % w_quantized.dtype)
76 return (w_min +
77 w_quantized.astype(np.float64) / np.power(2, bits) * (w_max - w_min))
78
79
80def main():

Callers 1

mainFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected