【问题标题】:Obtaining model of ResNet50 which cannot be obtained with the include_top attribute获取 ResNet50 无法通过 include_top 属性获取的模型
【发布时间】:2020-09-06 23:35:40
【问题描述】:

我正在使用 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 权重获得这样的架构将简化特征提取。

不胜感激。

【问题讨论】:

    标签: tensorflow keras resnet imagenet


    【解决方案1】:

    您可以从 ResNet 输入和全局平均池化 (GAP) 层的输出生成新的 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()
    

    【讨论】:

    • 工作就像一个魅力,你能告诉我model1.input中的'input'方法是什么。在 keras 文档中找不到它
    • 这不是方法,它提取模型输入张量。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-12-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-09-28
    • 2014-03-30
    相关资源
    最近更新 更多