【问题标题】:how to get a hidden layer of tensorflow hub module如何获得 tensorflow hub 模块的隐藏层
【发布时间】:2018-07-30 23:18:26
【问题描述】:
我想使用 tensorflow hub 为我的图像生成特征,但似乎 Inception Module 的 2048 个特征不足以解决我的问题,因为我的类图像非常相似。所以我决定使用这个模块的一个隐藏层的特性,例如:
“模块/InceptionV3/InceptionV3/Mixed_7c/concat:0”
那么我怎样才能编写一个函数来为我提供这个?*8*8*2048 来自我的输入图像的特征?
【问题讨论】:
标签:
python
tensorflow
tensorflow-hub
【解决方案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 张量,因此您可能希望在将其输入分类之前通过对它们进行 avg- 或 max-pooling 来移除这些中间维度。