Keras:ValueError:输入 0 与层 lstm_1 不兼容:预期 ndim=3,发现 ndim=2

时间:2021-05-05 21:43:57

标签: tensorflow keras deep-learning lstm

我正在使用 Keras 函数式 API 编写一个 LSTM 模型,但它抛出了一个错误,有人可以帮忙吗?下面是输出形状为 65 的模型的代码。

event_num = 65
droprate = 0.3
vector_size = 572

def DNN():
    train_input=Input(shape=(vector_size*2,),name='Inputlayer')
    train_in=LSTM(512)(train_input)
    # train_in=BatchNormalization()(train_in)
    train_in=Dropout(droprate)(train_in)
    train_in=LSTM(256)(train_in)
    # train_in=BatchNormalization()(train_in)
    train_in=Dropout(droprate)(train_in)
    train_in=Flatten()(train_in)
    train_in=Dense(event_num)(train_in)
    out=Activation('softmax')(train_in)
    model=Model(input=train_input,output=out)
    model.compile(optimizer='adam', loss='categorical_crossentropy', metrics=['accuracy'])
    return model

Error of the code

0 个答案:

没有答案