【问题标题】:LSTM on top of a pre-trained CNNLSTM 在预训练的 CNN 之上
【发布时间】:2018-03-28 13:08:47
【问题描述】:

我已经训练了一个 CNN,现在我想加载模型,然后在上面放置一个 LSTM,但我遇到了一些错误。

'''
Load the output of the CNN
'''
cnn_model = load_model(os.path.join('weights', 'CNN_patch_epoch-20.hdf5'))

last_layer = cnn_model.get_layer('pool5').output    

''' Freeze previous layers '''
for layer in cnn_model.layers:
    layer.trainable = False

x = TimeDistributed(Flatten())(last_layer)
x = LSTM(neurons, dropout=dropout, name='lstm')(x)
out = Dense(n_output, kernel_initializer=weight_init, name='out')(x)

model = Model(inputs=[cnn_model.input], outputs=out)

model.summary() 

我不确定在哪里指定我想要 5 帧(图像)。所以我的输入是(None, 5, 224, 224, 3)。所以我的问题是我应该在哪里指定它?

谢谢

【问题讨论】:

    标签: tensorflow keras conv-neural-network lstm


    【解决方案1】:

    您也可以将 cnn_model 包装在 TimeDistributed 包装器中。

    frames = Input(shape=(5, 224, 224, 3))
    x = TimeDistributed(cnn_model)(frames)
    x = TimeDistributed(Flatten())(x)
    x = LSTM(neurons, dropout=dropout, name='lstm')(x)
    out = Dense(n_output, kernel_initializer=weight_init, name='out')(x)
    model = Model(inputs=frames, outputs=out)
    

    【讨论】:

      猜你喜欢
      • 2017-06-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-07-22
      • 2016-10-11
      • 2017-07-07
      • 2019-03-02
      • 2021-10-07
      相关资源
      最近更新 更多