错误的input_shape预计有4个尺度,但得到的列有形状(73257,32,32)

0

的问题

我有灰度图像这个的形状: x_train_grey.shape = (73257, 32, 32)

我指定第一层是这样的:

Flatten(input_shape=(32,32,1)' 因为我不通过batch_size和灰度的图像只有1道。 但我得到这个错误:

ValueError: Error when checking input: expected flatten_1_input to have 4 dimensions, but got an array with shape (73257, 32, 32)

我不明白什么是错误的,请帮助。 我理解这一点已经问过很多次,但是我不能找到一个解决方案。

干杯!

2

最好的答案

1

问题可能在于你通过你的数据模型中。 如果你输入形状 (batch_size, 32, 32) 然后尝试这样的事情:

import tensorflow as tf

grey_scale_images = tf.random.normal((64, 32, 32))

model = tf.keras.Sequential()
model.add(tf.keras.layers.Flatten(input_shape=(32,32,1)))

print(model(grey_scale_images).shape)
# (64, 1024)

更新:两个 input_shape=(32,32,1)input_shape=(32,32) 将工作。 这取决于你是怎么喂你的数据模型:

import tensorflow as tf

grey_scale_images = tf.random.normal((64, 32, 32))
Y = tf.random.normal((64, 1024))
model = tf.keras.Sequential()
model.add(tf.keras.layers.Flatten(input_shape=(32, 32, 1)))
model.compile(loss='MSE')
model.fit(grey_scale_images, Y)
2021-11-24 08:40:01

实际上,只是路过 input_shape=(32,32) 合作,谢谢!
mankojag

我认为你是错误的...看看我的新答复。
AloneTogether

谢谢,但我不太确定这是正确的。 我试过了 input_shape=(32,32,1) 但是它不工作。 你有什么建议需要做之前通过,而不是的 input_shape=(32,32)? 是有一些规定说 (32,32,1) 应该够用了 (32,32) 或者不会它没事,就像你说的这两个选项工作?
mankojag

检查的底部,我的答案。 正如我所说的这两个工作但是这取决于你的数据看起来像
AloneTogether
-1

我还在学这东西太多但是我猜想"1"为维度的条目数量是不可能的。 甚至如果这是可能的,它是一个开始。 "1"作为一个小的轴不到我。 其他人?

2021-11-24 07:34:08

谢谢,事实上 input_shape=(32,32) 似乎是工作的现
mankojag

其他语言

此页面有其他语言版本

Русский
..................................................................................................................
Italiano
..................................................................................................................
Polski
..................................................................................................................
Română
..................................................................................................................
한국어
..................................................................................................................
हिन्दी
..................................................................................................................
Français
..................................................................................................................
Türk
..................................................................................................................
Česk
..................................................................................................................
Português
..................................................................................................................
ไทย
..................................................................................................................
Español
..................................................................................................................
Slovenský
..................................................................................................................