max_pooling2d层的输入0与该层不兼容:预期ndim = 4,找到的ndim = 5.收到完整的图形:[无,4、10、8、32] [英] Input 0 of layer max_pooling2d is incompatible with the layer: expected ndim=4, found ndim=5. Full shape received: [None, 4, 10, 8, 32]

查看:248
本文介绍了max_pooling2d层的输入0与该层不兼容:预期ndim = 4,找到的ndim = 5.收到完整的图形:[无,4、10、8、32]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我尝试定义模型时,出现以下错误消息:

When I try to define my model, I get the following error message:

Input 0 of layer max_pooling2d is incompatible with the layer: 
expected ndim=4, found ndim=5. 
Full shape received: [None, 4, 10, 8, 32].

我正在使用的代码是:

X_train = X_train.reshape(X_train.shape[0], 8, 10, 1)
X_test = X_test.reshape(len(X_test),10,8,1)
print(type(X_train),np.shape(X_train))



# CNN 
model = Sequential()
model.add(layers.Conv2D(32, (2, 2), activation='relu',
                    input_shape=(4,10, 8, 1),padding='same'))
model.add(layers.MaxPooling2D((2, 2)))
model.add(layers.Conv2D(64, (3, 3), activation='relu'))
model.add(layers.MaxPooling2D((2, 2)))
model.add(layers.Conv2D(64, (3, 3), activation='relu'))
model.add(layers.Flatten())
model.add(layers.Dense(64, activation='relu'))
model.add(Dropout(0.5))
model.add(layers.Dense(10, activation='softmax'))

推荐答案

输入层需要NHWC或NCHW格式的数据.

Input Layer is either expects data in the format of NHWC or NCHW.

N = Number of samples
H = Height of the Image
W = Width of the Image
C = Number of Channels

在大多数情况下,N保持变化,因此N被指定为None.根据您的例如,您可以提供输入形状,并在NHWC和NCHW之间进行转换,您可以将输入参数指定为data_format ='channel_first'或data_format ='channel_last'

In most cases, N keeps varying so N is given as None. Based on your example, you can provide input shape and to convert between NHWC and NCHW you give input parameter as data_format=‘channel_first’ or data_format=‘channel_last’

这篇关于max_pooling2d层的输入0与该层不兼容:预期ndim = 4,找到的ndim = 5.收到完整的图形:[无,4、10、8、32]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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