Keras ValueError:输入0与层conv2d_1不兼容:预期ndim = 4,找到的ndim = 5 [英] Keras ValueError: Input 0 is incompatible with layer conv2d_1: expected ndim=4, found ndim=5

查看:247
本文介绍了Keras ValueError:输入0与层conv2d_1不兼容:预期ndim = 4,找到的ndim = 5的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经检查了所有解决方案,但是仍然遇到相同的错误。我的训练图像形状为(26721,32,32,1),我相信它是4维的,但是我不知道为什么错误显示它是5维的。

I have checked all the solutions, but still, I am facing the same error. My training images shape is (26721, 32, 32, 1), which I believe it is 4 dimension, but I don't know why error shows it is 5 dimension.

 model = Sequential()

 model.add(Convolution2D(16, 5, 5, border_mode='same', input_shape= input_shape ))

这就是我定义<$ c $的方式c> model.fit_generator

model.fit_generator(train_dataset, train_labels, nb_epoch=epochs, verbose=1,validation_data=(valid_dataset, valid_labels), nb_val_samples=valid_dataset.shape[0],callbacks=model_callbacks)


推荐答案

问题是 input_shape

实际上应该只包含3个维度。并且在内部keras将添加批处理尺寸,使其成为4。

It should actually contain 3 dimensions only. And internally keras will add the batch dimension making it 4.

由于您可能使用了 input_shape 具有4个尺寸(批处理包括在内),喀拉拉邦则排名第五。

Since you probably used input_shape with 4 dimensions (batch included), keras is adding the 5th.

您应该使用 input_shape =(32,32,1)

这篇关于Keras ValueError:输入0与层conv2d_1不兼容:预期ndim = 4,找到的ndim = 5的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆