【问题标题】:ValueError: Importing a SavedModel with tf.saved_model.load requires a 'tags=' argumentValueError:使用 tf.saved_model.load 导入 SavedModel 需要“tags=”参数
【发布时间】:2019-08-07 21:06:51
【问题描述】:

我正在关注使用 tensorflow 1.14 的教程 Hub with Keras。我没有为 MacOS 安装 tf-nightly-gpu,因为它 does not seem to be available。在 keras.Sequential() 之前一切都很好:

import tensorflow_hub as hub
from tensorflow.keras import layers
classifier_url ="https://tfhub.dev/google/imagenet/resnet_v2_50/feature_vector/3"
IMAGE_SHAPE = (224, 224)
classifier = tf.keras.Sequential([
     hub.KerasLayer(classifier_url, input_shape=IMAGE_SHAPE+(3,))
])

最后一行给出以下错误:

ValueError: Importing a SavedModel with tf.saved_model.load requires a 'tags=' argument if there is more than one MetaGraph. Got 'tags=None', but there are 2 MetaGraphs in the SavedModel with tag sets [[], ['train']]. Pass a 'tags=' argument to load this SavedModel.

是和tensorflow版本有关还是和别的有关?

MacOS High Sierra 10.13.1 蟒蛇 3.6.8 张量流 1.14.0

【问题讨论】:

  • 我被困在同一个module = hub.load(feature_extractor_url, tags='train') print(type(module)) #feature_extractor_layer = hub.KerasLayer(module, # input_shape=(HEIGHT, WIDTH, CHANNELS)) 返回错误,看起来句柄可能在 TF 2.X 中工作,将检查。
  • “将 TF2 的 Hub 模块(或类似的可调用)包装为 Keras 层。” tensorflow.org/hub/api_docs/python/hub/KerasLayer

标签: python-3.x tensorflow


【解决方案1】:

这在 TF 1.14.0 中对我有用:


# Image information
HEIGHT = 224
WIDTH = 224
CHANNELS = 3
IMAGE_SHAPE = (HEIGHT, WIDTH)

feature_extractor_url = "https://tfhub.dev/google/imagenet/resnet_v2_50/feature_vector/3" #@param {type:"string"}

module = hub.Module(feature_extractor_url, tags=['train'])
feature_extractor_layer = hub.KerasLayer(module, 
                                         input_shape=(HEIGHT, WIDTH, CHANNELS))

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-04-16
    • 1970-01-01
    • 1970-01-01
    • 2016-12-01
    • 2015-11-05
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多