使用keras在卷积层上应用卷积

时间:2019-09-12 00:39:51

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

我有一个经过预训练的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

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

1 个答案:

答案 0 :(得分:0)

有几种方法可以实现,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
相关问题