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

查看:34
本文介绍了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 ))

所以这就是我定义 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.

由于您可能使用了具有 4 个维度(包括批次)的 input_shape,因此 keras 将添加第 5 个维度.

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天全站免登陆