tf.quantization.quantize_and_dequantize_v2
Stay organized with collections
Save and categorize content based on your preferences.
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)
Args |
input
|
A Tensor to quantize and dequantize.
|
input_min
|
If range_given=True, the minimum input value, that needs to be
represented in the quantized representation. If axis is specified, this
should be a vector of minimum values for each slice along axis.
|
input_max
|
If range_given=True, the maximum input value that needs to be
represented in the quantized representation. If axis is specified, this
should be a vector of maximum values for each slice along axis.
|
signed_input
|
True if the quantization is signed or unsigned.
|
num_bits
|
The bitwidth of the quantization.
|
range_given
|
If true use input_min and input_max for the range of the
input, otherwise determine min and max from the input Tensor .
|
round_mode
|
Rounding mode when rounding from float values to quantized ones.
one of ['HALF_TO_EVEN', 'HALF_UP']
|
name
|
Optional name for the operation.
|
narrow_range
|
If true, then the absolute value of the quantized minimum
value is the same as the quantized maximum value, instead of 1 greater.
i.e. for 8 bit quantization, the minimum value is -127 instead of -128.
|
axis
|
Integer. If specified, refers to a dimension of the input tensor, such
that quantization will be per slice along that dimension.
|
Returns |
A Tensor . Each element is the result of quantizing and dequantizing the
corresponding element of input .
|
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates. Some content is licensed under the numpy license.
Last updated 2023-03-23 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2023-03-23 UTC."],[],[]]