【问题标题】:Applying convolution on individual layers using keras使用 keras 在各个层上应用卷积
【发布时间】:2019-09-13 06:13:38
【问题描述】:

我有一个预训练的 VGG16 网络,我使用迁移学习修改了 PASCAL VOC 2012 数据集的网络。现在,我想从修改后的 VGG16 网络中获取每一层的输出,并在每一层上应用卷积,然后将它们上采样到相同的大小并添加它们。这是为了识别图像中的重要区域。我已经从每一层获取了输出

output = [layer.output for layer in model.layers]

现在我想要类似的东西

hypercolumns = []
for op in output:
            #apply convolution on this output layer 
            #upsample it to the size of the input image
            #store this in hypercolumns list

最后,在对所有层进行上采样后,我将从列表中添加它们以获得单个矩阵。现在,我对如何在不创建模型和进行上采样的情况下应用卷积感到困惑。 keras有没有办法。

【问题讨论】:

  • Now, I am confused on how to apply convolution without creating a model and do upsampling.。为此目的创建模型有什么问题?
  • @hushv89 我希望每一层都这样,所以在这种情况下,我会创建太多模型(输出列表中的一层一个模型),而且我必须在一个模型中编译和训练该模型我认为循环不是一个好方法。
  • 您可能想查看 Keras 中的 Lambda 层。您可以使用 Keras 后端功能来实现您想要做的事情。我不需要您使用Lambda 层创建多个模型。只有一个模型。

标签: python tensorflow keras deep-learning conv-neural-network


【解决方案1】:

有几种方法可以实现这一点,其中一些在here in the Keras FAQ 中列出。我不知道那里列出的两种主要方式之间有任何显着差异,因此请尝试两种方式,看看有什么用。这是您可以执行的操作的示例:

input = model.layers[0].input
for op in output:
    intermediate_function = K.function([input], [output])
    layer_output = intermediate_function([YOUR_INPUT_DATA_HERE])[0]
    # do the upsampling and stuff here

【讨论】:

    猜你喜欢
    • 2019-08-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-08-16
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多