2017-06-01 37 views
0

我正在试验Tensorflow 1.1中神经网络的量化。带量化值的Tensorflow tanh

根据documentationtanh操作支持浮点输入以及类型为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 

有没有出路,或只是在文档中的错误?

回答

1

这可能是doc中的一个错误。根据后端功能_tanhgen_math_ops.py

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新版本仍在进行中。

+0

查看文件历史记录后,我可以确认这是2015年7月推出的文档中的一个错误,在我们发布之前以及量化定义尚未完全确定之前。 –

+0

感谢您澄清这一点!那么,对于使用tanh激活函数的网络来说,量化推理的最直接方法是什么? – rerx