【问题标题】: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]层 max_pooling2d 的输入 0 与层不兼容:预期 ndim=4,发现 ndim=5。收到的完整形状:[None, 4, 10, 8, 32]
【发布时间】:2020-11-01 12:27:46
【问题描述】:

当我尝试定义我的模型时,我收到以下错误消息:

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'))

【问题讨论】:

    标签: python tensorflow conv-neural-network


    【解决方案1】:

    输入层需要 NHWC 或 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'

    【讨论】:

    • 我的数据不是其时代的图像
    猜你喜欢
    • 1970-01-01
    • 2021-03-22
    • 2020-11-15
    • 2020-09-01
    • 2021-01-14
    • 2020-08-13
    • 2021-04-09
    • 2020-08-11
    • 1970-01-01
    相关资源
    最近更新 更多