简体   繁体   English

Keras Conv2D - ValueError:层序的输入 0 与层不兼容::预期 min_ndim=4,发现 ndim=3

[英]Keras Conv2D - ValueError: Input 0 of layer sequential is incompatible with the layer: : expected min_ndim=4, found ndim=3

I konw, there are already some questions like this, but I couldn´t find any solution for this problem.我知道,已经有一些这样的问题,但我找不到这个问题的任何解决方案。

I created a model like this:我创建了一个这样的模型:

def CreateModel(optimizer=optimizer, loss=loss, learn_rate=learn_rate, activity_regularizer=activity_regularizer):
    model = keras.Sequential([
            keras.layers.Conv2D(32,3,input_shape=(9,21,1)),
            keras.layers.Flatten(),
            keras.layers.Dense(32, activation='relu', kernel_initializer=keras.initializers.RandomUniform(maxval=1, minval=0), bias_initializer=keras.initializers.Zeros(), activity_regularizer=activity_regularizer),
            keras.layers.Dense(2, activation='softmax', kernel_initializer=keras.initializers.RandomUniform(maxval=1, minval=0), bias_initializer=keras.initializers.Zeros(), activity_regularizer=activity_regularizer)
            ])
    model.compile(optimizer=optimizer,
              loss=loss,
              metrics=['accuracy', keras.metrics.FalseNegatives(), keras.metrics.FalsePositives(), keras.metrics.Precision(), keras.metrics.Recall()])
    return model

My input consists of 300 9x21 gray scale images.我的输入由 300 张 9x21 灰度图像组成。

Without the Conv2D layer it works perfectly fine.没有 Conv2D 层,它工作得很好。 But with this Conv2D layer I got the error:但是使用这个 Conv2D 层我得到了错误:

ValueError: Input 0 of layer sequential is incompatible with the layer: : expected min_ndim=4, found ndim=3

I also tried some other input_shapes like:我还尝试了其他一些 input_shapes,例如:

keras.layers.Conv2D(32,3,input_shape=(300,9,21,1))
keras.layers.Conv2D(32,3,input_shape=(300,9,21))

but without success.但没有成功。

Thanks Prickels谢谢皮克尔斯

Prickels,皮克尔斯,

Just make sure that you feed the model with data in [n_items,9,21,1] shape.只需确保为模型提供 [n_items,9,21,1] 形状的数据。 use data = tf.expand_dims(data, axis =-1)使用data = tf.expand_dims(data, axis =-1)

Alternatively add Reshape layer first:或者先添加 Reshape 图层:

tf.keras.layers.Reshape((9,21,1), input_shape=(9,21))

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Keras Conv1D ValueError:层顺序的输入 0 与层不兼容::预期 min_ndim=3,发现 ndim=2 - Keras Conv1D ValueError: Input 0 of layer sequential is incompatible with the layer: : expected min_ndim=3, found ndim=2 ValueError:conv2d 层的输入 0 与层不兼容::预期 min_ndim=4,发现 ndim=3。 收到的完整形状:(2240、70、3) - ValueError: Input 0 of layer conv2d is incompatible with the layer: : expected min_ndim=4, found ndim=3. Full shape received: (2240, 70, 3) ValueError:层“conv2d”的输入 0 与层不兼容:预期 min_ndim=4,发现 ndim=3。 收到的完整形状:(28、28、1) - ValueError: Input 0 of layer "conv2d" is incompatible with the layer: expected min_ndim=4, found ndim=3. Full shape received: (28, 28, 1) 二进制信号数据:keras ValueError:层顺序的输入 0 与层不兼容::预期 min_ndim=3,发现 ndim=2 - binary signal data: keras ValueError: Input 0 of layer sequential is incompatible with the layer: : expected min_ndim=3, found ndim=2 ValueError: 层 conv1d 的输入 0 与层不兼容: : 预期 min_ndim=3, 发现 ndim=2 - ValueError: Input 0 of layer conv1d is incompatible with the layer: : expected min_ndim=3, found ndim=2 Keras Conv1d输入形状问题,conv1d层的输入0与层不兼容::预期min_ndim=3,发现ndim=2 - Keras Conv1d input shape problem, Input 0 of layer conv1d is incompatible with the layer: : expected min_ndim=3, found ndim=2 ValueError:conv2d 层的输入 0 与层不兼容::预期 min_ndim=4,发现 ndim=3。 收到的完整形状:(无、400、50) - ValueError: Input 0 of layer conv2d is incompatible with the layer: : expected min_ndim=4, found ndim=3. Full shape received: (None, 400, 50) ValueError:层顺序的输入0与层不兼容::预期的min_ndim = 4,发现ndim = 3 - ValueError: Input 0 of layer sequential is incompatible with the layer: : expected min_ndim=4, found ndim=3 在 Tensorflow 中创建 model 时出错。 ValueError: 层 conv2d_1 的输入 0 与层不兼容: : 预期 min_ndim=4, 发现 ndim=3 - Error with creating a model in Tensorflow. ValueError: Input 0 of layer conv2d_1 is incompatible with the layer: : expected min_ndim=4, found ndim=3 Keras CNN错误conv1d_13层的输入0与层不兼容::预期min_ndim=3,发现ndim=2 - Keras CNN error Input 0 of layer conv1d_13 is incompatible with the layer: : expected min_ndim=3, found ndim=2
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM