When downloading trained models and loading saved model, it gives `OSError: SavedModel file does not exist at: C:\Users\user\AppData\Local\Temp\tfhub_modules\602d30248ff7929470db09f7385fc895e9ceb4c0\{saved_model.pbtxt|saved_model.pb}`
HermanTam opened this issue · 5 comments
The codes were working with no such errors last month. However, I tried running the same codes today and the following codes generate the OS error. It generates the following OS Error when I tried to download the trained models (bert_preprocessor & bert_encoder) with correct URLs or load the saved model with the correct path as they worked last time. I am curious to know why that is. Thanks!
bert_preprocessor = hub.KerasLayer('https://tfhub.dev/tensorflow/bert_en_uncased_preprocess/3')
OSError Traceback (most recent call last)
~\AppData\Local\Temp/ipykernel_10908/280207346.py in <module>
----> 1 bert_preprocessor = hub.KerasLayer('https://tfhub.dev/tensorflow/bert_en_uncased_preprocess/3')
2 bert_encoder = hub.KerasLayer('https://tfhub.dev/tensorflow/bert_en_uncased_L-12_H-768_A-12/4')
~\AppData\Local\Programs\Python\Python39\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)
~\AppData\Local\Programs\Python\Python39\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
~\AppData\Local\Programs\Python\Python39\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
~\AppData\Roaming\Python\Python39\site-packages\tensorflow\python\saved_model\load.py in load(export_dir, tags, options)
798 if isinstance(export_dir, os.PathLike):
799 export_dir = os.fspath(export_dir)
--> 800 result = load_partial(export_dir, None, tags, options)["root"]
801 return result
802
~\AppData\Roaming\Python\Python39\site-packages\tensorflow\python\saved_model\load.py in load_partial(export_dir, filters, tags, options)
903 tags = nest.flatten(tags)
904 saved_model_proto, debug_info = (
--> 905 loader_impl.parse_saved_model_with_debug_info(export_dir))
906
907 if (len(saved_model_proto.meta_graphs) == 1 and
~\AppData\Roaming\Python\Python39\site-packages\tensorflow\python\saved_model\loader_impl.py in parse_saved_model_with_debug_info(export_dir)
55 parsed. Missing graph debug info file is fine.
56 """
---> 57 saved_model = parse_saved_model(export_dir)
58
59 debug_info_path = file_io.join(
~\AppData\Roaming\Python\Python39\site-packages\tensorflow\python\saved_model\loader_impl.py in parse_saved_model(export_dir)
113 raise IOError(f"Cannot parse file {path_to_pbtxt}: {str(e)}.")
114 else:
--> 115 raise IOError(
116 f"SavedModel file does not exist at: {export_dir}{os.path.sep}"
117 f"{{{constants.SAVED_MODEL_FILENAME_PBTXT}|"
OSError: SavedModel file does not exist at: C:\Users\user\AppData\Local\Temp\tfhub_modules\602d30248ff7929470db09f7385fc895e9ceb4c0\{saved_model.pbtxt|saved_model.pb}
bert_encoder = hub.KerasLayer('https://tfhub.dev/tensorflow/bert_en_uncased_L-12_H-768_A-12/4')
OSError Traceback (most recent call last)
~\AppData\Local\Temp/ipykernel_10908/453047902.py in <module>
1 #bert_preprocessor = hub.KerasLayer('https://tfhub.dev/tensorflow/bert_en_uncased_preprocess/3')
----> 2 bert_encoder = hub.KerasLayer('https://tfhub.dev/tensorflow/bert_en_uncased_L-12_H-768_A-12/4')
~\AppData\Local\Programs\Python\Python39\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)
~\AppData\Local\Programs\Python\Python39\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
~\AppData\Local\Programs\Python\Python39\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
~\AppData\Roaming\Python\Python39\site-packages\tensorflow\python\saved_model\load.py in load(export_dir, tags, options)
798 if isinstance(export_dir, os.PathLike):
799 export_dir = os.fspath(export_dir)
--> 800 result = load_partial(export_dir, None, tags, options)["root"]
801 return result
802
~\AppData\Roaming\Python\Python39\site-packages\tensorflow\python\saved_model\load.py in load_partial(export_dir, filters, tags, options)
903 tags = nest.flatten(tags)
904 saved_model_proto, debug_info = (
--> 905 loader_impl.parse_saved_model_with_debug_info(export_dir))
906
907 if (len(saved_model_proto.meta_graphs) == 1 and
~\AppData\Roaming\Python\Python39\site-packages\tensorflow\python\saved_model\loader_impl.py in parse_saved_model_with_debug_info(export_dir)
55 parsed. Missing graph debug info file is fine.
56 """
---> 57 saved_model = parse_saved_model(export_dir)
58
59 debug_info_path = file_io.join(
~\AppData\Roaming\Python\Python39\site-packages\tensorflow\python\saved_model\loader_impl.py in parse_saved_model(export_dir)
113 raise IOError(f"Cannot parse file {path_to_pbtxt}: {str(e)}.")
114 else:
--> 115 raise IOError(
116 f"SavedModel file does not exist at: {export_dir}{os.path.sep}"
117 f"{{{constants.SAVED_MODEL_FILENAME_PBTXT}|"
OSError: SavedModel file does not exist at: C:\Users\user\AppData\Local\Temp\tfhub_modules\d760773f85f64fc84ae0b47310f7cfe3bcec4868\{saved_model.pbtxt|saved_model.pb}
loaded_model = tf.keras.models.load_model(
('BertForSpam.h5'),
custom_objects={'KerasLayer':hub.KerasLayer}
)
OSError Traceback (most recent call last)
~\AppData\Local\Temp/ipykernel_10908/1893849820.py in <module>
2 #ValueError: Unknown layer: KerasLayer. Please ensure this object is passed to the `custom_objects` argument.
3
----> 4 loaded_model = tf.keras.models.load_model(
5 ('BertForSpam.h5'),
6 custom_objects={'KerasLayer':hub.KerasLayer}
~\AppData\Local\Programs\Python\Python39\lib\site-packages\keras\utils\traceback_utils.py in error_handler(*args, **kwargs)
68 # To get the full stack trace, call:
69 # `tf.debugging.disable_traceback_filtering()`
---> 70 raise e.with_traceback(filtered_tb) from None
71 finally:
72 del filtered_tb
~\AppData\Local\Programs\Python\Python39\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)
~\AppData\Local\Programs\Python\Python39\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
~\AppData\Local\Programs\Python\Python39\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
OSError: SavedModel file does not exist at: C:\Users\herman.tam\AppData\Local\Temp\tfhub_modules\602d30248ff7929470db09f7385fc895e9ceb4c0\{saved_model.pbtxt|saved_model.pb}
It's saying it cannot find the model file:
OSError: SavedModel file does not exist at: C:\Users\user\AppData\Local\Temp\tfhub_modules\d760773f85f64fc84ae0b47310f7cfe3bcec4868\{saved_model.pbtxt|saved_model.pb}
Can you look in that directory to see if it exists? Maybe it's saved under a different name? Or, did the operations to create it fail?
Thank you for your response.
There are two empty folders in the directory (please refer to the screenshot). I wonder why this happens because there is currently even a problem with downloading the trained models (bert_preprocessor & bert_encoder) and there was no problem with the same code last month.
Seems like this person below has experienced something similar:
I'm glad you got it working. One thing I noticed is that these file are in your .../Local/Temp/... directory. The operating system will delete files in here after some amount of time.
My guess at a timeline of events:
- run code and it saves the model correctly in the directory
- time passes and the OS deletes the model files
- run code again and it finds the directory for the model so doesn't save to overwrite it even though files in the directory don't exist - thus it fails trying to load it.
- more time passes and the directory is now removed also
- run code again, directory doesn't exist, so model is correctly saved like the first time you ran it.