【问题标题】:I have this error "input 0 is incompatible with layer lstm expected ndim=3 found ndim=5"我有这个错误“输入 0 与层 lstm 不兼容预期 ndim=3 发现 ndim=5”
【发布时间】:2023-03-12 23:30:02
【问题描述】:

我是这个领域的新手。我在互联网上搜索,但找不到解决方案。我正在等待对此领域感兴趣的人的帮助。

我的模型

def load_VGG16_model():
    base_model = VGG16(weights='imagenet', include_top=False, input_shape=(256,256,3))
    print("Model loaded..!")
    return base_model

模型总结

load_VGG16_model().summary()

添加图层

def action_model(shape=(30, 256, 256, 3), nbout=len(classes)):
    convnet = load_VGG16_model()

    model = Sequential()
    model.add(TimeDistributed(convnet, input_shape=shape))
    model.add(LSTM(30,return_sequences=True,input_shape=(30,512))) # the error shows this line.
    top_model.add(Dense(4096, activation='relu', W_regularizer=l2(0.1)))
    top_model.add(Dropout(0.5))
    top_model.add(Dense(4096, activation='relu', W_regularizer=l2(0.1)))
    top_model.add(Dropout(0.5))
    model.add(Dense(nbout, activation='softmax'))
    return model

model.add(LSTM(30,return_sequences=True,input_shape=(30,512))) ==>错误显示这一行。

【问题讨论】:

    标签: machine-learning deep-learning artificial-intelligence lstm conv-neural-network


    【解决方案1】:

    你的问题和这个Building CNN + LSTM in Keras for a regression problem. What are proper shapes?类似

    在 LSTM 之前使用重塑层应该可以正常工作

    def action_model(shape=(256, 256, 3), nbout=len(classes)):
        convnet = load_VGG16_model()
    
        model = Sequential()
        model.add(convnet)
        model.add(tf.keras.layers.Reshape((8*8, 512))) # Shape comes from the last output of covnet
        model.add(LSTM(30,return_sequences=True,input_shape=(8*8,512))) # the error shows this line.
        top_model.add(Dense(4096, activation='relu', W_regularizer=l2(0.1)))
        top_model.add(Dropout(0.5))
        top_model.add(Dense(4096, activation='relu', W_regularizer=l2(0.1)))
        top_model.add(Dropout(0.5))
        model.add(Dense(nbout, activation='softmax'))
        return model
    

    【讨论】:

      猜你喜欢
      • 2020-06-12
      • 1970-01-01
      • 1970-01-01
      • 2020-10-05
      • 2022-08-15
      • 2019-04-14
      • 2019-06-04
      • 2018-09-25
      • 2017-11-18
      相关资源
      最近更新 更多