【问题标题】:Getting imagenet model pnasnet_large with to work with hub.KerasLayer让 imagenet 模型 pnasnet_large 与 hub.KerasLayer 一起使用
【发布时间】: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


    【解决方案1】:

    目前,hub.KerasLayer 仅适用于https://tfhub.dev/google/tf2-preview/inception_v3/feature_vector/4 等 TF2 风格的模型。

    随着 TensorFlow 2.0 的发布,请继续关注更多 TF2 风格的模型选择。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-09-28
      • 2012-10-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多