View source on GitHub |
Quantizes then dequantizes a tensor.
tf.quantization.quantize_and_dequantize_v2(
input,
input_min,
input_max,
signed_input=True,
num_bits=8,
range_given=False,
round_mode='HALF_TO_EVEN',
name=None,
narrow_range=False,
axis=None
)
Updates the gradient definition for quantization that is outside the range to be 0.To simulate the V1 the behavior of tf.quantization.quantize_and_dequantize(...) use tf.grad_pass_through(tf.quantization.quantize_and_dequantize_v2)(...).
Example usage:
def getQuantizeOp(input):
input_tensor = tf.placeholder(tf.float32, shape=[4, 4])
net = tf.quantization.quantize_and_dequantize(input,
input_min=min_threshold,
input_max=max_threshold,
range_given=True)
To simulate v1 behavior:
def testDecomposeQuantizeDequantize(self):
def f(input_tensor):
return tf.quantization.quantize_and_dequantize_v2(input_tensor,
input_min = 5.0,
input_max= -10.0,
range_given=True)
input_tensor = tf.placeholder(tf.float32, shape=[4, 4])
net = tf.grad_pass_through(f)(input_tensor)
Returns | |
---|---|
A Tensor . Each element is the result of quantizing and dequantizing the
corresponding element of input .
|