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

Saved Model doesn't exist error, when trying to use TensorFlow Hub #816

Closed
IavTavares opened this issue Oct 21, 2021 · 9 comments
Closed

Comments

@IavTavares
Copy link

System information
-Windows 10

  • TensorFlow version 2.6
  • Python version 3.8
  • Installed using "pip install tensorflow"

Describe the problem
I'm trying to follow tensorflow's tutorial on how to classify text with the BERT model.
However, using their notebook, I encounter a error message telling me that the model I saved does not exist.

Provide the exact sequence of commands / steps that you executed before running into the problem

I run the notebook I downloaded above. Everything goes well, until I run the following:
bert_preprocess_model = hub.KerasLayer(tfhub_handle_preprocess)

Any other info / logs

OSError Traceback (most recent call last)
in
----> 1 bert_preprocess_model = hub.KerasLayer(tfhub_handle_preprocess)

~\anaconda3\lib\site-packages\tensorflow_hub\keras_layer.py in init(self, handle, trainable, arguments, _sentinel, tags, signature, signature_outputs_as_dict, output_key, output_shape, load_options, **kwargs)
151
152 self._load_options = load_options
--> 153 self._func = load_module(handle, tags, self._load_options)
154 self._has_training_argument = func_has_training_argument(self._func)
155 self._is_hub_module_v1 = getattr(self._func, "_is_hub_module_v1", False)

~\anaconda3\lib\site-packages\tensorflow_hub\keras_layer.py in load_module(handle, tags, load_options)
447 except ImportError: # Expected before TF2.4.
448 set_load_options = load_options
--> 449 return module_v2.load(handle, tags=tags, options=set_load_options)
450
451

~\anaconda3\lib\site-packages\tensorflow_hub\module_v2.py in load(handle, tags, options)
104 module_path, tags=tags, options=options)
105 else:
--> 106 obj = tf.compat.v1.saved_model.load_v2(module_path, tags=tags)
107 obj._is_hub_module_v1 = is_hub_module_v1 # pylint: disable=protected-access
108 return obj

~\anaconda3\lib\site-packages\tensorflow\python\saved_model\load.py in load(export_dir, tags, options)
862 """
863 metrics.IncrementReadApi(_LOAD_V2_LABEL)
--> 864 result = load_internal(export_dir, tags, options)["root"]
865 metrics.IncrementRead()
866 return result

~\anaconda3\lib\site-packages\tensorflow\python\saved_model\load.py in load_internal(export_dir, tags, options, loader_cls, filters)
876 tags = nest.flatten(tags)
877 saved_model_proto, debug_info = (
--> 878 loader_impl.parse_saved_model_with_debug_info(export_dir))
879
880 if (len(saved_model_proto.meta_graphs) == 1 and

~\anaconda3\lib\site-packages\tensorflow\python\saved_model\loader_impl.py in parse_saved_model_with_debug_info(export_dir)
58 parsed. Missing graph debug info file is fine.
59 """
---> 60 saved_model = _parse_saved_model(export_dir)
61
62 debug_info_path = os.path.join(

~\anaconda3\lib\site-packages\tensorflow\python\saved_model\loader_impl.py in parse_saved_model(export_dir)
116 raise IOError("Cannot parse file %s: %s." % (path_to_pbtxt, str(e)))
117 else:
--> 118 raise IOError(
119 "SavedModel file does not exist at: %s%s{%s|%s}" %
120 (export_dir, os.path.sep, constants.SAVED_MODEL_FILENAME_PBTXT,

OSError: SavedModel file does not exist at: C:\Users\iavta\AppData\Local\Temp\tfhub_modules\602d30248ff7929470db09f7385fc895e9ceb4c0{saved_model.pbtxt|saved_model.pb}



In the directory C:\Users\iavta\AppData\Local\Temp\tfhub_modules\602d30248ff7929470db09f7385fc895e9ceb4c0

I have only two empty folders called "assets" and "variables".

@IavTavares
Copy link
Author

Also, the problem doesn't seem to be from TensorFlow-Hub, since when I run

import tensorflow_hub as hub
model = hub.KerasLayer("https://tfhub.dev/google/nnlm-en-dim128/2")
embeddings = model(["The rain in Spain.", "falls",
                      "mainly", "In the plain!"])

print(embeddings.shape)  #(4,128)

Everything runs smoothly, and I get the desired output.

@sushreebarsa
Copy link
Contributor

sushreebarsa commented Oct 21, 2021

@IavTavares Could you please refer to the similar issues link1, link2 ,Please have a look at the common issues and let us know if it helps?Thank you!

@IavTavares
Copy link
Author

IavTavares commented Oct 21, 2021

I tried one of the answers in link1.

I downloaded the preprocessing model, and redirected the hub.load() statement to the model's directory.

I also had to do something similar for the encoder.

@sushreebarsa
Copy link
Contributor

@IavTavares Thank you for the update! Could you please let us know if this issue is resolved ? Thanks!

@IavTavares
Copy link
Author

IavTavares commented Oct 22, 2021 via email

@sanatmpa1 sanatmpa1 transferred this issue from tensorflow/tensorflow Oct 22, 2021
@sanatmpa1
Copy link

@IavTavares,

Are you getting this error only when loading the model small_bert/bert_en_uncased_L-4_H-512_A-8? Can you try using ert_model_name = small_bert/bert_en_uncased_L-2_H-128_A-2 and let us know if you're getting the same error for that one as well? Thanks!

@IavTavares
Copy link
Author

IavTavares commented Oct 22, 2021 via email

@sanatmpa1
Copy link

@IavTavares

Can you try providing a custom directory for TFHUB_CACHE_DIR and let us know if the issue still persists? You can refer this link

@UsharaniPagadala
Copy link

@IavTavares

Closing this issue due to inactivity.Please feel free to reopen if this issue still persists.Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants