我正在使用预训练的 ResNet-50 模型,并希望将倒数第二层的输出提供给 LSTM 网络。这是我仅包含 CNN (ResNet-50) 的示例代码:N = NUMBER_OF_CLASSES#img_size = (224,224,3)....same as that of ImageNet base_model = ResNet50(include_top=False, weights='imagenet',pooling=None)x = base_model.outputx = GlobalAveragePooling2D()(x)predictions = Dense(1024, activation='relu')(x)model = Model(inputs=base_model.input, outputs=predictions)接下来,我想把它喂给一个LSTM网络,如下...final_model = Sequential()final_model.add((model))final_model.add(LSTM(64, return_sequences=True, stateful=True))final_model.add(Dense(N, activation='softmax'))但我很困惑如何将输出重塑为 LSTM 输入。我的原始输入是 (224*224*3) 到 CNN。另外,我应该使用 TimeDistributed 吗?任何形式的帮助表示赞赏。
2 回答
幕布斯6054654
TA贡献1876条经验 获得超7个赞
将预训练网络与 LSTM 结合使用的示例:
inputs = Input(shape=(config.N_FRAMES_IN_SEQUENCE, config.IMAGE_H, config.IMAGE_W, config.N_CHANNELS))
cnn = VGG16(include_top=False, weights='imagenet', input_shape=(config.IMAGE_H, config.IMAGE_W, config.N_CHANNELS))
x = TimeDistributed(cnn)(inputs)
x = TimeDistributed(Flatten())(x)
x = LSTM(256)(x)
添加回答
举报
0/150
提交
取消