【发布时间】:2016-07-08 21:00:31
【问题描述】:
在 TensorFlow 中,以下代码失败并出现错误 ValueError: Shapes (3, 32, 28, 28) and () are not compatible
import tensorflow as tf
filters = 32
width = 28
height = 28
channels = 3
x = tf.placeholder(tf.float32, shape=[None, height, width, channels])
w = tf.Variable(tf.truncated_normal([channels, filters, height, width], stddev=0.1))
b = tf.Variable(tf.constant(0.1, shape=[32]))
w_ifft = tf.real(tf.batch_ifft2d(tf.complex(w, 0.0)))
w_ifft_transpose = tf.transpose(w_ifft, [2, 3, 0, 1])
conv = tf.nn.conv2d(x, w_ifft_transpose, strides=[1, 1, 1, 1], padding='SAME')
output = tf.nn.bias_add(conv, b)
print tf.gradients(output, w)
虽然这是一个说明错误的简化示例,但我在变量上使用 iffts 来参数化频域中的卷积滤波器,如 Spectral Representations for Convolutional Neural Networks 中所述
【问题讨论】:
-
您使用的是什么版本的 TensorFlow?我用 0.9.0 运行它,这段代码打印出
[<tf.Tensor 'gradients/Complex_grad/Reshape:0' shape=(3, 32, 28, 28) dtype=float32>]。 -
0.9.0 -- 您是否尝试了最近编辑的代码版本?
-
是的,似乎工作正常。
-
我使用的是 python 2.7、tensorflow 0.9.0(通过 pip 安装)、cuda 7.5、cudnn 4.0.7
标签: python neural-network tensorflow conv-neural-network