【问题标题】:Why I'm getting error incompatible with the layer?为什么我收到与图层不兼容的错误?
【发布时间】:2020-12-03 21:12:28
【问题描述】:

我有一个 cnn 网络,我正在尝试对其进行测试。 我收到关于输入的错误,我不知道为什么

    model = Sequential()
    model.add(Conv2D(32, kernel_size=(3, 3), activation='relu', input_shape=(99,13,1)))
    model.add(Conv2D(64, kernel_size=(3, 3), activation='relu'))
    model.add(MaxPooling2D(pool_size=(2, 2)))
    model.add(Dropout(0.25))
    model.add(Flatten())
    model.add(Dense(128, activation='relu'))
    model.add(Dropout(0.5))
    model.add(Dense(num_classes, activation='softmax'))
    model.compile(loss='categorical_crossentropy',optimizer='adam', metrics=['accuracy'])
    print(model.summary())
    model.fit(x_train, y_train, batch_size=4, epochs=10, verbose=1, validation_data=(x_test, y_test))

地点:

x_train / test .shape = {tuple: 3}(30, 99, 13)
y_train / test shape = {tuple: 1}30

错误:

ValueError: Input 0 of layer sequential is incompatible with the layer: : expected min_ndim=4, found ndim=3. Full shape received: [None, 99, 13]

出了什么问题,我该如何解决?

【问题讨论】:

    标签: tensorflow keras


    【解决方案1】:
    model.add(Conv2D(32, kernel_size=(3, 3), activation='relu', input_shape=(99,13,1)))
    

    模型等待形状 [batch, (99,13,1)],您正在尝试喂食 [batch, 99, 13]。 我认为您需要将输入更改为 input_shape=(99,13) 以匹配火车数据

    Conv2D 需要 4D+ shape 将数据维度扩展到批处理、99、13、1

    【讨论】:

    • 我更改为 input_shape=(99,13),我得到了类似的错误:ValueError: Input 0 of layer conv2d is incompatible with the layer: : expected min_ndim=4, found ndim=3.收到的完整形状:[None, 99, 13]
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-05-06
    • 2012-02-07
    • 2014-07-18
    • 1970-01-01
    • 2021-04-04
    • 1970-01-01
    • 2014-04-23
    相关资源
    最近更新 更多