1
votes

I am trying out various Tensorflow models from hub but I can't seem to get this one to work with KerasLayer:

"https://tfhub.dev/google/imagenet/pnasnet_large/feature_vector/3"

I am using the same procedure used within the examples in the documentation:

https://www.tensorflow.org/tutorials/images/hub_with_keras

feature_extractor = hub.KerasLayer(URL, input_shape=(height, width,3))

even tried a few amendments such as including: trainable=True, tags={"train"}),

so it would look like this:

feature_extractor = hub.KerasLayer(URL, input_shape=(height, width,3), trainable=True, tags={"train"}))

because that's what it said to do in the docs.

However, I am still getting this error:

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

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"})
1

1 Answers

1
votes

At this time, hub.KerasLayer only works for TF2-style models like https://tfhub.dev/google/tf2-preview/inception_v3/feature_vector/4.

Please stay tuned for more choice of TF2-style models as TensorFlow 2.0 is getting released.