使用量化Conv2D时出错tf.qint8输入

2021-05-13 14:36:44 发布

您现在位置:Python中文网/ 问答频道 /正文

我是一个新的量子化,我正在学习如何在tensorflow中使用QuantizedConv2D运算。代码如下

import tensorflow as tf
a = tf.constant([1.5,1.2],shape = [1,1,1,2], name ='a')
a1 = tf.constant([[2.0],[1.0]],shape = [1,1,2,1], name ='b')
min_a= tf.reduce_min(a)
max_a= tf.reduce_max(a)
x = tf.quantize(a,min_a,max_a,tf.qint8)
min_a1= tf.reduce_min(a1)
max_a1= tf.reduce_max(a1)
x1 = tf.quantize(a1,min_a1,max_a1,tf.qint8)
y1 = t  f.nn.quantized_conv2d(x.output,x1.output,x.output_min,x.output_max,x1.output_min,x1.output_max,[1,1,1,1],"SAME")
with tf.Session() as sess:
  print (sess.run(y1))

我得到以下错误:

InvalidArgumentError (see above for traceback): No OpKernel was registered to support Op 'QuantizedConv2D' with these attrs. Registered devices: [CPU], Registered kernels: device='CPU'; Tinput in [DT_QUINT8]; Tfilter in [DT_QUINT8]; out_type in [DT_QINT32] [[Node: QuantizedConv2D = QuantizedConv2D[Tfilter=DT_QINT8, Tinput=DT_QINT8, dilations=[1, 1, 1, 1], out_type=DT_QINT32, padding="SAME", strides=[1, 1, 1, 1]](QuantizeV2, QuantizeV2_1, QuantizeV2:1, QuantizeV2:2, QuantizeV2_1:1, QuantizeV2_1:2)]]

我不确定我的代码是否正确,或者这是一个bug。在

任何帮助都将不胜感激。在

谢谢和问候

阿比纳夫