具有量化值的 Tensorflow tanh
Tensorflow tanh with quantized values
我正在 Tensorflow 1.1 中试验神经网络的量化。
根据 documentation,tanh
运算支持浮点输入以及类型 qint32
的定点输入。但是,我无法让它工作:
import tensorflow as tf
sess = tf.InteractiveSession()
x = tf.constant([1.,2.,3.], dtype=tf.float32)
from tensorflow.python.ops.gen_array_ops import quantize_v2
x_quant = quantize_v2(x, min_range=0., max_range=4., T=tf.qint32)
y_quant = tf.nn.tanh(x_quant[0])
代码产生一条错误消息:
TypeError: Value passed to parameter 'x' has DataType qint32 not in list of
allowed values: float16, float32, float64, complex64, complex128
有解决办法还是只是文档中的错误?
这可能是文档中的错误。根据gen_math_ops.py
中的后端函数_tanh
:
def _tanh(x, name=None):
r"""Computes hyperbolic tangent of `x` element-wise.
Args:
x: A `Tensor`. Must be one of the following types: `half`, `float32`, `float64`, `complex64`, `complex128`.
name: A name for the operation (optional).
既然量化真的很新,可能_tanh
新版本还在进行中
我正在 Tensorflow 1.1 中试验神经网络的量化。
根据 documentation,tanh
运算支持浮点输入以及类型 qint32
的定点输入。但是,我无法让它工作:
import tensorflow as tf
sess = tf.InteractiveSession()
x = tf.constant([1.,2.,3.], dtype=tf.float32)
from tensorflow.python.ops.gen_array_ops import quantize_v2
x_quant = quantize_v2(x, min_range=0., max_range=4., T=tf.qint32)
y_quant = tf.nn.tanh(x_quant[0])
代码产生一条错误消息:
TypeError: Value passed to parameter 'x' has DataType qint32 not in list of allowed values: float16, float32, float64, complex64, complex128
有解决办法还是只是文档中的错误?
这可能是文档中的错误。根据gen_math_ops.py
中的后端函数_tanh
:
def _tanh(x, name=None): r"""Computes hyperbolic tangent of `x` element-wise. Args: x: A `Tensor`. Must be one of the following types: `half`, `float32`, `float64`, `complex64`, `complex128`. name: A name for the operation (optional).
既然量化真的很新,可能_tanh
新版本还在进行中