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

2024-09-30 22:10:00 发布

您现在位置:Python中文网/ 问答频道 /正文

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

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


Tags: the数据in图像网络layer区域for
1条回答
网友
1楼 · 发布于 2024-09-30 22:10:00

有几种方法可以实现这一点,其中一些方法在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

相关问题 更多 >