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

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日

    悬赏问题

    • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
    • ¥15 TLE9879QXA40 电机驱动
    • ¥15 clion的参数提示怎么关闭
    • ¥20 对于工程问题的非线性数学模型进行线性化
    • ¥15 Mirare PLUS 进行密钥认证?(详解)
    • ¥15 物体双站RCS和其组成阵列后的双站RCS关系验证
    • ¥20 想用ollama做一个自己的AI数据库
    • ¥15 关于qualoth编辑及缝合服装领子的问题解决方案探寻
    • ¥15 请问怎么才能复现这样的图呀
    • ¥15 mifare plus卡认证