【发布时间】:2019-03-02 16:22:34
【问题描述】:
我正在使用预训练的 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.output
x = 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 吗?
感谢任何形式的帮助。
【问题讨论】:
-
您是否使用 imageDataGenerator 来准备图像序列?
-
@TheJokerAEZ 不,我没有使用 ImageDataGenerator。改为使用预先保存的路径...
标签: python tensorflow neural-network keras lstm