【发布时间】:2018-03-14 23:01:55
【问题描述】:
我正在尝试对可变尺寸的图像执行卷积 (conv2d)。我有这些一维数组形式的图像,我想对它们进行卷积,但是我在形状上有很多麻烦。
这是我的conv2d代码:
tf.nn.conv2d(x, w, strides=[1, 1, 1, 1], padding='SAME')
其中x 是输入图像。
错误是:
ValueError: Shape must be rank 4 but is rank 1 for 'Conv2D' (op: 'Conv2D') with input shapes: [1], [5,5,1,32].
我想我可能会重塑x,但我不知道正确的尺寸。当我尝试这段代码时:
x = tf.reshape(self.x, shape=[-1, 5, 5, 1]) # example
我明白了:
ValueError: Dimension size must be evenly divisible by 25 but is 1 for 'Reshape' (op: 'Reshape') with input shapes: [1], [4] and with input tensors computed as partial shapes: input[1] = [?,5,5,1].
【问题讨论】:
-
conv2d想要shape=[batch, height, width, channels]的数据,因此如果可以选择,最好直接使用图像而不是将它们展平为一维数组。 -
谢谢。问题是图像没有标准的高度或宽度,所以我无法提前告诉形状。
标签: python image tensorflow reshape convolution