Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't load Keras model with multiple MetaGraphs, can't pass tags #37068

Closed
uchua opened this issue Feb 25, 2020 · 11 comments
Closed

Can't load Keras model with multiple MetaGraphs, can't pass tags #37068

uchua opened this issue Feb 25, 2020 · 11 comments
Assignees
Labels
comp:keras Keras related issues stale This label marks the issue/pr stale - to be closed automatically if no activity stat:awaiting response Status - Awaiting response from author TF 1.15 for issues seen on TF 1.15 type:bug Bug

Comments

@uchua
Copy link

uchua commented Feb 25, 2020

  • Have I written custom code: Yes
  • OS Platform and Distribution: Amazon Linux AMI 2018.03
  • TensorFlow installed from: Preinstalled by Amazon
  • TensorFlow version: 1.15.0
  • Python version: 3.6
  • CUDA/cuDNN version:
  • GPU model and memory: Nvidia Tesla V100

Describe the current behavior
When trying to load a saved model using keras.models.load_model, an error occurs stating that tf.saved_model.load requires a 'tags='. There is also no way to pass tags through the load_model function.

Describe the expected behavior
Model should load.

Standalone code to reproduce the issue
With "albert/" being a path to this model locally: https://tfhub.dev/google/albert_xlarge/3:

from tensorflow import keras

model = keras.models.load_model("albert/")

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.

Other info / logs

File "albert_entrypoint.py", line 50, in <module>
    model = keras.models.load_model(MODEL_EXTRACT_DIR)
  File "/usr/local/lib/python3.6/dist-packages/tensorflow_core/python/keras/saving/save.py", line 147, in load_model
    return saved_model_load.load(filepath, compile)
  File "/usr/local/lib/python3.6/dist-packages/tensorflow_core/python/keras/saving/saved_model/load.py", line 86, in load
    model = tf_load.load_internal(path, loader_cls=KerasObjectLoader)
  File "/usr/local/lib/python3.6/dist-packages/tensorflow_core/python/saved_model/load.py", line 550, in load_internal
    root = load_v1_in_v2.load(export_dir, tags)
  File "/usr/local/lib/python3.6/dist-packages/tensorflow_core/python/saved_model/load_v1_in_v2.py", line 239, in load
    return loader.load(tags=tags)
  File "/usr/local/lib/python3.6/dist-packages/tensorflow_core/python/saved_model/load_v1_in_v2.py", line 168, in load
    meta_graph_def = self.get_meta_graph_def_from_tags(tags)
  File "/usr/local/lib/python3.6/dist-packages/tensorflow_core/python/saved_model/load_v1_in_v2.py", line 80, in get_meta_graph_def_from_tags
    .format(len(self._saved_model.meta_graphs), tag_sets))

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.
@uchua uchua added the type:bug Bug label Feb 25, 2020
@uchua uchua changed the title Can't load Keras model with multiple Can't load Keras model with multiple MetaGraphs, can't pass tags Feb 25, 2020
@ravikyram ravikyram added the TF 1.15 for issues seen on TF 1.15 label Feb 26, 2020
@ravikyram
Copy link
Contributor

@uchua

This issue is more suitable for TensorFlow Hub repo. Please post it on hub repo from here. Thanks!

@ravikyram ravikyram added the stat:awaiting response Status - Awaiting response from author label Feb 26, 2020
@uchua
Copy link
Author

uchua commented Feb 26, 2020

@ravikyram outside of the model (which I don't believe the TensorFlow Hub team would have any control of), the issue doesn't involve TensorFlow Hub. Any model with multiple MetaGraphs (where tf.saved_model.load requires the tags= argument), won't be able to be load correctly.

@ravikyram ravikyram added comp:keras Keras related issues and removed stat:awaiting response Status - Awaiting response from author labels Feb 27, 2020
@ravikyram
Copy link
Contributor

I have tried on colab with TF version 1.15 , 2.2.0-dev20200226 and was able to reproduce the issue.Please, find the gist here. Thanks!

@ravikyram ravikyram assigned gowthamkpr and unassigned ravikyram Feb 27, 2020
@gowthamkpr
Copy link

You can load the module as a Keras layer to use it. Heres the gist.

I was also able to lad the model using tf.saved_model.load() which has tags argument. Please find the gist here.

keras.models.load_model doesnt have tags argument explicitly defined and thats the reason why you are not able to load this model.

@gowthamkpr gowthamkpr added the stat:awaiting response Status - Awaiting response from author label Feb 28, 2020
@uchua
Copy link
Author

uchua commented Mar 2, 2020

Is there a way to load a model using tf.saved_model.load() and then add it to a Keras model?

@tensorflowbutler tensorflowbutler removed the stat:awaiting response Status - Awaiting response from author label Mar 4, 2020
@gowthamkpr
Copy link

You can take the outputs of the loaded model and create a new model with those outputs @uchua
You can take a look at this issue

@gowthamkpr gowthamkpr added the stat:awaiting response Status - Awaiting response from author label Mar 5, 2020
@bilalghanem
Copy link

Upgrade your tensorflow version to 2.0.

@tensorflowbutler
Copy link
Member

It has been 29 days with no activity and the awaiting response label was assigned. Is this still an issue?

@google-ml-butler
Copy link

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you.

@google-ml-butler google-ml-butler bot added the stale This label marks the issue/pr stale - to be closed automatically if no activity label Apr 20, 2020
@gowthamkpr
Copy link

Closing this issue as it has been inactive for 3 weeks. Please add additional comments for us to open this issue again.

@google-ml-butler
Copy link

Are you satisfied with the resolution of your issue?
Yes
No

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
comp:keras Keras related issues stale This label marks the issue/pr stale - to be closed automatically if no activity stat:awaiting response Status - Awaiting response from author TF 1.15 for issues seen on TF 1.15 type:bug Bug
Projects
None yet
Development

No branches or pull requests

5 participants