我使用ResNet50模型进行特征提取。我有两个用以下方式初始化的模型:
from tensorflow.keras.applications import ResNet50
model1=ResNet50(weights="imagenet", include_top=False)
model2=ResNet50(weights="imagenet", include_top=True)`现在,当我绘制模型架构时,我得到这样的结果:(我只展示了架构的结尾)

它们都不会在avg_pool: GlobalAveragePooling2D结束,即我希望模型的输出为( ?,2048 )。有可能得到架构吗?使用imagenet权重获得这样的架构将使特征提取变得容易。
会很感激你的帮助。
发布于 2020-05-20 23:05:23
您可以从全局平均池(GAP)层的ResNet输入和输出生成新的keras模型。为了获得GAP层的输出,您需要使用get_layer方法提取它。通过使用model.summary()查找图层名称,可以对任何图层执行此操作
model1=ResNet50(weights='imagenet', include_top=True)
GAP_output = model1.get_layer('avg_pool').output
new_model = tf.keras.Model(model1.input, GAP_output)
new_model.summary()https://stackoverflow.com/questions/61915869
复制相似问题