量化然後去量化一個張量。
用法
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
)
參數
-
input
用於量化和去量化的Tensor
。 -
input_min
如果range_given=True,最小輸入值,需要在量化表示中表示。如果指定了軸,則這應該是沿軸的每個切片的最小值向量。 -
input_max
如果range_given=True,則量化表示中需要表示的最大輸入值。如果指定了軸,則這應該是沿軸的每個切片的最大值向量。 -
signed_input
如果量化有符號或無符號則為真。 -
num_bits
量化的位寬。 -
range_given
如果為真,則使用input_min
和input_max
作為輸入範圍,否則從輸入Tensor
確定最小值和最大值。 -
round_mode
從浮點值舍入到量化值時的舍入模式。 ['HALF_TO_EVEN','HALF_UP'] 之一 -
name
操作的可選名稱。 -
narrow_range
如果為真,則量化最小值的絕對值與量化最大值相同,而不是大 1。即對於 8 位量化,最小值是 -127 而不是 -128。 -
axis
整數。如果指定,則指輸入張量的維度,這樣量化將是沿該維度的每個切片。
返回
-
一個
Tensor
。每個元素都是對input
的相應元素進行量化和反量化的結果。
將超出範圍的量化梯度定義更新為 0。要模擬 V1 的行為 tf.quantization.quantize_and_dequantize(...) 使用 tf.grad_pass_through(tf.quantization.quantize_and_dequantize_v2) (...)。
示例用法:
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)
相關用法
- Python tf.quantization.quantize用法及代碼示例
- Python tf.quantization.dequantize用法及代碼示例
- Python tf.compat.v1.distributions.Multinomial.stddev用法及代碼示例
- Python tf.compat.v1.distribute.MirroredStrategy.experimental_distribute_dataset用法及代碼示例
- Python tf.compat.v1.data.TFRecordDataset.interleave用法及代碼示例
- Python tf.summary.scalar用法及代碼示例
- Python tf.linalg.LinearOperatorFullMatrix.matvec用法及代碼示例
- Python tf.linalg.LinearOperatorToeplitz.solve用法及代碼示例
- Python tf.raw_ops.TPUReplicatedInput用法及代碼示例
- Python tf.raw_ops.Bitcast用法及代碼示例
- Python tf.compat.v1.distributions.Bernoulli.cross_entropy用法及代碼示例
- Python tf.compat.v1.Variable.eval用法及代碼示例
- Python tf.compat.v1.train.FtrlOptimizer.compute_gradients用法及代碼示例
- Python tf.distribute.OneDeviceStrategy.experimental_distribute_values_from_function用法及代碼示例
- Python tf.math.special.fresnel_cos用法及代碼示例
- Python tf.keras.applications.inception_resnet_v2.preprocess_input用法及代碼示例
- Python tf.compat.v1.layers.conv3d用法及代碼示例
- Python tf.Variable.__lt__用法及代碼示例
- Python tf.keras.metrics.Mean.merge_state用法及代碼示例
- Python tf.keras.layers.InputLayer用法及代碼示例
注:本文由純淨天空篩選整理自tensorflow.org大神的英文原創作品 tf.quantization.quantize_and_dequantize_v2。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。