【发布时间】:2020-01-12 17:09:51
【问题描述】:
我正在尝试来自 hub 的各种 Tensorflow 模型,但是 我似乎无法让这个与 KerasLayer 一起工作:
“https://tfhub.dev/google/imagenet/pnasnet_large/feature_vector/3”
我正在使用文档中示例中使用的相同程序:
https://www.tensorflow.org/tutorials/images/hub_with_keras
feature_extractor = hub.KerasLayer(URL,
input_shape=(height, width,3))
甚至尝试了一些修改,例如:
trainable=True, tags={"train"}),
所以它看起来像这样:
feature_extractor = hub.KerasLayer(URL,
input_shape=(height, width,3), trainable=True, tags={"train"}))
因为这就是它在文档中所说的。
但是,我仍然收到此错误:
ValueError:如果存在多个 MetaGraph,则使用 tf.saved_model.load 导入 SavedModel 需要一个“tags=”参数。得到了'tags=None',但 SavedModel 中有 2 个带有标签集 [[]、['train']] 的 MetaGraph。传递一个 'tags=' 参数来加载这个 SavedModel
import tensorflow as tf
import tensorflow_hub as hub
import time
import numpy as np
import matplotlib.pylab as plt
import tensorflow_datasets as tfds
tfds.disable_progress_bar()
from tensorflow.keras import layers
from tensorflow.keras.applications import imagenet_utils
from tensorflow.keras.callbacks import ModelCheckpoint
tf.compat.v1.disable_eager_execution()
URL = "https://tfhub.dev/google/imagenet/pnasnet_large/feature_vector/3"
module = hub.Module(URL)
height, width = hub.get_expected_image_size(module)
# here is where the error comes from
feature_extractor = hub.KerasLayer(URL,
input_shape=(height, width,3), trainable=True, tags={"train"})
【问题讨论】:
标签: python python-3.x tensorflow