【问题标题】:Tensorflow tanh with quantized values具有量化值的 TensorFlow tanh
【发布时间】:2017-06-01 15:35:30
【问题描述】:

我正在 Tensorflow 1.1 中尝试神经网络的量化。

根据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

有出路还是只是文档中的错误?

【问题讨论】:

    标签: python tensorflow quantization


    【解决方案1】:

    这可能是文档中的错误。根据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的新版本还在进行中。

    【讨论】:

    • 查看文件历史记录后,我可以确认这是 2015 年 7 月引入的文档中的错误,在我们发布之前并且量化定义尚未完全确定时.
    • 感谢您澄清这一点!那么,对于使用 tanh 激活函数的网络,量化推理最直接的方法是什么?
    猜你喜欢
    • 1970-01-01
    • 2021-03-05
    • 2021-06-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-04-04
    • 1970-01-01
    • 2020-12-06
    相关资源
    最近更新 更多