我有一个预训练的 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 中有没有办法。
有几种方法可以实现这一点,其中一些列在 Keras 常见问题解答中。我不知道那里列出的两种主要方式之间有什么显着区别,因此请尝试两种方法,看看哪种方法有效。以下是您可以执行的操作的示例:
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
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句