提取CNN的特征向量

数据挖掘 喀拉斯 特征提取 美国有线电视新闻网
2021-09-27 07:24:09

如何获取数据集的特征向量。我的数据有一个微调的 CNN 模型。现在我想将从 CNN 的最后一层提取的所有数据集的特征输入到 LSTM 中。

到目前为止我有

cnn_model = load_model('weights/pre-trained_CNN.hdf5')
cnn_output = cnn_model.get_layer('fc7').output

我知道我必须将我所有的数据集都输入这个模型,但我不知道如何“保存”这些特征。

1个回答

为了“挖掘”现有模型的中间层,您可以执行以下操作:

# get your feature layer
cnn_model = load_model('weights/pre-trained_CNN.hdf5')
feature_layer = cnn_model.get_layer('fc7')

# stack your LSTM and other layers below, e.g.:
lstm_layer = TimeDistributed(LSTM(...), input_shape = ...)(feature_layer)
output = Dense(...)(lstm_layer)

# create a combined model 
model = Model(inputs = cnn_model.input, outputs = [output])