我想使用 tensorflow hub 为我的图像生成特征,但似乎 Inception Module 的 2048 个特征不足以解决我的问题,因为我的类图像非常相似。所以我决定使用这个模块的一个隐藏层的特性,例如:
“模块/InceptionV3/InceptionV3/Mixed_7c/concat:0”
那么我怎样才能编写一个函数来给我这个?* 8 * 8 * 2048 来自我的输入图像的特征?
我想使用 tensorflow hub 为我的图像生成特征,但似乎 Inception Module 的 2048 个特征不足以解决我的问题,因为我的类图像非常相似。所以我决定使用这个模块的一个隐藏层的特性,例如:
“模块/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/
(或您选择的任何其他架构)开头的键下。这些是具有 shape 的 4D 张量[batch_size, feature_map_height, feature_map_width, num_features]
,因此您可能希望在将其输入分类之前通过对它们进行 avg- 或 max-pooling 来删除这些中间维度。