如何获取tensorflow hub模块的隐藏层

how to get a hidden layer of tensorflow hub module

我想使用 tensorflow hub 为我的图像生成特征,但 Inception Module 的 2048 个特征似乎不足以解决我的问题,因为我的 class 图像非常相似。所以我决定使用这个模块的隐藏层的特性,例如:

"module/InceptionV3/InceptionV3/Mixed_7c/concat:0"

那么我如何编写一个函数来从我的输入图像中获得这个?*8*8*2048 个特征?

请尝试

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

除了带有最终特征向量输出的 default 输出之外,您应该看到一堆中间特征图,在以 InceptionV3/ 开头的键下(或您 select ).这些是形状为 [batch_size, feature_map_height, feature_map_width, num_features] 的 4D 张量,因此您可能希望在将其输入分类之前通过对它们进行平均或最大池化来删除这些中间维度。