Skip to main content
 首页 » 编程设计

python之在 TensorFlow 中对整数张量进行卷积

2024年10月01日27youxin

因此,我正在尝试使用 tf.int32 过滤器在 tf.int32 批处理上运行卷积(标准 depthwise_conv2d) .我收到错误:TypeError: Value passed to parameter 'input' has DataType int32 not in list of allowed values: float32, float64。鉴于我不需要渐变,我想知道是否有人知道可以表达卷积并接受整数的运算符?谢谢!

请您参考如下方法:

你不能这样做因为conv2d不接受 int 类型:

input: A Tensor. Must be one of the following types: half, float32. A 4-D tensor. The dimension order is interpreted according to the value of data_format, see below for details.

因此,您的解决方案要么是编写您自己的 conv2dint(这只是他们的 conv2d 的不同类型的副本),要么使用他们的 conv2d 并应用 tf.cast(res_from_conv, tf.int32)。