A_0xl 2021-07-29 17:31 采纳率: 33.3%
浏览 448
已结题

Input 0 of layer sequential is incompatible with the layer

用Keras-RNN-LSTM做模型时,报错

# 模型训练
from keras.callbacks import ModelCheckpoint
Train = True  

if __name__ == "__main__": 
    if Train == True:  
        train_iter = xs_gen()  
        val_iter = xs_gen(train=False)  

        ckpt = keras.callbacks.ModelCheckpoint(  
            filepath='best_model.{epoch:02d}-{val_loss:.4f}.h5',  
            monitor='val_loss', save_best_only=True,verbose=1)  
        

        model = build_model()  
        opt = Adam(0.0002)  
        model.compile(loss='categorical_crossentropy',  
                    optimizer=opt, metrics=['accuracy'])  
        print(model.summary())  

报错:

Found 400 train items.
list 1 is 3.0
Epoch 1/50
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-7-3994b0506699> in <module>
     28             validation_data = val_iter,
     29             validation_steps = (Long - Lens)//Batch_size,     # ###gai
---> 30             callbacks=[ckpt],
     31             )  
     32         model.save("finishModel.h5")

ValueError: Input 0 of layer sequential is incompatible with the layer: expected ndim=3, found ndim=2. Full shape received: (None, None)
  • 写回答

0条回答 默认 最新

    报告相同问题?

    问题事件

    • 系统已结题 8月6日
    • 创建了问题 7月29日

    悬赏问题

    • ¥30 电脑误删了手机的照片怎么恢复?
    • ¥15 (标签-python|关键词-char)
    • ¥15 python+selenium,在新增时弹出了一个输入框
    • ¥15 苹果验机结果的api接口哪里有??单次调用1毛钱及以下。
    • ¥20 学生成绩管理系统设计
    • ¥15 来一个cc穿盾脚本开发者
    • ¥15 CST2023安装报错
    • ¥15 使用diffusionbert生成文字 结果是PAD和UNK怎么办
    • ¥15 有人懂怎么做大模型的客服系统吗?卡住了卡住了
    • ¥20 firefly-rk3399上启动卡住了