tensorflow / hub

A library for transfer learning by reusing parts of TensorFlow models.
https://tensorflow.org/hub
Apache License 2.0
3.49k stars 1.67k forks source link

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

Closed IavTavares closed 3 years ago

IavTavares commented 3 years ago

System information -Windows 10

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 commented 3 years ago

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 commented 3 years ago

@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 commented 3 years ago

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 commented 3 years ago

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

IavTavares commented 3 years ago

Well... it depends on what you mean by resolved. If you mean did I find a workaround? Yes. If the underlying issue was solved? No.

Sent from Mailhttps://go.microsoft.com/fwlink/?LinkId=550986 for Windows

From: @.> Sent: 22 October 2021 04:49 To: @.> Cc: @.>; @.> Subject: Re: [tensorflow/tensorflow] Saved Model doesn't exist error, when trying to use TensorFlow Hub (Issue tensorflow/tensorflow#52606)

@IavTavareshttps://github.com/IavTavares Thank you for the update! Could you please let us know if this issue is resolved ? Thanks!

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHubhttps://github.com/tensorflow/tensorflow/issues/52606#issuecomment-949262894, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AV4NS6PS7RCEXJ6FSSVQHATUIDNLJANCNFSM5GNNZ5ZQ. Triage notifications on the go with GitHub Mobile for iOShttps://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Androidhttps://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

sanatmpa1 commented 3 years ago

@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 commented 3 years ago

If I run

tfhub_handle_preprocess="https://tfhub.dev/tensorflow/bert_en_uncased_preprocess/3"

bert_preprocess_model = hub.KerasLayer(tfhub_handle_preprocess)

tfhub_handle_encoder="https://tfhub.dev/tensorflow/small_bert/bert_en_uncased_L-12_H-128_A-2/2"

bert_model = hub.KerasLayer(tfhub_handle_encoder)

Then I get the same error. However, if I point tfhub_handle_preprocess to a directory with the preprocess already downloaded, then everything works fine.

Sent from Mailhttps://go.microsoft.com/fwlink/?LinkId=550986 for Windows

From: @.> Sent: 22 October 2021 16:22 To: @.> Cc: @.>; @.> Subject: Re: [tensorflow/hub] Saved Model doesn't exist error, when trying to use TensorFlow Hub (Issue #816)

@IavTavareshttps://github.com/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!

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHubhttps://github.com/tensorflow/hub/issues/816#issuecomment-949729614, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AV4NS6JYBDWEQKGNQ5EEAT3UIF6R5ANCNFSM5GQVNJ2A. Triage notifications on the go with GitHub Mobile for iOShttps://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Androidhttps://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

sanatmpa1 commented 3 years ago

@IavTavares

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

UsharaniPagadala commented 3 years ago

@IavTavares

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