如何获取tensorflow集线器模块的隐藏层

时间:2018-07-24 13:46:42

标签: python tensorflow tensorflow-hub

我想使用tensorflow集线器为我的图像生成特征,但是似乎Inception Module的2048个功能不足以解决我的问题,因为我的类图像非常相似。因此,我决定使用此模块隐藏层的功能,例如:

  

“模块/ InceptionV3 / InceptionV3 / Mixed_7c / concat:0”

那么我该如何从我的输入图像中编写一个为我提供此* 8 * 8 * 2048功能的函数?

1 个答案:

答案 0 :(得分:1)

请尝试

module = hub.Module(...)  # As before.
outputs = module(dict(images=images),
                 signature="image_feature_vector",
                 as_dict=True)
print(outputs.items())

除了具有最终特征向量输出的default输出之外,您还应该在以InceptionV3/开头的键(或选择的任何其他体系结构)下看到一堆中间特征图。这些是形状为[batch_size, feature_map_height, feature_map_width, num_features]的4D张量,因此您可能希望通过在它们中间进行平均或最大合并来移除这些中间尺寸,然后再将其输入分类。

相关问题